1set(LIBCXX_LIB_CMAKEFILES_DIR "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}" PARENT_SCOPE) 2 3# Get sources 4set(LIBCXX_SOURCES 5 algorithm.cpp 6 any.cpp 7 atomic.cpp 8 barrier.cpp 9 bind.cpp 10 charconv.cpp 11 chrono.cpp 12 condition_variable.cpp 13 condition_variable_destructor.cpp 14 exception.cpp 15 format.cpp 16 functional.cpp 17 future.cpp 18 hash.cpp 19 include/apple_availability.h 20 include/atomic_support.h 21 include/config_elast.h 22 include/refstring.h 23 memory.cpp 24 mutex.cpp 25 mutex_destructor.cpp 26 new.cpp 27 optional.cpp 28 random_shuffle.cpp 29 shared_mutex.cpp 30 stdexcept.cpp 31 string.cpp 32 support/runtime/exception_fallback.ipp 33 support/runtime/exception_glibcxx.ipp 34 support/runtime/exception_libcxxabi.ipp 35 support/runtime/exception_libcxxrt.ipp 36 support/runtime/exception_msvc.ipp 37 support/runtime/exception_pointer_cxxabi.ipp 38 support/runtime/exception_pointer_glibcxx.ipp 39 support/runtime/exception_pointer_msvc.ipp 40 support/runtime/exception_pointer_unimplemented.ipp 41 support/runtime/new_handler_fallback.ipp 42 support/runtime/stdexcept_default.ipp 43 support/runtime/stdexcept_vcruntime.ipp 44 system_error.cpp 45 thread.cpp 46 typeinfo.cpp 47 utility.cpp 48 valarray.cpp 49 variant.cpp 50 vector.cpp 51 ) 52 53if (LIBCXX_ENABLE_DEBUG_MODE_SUPPORT) 54 list(APPEND LIBCXX_SOURCES 55 debug.cpp 56 ) 57endif() 58 59if (LIBCXX_ENABLE_RANDOM_DEVICE) 60 list(APPEND LIBCXX_SOURCES 61 random.cpp 62 ) 63endif() 64 65if (LIBCXX_ENABLE_LOCALIZATION) 66 list(APPEND LIBCXX_SOURCES 67 include/sso_allocator.h 68 ios.cpp 69 ios.instantiations.cpp 70 iostream.cpp 71 locale.cpp 72 regex.cpp 73 strstream.cpp 74 ) 75endif() 76 77if(WIN32) 78 list(APPEND LIBCXX_SOURCES 79 support/win32/locale_win32.cpp 80 support/win32/support.cpp 81 ) 82 83 if (NOT LIBCXX_HAS_PTHREAD_API) 84 list(APPEND LIBCXX_SOURCES 85 support/win32/thread_win32.cpp 86 ) 87 endif() 88elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS") 89 list(APPEND LIBCXX_SOURCES 90 support/solaris/mbsnrtowcs.inc 91 support/solaris/wcsnrtombs.inc 92 support/solaris/xlocale.cpp 93 ) 94elseif(ZOS) 95 list(APPEND LIBCXX_SOURCES 96 support/ibm/xlocale_zos.cpp 97 ) 98endif() 99 100if (LIBCXX_ENABLE_FILESYSTEM) 101 list(APPEND LIBCXX_SOURCES 102 filesystem/filesystem_common.h 103 filesystem/operations.cpp 104 filesystem/directory_iterator.cpp 105 filesystem/posix_compat.h 106 ) 107 # Filesystem uses __int128_t, which requires a definition of __muloi4 when 108 # compiled with UBSAN. This definition is not provided by libgcc_s, but is 109 # provided by compiler-rt. So we need to disable it to avoid having multiple 110 # definitions. See filesystem/int128_builtins.cpp. 111 if (NOT LIBCXX_USE_COMPILER_RT) 112 list(APPEND LIBCXX_SOURCES 113 filesystem/int128_builtins.cpp 114 ) 115 endif() 116endif() 117 118# Add all the headers to the project for IDEs. 119if (LIBCXX_CONFIGURE_IDE) 120 file(GLOB_RECURSE LIBCXX_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/*) 121 if(WIN32) 122 file( GLOB LIBCXX_WIN32_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/__support/win32/*.h) 123 list(APPEND LIBCXX_HEADERS ${LIBCXX_WIN32_HEADERS}) 124 endif() 125 # Force them all into the headers dir on MSVC, otherwise they end up at 126 # project scope because they don't have extensions. 127 if (MSVC_IDE) 128 source_group("Header Files" FILES ${LIBCXX_HEADERS}) 129 endif() 130endif() 131 132if(NOT LIBCXX_INSTALL_LIBRARY) 133 set(exclude_from_all EXCLUDE_FROM_ALL) 134endif() 135 136# If LIBCXX_CXX_ABI_LIBRARY_PATH is defined we want to add it to the search path. 137add_link_flags_if(LIBCXX_CXX_ABI_LIBRARY_PATH 138 "${CMAKE_LIBRARY_PATH_FLAG}${LIBCXX_CXX_ABI_LIBRARY_PATH}") 139 140 141if (LIBCXX_GENERATE_COVERAGE AND NOT LIBCXX_COVERAGE_LIBRARY) 142 find_compiler_rt_library(profile LIBCXX_COVERAGE_LIBRARY) 143endif() 144add_library_flags_if(LIBCXX_COVERAGE_LIBRARY "${LIBCXX_COVERAGE_LIBRARY}") 145 146if (APPLE AND LLVM_USE_SANITIZER) 147 if (("${LLVM_USE_SANITIZER}" STREQUAL "Address") OR 148 ("${LLVM_USE_SANITIZER}" STREQUAL "Address;Undefined") OR 149 ("${LLVM_USE_SANITIZER}" STREQUAL "Undefined;Address")) 150 set(LIBFILE "libclang_rt.asan_osx_dynamic.dylib") 151 elseif("${LLVM_USE_SANITIZER}" STREQUAL "Undefined") 152 set(LIBFILE "libclang_rt.ubsan_osx_dynamic.dylib") 153 elseif("${LLVM_USE_SANITIZER}" STREQUAL "Thread") 154 set(LIBFILE "libclang_rt.tsan_osx_dynamic.dylib") 155 else() 156 message(WARNING "LLVM_USE_SANITIZER=${LLVM_USE_SANITIZER} is not supported on OS X") 157 endif() 158 if (LIBFILE) 159 find_compiler_rt_dir(LIBDIR) 160 if (NOT IS_DIRECTORY "${LIBDIR}") 161 message(FATAL_ERROR "Cannot find compiler-rt directory on OS X required for LLVM_USE_SANITIZER") 162 endif() 163 set(LIBCXX_SANITIZER_LIBRARY "${LIBDIR}/${LIBFILE}") 164 set(LIBCXX_SANITIZER_LIBRARY "${LIBCXX_SANITIZER_LIBRARY}" PARENT_SCOPE) 165 message(STATUS "Manually linking compiler-rt library: ${LIBCXX_SANITIZER_LIBRARY}") 166 add_library_flags("${LIBCXX_SANITIZER_LIBRARY}") 167 add_link_flags("-Wl,-rpath,${LIBDIR}") 168 endif() 169endif() 170 171if (LIBCXX_ENABLE_PARALLEL_ALGORITHMS AND NOT TARGET pstl::ParallelSTL) 172 message(FATAL_ERROR "Could not find ParallelSTL") 173endif() 174 175function(cxx_set_common_defines name) 176 if(LIBCXX_CXX_ABI_HEADER_TARGET) 177 add_dependencies(${name} ${LIBCXX_CXX_ABI_HEADER_TARGET}) 178 endif() 179 180 if (LIBCXX_ENABLE_PARALLEL_ALGORITHMS) 181 target_link_libraries(${name} PUBLIC pstl::ParallelSTL) 182 endif() 183endfunction() 184 185split_list(LIBCXX_COMPILE_FLAGS) 186split_list(LIBCXX_LINK_FLAGS) 187 188# Build the shared library. 189if (LIBCXX_ENABLE_SHARED) 190 add_library(cxx_shared SHARED ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS}) 191 target_link_libraries(cxx_shared PUBLIC cxx-headers 192 PRIVATE ${LIBCXX_LIBRARIES}) 193 set_target_properties(cxx_shared 194 PROPERTIES 195 COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" 196 LINK_FLAGS "${LIBCXX_LINK_FLAGS}" 197 OUTPUT_NAME "c++" 198 VERSION "${LIBCXX_ABI_VERSION}.0" 199 SOVERSION "${LIBCXX_ABI_VERSION}" 200 DEFINE_SYMBOL "" 201 ) 202 cxx_add_common_build_flags(cxx_shared) 203 cxx_set_common_defines(cxx_shared) 204 205 # Link against LLVM libunwind 206 if (LIBCXXABI_USE_LLVM_UNWINDER) 207 if (NOT LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY AND (TARGET unwind_shared OR HAVE_LIBUNWIND)) 208 target_link_libraries(cxx_shared PUBLIC unwind_shared) 209 elseif (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY AND (TARGET unwind_static OR HAVE_LIBUNWIND)) 210 # libunwind is already included in libc++abi 211 else() 212 target_link_libraries(cxx_shared PUBLIC unwind) 213 endif() 214 endif() 215 216 # Link against libc++abi 217 if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY) 218 if (APPLE) 219 target_link_libraries(cxx_shared PRIVATE "-Wl,-force_load" "${LIBCXX_CXX_STATIC_ABI_LIBRARY}") 220 else() 221 target_link_libraries(cxx_shared PRIVATE "-Wl,--whole-archive,-Bstatic" "${LIBCXX_CXX_STATIC_ABI_LIBRARY}" "-Wl,-Bdynamic,--no-whole-archive") 222 endif() 223 else() 224 target_link_libraries(cxx_shared PUBLIC "${LIBCXX_CXX_SHARED_ABI_LIBRARY}") 225 endif() 226 227 # Maybe re-export symbols from libc++abi 228 # In particular, we don't re-export the symbols if libc++abi is merged statically 229 # into libc++ because in that case there's no dylib to re-export from. 230 if (APPLE AND (LIBCXX_CXX_ABI_LIBNAME STREQUAL "libcxxabi" OR 231 LIBCXX_CXX_ABI_LIBNAME STREQUAL "default") 232 AND NOT DEFINED LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS 233 AND NOT LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY) 234 set(LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS ON) 235 endif() 236 237 if (LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS) 238 target_link_libraries(cxx_shared PRIVATE 239 "-Wl,-unexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/libc++unexp.exp" 240 "-Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/libc++abi.v${LIBCXX_LIBCPPABI_VERSION}.exp" 241 "-Wl,-force_symbols_not_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/notweak.exp" 242 "-Wl,-force_symbols_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/weak.exp") 243 244 target_link_libraries(cxx_shared PRIVATE $<TARGET_NAME_IF_EXISTS:cxxabi-reexports>) 245 endif() 246 247 # Generate a linker script in place of a libc++.so symlink. 248 if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT) 249 include(DefineLinkerScript) 250 define_linker_script(cxx_shared) 251 endif() 252 253 list(APPEND LIBCXX_BUILD_TARGETS "cxx_shared") 254 if(WIN32 AND NOT MINGW AND NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows") 255 # Since we most likely do not have a mt.exe replacement, disable the 256 # manifest bundling. This allows a normal cmake invocation to pass which 257 # will attempt to use the manifest tool to generate the bundled manifest 258 set_target_properties(cxx_shared PROPERTIES 259 APPEND_STRING PROPERTY LINK_FLAGS " /MANIFEST:NO") 260 endif() 261endif() 262 263set(CMAKE_STATIC_LIBRARY_PREFIX "lib") 264 265# Build the static library. 266if (LIBCXX_ENABLE_STATIC) 267 add_library(cxx_static STATIC ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS}) 268 target_link_libraries(cxx_static PUBLIC cxx-headers 269 PRIVATE ${LIBCXX_LIBRARIES}) 270 set_target_properties(cxx_static 271 PROPERTIES 272 COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" 273 LINK_FLAGS "${LIBCXX_LINK_FLAGS}" 274 OUTPUT_NAME "c++" 275 ) 276 cxx_add_common_build_flags(cxx_static) 277 cxx_set_common_defines(cxx_static) 278 279 if (LIBCXX_HERMETIC_STATIC_LIBRARY) 280 # If the hermetic library doesn't define the operator new/delete functions 281 # then its code shouldn't declare them with hidden visibility. They might 282 # actually be provided by a shared library at link time. 283 if (LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS) 284 append_flags_if_supported(CXX_STATIC_LIBRARY_FLAGS -fvisibility-global-new-delete-hidden) 285 endif() 286 target_compile_options(cxx_static PRIVATE ${CXX_STATIC_LIBRARY_FLAGS}) 287 target_compile_definitions(cxx_static PRIVATE _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 288 endif() 289 290 list(APPEND LIBCXX_BUILD_TARGETS "cxx_static") 291 # Attempt to merge the libc++.a archive and the ABI library archive into one. 292 if (LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY) 293 set(MERGE_ARCHIVES_SEARCH_PATHS "") 294 if (LIBCXX_CXX_ABI_LIBRARY_PATH) 295 set(MERGE_ARCHIVES_SEARCH_PATHS "-L${LIBCXX_CXX_ABI_LIBRARY_PATH}") 296 endif() 297 if (TARGET "${LIBCXX_CXX_STATIC_ABI_LIBRARY}" OR HAVE_LIBCXXABI) 298 set(MERGE_ARCHIVES_ABI_TARGET "$<TARGET_LINKER_FILE:${LIBCXX_CXX_STATIC_ABI_LIBRARY}>") 299 else() 300 set(MERGE_ARCHIVES_ABI_TARGET 301 "${CMAKE_STATIC_LIBRARY_PREFIX}${LIBCXX_CXX_STATIC_ABI_LIBRARY}${CMAKE_STATIC_LIBRARY_SUFFIX}") 302 if (LIBCXX_CXX_ABI_LIBRARY_PATH) 303 set(MERGE_ARCHIVES_ABI_TARGET "${LIBCXX_CXX_ABI_LIBRARY_PATH}/${MERGE_ARCHIVES_ABI_TARGET}") 304 endif () 305 endif() 306 if (APPLE) 307 set(MERGE_ARCHIVES_LIBTOOL "--use-libtool" "--libtool" "${CMAKE_LIBTOOL}") 308 endif() 309 add_custom_command(TARGET cxx_static POST_BUILD 310 COMMAND 311 ${Python3_EXECUTABLE} ${LIBCXX_SOURCE_DIR}/utils/merge_archives.py 312 ARGS 313 -o $<TARGET_LINKER_FILE:cxx_static> 314 --ar "${CMAKE_AR}" 315 ${MERGE_ARCHIVES_LIBTOOL} 316 "$<TARGET_LINKER_FILE:cxx_static>" 317 "${MERGE_ARCHIVES_ABI_TARGET}" 318 "${MERGE_ARCHIVES_SEARCH_PATHS}" 319 WORKING_DIRECTORY ${LIBCXX_BUILD_DIR} 320 DEPENDS ${MERGE_ARCHIVES_ABI_TARGET} 321 ) 322 endif() 323endif() 324 325# Add a meta-target for both libraries. 326add_custom_target(cxx DEPENDS ${LIBCXX_BUILD_TARGETS}) 327 328if (LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY) 329 set(LIBCXX_EXPERIMENTAL_SOURCES 330 experimental/memory_resource.cpp 331 ) 332 add_library(cxx_experimental STATIC ${LIBCXX_EXPERIMENTAL_SOURCES}) 333 if (LIBCXX_ENABLE_SHARED) 334 target_link_libraries(cxx_experimental PRIVATE cxx_shared) 335 else() 336 target_link_libraries(cxx_experimental PRIVATE cxx_static) 337 endif() 338 339 set_target_properties(cxx_experimental 340 PROPERTIES 341 COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" 342 OUTPUT_NAME "c++experimental" 343 ) 344 cxx_add_common_build_flags(cxx_experimental) 345endif() 346 347 348if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY) 349 set(LIBCXX_EXTERNAL_THREADING_SUPPORT_SOURCES 350 "${CMAKE_CURRENT_SOURCE_DIR}/../test/support/external_threads.cpp") 351 352 if (LIBCXX_ENABLE_SHARED) 353 add_library(cxx_external_threads SHARED ${LIBCXX_EXTERNAL_THREADING_SUPPORT_SOURCES}) 354 else() 355 add_library(cxx_external_threads STATIC ${LIBCXX_EXTERNAL_THREADING_SUPPORT_SOURCES}) 356 endif() 357 358 set_target_properties(cxx_external_threads 359 PROPERTIES 360 LINK_FLAGS "${LIBCXX_LINK_FLAGS}" 361 COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" 362 OUTPUT_NAME "c++external_threads" 363 ) 364 365 target_link_libraries(cxx_external_threads PRIVATE cxx-headers) 366endif() 367 368if (LIBCXX_INSTALL_SHARED_LIBRARY) 369 install(TARGETS cxx_shared 370 ARCHIVE DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx 371 LIBRARY DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx 372 RUNTIME DESTINATION bin COMPONENT cxx) 373endif() 374 375if (LIBCXX_INSTALL_STATIC_LIBRARY) 376 install(TARGETS cxx_static 377 ARCHIVE DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx 378 LIBRARY DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx 379 RUNTIME DESTINATION bin COMPONENT cxx) 380endif() 381 382if(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY) 383 install(TARGETS cxx_experimental 384 LIBRARY DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx 385 ARCHIVE DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx 386 RUNTIME DESTINATION bin COMPONENT cxx) 387endif() 388 389# NOTE: This install command must go after the cxx install command otherwise 390# it will not be executed after the library symlinks are installed. 391if (LIBCXX_ENABLE_SHARED AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT) 392 install(FILES "$<TARGET_LINKER_FILE:cxx_shared>" 393 DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} 394 COMPONENT libcxx) 395endif() 396 397if (NOT CMAKE_CONFIGURATION_TYPES) 398 if(LIBCXX_INSTALL_LIBRARY) 399 set(lib_install_target cxx) 400 endif() 401 if (LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY) 402 set(experimental_lib_install_target cxx_experimental) 403 endif() 404 if(LIBCXX_INSTALL_HEADERS) 405 set(header_install_target install-cxx-headers) 406 endif() 407 if (LIBCXX_ENABLE_PARALLEL_ALGORITHMS) 408 set(pstl_install_target install-pstl) 409 endif() 410 add_custom_target(install-cxx 411 DEPENDS ${lib_install_target} 412 ${experimental_lib_install_target} 413 ${header_install_target} 414 ${pstl_install_target} 415 COMMAND "${CMAKE_COMMAND}" 416 -DCMAKE_INSTALL_COMPONENT=cxx 417 -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake") 418 add_custom_target(install-cxx-stripped 419 DEPENDS ${lib_install_target} 420 ${experimental_lib_install_target} 421 ${header_install_target} 422 ${pstl_install_target} 423 COMMAND "${CMAKE_COMMAND}" 424 -DCMAKE_INSTALL_COMPONENT=cxx 425 -DCMAKE_INSTALL_DO_STRIP=1 426 -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake") 427endif() 428