415 lines · plain
1# Get sources2set(LIBCXX_SOURCES3 algorithm.cpp4 any.cpp5 bind.cpp6 call_once.cpp7 charconv.cpp8 chrono.cpp9 error_category.cpp10 exception.cpp11 expected.cpp12 filesystem/filesystem_clock.cpp13 filesystem/filesystem_error.cpp14 filesystem/path_parser.h15 filesystem/path.cpp16 functional.cpp17 hash.cpp18 include/apple_availability.h19 include/atomic_support.h20 include/config_elast.h21 include/refstring.h22 include/ryu/common.h23 include/ryu/d2fixed.h24 include/ryu/d2fixed_full_table.h25 include/ryu/d2s.h26 include/ryu/d2s_full_table.h27 include/ryu/d2s_intrinsics.h28 include/ryu/digit_table.h29 include/ryu/f2s.h30 include/ryu/ryu.h31 include/to_chars_floating_point.h32 include/from_chars_floating_point.h33 memory.cpp34 memory_resource.cpp35 new_handler.cpp36 new_helpers.cpp37 optional.cpp38 print.cpp39 random_shuffle.cpp40 ryu/d2fixed.cpp41 ryu/d2s.cpp42 ryu/f2s.cpp43 stdexcept.cpp44 string.cpp45 support/runtime/exception_fallback.ipp46 support/runtime/exception_glibcxx.ipp47 support/runtime/exception_libcxxabi.ipp48 support/runtime/exception_libcxxrt.ipp49 support/runtime/exception_msvc.ipp50 support/runtime/exception_pointer_cxxabi.ipp51 support/runtime/exception_pointer_glibcxx.ipp52 support/runtime/exception_pointer_msvc.ipp53 support/runtime/exception_pointer_unimplemented.ipp54 support/runtime/stdexcept_default.ipp55 support/runtime/stdexcept_vcruntime.ipp56 system_error.cpp57 typeinfo.cpp58 valarray.cpp59 variant.cpp60 vector.cpp61 verbose_abort.cpp62 )63 64if (LIBCXX_ENABLE_THREADS)65 list(APPEND LIBCXX_SOURCES66 atomic.cpp67 barrier.cpp68 condition_variable_destructor.cpp69 condition_variable.cpp70 future.cpp71 mutex_destructor.cpp72 mutex.cpp73 shared_mutex.cpp74 thread.cpp75 )76endif()77 78if (LIBCXX_ENABLE_RANDOM_DEVICE)79 list(APPEND LIBCXX_SOURCES80 random.cpp81 )82endif()83 84if (LIBCXX_ENABLE_LOCALIZATION)85 list(APPEND LIBCXX_SOURCES86 fstream.cpp87 include/sso_allocator.h88 ios.cpp89 ios.instantiations.cpp90 iostream.cpp91 locale.cpp92 ostream.cpp93 regex.cpp94 strstream.cpp95 )96endif()97 98if(WIN32)99 list(APPEND LIBCXX_SOURCES100 support/win32/compiler_rt_shims.cpp101 support/win32/locale_win32.cpp102 support/win32/support.cpp103 )104 105 if (NOT LIBCXX_HAS_PTHREAD_API)106 list(APPEND LIBCXX_SOURCES107 support/win32/thread_win32.cpp108 )109 endif()110elseif(ZOS)111 list(APPEND LIBCXX_SOURCES112 support/ibm/mbsnrtowcs.cpp113 support/ibm/wcsnrtombs.cpp114 support/ibm/xlocale_zos.cpp115 )116endif()117 118if (LIBCXX_ENABLE_FILESYSTEM)119 list(APPEND LIBCXX_SOURCES120 filesystem/directory_entry.cpp121 filesystem/directory_iterator.cpp122 filesystem/file_descriptor.h123 filesystem/operations.cpp124 filesystem/posix_compat.h125 filesystem/time_utils.h126 )127 # Filesystem uses __int128_t, which requires a definition of __muloi4 when128 # compiled with UBSAN. This definition is not provided by libgcc_s, but is129 # provided by compiler-rt. So we need to disable it to avoid having multiple130 # definitions. See filesystem/int128_builtins.cpp.131 if (NOT LIBCXX_USE_COMPILER_RT)132 list(APPEND LIBCXX_SOURCES133 filesystem/int128_builtins.cpp134 )135 endif()136endif()137 138if (LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS)139 list(APPEND LIBCXX_SOURCES140 new.cpp141 )142endif()143 144if (APPLE AND LLVM_USE_SANITIZER)145 if (("${LLVM_USE_SANITIZER}" STREQUAL "Address") OR146 ("${LLVM_USE_SANITIZER}" STREQUAL "Address;Undefined") OR147 ("${LLVM_USE_SANITIZER}" STREQUAL "Undefined;Address"))148 set(LIBFILE "libclang_rt.asan_osx_dynamic.dylib")149 elseif("${LLVM_USE_SANITIZER}" STREQUAL "Undefined")150 set(LIBFILE "libclang_rt.ubsan_osx_dynamic.dylib")151 elseif("${LLVM_USE_SANITIZER}" STREQUAL "Thread")152 set(LIBFILE "libclang_rt.tsan_osx_dynamic.dylib")153 else()154 message(WARNING "LLVM_USE_SANITIZER=${LLVM_USE_SANITIZER} is not supported on OS X")155 endif()156 if (LIBFILE)157 find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY)158 get_filename_component(LIBDIR "${LIBCXX_BUILTINS_LIBRARY}" DIRECTORY)159 if (NOT IS_DIRECTORY "${LIBDIR}")160 message(FATAL_ERROR "Cannot find compiler-rt directory on OS X required for LLVM_USE_SANITIZER")161 endif()162 set(LIBCXX_SANITIZER_LIBRARY "${LIBDIR}/${LIBFILE}")163 set(LIBCXX_SANITIZER_LIBRARY "${LIBCXX_SANITIZER_LIBRARY}" PARENT_SCOPE)164 message(STATUS "Manually linking compiler-rt library: ${LIBCXX_SANITIZER_LIBRARY}")165 add_library_flags("${LIBCXX_SANITIZER_LIBRARY}")166 add_link_flags("-Wl,-rpath,${LIBDIR}")167 endif()168endif()169 170split_list(LIBCXX_COMPILE_FLAGS)171split_list(LIBCXX_LINK_FLAGS)172 173include(FindLibcCommonUtils)174 175# Build the shared library.176add_library(cxx_shared SHARED ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})177target_include_directories(cxx_shared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})178target_link_libraries(cxx_shared PUBLIC cxx-headers runtimes-libc-shared179 PRIVATE ${LIBCXX_LIBRARIES}180 PRIVATE llvm-libc-common-utilities)181set_target_properties(cxx_shared182 PROPERTIES183 EXCLUDE_FROM_ALL "$<IF:$<BOOL:${LIBCXX_ENABLE_SHARED}>,FALSE,TRUE>"184 COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"185 LINK_FLAGS "${LIBCXX_LINK_FLAGS}"186 OUTPUT_NAME "${LIBCXX_SHARED_OUTPUT_NAME}"187 VERSION "${LIBCXX_LIBRARY_VERSION}"188 SOVERSION "${LIBCXX_ABI_VERSION}"189 DEFINE_SYMBOL ""190)191cxx_add_common_build_flags(cxx_shared)192 193if(ZOS)194 add_custom_command(TARGET cxx_shared POST_BUILD195 COMMAND196 ${LIBCXX_SOURCE_DIR}/utils/zos_rename_dll_side_deck.sh197 $<TARGET_LINKER_FILE_NAME:cxx_shared> $<TARGET_FILE_NAME:cxx_shared> "${LIBCXX_DLL_NAME}"198 COMMENT "Rename dll name inside the side deck file"199 WORKING_DIRECTORY $<TARGET_FILE_DIR:cxx_shared>200 )201endif()202 203# Link against libc++abi204if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY)205 target_link_libraries(cxx_shared PRIVATE libcxx-abi-shared-objects)206else()207 target_link_libraries(cxx_shared PUBLIC libcxx-abi-shared)208endif()209 210# Maybe force some symbols to be weak, not weak or not exported.211# TODO: This shouldn't depend on the platform, and ideally it should be done in the sources.212if (APPLE AND LIBCXX_CXX_ABI MATCHES "libcxxabi$"213 AND NOT LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY)214 target_link_libraries(cxx_shared PRIVATE215 "-Wl,-force_symbols_not_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/notweak.exp"216 "-Wl,-force_symbols_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/weak.exp")217endif()218 219# Generate a linker script in place of a libc++.so symlink.220if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)221 set(link_libraries)222 223 set(imported_libname "$<TARGET_PROPERTY:libcxx-abi-shared,IMPORTED_LIBNAME>")224 set(output_name "$<TARGET_PROPERTY:libcxx-abi-shared,OUTPUT_NAME>")225 string(APPEND link_libraries "${CMAKE_LINK_LIBRARY_FLAG}$<IF:$<BOOL:${imported_libname}>,${imported_libname},${output_name}>")226 227 # TODO: Move to the same approach as above for the unwind library228 if (LIBCXXABI_USE_LLVM_UNWINDER)229 if (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY)230 # libunwind is already included in libc++abi231 elseif (TARGET unwind_shared OR HAVE_LIBUNWIND)232 string(APPEND link_libraries " ${CMAKE_LINK_LIBRARY_FLAG}$<TARGET_PROPERTY:unwind_shared,OUTPUT_NAME>")233 else()234 string(APPEND link_libraries " ${CMAKE_LINK_LIBRARY_FLAG}unwind")235 endif()236 endif()237 238 set(linker_script "INPUT($<TARGET_SONAME_FILE_NAME:cxx_shared> ${link_libraries})")239 add_custom_command(TARGET cxx_shared POST_BUILD240 COMMAND "${CMAKE_COMMAND}" -E remove "$<TARGET_LINKER_FILE:cxx_shared>"241 COMMAND "${CMAKE_COMMAND}" -E echo "${linker_script}" > "$<TARGET_LINKER_FILE:cxx_shared>"242 COMMENT "Generating linker script: '${linker_script}' as file $<TARGET_LINKER_FILE:cxx_shared>"243 VERBATIM244 )245endif()246 247if (LIBCXX_ENABLE_SHARED)248 list(APPEND LIBCXX_BUILD_TARGETS "cxx_shared")249endif()250 251if(WIN32 AND NOT MINGW AND NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")252 # Since we most likely do not have a mt.exe replacement, disable the253 # manifest bundling. This allows a normal cmake invocation to pass which254 # will attempt to use the manifest tool to generate the bundled manifest255 if (${CMAKE_CXX_COMPILER_FRONTEND_VARIANT} STREQUAL "MSVC")256 set_target_properties(cxx_shared PROPERTIES257 APPEND_STRING PROPERTY LINK_FLAGS " /MANIFEST:NO")258 else()259 set_target_properties(cxx_shared PROPERTIES260 APPEND_STRING PROPERTY LINK_FLAGS " -Xlinker /MANIFEST:NO")261 endif()262endif()263 264set(CMAKE_STATIC_LIBRARY_PREFIX "lib")265 266# Build the static library.267add_library(cxx_static STATIC ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})268target_include_directories(cxx_static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})269target_link_libraries(cxx_static PUBLIC cxx-headers runtimes-libc-static270 PRIVATE ${LIBCXX_LIBRARIES}271 PRIVATE libcxx-abi-static272 PRIVATE llvm-libc-common-utilities)273set_target_properties(cxx_static274 PROPERTIES275 EXCLUDE_FROM_ALL "$<IF:$<BOOL:${LIBCXX_ENABLE_STATIC}>,FALSE,TRUE>"276 COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"277 LINK_FLAGS "${LIBCXX_LINK_FLAGS}"278 OUTPUT_NAME "${LIBCXX_STATIC_OUTPUT_NAME}"279)280cxx_add_common_build_flags(cxx_static)281 282if (LIBCXX_HERMETIC_STATIC_LIBRARY)283 # If the hermetic library doesn't define the operator new/delete functions284 # then its code shouldn't declare them with hidden visibility. They might285 # actually be provided by a shared library at link time.286 if (LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS)287 append_flags_if_supported(CXX_STATIC_LIBRARY_FLAGS -fvisibility-global-new-delete=force-hidden)288 if (NOT CXX_SUPPORTS_FVISIBILITY_GLOBAL_NEW_DELETE_EQ_FORCE_HIDDEN_FLAG)289 append_flags_if_supported(CXX_STATIC_LIBRARY_FLAGS -fvisibility-global-new-delete-hidden)290 endif()291 endif()292 target_compile_options(cxx_static PRIVATE ${CXX_STATIC_LIBRARY_FLAGS})293 # _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS can be defined in __config_site294 # too. Define it in the same way here, to avoid redefinition conflicts.295 target_compile_definitions(cxx_static PRIVATE _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS=)296endif()297 298if (LIBCXX_ENABLE_STATIC)299 list(APPEND LIBCXX_BUILD_TARGETS "cxx_static")300endif()301# Attempt to merge the libc++.a archive and the ABI library archive into one.302if (LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY)303 target_link_libraries(cxx_static PRIVATE libcxx-abi-static-objects)304endif()305 306# Add a meta-target for both libraries.307add_custom_target(cxx DEPENDS ${LIBCXX_BUILD_TARGETS})308 309# Build the experimental static library310set(LIBCXX_EXPERIMENTAL_SOURCES311 experimental/keep.cpp312 experimental/log_hardening_failure.cpp313 )314 315if (LIBCXX_PSTL_BACKEND STREQUAL "libdispatch")316 list(APPEND LIBCXX_EXPERIMENTAL_SOURCES317 pstl/libdispatch.cpp318 )319endif()320 321if (LIBCXX_ENABLE_LOCALIZATION AND LIBCXX_ENABLE_FILESYSTEM AND LIBCXX_ENABLE_TIME_ZONE_DATABASE)322 list(APPEND LIBCXX_EXPERIMENTAL_SOURCES323 experimental/include/tzdb/time_zone_private.h324 experimental/include/tzdb/types_private.h325 experimental/include/tzdb/tzdb_list_private.h326 experimental/include/tzdb/tzdb_private.h327 # TODO TZDB The exception could be moved in chrono once the TZDB library328 # is no longer experimental.329 experimental/chrono_exception.cpp330 experimental/time_zone.cpp331 experimental/tzdb.cpp332 experimental/tzdb_list.cpp333 )334endif()335 336add_library(cxx_experimental STATIC ${LIBCXX_EXPERIMENTAL_SOURCES})337target_link_libraries(cxx_experimental PUBLIC cxx-headers)338if (LIBCXX_ENABLE_SHARED)339 target_link_libraries(cxx_experimental PRIVATE cxx_shared)340else()341 target_link_libraries(cxx_experimental PRIVATE cxx_static)342endif()343 344if (LIBCXX_HERMETIC_STATIC_LIBRARY)345 # _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS can be defined in __config_site346 # too. Define it in the same way here, to avoid redefinition conflicts.347 target_compile_definitions(cxx_experimental PRIVATE _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS=)348endif()349 350set_target_properties(cxx_experimental351 PROPERTIES352 COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"353 OUTPUT_NAME "c++experimental"354)355cxx_add_common_build_flags(cxx_experimental)356target_compile_options(cxx_experimental PUBLIC -D_LIBCPP_ENABLE_EXPERIMENTAL)357 358if (LIBCXX_INSTALL_SHARED_LIBRARY)359 install(TARGETS cxx_shared360 ARCHIVE DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx361 LIBRARY DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx362 RUNTIME DESTINATION ${LIBCXX_INSTALL_RUNTIME_DIR} COMPONENT cxx)363endif()364 365if (LIBCXX_INSTALL_STATIC_LIBRARY)366 install(TARGETS cxx_static367 ARCHIVE DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx368 LIBRARY DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx369 RUNTIME DESTINATION ${LIBCXX_INSTALL_RUNTIME_DIR} COMPONENT cxx)370endif()371 372if (LIBCXX_INSTALL_LIBRARY)373 install(TARGETS cxx_experimental374 LIBRARY DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx375 ARCHIVE DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx376 RUNTIME DESTINATION ${LIBCXX_INSTALL_RUNTIME_DIR} COMPONENT cxx)377endif()378 379# NOTE: This install command must go after the cxx install command otherwise380# it will not be executed after the library symlinks are installed.381if (LIBCXX_ENABLE_SHARED AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT)382 install(FILES "$<TARGET_LINKER_FILE:cxx_shared>"383 DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR}384 COMPONENT libcxx)385endif()386 387if (NOT CMAKE_CONFIGURATION_TYPES)388 if(LIBCXX_INSTALL_LIBRARY)389 set(lib_install_target "cxx;cxx_experimental")390 endif()391 if(LIBCXX_INSTALL_HEADERS)392 set(header_install_target install-cxx-headers)393 endif()394 if(LIBCXX_INSTALL_MODULES)395 set(module_install_target install-cxx-modules)396 endif()397 add_custom_target(install-cxx398 DEPENDS ${lib_install_target}399 cxx_experimental400 ${header_install_target}401 ${module_install_target}402 COMMAND "${CMAKE_COMMAND}"403 -DCMAKE_INSTALL_COMPONENT=cxx404 -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")405 add_custom_target(install-cxx-stripped406 DEPENDS ${lib_install_target}407 cxx_experimental408 ${header_install_target}409 ${module_install_target}410 COMMAND "${CMAKE_COMMAND}"411 -DCMAKE_INSTALL_COMPONENT=cxx412 -DCMAKE_INSTALL_DO_STRIP=1413 -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")414endif()415