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 option(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY "Build libc++experimental.a" ON)
59 set(ENABLE_FILESYSTEM_DEFAULT ON)
60 if (WIN32 AND NOT MINGW)
61 # Filesystem is buildable for windows, but it requires __int128 helper
62 # functions, that currently are provided by libgcc or compiler_rt builtins.
63 # These are available in MinGW environments, but not currently in MSVC
65 set(ENABLE_FILESYSTEM_DEFAULT OFF)
67 option(LIBCXX_ENABLE_FILESYSTEM "Build filesystem as part of the main libc++ library"
68 ${ENABLE_FILESYSTEM_DEFAULT})
69 option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS})
70 option(LIBCXX_ENABLE_PARALLEL_ALGORITHMS "Enable the parallel algorithms library. This requires the PSTL to be available." OFF)
71 option(LIBCXX_ENABLE_DEBUG_MODE_SUPPORT
72 "Whether to include support for libc++'s debugging mode in the library.
73 By default, this is turned on. If you turn it off and try to enable the
74 debug mode when compiling a program against libc++, it will fail to link
75 since the required support isn't provided in the library." ON)
76 option(LIBCXX_ENABLE_RANDOM_DEVICE
77 "Whether to include support for std::random_device in the library. Disabling
78 this can be useful when building the library for platforms that don't have
79 a source of randomness, such as some embedded platforms. When this is not
80 supported, most of <random> will still be available, but std::random_device
82 option(LIBCXX_ENABLE_LOCALIZATION
83 "Whether to include support for localization in the library. Disabling
84 localization can be useful when porting to platforms that don't support
85 the C locale API (e.g. embedded). When localization is not supported,
86 several parts of the library will be disabled: <iostream>, <regex>, <locale>
87 will be completely unusable, and other parts may be only partly available." ON)
88 option(LIBCXX_ENABLE_UNICODE
89 "Whether to include support for Unicode in the library. Disabling Unicode can
90 be useful when porting to platforms that don't support UTF-8 encoding (e.g.
92 option(LIBCXX_ENABLE_WIDE_CHARACTERS
93 "Whether to include support for wide characters in the library. Disabling
94 wide character support can be useful when porting to platforms that don't
95 support the C functionality for wide characters. When wide characters are
96 not supported, several parts of the library will be disabled, notably the
97 wide character specializations of std::basic_string." ON)
98 option(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS
99 "Whether to turn on vendor availability annotations on declarations that depend
100 on definitions in a shared library. By default, we assume that we're not building
101 libc++ for any specific vendor, and we disable those annotations. Vendors wishing
102 to provide compile-time errors when using features unavailable on some version of
103 the shared library they shipped should turn this on and see `include/__availability`
104 for more details." OFF)
105 option(LIBCXX_ENABLE_INCOMPLETE_FEATURES
106 "Whether to enable support for incomplete library features. Incomplete features
107 are new library features under development. These features don't guarantee
108 ABI stability nor the quality of completed library features. Vendors
109 shipping the library may want to disable this option." ON)
111 if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
112 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-gcc.cfg.in")
114 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-mingw.cfg.in")
115 elseif(WIN32) # clang-cl
116 if (LIBCXX_ENABLE_SHARED)
117 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-clangcl.cfg.in")
119 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-static-clangcl.cfg.in")
122 if (LIBCXX_ENABLE_SHARED)
123 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared.cfg.in")
125 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-static.cfg.in")
128 set(LIBCXX_TEST_CONFIG "${LIBCXX_DEFAULT_TEST_CONFIG}" CACHE STRING
129 "The path to the Lit testing configuration to use when running the tests.
130 If a relative path is provided, it is assumed to be relative to '<monorepo>/libcxx/test/configs'.")
131 if (NOT IS_ABSOLUTE "${LIBCXX_TEST_CONFIG}")
132 set(LIBCXX_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/configs/${LIBCXX_TEST_CONFIG}")
134 message(STATUS "Using libc++ testing configuration: ${LIBCXX_TEST_CONFIG}")
135 set(LIBCXX_TEST_PARAMS "" CACHE STRING
136 "A list of parameters to run the Lit test suite with.")
138 # Benchmark options -----------------------------------------------------------
139 option(LIBCXX_INCLUDE_BENCHMARKS "Build the libc++ benchmarks and their dependencies" ON)
141 set(LIBCXX_BENCHMARK_TEST_ARGS_DEFAULT --benchmark_min_time=0.01)
142 set(LIBCXX_BENCHMARK_TEST_ARGS "${LIBCXX_BENCHMARK_TEST_ARGS_DEFAULT}" CACHE STRING
143 "Arguments to pass when running the benchmarks using check-cxx-benchmarks")
145 set(LIBCXX_BENCHMARK_NATIVE_STDLIB "" CACHE STRING
146 "Build the benchmarks against the specified native STL.
147 The value must be one of libc++/libstdc++")
148 set(LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN "" CACHE STRING
149 "Use alternate GCC toolchain when building the native benchmarks")
151 if (LIBCXX_BENCHMARK_NATIVE_STDLIB)
152 if (NOT (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libc++"
153 OR LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libstdc++"))
154 message(FATAL_ERROR "Invalid value for LIBCXX_BENCHMARK_NATIVE_STDLIB: "
155 "'${LIBCXX_BENCHMARK_NATIVE_STDLIB}'")
159 option(LIBCXX_INCLUDE_DOCS "Build the libc++ documentation." ${LLVM_INCLUDE_DOCS})
160 set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
161 "Define suffix of library directory name (32/64)")
162 option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON)
163 option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON)
164 cmake_dependent_option(LIBCXX_INSTALL_STATIC_LIBRARY
165 "Install the static libc++ library." ON
166 "LIBCXX_ENABLE_STATIC;LIBCXX_INSTALL_LIBRARY" OFF)
167 cmake_dependent_option(LIBCXX_INSTALL_SHARED_LIBRARY
168 "Install the shared libc++ library." ON
169 "LIBCXX_ENABLE_SHARED;LIBCXX_INSTALL_LIBRARY" OFF)
170 cmake_dependent_option(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY
171 "Install libc++experimental.a" ON
172 "LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY;LIBCXX_INSTALL_LIBRARY" OFF)
174 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)
175 if (LIBCXX_ABI_UNSTABLE)
180 set(LIBCXX_ABI_VERSION "${abi_version}" CACHE STRING
181 "ABI version of libc++. Can be either 1 or 2, where 2 is currently the unstable ABI.
182 Defaults to 1 unless LIBCXX_ABI_UNSTABLE is specified, in which case this is 2.")
183 set(LIBCXX_LIBRARY_VERSION "${LIBCXX_ABI_VERSION}.0" CACHE STRING
184 "Version of libc++. This will be reflected in the name of the shared library produced.
185 For example, -DLIBCXX_LIBRARY_VERSION=x.y will result in the library being named
186 libc++.x.y.dylib, along with the usual symlinks pointing to that. On Apple platforms,
187 this also controls the linker's 'current_version' property.")
188 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.")
189 if (NOT LIBCXX_ABI_NAMESPACE MATCHES "__.*")
190 message(FATAL_ERROR "LIBCXX_ABI_NAMESPACE must be a reserved identifier.")
192 option(LIBCXX_ABI_FORCE_ITANIUM "Ignore auto-detection and force use of the Itanium ABI.")
193 option(LIBCXX_ABI_FORCE_MICROSOFT "Ignore auto-detection and force use of the Microsoft ABI.")
195 set(LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION "default" CACHE STRING
196 "Override the implementation to use for comparing typeinfos. By default, this
197 is detected automatically by the library, but this option allows overriding
198 which implementation is used unconditionally.
200 See the documentation in <libcxx/include/typeinfo> for details on what each
202 set(TYPEINFO_COMPARISON_VALUES "default;1;2;3")
203 if (NOT ("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" IN_LIST TYPEINFO_COMPARISON_VALUES))
204 message(FATAL_ERROR "Value '${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}' is not a valid value for
205 LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION")
208 option(LIBCXX_HIDE_FROM_ABI_PER_TU_BY_DEFAULT "Enable per TU ABI insulation by default. To be used by vendors." OFF)
209 set(LIBCXX_ABI_DEFINES "" CACHE STRING "A semicolon separated list of ABI macros to define in the site config header.")
210 option(LIBCXX_EXTRA_SITE_DEFINES "Extra defines to add into __config_site")
211 option(LIBCXX_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
213 # ABI Library options ---------------------------------------------------------
214 if (LIBCXX_TARGETING_MSVC)
215 set(LIBCXX_DEFAULT_ABI_LIBRARY "vcruntime")
216 elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
217 set(LIBCXX_DEFAULT_ABI_LIBRARY "libcxxrt")
219 set(LIBCXX_DEFAULT_ABI_LIBRARY "libcxxabi")
222 set(LIBCXX_SUPPORTED_ABI_LIBRARIES none libcxxabi system-libcxxabi libcxxrt libstdc++ libsupc++ vcruntime)
223 set(LIBCXX_CXX_ABI "${LIBCXX_DEFAULT_ABI_LIBRARY}" CACHE STRING "Specify C++ ABI library to use. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}.")
225 # Temporary to still accept existing CMake caches that contain "default" as the value
226 if (LIBCXX_CXX_ABI STREQUAL "default")
227 set(LIBCXX_CXX_ABI "${LIBCXX_DEFAULT_ABI_LIBRARY}")
230 if (NOT "${LIBCXX_CXX_ABI}" IN_LIST LIBCXX_SUPPORTED_ABI_LIBRARIES)
231 message(FATAL_ERROR "Unsupported C++ ABI library: '${LIBCXX_CXX_ABI}'. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}.")
234 option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY
235 "Use a static copy of the ABI library when linking libc++.
236 This option cannot be used with LIBCXX_ENABLE_ABI_LINKER_SCRIPT." OFF)
238 cmake_dependent_option(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY
239 "Statically link the ABI library to static library" ON
240 "LIBCXX_ENABLE_STATIC_ABI_LIBRARY;LIBCXX_ENABLE_STATIC" OFF)
242 cmake_dependent_option(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY
243 "Statically link the ABI library to shared library" ON
244 "LIBCXX_ENABLE_STATIC_ABI_LIBRARY;LIBCXX_ENABLE_SHARED" OFF)
246 # Generate and install a linker script inplace of libc++.so. The linker script
247 # will link libc++ to the correct ABI library. This option is on by default
248 # on UNIX platforms other than Apple unless 'LIBCXX_ENABLE_STATIC_ABI_LIBRARY'
249 # is on. This option is also disabled when the ABI library is not specified
250 # or is specified to be "none".
251 set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF)
252 if (LLVM_HAVE_LINK_VERSION_SCRIPT AND NOT LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY
253 AND NOT LIBCXX_CXX_ABI STREQUAL "none"
254 AND Python3_EXECUTABLE
255 AND LIBCXX_ENABLE_SHARED)
256 set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE ON)
259 option(LIBCXX_ENABLE_ABI_LINKER_SCRIPT
260 "Use and install a linker script for the given ABI library"
261 ${ENABLE_LINKER_SCRIPT_DEFAULT_VALUE})
263 option(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS
264 "Build libc++ with definitions for operator new/delete. These are normally
265 defined in libc++abi, but this option can be used to define them in libc++
266 instead. If you define them in libc++, make sure they are NOT defined in
267 libc++abi. Doing otherwise is an ODR violation." OFF)
268 # Build libc++abi with libunwind. We need this option to determine whether to
269 # link with libunwind or libgcc_s while running the test cases.
270 option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF)
272 # Target options --------------------------------------------------------------
273 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})
274 if (LIBCXX_BUILD_32_BITS)
275 message(FATAL_ERROR "LIBCXX_BUILD_32_BITS is not supported anymore when building the runtimes, please specify a full triple instead.")
278 # TODO: Remove this after branching for LLVM 15
279 if(LIBCXX_SYSROOT OR LIBCXX_TARGET_TRIPLE OR LIBCXX_GCC_TOOLCHAIN)
280 message(WARNING "LIBCXX_SYSROOT, LIBCXX_TARGET_TRIPLE and LIBCXX_GCC_TOOLCHAIN are not supported anymore, please use the native CMake equivalents instead")
283 # Feature options -------------------------------------------------------------
284 option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON)
285 option(LIBCXX_ENABLE_RTTI "Use run time type information." ON)
286 option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON)
287 option(LIBCXX_ENABLE_MONOTONIC_CLOCK
288 "Build libc++ with support for a monotonic clock.
289 This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON)
290 option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF)
291 option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF)
292 option(LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32 thread API" OFF)
293 option(LIBCXX_HAS_EXTERNAL_THREAD_API
294 "Build libc++ with an externalized threading API.
295 This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF)
296 option(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY
297 "Build libc++ with an externalized threading library.
298 This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON" OFF)
300 # Misc options ----------------------------------------------------------------
301 # FIXME: Turn -pedantic back ON. It is currently off because it warns
302 # about #include_next which is used everywhere.
303 option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF)
304 option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
305 option(LIBCXX_DISABLE_MACRO_CONFLICT_WARNINGS "Disable #warnings about conflicting macros." OFF)
307 option(LIBCXX_GENERATE_COVERAGE "Enable generating code coverage." OFF)
308 set(LIBCXX_COVERAGE_LIBRARY "" CACHE STRING
309 "The Profile-rt library used to build with code coverage")
311 set(LIBCXX_CONFIGURE_IDE_DEFAULT OFF)
312 if (XCODE OR MSVC_IDE)
313 set(LIBCXX_CONFIGURE_IDE_DEFAULT ON)
315 option(LIBCXX_CONFIGURE_IDE "Configure libcxx for use within an IDE"
316 ${LIBCXX_CONFIGURE_IDE_DEFAULT})
318 set(LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT OFF)
320 set(LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT ON)
322 option(LIBCXX_HERMETIC_STATIC_LIBRARY
323 "Do not export any symbols from the static library." ${LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT})
325 #===============================================================================
326 # Check option configurations
327 #===============================================================================
329 # Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON only when
330 # LIBCXX_ENABLE_THREADS is on.
331 if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_ENABLE_MONOTONIC_CLOCK)
332 message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF"
333 " when LIBCXX_ENABLE_THREADS is also set to OFF.")
336 if(NOT LIBCXX_ENABLE_THREADS)
337 if(LIBCXX_HAS_PTHREAD_API)
338 message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON"
339 " when LIBCXX_ENABLE_THREADS is also set to ON.")
341 if(LIBCXX_HAS_EXTERNAL_THREAD_API)
342 message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set to ON"
343 " when LIBCXX_ENABLE_THREADS is also set to ON.")
345 if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY)
346 message(FATAL_ERROR "LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY can only be set "
347 "to ON when LIBCXX_ENABLE_THREADS is also set to ON.")
349 if (LIBCXX_HAS_WIN32_THREAD_API)
350 message(FATAL_ERROR "LIBCXX_HAS_WIN32_THREAD_API can only be set to ON"
351 " when LIBCXX_ENABLE_THREADS is also set to ON.")
356 if (LIBCXX_HAS_EXTERNAL_THREAD_API)
357 if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY)
358 message(FATAL_ERROR "The options LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY and "
359 "LIBCXX_HAS_EXTERNAL_THREAD_API cannot both be ON at "
362 if (LIBCXX_HAS_PTHREAD_API)
363 message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
364 "and LIBCXX_HAS_PTHREAD_API cannot be both"
365 "set to ON at the same time.")
367 if (LIBCXX_HAS_WIN32_THREAD_API)
368 message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
369 "and LIBCXX_HAS_WIN32_THREAD_API cannot be both"
370 "set to ON at the same time.")
374 if (LIBCXX_HAS_PTHREAD_API)
375 if (LIBCXX_HAS_WIN32_THREAD_API)
376 message(FATAL_ERROR "The options LIBCXX_HAS_PTHREAD_API"
377 "and LIBCXX_HAS_WIN32_THREAD_API cannot be both"
378 "set to ON at the same time.")
382 # Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE
384 if (LLVM_USE_SANITIZER AND LIBCXX_GENERATE_COVERAGE)
385 message(FATAL_ERROR "LLVM_USE_SANITIZER cannot be used with LIBCXX_GENERATE_COVERAGE")
388 # Warn users that LIBCXX_ENABLE_STATIC_ABI_LIBRARY is an experimental option.
389 if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
390 message(WARNING "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is an experimental option")
391 if (LIBCXX_ENABLE_STATIC AND NOT Python3_EXECUTABLE)
392 message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY requires python but it was not found.")
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_ENABLE_STATIC_ABI_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 #===============================================================================
417 #===============================================================================
419 # TODO: Projects that depend on libc++ should use LIBCXX_GENERATED_INCLUDE_DIR
420 # instead of hard-coding include/c++/v1.
422 set(LIBCXX_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/c++/v1" CACHE PATH
423 "Path where target-agnostic libc++ headers should be installed.")
424 set(LIBCXX_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH
425 "Path where built libc++ runtime libraries should be installed.")
427 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
428 set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
429 set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
430 set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1")
431 set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH
432 "Path where built libc++ libraries should be installed.")
433 set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1" CACHE PATH
434 "Path where target-specific libc++ headers should be installed.")
435 if(LIBCXX_LIBDIR_SUBDIR)
436 string(APPEND LIBCXX_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR})
437 string(APPEND LIBCXX_INSTALL_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR})
440 if(LLVM_LIBRARY_OUTPUT_INTDIR)
441 set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
442 set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
444 set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
445 set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1")
447 set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}")
448 set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX} CACHE PATH
449 "Path where built libc++ libraries should be installed.")
450 set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${LIBCXX_INSTALL_INCLUDE_DIR}" CACHE PATH
451 "Path where target-specific libc++ headers should be installed.")
454 file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}")
456 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
457 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
458 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
460 # Declare libc++ configuration variables.
461 # They are intended for use as follows:
462 # LIBCXX_CXX_FLAGS: General flags for both the compiler and linker.
463 # LIBCXX_COMPILE_FLAGS: Compile only flags.
464 # LIBCXX_LINK_FLAGS: Linker only flags.
465 # LIBCXX_LIBRARIES: libraries libc++ is linked to.
466 set(LIBCXX_COMPILE_FLAGS "")
467 set(LIBCXX_LINK_FLAGS "")
468 set(LIBCXX_LIBRARIES "")
470 # Include macros for adding and removing libc++ flags.
471 include(HandleLibcxxFlags)
473 # Target flags ================================================================
474 # These flags get added to CMAKE_CXX_FLAGS and CMAKE_C_FLAGS so that
475 # 'config-ix' use them during feature checks. It also adds them to both
476 # 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS'
478 add_target_flags_if_supported("-fzos-le-char-mode=ebcdic")
481 # Configure compiler.
484 # Configure coverage options.
485 if (LIBCXX_GENERATE_COVERAGE)
486 include(CodeCoverage)
487 set(CMAKE_BUILD_TYPE "COVERAGE" CACHE STRING "" FORCE)
490 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
491 if (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
492 set(LIBCXX_DEBUG_BUILD ON)
494 set(LIBCXX_DEBUG_BUILD OFF)
497 #===============================================================================
498 # Setup Compiler Flags
499 #===============================================================================
501 include(HandleLibCXXABI) # Setup the ABI library flags
503 # Remove flags that may have snuck in.
504 # TODO: This shouldn't be necessary anymore since we don't support the Project
505 # build anymore, so the rest of LLVM can't pollute our flags.
506 remove_flags(-DNDEBUG -UNDEBUG -D_DEBUG -lc++abi)
507 remove_flags(--stdlib=libc++ -stdlib=libc++ --stdlib=libstdc++ -stdlib=libstdc++)
509 # FIXME: Remove all debug flags and flags that change which Windows
510 # default libraries are linked. Currently we only support linking the
512 remove_flags("/D_DEBUG" "/MTd" "/MDd" "/MT" "/Md")
514 # FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC.
515 # Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors
516 # so they don't get transformed into -Wno and -errors respectively.
517 remove_flags(-Wno-pedantic -pedantic-errors -pedantic)
519 # Required flags ==============================================================
520 function(cxx_add_basic_build_flags target)
522 # Require C++20 for all targets. C++17 is needed to use aligned allocation
523 # in the dylib. C++20 is needed to use char8_t.
524 set_target_properties(${target} PROPERTIES
526 CXX_STANDARD_REQUIRED YES
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 excepton 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 if (LIBCXX_CONFIGURE_IDE)
558 # This simply allows IDE to process <experimental/coroutine>
559 target_add_compile_flags_if_supported(${target} PRIVATE -fcoroutines-ts)
562 # Let the library headers know they are currently being used to build the
564 target_compile_definitions(${target} PRIVATE -D_LIBCPP_BUILDING_LIBRARY)
566 if (NOT LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS)
567 target_compile_definitions(${target} PRIVATE -D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS)
570 if (C_SUPPORTS_COMMENT_LIB_PRAGMA)
571 if (LIBCXX_HAS_PTHREAD_LIB)
572 target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_PTHREAD_LIB)
574 if (LIBCXX_HAS_RT_LIB)
575 target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_RT_LIB)
580 # Warning flags ===============================================================
581 function(cxx_add_warning_flags target)
582 target_compile_definitions(${target} PUBLIC -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
584 # -W4 is the cl.exe/clang-cl equivalent of -Wall. (In cl.exe and clang-cl,
585 # -Wall is equivalent to -Weverything in GCC style compiler drivers.)
586 target_add_compile_flags_if_supported(${target} PRIVATE -W4)
588 target_add_compile_flags_if_supported(${target} PRIVATE -Wall)
590 target_add_compile_flags_if_supported(${target} PRIVATE -Wextra -W -Wwrite-strings
591 -Wno-unused-parameter -Wno-long-long
592 -Werror=return-type -Wextra-semi -Wundef
594 if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
595 target_add_compile_flags_if_supported(${target} PRIVATE
596 -Wno-user-defined-literals
597 -Wno-covered-switch-default
598 -Wno-suggest-override
600 if (LIBCXX_TARGETING_CLANG_CL)
601 target_add_compile_flags_if_supported(${target} PRIVATE
603 -Wno-c++98-compat-pedantic
606 -Wno-reserved-id-macro
607 -Wno-gnu-include-next
608 -Wno-gcc-compat # For ignoring "'diagnose_if' is a clang extension" warnings
609 -Wno-zero-as-null-pointer-constant # FIXME: Remove this and fix all occurrences.
610 -Wno-deprecated-dynamic-exception-spec # For auto_ptr
613 -Wno-deprecated # FIXME: Remove this and fix all occurrences.
614 -Wno-shift-sign-overflow # FIXME: Why do we need this with clang-cl but not clang?
615 -Wno-double-promotion # FIXME: remove me
618 elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
619 target_add_compile_flags_if_supported(${target} PRIVATE
624 -Wno-suggest-override)
626 if (LIBCXX_ENABLE_WERROR)
627 target_add_compile_flags_if_supported(${target} PRIVATE -Werror)
628 target_add_compile_flags_if_supported(${target} PRIVATE -WX)
630 # TODO(EricWF) Remove this. We shouldn't be suppressing errors when -Werror is
632 target_add_compile_flags_if_supported(${target} PRIVATE -Wno-error)
634 if (LIBCXX_ENABLE_PEDANTIC)
635 target_add_compile_flags_if_supported(${target} PRIVATE -pedantic)
637 if (LIBCXX_DISABLE_MACRO_CONFLICT_WARNINGS)
638 target_compile_definitions(${target} PRIVATE -D_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS)
642 # Exception flags =============================================================
643 function(cxx_add_exception_flags target)
644 if (LIBCXX_ENABLE_EXCEPTIONS)
645 # Catches C++ exceptions only and tells the compiler to assume that extern C
646 # functions never throw a C++ exception.
647 target_add_compile_flags_if_supported(${target} PUBLIC -EHsc)
649 target_add_compile_flags_if_supported(${target} PUBLIC -EHs- -EHa-)
650 target_add_compile_flags_if_supported(${target} PUBLIC -fno-exceptions)
654 # RTTI flags ==================================================================
655 function(cxx_add_rtti_flags target)
656 if (NOT LIBCXX_ENABLE_RTTI)
657 target_add_compile_flags_if_supported(${target} PUBLIC -GR-)
658 target_add_compile_flags_if_supported(${target} PUBLIC -fno-rtti)
662 # Threading flags =============================================================
663 if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY AND LIBCXX_ENABLE_SHARED)
664 # Need to allow unresolved symbols if this is to work with shared library builds
666 add_link_flags("-undefined dynamic_lookup")
668 # Relax this restriction from HandleLLVMOptions
669 string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
673 # Assertion flags =============================================================
674 define_if(LIBCXX_DEBUG_BUILD -D_DEBUG)
675 if (LIBCXX_ENABLE_ASSERTIONS AND NOT LIBCXX_DEBUG_BUILD)
676 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
677 define_if_not(LIBCXX_TARGETING_MSVC -D_DEBUG)
680 # Modules flags ===============================================================
681 # FIXME The libc++ sources are fundamentally non-modular. They need special
682 # versions of the headers in order to provide C++03 and legacy ABI definitions.
683 # NOTE: The public headers can be used with modules in all other contexts.
684 function(cxx_add_module_flags target)
685 if (LLVM_ENABLE_MODULES)
686 # Ignore that the rest of the modules flags are now unused.
687 target_add_compile_flags_if_supported(${target} PUBLIC -Wno-unused-command-line-argument)
688 target_compile_options(${target} PUBLIC -fno-modules)
692 # Sanitizer flags =============================================================
694 function(get_sanitizer_flags OUT_VAR USE_SANITIZER)
696 set(USE_SANITIZER "${USE_SANITIZER}")
697 # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC.
698 # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do.
699 if (USE_SANITIZER AND NOT MSVC)
700 append_flags_if_supported(SANITIZER_FLAGS "-fno-omit-frame-pointer")
701 append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only")
703 if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND
704 NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
705 append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only")
707 if (USE_SANITIZER STREQUAL "Address")
708 append_flags(SANITIZER_FLAGS "-fsanitize=address")
709 elseif (USE_SANITIZER MATCHES "Memory(WithOrigins)?")
710 append_flags(SANITIZER_FLAGS -fsanitize=memory)
711 if (USE_SANITIZER STREQUAL "MemoryWithOrigins")
712 append_flags(SANITIZER_FLAGS "-fsanitize-memory-track-origins")
714 elseif (USE_SANITIZER STREQUAL "Undefined")
715 append_flags(SANITIZER_FLAGS "-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all")
716 elseif (USE_SANITIZER STREQUAL "Address;Undefined" OR
717 USE_SANITIZER STREQUAL "Undefined;Address")
718 append_flags(SANITIZER_FLAGS "-fsanitize=address,undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all")
719 elseif (USE_SANITIZER STREQUAL "Thread")
720 append_flags(SANITIZER_FLAGS -fsanitize=thread)
721 elseif (USE_SANITIZER STREQUAL "DataFlow")
722 append_flags(SANITIZER_FLAGS -fsanitize=dataflow)
724 message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${USE_SANITIZER}")
726 elseif(USE_SANITIZER AND MSVC)
727 message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.")
729 set(${OUT_VAR} "${SANITIZER_FLAGS}" PARENT_SCOPE)
732 get_sanitizer_flags(SANITIZER_FLAGS "${LLVM_USE_SANITIZER}")
734 # Link system libraries =======================================================
735 function(cxx_link_system_libraries target)
737 # In order to remove just libc++ from the link step
738 # we need to use -nostdlib++ whenever it is supported.
739 # Unfortunately this cannot be used universally because for example g++ supports
740 # only -nodefaultlibs in which case all libraries will be removed and
741 # all libraries but c++ have to be added in manually.
742 if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
743 target_add_link_flags_if_supported(${target} PRIVATE "-nostdlib++")
745 target_add_link_flags_if_supported(${target} PRIVATE "-nodefaultlibs")
746 target_add_compile_flags_if_supported(${target} PRIVATE "/Zl")
747 target_add_link_flags_if_supported(${target} PRIVATE "/nodefaultlib")
750 if (CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG AND LIBCXXABI_USE_LLVM_UNWINDER)
751 # If we're linking directly against the libunwind that we're building
752 # in the same invocation, don't try to link in the toolchain's
753 # default libunwind (which may be missing still).
754 target_add_link_flags_if_supported(${target} PRIVATE "--unwindlib=none")
757 if (LIBCXX_HAS_SYSTEM_LIB)
758 target_link_libraries(${target} PRIVATE System)
761 if (LIBCXX_HAS_PTHREAD_LIB)
762 target_link_libraries(${target} PRIVATE pthread)
765 if (LIBCXX_HAS_C_LIB)
766 target_link_libraries(${target} PRIVATE c)
769 if (LIBCXX_HAS_M_LIB)
770 target_link_libraries(${target} PRIVATE m)
773 if (LIBCXX_HAS_RT_LIB)
774 target_link_libraries(${target} PRIVATE rt)
777 if (LIBCXX_USE_COMPILER_RT)
778 find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY)
779 if (LIBCXX_BUILTINS_LIBRARY)
780 target_link_libraries(${target} PRIVATE "${LIBCXX_BUILTINS_LIBRARY}")
782 elseif (LIBCXX_HAS_GCC_LIB)
783 target_link_libraries(${target} PRIVATE gcc)
784 elseif (LIBCXX_HAS_GCC_S_LIB)
785 target_link_libraries(${target} PRIVATE gcc_s)
788 if (LIBCXX_HAS_ATOMIC_LIB)
789 target_link_libraries(${target} PRIVATE atomic)
793 target_link_libraries(${target} PRIVATE "${MINGW_LIBRARIES}")
796 if (LIBCXX_TARGETING_MSVC)
797 if (LIBCXX_DEBUG_BUILD)
803 target_link_libraries(${target} PRIVATE ucrt${LIB_SUFFIX}) # Universal C runtime
804 target_link_libraries(${target} PRIVATE vcruntime${LIB_SUFFIX}) # C++ runtime
805 target_link_libraries(${target} PRIVATE msvcrt${LIB_SUFFIX}) # C runtime startup files
806 target_link_libraries(${target} PRIVATE msvcprt${LIB_SUFFIX}) # C++ standard library. Required for exception_ptr internals.
807 # Required for standards-complaint wide character formatting functions
808 # (e.g. `printfw`/`scanfw`)
809 target_link_libraries(${target} PRIVATE iso_stdio_wide_specifiers)
812 if (ANDROID AND ANDROID_PLATFORM_LEVEL LESS 21)
813 target_link_libraries(${target} PUBLIC android_support)
817 # Windows-related flags =======================================================
818 function(cxx_add_windows_flags target)
819 if(WIN32 AND NOT MINGW)
820 target_compile_definitions(${target} PRIVATE
821 # Ignore the -MSC_VER mismatch, as we may build
822 # with a different compatibility version.
823 _ALLOW_MSC_VER_MISMATCH
824 # Don't check the msvcprt iterator debug levels
825 # as we will define the iterator types; libc++
826 # uses a different macro to identify the debug
828 _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH
829 # We are building the c++ runtime, don't pull in
832 # Don't warn on the use of "deprecated"
833 # "insecure" functions which are standards
835 _CRT_SECURE_NO_WARNINGS
836 # Use the ISO conforming behaviour for conversion
838 _CRT_STDIO_ISO_WIDE_SPECIFIERS)
842 # Configuration file flags =====================================================
843 config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION)
844 config_define(${LIBCXX_ABI_NAMESPACE} _LIBCPP_ABI_NAMESPACE)
845 config_define_if(LIBCXX_ABI_FORCE_ITANIUM _LIBCPP_ABI_FORCE_ITANIUM)
846 config_define_if(LIBCXX_ABI_FORCE_MICROSOFT _LIBCPP_ABI_FORCE_MICROSOFT)
847 config_define_if(LIBCXX_HIDE_FROM_ABI_PER_TU_BY_DEFAULT _LIBCPP_HIDE_FROM_ABI_PER_TU_BY_DEFAULT)
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 if (LIBCXX_ENABLE_ASSERTIONS)
867 config_define(1 _LIBCPP_ENABLE_ASSERTIONS_DEFAULT)
869 config_define(0 _LIBCPP_ENABLE_ASSERTIONS_DEFAULT)
871 # Incomplete features get their own specific disabling flags. This makes it
872 # easier to grep for target specific flags once the feature is complete.
873 config_define_if_not(LIBCXX_ENABLE_INCOMPLETE_FEATURES _LIBCPP_HAS_NO_INCOMPLETE_FORMAT)
874 config_define_if_not(LIBCXX_ENABLE_INCOMPLETE_FEATURES _LIBCPP_HAS_NO_INCOMPLETE_RANGES)
876 if (LIBCXX_ABI_DEFINES)
878 foreach (abi_define ${LIBCXX_ABI_DEFINES})
879 if (NOT abi_define MATCHES "^_LIBCPP_ABI_")
880 message(SEND_ERROR "Invalid ABI macro ${abi_define} in LIBCXX_ABI_DEFINES")
882 list(APPEND abi_defines "#define ${abi_define}")
884 string(REPLACE ";" "\n" abi_defines "${abi_defines}")
885 config_define(${abi_defines} _LIBCPP_ABI_DEFINES)
888 if (LIBCXX_EXTRA_SITE_DEFINES)
889 set(extra_site_defines)
890 foreach (extra_site_define ${LIBCXX_EXTRA_SITE_DEFINES})
891 # Allow defines such as DEFINE=VAL, transformed into "#define DEFINE VAL".
892 string(REPLACE "=" " " extra_site_define "${extra_site_define}")
893 list(APPEND extra_site_defines "#define ${extra_site_define}")
895 string(REPLACE ";" "\n" extra_site_defines "${extra_site_defines}")
896 config_define(${extra_site_defines} _LIBCPP_EXTRA_SITE_DEFINES)
899 # By default libc++ on Windows expects to use a shared library, which requires
900 # the headers to use DLL import/export semantics. However when building a
901 # static library only we modify the headers to disable DLL import/export.
902 if (DEFINED WIN32 AND LIBCXX_ENABLE_STATIC AND NOT LIBCXX_ENABLE_SHARED)
903 message(STATUS "Generating custom __config for non-DLL Windows build")
904 config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
907 if (WIN32 AND LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
908 # If linking libcxxabi statically into libcxx, skip the dllimport attributes
909 # on symbols we refer to from libcxxabi.
910 add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS)
913 # Setup all common build flags =================================================
914 function(cxx_add_common_build_flags target)
915 cxx_add_basic_build_flags(${target})
916 cxx_add_warning_flags(${target})
917 cxx_add_windows_flags(${target})
918 cxx_add_exception_flags(${target})
919 cxx_add_rtti_flags(${target})
920 cxx_add_module_flags(${target})
921 cxx_link_system_libraries(${target})
924 #===============================================================================
925 # Setup Source Code And Tests
926 #===============================================================================
927 add_subdirectory(include)
928 add_subdirectory(src)
929 add_subdirectory(utils)
931 set(LIBCXX_TEST_DEPS "")
933 if (LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY)
934 list(APPEND LIBCXX_TEST_DEPS cxx_experimental)
937 if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY)
938 list(APPEND LIBCXX_TEST_DEPS cxx_external_threads)
941 if (LIBCXX_INCLUDE_BENCHMARKS)
942 add_subdirectory(benchmarks)
945 if (LIBCXX_INCLUDE_TESTS)
946 add_subdirectory(test)
947 add_subdirectory(lib/abi)
950 if (LIBCXX_INCLUDE_DOCS)
951 add_subdirectory(docs)