Debian Codegraph @

libcxx/src/CMakeLists.txt

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