1 # See https://libcxx.llvm.org/docs/BuildingLibcxx.html for instructions on how
2 # to build libcxx with CMake.
4 if (NOT IS_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/../libcxxabi")
5 message(FATAL_ERROR "libc++ now requires being built in a monorepo layout with libcxxabi available")
8 #===============================================================================
10 #===============================================================================
11 cmake_minimum_required(VERSION 3.13.4)
13 # Add path for custom modules
15 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
16 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
17 "${CMAKE_CURRENT_SOURCE_DIR}/../cmake"
18 "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules"
22 set(CMAKE_FOLDER "libc++")
24 set(LIBCXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
25 set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
26 set(LIBCXX_BINARY_INCLUDE_DIR "${LIBCXX_BINARY_DIR}/include/c++build")
28 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXX_STANDALONE_BUILD)
31 set(PACKAGE_NAME libcxx)
32 set(PACKAGE_VERSION 14.0.0git)
33 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
34 set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org")
36 # In a standalone build, we don't have llvm to automatically generate the
37 # llvm-lit script for us. So we need to provide an explicit directory that
38 # the configurator should write the script into.
39 set(LIBCXX_STANDALONE_BUILD 1)
40 set(LLVM_LIT_OUTPUT_DIR "${LIBCXX_BINARY_DIR}/bin")
42 # Find the LLVM sources and simulate LLVM CMake options.
43 include(HandleOutOfTreeLLVM)
46 if (LIBCXX_STANDALONE_BUILD)
47 find_package(Python3 COMPONENTS Interpreter)
48 if(NOT Python3_Interpreter_FOUND)
49 message(SEND_ERROR "Python3 not found. Python3 is required")
53 # Require out of source build.
54 include(MacroEnsureOutOfSourceBuild)
55 MACRO_ENSURE_OUT_OF_SOURCE_BUILD(
56 "${PROJECT_NAME} requires an out of source build. Please create a separate
57 build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there."
59 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
60 message(STATUS "Configuring for clang-cl")
61 set(LIBCXX_TARGETING_CLANG_CL ON)
65 set(LIBCXX_TARGETING_MSVC ON)
66 message(STATUS "Configuring for MSVC")
68 set(LIBCXX_TARGETING_MSVC OFF)
71 #===============================================================================
73 #===============================================================================
74 include(CMakeDependentOption)
75 include(HandleCompilerRT)
77 # Basic options ---------------------------------------------------------------
78 option(LIBCXX_ENABLE_ASSERTIONS "Enable assertions independent of build mode." OFF)
79 option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON)
80 option(LIBCXX_ENABLE_STATIC "Build libc++ as a static library." ON)
81 option(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY "Build libc++experimental.a" ON)
82 set(ENABLE_FILESYSTEM_DEFAULT ON)
83 if (WIN32 AND NOT MINGW)
84 # Filesystem is buildable for windows, but it requires __int128 helper
85 # functions, that currently are provided by libgcc or compiler_rt builtins.
86 # These are available in MinGW environments, but not currently in MSVC
88 set(ENABLE_FILESYSTEM_DEFAULT OFF)
90 option(LIBCXX_ENABLE_FILESYSTEM "Build filesystem as part of the main libc++ library"
91 ${ENABLE_FILESYSTEM_DEFAULT})
92 option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS})
93 option(LIBCXX_ENABLE_PARALLEL_ALGORITHMS "Enable the parallel algorithms library. This requires the PSTL to be available." OFF)
94 option(LIBCXX_ENABLE_DEBUG_MODE_SUPPORT
95 "Whether to include support for libc++'s debugging mode in the library.
96 By default, this is turned on. If you turn it off and try to enable the
97 debug mode when compiling a program against libc++, it will fail to link
98 since the required support isn't provided in the library." ON)
99 option(LIBCXX_ENABLE_RANDOM_DEVICE
100 "Whether to include support for std::random_device in the library. Disabling
101 this can be useful when building the library for platforms that don't have
102 a source of randomness, such as some embedded platforms. When this is not
103 supported, most of <random> will still be available, but std::random_device
105 option(LIBCXX_ENABLE_LOCALIZATION
106 "Whether to include support for localization in the library. Disabling
107 localization can be useful when porting to platforms that don't support
108 the C locale API (e.g. embedded). When localization is not supported,
109 several parts of the library will be disabled: <iostream>, <regex>, <locale>
110 will be completely unusable, and other parts may be only partly available." ON)
111 option(LIBCXX_ENABLE_UNICODE
112 "Whether to include support for Unicode in the library. Disabling Unicode can
113 be useful when porting to platforms that don't support UTF-8 encoding (e.g.
115 option(LIBCXX_ENABLE_WIDE_CHARACTERS
116 "Whether to include support for wide characters in the library. Disabling
117 wide character support can be useful when porting to platforms that don't
118 support the C functionality for wide characters. When wide characters are
119 not supported, several parts of the library will be disabled, notably the
120 wide character specializations of std::basic_string." ON)
121 option(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS
122 "Whether to turn on vendor availability annotations on declarations that depend
123 on definitions in a shared library. By default, we assume that we're not building
124 libc++ for any specific vendor, and we disable those annotations. Vendors wishing
125 to provide compile-time errors when using features unavailable on some version of
126 the shared library they shipped should turn this on and see `include/__availability`
127 for more details." OFF)
128 option(LIBCXX_ENABLE_INCOMPLETE_FEATURES
129 "Whether to enable support for incomplete library features. Incomplete features
130 are new library features under development. These features don't guarantee
131 ABI stability nor the quality of completed library features. Vendors
132 shipping the library may want to disable this option." ON)
133 set(LIBCXX_TEST_CONFIG "legacy.cfg.in" CACHE STRING
134 "The path to the Lit testing configuration to use when running the tests.
135 If a relative path is provided, it is assumed to be relative to '<monorepo>/libcxx/test/configs'.")
136 if (NOT IS_ABSOLUTE "${LIBCXX_TEST_CONFIG}")
137 set(LIBCXX_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/configs/${LIBCXX_TEST_CONFIG}")
139 set(LIBCXX_TEST_PARAMS "" CACHE STRING
140 "A list of parameters to run the Lit test suite with.")
142 # Benchmark options -----------------------------------------------------------
143 option(LIBCXX_INCLUDE_BENCHMARKS "Build the libc++ benchmarks and their dependencies" ON)
145 set(LIBCXX_BENCHMARK_TEST_ARGS_DEFAULT --benchmark_min_time=0.01)
146 set(LIBCXX_BENCHMARK_TEST_ARGS "${LIBCXX_BENCHMARK_TEST_ARGS_DEFAULT}" CACHE STRING
147 "Arguments to pass when running the benchmarks using check-cxx-benchmarks")
149 set(LIBCXX_BENCHMARK_NATIVE_STDLIB "" CACHE STRING
150 "Build the benchmarks against the specified native STL.
151 The value must be one of libc++/libstdc++")
152 set(LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN "" CACHE STRING
153 "Use alternate GCC toolchain when building the native benchmarks")
155 if (LIBCXX_BENCHMARK_NATIVE_STDLIB)
156 if (NOT (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libc++"
157 OR LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libstdc++"))
158 message(FATAL_ERROR "Invalid value for LIBCXX_BENCHMARK_NATIVE_STDLIB: "
159 "'${LIBCXX_BENCHMARK_NATIVE_STDLIB}'")
163 option(LIBCXX_INCLUDE_DOCS "Build the libc++ documentation." ${LLVM_INCLUDE_DOCS})
164 set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
165 "Define suffix of library directory name (32/64)")
166 option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON)
167 option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON)
168 cmake_dependent_option(LIBCXX_INSTALL_STATIC_LIBRARY
169 "Install the static libc++ library." ON
170 "LIBCXX_ENABLE_STATIC;LIBCXX_INSTALL_LIBRARY" OFF)
171 cmake_dependent_option(LIBCXX_INSTALL_SHARED_LIBRARY
172 "Install the shared libc++ library." ON
173 "LIBCXX_ENABLE_SHARED;LIBCXX_INSTALL_LIBRARY" OFF)
174 cmake_dependent_option(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY
175 "Install libc++experimental.a" ON
176 "LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY;LIBCXX_INSTALL_LIBRARY" OFF)
178 set(LIBCXX_ABI_VERSION "1" CACHE STRING "ABI version of libc++. Can be either 1 or 2, where 2 is currently not stable. Defaults to 1.")
179 set(LIBCXX_ABI_NAMESPACE "" CACHE STRING "The inline ABI namespace used by libc++. It defaults to __n where `n` is the current ABI version.")
180 option(LIBCXX_ABI_UNSTABLE "Unstable ABI of libc++." OFF)
181 option(LIBCXX_ABI_FORCE_ITANIUM "Ignore auto-detection and force use of the Itanium ABI.")
182 option(LIBCXX_ABI_FORCE_MICROSOFT "Ignore auto-detection and force use of the Microsoft ABI.")
184 set(LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION "default" CACHE STRING
185 "Override the implementation to use for comparing typeinfos. By default, this
186 is detected automatically by the library, but this option allows overriding
187 which implementation is used unconditionally.
189 See the documentation in <libcxx/include/typeinfo> for details on what each
191 set(TYPEINFO_COMPARISON_VALUES "default;1;2;3")
192 if (NOT ("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" IN_LIST TYPEINFO_COMPARISON_VALUES))
193 message(FATAL_ERROR "Value '${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}' is not a valid value for
194 LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION")
197 option(LIBCXX_HIDE_FROM_ABI_PER_TU_BY_DEFAULT "Enable per TU ABI insulation by default. To be used by vendors." OFF)
198 set(LIBCXX_ABI_DEFINES "" CACHE STRING "A semicolon separated list of ABI macros to define in the site config header.")
199 option(LIBCXX_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
200 set(LIBCXX_LIBCPPABI_VERSION "2" CACHE STRING "Version of libc++abi's ABI to re-export from libc++ when re-exporting is enabled.
201 Note that this is not related to the version of libc++'s ABI itself!")
203 # ABI Library options ---------------------------------------------------------
204 set(LIBCXX_CXX_ABI "default" CACHE STRING "Specify C++ ABI library to use.")
205 set(CXXABIS none default libcxxabi libcxxrt libstdc++ libsupc++ vcruntime)
206 set_property(CACHE LIBCXX_CXX_ABI PROPERTY STRINGS ;${CXXABIS})
208 # Setup the default options if LIBCXX_CXX_ABI is not specified.
209 if (LIBCXX_CXX_ABI STREQUAL "default")
210 if (LIBCXX_TARGETING_MSVC)
211 # FIXME: Figure out how to configure the ABI library on Windows.
212 set(LIBCXX_CXX_ABI_LIBNAME "vcruntime")
213 elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
214 set(LIBCXX_CXX_ABI_LIBNAME "libcxxrt")
215 elseif (NOT LIBCXX_STANDALONE_BUILD OR HAVE_LIBCXXABI)
216 set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi")
218 set(LIBCXX_CXX_ABI_LIBNAME "default")
221 set(LIBCXX_CXX_ABI_LIBNAME "${LIBCXX_CXX_ABI}")
224 option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY
225 "Use a static copy of the ABI library when linking libc++.
226 This option cannot be used with LIBCXX_ENABLE_ABI_LINKER_SCRIPT." OFF)
228 cmake_dependent_option(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY
229 "Statically link the ABI library to static library" ON
230 "LIBCXX_ENABLE_STATIC_ABI_LIBRARY;LIBCXX_ENABLE_STATIC" OFF)
232 cmake_dependent_option(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY
233 "Statically link the ABI library to shared library" ON
234 "LIBCXX_ENABLE_STATIC_ABI_LIBRARY;LIBCXX_ENABLE_SHARED" OFF)
236 # Generate and install a linker script inplace of libc++.so. The linker script
237 # will link libc++ to the correct ABI library. This option is on by default
238 # on UNIX platforms other than Apple unless 'LIBCXX_ENABLE_STATIC_ABI_LIBRARY'
239 # is on. This option is also disabled when the ABI library is not specified
240 # or is specified to be "none".
241 set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF)
242 if (LLVM_HAVE_LINK_VERSION_SCRIPT AND NOT LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY
243 AND NOT LIBCXX_CXX_ABI_LIBNAME STREQUAL "none"
244 AND NOT LIBCXX_CXX_ABI_LIBNAME STREQUAL "default"
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 if(CMAKE_CXX_COMPILER_TARGET)
270 set(LIBCXX_DEFAULT_TARGET_TRIPLE "${CMAKE_CXX_COMPILER_TARGET}")
272 set(LIBCXX_DEFAULT_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
274 set(LIBCXX_TARGET_TRIPLE "${LIBCXX_DEFAULT_TARGET_TRIPLE}" CACHE STRING "Use alternate target triple.")
275 set(LIBCXX_SYSROOT "${CMAKE_SYSROOT}" CACHE STRING "Use alternate sysroot.")
276 set(LIBCXX_GCC_TOOLCHAIN "${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}" CACHE STRING "Use alternate GCC toolchain.")
278 # Feature options -------------------------------------------------------------
279 option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON)
280 option(LIBCXX_ENABLE_RTTI "Use run time type information." ON)
281 option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON)
282 option(LIBCXX_ENABLE_MONOTONIC_CLOCK
283 "Build libc++ with support for a monotonic clock.
284 This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON)
285 option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF)
286 option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF)
287 option(LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32 thread API" OFF)
288 option(LIBCXX_HAS_EXTERNAL_THREAD_API
289 "Build libc++ with an externalized threading API.
290 This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF)
291 option(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY
292 "Build libc++ with an externalized threading library.
293 This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON" OFF)
295 # Misc options ----------------------------------------------------------------
296 # FIXME: Turn -pedantic back ON. It is currently off because it warns
297 # about #include_next which is used everywhere.
298 option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF)
299 option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
300 option(LIBCXX_DISABLE_MACRO_CONFLICT_WARNINGS "Disable #warnings about conflicting macros." OFF)
302 option(LIBCXX_GENERATE_COVERAGE "Enable generating code coverage." OFF)
303 set(LIBCXX_COVERAGE_LIBRARY "" CACHE STRING
304 "The Profile-rt library used to build with code coverage")
306 set(LIBCXX_CONFIGURE_IDE_DEFAULT OFF)
307 if (XCODE OR MSVC_IDE)
308 set(LIBCXX_CONFIGURE_IDE_DEFAULT ON)
310 option(LIBCXX_CONFIGURE_IDE "Configure libcxx for use within an IDE"
311 ${LIBCXX_CONFIGURE_IDE_DEFAULT})
313 option(LIBCXX_HERMETIC_STATIC_LIBRARY
314 "Do not export any symbols from the static library." OFF)
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 # Warn users that LIBCXX_ENABLE_STATIC_ABI_LIBRARY is an experimental option.
380 if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
381 message(WARNING "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is an experimental option")
382 if (LIBCXX_ENABLE_STATIC AND NOT Python3_EXECUTABLE)
383 message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY requires python but it was not found.")
387 if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
389 message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT cannot be used on APPLE targets")
391 if (NOT LIBCXX_ENABLE_SHARED)
392 message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT is only available for shared library builds.")
396 if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
397 message(FATAL_ERROR "Conflicting options given.
398 LIBCXX_ENABLE_STATIC_ABI_LIBRARY cannot be specified with
399 LIBCXX_ENABLE_ABI_LINKER_SCRIPT")
402 if (LIBCXX_ABI_FORCE_ITANIUM AND LIBCXX_ABI_FORCE_MICROSOFT)
403 message(FATAL_ERROR "Only one of LIBCXX_ABI_FORCE_ITANIUM and LIBCXX_ABI_FORCE_MICROSOFT can be specified.")
406 #===============================================================================
408 #===============================================================================
410 # TODO: Projects that depend on libc++ should use LIBCXX_GENERATED_INCLUDE_DIR
411 # instead of hard-coding include/c++/v1.
412 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
413 set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
414 set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
415 set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1")
416 set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH
417 "Path where built libc++ libraries should be installed.")
418 set(LIBCXX_INSTALL_RUNTIME_DIR bin CACHE PATH
419 "Path where built libc++ runtime libraries should be installed.")
420 set(LIBCXX_INSTALL_INCLUDE_DIR "include/c++/v1" CACHE PATH
421 "Path where target-agnostic libc++ headers should be installed.")
422 set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1" CACHE PATH
423 "Path where target-specific libc++ headers should be installed.")
424 if(LIBCXX_LIBDIR_SUBDIR)
425 string(APPEND LIBCXX_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR})
426 string(APPEND LIBCXX_INSTALL_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR})
428 elseif(LLVM_LIBRARY_OUTPUT_INTDIR)
429 set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
430 set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
431 set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}")
432 set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX} CACHE PATH
433 "Path where built libc++ libraries should be installed.")
434 set(LIBCXX_INSTALL_RUNTIME_DIR bin CACHE PATH
435 "Path where built libc++ runtime libraries should be installed.")
436 set(LIBCXX_INSTALL_INCLUDE_DIR "include/c++/v1" CACHE PATH
437 "Path where target-agnostic libc++ headers should be installed.")
438 set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${LIBCXX_INSTALL_INCLUDE_DIR}" CACHE PATH
439 "Path where target-specific libc++ headers should be installed.")
441 set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
442 set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1")
443 set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}")
444 set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX} CACHE PATH
445 "Path where built libc++ libraries should be installed.")
446 set(LIBCXX_INSTALL_RUNTIME_DIR bin CACHE PATH
447 "Path where built libc++ runtime libraries should be installed.")
448 set(LIBCXX_INSTALL_INCLUDE_DIR "include/c++/v1" CACHE PATH
449 "Path where target-agnostic libc++ headers 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'
477 if(LIBCXX_TARGET_TRIPLE)
478 add_target_flags_if_supported("--target=${LIBCXX_TARGET_TRIPLE}")
481 add_target_flags_if_supported("--sysroot=${LIBCXX_SYSROOT}")
483 if(LIBCXX_GCC_TOOLCHAIN)
484 add_target_flags_if_supported("--gcc-toolchain=${LIBCXX_GCC_TOOLCHAIN}")
487 # Configure compiler.
490 # Configure coverage options.
491 if (LIBCXX_GENERATE_COVERAGE)
492 include(CodeCoverage)
493 set(CMAKE_BUILD_TYPE "COVERAGE" CACHE STRING "" FORCE)
496 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
497 if (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
498 set(LIBCXX_DEBUG_BUILD ON)
500 set(LIBCXX_DEBUG_BUILD OFF)
503 #===============================================================================
504 # Setup Compiler Flags
505 #===============================================================================
507 include(HandleLibCXXABI) # Setup the ABI library flags
509 if (NOT LIBCXX_STANDALONE_BUILD)
510 # Remove flags that may have snuck in.
511 remove_flags(-DNDEBUG -UNDEBUG -D_DEBUG
514 remove_flags(--stdlib=libc++ -stdlib=libc++ --stdlib=libstdc++ -stdlib=libstdc++)
516 # FIXME: Remove all debug flags and flags that change which Windows
517 # default libraries are linked. Currently we only support linking the
519 remove_flags("/D_DEBUG" "/MTd" "/MDd" "/MT" "/Md")
521 # FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC.
522 # Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors
523 # so they don't get transformed into -Wno and -errors respectively.
524 remove_flags(-Wno-pedantic -pedantic-errors -pedantic)
526 # Required flags ==============================================================
527 function(cxx_add_basic_build_flags target)
529 # Require C++20 for all targets. C++17 is needed to use aligned allocation
530 # in the dylib. C++20 is needed to use char8_t.
531 set_target_properties(${target} PROPERTIES
533 CXX_STANDARD_REQUIRED YES
536 # When building the dylib, don't warn for unavailable aligned allocation
537 # functions based on the deployment target -- they are always available
538 # because they are provided by the dylib itself with the excepton of z/OS.
540 target_add_compile_flags_if_supported(${target} PRIVATE -fno-aligned-allocation)
542 target_add_compile_flags_if_supported(${target} PRIVATE -faligned-allocation)
545 # On all systems the system c++ standard library headers need to be excluded.
546 # MSVC only has -X, which disables all default includes; including the crt.
547 # Thus, we do nothing and hope we don't accidentally include any of the C++
549 target_add_compile_flags_if_supported(${target} PUBLIC -nostdinc++)
551 # Hide all inline function definitions which have not explicitly been marked
552 # visible. This prevents new definitions for inline functions from appearing in
553 # the dylib when get ODR used by another function.
554 target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility-inlines-hidden)
556 # Our visibility annotations are not quite right for non-Clang compilers,
557 # so we end up not exporting all the symbols we should. In the future, we
558 # can improve the situation by providing an explicit list of exported
559 # symbols on all compilers.
560 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
561 target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility=hidden)
564 if (LIBCXX_CONFIGURE_IDE)
565 # This simply allows IDE to process <experimental/coroutine>
566 target_add_compile_flags_if_supported(${target} PRIVATE -fcoroutines-ts)
569 # Let the library headers know they are currently being used to build the
571 target_compile_definitions(${target} PRIVATE -D_LIBCPP_BUILDING_LIBRARY)
573 if (NOT LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS)
574 target_compile_definitions(${target} PRIVATE -D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS)
577 if (LIBCXX_HAS_COMMENT_LIB_PRAGMA)
578 if (LIBCXX_HAS_PTHREAD_LIB)
579 target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_PTHREAD_LIB)
581 if (LIBCXX_HAS_RT_LIB)
582 target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_RT_LIB)
587 # Warning flags ===============================================================
588 function(cxx_add_warning_flags target)
589 target_compile_definitions(${target} PUBLIC -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
591 # -W4 is the cl.exe/clang-cl equivalent of -Wall. (In cl.exe and clang-cl,
592 # -Wall is equivalent to -Weverything in GCC style compiler drivers.)
593 target_add_compile_flags_if_supported(${target} PRIVATE -W4)
595 target_add_compile_flags_if_supported(${target} PRIVATE -Wall)
597 target_add_compile_flags_if_supported(${target} PRIVATE -Wextra -W -Wwrite-strings
598 -Wno-unused-parameter -Wno-long-long
599 -Werror=return-type -Wextra-semi -Wundef
601 if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
602 target_add_compile_flags_if_supported(${target} PRIVATE
603 -Wno-user-defined-literals
604 -Wno-covered-switch-default
605 -Wno-suggest-override
607 if (LIBCXX_TARGETING_CLANG_CL)
608 target_add_compile_flags_if_supported(${target} PRIVATE
610 -Wno-c++98-compat-pedantic
613 -Wno-reserved-id-macro
614 -Wno-gnu-include-next
615 -Wno-gcc-compat # For ignoring "'diagnose_if' is a clang extension" warnings
616 -Wno-zero-as-null-pointer-constant # FIXME: Remove this and fix all occurrences.
617 -Wno-deprecated-dynamic-exception-spec # For auto_ptr
620 -Wno-deprecated # FIXME: Remove this and fix all occurrences.
621 -Wno-shift-sign-overflow # FIXME: Why do we need this with clang-cl but not clang?
622 -Wno-double-promotion # FIXME: remove me
625 elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
626 target_add_compile_flags_if_supported(${target} PRIVATE
630 -Wno-suggest-override)
632 if (LIBCXX_ENABLE_WERROR)
633 target_add_compile_flags_if_supported(${target} PRIVATE -Werror)
634 target_add_compile_flags_if_supported(${target} PRIVATE -WX)
636 # TODO(EricWF) Remove this. We shouldn't be suppressing errors when -Werror is
638 target_add_compile_flags_if_supported(${target} PRIVATE -Wno-error)
640 if (LIBCXX_ENABLE_PEDANTIC)
641 target_add_compile_flags_if_supported(${target} PRIVATE -pedantic)
643 if (LIBCXX_DISABLE_MACRO_CONFLICT_WARNINGS)
644 target_compile_definitions(${target} PRIVATE -D_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS)
648 # Exception flags =============================================================
649 function(cxx_add_exception_flags target)
650 if (LIBCXX_ENABLE_EXCEPTIONS)
651 # Catches C++ exceptions only and tells the compiler to assume that extern C
652 # functions never throw a C++ exception.
653 target_add_compile_flags_if_supported(${target} PUBLIC -EHsc)
655 target_add_compile_flags_if_supported(${target} PUBLIC -EHs- -EHa-)
656 target_add_compile_flags_if_supported(${target} PUBLIC -fno-exceptions)
660 # RTTI flags ==================================================================
661 function(cxx_add_rtti_flags target)
662 if (NOT LIBCXX_ENABLE_RTTI)
663 target_add_compile_flags_if_supported(${target} PUBLIC -GR-)
664 target_add_compile_flags_if_supported(${target} PUBLIC -fno-rtti)
668 # Threading flags =============================================================
669 if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY AND LIBCXX_ENABLE_SHARED)
670 # Need to allow unresolved symbols if this is to work with shared library builds
672 add_link_flags("-undefined dynamic_lookup")
674 # Relax this restriction from HandleLLVMOptions
675 string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
679 # Assertion flags =============================================================
680 define_if(LIBCXX_ENABLE_ASSERTIONS -UNDEBUG)
681 define_if_not(LIBCXX_ENABLE_ASSERTIONS -DNDEBUG)
682 define_if(LIBCXX_ENABLE_ASSERTIONS -D_LIBCPP_DEBUG=0)
683 define_if(LIBCXX_DEBUG_BUILD -D_DEBUG)
684 if (LIBCXX_ENABLE_ASSERTIONS AND NOT LIBCXX_DEBUG_BUILD)
685 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
686 define_if_not(LIBCXX_TARGETING_MSVC -D_DEBUG)
689 # Modules flags ===============================================================
690 # FIXME The libc++ sources are fundamentally non-modular. They need special
691 # versions of the headers in order to provide C++03 and legacy ABI definitions.
692 # NOTE: The public headers can be used with modules in all other contexts.
693 function(cxx_add_module_flags target)
694 if (LLVM_ENABLE_MODULES)
695 # Ignore that the rest of the modules flags are now unused.
696 target_add_compile_flags_if_supported(${target} PUBLIC -Wno-unused-command-line-argument)
697 target_compile_options(${target} PUBLIC -fno-modules)
701 # Sanitizer flags =============================================================
703 function(get_sanitizer_flags OUT_VAR USE_SANITIZER)
705 set(USE_SANITIZER "${USE_SANITIZER}")
706 # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC.
707 # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do.
708 if (USE_SANITIZER AND NOT MSVC)
709 append_flags_if_supported(SANITIZER_FLAGS "-fno-omit-frame-pointer")
710 append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only")
712 if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND
713 NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
714 append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only")
716 if (USE_SANITIZER STREQUAL "Address")
717 append_flags(SANITIZER_FLAGS "-fsanitize=address")
718 elseif (USE_SANITIZER MATCHES "Memory(WithOrigins)?")
719 append_flags(SANITIZER_FLAGS -fsanitize=memory)
720 if (USE_SANITIZER STREQUAL "MemoryWithOrigins")
721 append_flags(SANITIZER_FLAGS "-fsanitize-memory-track-origins")
723 elseif (USE_SANITIZER STREQUAL "Undefined")
724 append_flags(SANITIZER_FLAGS "-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all")
725 elseif (USE_SANITIZER STREQUAL "Address;Undefined" OR
726 USE_SANITIZER STREQUAL "Undefined;Address")
727 append_flags(SANITIZER_FLAGS "-fsanitize=address,undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all")
728 elseif (USE_SANITIZER STREQUAL "Thread")
729 append_flags(SANITIZER_FLAGS -fsanitize=thread)
730 elseif (USE_SANITIZER STREQUAL "DataFlow")
731 append_flags(SANITIZER_FLAGS -fsanitize=dataflow)
733 message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${USE_SANITIZER}")
735 elseif(USE_SANITIZER AND MSVC)
736 message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.")
738 set(${OUT_VAR} "${SANITIZER_FLAGS}" PARENT_SCOPE)
741 # Configure for sanitizers. If LIBCXX_STANDALONE_BUILD then we have to do
742 # the flag translation ourselves. Othewise LLVM's CMakeList.txt will handle it.
743 if (LIBCXX_STANDALONE_BUILD)
744 set(LLVM_USE_SANITIZER "" CACHE STRING
745 "Define the sanitizer used to build the library and tests")
747 get_sanitizer_flags(SANITIZER_FLAGS "${LLVM_USE_SANITIZER}")
748 if (LIBCXX_STANDALONE_BUILD AND SANITIZER_FLAGS)
749 add_flags(${SANITIZER_FLAGS})
752 # Link system libraries =======================================================
753 function(cxx_link_system_libraries target)
755 # In order to remove just libc++ from the link step
756 # we need to use -nostdlib++ whenever it is supported.
757 # Unfortunately this cannot be used universally because for example g++ supports
758 # only -nodefaultlibs in which case all libraries will be removed and
759 # all libraries but c++ have to be added in manually.
760 if (LIBCXX_SUPPORTS_NOSTDLIBXX_FLAG)
761 target_add_link_flags_if_supported(${target} PRIVATE "-nostdlib++")
763 target_add_link_flags_if_supported(${target} PRIVATE "-nodefaultlibs")
764 target_add_compile_flags_if_supported(${target} PRIVATE "/Zl")
765 target_add_link_flags_if_supported(${target} PRIVATE "/nodefaultlib")
768 if (LIBCXX_SUPPORTS_UNWINDLIB_NONE_FLAG AND LIBCXXABI_USE_LLVM_UNWINDER)
769 # If we're linking directly against the libunwind that we're building
770 # in the same invocation, don't try to link in the toolchain's
771 # default libunwind (which may be missing still).
772 target_add_link_flags_if_supported(${target} PRIVATE "--unwindlib=none")
775 if (LIBCXX_HAS_SYSTEM_LIB)
776 target_link_libraries(${target} PRIVATE System)
779 if (LIBCXX_HAS_PTHREAD_LIB)
780 target_link_libraries(${target} PRIVATE pthread)
783 if (LIBCXX_HAS_C_LIB)
784 target_link_libraries(${target} PRIVATE c)
787 if (LIBCXX_HAS_M_LIB)
788 target_link_libraries(${target} PRIVATE m)
791 if (LIBCXX_HAS_RT_LIB)
792 target_link_libraries(${target} PRIVATE rt)
795 if (LIBCXX_USE_COMPILER_RT)
796 find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY)
797 if (LIBCXX_BUILTINS_LIBRARY)
798 target_link_libraries(${target} PRIVATE "${LIBCXX_BUILTINS_LIBRARY}")
800 elseif (LIBCXX_HAS_GCC_LIB)
801 target_link_libraries(${target} PRIVATE gcc)
802 elseif (LIBCXX_HAS_GCC_S_LIB)
803 target_link_libraries(${target} PRIVATE gcc_s)
806 if (LIBCXX_HAS_ATOMIC_LIB)
807 target_link_libraries(${target} PRIVATE atomic)
811 target_link_libraries(${target} PRIVATE "${MINGW_LIBRARIES}")
814 if (LIBCXX_TARGETING_MSVC)
815 if (LIBCXX_DEBUG_BUILD)
821 target_link_libraries(${target} PRIVATE ucrt${LIB_SUFFIX}) # Universal C runtime
822 target_link_libraries(${target} PRIVATE vcruntime${LIB_SUFFIX}) # C++ runtime
823 target_link_libraries(${target} PRIVATE msvcrt${LIB_SUFFIX}) # C runtime startup files
824 target_link_libraries(${target} PRIVATE msvcprt${LIB_SUFFIX}) # C++ standard library. Required for exception_ptr internals.
825 # Required for standards-complaint wide character formatting functions
826 # (e.g. `printfw`/`scanfw`)
827 target_link_libraries(${target} PRIVATE iso_stdio_wide_specifiers)
830 if (ANDROID AND ANDROID_PLATFORM_LEVEL LESS 21)
831 target_link_libraries(${target} PUBLIC android_support)
835 # Windows-related flags =======================================================
836 function(cxx_add_windows_flags target)
837 if(WIN32 AND NOT MINGW)
838 target_compile_definitions(${target} PRIVATE
839 # Ignore the -MSC_VER mismatch, as we may build
840 # with a different compatibility version.
841 _ALLOW_MSC_VER_MISMATCH
842 # Don't check the msvcprt iterator debug levels
843 # as we will define the iterator types; libc++
844 # uses a different macro to identify the debug
846 _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH
847 # We are building the c++ runtime, don't pull in
850 # Don't warn on the use of "deprecated"
851 # "insecure" functions which are standards
853 _CRT_SECURE_NO_WARNINGS
854 # Use the ISO conforming behaviour for conversion
856 _CRT_STDIO_ISO_WIDE_SPECIFIERS)
860 # Configuration file flags =====================================================
861 if (NOT LIBCXX_ABI_VERSION EQUAL 1)
862 config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION)
864 if (NOT LIBCXX_ABI_NAMESPACE STREQUAL "")
865 if (NOT LIBCXX_ABI_NAMESPACE MATCHES "__.*")
866 message(FATAL_ERROR "LIBCXX_ABI_NAMESPACE must be a reserved identifier.")
868 if (LIBCXX_ABI_NAMESPACE MATCHES "__[0-9]+$")
869 message(FATAL_ERROR "LIBCXX_ABI_NAMESPACE '${LIBCXX_ABI_NAMESPACE}' is reserved for use by libc++.")
871 config_define(${LIBCXX_ABI_NAMESPACE} _LIBCPP_ABI_NAMESPACE)
873 config_define_if(LIBCXX_ABI_UNSTABLE _LIBCPP_ABI_UNSTABLE)
874 config_define_if(LIBCXX_ABI_FORCE_ITANIUM _LIBCPP_ABI_FORCE_ITANIUM)
875 config_define_if(LIBCXX_ABI_FORCE_MICROSOFT _LIBCPP_ABI_FORCE_MICROSOFT)
876 config_define_if(LIBCXX_HIDE_FROM_ABI_PER_TU_BY_DEFAULT _LIBCPP_HIDE_FROM_ABI_PER_TU_BY_DEFAULT)
877 config_define_if_not(LIBCXX_ENABLE_THREADS _LIBCPP_HAS_NO_THREADS)
878 config_define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK _LIBCPP_HAS_NO_MONOTONIC_CLOCK)
879 if (NOT LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION STREQUAL "default")
880 config_define("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION)
882 config_define_if(LIBCXX_HAS_PTHREAD_API _LIBCPP_HAS_THREAD_API_PTHREAD)
883 config_define_if(LIBCXX_HAS_EXTERNAL_THREAD_API _LIBCPP_HAS_THREAD_API_EXTERNAL)
884 config_define_if(LIBCXX_HAS_WIN32_THREAD_API _LIBCPP_HAS_THREAD_API_WIN32)
885 config_define_if(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL)
886 config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC)
887 config_define_if(LIBCXX_NO_VCRUNTIME _LIBCPP_NO_VCRUNTIME)
888 config_define_if(LIBCXX_ENABLE_PARALLEL_ALGORITHMS _LIBCPP_HAS_PARALLEL_ALGORITHMS)
889 config_define_if_not(LIBCXX_ENABLE_FILESYSTEM _LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)
890 config_define_if_not(LIBCXX_ENABLE_RANDOM_DEVICE _LIBCPP_HAS_NO_RANDOM_DEVICE)
891 config_define_if_not(LIBCXX_ENABLE_LOCALIZATION _LIBCPP_HAS_NO_LOCALIZATION)
892 config_define_if_not(LIBCXX_ENABLE_UNICODE _LIBCPP_HAS_NO_UNICODE)
893 config_define_if_not(LIBCXX_ENABLE_WIDE_CHARACTERS _LIBCPP_HAS_NO_WIDE_CHARACTERS)
894 config_define_if_not(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)
895 # Incomplete features get their own specific disabling flags. This makes it
896 # easier to grep for target specific flags once the feature is complete.
897 config_define_if_not(LIBCXX_ENABLE_INCOMPLETE_FEATURES _LIBCPP_HAS_NO_INCOMPLETE_FORMAT)
898 config_define_if_not(LIBCXX_ENABLE_INCOMPLETE_FEATURES _LIBCPP_HAS_NO_INCOMPLETE_RANGES)
900 if (LIBCXX_ABI_DEFINES)
902 foreach (abi_define ${LIBCXX_ABI_DEFINES})
903 if (NOT abi_define MATCHES "^_LIBCPP_ABI_")
904 message(SEND_ERROR "Invalid ABI macro ${abi_define} in LIBCXX_ABI_DEFINES")
906 list(APPEND abi_defines "#define ${abi_define}")
908 string(REPLACE ";" "\n" abi_defines "${abi_defines}")
909 config_define(${abi_defines} _LIBCPP_ABI_DEFINES)
912 # By default libc++ on Windows expects to use a shared library, which requires
913 # the headers to use DLL import/export semantics. However when building a
914 # static library only we modify the headers to disable DLL import/export.
915 if (DEFINED WIN32 AND LIBCXX_ENABLE_STATIC AND NOT LIBCXX_ENABLE_SHARED)
916 message(STATUS "Generating custom __config for non-DLL Windows build")
917 config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
920 if (WIN32 AND LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
921 # If linking libcxxabi statically into libcxx, skip the dllimport attributes
922 # on symbols we refer to from libcxxabi.
923 add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS)
926 # Setup all common build flags =================================================
927 function(cxx_add_common_build_flags target)
928 cxx_add_basic_build_flags(${target})
929 cxx_add_warning_flags(${target})
930 cxx_add_windows_flags(${target})
931 cxx_add_exception_flags(${target})
932 cxx_add_rtti_flags(${target})
933 cxx_add_module_flags(${target})
934 cxx_link_system_libraries(${target})
937 #===============================================================================
938 # Setup Source Code And Tests
939 #===============================================================================
940 add_subdirectory(include)
941 add_subdirectory(src)
942 add_subdirectory(utils)
944 set(LIBCXX_TEST_DEPS "")
946 if (LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY)
947 list(APPEND LIBCXX_TEST_DEPS cxx_experimental)
950 if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY)
951 list(APPEND LIBCXX_TEST_DEPS cxx_external_threads)
954 if (LIBCXX_INCLUDE_BENCHMARKS)
955 add_subdirectory(benchmarks)
958 if (LIBCXX_INCLUDE_TESTS)
959 add_subdirectory(test)
960 add_subdirectory(lib/abi)
961 if (LIBCXX_STANDALONE_BUILD)
962 include(AddLLVM) # for get_llvm_lit_path
963 # Make sure the llvm-lit script is generated into the bin directory, and
964 # do it after adding all tests, since the generated script will only work
965 # correctly discovered tests against test locations from the source tree
966 # that have already been discovered.
967 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit
968 ${CMAKE_CURRENT_BINARY_DIR}/llvm-lit)
972 if (LIBCXX_INCLUDE_DOCS)
973 add_subdirectory(docs)