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.13.4)
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 "${LLVM_COMMON_CMAKE_UTILS}"
16 "${LLVM_COMMON_CMAKE_UTILS}/Modules"
19 set(CMAKE_FOLDER "libc++")
21 set(LIBCXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
22 set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
23 set(LIBCXX_BINARY_INCLUDE_DIR "${LIBCXX_BINARY_DIR}/include/c++build")
25 include(GNUInstallDirs)
27 # Require out of source build.
28 include(MacroEnsureOutOfSourceBuild)
29 MACRO_ENSURE_OUT_OF_SOURCE_BUILD(
30 "${PROJECT_NAME} requires an out of source build. Please create a separate
31 build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there."
33 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
34 message(STATUS "Configuring for clang-cl")
35 set(LIBCXX_TARGETING_CLANG_CL ON)
39 set(LIBCXX_TARGETING_MSVC ON)
40 message(STATUS "Configuring for MSVC")
42 set(LIBCXX_TARGETING_MSVC OFF)
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 set(ENABLE_FILESYSTEM_DEFAULT ON)
59 if (WIN32 AND NOT MINGW)
60 # Filesystem is buildable for windows, but it requires __int128 helper
61 # functions, that currently are provided by libgcc or compiler_rt builtins.
62 # These are available in MinGW environments, but not currently in MSVC
64 set(ENABLE_FILESYSTEM_DEFAULT OFF)
66 option(LIBCXX_ENABLE_FILESYSTEM "Build filesystem as part of the main libc++ library"
67 ${ENABLE_FILESYSTEM_DEFAULT})
68 option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS})
69 option(LIBCXX_ENABLE_PARALLEL_ALGORITHMS "Enable the parallel algorithms library. This requires the PSTL to be available." OFF)
70 option(LIBCXX_ENABLE_DEBUG_MODE
71 "Whether to build libc++ with the debug mode enabled.
72 By default, this is turned off. Turning it on results in a different ABI (additional
73 symbols but also potentially different layouts of types), and one should not mix code
74 built against a dylib that has debug mode and code built against a regular dylib." OFF)
75 option(LIBCXX_ENABLE_RANDOM_DEVICE
76 "Whether to include support for std::random_device in the library. Disabling
77 this can be useful when building the library for platforms that don't have
78 a source of randomness, such as some embedded platforms. When this is not
79 supported, most of <random> will still be available, but std::random_device
81 option(LIBCXX_ENABLE_LOCALIZATION
82 "Whether to include support for localization in the library. Disabling
83 localization can be useful when porting to platforms that don't support
84 the C locale API (e.g. embedded). When localization is not supported,
85 several parts of the library will be disabled: <iostream>, <regex>, <locale>
86 will be completely unusable, and other parts may be only partly available." ON)
87 option(LIBCXX_ENABLE_UNICODE
88 "Whether to include support for Unicode in the library. Disabling Unicode can
89 be useful when porting to platforms that don't support UTF-8 encoding (e.g.
91 option(LIBCXX_ENABLE_WIDE_CHARACTERS
92 "Whether to include support for wide characters in the library. Disabling
93 wide character support can be useful when porting to platforms that don't
94 support the C functionality for wide characters. When wide characters are
95 not supported, several parts of the library will be disabled, notably the
96 wide character specializations of std::basic_string." ON)
97 option(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS
98 "Whether to turn on vendor availability annotations on declarations that depend
99 on definitions in a shared library. By default, we assume that we're not building
100 libc++ for any specific vendor, and we disable those annotations. Vendors wishing
101 to provide compile-time errors when using features unavailable on some version of
102 the shared library they shipped should turn this on and see `include/__availability`
103 for more details." OFF)
105 if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
106 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-gcc.cfg.in")
108 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-mingw.cfg.in")
109 elseif(WIN32) # clang-cl
110 if (LIBCXX_ENABLE_SHARED)
111 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-clangcl.cfg.in")
113 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-static-clangcl.cfg.in")
116 if (LIBCXX_ENABLE_SHARED)
117 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared.cfg.in")
119 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-static.cfg.in")
122 set(LIBCXX_TEST_CONFIG "${LIBCXX_DEFAULT_TEST_CONFIG}" CACHE STRING
123 "The path to the Lit testing configuration to use when running the tests.
124 If a relative path is provided, it is assumed to be relative to '<monorepo>/libcxx/test/configs'.")
125 if (NOT IS_ABSOLUTE "${LIBCXX_TEST_CONFIG}")
126 set(LIBCXX_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/configs/${LIBCXX_TEST_CONFIG}")
128 message(STATUS "Using libc++ testing configuration: ${LIBCXX_TEST_CONFIG}")
129 set(LIBCXX_TEST_PARAMS "" CACHE STRING
130 "A list of parameters to run the Lit test suite with.")
132 # Benchmark options -----------------------------------------------------------
133 option(LIBCXX_INCLUDE_BENCHMARKS "Build the libc++ benchmarks and their dependencies" ON)
135 set(LIBCXX_BENCHMARK_TEST_ARGS_DEFAULT --benchmark_min_time=0.01)
136 set(LIBCXX_BENCHMARK_TEST_ARGS "${LIBCXX_BENCHMARK_TEST_ARGS_DEFAULT}" CACHE STRING
137 "Arguments to pass when running the benchmarks using check-cxx-benchmarks")
139 set(LIBCXX_BENCHMARK_NATIVE_STDLIB "" CACHE STRING
140 "Build the benchmarks against the specified native STL.
141 The value must be one of libc++/libstdc++")
142 set(LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN "" CACHE STRING
143 "Use alternate GCC toolchain when building the native benchmarks")
145 if (LIBCXX_BENCHMARK_NATIVE_STDLIB)
146 if (NOT (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libc++"
147 OR LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libstdc++"))
148 message(FATAL_ERROR "Invalid value for LIBCXX_BENCHMARK_NATIVE_STDLIB: "
149 "'${LIBCXX_BENCHMARK_NATIVE_STDLIB}'")
153 option(LIBCXX_INCLUDE_DOCS "Build the libc++ documentation." ${LLVM_INCLUDE_DOCS})
154 set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
155 "Define suffix of library directory name (32/64)")
156 option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON)
157 option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON)
158 cmake_dependent_option(LIBCXX_INSTALL_STATIC_LIBRARY
159 "Install the static libc++ library." ON
160 "LIBCXX_ENABLE_STATIC;LIBCXX_INSTALL_LIBRARY" OFF)
161 cmake_dependent_option(LIBCXX_INSTALL_SHARED_LIBRARY
162 "Install the shared libc++ library." ON
163 "LIBCXX_ENABLE_SHARED;LIBCXX_INSTALL_LIBRARY" OFF)
165 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)
166 if (LIBCXX_ABI_UNSTABLE)
171 set(LIBCXX_ABI_VERSION "${abi_version}" CACHE STRING
172 "ABI version of libc++. Can be either 1 or 2, where 2 is currently the unstable ABI.
173 Defaults to 1 unless LIBCXX_ABI_UNSTABLE is specified, in which case this is 2.")
174 set(LIBCXX_LIBRARY_VERSION "${LIBCXX_ABI_VERSION}.0" CACHE STRING
175 "Version of libc++. This will be reflected in the name of the shared library produced.
176 For example, -DLIBCXX_LIBRARY_VERSION=x.y will result in the library being named
177 libc++.x.y.dylib, along with the usual symlinks pointing to that. On Apple platforms,
178 this also controls the linker's 'current_version' property.")
179 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.")
180 if (NOT LIBCXX_ABI_NAMESPACE MATCHES "__.*")
181 message(FATAL_ERROR "LIBCXX_ABI_NAMESPACE must be a reserved identifier, got '${LIBCXX_ABI_NAMESPACE}'.")
183 option(LIBCXX_ABI_FORCE_ITANIUM "Ignore auto-detection and force use of the Itanium ABI.")
184 option(LIBCXX_ABI_FORCE_MICROSOFT "Ignore auto-detection and force use of the Microsoft ABI.")
186 set(LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION "default" CACHE STRING
187 "Override the implementation to use for comparing typeinfos. By default, this
188 is detected automatically by the library, but this option allows overriding
189 which implementation is used unconditionally.
191 See the documentation in <libcxx/include/typeinfo> for details on what each
193 set(TYPEINFO_COMPARISON_VALUES "default;1;2;3")
194 if (NOT ("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" IN_LIST TYPEINFO_COMPARISON_VALUES))
195 message(FATAL_ERROR "Value '${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}' is not a valid value for
196 LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION")
199 set(LIBCXX_ABI_DEFINES "" CACHE STRING "A semicolon separated list of ABI macros to define in the site config header.")
200 option(LIBCXX_EXTRA_SITE_DEFINES "Extra defines to add into __config_site")
201 option(LIBCXX_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
203 option(LIBCXX_ENABLE_BACKWARDS_COMPATIBILITY_DEBUG_MODE_SYMBOLS
204 "Whether to include the old Debug mode symbols in the compiled library. This
205 is provided for backwards compatibility since the compiled library used to
206 always contain those symbols, regardless of whether the library was built
207 with the debug mode enabled. This is OFF by default, please contact the libc++
208 developers if you need to turn this on, as this will be removed in LLVM 16." OFF)
210 # ABI Library options ---------------------------------------------------------
211 if (LIBCXX_TARGETING_MSVC)
212 set(LIBCXX_DEFAULT_ABI_LIBRARY "vcruntime")
213 elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
214 set(LIBCXX_DEFAULT_ABI_LIBRARY "libcxxrt")
216 set(LIBCXX_DEFAULT_ABI_LIBRARY "libcxxabi")
219 set(LIBCXX_SUPPORTED_ABI_LIBRARIES none libcxxabi system-libcxxabi libcxxrt libstdc++ libsupc++ vcruntime)
220 set(LIBCXX_CXX_ABI "${LIBCXX_DEFAULT_ABI_LIBRARY}" CACHE STRING "Specify C++ ABI library to use. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}.")
221 if (NOT "${LIBCXX_CXX_ABI}" IN_LIST LIBCXX_SUPPORTED_ABI_LIBRARIES)
222 message(FATAL_ERROR "Unsupported C++ ABI library: '${LIBCXX_CXX_ABI}'. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}.")
225 option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY
226 "Use a static copy of the ABI library when linking libc++.
227 This option cannot be used with LIBCXX_ENABLE_ABI_LINKER_SCRIPT." OFF)
229 option(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY
230 "Statically link the ABI library to static library"
231 ${LIBCXX_ENABLE_STATIC_ABI_LIBRARY})
233 option(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY
234 "Statically link the ABI library to shared library"
235 ${LIBCXX_ENABLE_STATIC_ABI_LIBRARY})
237 # Generate and install a linker script inplace of libc++.so. The linker script
238 # will link libc++ to the correct ABI library. This option is on by default
239 # on UNIX platforms other than Apple unless
240 # 'LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY' is on. This option is also
241 # disabled when the ABI library is not specified or is specified to be "none".
242 set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF)
243 if (LLVM_HAVE_LINK_VERSION_SCRIPT AND NOT LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY
244 AND NOT LIBCXX_CXX_ABI STREQUAL "none"
245 AND Python3_EXECUTABLE
246 AND LIBCXX_ENABLE_SHARED)
247 set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE ON)
250 option(LIBCXX_ENABLE_ABI_LINKER_SCRIPT
251 "Use and install a linker script for the given ABI library"
252 ${ENABLE_LINKER_SCRIPT_DEFAULT_VALUE})
254 option(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS
255 "Build libc++ with definitions for operator new/delete. These are normally
256 defined in libc++abi, but this option can be used to define them in libc++
257 instead. If you define them in libc++, make sure they are NOT defined in
258 libc++abi. Doing otherwise is an ODR violation." OFF)
259 # Build libc++abi with libunwind. We need this option to determine whether to
260 # link with libunwind or libgcc_s while running the test cases.
261 option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF)
263 # Target options --------------------------------------------------------------
264 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})
265 if (LIBCXX_BUILD_32_BITS)
266 message(FATAL_ERROR "LIBCXX_BUILD_32_BITS is not supported anymore when building the runtimes, please specify a full triple instead.")
269 # TODO: Remove this after branching for LLVM 15
270 if(LIBCXX_SYSROOT OR LIBCXX_TARGET_TRIPLE OR LIBCXX_GCC_TOOLCHAIN)
271 message(WARNING "LIBCXX_SYSROOT, LIBCXX_TARGET_TRIPLE and LIBCXX_GCC_TOOLCHAIN are not supported anymore, please use the native CMake equivalents instead")
274 # Feature options -------------------------------------------------------------
275 option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON)
276 option(LIBCXX_ENABLE_RTTI "Use run time type information." ON)
277 option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON)
278 option(LIBCXX_ENABLE_MONOTONIC_CLOCK
279 "Build libc++ with support for a monotonic clock.
280 This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON)
281 option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF)
282 option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF)
283 option(LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32 thread API" OFF)
284 option(LIBCXX_HAS_EXTERNAL_THREAD_API
285 "Build libc++ with an externalized threading API.
286 This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF)
287 option(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY
288 "Build libc++ with an externalized threading library.
289 This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON" OFF)
291 # Misc options ----------------------------------------------------------------
292 # FIXME: Turn -pedantic back ON. It is currently off because it warns
293 # about #include_next which is used everywhere.
294 option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF)
295 option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
296 option(LIBCXX_DISABLE_MACRO_CONFLICT_WARNINGS "Disable #warnings about conflicting macros." OFF)
298 option(LIBCXX_GENERATE_COVERAGE "Enable generating code coverage." OFF)
299 set(LIBCXX_COVERAGE_LIBRARY "" CACHE STRING
300 "The Profile-rt library used to build with code coverage")
302 set(LIBCXX_CONFIGURE_IDE_DEFAULT OFF)
303 if (XCODE OR MSVC_IDE)
304 set(LIBCXX_CONFIGURE_IDE_DEFAULT ON)
306 option(LIBCXX_CONFIGURE_IDE "Configure libcxx for use within an IDE"
307 ${LIBCXX_CONFIGURE_IDE_DEFAULT})
309 set(LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT OFF)
311 set(LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT ON)
313 option(LIBCXX_HERMETIC_STATIC_LIBRARY
314 "Do not export any symbols from the static library." ${LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT})
316 #===============================================================================
317 # Check option configurations
318 #===============================================================================
320 # Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON only when
321 # LIBCXX_ENABLE_THREADS is on.
322 if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_ENABLE_MONOTONIC_CLOCK)
323 message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF"
324 " when LIBCXX_ENABLE_THREADS is also set to OFF.")
327 if(NOT LIBCXX_ENABLE_THREADS)
328 if(LIBCXX_HAS_PTHREAD_API)
329 message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON"
330 " when LIBCXX_ENABLE_THREADS is also set to ON.")
332 if(LIBCXX_HAS_EXTERNAL_THREAD_API)
333 message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set to ON"
334 " when LIBCXX_ENABLE_THREADS is also set to ON.")
336 if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY)
337 message(FATAL_ERROR "LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY can only be set "
338 "to ON when LIBCXX_ENABLE_THREADS is also set to ON.")
340 if (LIBCXX_HAS_WIN32_THREAD_API)
341 message(FATAL_ERROR "LIBCXX_HAS_WIN32_THREAD_API can only be set to ON"
342 " when LIBCXX_ENABLE_THREADS is also set to ON.")
347 if (LIBCXX_HAS_EXTERNAL_THREAD_API)
348 if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY)
349 message(FATAL_ERROR "The options LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY and "
350 "LIBCXX_HAS_EXTERNAL_THREAD_API cannot both be ON at "
353 if (LIBCXX_HAS_PTHREAD_API)
354 message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
355 "and LIBCXX_HAS_PTHREAD_API cannot be both"
356 "set to ON at the same time.")
358 if (LIBCXX_HAS_WIN32_THREAD_API)
359 message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
360 "and LIBCXX_HAS_WIN32_THREAD_API cannot be both"
361 "set to ON at the same time.")
365 if (LIBCXX_HAS_PTHREAD_API)
366 if (LIBCXX_HAS_WIN32_THREAD_API)
367 message(FATAL_ERROR "The options LIBCXX_HAS_PTHREAD_API"
368 "and LIBCXX_HAS_WIN32_THREAD_API cannot be both"
369 "set to ON at the same time.")
373 # Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE
375 if (LLVM_USE_SANITIZER AND LIBCXX_GENERATE_COVERAGE)
376 message(FATAL_ERROR "LLVM_USE_SANITIZER cannot be used with LIBCXX_GENERATE_COVERAGE")
379 if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
381 message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT cannot be used on APPLE targets")
383 if (NOT LIBCXX_ENABLE_SHARED)
384 message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT is only available for shared library builds.")
388 if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
389 message(FATAL_ERROR "Conflicting options given.
390 LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY cannot be specified with
391 LIBCXX_ENABLE_ABI_LINKER_SCRIPT")
394 if (LIBCXX_ABI_FORCE_ITANIUM AND LIBCXX_ABI_FORCE_MICROSOFT)
395 message(FATAL_ERROR "Only one of LIBCXX_ABI_FORCE_ITANIUM and LIBCXX_ABI_FORCE_MICROSOFT can be specified.")
398 #===============================================================================
400 #===============================================================================
402 # TODO: Projects that depend on libc++ should use LIBCXX_GENERATED_INCLUDE_DIR
403 # instead of hard-coding include/c++/v1.
405 set(LIBCXX_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/c++/v1" CACHE PATH
406 "Path where target-agnostic libc++ headers should be installed.")
407 set(LIBCXX_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH
408 "Path where built libc++ runtime libraries should be installed.")
410 set(LIBCXX_SHARED_OUTPUT_NAME "c++" CACHE STRING "Output name for the shared libc++ runtime library.")
411 set(LIBCXX_STATIC_OUTPUT_NAME "c++" CACHE STRING "Output name for the static libc++ runtime library.")
413 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
414 set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
415 set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
416 set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1")
417 set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH
418 "Path where built libc++ libraries should be installed.")
419 set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1" CACHE PATH
420 "Path where target-specific libc++ headers should be installed.")
421 if(LIBCXX_LIBDIR_SUBDIR)
422 string(APPEND LIBCXX_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR})
423 string(APPEND LIBCXX_INSTALL_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR})
426 if(LLVM_LIBRARY_OUTPUT_INTDIR)
427 set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
428 set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
430 set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
431 set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1")
433 set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}")
434 set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX} CACHE PATH
435 "Path where built libc++ libraries should be installed.")
436 set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${LIBCXX_INSTALL_INCLUDE_DIR}" CACHE PATH
437 "Path where target-specific libc++ headers should be installed.")
440 file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}")
442 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
443 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
444 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
446 # Declare libc++ configuration variables.
447 # They are intended for use as follows:
448 # LIBCXX_CXX_FLAGS: General flags for both the compiler and linker.
449 # LIBCXX_COMPILE_FLAGS: Compile only flags.
450 # LIBCXX_LINK_FLAGS: Linker only flags.
451 # LIBCXX_LIBRARIES: libraries libc++ is linked to.
452 set(LIBCXX_COMPILE_FLAGS "")
453 set(LIBCXX_LINK_FLAGS "")
454 set(LIBCXX_LIBRARIES "")
455 set(LIBCXX_ADDITIONAL_COMPILE_FLAGS "" CACHE STRING
456 "Additional Compile only flags which can be provided in cache")
457 set(LIBCXX_ADDITIONAL_LIBRARIES "" CACHE STRING
458 "Additional libraries libc++ is linked to which can be provided in cache")
460 # Include macros for adding and removing libc++ flags.
461 include(HandleLibcxxFlags)
463 # Target flags ================================================================
464 # These flags get added to CMAKE_CXX_FLAGS and CMAKE_C_FLAGS so that
465 # 'config-ix' use them during feature checks. It also adds them to both
466 # 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS'
468 if (${CMAKE_SYSTEM_NAME} MATCHES "AIX")
469 add_target_flags_if_supported("-mdefault-visibility-export-mapping=explicit")
470 set(CMAKE_AIX_EXPORT_ALL_SYMBOLS OFF)
473 # Configure compiler.
476 # Configure coverage options.
477 if (LIBCXX_GENERATE_COVERAGE)
478 include(CodeCoverage)
479 set(CMAKE_BUILD_TYPE "COVERAGE" CACHE STRING "" FORCE)
482 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
483 if (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
484 set(LIBCXX_DEBUG_BUILD ON)
486 set(LIBCXX_DEBUG_BUILD OFF)
489 #===============================================================================
490 # Setup Compiler Flags
491 #===============================================================================
493 include(HandleLibCXXABI) # Setup the ABI library flags
495 # Remove flags that may have snuck in.
496 # TODO: This shouldn't be necessary anymore since we don't support the Project
497 # build anymore, so the rest of LLVM can't pollute our flags.
498 remove_flags(-DNDEBUG -UNDEBUG -D_DEBUG -lc++abi)
499 remove_flags(--stdlib=libc++ -stdlib=libc++ --stdlib=libstdc++ -stdlib=libstdc++)
501 # FIXME: Remove all debug flags and flags that change which Windows
502 # default libraries are linked. Currently we only support linking the
504 remove_flags("/D_DEBUG" "/MTd" "/MDd" "/MT" "/Md")
506 # FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC.
507 # Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors
508 # so they don't get transformed into -Wno and -errors respectively.
509 remove_flags(-Wno-pedantic -pedantic-errors -pedantic)
511 # Required flags ==============================================================
512 function(cxx_add_basic_build_flags target)
514 # Require C++20 for all targets. C++17 is needed to use aligned allocation
515 # in the dylib. C++20 is needed to use char8_t.
516 set_target_properties(${target} PROPERTIES
518 CXX_STANDARD_REQUIRED YES
521 # When building the dylib, don't warn for unavailable aligned allocation
522 # functions based on the deployment target -- they are always available
523 # because they are provided by the dylib itself with the exception of z/OS.
525 target_add_compile_flags_if_supported(${target} PRIVATE -fno-aligned-allocation)
527 target_add_compile_flags_if_supported(${target} PRIVATE -faligned-allocation)
530 # On all systems the system c++ standard library headers need to be excluded.
531 # MSVC only has -X, which disables all default includes; including the crt.
532 # Thus, we do nothing and hope we don't accidentally include any of the C++
534 target_add_compile_flags_if_supported(${target} PUBLIC -nostdinc++)
536 # Hide all inline function definitions which have not explicitly been marked
537 # visible. This prevents new definitions for inline functions from appearing in
538 # the dylib when get ODR used by another function.
539 target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility-inlines-hidden)
541 # Our visibility annotations are not quite right for non-Clang compilers,
542 # so we end up not exporting all the symbols we should. In the future, we
543 # can improve the situation by providing an explicit list of exported
544 # symbols on all compilers.
545 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
546 target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility=hidden)
549 if (LIBCXX_CONFIGURE_IDE)
550 # This simply allows IDE to process <experimental/coroutine>
551 target_add_compile_flags_if_supported(${target} PRIVATE -fcoroutines-ts)
554 # Let the library headers know they are currently being used to build the
556 target_compile_definitions(${target} PRIVATE -D_LIBCPP_BUILDING_LIBRARY)
558 if (NOT LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS)
559 target_compile_definitions(${target} PRIVATE -D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS)
562 if (C_SUPPORTS_COMMENT_LIB_PRAGMA)
563 if (LIBCXX_HAS_PTHREAD_LIB)
564 target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_PTHREAD_LIB)
566 if (LIBCXX_HAS_RT_LIB)
567 target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_RT_LIB)
570 target_compile_options(${target} PUBLIC "${LIBCXX_ADDITIONAL_COMPILE_FLAGS}")
573 # Warning flags ===============================================================
574 function(cxx_add_warning_flags target)
575 target_compile_definitions(${target} PUBLIC -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
577 # -W4 is the cl.exe/clang-cl equivalent of -Wall. (In cl.exe and clang-cl,
578 # -Wall is equivalent to -Weverything in GCC style compiler drivers.)
579 target_add_compile_flags_if_supported(${target} PRIVATE -W4)
581 target_add_compile_flags_if_supported(${target} PRIVATE -Wall)
583 target_add_compile_flags_if_supported(${target} PRIVATE -Wextra -W -Wwrite-strings
584 -Wno-unused-parameter -Wno-long-long
585 -Werror=return-type -Wextra-semi -Wundef
587 if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
588 target_add_compile_flags_if_supported(${target} PRIVATE
589 -Wno-user-defined-literals
590 -Wno-covered-switch-default
591 -Wno-suggest-override
593 if (LIBCXX_TARGETING_CLANG_CL)
594 target_add_compile_flags_if_supported(${target} PRIVATE
596 -Wno-c++98-compat-pedantic
599 -Wno-reserved-id-macro
600 -Wno-gnu-include-next
601 -Wno-gcc-compat # For ignoring "'diagnose_if' is a clang extension" warnings
602 -Wno-zero-as-null-pointer-constant # FIXME: Remove this and fix all occurrences.
603 -Wno-deprecated-dynamic-exception-spec # For auto_ptr
606 -Wno-deprecated # FIXME: Remove this and fix all occurrences.
607 -Wno-shift-sign-overflow # FIXME: Why do we need this with clang-cl but not clang?
608 -Wno-double-promotion # FIXME: remove me
611 elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
612 target_add_compile_flags_if_supported(${target} PRIVATE
617 -Wno-suggest-override)
619 if (LIBCXX_ENABLE_WERROR)
620 target_add_compile_flags_if_supported(${target} PRIVATE -Werror)
621 target_add_compile_flags_if_supported(${target} PRIVATE -WX)
623 # TODO(EricWF) Remove this. We shouldn't be suppressing errors when -Werror is
625 target_add_compile_flags_if_supported(${target} PRIVATE -Wno-error)
627 if (LIBCXX_ENABLE_PEDANTIC)
628 target_add_compile_flags_if_supported(${target} PRIVATE -pedantic)
632 # Exception flags =============================================================
633 function(cxx_add_exception_flags target)
634 if (LIBCXX_ENABLE_EXCEPTIONS)
635 # Catches C++ exceptions only and tells the compiler to assume that extern C
636 # functions never throw a C++ exception.
637 target_add_compile_flags_if_supported(${target} PUBLIC -EHsc)
639 target_add_compile_flags_if_supported(${target} PUBLIC -EHs- -EHa-)
640 target_add_compile_flags_if_supported(${target} PUBLIC -fno-exceptions)
644 # RTTI flags ==================================================================
645 function(cxx_add_rtti_flags target)
646 if (NOT LIBCXX_ENABLE_RTTI)
647 target_add_compile_flags_if_supported(${target} PUBLIC -GR-)
648 target_add_compile_flags_if_supported(${target} PUBLIC -fno-rtti)
652 # Threading flags =============================================================
653 if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY AND LIBCXX_ENABLE_SHARED)
654 # Need to allow unresolved symbols if this is to work with shared library builds
656 add_link_flags("-undefined dynamic_lookup")
658 # Relax this restriction from HandleLLVMOptions
659 string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
663 # Assertion flags =============================================================
664 define_if(LIBCXX_DEBUG_BUILD -D_DEBUG)
665 if (LIBCXX_ENABLE_ASSERTIONS AND NOT LIBCXX_DEBUG_BUILD)
666 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
667 define_if_not(LIBCXX_TARGETING_MSVC -D_DEBUG)
670 # Modules flags ===============================================================
671 # FIXME The libc++ sources are fundamentally non-modular. They need special
672 # versions of the headers in order to provide C++03 and legacy ABI definitions.
673 # NOTE: The public headers can be used with modules in all other contexts.
674 function(cxx_add_module_flags target)
675 if (LLVM_ENABLE_MODULES)
676 # Ignore that the rest of the modules flags are now unused.
677 target_add_compile_flags_if_supported(${target} PUBLIC -Wno-unused-command-line-argument)
678 target_compile_options(${target} PUBLIC -fno-modules)
682 # Sanitizer flags =============================================================
684 function(get_sanitizer_flags OUT_VAR USE_SANITIZER)
686 set(USE_SANITIZER "${USE_SANITIZER}")
687 # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC.
688 # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do.
689 if (USE_SANITIZER AND NOT MSVC)
690 append_flags_if_supported(SANITIZER_FLAGS "-fno-omit-frame-pointer")
691 append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only")
693 if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND
694 NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
695 append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only")
697 if (USE_SANITIZER STREQUAL "Address")
698 append_flags(SANITIZER_FLAGS "-fsanitize=address")
699 elseif (USE_SANITIZER STREQUAL "HWAddress")
700 append_flags(SANITIZER_FLAGS "-fsanitize=hwaddress")
701 elseif (USE_SANITIZER MATCHES "Memory(WithOrigins)?")
702 append_flags(SANITIZER_FLAGS -fsanitize=memory)
703 if (USE_SANITIZER STREQUAL "MemoryWithOrigins")
704 append_flags(SANITIZER_FLAGS "-fsanitize-memory-track-origins")
706 elseif (USE_SANITIZER STREQUAL "Undefined")
707 append_flags(SANITIZER_FLAGS "-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all")
708 elseif (USE_SANITIZER STREQUAL "Address;Undefined" OR
709 USE_SANITIZER STREQUAL "Undefined;Address")
710 append_flags(SANITIZER_FLAGS "-fsanitize=address,undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all")
711 elseif (USE_SANITIZER STREQUAL "Thread")
712 append_flags(SANITIZER_FLAGS -fsanitize=thread)
713 elseif (USE_SANITIZER STREQUAL "DataFlow")
714 append_flags(SANITIZER_FLAGS -fsanitize=dataflow)
716 message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${USE_SANITIZER}")
718 elseif(USE_SANITIZER AND MSVC)
719 message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.")
721 set(${OUT_VAR} "${SANITIZER_FLAGS}" PARENT_SCOPE)
724 get_sanitizer_flags(SANITIZER_FLAGS "${LLVM_USE_SANITIZER}")
726 # Link system libraries =======================================================
727 function(cxx_link_system_libraries target)
729 # In order to remove just libc++ from the link step
730 # we need to use -nostdlib++ whenever it is supported.
731 # Unfortunately this cannot be used universally because for example g++ supports
732 # only -nodefaultlibs in which case all libraries will be removed and
733 # all libraries but c++ have to be added in manually.
734 if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
735 target_add_link_flags_if_supported(${target} PRIVATE "-nostdlib++")
737 target_add_link_flags_if_supported(${target} PRIVATE "-nodefaultlibs")
738 target_add_compile_flags_if_supported(${target} PRIVATE "/Zl")
739 target_add_link_flags_if_supported(${target} PRIVATE "/nodefaultlib")
742 if (CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG AND LIBCXXABI_USE_LLVM_UNWINDER)
743 # If we're linking directly against the libunwind that we're building
744 # in the same invocation, don't try to link in the toolchain's
745 # default libunwind (which may be missing still).
746 target_add_link_flags_if_supported(${target} PRIVATE "--unwindlib=none")
749 if (LIBCXX_HAS_SYSTEM_LIB)
750 target_link_libraries(${target} PRIVATE System)
753 if (LIBCXX_HAS_PTHREAD_LIB)
754 target_link_libraries(${target} PRIVATE pthread)
757 if (LIBCXX_HAS_C_LIB)
758 target_link_libraries(${target} PRIVATE c)
761 if (LIBCXX_HAS_M_LIB)
762 target_link_libraries(${target} PRIVATE m)
765 if (LIBCXX_HAS_RT_LIB)
766 target_link_libraries(${target} PRIVATE rt)
769 if (LIBCXX_USE_COMPILER_RT)
770 find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY)
771 if (LIBCXX_BUILTINS_LIBRARY)
772 target_link_libraries(${target} PRIVATE "${LIBCXX_BUILTINS_LIBRARY}")
774 elseif (LIBCXX_HAS_GCC_LIB)
775 target_link_libraries(${target} PRIVATE gcc)
776 elseif (LIBCXX_HAS_GCC_S_LIB)
777 target_link_libraries(${target} PRIVATE gcc_s)
780 if (LIBCXX_HAS_ATOMIC_LIB)
781 target_link_libraries(${target} PRIVATE atomic)
785 target_link_libraries(${target} PRIVATE "${MINGW_LIBRARIES}")
788 if (LIBCXX_TARGETING_MSVC)
789 if (LIBCXX_DEBUG_BUILD)
795 target_link_libraries(${target} PRIVATE ucrt${LIB_SUFFIX}) # Universal C runtime
796 target_link_libraries(${target} PRIVATE vcruntime${LIB_SUFFIX}) # C++ runtime
797 target_link_libraries(${target} PRIVATE msvcrt${LIB_SUFFIX}) # C runtime startup files
798 target_link_libraries(${target} PRIVATE msvcprt${LIB_SUFFIX}) # C++ standard library. Required for exception_ptr internals.
799 # Required for standards-complaint wide character formatting functions
800 # (e.g. `printfw`/`scanfw`)
801 target_link_libraries(${target} PRIVATE iso_stdio_wide_specifiers)
804 if (ANDROID AND ANDROID_PLATFORM_LEVEL LESS 21)
805 target_link_libraries(${target} PUBLIC android_support)
807 target_link_libraries(${target} PUBLIC "${LIBCXX_ADDITIONAL_LIBRARIES}")
810 # Windows-related flags =======================================================
811 function(cxx_add_windows_flags target)
812 if(WIN32 AND NOT MINGW)
813 target_compile_definitions(${target} PRIVATE
814 # Ignore the -MSC_VER mismatch, as we may build
815 # with a different compatibility version.
816 _ALLOW_MSC_VER_MISMATCH
817 # Don't check the msvcprt iterator debug levels
818 # as we will define the iterator types; libc++
819 # uses a different macro to identify the debug
821 _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH
822 # We are building the c++ runtime, don't pull in
825 # Don't warn on the use of "deprecated"
826 # "insecure" functions which are standards
828 _CRT_SECURE_NO_WARNINGS
829 # Use the ISO conforming behaviour for conversion
831 _CRT_STDIO_ISO_WIDE_SPECIFIERS)
832 # Clang-cl shared builds don't support the experimental library.
833 # To avoid linker errors the format_error destructor is inlined for the
834 # dylib. Users can never use format in this mode.
835 # TODO FMT Remove when format becomes mainline.
836 if (LIBCXX_ENABLE_SHARED)
837 target_compile_definitions(${target} PRIVATE
838 _LIBCPP_INLINE_FORMAT_ERROR_DTOR)
843 # Configuration file flags =====================================================
844 config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION)
845 config_define(${LIBCXX_ABI_NAMESPACE} _LIBCPP_ABI_NAMESPACE)
846 config_define_if(LIBCXX_ABI_FORCE_ITANIUM _LIBCPP_ABI_FORCE_ITANIUM)
847 config_define_if(LIBCXX_ABI_FORCE_MICROSOFT _LIBCPP_ABI_FORCE_MICROSOFT)
848 config_define_if_not(LIBCXX_ENABLE_THREADS _LIBCPP_HAS_NO_THREADS)
849 config_define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK _LIBCPP_HAS_NO_MONOTONIC_CLOCK)
850 if (NOT LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION STREQUAL "default")
851 config_define("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION)
853 config_define_if(LIBCXX_HAS_PTHREAD_API _LIBCPP_HAS_THREAD_API_PTHREAD)
854 config_define_if(LIBCXX_HAS_EXTERNAL_THREAD_API _LIBCPP_HAS_THREAD_API_EXTERNAL)
855 config_define_if(LIBCXX_HAS_WIN32_THREAD_API _LIBCPP_HAS_THREAD_API_WIN32)
856 config_define_if(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL)
857 config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC)
858 config_define_if(LIBCXX_NO_VCRUNTIME _LIBCPP_NO_VCRUNTIME)
859 config_define_if(LIBCXX_ENABLE_PARALLEL_ALGORITHMS _LIBCPP_HAS_PARALLEL_ALGORITHMS)
860 config_define_if_not(LIBCXX_ENABLE_FILESYSTEM _LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)
861 config_define_if_not(LIBCXX_ENABLE_RANDOM_DEVICE _LIBCPP_HAS_NO_RANDOM_DEVICE)
862 config_define_if_not(LIBCXX_ENABLE_LOCALIZATION _LIBCPP_HAS_NO_LOCALIZATION)
863 config_define_if_not(LIBCXX_ENABLE_UNICODE _LIBCPP_HAS_NO_UNICODE)
864 config_define_if_not(LIBCXX_ENABLE_WIDE_CHARACTERS _LIBCPP_HAS_NO_WIDE_CHARACTERS)
865 config_define_if_not(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)
866 config_define_if(LIBCXX_ENABLE_DEBUG_MODE _LIBCPP_ENABLE_DEBUG_MODE)
867 if (LIBCXX_ENABLE_ASSERTIONS)
868 config_define(1 _LIBCPP_ENABLE_ASSERTIONS_DEFAULT)
870 config_define(0 _LIBCPP_ENABLE_ASSERTIONS_DEFAULT)
873 if (LIBCXX_ABI_DEFINES)
875 foreach (abi_define ${LIBCXX_ABI_DEFINES})
876 if (NOT abi_define MATCHES "^_LIBCPP_ABI_")
877 message(SEND_ERROR "Invalid ABI macro ${abi_define} in LIBCXX_ABI_DEFINES")
879 list(APPEND abi_defines "#define ${abi_define}")
881 string(REPLACE ";" "\n" abi_defines "${abi_defines}")
882 config_define(${abi_defines} _LIBCPP_ABI_DEFINES)
885 if (LIBCXX_EXTRA_SITE_DEFINES)
886 set(extra_site_defines)
887 foreach (extra_site_define ${LIBCXX_EXTRA_SITE_DEFINES})
888 # Allow defines such as DEFINE=VAL, transformed into "#define DEFINE VAL".
889 string(REPLACE "=" " " extra_site_define "${extra_site_define}")
890 list(APPEND extra_site_defines "#define ${extra_site_define}")
892 string(REPLACE ";" "\n" extra_site_defines "${extra_site_defines}")
893 config_define(${extra_site_defines} _LIBCPP_EXTRA_SITE_DEFINES)
896 # By default libc++ on Windows expects to use a shared library, which requires
897 # the headers to use DLL import/export semantics. However when building a
898 # static library only we modify the headers to disable DLL import/export.
899 if (DEFINED WIN32 AND LIBCXX_ENABLE_STATIC AND NOT LIBCXX_ENABLE_SHARED)
900 message(STATUS "Generating custom __config for non-DLL Windows build")
901 config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
904 if (WIN32 AND LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
905 # If linking libcxxabi statically into libcxx, skip the dllimport attributes
906 # on symbols we refer to from libcxxabi.
907 add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS)
910 # Setup all common build flags =================================================
911 function(cxx_add_common_build_flags target)
912 cxx_add_basic_build_flags(${target})
913 cxx_add_warning_flags(${target})
914 cxx_add_windows_flags(${target})
915 cxx_add_exception_flags(${target})
916 cxx_add_rtti_flags(${target})
917 cxx_add_module_flags(${target})
918 cxx_link_system_libraries(${target})
921 #===============================================================================
922 # Setup Source Code And Tests
923 #===============================================================================
924 add_subdirectory(include)
925 add_subdirectory(src)
926 add_subdirectory(utils)
928 set(LIBCXX_TEST_DEPS "cxx_experimental")
930 if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY)
931 list(APPEND LIBCXX_TEST_DEPS cxx_external_threads)
934 if (LIBCXX_INCLUDE_BENCHMARKS)
935 add_subdirectory(benchmarks)
938 if (LIBCXX_INCLUDE_TESTS)
939 add_subdirectory(test)
940 add_subdirectory(lib/abi)
943 if (LIBCXX_INCLUDE_DOCS)
944 add_subdirectory(docs)