1 # See https://libcxx.llvm.org/docs/BuildingLibcxx.html for instructions on how
2 # to build libcxx with CMake.
4 #===============================================================================
6 #===============================================================================
7 cmake_minimum_required(VERSION 3.20.0)
9 set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
11 # Add path for custom modules
12 list(INSERT CMAKE_MODULE_PATH 0
13 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
14 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
15 "${CMAKE_CURRENT_SOURCE_DIR}/../runtimes/cmake/Modules"
16 "${LLVM_COMMON_CMAKE_UTILS}"
17 "${LLVM_COMMON_CMAKE_UTILS}/Modules"
20 set(CMAKE_FOLDER "libc++")
22 set(LIBCXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
23 set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
24 set(LIBCXX_BINARY_INCLUDE_DIR "${LIBCXX_BINARY_DIR}/include/c++build")
26 include(GNUInstallDirs)
29 # Require out of source build.
30 include(MacroEnsureOutOfSourceBuild)
31 MACRO_ENSURE_OUT_OF_SOURCE_BUILD(
32 "${PROJECT_NAME} requires an out of source build. Please create a separate
33 build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there."
35 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
36 message(STATUS "Configuring for clang-cl")
37 set(LIBCXX_TARGETING_CLANG_CL ON)
41 message(STATUS "Configuring for MSVC")
44 #===============================================================================
46 #===============================================================================
47 include(CMakeDependentOption)
48 include(HandleCompilerRT)
50 # Basic options ---------------------------------------------------------------
51 option(LIBCXX_ENABLE_ASSERTIONS
52 "Enable assertions inside the compiled library, and at the same time make it the
53 default when compiling user code. Note that assertions can be enabled or disabled
54 by users in their own code regardless of this option." OFF)
55 option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON)
56 option(LIBCXX_ENABLE_STATIC "Build libc++ as a static library." ON)
57 option(LIBCXX_ENABLE_FILESYSTEM
58 "Whether to include support for parts of the library that rely on a filesystem being
59 available on the platform. This includes things like most parts of <filesystem> and
60 others like <fstream>" ON)
61 option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS})
62 set(LIBCXX_SUPPORTED_HARDENING_MODES none fast extensive debug)
63 set(LIBCXX_HARDENING_MODE "none" CACHE STRING
64 "Specify the default hardening mode to use. This mode will be used inside the
65 compiled library and will be the default when compiling user code. Note that
66 users can override this setting in their own code. This does not affect the
67 ABI. Supported values are ${LIBCXX_SUPPORTED_HARDENING_MODES}.")
68 if (NOT "${LIBCXX_HARDENING_MODE}" IN_LIST LIBCXX_SUPPORTED_HARDENING_MODES)
70 "Unsupported hardening mode: '${LIBCXX_HARDENING_MODE}'. Supported values are ${LIBCXX_SUPPORTED_HARDENING_MODES}.")
72 set(LIBCXX_ASSERTION_HANDLER_FILE
73 "${CMAKE_CURRENT_SOURCE_DIR}/vendor/llvm/default_assertion_handler.in"
75 "Specify the path to a header that contains a custom implementation of the
76 assertion handler that gets invoked when a hardening assertion fails. If
77 provided, this header will be included by the library, replacing the
78 default assertion handler.")
79 option(LIBCXX_ENABLE_RANDOM_DEVICE
80 "Whether to include support for std::random_device in the library. Disabling
81 this can be useful when building the library for platforms that don't have
82 a source of randomness, such as some embedded platforms. When this is not
83 supported, most of <random> will still be available, but std::random_device
85 option(LIBCXX_ENABLE_LOCALIZATION
86 "Whether to include support for localization in the library. Disabling
87 localization can be useful when porting to platforms that don't support
88 the C locale API (e.g. embedded). When localization is not supported,
89 several parts of the library will be disabled: <iostream>, <regex>, <locale>
90 will be completely unusable, and other parts may be only partly available." ON)
91 option(LIBCXX_ENABLE_UNICODE
92 "Whether to include support for Unicode in the library. Disabling Unicode can
93 be useful when porting to platforms that don't support UTF-8 encoding (e.g.
95 option(LIBCXX_ENABLE_WIDE_CHARACTERS
96 "Whether to include support for wide characters in the library. Disabling
97 wide character support can be useful when porting to platforms that don't
98 support the C functionality for wide characters. When wide characters are
99 not supported, several parts of the library will be disabled, notably the
100 wide character specializations of std::basic_string." ON)
102 # To use time zone support in libc++ the platform needs to have the IANA
103 # database installed. Libc++ will fail to build if this is enabled on a
104 # platform that does not provide the IANA database. The default is set to the
105 # current implementation state on the different platforms.
107 # TODO TZDB make the default always ON when most platforms ship with the IANA
109 if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
110 set(ENABLE_TIME_ZONE_DATABASE_DEFAULT ON)
112 set(ENABLE_TIME_ZONE_DATABASE_DEFAULT OFF)
114 option(LIBCXX_ENABLE_TIME_ZONE_DATABASE
115 "Whether to include support for time zones in the library. Disabling
116 time zone support can be useful when porting to platforms that don't
117 ship the IANA time zone database. When time zones are not supported,
118 time zone support in <chrono> will be disabled." ${ENABLE_TIME_ZONE_DATABASE_DEFAULT})
119 option(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS
120 "Whether to turn on vendor availability annotations on declarations that depend
121 on definitions in a shared library. By default, we assume that we're not building
122 libc++ for any specific vendor, and we disable those annotations. Vendors wishing
123 to provide compile-time errors when using features unavailable on some version of
124 the shared library they shipped should turn this on and see `include/__availability`
125 for more details." OFF)
126 option(LIBCXX_ENABLE_CLANG_TIDY "Whether to compile and run clang-tidy checks" OFF)
128 if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
129 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-gcc.cfg.in")
131 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-mingw.cfg.in")
132 elseif(WIN32) # clang-cl
133 if (LIBCXX_ENABLE_SHARED)
134 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-clangcl.cfg.in")
136 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-static-clangcl.cfg.in")
139 if (LIBCXX_ENABLE_SHARED)
140 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared.cfg.in")
142 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-static.cfg.in")
145 set(LIBCXX_TEST_CONFIG "${LIBCXX_DEFAULT_TEST_CONFIG}" CACHE STRING
146 "The path to the Lit testing configuration to use when running the tests.
147 If a relative path is provided, it is assumed to be relative to '<monorepo>/libcxx/test/configs'.")
148 if (NOT IS_ABSOLUTE "${LIBCXX_TEST_CONFIG}")
149 set(LIBCXX_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/configs/${LIBCXX_TEST_CONFIG}")
151 message(STATUS "Using libc++ testing configuration: ${LIBCXX_TEST_CONFIG}")
152 set(LIBCXX_TEST_PARAMS "" CACHE STRING
153 "A list of parameters to run the Lit test suite with.")
155 # Benchmark options -----------------------------------------------------------
156 option(LIBCXX_INCLUDE_BENCHMARKS "Build the libc++ benchmarks and their dependencies" ON)
158 set(LIBCXX_BENCHMARK_TEST_ARGS_DEFAULT --benchmark_min_time=0.01)
159 set(LIBCXX_BENCHMARK_TEST_ARGS "${LIBCXX_BENCHMARK_TEST_ARGS_DEFAULT}" CACHE STRING
160 "Arguments to pass when running the benchmarks using check-cxx-benchmarks")
162 set(LIBCXX_BENCHMARK_NATIVE_STDLIB "" CACHE STRING
163 "Build the benchmarks against the specified native STL.
164 The value must be one of libc++/libstdc++")
165 set(LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN "" CACHE STRING
166 "Use alternate GCC toolchain when building the native benchmarks")
168 if (LIBCXX_BENCHMARK_NATIVE_STDLIB)
169 if (NOT (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libc++"
170 OR LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libstdc++"))
171 message(FATAL_ERROR "Invalid value for LIBCXX_BENCHMARK_NATIVE_STDLIB: "
172 "'${LIBCXX_BENCHMARK_NATIVE_STDLIB}'")
176 option(LIBCXX_INCLUDE_DOCS "Build the libc++ documentation." ${LLVM_INCLUDE_DOCS})
177 set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
178 "Define suffix of library directory name (32/64)")
179 option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON)
180 option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON)
181 option(LIBCXX_INSTALL_MODULES
182 "Install the libc++ C++20 module source files (experimental)." OFF
184 cmake_dependent_option(LIBCXX_INSTALL_STATIC_LIBRARY
185 "Install the static libc++ library." ON
186 "LIBCXX_ENABLE_STATIC;LIBCXX_INSTALL_LIBRARY" OFF)
187 cmake_dependent_option(LIBCXX_INSTALL_SHARED_LIBRARY
188 "Install the shared libc++ library." ON
189 "LIBCXX_ENABLE_SHARED;LIBCXX_INSTALL_LIBRARY" OFF)
191 option(LIBCXX_ABI_UNSTABLE "Use the unstable ABI of libc++. This is equivalent to specifying LIBCXX_ABI_VERSION=n, where n is the not-yet-stable version." OFF)
192 if (LIBCXX_ABI_UNSTABLE)
197 set(LIBCXX_ABI_VERSION "${abi_version}" CACHE STRING
198 "ABI version of libc++. Can be either 1 or 2, where 2 is currently the unstable ABI.
199 Defaults to 1 unless LIBCXX_ABI_UNSTABLE is specified, in which case this is 2.")
200 set(LIBCXX_LIBRARY_VERSION "${LIBCXX_ABI_VERSION}.0" CACHE STRING
201 "Version of libc++. This will be reflected in the name of the shared library produced.
202 For example, -DLIBCXX_LIBRARY_VERSION=x.y will result in the library being named
203 libc++.x.y.dylib, along with the usual symlinks pointing to that. On Apple platforms,
204 this also controls the linker's 'current_version' property.")
205 set(LIBCXX_ABI_NAMESPACE "__${LIBCXX_ABI_VERSION}" CACHE STRING "The inline ABI namespace used by libc++. It defaults to __n where `n` is the current ABI version.")
206 if (NOT LIBCXX_ABI_NAMESPACE MATCHES "__.*")
207 message(FATAL_ERROR "LIBCXX_ABI_NAMESPACE must be a reserved identifier, got '${LIBCXX_ABI_NAMESPACE}'.")
209 option(LIBCXX_ABI_FORCE_ITANIUM "Ignore auto-detection and force use of the Itanium ABI.")
210 option(LIBCXX_ABI_FORCE_MICROSOFT "Ignore auto-detection and force use of the Microsoft ABI.")
212 set(LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION "default" CACHE STRING
213 "Override the implementation to use for comparing typeinfos. By default, this
214 is detected automatically by the library, but this option allows overriding
215 which implementation is used unconditionally.
217 See the documentation in <libcxx/include/typeinfo> for details on what each
219 set(TYPEINFO_COMPARISON_VALUES "default;1;2;3")
220 if (NOT ("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" IN_LIST TYPEINFO_COMPARISON_VALUES))
221 message(FATAL_ERROR "Value '${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}' is not a valid value for
222 LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION")
225 set(LIBCXX_ABI_DEFINES "" CACHE STRING "A semicolon separated list of ABI macros to define in the site config header.")
226 set(LIBCXX_EXTRA_SITE_DEFINES "" CACHE STRING "Extra defines to add into __config_site")
227 option(LIBCXX_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
229 # ABI Library options ---------------------------------------------------------
231 set(LIBCXX_DEFAULT_ABI_LIBRARY "vcruntime")
232 elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
233 set(LIBCXX_DEFAULT_ABI_LIBRARY "libcxxrt")
235 set(LIBCXX_DEFAULT_ABI_LIBRARY "libcxxabi")
238 set(LIBCXX_SUPPORTED_ABI_LIBRARIES none libcxxabi system-libcxxabi libcxxrt libstdc++ libsupc++ vcruntime)
239 set(LIBCXX_CXX_ABI "${LIBCXX_DEFAULT_ABI_LIBRARY}" CACHE STRING "Specify C++ ABI library to use. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}.")
240 if (NOT "${LIBCXX_CXX_ABI}" IN_LIST LIBCXX_SUPPORTED_ABI_LIBRARIES)
241 message(FATAL_ERROR "Unsupported C++ ABI library: '${LIBCXX_CXX_ABI}'. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}.")
244 option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY
245 "Use a static copy of the ABI library when linking libc++.
246 This option cannot be used with LIBCXX_ENABLE_ABI_LINKER_SCRIPT." OFF)
248 option(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY
249 "Statically link the ABI library to static library"
250 ${LIBCXX_ENABLE_STATIC_ABI_LIBRARY})
252 option(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY
253 "Statically link the ABI library to shared library"
254 ${LIBCXX_ENABLE_STATIC_ABI_LIBRARY})
256 # Generate and install a linker script inplace of libc++.so. The linker script
257 # will link libc++ to the correct ABI library. This option is on by default
258 # on UNIX platforms other than Apple, and on the Fuchsia platform unless we
259 # statically link libc++abi inside libc++.so, we don't build libc++.so at all
260 # or we don't have any ABI library.
261 if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY
262 OR NOT LIBCXX_ENABLE_SHARED
263 OR LIBCXX_CXX_ABI STREQUAL "none")
264 set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF)
265 elseif((UNIX OR FUCHSIA) AND NOT APPLE)
266 set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE ON)
268 set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF)
270 option(LIBCXX_ENABLE_ABI_LINKER_SCRIPT
271 "Use and install a linker script for the given ABI library"
272 ${ENABLE_LINKER_SCRIPT_DEFAULT_VALUE})
274 option(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS
275 "Build libc++ with definitions for operator new/delete. These are normally
276 defined in libc++abi, but this option can be used to define them in libc++
277 instead. If you define them in libc++, make sure they are NOT defined in
278 libc++abi. Doing otherwise is an ODR violation." OFF)
279 # Build libc++abi with libunwind. We need this option to determine whether to
280 # link with libunwind or libgcc_s while running the test cases.
281 option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." ON)
283 # Target options --------------------------------------------------------------
284 option(LIBCXX_BUILD_32_BITS "Build 32 bit multilib libc++. This option is not supported anymore when building the runtimes. Please specify a full triple instead." ${LLVM_BUILD_32_BITS})
285 if (LIBCXX_BUILD_32_BITS)
286 message(FATAL_ERROR "LIBCXX_BUILD_32_BITS is not supported anymore when building the runtimes, please specify a full triple instead.")
289 # Feature options -------------------------------------------------------------
290 option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON)
291 option(LIBCXX_ENABLE_RTTI
292 "Use runtime type information.
293 This option may only be set to OFF when LIBCXX_ENABLE_EXCEPTIONS=OFF." ON)
294 option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON)
295 option(LIBCXX_ENABLE_MONOTONIC_CLOCK
296 "Build libc++ with support for a monotonic clock.
297 This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON)
298 option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF)
299 option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF)
300 option(LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32 thread API" OFF)
301 option(LIBCXX_HAS_EXTERNAL_THREAD_API
302 "Build libc++ with an externalized threading API.
303 This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF)
305 if (LIBCXX_ENABLE_THREADS)
306 set(LIBCXX_PSTL_CPU_BACKEND "std_thread" CACHE STRING "Which PSTL CPU backend to use")
308 set(LIBCXX_PSTL_CPU_BACKEND "serial" CACHE STRING "Which PSTL CPU backend to use")
311 # Misc options ----------------------------------------------------------------
312 # FIXME: Turn -pedantic back ON. It is currently off because it warns
313 # about #include_next which is used everywhere.
314 option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF)
315 option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
317 option(LIBCXX_GENERATE_COVERAGE "Enable generating code coverage." OFF)
318 set(LIBCXX_COVERAGE_LIBRARY "" CACHE STRING
319 "The Profile-rt library used to build with code coverage")
321 set(LIBCXX_CONFIGURE_IDE_DEFAULT OFF)
322 if (XCODE OR MSVC_IDE)
323 set(LIBCXX_CONFIGURE_IDE_DEFAULT ON)
325 option(LIBCXX_CONFIGURE_IDE "Configure libcxx for use within an IDE"
326 ${LIBCXX_CONFIGURE_IDE_DEFAULT})
328 set(LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT OFF)
330 set(LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT ON)
332 option(LIBCXX_HERMETIC_STATIC_LIBRARY
333 "Do not export any symbols from the static library." ${LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT})
335 #===============================================================================
336 # Check option configurations
337 #===============================================================================
339 # Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON only when
340 # LIBCXX_ENABLE_THREADS is on.
341 if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_ENABLE_MONOTONIC_CLOCK)
342 message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF"
343 " when LIBCXX_ENABLE_THREADS is also set to OFF.")
346 if(NOT LIBCXX_ENABLE_THREADS)
347 if(LIBCXX_HAS_PTHREAD_API)
348 message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON"
349 " when LIBCXX_ENABLE_THREADS is also set to ON.")
351 if(LIBCXX_HAS_EXTERNAL_THREAD_API)
352 message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set to ON"
353 " when LIBCXX_ENABLE_THREADS is also set to ON.")
355 if (LIBCXX_HAS_WIN32_THREAD_API)
356 message(FATAL_ERROR "LIBCXX_HAS_WIN32_THREAD_API can only be set to ON"
357 " when LIBCXX_ENABLE_THREADS is also set to ON.")
362 if (LIBCXX_HAS_EXTERNAL_THREAD_API)
363 if (LIBCXX_HAS_PTHREAD_API)
364 message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
365 " and LIBCXX_HAS_PTHREAD_API cannot be both"
366 " set to ON at the same time.")
368 if (LIBCXX_HAS_WIN32_THREAD_API)
369 message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
370 " and LIBCXX_HAS_WIN32_THREAD_API cannot be both"
371 " set to ON at the same time.")
375 if (LIBCXX_HAS_PTHREAD_API)
376 if (LIBCXX_HAS_WIN32_THREAD_API)
377 message(FATAL_ERROR "The options LIBCXX_HAS_PTHREAD_API"
378 " and LIBCXX_HAS_WIN32_THREAD_API cannot be both"
379 " set to ON at the same time.")
383 if (NOT LIBCXX_ENABLE_RTTI AND LIBCXX_ENABLE_EXCEPTIONS)
384 message(FATAL_ERROR "Libc++ cannot be built with exceptions enabled but RTTI"
385 " disabled, since that configuration is broken. See"
386 " https://github.com/llvm/llvm-project/issues/66117"
390 # Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE
392 if (LLVM_USE_SANITIZER AND LIBCXX_GENERATE_COVERAGE)
393 message(FATAL_ERROR "LLVM_USE_SANITIZER cannot be used with LIBCXX_GENERATE_COVERAGE")
396 if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
398 message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT cannot be used on APPLE targets")
400 if (NOT LIBCXX_ENABLE_SHARED)
401 message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT is only available for shared library builds.")
405 if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
406 message(FATAL_ERROR "Conflicting options given.
407 LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY cannot be specified with
408 LIBCXX_ENABLE_ABI_LINKER_SCRIPT")
411 if (LIBCXX_ABI_FORCE_ITANIUM AND LIBCXX_ABI_FORCE_MICROSOFT)
412 message(FATAL_ERROR "Only one of LIBCXX_ABI_FORCE_ITANIUM and LIBCXX_ABI_FORCE_MICROSOFT can be specified.")
415 if (LIBCXX_ENABLE_SHARED AND CMAKE_MSVC_RUNTIME_LIBRARY AND
416 (NOT CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL$"))
417 message(WARNING "A static CRT linked into a shared libc++ doesn't work correctly.")
420 #===============================================================================
422 #===============================================================================
424 # TODO: Projects that depend on libc++ should use LIBCXX_GENERATED_INCLUDE_DIR
425 # instead of hard-coding include/c++/v1.
427 set(LIBCXX_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/c++/v1" CACHE STRING
428 "Path where target-agnostic libc++ headers should be installed.")
429 set(LIBCXX_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING
430 "Path where built libc++ runtime libraries should be installed.")
431 set(LIBCXX_INSTALL_MODULES_DIR "share/libc++/v1" CACHE STRING
432 "Path where target-agnostic libc++ module source files should be installed.")
434 set(LIBCXX_SHARED_OUTPUT_NAME "c++" CACHE STRING "Output name for the shared libc++ runtime library.")
435 set(LIBCXX_STATIC_OUTPUT_NAME "c++" CACHE STRING "Output name for the static libc++ runtime library.")
437 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
438 set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
439 set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
440 set(LIBCXX_GENERATED_MODULE_DIR "${LLVM_BINARY_DIR}/modules/c++/v1")
441 set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1")
442 set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE STRING
443 "Path where built libc++ libraries should be installed.")
444 set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1" CACHE STRING
445 "Path where target-specific libc++ headers should be installed.")
446 if(LIBCXX_LIBDIR_SUBDIR)
447 string(APPEND LIBCXX_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR})
448 string(APPEND LIBCXX_INSTALL_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR})
451 if(LLVM_LIBRARY_OUTPUT_INTDIR)
452 set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
453 set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
454 set(LIBCXX_GENERATED_MODULE_DIR "${LLVM_BINARY_DIR}/modules/c++/v1")
456 set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
457 set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1")
458 set(LIBCXX_GENERATED_MODULE_DIR "${CMAKE_BINARY_DIR}/modules/c++/v1")
460 set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}")
461 set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX} CACHE STRING
462 "Path where built libc++ libraries should be installed.")
463 set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${LIBCXX_INSTALL_INCLUDE_DIR}" CACHE STRING
464 "Path where target-specific libc++ headers should be installed.")
467 file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}")
469 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
470 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
471 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
473 # Declare libc++ configuration variables.
474 # They are intended for use as follows:
475 # LIBCXX_CXX_FLAGS: General flags for both the compiler and linker.
476 # LIBCXX_COMPILE_FLAGS: Compile only flags.
477 # LIBCXX_LINK_FLAGS: Linker only flags.
478 # LIBCXX_LIBRARIES: libraries libc++ is linked to.
479 set(LIBCXX_COMPILE_FLAGS "")
480 set(LIBCXX_LINK_FLAGS "")
481 set(LIBCXX_LIBRARIES "")
482 set(LIBCXX_ADDITIONAL_COMPILE_FLAGS "" CACHE STRING
483 "Additional Compile only flags which can be provided in cache")
484 set(LIBCXX_ADDITIONAL_LIBRARIES "" CACHE STRING
485 "Additional libraries libc++ is linked to which can be provided in cache")
487 # Include macros for adding and removing libc++ flags.
488 include(HandleLibcxxFlags)
490 # Target flags ================================================================
491 # These flags get added to CMAKE_CXX_FLAGS and CMAKE_C_FLAGS so that
492 # 'config-ix' use them during feature checks. It also adds them to both
493 # 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS'
495 if (${CMAKE_SYSTEM_NAME} MATCHES "AIX")
496 add_flags_if_supported("-mdefault-visibility-export-mapping=explicit")
497 set(CMAKE_AIX_EXPORT_ALL_SYMBOLS OFF)
500 # Configure compiler.
503 # Configure coverage options.
504 if (LIBCXX_GENERATE_COVERAGE)
505 include(CodeCoverage)
506 set(CMAKE_BUILD_TYPE "COVERAGE" CACHE STRING "" FORCE)
509 #===============================================================================
510 # Setup Compiler Flags
511 #===============================================================================
513 include(HandleLibCXXABI) # Setup the ABI library flags
515 # FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC.
516 # Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors
517 # so they don't get transformed into -Wno and -errors respectively.
518 remove_flags(-Wno-pedantic -pedantic-errors -pedantic)
520 # Required flags ==============================================================
521 function(cxx_add_basic_build_flags target)
523 # Use C++23 for all targets.
524 set_target_properties(${target} PROPERTIES
526 CXX_STANDARD_REQUIRED OFF # TODO: Make this REQUIRED once we don't need to accommodate the LLVM documentation builders using an ancient CMake
529 # When building the dylib, don't warn for unavailable aligned allocation
530 # functions based on the deployment target -- they are always available
531 # because they are provided by the dylib itself with the exception of z/OS.
533 target_add_compile_flags_if_supported(${target} PRIVATE -fno-aligned-allocation)
535 target_add_compile_flags_if_supported(${target} PRIVATE -faligned-allocation)
538 # On all systems the system c++ standard library headers need to be excluded.
539 # MSVC only has -X, which disables all default includes; including the crt.
540 # Thus, we do nothing and hope we don't accidentally include any of the C++
542 target_add_compile_flags_if_supported(${target} PUBLIC -nostdinc++)
544 # Hide all inline function definitions which have not explicitly been marked
545 # visible. This prevents new definitions for inline functions from appearing in
546 # the dylib when get ODR used by another function.
547 target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility-inlines-hidden)
549 # Our visibility annotations are not quite right for non-Clang compilers,
550 # so we end up not exporting all the symbols we should. In the future, we
551 # can improve the situation by providing an explicit list of exported
552 # symbols on all compilers.
553 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
554 target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility=hidden)
557 # Let the library headers know they are currently being used to build the
559 target_compile_definitions(${target} PRIVATE -D_LIBCPP_BUILDING_LIBRARY)
561 # Make sure the library can be build without transitive includes. This makes
562 # it easier to upgrade the library to a newer language standard without build
564 target_compile_definitions(${target} PRIVATE -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
566 if (C_SUPPORTS_COMMENT_LIB_PRAGMA)
567 if (LIBCXX_HAS_PTHREAD_LIB)
568 target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_PTHREAD_LIB)
570 if (LIBCXX_HAS_RT_LIB)
571 target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_RT_LIB)
574 target_compile_options(${target} PUBLIC "${LIBCXX_ADDITIONAL_COMPILE_FLAGS}")
577 # Exception flags =============================================================
578 function(cxx_add_exception_flags target)
579 if (LIBCXX_ENABLE_EXCEPTIONS)
580 # Catches C++ exceptions only and tells the compiler to assume that extern C
581 # functions never throw a C++ exception.
582 target_add_compile_flags_if_supported(${target} PUBLIC -EHsc)
584 target_add_compile_flags_if_supported(${target} PUBLIC -EHs- -EHa-)
585 target_add_compile_flags_if_supported(${target} PUBLIC -fno-exceptions)
589 # RTTI flags ==================================================================
590 function(cxx_add_rtti_flags target)
591 if (NOT LIBCXX_ENABLE_RTTI)
593 target_add_compile_flags_if_supported(${target} PUBLIC -GR-)
595 target_add_compile_flags_if_supported(${target} PUBLIC -fno-rtti)
600 # Modules flags ===============================================================
601 # FIXME The libc++ sources are fundamentally non-modular. They need special
602 # versions of the headers in order to provide C++03 and legacy ABI definitions.
603 # NOTE: The public headers can be used with modules in all other contexts.
604 function(cxx_add_module_flags target)
605 if (LLVM_ENABLE_MODULES)
606 # Ignore that the rest of the modules flags are now unused.
607 target_add_compile_flags_if_supported(${target} PUBLIC -Wno-unused-command-line-argument)
608 target_compile_options(${target} PUBLIC -fno-modules)
612 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
614 # Sanitizer flags =============================================================
616 function(get_sanitizer_flags OUT_VAR USE_SANITIZER)
618 set(USE_SANITIZER "${USE_SANITIZER}")
619 # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC.
620 # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do.
621 if (USE_SANITIZER AND NOT MSVC)
622 append_flags_if_supported(SANITIZER_FLAGS "-fno-omit-frame-pointer")
623 append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only")
625 if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND
626 NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
627 append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only")
629 if (USE_SANITIZER STREQUAL "Address")
630 append_flags(SANITIZER_FLAGS "-fsanitize=address")
631 elseif (USE_SANITIZER STREQUAL "HWAddress")
632 append_flags(SANITIZER_FLAGS "-fsanitize=hwaddress")
633 elseif (USE_SANITIZER MATCHES "Memory(WithOrigins)?")
634 append_flags(SANITIZER_FLAGS -fsanitize=memory)
635 if (USE_SANITIZER STREQUAL "MemoryWithOrigins")
636 append_flags(SANITIZER_FLAGS "-fsanitize-memory-track-origins")
638 elseif (USE_SANITIZER STREQUAL "Undefined")
639 append_flags(SANITIZER_FLAGS "-fsanitize=undefined" "-fno-sanitize=vptr,function" "-fno-sanitize-recover=all")
640 elseif (USE_SANITIZER STREQUAL "Address;Undefined" OR
641 USE_SANITIZER STREQUAL "Undefined;Address")
642 append_flags(SANITIZER_FLAGS "-fsanitize=address,undefined" "-fno-sanitize=vptr,function" "-fno-sanitize-recover=all")
643 elseif (USE_SANITIZER STREQUAL "Thread")
644 append_flags(SANITIZER_FLAGS -fsanitize=thread)
645 elseif (USE_SANITIZER STREQUAL "DataFlow")
646 append_flags(SANITIZER_FLAGS -fsanitize=dataflow)
648 message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${USE_SANITIZER}")
650 elseif(USE_SANITIZER AND MSVC)
651 message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.")
653 set(${OUT_VAR} "${SANITIZER_FLAGS}" PARENT_SCOPE)
656 get_sanitizer_flags(SANITIZER_FLAGS "${LLVM_USE_SANITIZER}")
657 add_library(cxx-sanitizer-flags INTERFACE)
658 target_compile_options(cxx-sanitizer-flags INTERFACE ${SANITIZER_FLAGS})
660 # _LIBCPP_INSTRUMENTED_WITH_ASAN informs that library was built with ASan.
661 # Defining _LIBCPP_INSTRUMENTED_WITH_ASAN while building the library with ASan is required.
662 # Normally, the _LIBCPP_INSTRUMENTED_WITH_ASAN flag is used to keep information whether
663 # dylibs are built with AddressSanitizer. However, when building libc++,
664 # this flag needs to be defined so that the resulting dylib has all ASan functionalities guarded by this flag.
665 # If the _LIBCPP_INSTRUMENTED_WITH_ASAN flag is not defined, then parts of the ASan instrumentation code in libc++
666 # will not be compiled into it, resulting in false positives.
667 # For context, read: https://github.com/llvm/llvm-project/pull/72677#pullrequestreview-1765402800
668 string(FIND "${LLVM_USE_SANITIZER}" "Address" building_with_asan)
669 if (NOT "${building_with_asan}" STREQUAL "-1")
670 config_define(ON _LIBCPP_INSTRUMENTED_WITH_ASAN)
673 # Link system libraries =======================================================
674 function(cxx_link_system_libraries target)
676 target_link_libraries(${target} PRIVATE "-nostdlib++")
679 if (CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG AND LIBCXXABI_USE_LLVM_UNWINDER)
680 # If we're linking directly against the libunwind that we're building
681 # in the same invocation, don't try to link in the toolchain's
682 # default libunwind (which may be missing still).
683 target_add_link_flags_if_supported(${target} PRIVATE "--unwindlib=none")
687 if (LIBCXX_USE_COMPILER_RT)
688 find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY)
689 if (LIBCXX_BUILTINS_LIBRARY)
690 target_link_libraries(${target} PRIVATE "${LIBCXX_BUILTINS_LIBRARY}")
692 elseif (LIBCXX_HAS_GCC_LIB)
693 target_link_libraries(${target} PRIVATE gcc)
694 elseif (LIBCXX_HAS_GCC_S_LIB)
695 target_link_libraries(${target} PRIVATE gcc_s)
699 if (LIBCXX_HAS_ATOMIC_LIB)
700 target_link_libraries(${target} PRIVATE atomic)
704 target_link_libraries(${target} PRIVATE "${MINGW_LIBRARIES}")
708 if ((NOT CMAKE_MSVC_RUNTIME_LIBRARY AND uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
709 OR (CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "Debug"))
715 if (NOT CMAKE_MSVC_RUNTIME_LIBRARY OR CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL$")
716 set(CRT_LIB "msvcrt")
717 set(CXX_LIB "msvcprt")
719 set(CRT_LIB "libcmt")
720 set(CXX_LIB "libcpmt")
723 target_link_libraries(${target} PRIVATE ${CRT_LIB}${LIB_SUFFIX}) # C runtime startup files
724 target_link_libraries(${target} PRIVATE ${CXX_LIB}${LIB_SUFFIX}) # C++ standard library. Required for exception_ptr internals.
725 # Required for standards-complaint wide character formatting functions
726 # (e.g. `printfw`/`scanfw`)
727 target_link_libraries(${target} PRIVATE iso_stdio_wide_specifiers)
730 if (ANDROID AND ANDROID_PLATFORM_LEVEL LESS 21)
731 target_link_libraries(${target} PUBLIC android_support)
733 target_link_libraries(${target} PUBLIC "${LIBCXX_ADDITIONAL_LIBRARIES}")
736 # Windows-related flags =======================================================
737 function(cxx_add_windows_flags target)
738 if(WIN32 AND NOT MINGW)
739 target_compile_definitions(${target} PRIVATE
740 # Ignore the -MSC_VER mismatch, as we may build
741 # with a different compatibility version.
742 _ALLOW_MSC_VER_MISMATCH
743 # Don't check the msvcprt iterator debug levels
744 # as we will define the iterator types; libc++
745 # uses a different macro to identify the debug
747 _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH
748 # We are building the c++ runtime, don't pull in
751 # Don't warn on the use of "deprecated"
752 # "insecure" functions which are standards
754 _CRT_SECURE_NO_WARNINGS
755 # Use the ISO conforming behaviour for conversion
757 _CRT_STDIO_ISO_WIDE_SPECIFIERS)
761 # Configuration file flags =====================================================
762 config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION)
763 config_define(${LIBCXX_ABI_NAMESPACE} _LIBCPP_ABI_NAMESPACE)
764 config_define_if(LIBCXX_ABI_FORCE_ITANIUM _LIBCPP_ABI_FORCE_ITANIUM)
765 config_define_if(LIBCXX_ABI_FORCE_MICROSOFT _LIBCPP_ABI_FORCE_MICROSOFT)
766 config_define_if_not(LIBCXX_ENABLE_THREADS _LIBCPP_HAS_NO_THREADS)
767 config_define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK _LIBCPP_HAS_NO_MONOTONIC_CLOCK)
768 if (NOT LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION STREQUAL "default")
769 config_define("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION)
771 config_define_if(LIBCXX_HAS_PTHREAD_API _LIBCPP_HAS_THREAD_API_PTHREAD)
772 config_define_if(LIBCXX_HAS_EXTERNAL_THREAD_API _LIBCPP_HAS_THREAD_API_EXTERNAL)
773 config_define_if(LIBCXX_HAS_WIN32_THREAD_API _LIBCPP_HAS_THREAD_API_WIN32)
774 config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC)
775 config_define_if(LIBCXX_NO_VCRUNTIME _LIBCPP_NO_VCRUNTIME)
776 config_define_if_not(LIBCXX_ENABLE_FILESYSTEM _LIBCPP_HAS_NO_FILESYSTEM)
777 config_define_if_not(LIBCXX_ENABLE_RANDOM_DEVICE _LIBCPP_HAS_NO_RANDOM_DEVICE)
778 config_define_if_not(LIBCXX_ENABLE_LOCALIZATION _LIBCPP_HAS_NO_LOCALIZATION)
779 config_define_if_not(LIBCXX_ENABLE_UNICODE _LIBCPP_HAS_NO_UNICODE)
780 config_define_if_not(LIBCXX_ENABLE_WIDE_CHARACTERS _LIBCPP_HAS_NO_WIDE_CHARACTERS)
781 config_define_if_not(LIBCXX_ENABLE_TIME_ZONE_DATABASE _LIBCPP_HAS_NO_TIME_ZONE_DATABASE)
782 config_define_if_not(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)
784 # TODO(LLVM 19): Produce a deprecation warning.
785 if (LIBCXX_ENABLE_ASSERTIONS)
786 set(LIBCXX_HARDENING_MODE "extensive")
788 if (LIBCXX_HARDENING_MODE STREQUAL "none")
789 config_define(2 _LIBCPP_HARDENING_MODE_DEFAULT)
790 elseif (LIBCXX_HARDENING_MODE STREQUAL "fast")
791 config_define(4 _LIBCPP_HARDENING_MODE_DEFAULT)
792 elseif (LIBCXX_HARDENING_MODE STREQUAL "extensive")
793 config_define(16 _LIBCPP_HARDENING_MODE_DEFAULT)
794 elseif (LIBCXX_HARDENING_MODE STREQUAL "debug")
795 config_define(8 _LIBCPP_HARDENING_MODE_DEFAULT)
798 if (LIBCXX_PSTL_CPU_BACKEND STREQUAL "serial")
799 config_define(1 _LIBCPP_PSTL_CPU_BACKEND_SERIAL)
800 elseif(LIBCXX_PSTL_CPU_BACKEND STREQUAL "std_thread")
801 config_define(1 _LIBCPP_PSTL_CPU_BACKEND_THREAD)
802 elseif(LIBCXX_PSTL_CPU_BACKEND STREQUAL "libdispatch")
803 config_define(1 _LIBCPP_PSTL_CPU_BACKEND_LIBDISPATCH)
805 message(FATAL_ERROR "LIBCXX_PSTL_CPU_BACKEND is set to ${LIBCXX_PSTL_CPU_BACKEND}, which is not a valid backend.
806 Valid backends are: serial, std_thread and libdispatch")
809 if (LIBCXX_ABI_DEFINES)
811 foreach (abi_define ${LIBCXX_ABI_DEFINES})
812 if (NOT abi_define MATCHES "^_LIBCPP_ABI_")
813 message(SEND_ERROR "Invalid ABI macro ${abi_define} in LIBCXX_ABI_DEFINES")
815 list(APPEND abi_defines "#define ${abi_define}")
817 string(REPLACE ";" "\n" abi_defines "${abi_defines}")
818 config_define(${abi_defines} _LIBCPP_ABI_DEFINES)
821 if (LIBCXX_EXTRA_SITE_DEFINES)
822 set(extra_site_defines)
823 foreach (extra_site_define ${LIBCXX_EXTRA_SITE_DEFINES})
824 # Allow defines such as DEFINE=VAL, transformed into "#define DEFINE VAL".
825 string(REPLACE "=" " " extra_site_define "${extra_site_define}")
826 list(APPEND extra_site_defines "#define ${extra_site_define}")
828 string(REPLACE ";" "\n" extra_site_defines "${extra_site_defines}")
829 config_define(${extra_site_defines} _LIBCPP_EXTRA_SITE_DEFINES)
832 # By default libc++ on Windows expects to use a shared library, which requires
833 # the headers to use DLL import/export semantics. However when building a
834 # static library only we modify the headers to disable DLL import/export.
835 if (DEFINED WIN32 AND LIBCXX_ENABLE_STATIC AND NOT LIBCXX_ENABLE_SHARED)
836 message(STATUS "Generating custom __config for non-DLL Windows build")
837 config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
840 if (WIN32 AND LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
841 # If linking libcxxabi statically into libcxx, skip the dllimport attributes
842 # on symbols we refer to from libcxxabi.
843 add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS)
846 # Setup all common build flags =================================================
847 function(cxx_add_common_build_flags target)
848 cxx_add_basic_build_flags(${target})
849 cxx_add_warning_flags(${target} ${LIBCXX_ENABLE_WERROR} ${LIBCXX_ENABLE_PEDANTIC})
850 cxx_add_windows_flags(${target})
851 cxx_add_exception_flags(${target})
852 cxx_add_rtti_flags(${target})
853 cxx_add_module_flags(${target})
854 cxx_link_system_libraries(${target})
855 target_link_libraries(${target} PRIVATE cxx-sanitizer-flags)
858 #===============================================================================
859 # Setup Source Code And Tests
860 #===============================================================================
861 add_subdirectory(include)
862 add_subdirectory(src)
863 add_subdirectory(utils)
864 add_subdirectory(modules)
866 set(LIBCXX_TEST_DEPS "cxx_experimental")
868 if (LIBCXX_ENABLE_CLANG_TIDY)
869 list(APPEND LIBCXX_TEST_DEPS cxx-tidy)
872 list(APPEND LIBCXX_TEST_DEPS generate-cxx-modules)
874 if (LIBCXX_INCLUDE_BENCHMARKS)
875 add_subdirectory(benchmarks)
878 if (LIBCXX_INCLUDE_TESTS)
879 add_subdirectory(test)
880 add_subdirectory(lib/abi)
883 if (LIBCXX_INCLUDE_DOCS)
884 add_subdirectory(docs)