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)
8 set(LLVM_SUBPROJECT_TITLE "libc++")
10 set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
12 # Add path for custom modules
13 list(INSERT CMAKE_MODULE_PATH 0
14 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
15 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
16 "${CMAKE_CURRENT_SOURCE_DIR}/../runtimes/cmake/Modules"
17 "${LLVM_COMMON_CMAKE_UTILS}"
18 "${LLVM_COMMON_CMAKE_UTILS}/Modules"
21 set(CMAKE_FOLDER "libc++")
23 set(LIBCXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
24 set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
25 set(LIBCXX_BINARY_INCLUDE_DIR "${LIBCXX_BINARY_DIR}/include/c++build")
27 include(GNUInstallDirs)
30 # Require out of source build.
31 include(MacroEnsureOutOfSourceBuild)
32 MACRO_ENSURE_OUT_OF_SOURCE_BUILD(
33 "${PROJECT_NAME} requires an out of source build. Please create a separate
34 build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there."
36 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
37 message(STATUS "Configuring for clang-cl")
38 set(LIBCXX_TARGETING_CLANG_CL ON)
42 message(STATUS "Configuring for MSVC")
45 #===============================================================================
47 #===============================================================================
48 include(CMakeDependentOption)
49 include(HandleCompilerRT)
51 # Basic options ---------------------------------------------------------------
52 option(LIBCXX_ENABLE_ASSERTIONS
53 "Enable assertions inside the compiled library, and at the same time make it the
54 default when compiling user code. Note that assertions can be enabled or disabled
55 by users in their own code regardless of this option." OFF)
56 option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON)
57 option(LIBCXX_ENABLE_STATIC "Build libc++ as a static library." ON)
58 option(LIBCXX_ENABLE_FILESYSTEM
59 "Whether to include support for parts of the library that rely on a filesystem being
60 available on the platform. This includes things like most parts of <filesystem> and
61 others like <fstream>" ON)
62 option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS})
63 set(LIBCXX_SUPPORTED_HARDENING_MODES none fast extensive debug)
64 set(LIBCXX_HARDENING_MODE "none" CACHE STRING
65 "Specify the default hardening mode to use. This mode will be used inside the
66 compiled library and will be the default when compiling user code. Note that
67 users can override this setting in their own code. This does not affect the
68 ABI. Supported values are ${LIBCXX_SUPPORTED_HARDENING_MODES}.")
69 if (NOT "${LIBCXX_HARDENING_MODE}" IN_LIST LIBCXX_SUPPORTED_HARDENING_MODES)
71 "Unsupported hardening mode: '${LIBCXX_HARDENING_MODE}'. Supported values are ${LIBCXX_SUPPORTED_HARDENING_MODES}.")
73 set(LIBCXX_ASSERTION_HANDLER_FILE
74 "vendor/llvm/default_assertion_handler.in"
76 "Specify the path to a header that contains a custom implementation of the
77 assertion handler that gets invoked when a hardening assertion fails. If
78 provided, this header will be included by the library, replacing the
79 default assertion handler. If this is specified as a relative path, it
80 is assumed to be relative to '<monorepo>/libcxx'.")
81 if (NOT IS_ABSOLUTE "${LIBCXX_ASSERTION_HANDLER_FILE}")
82 set(LIBCXX_ASSERTION_HANDLER_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${LIBCXX_ASSERTION_HANDLER_FILE}")
84 option(LIBCXX_ENABLE_RANDOM_DEVICE
85 "Whether to include support for std::random_device in the library. Disabling
86 this can be useful when building the library for platforms that don't have
87 a source of randomness, such as some embedded platforms. When this is not
88 supported, most of <random> will still be available, but std::random_device
90 option(LIBCXX_ENABLE_LOCALIZATION
91 "Whether to include support for localization in the library. Disabling
92 localization can be useful when porting to platforms that don't support
93 the C locale API (e.g. embedded). When localization is not supported,
94 several parts of the library will be disabled: <iostream>, <regex>, <locale>
95 will be completely unusable, and other parts may be only partly available." ON)
96 option(LIBCXX_ENABLE_UNICODE
97 "Whether to include support for Unicode in the library. Disabling Unicode can
98 be useful when porting to platforms that don't support UTF-8 encoding (e.g.
100 option(LIBCXX_ENABLE_WIDE_CHARACTERS
101 "Whether to include support for wide characters in the library. Disabling
102 wide character support can be useful when porting to platforms that don't
103 support the C functionality for wide characters. When wide characters are
104 not supported, several parts of the library will be disabled, notably the
105 wide character specializations of std::basic_string." ON)
107 # To use time zone support in libc++ the platform needs to have the IANA
108 # database installed. Libc++ will fail to build if this is enabled on a
109 # platform that does not provide the IANA database. The default is set to the
110 # current implementation state on the different platforms.
112 # TODO TZDB make the default always ON when most platforms ship with the IANA
114 if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
115 set(ENABLE_TIME_ZONE_DATABASE_DEFAULT ON)
117 set(ENABLE_TIME_ZONE_DATABASE_DEFAULT OFF)
119 option(LIBCXX_ENABLE_TIME_ZONE_DATABASE
120 "Whether to include support for time zones in the library. Disabling
121 time zone support can be useful when porting to platforms that don't
122 ship the IANA time zone database. When time zones are not supported,
123 time zone support in <chrono> will be disabled." ${ENABLE_TIME_ZONE_DATABASE_DEFAULT})
124 option(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS
125 "Whether to turn on vendor availability annotations on declarations that depend
126 on definitions in a shared library. By default, we assume that we're not building
127 libc++ for any specific vendor, and we disable those annotations. Vendors wishing
128 to provide compile-time errors when using features unavailable on some version of
129 the shared library they shipped should turn this on and see `include/__configuration/availability.h`
130 for more details." OFF)
132 if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
133 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-gcc.cfg.in")
135 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-mingw.cfg.in")
136 elseif(WIN32) # clang-cl
137 if (LIBCXX_ENABLE_SHARED)
138 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-clangcl.cfg.in")
140 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-static-clangcl.cfg.in")
143 if (LIBCXX_ENABLE_SHARED)
144 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared.cfg.in")
146 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-static.cfg.in")
149 set(LIBCXX_TEST_CONFIG "${LIBCXX_DEFAULT_TEST_CONFIG}" CACHE STRING
150 "The path to the Lit testing configuration to use when running the tests.
151 If a relative path is provided, it is assumed to be relative to '<monorepo>/libcxx/test/configs'.")
152 if (NOT IS_ABSOLUTE "${LIBCXX_TEST_CONFIG}")
153 set(LIBCXX_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/configs/${LIBCXX_TEST_CONFIG}")
155 message(STATUS "Using libc++ testing configuration: ${LIBCXX_TEST_CONFIG}")
156 set(LIBCXX_TEST_PARAMS "" CACHE STRING
157 "A list of parameters to run the Lit test suite with.")
159 # Benchmark options -----------------------------------------------------------
160 option(LIBCXX_INCLUDE_BENCHMARKS "Build the libc++ benchmarks and their dependencies" ON)
162 set(LIBCXX_BENCHMARK_TEST_ARGS_DEFAULT --benchmark_min_time=0.01)
163 set(LIBCXX_BENCHMARK_TEST_ARGS "${LIBCXX_BENCHMARK_TEST_ARGS_DEFAULT}" CACHE STRING
164 "Arguments to pass when running the benchmarks using check-cxx-benchmarks")
166 option(LIBCXX_INCLUDE_DOCS "Build the libc++ documentation." ${LLVM_INCLUDE_DOCS})
167 set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
168 "Define suffix of library directory name (32/64)")
169 option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON)
170 option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON)
171 option(LIBCXX_INSTALL_MODULES
172 "Install the libc++ C++20 module source files (experimental)." ON
174 cmake_dependent_option(LIBCXX_INSTALL_STATIC_LIBRARY
175 "Install the static libc++ library." ON
176 "LIBCXX_ENABLE_STATIC;LIBCXX_INSTALL_LIBRARY" OFF)
177 cmake_dependent_option(LIBCXX_INSTALL_SHARED_LIBRARY
178 "Install the shared libc++ library." ON
179 "LIBCXX_ENABLE_SHARED;LIBCXX_INSTALL_LIBRARY" OFF)
181 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)
182 if (LIBCXX_ABI_UNSTABLE)
187 set(LIBCXX_ABI_VERSION "${abi_version}" CACHE STRING
188 "ABI version of libc++. Can be either 1 or 2, where 2 is currently the unstable ABI.
189 Defaults to 1 unless LIBCXX_ABI_UNSTABLE is specified, in which case this is 2.")
190 set(LIBCXX_LIBRARY_VERSION "${LIBCXX_ABI_VERSION}.0" CACHE STRING
191 "Version of libc++. This will be reflected in the name of the shared library produced.
192 For example, -DLIBCXX_LIBRARY_VERSION=x.y will result in the library being named
193 libc++.x.y.dylib, along with the usual symlinks pointing to that. On Apple platforms,
194 this also controls the linker's 'current_version' property.")
195 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.")
196 if (NOT LIBCXX_ABI_NAMESPACE MATCHES "__.*")
197 message(FATAL_ERROR "LIBCXX_ABI_NAMESPACE must be a reserved identifier, got '${LIBCXX_ABI_NAMESPACE}'.")
199 option(LIBCXX_ABI_FORCE_ITANIUM "Ignore auto-detection and force use of the Itanium ABI.")
200 option(LIBCXX_ABI_FORCE_MICROSOFT "Ignore auto-detection and force use of the Microsoft ABI.")
202 set(LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION "default" CACHE STRING
203 "Override the implementation to use for comparing typeinfos. By default, this
204 is detected automatically by the library, but this option allows overriding
205 which implementation is used unconditionally.
207 See the documentation in <libcxx/include/typeinfo> for details on what each
209 set(TYPEINFO_COMPARISON_VALUES "default;1;2;3")
210 if (NOT ("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" IN_LIST TYPEINFO_COMPARISON_VALUES))
211 message(FATAL_ERROR "Value '${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}' is not a valid value for
212 LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION")
215 set(LIBCXX_ABI_DEFINES "" CACHE STRING "A semicolon separated list of ABI macros to define in the site config header.")
216 set(LIBCXX_EXTRA_SITE_DEFINES "" CACHE STRING "Extra defines to add into __config_site")
217 option(LIBCXX_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
219 # C Library options -----------------------------------------------------------
221 set(LIBCXX_SUPPORTED_C_LIBRARIES system llvm-libc)
222 set(LIBCXX_LIBC "system" CACHE STRING "Specify C library to use. Supported values are ${LIBCXX_SUPPORTED_C_LIBRARIES}.")
223 if (NOT "${LIBCXX_LIBC}" IN_LIST LIBCXX_SUPPORTED_C_LIBRARIES)
224 message(FATAL_ERROR "Unsupported C library: '${LIBCXX_CXX_ABI}'. Supported values are ${LIBCXX_SUPPORTED_C_LIBRARIES}.")
227 # ABI Library options ---------------------------------------------------------
229 set(LIBCXX_DEFAULT_ABI_LIBRARY "vcruntime")
231 set(LIBCXX_DEFAULT_ABI_LIBRARY "libcxxabi")
234 set(LIBCXX_SUPPORTED_ABI_LIBRARIES none libcxxabi system-libcxxabi libcxxrt libstdc++ libsupc++ vcruntime)
235 set(LIBCXX_CXX_ABI "${LIBCXX_DEFAULT_ABI_LIBRARY}" CACHE STRING "Specify C++ ABI library to use. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}.")
236 if (NOT "${LIBCXX_CXX_ABI}" IN_LIST LIBCXX_SUPPORTED_ABI_LIBRARIES)
237 message(FATAL_ERROR "Unsupported C++ ABI library: '${LIBCXX_CXX_ABI}'. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}.")
240 option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY
241 "Use a static copy of the ABI library when linking libc++.
242 This option cannot be used with LIBCXX_ENABLE_ABI_LINKER_SCRIPT." OFF)
244 option(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY
245 "Statically link the ABI library to static library"
246 ${LIBCXX_ENABLE_STATIC_ABI_LIBRARY})
248 option(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY
249 "Statically link the ABI library to shared library"
250 ${LIBCXX_ENABLE_STATIC_ABI_LIBRARY})
252 # Generate and install a linker script inplace of libc++.so. The linker script
253 # will link libc++ to the correct ABI library. This option is on by default
254 # on UNIX platforms other than Apple, and on the Fuchsia platform unless we
255 # statically link libc++abi inside libc++.so, we don't build libc++.so at all
256 # or we don't have any ABI library.
257 if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY
258 OR NOT LIBCXX_ENABLE_SHARED
259 OR LIBCXX_CXX_ABI STREQUAL "none")
260 set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF)
261 elseif((UNIX OR FUCHSIA) AND NOT APPLE)
262 set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE ON)
264 set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF)
266 option(LIBCXX_ENABLE_ABI_LINKER_SCRIPT
267 "Use and install a linker script for the given ABI library"
268 ${ENABLE_LINKER_SCRIPT_DEFAULT_VALUE})
270 option(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS
271 "Build libc++ with definitions for operator new/delete. These are normally
272 defined in libc++abi, but this option can be used to define them in libc++
273 instead. If you define them in libc++, make sure they are NOT defined in
274 libc++abi. Doing otherwise is an ODR violation." OFF)
275 # Build libc++abi with libunwind. We need this option to determine whether to
276 # link with libunwind or libgcc_s while running the test cases.
277 option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." ON)
279 # Target options --------------------------------------------------------------
280 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})
281 if (LIBCXX_BUILD_32_BITS)
282 message(FATAL_ERROR "LIBCXX_BUILD_32_BITS is not supported anymore when building the runtimes, please specify a full triple instead.")
285 # Feature options -------------------------------------------------------------
286 option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON)
287 option(LIBCXX_ENABLE_RTTI
288 "Use runtime type information.
289 This option may only be set to OFF when LIBCXX_ENABLE_EXCEPTIONS=OFF." ON)
290 option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON)
291 option(LIBCXX_ENABLE_MONOTONIC_CLOCK
292 "Build libc++ with support for a monotonic clock.
293 This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON)
294 option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF)
295 option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF)
296 option(LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32 thread API" OFF)
297 option(LIBCXX_HAS_EXTERNAL_THREAD_API
298 "Build libc++ with an externalized threading API.
299 This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF)
301 if (LIBCXX_ENABLE_THREADS)
302 set(LIBCXX_PSTL_BACKEND "std_thread" CACHE STRING "Which PSTL backend to use")
304 set(LIBCXX_PSTL_BACKEND "serial" CACHE STRING "Which PSTL backend to use")
307 # Misc options ----------------------------------------------------------------
308 # FIXME: Turn -pedantic back ON. It is currently off because it warns
309 # about #include_next which is used everywhere.
310 option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF)
311 option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
313 option(LIBCXX_GENERATE_COVERAGE "Enable generating code coverage." OFF)
314 set(LIBCXX_COVERAGE_LIBRARY "" CACHE STRING
315 "The Profile-rt library used to build with code coverage")
317 set(LIBCXX_CONFIGURE_IDE_DEFAULT OFF)
318 if (XCODE OR MSVC_IDE)
319 set(LIBCXX_CONFIGURE_IDE_DEFAULT ON)
321 option(LIBCXX_CONFIGURE_IDE "Configure libcxx for use within an IDE"
322 ${LIBCXX_CONFIGURE_IDE_DEFAULT})
324 set(LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT OFF)
326 set(LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT ON)
328 option(LIBCXX_HERMETIC_STATIC_LIBRARY
329 "Do not export any symbols from the static library." ${LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT})
331 #===============================================================================
332 # Check option configurations
333 #===============================================================================
335 # Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON only when
336 # LIBCXX_ENABLE_THREADS is on.
337 if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_ENABLE_MONOTONIC_CLOCK)
338 message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF"
339 " when LIBCXX_ENABLE_THREADS is also set to OFF.")
342 if(NOT LIBCXX_ENABLE_THREADS)
343 if(LIBCXX_HAS_PTHREAD_API)
344 message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON"
345 " when LIBCXX_ENABLE_THREADS is also set to ON.")
347 if(LIBCXX_HAS_EXTERNAL_THREAD_API)
348 message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set to ON"
349 " when LIBCXX_ENABLE_THREADS is also set to ON.")
351 if (LIBCXX_HAS_WIN32_THREAD_API)
352 message(FATAL_ERROR "LIBCXX_HAS_WIN32_THREAD_API can only be set to ON"
353 " when LIBCXX_ENABLE_THREADS is also set to ON.")
358 if (LIBCXX_HAS_EXTERNAL_THREAD_API)
359 if (LIBCXX_HAS_PTHREAD_API)
360 message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
361 " and LIBCXX_HAS_PTHREAD_API cannot be both"
362 " set to ON at the same time.")
364 if (LIBCXX_HAS_WIN32_THREAD_API)
365 message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
366 " and LIBCXX_HAS_WIN32_THREAD_API cannot be both"
367 " set to ON at the same time.")
371 if (LIBCXX_HAS_PTHREAD_API)
372 if (LIBCXX_HAS_WIN32_THREAD_API)
373 message(FATAL_ERROR "The options LIBCXX_HAS_PTHREAD_API"
374 " and LIBCXX_HAS_WIN32_THREAD_API cannot be both"
375 " set to ON at the same time.")
379 if (NOT LIBCXX_ENABLE_RTTI AND LIBCXX_ENABLE_EXCEPTIONS)
380 message(FATAL_ERROR "Libc++ cannot be built with exceptions enabled but RTTI"
381 " disabled, since that configuration is broken. See"
382 " https://github.com/llvm/llvm-project/issues/66117"
386 # Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE
388 if (LLVM_USE_SANITIZER AND LIBCXX_GENERATE_COVERAGE)
389 message(FATAL_ERROR "LLVM_USE_SANITIZER cannot be used with LIBCXX_GENERATE_COVERAGE")
392 if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
394 message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT cannot be used on APPLE targets")
396 if (NOT LIBCXX_ENABLE_SHARED)
397 message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT is only available for shared library builds.")
401 if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
402 message(FATAL_ERROR "Conflicting options given.
403 LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY cannot be specified with
404 LIBCXX_ENABLE_ABI_LINKER_SCRIPT")
407 if (LIBCXX_ABI_FORCE_ITANIUM AND LIBCXX_ABI_FORCE_MICROSOFT)
408 message(FATAL_ERROR "Only one of LIBCXX_ABI_FORCE_ITANIUM and LIBCXX_ABI_FORCE_MICROSOFT can be specified.")
411 if (LIBCXX_ENABLE_SHARED AND CMAKE_MSVC_RUNTIME_LIBRARY AND
412 (NOT CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL$"))
413 message(WARNING "A static CRT linked into a shared libc++ doesn't work correctly.")
416 #===============================================================================
418 #===============================================================================
420 # TODO: Projects that depend on libc++ should use LIBCXX_GENERATED_INCLUDE_DIR
421 # instead of hard-coding include/c++/v1.
423 set(LIBCXX_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/c++/v1" CACHE STRING
424 "Path where target-agnostic libc++ headers should be installed.")
425 set(LIBCXX_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING
426 "Path where built libc++ runtime libraries should be installed.")
427 set(LIBCXX_INSTALL_MODULES_DIR "share/libc++/v1" CACHE STRING
428 "Path where target-agnostic libc++ module source files should be installed.")
430 set(LIBCXX_SHARED_OUTPUT_NAME "c++" CACHE STRING "Output name for the shared libc++ runtime library.")
431 set(LIBCXX_STATIC_OUTPUT_NAME "c++" CACHE STRING "Output name for the static libc++ runtime library.")
433 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
434 set(LIBCXX_TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE})
435 if(LIBCXX_LIBDIR_SUBDIR)
436 string(APPEND LIBCXX_TARGET_SUBDIR /${LIBCXX_LIBDIR_SUBDIR})
438 set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LIBCXX_TARGET_SUBDIR})
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/${LIBCXX_TARGET_SUBDIR}/c++/v1")
442 set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LIBCXX_TARGET_SUBDIR} CACHE STRING
443 "Path where built libc++ libraries should be installed.")
444 set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${LIBCXX_TARGET_SUBDIR}/c++/v1" CACHE STRING
445 "Path where target-specific libc++ headers should be installed.")
446 unset(LIBCXX_TARGET_SUBDIR)
448 if(LLVM_LIBRARY_OUTPUT_INTDIR)
449 set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
450 set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
451 set(LIBCXX_GENERATED_MODULE_DIR "${LLVM_BINARY_DIR}/modules/c++/v1")
453 set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
454 set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1")
455 set(LIBCXX_GENERATED_MODULE_DIR "${CMAKE_BINARY_DIR}/modules/c++/v1")
457 set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}")
458 set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX} CACHE STRING
459 "Path where built libc++ libraries should be installed.")
460 set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${LIBCXX_INSTALL_INCLUDE_DIR}" CACHE STRING
461 "Path where target-specific libc++ headers should be installed.")
464 file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}")
466 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
467 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
468 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
470 # Declare libc++ configuration variables.
471 # They are intended for use as follows:
472 # LIBCXX_CXX_FLAGS: General flags for both the compiler and linker.
473 # LIBCXX_COMPILE_FLAGS: Compile only flags.
474 # LIBCXX_LINK_FLAGS: Linker only flags.
475 # LIBCXX_LIBRARIES: libraries libc++ is linked to.
476 set(LIBCXX_COMPILE_FLAGS "")
477 set(LIBCXX_LINK_FLAGS "")
478 set(LIBCXX_LIBRARIES "")
479 set(LIBCXX_ADDITIONAL_COMPILE_FLAGS "" CACHE STRING
480 "Additional Compile only flags which can be provided in cache")
481 set(LIBCXX_ADDITIONAL_LIBRARIES "" CACHE STRING
482 "Additional libraries libc++ is linked to which can be provided in cache")
484 # Include macros for adding and removing libc++ flags.
485 include(HandleLibcxxFlags)
487 # Target flags ================================================================
488 # These flags get added to CMAKE_CXX_FLAGS and CMAKE_C_FLAGS so that
489 # 'config-ix' use them during feature checks. It also adds them to both
490 # 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS'
492 if (${CMAKE_SYSTEM_NAME} MATCHES "AIX")
493 add_flags_if_supported("-mdefault-visibility-export-mapping=explicit")
494 set(CMAKE_AIX_EXPORT_ALL_SYMBOLS OFF)
497 # Configure compiler.
500 # Configure coverage options.
501 if (LIBCXX_GENERATE_COVERAGE)
502 include(CodeCoverage)
503 set(CMAKE_BUILD_TYPE "COVERAGE" CACHE STRING "" FORCE)
506 #===============================================================================
507 # Setup Compiler Flags
508 #===============================================================================
510 include(HandleLibC) # Setup the C library flags
511 include(HandleLibCXXABI) # Setup the ABI library flags
513 # FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC.
514 # Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors
515 # so they don't get transformed into -Wno and -errors respectively.
516 remove_flags(-Wno-pedantic -pedantic-errors -pedantic)
518 # Required flags ==============================================================
519 function(cxx_add_basic_build_flags target)
521 # Use C++23 for all targets.
522 set_target_properties(${target} PROPERTIES
524 CXX_STANDARD_REQUIRED OFF # TODO: Make this REQUIRED once we don't need to accommodate the LLVM documentation builders using an ancient CMake
527 # When building the dylib, don't warn for unavailable aligned allocation
528 # functions based on the deployment target -- they are always available
529 # because they are provided by the dylib itself with the exception of z/OS.
531 target_add_compile_flags_if_supported(${target} PRIVATE -fno-aligned-allocation)
533 target_add_compile_flags_if_supported(${target} PRIVATE -faligned-allocation)
536 # On all systems the system c++ standard library headers need to be excluded.
537 # MSVC only has -X, which disables all default includes; including the crt.
538 # Thus, we do nothing and hope we don't accidentally include any of the C++
540 target_add_compile_flags_if_supported(${target} PUBLIC -nostdinc++)
542 # Hide all inline function definitions which have not explicitly been marked
543 # visible. This prevents new definitions for inline functions from appearing in
544 # the dylib when get ODR used by another function.
545 target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility-inlines-hidden)
547 # Our visibility annotations are not quite right for non-Clang compilers,
548 # so we end up not exporting all the symbols we should. In the future, we
549 # can improve the situation by providing an explicit list of exported
550 # symbols on all compilers.
551 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
552 target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility=hidden)
555 # Build with -fsized-deallocation, which is default in recent versions of Clang.
556 # TODO(LLVM 21): This can be dropped once we only support Clang >= 19.
557 target_add_compile_flags_if_supported(${target} PRIVATE -fsized-deallocation)
559 # Let the library headers know they are currently being used to build the
561 target_compile_definitions(${target} PRIVATE -D_LIBCPP_BUILDING_LIBRARY)
563 # Make sure the library can be build without transitive includes. This makes
564 # it easier to upgrade the library to a newer language standard without build
566 target_compile_definitions(${target} PRIVATE -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
568 if (C_SUPPORTS_COMMENT_LIB_PRAGMA)
569 if (LIBCXX_HAS_PTHREAD_LIB)
570 target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_PTHREAD_LIB)
572 if (LIBCXX_HAS_RT_LIB)
573 target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_RT_LIB)
576 target_compile_options(${target} PUBLIC "${LIBCXX_ADDITIONAL_COMPILE_FLAGS}")
579 # Exception flags =============================================================
580 function(cxx_add_exception_flags target)
581 if (LIBCXX_ENABLE_EXCEPTIONS)
582 # Catches C++ exceptions only and tells the compiler to assume that extern C
583 # functions never throw a C++ exception.
584 target_add_compile_flags_if_supported(${target} PUBLIC -EHsc)
586 target_add_compile_flags_if_supported(${target} PUBLIC -EHs- -EHa-)
587 target_add_compile_flags_if_supported(${target} PUBLIC -fno-exceptions)
591 # RTTI flags ==================================================================
592 function(cxx_add_rtti_flags target)
593 if (NOT LIBCXX_ENABLE_RTTI)
595 target_add_compile_flags_if_supported(${target} PUBLIC -GR-)
597 target_add_compile_flags_if_supported(${target} PUBLIC -fno-rtti)
602 # Modules flags ===============================================================
603 # FIXME The libc++ sources are fundamentally non-modular. They need special
604 # versions of the headers in order to provide C++03 and legacy ABI definitions.
605 # NOTE: The public headers can be used with modules in all other contexts.
606 function(cxx_add_module_flags target)
607 if (LLVM_ENABLE_MODULES)
608 # Ignore that the rest of the modules flags are now unused.
609 target_add_compile_flags_if_supported(${target} PUBLIC -Wno-unused-command-line-argument)
610 target_compile_options(${target} PUBLIC -fno-modules)
614 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
616 # Sanitizer flags =============================================================
618 function(get_sanitizer_flags OUT_VAR USE_SANITIZER)
620 set(USE_SANITIZER "${USE_SANITIZER}")
621 # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC.
622 # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do.
623 if (USE_SANITIZER AND NOT MSVC)
624 append_flags_if_supported(SANITIZER_FLAGS "-fno-omit-frame-pointer")
625 append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only")
627 if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND
628 NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
629 append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only")
631 if (USE_SANITIZER STREQUAL "Address")
632 append_flags(SANITIZER_FLAGS "-fsanitize=address")
633 elseif (USE_SANITIZER STREQUAL "HWAddress")
634 append_flags(SANITIZER_FLAGS "-fsanitize=hwaddress")
635 elseif (USE_SANITIZER MATCHES "Memory(WithOrigins)?")
636 append_flags(SANITIZER_FLAGS -fsanitize=memory)
637 if (USE_SANITIZER STREQUAL "MemoryWithOrigins")
638 append_flags(SANITIZER_FLAGS "-fsanitize-memory-track-origins")
640 elseif (USE_SANITIZER STREQUAL "Undefined")
641 append_flags(SANITIZER_FLAGS "-fsanitize=undefined" "-fno-sanitize=vptr,function" "-fno-sanitize-recover=all")
642 elseif (USE_SANITIZER STREQUAL "Address;Undefined" OR
643 USE_SANITIZER STREQUAL "Undefined;Address")
644 append_flags(SANITIZER_FLAGS "-fsanitize=address,undefined" "-fno-sanitize=vptr,function" "-fno-sanitize-recover=all")
645 elseif (USE_SANITIZER STREQUAL "Thread")
646 append_flags(SANITIZER_FLAGS -fsanitize=thread)
647 elseif (USE_SANITIZER STREQUAL "DataFlow")
648 append_flags(SANITIZER_FLAGS -fsanitize=dataflow)
650 message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${USE_SANITIZER}")
652 elseif(USE_SANITIZER AND MSVC)
653 message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.")
655 set(${OUT_VAR} "${SANITIZER_FLAGS}" PARENT_SCOPE)
658 get_sanitizer_flags(SANITIZER_FLAGS "${LLVM_USE_SANITIZER}")
659 add_library(cxx-sanitizer-flags INTERFACE)
660 target_compile_options(cxx-sanitizer-flags INTERFACE ${SANITIZER_FLAGS})
662 # _LIBCPP_INSTRUMENTED_WITH_ASAN informs that library was built with ASan.
663 # Defining _LIBCPP_INSTRUMENTED_WITH_ASAN while building the library with ASan is required.
664 # Normally, the _LIBCPP_INSTRUMENTED_WITH_ASAN flag is used to keep information whether
665 # dylibs are built with AddressSanitizer. However, when building libc++,
666 # this flag needs to be defined so that the resulting dylib has all ASan functionalities guarded by this flag.
667 # If the _LIBCPP_INSTRUMENTED_WITH_ASAN flag is not defined, then parts of the ASan instrumentation code in libc++
668 # will not be compiled into it, resulting in false positives.
669 # For context, read: https://github.com/llvm/llvm-project/pull/72677#pullrequestreview-1765402800
670 string(FIND "${LLVM_USE_SANITIZER}" "Address" building_with_asan)
671 if (NOT "${building_with_asan}" STREQUAL "-1")
672 config_define(ON _LIBCPP_INSTRUMENTED_WITH_ASAN)
675 # Link system libraries =======================================================
676 function(cxx_link_system_libraries target)
678 target_link_libraries(${target} PRIVATE "-nostdlib++")
681 if (CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG AND LIBCXXABI_USE_LLVM_UNWINDER)
682 # If we're linking directly against the libunwind that we're building
683 # in the same invocation, don't try to link in the toolchain's
684 # default libunwind (which may be missing still).
685 target_add_link_flags_if_supported(${target} PRIVATE "--unwindlib=none")
689 if (LIBCXX_USE_COMPILER_RT)
690 find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY)
691 if (LIBCXX_BUILTINS_LIBRARY)
692 target_link_libraries(${target} PRIVATE "${LIBCXX_BUILTINS_LIBRARY}")
694 elseif (LIBCXX_HAS_GCC_LIB)
695 target_link_libraries(${target} PRIVATE gcc)
696 elseif (LIBCXX_HAS_GCC_S_LIB)
697 target_link_libraries(${target} PRIVATE gcc_s)
701 if (LIBCXX_HAS_ATOMIC_LIB)
702 target_link_libraries(${target} PRIVATE atomic)
706 target_link_libraries(${target} PRIVATE "${MINGW_LIBRARIES}")
710 if ((NOT CMAKE_MSVC_RUNTIME_LIBRARY AND uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
711 OR (CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "Debug"))
717 if (NOT CMAKE_MSVC_RUNTIME_LIBRARY OR CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL$")
718 set(CRT_LIB "msvcrt")
719 set(CXX_LIB "msvcprt")
721 set(CRT_LIB "libcmt")
722 set(CXX_LIB "libcpmt")
725 target_link_libraries(${target} PRIVATE ${CRT_LIB}${LIB_SUFFIX}) # C runtime startup files
726 target_link_libraries(${target} PRIVATE ${CXX_LIB}${LIB_SUFFIX}) # C++ standard library. Required for exception_ptr internals.
727 # Required for standards-complaint wide character formatting functions
728 # (e.g. `printfw`/`scanfw`)
729 target_link_libraries(${target} PRIVATE iso_stdio_wide_specifiers)
732 if (ANDROID AND ANDROID_PLATFORM_LEVEL LESS 21)
733 target_link_libraries(${target} PUBLIC android_support)
735 target_link_libraries(${target} PUBLIC "${LIBCXX_ADDITIONAL_LIBRARIES}")
738 # Windows-related flags =======================================================
739 function(cxx_add_windows_flags target)
740 if(WIN32 AND NOT MINGW)
741 target_compile_definitions(${target} PRIVATE
742 # Ignore the -MSC_VER mismatch, as we may build
743 # with a different compatibility version.
744 _ALLOW_MSC_VER_MISMATCH
745 # Don't check the msvcprt iterator debug levels
746 # as we will define the iterator types; libc++
747 # uses a different macro to identify the debug
749 _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH
750 # We are building the c++ runtime, don't pull in
753 # Don't warn on the use of "deprecated"
754 # "insecure" functions which are standards
756 _CRT_SECURE_NO_WARNINGS
757 # Use the ISO conforming behaviour for conversion
759 _CRT_STDIO_ISO_WIDE_SPECIFIERS)
763 # Configuration file flags =====================================================
764 config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION)
765 config_define(${LIBCXX_ABI_NAMESPACE} _LIBCPP_ABI_NAMESPACE)
766 config_define_if(LIBCXX_ABI_FORCE_ITANIUM _LIBCPP_ABI_FORCE_ITANIUM)
767 config_define_if(LIBCXX_ABI_FORCE_MICROSOFT _LIBCPP_ABI_FORCE_MICROSOFT)
768 config_define_if_not(LIBCXX_ENABLE_THREADS _LIBCPP_HAS_NO_THREADS)
769 config_define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK _LIBCPP_HAS_NO_MONOTONIC_CLOCK)
770 if (NOT LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION STREQUAL "default")
771 config_define("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION)
773 config_define_if(LIBCXX_HAS_PTHREAD_API _LIBCPP_HAS_THREAD_API_PTHREAD)
774 config_define_if(LIBCXX_HAS_EXTERNAL_THREAD_API _LIBCPP_HAS_THREAD_API_EXTERNAL)
775 config_define_if(LIBCXX_HAS_WIN32_THREAD_API _LIBCPP_HAS_THREAD_API_WIN32)
776 config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC)
777 config_define_if(LIBCXX_NO_VCRUNTIME _LIBCPP_NO_VCRUNTIME)
778 config_define_if_not(LIBCXX_ENABLE_FILESYSTEM _LIBCPP_HAS_NO_FILESYSTEM)
779 config_define_if_not(LIBCXX_ENABLE_RANDOM_DEVICE _LIBCPP_HAS_NO_RANDOM_DEVICE)
780 config_define_if_not(LIBCXX_ENABLE_LOCALIZATION _LIBCPP_HAS_NO_LOCALIZATION)
781 config_define_if_not(LIBCXX_ENABLE_UNICODE _LIBCPP_HAS_NO_UNICODE)
782 config_define_if_not(LIBCXX_ENABLE_WIDE_CHARACTERS _LIBCPP_HAS_NO_WIDE_CHARACTERS)
783 config_define_if_not(LIBCXX_ENABLE_TIME_ZONE_DATABASE _LIBCPP_HAS_NO_TIME_ZONE_DATABASE)
784 config_define_if_not(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)
786 if (LIBCXX_ENABLE_ASSERTIONS)
787 message(DEPRECATION "LIBCXX_ENABLE_ASSERTIONS is deprecated and will be removed in LLVM 20. Please use LIBCXX_HARDENING_MODE instead.")
788 set(LIBCXX_HARDENING_MODE "extensive")
790 if (LIBCXX_HARDENING_MODE STREQUAL "none")
791 config_define(2 _LIBCPP_HARDENING_MODE_DEFAULT)
792 elseif (LIBCXX_HARDENING_MODE STREQUAL "fast")
793 config_define(4 _LIBCPP_HARDENING_MODE_DEFAULT)
794 elseif (LIBCXX_HARDENING_MODE STREQUAL "extensive")
795 config_define(16 _LIBCPP_HARDENING_MODE_DEFAULT)
796 elseif (LIBCXX_HARDENING_MODE STREQUAL "debug")
797 config_define(8 _LIBCPP_HARDENING_MODE_DEFAULT)
800 if (LIBCXX_PSTL_BACKEND STREQUAL "serial")
801 config_define(1 _LIBCPP_PSTL_BACKEND_SERIAL)
802 elseif(LIBCXX_PSTL_BACKEND STREQUAL "std_thread")
803 config_define(1 _LIBCPP_PSTL_BACKEND_STD_THREAD)
804 elseif(LIBCXX_PSTL_BACKEND STREQUAL "libdispatch")
805 config_define(1 _LIBCPP_PSTL_BACKEND_LIBDISPATCH)
807 message(FATAL_ERROR "LIBCXX_PSTL_BACKEND is set to ${LIBCXX_PSTL_BACKEND}, which is not a valid backend.
808 Valid backends are: serial, std_thread and libdispatch")
811 if (LIBCXX_ABI_DEFINES)
813 foreach (abi_define ${LIBCXX_ABI_DEFINES})
814 if (NOT abi_define MATCHES "^_LIBCPP_ABI_")
815 message(SEND_ERROR "Invalid ABI macro ${abi_define} in LIBCXX_ABI_DEFINES")
817 list(APPEND abi_defines "#define ${abi_define}")
819 string(REPLACE ";" "\n" abi_defines "${abi_defines}")
820 config_define(${abi_defines} _LIBCPP_ABI_DEFINES)
823 if (LIBCXX_EXTRA_SITE_DEFINES)
824 set(extra_site_defines)
825 foreach (extra_site_define ${LIBCXX_EXTRA_SITE_DEFINES})
826 # Allow defines such as DEFINE=VAL, transformed into "#define DEFINE VAL".
827 string(REPLACE "=" " " extra_site_define "${extra_site_define}")
828 list(APPEND extra_site_defines "#define ${extra_site_define}")
830 string(REPLACE ";" "\n" extra_site_defines "${extra_site_defines}")
831 config_define(${extra_site_defines} _LIBCPP_EXTRA_SITE_DEFINES)
834 # By default libc++ on Windows expects to use a shared library, which requires
835 # the headers to use DLL import/export semantics. However when building a
836 # static library only we modify the headers to disable DLL import/export.
837 if (DEFINED WIN32 AND LIBCXX_ENABLE_STATIC AND NOT LIBCXX_ENABLE_SHARED)
838 message(STATUS "Generating custom __config for non-DLL Windows build")
839 config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
842 if (WIN32 AND LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
843 # If linking libcxxabi statically into libcxx, skip the dllimport attributes
844 # on symbols we refer to from libcxxabi.
845 add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS)
848 # Setup all common build flags =================================================
849 function(cxx_add_common_build_flags target)
850 cxx_add_basic_build_flags(${target})
851 cxx_add_warning_flags(${target} ${LIBCXX_ENABLE_WERROR} ${LIBCXX_ENABLE_PEDANTIC})
852 cxx_add_windows_flags(${target})
853 cxx_add_exception_flags(${target})
854 cxx_add_rtti_flags(${target})
855 cxx_add_module_flags(${target})
856 cxx_link_system_libraries(${target})
857 target_link_libraries(${target} PRIVATE cxx-sanitizer-flags)
860 #===============================================================================
861 # Setup Source Code And Tests
862 #===============================================================================
863 add_custom_target(cxx-test-depends
864 COMMENT "Build dependencies required to run the libc++ test suite.")
866 add_subdirectory(include)
867 add_subdirectory(src)
868 add_subdirectory(utils)
869 add_subdirectory(modules)
871 if (LIBCXX_INCLUDE_BENCHMARKS)
872 add_subdirectory(benchmarks)
875 if (LIBCXX_INCLUDE_TESTS)
876 add_subdirectory(test)
877 add_subdirectory(lib/abi)
880 if (LIBCXX_INCLUDE_DOCS)
881 add_subdirectory(docs)