[Clang][RISCV] Recognize unsupport target feature by supporting isValidFeatureName...
[llvm-project.git] / libcxx / CMakeLists.txt
blobf1942e963ccc315005b50515f5f8a11c21fe74c5
1 #===============================================================================
2 # Setup Project
3 #===============================================================================
4 cmake_minimum_required(VERSION 3.20.0)
5 set(LLVM_SUBPROJECT_TITLE "libc++")
7 set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
9 # Add path for custom modules
10 list(INSERT CMAKE_MODULE_PATH 0
11   "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
12   "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
13   "${CMAKE_CURRENT_SOURCE_DIR}/../runtimes/cmake/Modules"
14   "${LLVM_COMMON_CMAKE_UTILS}"
15   "${LLVM_COMMON_CMAKE_UTILS}/Modules"
16   )
18 set(CMAKE_FOLDER "libc++")
20 set(LIBCXX_SOURCE_DIR  ${CMAKE_CURRENT_SOURCE_DIR})
21 set(LIBCXX_BINARY_DIR  ${CMAKE_CURRENT_BINARY_DIR})
22 set(LIBCXX_BINARY_INCLUDE_DIR "${LIBCXX_BINARY_DIR}/include/c++build")
24 include(GNUInstallDirs)
25 include(WarningFlags)
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."
32  )
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)
36 endif()
38 if (MSVC)
39   message(STATUS "Configuring for MSVC")
40 endif()
42 #===============================================================================
43 # Setup CMake Options
44 #===============================================================================
45 include(CMakeDependentOption)
46 include(HandleCompilerRT)
48 # Basic options ---------------------------------------------------------------
49 option(LIBCXX_ENABLE_ASSERTIONS
50   "Enable assertions inside the compiled library, and at the same time make it the
51    default when compiling user code. Note that assertions can be enabled or disabled
52    by users in their own code regardless of this option." OFF)
53 option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON)
54 option(LIBCXX_ENABLE_STATIC "Build libc++ as a static library." ON)
55 option(LIBCXX_ENABLE_FILESYSTEM
56   "Whether to include support for parts of the library that rely on a filesystem being
57    available on the platform. This includes things like most parts of <filesystem> and
58    others like <fstream>" ON)
59 option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS})
60 set(LIBCXX_SUPPORTED_HARDENING_MODES none fast extensive debug)
61 set(LIBCXX_HARDENING_MODE "none" CACHE STRING
62   "Specify the default hardening mode to use. This mode will be used inside the
63    compiled library and will be the default when compiling user code. Note that
64    users can override this setting in their own code. This does not affect the
65    ABI. Supported values are ${LIBCXX_SUPPORTED_HARDENING_MODES}.")
66 if (NOT "${LIBCXX_HARDENING_MODE}" IN_LIST LIBCXX_SUPPORTED_HARDENING_MODES)
67   message(FATAL_ERROR
68     "Unsupported hardening mode: '${LIBCXX_HARDENING_MODE}'. Supported values are ${LIBCXX_SUPPORTED_HARDENING_MODES}.")
69 endif()
70 set(LIBCXX_ASSERTION_HANDLER_FILE
71   "vendor/llvm/default_assertion_handler.in"
72   CACHE STRING
73   "Specify the path to a header that contains a custom implementation of the
74    assertion handler that gets invoked when a hardening assertion fails. If
75    provided, this header will be included by the library, replacing the
76    default assertion handler. If this is specified as a relative path, it
77    is assumed to be relative to '<monorepo>/libcxx'.")
78 if (NOT IS_ABSOLUTE "${LIBCXX_ASSERTION_HANDLER_FILE}")
79   set(LIBCXX_ASSERTION_HANDLER_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${LIBCXX_ASSERTION_HANDLER_FILE}")
80 endif()
81 option(LIBCXX_ENABLE_RANDOM_DEVICE
82   "Whether to include support for std::random_device in the library. Disabling
83    this can be useful when building the library for platforms that don't have
84    a source of randomness, such as some embedded platforms. When this is not
85    supported, most of <random> will still be available, but std::random_device
86    will not." ON)
87 option(LIBCXX_ENABLE_LOCALIZATION
88   "Whether to include support for localization in the library. Disabling
89    localization can be useful when porting to platforms that don't support
90    the C locale API (e.g. embedded). When localization is not supported,
91    several parts of the library will be disabled: <iostream>, <regex>, <locale>
92    will be completely unusable, and other parts may be only partly available." ON)
93 option(LIBCXX_ENABLE_UNICODE
94   "Whether to include support for Unicode in the library. Disabling Unicode can
95    be useful when porting to platforms that don't support UTF-8 encoding (e.g.
96    embedded)." ON)
97 option(LIBCXX_HAS_TERMINAL_AVAILABLE
98   "Build libc++ with support for checking whether a stream is a terminal." ON)
99 option(LIBCXX_ENABLE_WIDE_CHARACTERS
100   "Whether to include support for wide characters in the library. Disabling
101    wide character support can be useful when porting to platforms that don't
102    support the C functionality for wide characters. When wide characters are
103    not supported, several parts of the library will be disabled, notably the
104    wide character specializations of std::basic_string." ON)
106 # To use time zone support in libc++ the platform needs to have the IANA
107 # database installed. Libc++ will fail to build if this is enabled on a
108 # platform that does not provide the IANA database. The default is set to the
109 # current implementation state on the different platforms.
111 # TODO TZDB make the default always ON when most platforms ship with the IANA
112 # database.
113 if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
114   set(ENABLE_TIME_ZONE_DATABASE_DEFAULT ON)
115 else()
116   set(ENABLE_TIME_ZONE_DATABASE_DEFAULT OFF)
117 endif()
118 option(LIBCXX_ENABLE_TIME_ZONE_DATABASE
119   "Whether to include support for time zones in the library. Disabling
120   time zone support can be useful when porting to platforms that don't
121   ship the IANA time zone database. When time zones are not supported,
122   time zone support in <chrono> will be disabled." ${ENABLE_TIME_ZONE_DATABASE_DEFAULT})
123 option(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS
124   "Whether to turn on vendor availability annotations on declarations that depend
125    on definitions in a shared library. By default, we assume that we're not building
126    libc++ for any specific vendor, and we disable those annotations. Vendors wishing
127    to provide compile-time errors when using features unavailable on some version of
128    the shared library they shipped should turn this on and see `include/__configuration/availability.h`
129    for more details." OFF)
131 if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
132   set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-gcc.cfg.in")
133 elseif(MINGW)
134   if (LIBCXX_ENABLE_SHARED)
135     set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-mingw.cfg.in")
136   else()
137     set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-static-mingw.cfg.in")
138   endif()
139 elseif(WIN32) # clang-cl
140   if (LIBCXX_ENABLE_SHARED)
141     set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-clangcl.cfg.in")
142   else()
143     set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-static-clangcl.cfg.in")
144   endif()
145 else()
146   if (LIBCXX_ENABLE_SHARED)
147     set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared.cfg.in")
148   else()
149     set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-static.cfg.in")
150   endif()
151 endif()
152 set(LIBCXX_TEST_CONFIG "${LIBCXX_DEFAULT_TEST_CONFIG}" CACHE STRING
153     "The path to the Lit testing configuration to use when running the tests.
154      If a relative path is provided, it is assumed to be relative to '<monorepo>/libcxx/test/configs'.")
155 if (NOT IS_ABSOLUTE "${LIBCXX_TEST_CONFIG}")
156   set(LIBCXX_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/configs/${LIBCXX_TEST_CONFIG}")
157 endif()
158 message(STATUS "Using libc++ testing configuration: ${LIBCXX_TEST_CONFIG}")
159 set(LIBCXX_TEST_PARAMS "" CACHE STRING
160     "A list of parameters to run the Lit test suite with.")
162 # Benchmark options -----------------------------------------------------------
163 option(LIBCXX_INCLUDE_BENCHMARKS "Build the libc++ benchmarks and their dependencies" ON)
165 set(LIBCXX_BENCHMARK_TEST_ARGS_DEFAULT --benchmark_min_time=0.01)
166 set(LIBCXX_BENCHMARK_TEST_ARGS "${LIBCXX_BENCHMARK_TEST_ARGS_DEFAULT}" CACHE STRING
167     "Arguments to pass when running the benchmarks using check-cxx-benchmarks")
169 option(LIBCXX_INCLUDE_DOCS "Build the libc++ documentation." ${LLVM_INCLUDE_DOCS})
170 set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
171     "Define suffix of library directory name (32/64)")
172 option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON)
173 option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON)
174 option(LIBCXX_INSTALL_MODULES
175   "Install the libc++ C++20 module source files (experimental)." ON
177 cmake_dependent_option(LIBCXX_INSTALL_STATIC_LIBRARY
178   "Install the static libc++ library." ON
179   "LIBCXX_ENABLE_STATIC;LIBCXX_INSTALL_LIBRARY" OFF)
180 cmake_dependent_option(LIBCXX_INSTALL_SHARED_LIBRARY
181   "Install the shared libc++ library." ON
182   "LIBCXX_ENABLE_SHARED;LIBCXX_INSTALL_LIBRARY" OFF)
184 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)
185 if (LIBCXX_ABI_UNSTABLE)
186   set(abi_version "2")
187 else()
188   set(abi_version "1")
189 endif()
190 set(LIBCXX_ABI_VERSION "${abi_version}" CACHE STRING
191   "ABI version of libc++. Can be either 1 or 2, where 2 is currently the unstable ABI.
192    Defaults to 1 unless LIBCXX_ABI_UNSTABLE is specified, in which case this is 2.")
193 set(LIBCXX_LIBRARY_VERSION "${LIBCXX_ABI_VERSION}.0" CACHE STRING
194   "Version of libc++. This will be reflected in the name of the shared library produced.
195    For example, -DLIBCXX_LIBRARY_VERSION=x.y will result in the library being named
196    libc++.x.y.dylib, along with the usual symlinks pointing to that. On Apple platforms,
197    this also controls the linker's 'current_version' property.")
198 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.")
199 if (NOT LIBCXX_ABI_NAMESPACE MATCHES "__.*")
200   message(FATAL_ERROR "LIBCXX_ABI_NAMESPACE must be a reserved identifier, got '${LIBCXX_ABI_NAMESPACE}'.")
201 endif()
202 option(LIBCXX_ABI_FORCE_ITANIUM "Ignore auto-detection and force use of the Itanium ABI.")
203 option(LIBCXX_ABI_FORCE_MICROSOFT "Ignore auto-detection and force use of the Microsoft ABI.")
205 set(LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION "default" CACHE STRING
206   "Override the implementation to use for comparing typeinfos. By default, this
207    is detected automatically by the library, but this option allows overriding
208    which implementation is used unconditionally.
210    See the documentation in <libcxx/include/typeinfo> for details on what each
211    value means.")
212 set(TYPEINFO_COMPARISON_VALUES "default;1;2;3")
213 if (NOT ("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" IN_LIST TYPEINFO_COMPARISON_VALUES))
214   message(FATAL_ERROR "Value '${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}' is not a valid value for
215                        LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION")
216 endif()
218 set(LIBCXX_ABI_DEFINES "" CACHE STRING "A semicolon separated list of ABI macros to define in the site config header.")
219 set(LIBCXX_EXTRA_SITE_DEFINES "" CACHE STRING "Extra defines to add into __config_site")
220 option(LIBCXX_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
222 # C Library options -----------------------------------------------------------
224 set(LIBCXX_SUPPORTED_C_LIBRARIES system llvm-libc)
225 set(LIBCXX_LIBC "system" CACHE STRING "Specify C library to use. Supported values are ${LIBCXX_SUPPORTED_C_LIBRARIES}.")
226 if (NOT "${LIBCXX_LIBC}" IN_LIST LIBCXX_SUPPORTED_C_LIBRARIES)
227   message(FATAL_ERROR "Unsupported C library: '${LIBCXX_CXX_ABI}'. Supported values are ${LIBCXX_SUPPORTED_C_LIBRARIES}.")
228 endif()
230 # ABI Library options ---------------------------------------------------------
231 if (MSVC)
232   set(LIBCXX_DEFAULT_ABI_LIBRARY "vcruntime")
233 else()
234   set(LIBCXX_DEFAULT_ABI_LIBRARY "libcxxabi")
235 endif()
237 set(LIBCXX_SUPPORTED_ABI_LIBRARIES none libcxxabi system-libcxxabi libcxxrt libstdc++ libsupc++ vcruntime)
238 set(LIBCXX_CXX_ABI "${LIBCXX_DEFAULT_ABI_LIBRARY}" CACHE STRING "Specify C++ ABI library to use. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}.")
239 if (NOT "${LIBCXX_CXX_ABI}" IN_LIST LIBCXX_SUPPORTED_ABI_LIBRARIES)
240   message(FATAL_ERROR "Unsupported C++ ABI library: '${LIBCXX_CXX_ABI}'. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}.")
241 endif()
243 option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY
244   "Use a static copy of the ABI library when linking libc++.
245    This option cannot be used with LIBCXX_ENABLE_ABI_LINKER_SCRIPT." OFF)
247 option(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY
248   "Statically link the ABI library to static library"
249   ${LIBCXX_ENABLE_STATIC_ABI_LIBRARY})
251 option(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY
252   "Statically link the ABI library to shared library"
253   ${LIBCXX_ENABLE_STATIC_ABI_LIBRARY})
255 # Generate and install a linker script inplace of libc++.so. The linker script
256 # will link libc++ to the correct ABI library. This option is on by default
257 # on UNIX platforms other than Apple, and on the Fuchsia platform unless we
258 # statically link libc++abi inside libc++.so, we don't build libc++.so at all
259 # or we don't have any ABI library.
260 if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY
261     OR NOT LIBCXX_ENABLE_SHARED
262     OR LIBCXX_CXX_ABI STREQUAL "none")
263   set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF)
264 elseif((UNIX OR FUCHSIA) AND NOT APPLE)
265   set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE ON)
266 else()
267   set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF)
268 endif()
269 option(LIBCXX_ENABLE_ABI_LINKER_SCRIPT
270       "Use and install a linker script for the given ABI library"
271       ${ENABLE_LINKER_SCRIPT_DEFAULT_VALUE})
273 option(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS
274   "Build libc++ with definitions for operator new/delete. These are normally
275    defined in libc++abi, but this option can be used to define them in libc++
276    instead. If you define them in libc++, make sure they are NOT defined in
277    libc++abi. Doing otherwise is an ODR violation." OFF)
278 # Build libc++abi with libunwind. We need this option to determine whether to
279 # link with libunwind or libgcc_s while running the test cases.
280 option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." ON)
282 # Target options --------------------------------------------------------------
283 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})
284 if (LIBCXX_BUILD_32_BITS)
285   message(FATAL_ERROR "LIBCXX_BUILD_32_BITS is not supported anymore when building the runtimes, please specify a full triple instead.")
286 endif()
288 # Feature options -------------------------------------------------------------
289 option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON)
290 option(LIBCXX_ENABLE_RTTI
291   "Use runtime type information.
292    This option may only be set to OFF when LIBCXX_ENABLE_EXCEPTIONS=OFF." ON)
293 option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON)
294 option(LIBCXX_ENABLE_MONOTONIC_CLOCK
295   "Build libc++ with support for a monotonic clock.
296    This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON)
297 option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF)
298 option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF)
299 option(LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32 thread API" OFF)
300 option(LIBCXX_HAS_EXTERNAL_THREAD_API
301   "Build libc++ with an externalized threading API.
302    This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF)
304 if (LIBCXX_ENABLE_THREADS)
305   set(LIBCXX_PSTL_BACKEND "std_thread" CACHE STRING "Which PSTL backend to use")
306 else()
307   set(LIBCXX_PSTL_BACKEND "serial" CACHE STRING "Which PSTL backend to use")
308 endif()
310 # Misc options ----------------------------------------------------------------
311 # FIXME: Turn -pedantic back ON. It is currently off because it warns
312 # about #include_next which is used everywhere.
313 option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF)
314 option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
316 set(LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT OFF)
317 if (WIN32)
318   set(LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT ON)
319 endif()
320 option(LIBCXX_HERMETIC_STATIC_LIBRARY
321   "Do not export any symbols from the static library." ${LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT})
323 #===============================================================================
324 # Check option configurations
325 #===============================================================================
327 # Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON only when
328 # LIBCXX_ENABLE_THREADS is on.
329 if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_ENABLE_MONOTONIC_CLOCK)
330   message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF"
331                       " when LIBCXX_ENABLE_THREADS is also set to OFF.")
332 endif()
334 if(NOT LIBCXX_ENABLE_THREADS)
335   if(LIBCXX_HAS_PTHREAD_API)
336     message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON"
337                         " when LIBCXX_ENABLE_THREADS is also set to ON.")
338   endif()
339   if(LIBCXX_HAS_EXTERNAL_THREAD_API)
340     message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set to ON"
341                         " when LIBCXX_ENABLE_THREADS is also set to ON.")
342   endif()
343   if (LIBCXX_HAS_WIN32_THREAD_API)
344     message(FATAL_ERROR "LIBCXX_HAS_WIN32_THREAD_API can only be set to ON"
345                         " when LIBCXX_ENABLE_THREADS is also set to ON.")
346   endif()
348 endif()
350 if (LIBCXX_HAS_EXTERNAL_THREAD_API)
351   if (LIBCXX_HAS_PTHREAD_API)
352     message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
353                         " and LIBCXX_HAS_PTHREAD_API cannot be both"
354                         " set to ON at the same time.")
355   endif()
356   if (LIBCXX_HAS_WIN32_THREAD_API)
357     message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
358                         " and LIBCXX_HAS_WIN32_THREAD_API cannot be both"
359                         " set to ON at the same time.")
360   endif()
361 endif()
363 if (LIBCXX_HAS_PTHREAD_API)
364   if (LIBCXX_HAS_WIN32_THREAD_API)
365     message(FATAL_ERROR "The options LIBCXX_HAS_PTHREAD_API"
366                         " and LIBCXX_HAS_WIN32_THREAD_API cannot be both"
367                         " set to ON at the same time.")
368   endif()
369 endif()
371 if (NOT LIBCXX_ENABLE_RTTI AND LIBCXX_ENABLE_EXCEPTIONS)
372   message(FATAL_ERROR "Libc++ cannot be built with exceptions enabled but RTTI"
373                       " disabled, since that configuration is broken. See"
374                       " https://github.com/llvm/llvm-project/issues/66117"
375                       " for details.")
376 endif()
378 if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
379     if (APPLE)
380       message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT cannot be used on APPLE targets")
381     endif()
382     if (NOT LIBCXX_ENABLE_SHARED)
383       message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT is only available for shared library builds.")
384     endif()
385 endif()
387 if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
388     message(FATAL_ERROR "Conflicting options given.
389         LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY cannot be specified with
390         LIBCXX_ENABLE_ABI_LINKER_SCRIPT")
391 endif()
393 if (LIBCXX_ABI_FORCE_ITANIUM AND LIBCXX_ABI_FORCE_MICROSOFT)
394   message(FATAL_ERROR "Only one of LIBCXX_ABI_FORCE_ITANIUM and LIBCXX_ABI_FORCE_MICROSOFT can be specified.")
395 endif ()
397 if (LIBCXX_ENABLE_SHARED AND CMAKE_MSVC_RUNTIME_LIBRARY AND
398     (NOT CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL$"))
399   message(WARNING "A static CRT linked into a shared libc++ doesn't work correctly.")
400 endif()
402 #===============================================================================
403 # Configure System
404 #===============================================================================
406 # TODO: Projects that depend on libc++ should use LIBCXX_GENERATED_INCLUDE_DIR
407 # instead of hard-coding include/c++/v1.
409 set(LIBCXX_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/c++/v1" CACHE STRING
410     "Path where target-agnostic libc++ headers should be installed.")
411 set(LIBCXX_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING
412     "Path where built libc++ runtime libraries should be installed.")
413 set(LIBCXX_INSTALL_MODULES_DIR "share/libc++/v1" CACHE STRING
414     "Path where target-agnostic libc++ module source files should be installed.")
416 set(LIBCXX_SHARED_OUTPUT_NAME "c++" CACHE STRING "Output name for the shared libc++ runtime library.")
417 set(LIBCXX_STATIC_OUTPUT_NAME "c++" CACHE STRING "Output name for the static libc++ runtime library.")
419 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
420   set(LIBCXX_TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE})
421   if(LIBCXX_LIBDIR_SUBDIR)
422     string(APPEND LIBCXX_TARGET_SUBDIR /${LIBCXX_LIBDIR_SUBDIR})
423   endif()
424   set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LIBCXX_TARGET_SUBDIR})
425   set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
426   set(LIBCXX_GENERATED_MODULE_DIR "${LLVM_BINARY_DIR}/modules/c++/v1")
427   set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LIBCXX_TARGET_SUBDIR}/c++/v1")
428   set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LIBCXX_TARGET_SUBDIR} CACHE STRING
429       "Path where built libc++ libraries should be installed.")
430   set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${LIBCXX_TARGET_SUBDIR}/c++/v1" CACHE STRING
431       "Path where target-specific libc++ headers should be installed.")
432   unset(LIBCXX_TARGET_SUBDIR)
433 else()
434   if(LLVM_LIBRARY_OUTPUT_INTDIR)
435     set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
436     set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
437     set(LIBCXX_GENERATED_MODULE_DIR "${LLVM_BINARY_DIR}/modules/c++/v1")
438   else()
439     set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
440     set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1")
441     set(LIBCXX_GENERATED_MODULE_DIR "${CMAKE_BINARY_DIR}/modules/c++/v1")
442   endif()
443   set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}")
444   set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX} CACHE STRING
445       "Path where built libc++ libraries should be installed.")
446   set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${LIBCXX_INSTALL_INCLUDE_DIR}" CACHE STRING
447       "Path where target-specific libc++ headers should be installed.")
448 endif()
450 file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}")
452 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
453 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
454 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
456 # Declare libc++ configuration variables.
457 # They are intended for use as follows:
458 # LIBCXX_CXX_FLAGS: General flags for both the compiler and linker.
459 # LIBCXX_COMPILE_FLAGS: Compile only flags.
460 # LIBCXX_LINK_FLAGS: Linker only flags.
461 # LIBCXX_LIBRARIES: libraries libc++ is linked to.
462 set(LIBCXX_COMPILE_FLAGS "")
463 set(LIBCXX_LINK_FLAGS "")
464 set(LIBCXX_LIBRARIES "")
465 set(LIBCXX_ADDITIONAL_COMPILE_FLAGS "" CACHE STRING
466     "Additional Compile only flags which can be provided in cache")
467 set(LIBCXX_ADDITIONAL_LIBRARIES "" CACHE STRING
468     "Additional libraries libc++ is linked to which can be provided in cache")
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 if (${CMAKE_SYSTEM_NAME} MATCHES "AIX")
479   add_flags_if_supported("-mdefault-visibility-export-mapping=explicit")
480   set(CMAKE_AIX_EXPORT_ALL_SYMBOLS OFF)
481 endif()
483 # Configure compiler.
484 include(config-ix)
486 #===============================================================================
487 # Setup Compiler Flags
488 #===============================================================================
490 include(HandleLibC) # Setup the C library flags
491 include(HandleLibCXXABI) # Setup the ABI library flags
493 # FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC.
494 # Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors
495 # so they don't get transformed into -Wno and -errors respectively.
496 remove_flags(-Wno-pedantic -pedantic-errors -pedantic)
498 # Required flags ==============================================================
499 function(cxx_add_basic_build_flags target)
501   # Use C++23 for all targets.
502   set_target_properties(${target} PROPERTIES
503     CXX_STANDARD 23
504     CXX_STANDARD_REQUIRED OFF # TODO: Make this REQUIRED once we don't need to accommodate the LLVM documentation builders using an ancient CMake
505     CXX_EXTENSIONS NO)
507   # When building the dylib, don't warn for unavailable aligned allocation
508   # functions based on the deployment target -- they are always available
509   # because they are provided by the dylib itself with the exception of z/OS.
510   if (ZOS)
511     target_add_compile_flags_if_supported(${target} PRIVATE -fno-aligned-allocation)
512   else()
513     target_add_compile_flags_if_supported(${target} PRIVATE -faligned-allocation)
514   endif()
516   # On all systems the system c++ standard library headers need to be excluded.
517   # MSVC only has -X, which disables all default includes; including the crt.
518   # Thus, we do nothing and hope we don't accidentally include any of the C++
519   # headers
520   target_add_compile_flags_if_supported(${target} PUBLIC -nostdinc++)
522   # Hide all inline function definitions which have not explicitly been marked
523   # visible. This prevents new definitions for inline functions from appearing in
524   # the dylib when get ODR used by another function.
525   target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility-inlines-hidden)
527   # Our visibility annotations are not quite right for non-Clang compilers,
528   # so we end up not exporting all the symbols we should. In the future, we
529   # can improve the situation by providing an explicit list of exported
530   # symbols on all compilers.
531   if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
532     target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility=hidden)
533   endif()
535   # Build with -fsized-deallocation, which is default in recent versions of Clang.
536   # TODO(LLVM 21): This can be dropped once we only support Clang >= 19.
537   target_add_compile_flags_if_supported(${target} PRIVATE -fsized-deallocation)
539   # Let the library headers know they are currently being used to build the
540   # library.
541   target_compile_definitions(${target} PRIVATE -D_LIBCPP_BUILDING_LIBRARY)
543   # Make sure the library can be build without transitive includes. This makes
544   # it easier to upgrade the library to a newer language standard without build
545   # errors.
546   target_compile_definitions(${target} PRIVATE -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
548   if (C_SUPPORTS_COMMENT_LIB_PRAGMA)
549     if (LIBCXX_HAS_PTHREAD_LIB)
550       target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_PTHREAD_LIB)
551     endif()
552     if (LIBCXX_HAS_RT_LIB)
553       target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_RT_LIB)
554     endif()
555   endif()
556   target_compile_options(${target} PUBLIC "${LIBCXX_ADDITIONAL_COMPILE_FLAGS}")
557 endfunction()
559 # Exception flags =============================================================
560 function(cxx_add_exception_flags target)
561   if (LIBCXX_ENABLE_EXCEPTIONS)
562     # Catches C++ exceptions only and tells the compiler to assume that extern C
563     # functions never throw a C++ exception.
564     target_add_compile_flags_if_supported(${target} PUBLIC -EHsc)
565   else()
566     target_add_compile_flags_if_supported(${target} PUBLIC -EHs- -EHa-)
567     target_add_compile_flags_if_supported(${target} PUBLIC -fno-exceptions)
568   endif()
569 endfunction()
571 # RTTI flags ==================================================================
572 function(cxx_add_rtti_flags target)
573   if (NOT LIBCXX_ENABLE_RTTI)
574     if (MSVC)
575       target_add_compile_flags_if_supported(${target} PUBLIC -GR-)
576     else()
577       target_add_compile_flags_if_supported(${target} PUBLIC -fno-rtti)
578     endif()
579   endif()
580 endfunction()
582 # Modules flags ===============================================================
583 # FIXME The libc++ sources are fundamentally non-modular. They need special
584 # versions of the headers in order to provide C++03 and legacy ABI definitions.
585 # NOTE: The public headers can be used with modules in all other contexts.
586 function(cxx_add_module_flags target)
587   if (LLVM_ENABLE_MODULES)
588     # Ignore that the rest of the modules flags are now unused.
589     target_add_compile_flags_if_supported(${target} PUBLIC -Wno-unused-command-line-argument)
590     target_compile_options(${target} PUBLIC -fno-modules)
591   endif()
592 endfunction()
594 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
596 # Sanitizer flags =============================================================
598 function(get_sanitizer_flags OUT_VAR  USE_SANITIZER)
599   set(SANITIZER_FLAGS)
600   set(USE_SANITIZER "${USE_SANITIZER}")
601   # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC.
602   # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do.
603   if (USE_SANITIZER AND NOT MSVC)
604     append_flags_if_supported(SANITIZER_FLAGS "-fno-omit-frame-pointer")
605     append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only")
607     if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND
608             NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
609       append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only")
610     endif()
611     if (USE_SANITIZER STREQUAL "Address")
612       append_flags(SANITIZER_FLAGS "-fsanitize=address")
613     elseif (USE_SANITIZER STREQUAL "HWAddress")
614       append_flags(SANITIZER_FLAGS "-fsanitize=hwaddress")
615     elseif (USE_SANITIZER MATCHES "Memory(WithOrigins)?")
616       append_flags(SANITIZER_FLAGS -fsanitize=memory)
617       if (USE_SANITIZER STREQUAL "MemoryWithOrigins")
618         append_flags(SANITIZER_FLAGS "-fsanitize-memory-track-origins")
619       endif()
620     elseif (USE_SANITIZER STREQUAL "Undefined")
621       append_flags(SANITIZER_FLAGS "-fsanitize=undefined" "-fno-sanitize=vptr,function" "-fno-sanitize-recover=all")
622     elseif (USE_SANITIZER STREQUAL "Address;Undefined" OR
623             USE_SANITIZER STREQUAL "Undefined;Address")
624       append_flags(SANITIZER_FLAGS "-fsanitize=address,undefined" "-fno-sanitize=vptr,function" "-fno-sanitize-recover=all")
625     elseif (USE_SANITIZER STREQUAL "Thread")
626       append_flags(SANITIZER_FLAGS -fsanitize=thread)
627     elseif (USE_SANITIZER STREQUAL "DataFlow")
628       append_flags(SANITIZER_FLAGS -fsanitize=dataflow)
629     else()
630       message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${USE_SANITIZER}")
631     endif()
632   elseif(USE_SANITIZER AND MSVC)
633     message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.")
634   endif()
635   set(${OUT_VAR} "${SANITIZER_FLAGS}" PARENT_SCOPE)
636 endfunction()
638 get_sanitizer_flags(SANITIZER_FLAGS "${LLVM_USE_SANITIZER}")
639 add_library(cxx-sanitizer-flags INTERFACE)
640 target_compile_options(cxx-sanitizer-flags INTERFACE ${SANITIZER_FLAGS})
642 # _LIBCPP_INSTRUMENTED_WITH_ASAN informs that library was built with ASan.
643 # Defining _LIBCPP_INSTRUMENTED_WITH_ASAN while building the library with ASan is required.
644 # Normally, the _LIBCPP_INSTRUMENTED_WITH_ASAN flag is used to keep information whether
645 # dylibs are built with AddressSanitizer. However, when building libc++,
646 # this flag needs to be defined so that the resulting dylib has all ASan functionalities guarded by this flag.
647 # If the _LIBCPP_INSTRUMENTED_WITH_ASAN flag is not defined, then parts of the ASan instrumentation code in libc++
648 # will not be compiled into it, resulting in false positives.
649 # For context, read: https://github.com/llvm/llvm-project/pull/72677#pullrequestreview-1765402800
650 string(FIND "${LLVM_USE_SANITIZER}" "Address" building_with_asan)
651 if (NOT "${building_with_asan}" STREQUAL "-1")
652   config_define(ON _LIBCPP_INSTRUMENTED_WITH_ASAN)
653 endif()
655 # Link system libraries =======================================================
656 function(cxx_link_system_libraries target)
657   if (NOT MSVC)
658     target_link_libraries(${target} PRIVATE "-nostdlib++")
659   endif()
661   if (CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG AND LIBCXXABI_USE_LLVM_UNWINDER)
662     # If we're linking directly against the libunwind that we're building
663     # in the same invocation, don't try to link in the toolchain's
664     # default libunwind (which may be missing still).
665     target_add_link_flags_if_supported(${target} PRIVATE "--unwindlib=none")
666   endif()
668   if (MSVC)
669     if (LIBCXX_USE_COMPILER_RT)
670       find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY)
671       if (LIBCXX_BUILTINS_LIBRARY)
672         target_link_libraries(${target} PRIVATE "${LIBCXX_BUILTINS_LIBRARY}")
673       endif()
674     elseif (LIBCXX_HAS_GCC_LIB)
675       target_link_libraries(${target} PRIVATE gcc)
676     elseif (LIBCXX_HAS_GCC_S_LIB)
677       target_link_libraries(${target} PRIVATE gcc_s)
678     endif()
679   endif()
681   if (LIBCXX_HAS_ATOMIC_LIB)
682     target_link_libraries(${target} PRIVATE atomic)
683   endif()
685   if (MINGW)
686     target_link_libraries(${target} PRIVATE "${MINGW_LIBRARIES}")
687   endif()
689   if (MSVC)
690     if ((NOT CMAKE_MSVC_RUNTIME_LIBRARY AND uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
691         OR (CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "Debug"))
692       set(LIB_SUFFIX "d")
693     else()
694       set(LIB_SUFFIX "")
695     endif()
697     if (NOT CMAKE_MSVC_RUNTIME_LIBRARY OR CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL$")
698       set(CRT_LIB "msvcrt")
699       set(CXX_LIB "msvcprt")
700     else()
701       set(CRT_LIB "libcmt")
702       set(CXX_LIB "libcpmt")
703     endif()
705     target_link_libraries(${target} PRIVATE ${CRT_LIB}${LIB_SUFFIX}) # C runtime startup files
706     target_link_libraries(${target} PRIVATE ${CXX_LIB}${LIB_SUFFIX}) # C++ standard library. Required for exception_ptr internals.
707     # Required for standards-complaint wide character formatting functions
708     # (e.g. `printfw`/`scanfw`)
709     target_link_libraries(${target} PRIVATE iso_stdio_wide_specifiers)
710   endif()
712   if (ANDROID AND ANDROID_PLATFORM_LEVEL LESS 21)
713     target_link_libraries(${target} PUBLIC android_support)
714   endif()
715   target_link_libraries(${target} PUBLIC "${LIBCXX_ADDITIONAL_LIBRARIES}")
716 endfunction()
718 # Windows-related flags =======================================================
719 function(cxx_add_windows_flags target)
720   if(WIN32 AND NOT MINGW)
721     target_compile_definitions(${target} PRIVATE
722                                  # Ignore the -MSC_VER mismatch, as we may build
723                                  # with a different compatibility version.
724                                  _ALLOW_MSC_VER_MISMATCH
725                                  # Don't check the msvcprt iterator debug levels
726                                  # as we will define the iterator types; libc++
727                                  # uses a different macro to identify the debug
728                                  # level.
729                                  _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH
730                                  # We are building the c++ runtime, don't pull in
731                                  # msvcprt.
732                                  _CRTBLD
733                                  # Don't warn on the use of "deprecated"
734                                  # "insecure" functions which are standards
735                                  # specified.
736                                  _CRT_SECURE_NO_WARNINGS
737                                  # Use the ISO conforming behaviour for conversion
738                                  # in printf, scanf.
739                                  _CRT_STDIO_ISO_WIDE_SPECIFIERS)
740   endif()
741 endfunction()
743 # Configuration file flags =====================================================
744 config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION)
745 config_define(${LIBCXX_ABI_NAMESPACE} _LIBCPP_ABI_NAMESPACE)
746 config_define_if(LIBCXX_ABI_FORCE_ITANIUM _LIBCPP_ABI_FORCE_ITANIUM)
747 config_define_if(LIBCXX_ABI_FORCE_MICROSOFT _LIBCPP_ABI_FORCE_MICROSOFT)
748 config_define_if_not(LIBCXX_ENABLE_THREADS _LIBCPP_HAS_NO_THREADS)
749 config_define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK _LIBCPP_HAS_NO_MONOTONIC_CLOCK)
750 config_define_if_not(LIBCXX_HAS_TERMINAL_AVAILABLE _LIBCPP_HAS_NO_TERMINAL)
751 if (NOT LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION STREQUAL "default")
752   config_define("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION)
753 endif()
754 config_define_if(LIBCXX_HAS_PTHREAD_API _LIBCPP_HAS_THREAD_API_PTHREAD)
755 config_define_if(LIBCXX_HAS_EXTERNAL_THREAD_API _LIBCPP_HAS_THREAD_API_EXTERNAL)
756 config_define_if(LIBCXX_HAS_WIN32_THREAD_API _LIBCPP_HAS_THREAD_API_WIN32)
757 config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC)
758 config_define_if(LIBCXX_NO_VCRUNTIME _LIBCPP_NO_VCRUNTIME)
759 config_define_if_not(LIBCXX_ENABLE_FILESYSTEM _LIBCPP_HAS_NO_FILESYSTEM)
760 config_define_if_not(LIBCXX_ENABLE_RANDOM_DEVICE _LIBCPP_HAS_NO_RANDOM_DEVICE)
761 config_define_if_not(LIBCXX_ENABLE_LOCALIZATION _LIBCPP_HAS_NO_LOCALIZATION)
762 config_define_if_not(LIBCXX_ENABLE_UNICODE _LIBCPP_HAS_NO_UNICODE)
763 config_define_if_not(LIBCXX_ENABLE_WIDE_CHARACTERS _LIBCPP_HAS_NO_WIDE_CHARACTERS)
764 config_define_if_not(LIBCXX_ENABLE_TIME_ZONE_DATABASE _LIBCPP_HAS_NO_TIME_ZONE_DATABASE)
765 config_define_if_not(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)
767 if (LIBCXX_ENABLE_ASSERTIONS)
768   message(DEPRECATION "LIBCXX_ENABLE_ASSERTIONS is deprecated and will be removed in LLVM 20. Please use LIBCXX_HARDENING_MODE instead.")
769   set(LIBCXX_HARDENING_MODE "extensive")
770 endif()
771 if (LIBCXX_HARDENING_MODE STREQUAL "none")
772   config_define(2 _LIBCPP_HARDENING_MODE_DEFAULT)
773 elseif (LIBCXX_HARDENING_MODE STREQUAL "fast")
774   config_define(4 _LIBCPP_HARDENING_MODE_DEFAULT)
775 elseif (LIBCXX_HARDENING_MODE STREQUAL "extensive")
776   config_define(16 _LIBCPP_HARDENING_MODE_DEFAULT)
777 elseif (LIBCXX_HARDENING_MODE STREQUAL "debug")
778   config_define(8 _LIBCPP_HARDENING_MODE_DEFAULT)
779 endif()
781 if (LIBCXX_PSTL_BACKEND STREQUAL "serial")
782   config_define(1 _LIBCPP_PSTL_BACKEND_SERIAL)
783 elseif(LIBCXX_PSTL_BACKEND STREQUAL "std_thread")
784   config_define(1 _LIBCPP_PSTL_BACKEND_STD_THREAD)
785 elseif(LIBCXX_PSTL_BACKEND STREQUAL "libdispatch")
786   config_define(1 _LIBCPP_PSTL_BACKEND_LIBDISPATCH)
787 else()
788   message(FATAL_ERROR "LIBCXX_PSTL_BACKEND is set to ${LIBCXX_PSTL_BACKEND}, which is not a valid backend.
789                        Valid backends are: serial, std_thread and libdispatch")
790 endif()
792 if (LIBCXX_ABI_DEFINES)
793   set(abi_defines)
794   foreach (abi_define ${LIBCXX_ABI_DEFINES})
795     if (NOT abi_define MATCHES "^_LIBCPP_ABI_")
796       message(SEND_ERROR "Invalid ABI macro ${abi_define} in LIBCXX_ABI_DEFINES")
797     endif()
798     list(APPEND abi_defines "#define ${abi_define}")
799   endforeach()
800   string(REPLACE ";" "\n" abi_defines "${abi_defines}")
801   config_define(${abi_defines} _LIBCPP_ABI_DEFINES)
802 endif()
804 if (LIBCXX_EXTRA_SITE_DEFINES)
805   set(extra_site_defines)
806   foreach (extra_site_define ${LIBCXX_EXTRA_SITE_DEFINES})
807     # Allow defines such as DEFINE=VAL, transformed into "#define DEFINE VAL".
808     string(REPLACE "=" " " extra_site_define "${extra_site_define}")
809     list(APPEND extra_site_defines "#define ${extra_site_define}")
810   endforeach()
811   string(REPLACE ";" "\n" extra_site_defines "${extra_site_defines}")
812   config_define(${extra_site_defines} _LIBCPP_EXTRA_SITE_DEFINES)
813 endif()
815 # By default libc++ on Windows expects to use a shared library, which requires
816 # the headers to use DLL import/export semantics. However when building a
817 # static library only we modify the headers to disable DLL import/export.
818 if (DEFINED WIN32 AND LIBCXX_ENABLE_STATIC AND NOT LIBCXX_ENABLE_SHARED)
819   message(STATUS "Generating custom __config for non-DLL Windows build")
820   config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
821 endif()
823 if (WIN32 AND LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
824   # If linking libcxxabi statically into libcxx, skip the dllimport attributes
825   # on symbols we refer to from libcxxabi.
826   add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS)
827 endif()
829 # Setup all common build flags =================================================
830 function(cxx_add_common_build_flags target)
831   cxx_add_basic_build_flags(${target})
832   cxx_add_warning_flags(${target} ${LIBCXX_ENABLE_WERROR} ${LIBCXX_ENABLE_PEDANTIC})
833   cxx_add_windows_flags(${target})
834   cxx_add_exception_flags(${target})
835   cxx_add_rtti_flags(${target})
836   cxx_add_module_flags(${target})
837   cxx_link_system_libraries(${target})
838   target_link_libraries(${target} PRIVATE cxx-sanitizer-flags)
839 endfunction()
841 #===============================================================================
842 # Setup Source Code And Tests
843 #===============================================================================
844 add_custom_target(cxx-test-depends
845   COMMENT "Build dependencies required to run the libc++ test suite.")
847 add_subdirectory(include)
848 add_subdirectory(src)
849 add_subdirectory(utils)
850 add_subdirectory(modules)
852 if (LIBCXX_INCLUDE_TESTS)
853   add_subdirectory(test)
854   add_subdirectory(lib/abi)
855 endif()
857 if (LIBCXX_INCLUDE_DOCS)
858   add_subdirectory(docs)
859 endif()