1 set(LIBCXX_LIB_CMAKEFILES_DIR "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}" PARENT_SCOPE)
14 filesystem/filesystem_clock.cpp
15 filesystem/filesystem_error.cpp
16 filesystem/path_parser.h
20 include/apple_availability.h
21 include/atomic_support.h
22 include/config_elast.h
26 include/ryu/d2fixed_full_table.h
28 include/ryu/d2s_full_table.h
29 include/ryu/d2s_intrinsics.h
30 include/ryu/digit_table.h
33 include/to_chars_floating_point.h
34 include/from_chars_floating_point.h
35 legacy_pointer_safety.cpp
48 support/runtime/exception_fallback.ipp
49 support/runtime/exception_glibcxx.ipp
50 support/runtime/exception_libcxxabi.ipp
51 support/runtime/exception_libcxxrt.ipp
52 support/runtime/exception_msvc.ipp
53 support/runtime/exception_pointer_cxxabi.ipp
54 support/runtime/exception_pointer_glibcxx.ipp
55 support/runtime/exception_pointer_msvc.ipp
56 support/runtime/exception_pointer_unimplemented.ipp
57 support/runtime/stdexcept_default.ipp
58 support/runtime/stdexcept_vcruntime.ipp
67 if (LIBCXX_ENABLE_THREADS)
68 list(APPEND LIBCXX_SOURCES
71 condition_variable_destructor.cpp
72 condition_variable.cpp
81 if (LIBCXX_ENABLE_RANDOM_DEVICE)
82 list(APPEND LIBCXX_SOURCES
87 if (LIBCXX_ENABLE_LOCALIZATION)
88 list(APPEND LIBCXX_SOURCES
90 include/sso_allocator.h
92 ios.instantiations.cpp
102 list(APPEND LIBCXX_SOURCES
103 support/win32/compiler_rt_shims.cpp
104 support/win32/locale_win32.cpp
105 support/win32/support.cpp
108 if (NOT LIBCXX_HAS_PTHREAD_API)
109 list(APPEND LIBCXX_SOURCES
110 support/win32/thread_win32.cpp
114 list(APPEND LIBCXX_SOURCES
115 support/ibm/mbsnrtowcs.cpp
116 support/ibm/wcsnrtombs.cpp
117 support/ibm/xlocale_zos.cpp
121 if (LIBCXX_ENABLE_FILESYSTEM)
122 list(APPEND LIBCXX_SOURCES
123 filesystem/directory_entry.cpp
124 filesystem/directory_iterator.cpp
125 filesystem/file_descriptor.h
126 filesystem/operations.cpp
127 filesystem/posix_compat.h
128 filesystem/time_utils.h
130 # Filesystem uses __int128_t, which requires a definition of __muloi4 when
131 # compiled with UBSAN. This definition is not provided by libgcc_s, but is
132 # provided by compiler-rt. So we need to disable it to avoid having multiple
133 # definitions. See filesystem/int128_builtins.cpp.
134 if (NOT LIBCXX_USE_COMPILER_RT)
135 list(APPEND LIBCXX_SOURCES
136 filesystem/int128_builtins.cpp
141 if (LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS)
142 list(APPEND LIBCXX_SOURCES
147 if (APPLE AND LLVM_USE_SANITIZER)
148 if (("${LLVM_USE_SANITIZER}" STREQUAL "Address") OR
149 ("${LLVM_USE_SANITIZER}" STREQUAL "Address;Undefined") OR
150 ("${LLVM_USE_SANITIZER}" STREQUAL "Undefined;Address"))
151 set(LIBFILE "libclang_rt.asan_osx_dynamic.dylib")
152 elseif("${LLVM_USE_SANITIZER}" STREQUAL "Undefined")
153 set(LIBFILE "libclang_rt.ubsan_osx_dynamic.dylib")
154 elseif("${LLVM_USE_SANITIZER}" STREQUAL "Thread")
155 set(LIBFILE "libclang_rt.tsan_osx_dynamic.dylib")
157 message(WARNING "LLVM_USE_SANITIZER=${LLVM_USE_SANITIZER} is not supported on OS X")
160 find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY)
161 get_filename_component(LIBDIR "${LIBCXX_BUILTINS_LIBRARY}" DIRECTORY)
162 if (NOT IS_DIRECTORY "${LIBDIR}")
163 message(FATAL_ERROR "Cannot find compiler-rt directory on OS X required for LLVM_USE_SANITIZER")
165 set(LIBCXX_SANITIZER_LIBRARY "${LIBDIR}/${LIBFILE}")
166 set(LIBCXX_SANITIZER_LIBRARY "${LIBCXX_SANITIZER_LIBRARY}" PARENT_SCOPE)
167 message(STATUS "Manually linking compiler-rt library: ${LIBCXX_SANITIZER_LIBRARY}")
168 add_library_flags("${LIBCXX_SANITIZER_LIBRARY}")
169 add_link_flags("-Wl,-rpath,${LIBDIR}")
173 split_list(LIBCXX_COMPILE_FLAGS)
174 split_list(LIBCXX_LINK_FLAGS)
176 include(FindLibcCommonUtils)
178 # Build the shared library.
179 add_library(cxx_shared SHARED ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
180 target_include_directories(cxx_shared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
181 target_link_libraries(cxx_shared PUBLIC cxx-headers libcxx-libc-shared
182 PRIVATE ${LIBCXX_LIBRARIES}
183 PRIVATE llvm-libc-common-utilities)
184 set_target_properties(cxx_shared
186 EXCLUDE_FROM_ALL "$<IF:$<BOOL:${LIBCXX_ENABLE_SHARED}>,FALSE,TRUE>"
187 COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
188 LINK_FLAGS "${LIBCXX_LINK_FLAGS}"
189 OUTPUT_NAME "${LIBCXX_SHARED_OUTPUT_NAME}"
190 VERSION "${LIBCXX_LIBRARY_VERSION}"
191 SOVERSION "${LIBCXX_ABI_VERSION}"
194 cxx_add_common_build_flags(cxx_shared)
197 add_custom_command(TARGET cxx_shared POST_BUILD
199 ${LIBCXX_SOURCE_DIR}/utils/zos_rename_dll_side_deck.sh
200 $<TARGET_LINKER_FILE_NAME:cxx_shared> $<TARGET_FILE_NAME:cxx_shared> "${LIBCXX_DLL_NAME}"
201 COMMENT "Rename dll name inside the side deck file"
202 WORKING_DIRECTORY $<TARGET_FILE_DIR:cxx_shared>
206 # Link against libc++abi
207 if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY)
208 target_link_libraries(cxx_shared PRIVATE libcxx-abi-shared-objects)
210 target_link_libraries(cxx_shared PUBLIC libcxx-abi-shared)
213 # Maybe force some symbols to be weak, not weak or not exported.
214 # TODO: This shouldn't depend on the platform, and ideally it should be done in the sources.
215 if (APPLE AND LIBCXX_CXX_ABI MATCHES "libcxxabi$"
216 AND NOT LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY)
217 target_link_libraries(cxx_shared PRIVATE
218 "-Wl,-force_symbols_not_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/notweak.exp"
219 "-Wl,-force_symbols_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/weak.exp")
222 # Generate a linker script in place of a libc++.so symlink.
223 if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
226 set(imported_libname "$<TARGET_PROPERTY:libcxx-abi-shared,IMPORTED_LIBNAME>")
227 set(output_name "$<TARGET_PROPERTY:libcxx-abi-shared,OUTPUT_NAME>")
228 string(APPEND link_libraries "${CMAKE_LINK_LIBRARY_FLAG}$<IF:$<BOOL:${imported_libname}>,${imported_libname},${output_name}>")
230 # TODO: Move to the same approach as above for the unwind library
231 if (LIBCXXABI_USE_LLVM_UNWINDER)
232 if (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY)
233 # libunwind is already included in libc++abi
234 elseif (TARGET unwind_shared OR HAVE_LIBUNWIND)
235 string(APPEND link_libraries " ${CMAKE_LINK_LIBRARY_FLAG}$<TARGET_PROPERTY:unwind_shared,OUTPUT_NAME>")
237 string(APPEND link_libraries " ${CMAKE_LINK_LIBRARY_FLAG}unwind")
241 set(linker_script "INPUT($<TARGET_SONAME_FILE_NAME:cxx_shared> ${link_libraries})")
242 add_custom_command(TARGET cxx_shared POST_BUILD
243 COMMAND "${CMAKE_COMMAND}" -E remove "$<TARGET_LINKER_FILE:cxx_shared>"
244 COMMAND "${CMAKE_COMMAND}" -E echo "${linker_script}" > "$<TARGET_LINKER_FILE:cxx_shared>"
245 COMMENT "Generating linker script: '${linker_script}' as file $<TARGET_LINKER_FILE:cxx_shared>"
250 if (LIBCXX_ENABLE_SHARED)
251 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 if (${CMAKE_CXX_COMPILER_FRONTEND_VARIANT} STREQUAL "MSVC")
259 set_target_properties(cxx_shared PROPERTIES
260 APPEND_STRING PROPERTY LINK_FLAGS " /MANIFEST:NO")
262 set_target_properties(cxx_shared PROPERTIES
263 APPEND_STRING PROPERTY LINK_FLAGS " -Xlinker /MANIFEST:NO")
267 set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
269 # Build the static library.
270 add_library(cxx_static STATIC ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
271 target_include_directories(cxx_static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
272 target_link_libraries(cxx_static PUBLIC cxx-headers libcxx-libc-static
273 PRIVATE ${LIBCXX_LIBRARIES}
274 PRIVATE libcxx-abi-static
275 PRIVATE llvm-libc-common-utilities)
276 set_target_properties(cxx_static
278 EXCLUDE_FROM_ALL "$<IF:$<BOOL:${LIBCXX_ENABLE_STATIC}>,FALSE,TRUE>"
279 COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
280 LINK_FLAGS "${LIBCXX_LINK_FLAGS}"
281 OUTPUT_NAME "${LIBCXX_STATIC_OUTPUT_NAME}"
283 cxx_add_common_build_flags(cxx_static)
285 if (LIBCXX_HERMETIC_STATIC_LIBRARY)
286 # If the hermetic library doesn't define the operator new/delete functions
287 # then its code shouldn't declare them with hidden visibility. They might
288 # actually be provided by a shared library at link time.
289 if (LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS)
290 append_flags_if_supported(CXX_STATIC_LIBRARY_FLAGS -fvisibility-global-new-delete=force-hidden)
291 if (NOT CXX_SUPPORTS_FVISIBILITY_GLOBAL_NEW_DELETE_EQ_FORCE_HIDDEN_FLAG)
292 append_flags_if_supported(CXX_STATIC_LIBRARY_FLAGS -fvisibility-global-new-delete-hidden)
295 target_compile_options(cxx_static PRIVATE ${CXX_STATIC_LIBRARY_FLAGS})
296 # _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS can be defined in __config_site
297 # too. Define it in the same way here, to avoid redefinition conflicts.
298 target_compile_definitions(cxx_static PRIVATE _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS=)
301 if (LIBCXX_ENABLE_STATIC)
302 list(APPEND LIBCXX_BUILD_TARGETS "cxx_static")
304 # Attempt to merge the libc++.a archive and the ABI library archive into one.
305 if (LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY)
306 target_link_libraries(cxx_static PRIVATE libcxx-abi-static-objects)
309 # Add a meta-target for both libraries.
310 add_custom_target(cxx DEPENDS ${LIBCXX_BUILD_TARGETS})
312 # Build the experimental static library
313 set(LIBCXX_EXPERIMENTAL_SOURCES
314 experimental/keep.cpp
317 if (LIBCXX_PSTL_BACKEND STREQUAL "libdispatch")
318 list(APPEND LIBCXX_EXPERIMENTAL_SOURCES
323 if (LIBCXX_ENABLE_LOCALIZATION AND LIBCXX_ENABLE_FILESYSTEM AND LIBCXX_ENABLE_TIME_ZONE_DATABASE)
324 list(APPEND LIBCXX_EXPERIMENTAL_SOURCES
325 experimental/include/tzdb/time_zone_private.h
326 experimental/include/tzdb/types_private.h
327 experimental/include/tzdb/tzdb_list_private.h
328 experimental/include/tzdb/tzdb_private.h
329 # TODO TZDB The exception could be moved in chrono once the TZDB library
330 # is no longer experimental.
331 experimental/chrono_exception.cpp
332 experimental/time_zone.cpp
333 experimental/tzdb.cpp
334 experimental/tzdb_list.cpp
338 add_library(cxx_experimental STATIC ${LIBCXX_EXPERIMENTAL_SOURCES})
339 target_link_libraries(cxx_experimental PUBLIC cxx-headers)
340 if (LIBCXX_ENABLE_SHARED)
341 target_link_libraries(cxx_experimental PRIVATE cxx_shared)
343 target_link_libraries(cxx_experimental PRIVATE cxx_static)
346 if (LIBCXX_HERMETIC_STATIC_LIBRARY)
347 # _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS can be defined in __config_site
348 # too. Define it in the same way here, to avoid redefinition conflicts.
349 target_compile_definitions(cxx_experimental PRIVATE _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS=)
352 set_target_properties(cxx_experimental
354 COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
355 OUTPUT_NAME "c++experimental"
357 cxx_add_common_build_flags(cxx_experimental)
358 target_compile_options(cxx_experimental PUBLIC -D_LIBCPP_ENABLE_EXPERIMENTAL)
360 if (LIBCXX_INSTALL_SHARED_LIBRARY)
361 install(TARGETS cxx_shared
362 ARCHIVE DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx
363 LIBRARY DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx
364 RUNTIME DESTINATION ${LIBCXX_INSTALL_RUNTIME_DIR} COMPONENT cxx)
367 if (LIBCXX_INSTALL_STATIC_LIBRARY)
368 install(TARGETS cxx_static
369 ARCHIVE DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx
370 LIBRARY DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx
371 RUNTIME DESTINATION ${LIBCXX_INSTALL_RUNTIME_DIR} COMPONENT cxx)
374 if (LIBCXX_INSTALL_LIBRARY)
375 install(TARGETS cxx_experimental
376 LIBRARY DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx
377 ARCHIVE DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx
378 RUNTIME DESTINATION ${LIBCXX_INSTALL_RUNTIME_DIR} COMPONENT cxx)
381 # NOTE: This install command must go after the cxx install command otherwise
382 # it will not be executed after the library symlinks are installed.
383 if (LIBCXX_ENABLE_SHARED AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
384 install(FILES "$<TARGET_LINKER_FILE:cxx_shared>"
385 DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR}
389 if (NOT CMAKE_CONFIGURATION_TYPES)
390 if(LIBCXX_INSTALL_LIBRARY)
391 set(lib_install_target "cxx;cxx_experimental")
393 if(LIBCXX_INSTALL_HEADERS)
394 set(header_install_target install-cxx-headers)
396 if(LIBCXX_INSTALL_MODULES)
397 set(module_install_target install-cxx-modules)
399 add_custom_target(install-cxx
400 DEPENDS ${lib_install_target}
402 ${header_install_target}
403 ${module_install_target}
404 COMMAND "${CMAKE_COMMAND}"
405 -DCMAKE_INSTALL_COMPONENT=cxx
406 -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
407 add_custom_target(install-cxx-stripped
408 DEPENDS ${lib_install_target}
410 ${header_install_target}
411 ${module_install_target}
412 COMMAND "${CMAKE_COMMAND}"
413 -DCMAKE_INSTALL_COMPONENT=cxx
414 -DCMAKE_INSTALL_DO_STRIP=1
415 -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")