882 lines · plain
1#===============================================================================2# Setup Project3#===============================================================================4cmake_minimum_required(VERSION 3.20.0)5set(LLVM_SUBPROJECT_TITLE "libc++")6 7set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")8 9# Add path for custom modules10list(INSERT CMAKE_MODULE_PATH 011 "${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 )17 18set(CMAKE_FOLDER "libc++")19 20set(LIBCXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})21set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})22 23include(GNUInstallDirs)24include(WarningFlags)25 26# Require out of source build.27include(MacroEnsureOutOfSourceBuild)28MACRO_ENSURE_OUT_OF_SOURCE_BUILD(29 "${PROJECT_NAME} requires an out of source build. Please create a separate30 build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there."31 )32if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")33 message(STATUS "Configuring for clang-cl")34 set(LIBCXX_TARGETING_CLANG_CL ON)35endif()36 37if (MSVC)38 message(STATUS "Configuring for MSVC")39endif()40 41#===============================================================================42# Setup CMake Options43#===============================================================================44include(CMakeDependentOption)45include(HandleCompilerRT)46 47# Basic options ---------------------------------------------------------------48option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON)49option(LIBCXX_ENABLE_STATIC "Build libc++ as a static library." ON)50option(LIBCXX_ENABLE_EXCEPTIONS "Enable exceptions in the built library." ON)51option(LIBCXX_ENABLE_RTTI52 "Use runtime type information.53 This option may only be set to OFF when LIBCXX_ENABLE_EXCEPTIONS=OFF." ON)54option(LIBCXX_ENABLE_FILESYSTEM55 "Whether to include support for parts of the library that rely on a filesystem being56 available on the platform. This includes things like most parts of <filesystem> and57 others like <fstream>" ON)58option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS})59set(LIBCXX_SUPPORTED_HARDENING_MODES none fast extensive debug)60set(LIBCXX_HARDENING_MODE "none" CACHE STRING61 "Specify the default hardening mode to use. This mode will be used inside the62 compiled library and will be the default when compiling user code. Note that63 users can override this setting in their own code. This does not affect the64 ABI. Supported values are ${LIBCXX_SUPPORTED_HARDENING_MODES}.")65if (NOT "${LIBCXX_HARDENING_MODE}" IN_LIST LIBCXX_SUPPORTED_HARDENING_MODES)66 message(FATAL_ERROR67 "Unsupported hardening mode: '${LIBCXX_HARDENING_MODE}'. Supported values are ${LIBCXX_SUPPORTED_HARDENING_MODES}.")68endif()69set(LIBCXX_SUPPORTED_ASSERTION_SEMANTICS hardening_dependent ignore observe quick_enforce enforce)70set(LIBCXX_ASSERTION_SEMANTIC "hardening_dependent" CACHE STRING71 "Specify the default assertion semantic to use. This semantic will be used72 inside the compiled library and will be the default when compiling user code.73 Note that users can override this setting in their own code. This does not74 affect the ABI. Supported values are ${LIBCXX_SUPPORTED_ASSERTION_SEMANTICS}.75 `hardening_dependent` is a special value that instructs the library to select76 the assertion semantic based on the hardening mode in effect.")77 78if (NOT "${LIBCXX_ASSERTION_SEMANTIC}" IN_LIST LIBCXX_SUPPORTED_ASSERTION_SEMANTICS)79 message(FATAL_ERROR80 "Unsupported assertion semantic: '${LIBCXX_ASSERTION_SEMANTIC}'. Supported values are ${LIBCXX_SUPPORTED_ASSERTION_SEMANTICS}.")81endif()82set(LIBCXX_ASSERTION_HANDLER_FILE83 "vendor/llvm/default_assertion_handler.in"84 CACHE STRING85 "Specify the path to a header that contains a custom implementation of the86 assertion handler that gets invoked when a hardening assertion fails. If87 provided, this header will be included by the library, replacing the88 default assertion handler. If this is specified as a relative path, it89 is assumed to be relative to '<monorepo>/libcxx'.")90if (NOT IS_ABSOLUTE "${LIBCXX_ASSERTION_HANDLER_FILE}")91 set(LIBCXX_ASSERTION_HANDLER_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${LIBCXX_ASSERTION_HANDLER_FILE}")92endif()93option(LIBCXX_ENABLE_RANDOM_DEVICE94 "Whether to include support for std::random_device in the library. Disabling95 this can be useful when building the library for platforms that don't have96 a source of randomness, such as some embedded platforms. When this is not97 supported, most of <random> will still be available, but std::random_device98 will not." ON)99option(LIBCXX_ENABLE_LOCALIZATION100 "Whether to include support for localization in the library. Disabling101 localization can be useful when porting to platforms that don't support102 the C locale API (e.g. embedded). When localization is not supported,103 several parts of the library will be disabled: <iostream>, <regex>, <locale>104 will be completely unusable, and other parts may be only partly available." ON)105option(LIBCXX_ENABLE_UNICODE106 "Whether to include support for Unicode in the library. Disabling Unicode can107 be useful when porting to platforms that don't support UTF-8 encoding (e.g.108 embedded)." ON)109option(LIBCXX_HAS_TERMINAL_AVAILABLE110 "Build libc++ with support for checking whether a stream is a terminal." ON)111option(LIBCXX_ENABLE_WIDE_CHARACTERS112 "Whether to include support for wide characters in the library. Disabling113 wide character support can be useful when porting to platforms that don't114 support the C functionality for wide characters. When wide characters are115 not supported, several parts of the library will be disabled, notably the116 wide character specializations of std::basic_string." ON)117option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON)118option(LIBCXX_ENABLE_MONOTONIC_CLOCK119 "Build libc++ with support for a monotonic clock.120 This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON)121 122# To use time zone support in libc++ the platform needs to have the IANA123# database installed. Libc++ will fail to build if this is enabled on a124# platform that does not provide the IANA database. The default is set to the125# current implementation state on the different platforms.126#127# TODO TZDB make the default always ON when most platforms ship with the IANA128# database.129if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")130 set(ENABLE_TIME_ZONE_DATABASE_DEFAULT ON)131else()132 set(ENABLE_TIME_ZONE_DATABASE_DEFAULT OFF)133endif()134option(LIBCXX_ENABLE_TIME_ZONE_DATABASE135 "Whether to include support for time zones in the library. Disabling136 time zone support can be useful when porting to platforms that don't137 ship the IANA time zone database. When time zones are not supported,138 time zone support in <chrono> will be disabled." ${ENABLE_TIME_ZONE_DATABASE_DEFAULT})139option(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS140 "Whether to turn on vendor availability annotations on declarations that depend141 on definitions in a shared library. By default, we assume that we're not building142 libc++ for any specific vendor, and we disable those annotations. Vendors wishing143 to provide compile-time errors when using features unavailable on some version of144 the shared library they shipped should turn this on and see `include/__configuration/availability.h`145 for more details." OFF)146 147if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")148 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-gcc.cfg.in")149elseif(MINGW)150 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-mingw.cfg.in")151elseif(WIN32) # clang-cl152 if (LIBCXX_ENABLE_SHARED)153 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-clangcl.cfg.in")154 else()155 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-static-clangcl.cfg.in")156 endif()157else()158 if (LIBCXX_ENABLE_SHARED)159 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared.cfg.in")160 else()161 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-static.cfg.in")162 endif()163endif()164set(LIBCXX_TEST_CONFIG "${LIBCXX_DEFAULT_TEST_CONFIG}" CACHE STRING165 "The path to the Lit testing configuration to use when running the tests.166 If a relative path is provided, it is assumed to be relative to '<monorepo>/libcxx/test/configs'.")167if (NOT IS_ABSOLUTE "${LIBCXX_TEST_CONFIG}")168 set(LIBCXX_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/configs/${LIBCXX_TEST_CONFIG}")169endif()170message(STATUS "Using libc++ testing configuration: ${LIBCXX_TEST_CONFIG}")171set(LIBCXX_TEST_PARAMS "" CACHE STRING172 "A list of parameters to run the Lit test suite with.")173 174# TODO: Figure out how to build GoogleBenchmark on those platforms, and how to build when exceptions or RTTI is disabled175if (WIN32 OR MINGW OR ANDROID OR "${CMAKE_SYSTEM_NAME}" MATCHES "AIX"176 OR NOT LIBCXX_ENABLE_LOCALIZATION177 OR NOT LIBCXX_ENABLE_THREADS178 OR NOT LIBCXX_ENABLE_FILESYSTEM179 OR NOT LIBCXX_ENABLE_RANDOM_DEVICE180 OR NOT LIBCXX_ENABLE_EXCEPTIONS181 OR NOT LIBCXX_ENABLE_RTTI)182 set(_include_benchmarks OFF)183else()184 set(_include_benchmarks ON)185endif()186option(LIBCXX_INCLUDE_BENCHMARKS "Build the libc++ benchmarks and their dependencies" ${_include_benchmarks})187 188option(LIBCXX_INCLUDE_DOCS "Build the libc++ documentation." ${LLVM_INCLUDE_DOCS})189set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING190 "Define suffix of library directory name (32/64)")191option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON)192option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON)193option(LIBCXX_INSTALL_MODULES194 "Install the libc++ C++20 module source files (experimental)." ON195)196cmake_dependent_option(LIBCXX_INSTALL_STATIC_LIBRARY197 "Install the static libc++ library." ON198 "LIBCXX_ENABLE_STATIC;LIBCXX_INSTALL_LIBRARY" OFF)199cmake_dependent_option(LIBCXX_INSTALL_SHARED_LIBRARY200 "Install the shared libc++ library." ON201 "LIBCXX_ENABLE_SHARED;LIBCXX_INSTALL_LIBRARY" OFF)202 203option(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)204if (LIBCXX_ABI_UNSTABLE)205 set(abi_version "2")206else()207 set(abi_version "1")208endif()209set(LIBCXX_ABI_VERSION "${abi_version}" CACHE STRING210 "ABI version of libc++. Can be either 1 or 2, where 2 is currently the unstable ABI.211 Defaults to 1 unless LIBCXX_ABI_UNSTABLE is specified, in which case this is 2.")212set(LIBCXX_LIBRARY_VERSION "${LIBCXX_ABI_VERSION}.0" CACHE STRING213 "Version of libc++. This will be reflected in the name of the shared library produced.214 For example, -DLIBCXX_LIBRARY_VERSION=x.y will result in the library being named215 libc++.x.y.dylib, along with the usual symlinks pointing to that. On Apple platforms,216 this also controls the linker's 'current_version' property.")217set(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.")218if (NOT LIBCXX_ABI_NAMESPACE MATCHES "__.*")219 message(FATAL_ERROR "LIBCXX_ABI_NAMESPACE must be a reserved identifier, got '${LIBCXX_ABI_NAMESPACE}'.")220endif()221option(LIBCXX_ABI_FORCE_ITANIUM "Ignore auto-detection and force use of the Itanium ABI.")222option(LIBCXX_ABI_FORCE_MICROSOFT "Ignore auto-detection and force use of the Microsoft ABI.")223 224set(LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION "default" CACHE STRING225 "Override the implementation to use for comparing typeinfos. By default, this226 is detected automatically by the library, but this option allows overriding227 which implementation is used unconditionally.228 229 See the documentation in <libcxx/include/typeinfo> for details on what each230 value means.")231set(TYPEINFO_COMPARISON_VALUES "default;1;2;3")232if (NOT ("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" IN_LIST TYPEINFO_COMPARISON_VALUES))233 message(FATAL_ERROR "Value '${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}' is not a valid value for234 LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION")235endif()236 237set(LIBCXX_ABI_DEFINES "" CACHE STRING "A semicolon separated list of ABI macros to define in the site config header.")238set(LIBCXX_EXTRA_SITE_DEFINES "" CACHE STRING "Extra defines to add into __config_site")239option(LIBCXX_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)240 241# ABI Library options ---------------------------------------------------------242if (MSVC)243 set(LIBCXX_DEFAULT_ABI_LIBRARY "vcruntime")244else()245 set(LIBCXX_DEFAULT_ABI_LIBRARY "libcxxabi")246endif()247 248set(LIBCXX_SUPPORTED_ABI_LIBRARIES none libcxxabi system-libcxxabi libcxxrt libstdc++ libsupc++ vcruntime)249set(LIBCXX_CXX_ABI "${LIBCXX_DEFAULT_ABI_LIBRARY}" CACHE STRING "Specify C++ ABI library to use. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}.")250if (NOT "${LIBCXX_CXX_ABI}" IN_LIST LIBCXX_SUPPORTED_ABI_LIBRARIES)251 message(FATAL_ERROR "Unsupported C++ ABI library: '${LIBCXX_CXX_ABI}'. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}.")252endif()253 254option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY255 "Use a static copy of the ABI library when linking libc++.256 This option cannot be used with LIBCXX_ENABLE_ABI_LINKER_SCRIPT." OFF)257 258option(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY259 "Statically link the ABI library to static library"260 ${LIBCXX_ENABLE_STATIC_ABI_LIBRARY})261 262option(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY263 "Statically link the ABI library to shared library"264 ${LIBCXX_ENABLE_STATIC_ABI_LIBRARY})265 266# Generate and install a linker script inplace of libc++.so. The linker script267# will link libc++ to the correct ABI library. This option is on by default268# on UNIX platforms other than Apple, and on the Fuchsia platform unless we269# statically link libc++abi inside libc++.so, we don't build libc++.so at all270# or we don't have any ABI library.271if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY272 OR NOT LIBCXX_ENABLE_SHARED273 OR LIBCXX_CXX_ABI STREQUAL "none")274 set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF)275elseif((UNIX OR FUCHSIA) AND NOT APPLE)276 set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE ON)277else()278 set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF)279endif()280option(LIBCXX_ENABLE_ABI_LINKER_SCRIPT281 "Use and install a linker script for the given ABI library"282 ${ENABLE_LINKER_SCRIPT_DEFAULT_VALUE})283 284option(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS285 "Build libc++ with definitions for operator new/delete. These are normally286 defined in libc++abi, but this option can be used to define them in libc++287 instead. If you define them in libc++, make sure they are NOT defined in288 libc++abi. Doing otherwise is an ODR violation." OFF)289# Build libc++abi with libunwind. We need this option to determine whether to290# link with libunwind or libgcc_s while running the test cases.291option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." ON)292 293# Target options --------------------------------------------------------------294option(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})295if (LIBCXX_BUILD_32_BITS)296 message(FATAL_ERROR "LIBCXX_BUILD_32_BITS is not supported anymore when building the runtimes, please specify a full triple instead.")297endif()298 299# Feature options -------------------------------------------------------------300option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF)301option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF)302option(LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32 thread API" OFF)303option(LIBCXX_HAS_EXTERNAL_THREAD_API304 "Build libc++ with an externalized threading API.305 This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF)306 307if (LIBCXX_ENABLE_THREADS)308 set(LIBCXX_PSTL_BACKEND "std_thread" CACHE STRING "Which PSTL backend to use")309else()310 set(LIBCXX_PSTL_BACKEND "serial" CACHE STRING "Which PSTL backend to use")311endif()312 313# Misc options ----------------------------------------------------------------314# FIXME: Turn -pedantic back ON. It is currently off because it warns315# about #include_next which is used everywhere.316option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF)317option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)318 319set(LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT OFF)320if (WIN32)321 set(LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT ON)322endif()323option(LIBCXX_HERMETIC_STATIC_LIBRARY324 "Do not export any symbols from the static library." ${LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT})325 326#===============================================================================327# Check option configurations328#===============================================================================329 330# Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON only when331# LIBCXX_ENABLE_THREADS is on.332if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_ENABLE_MONOTONIC_CLOCK)333 message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF"334 " when LIBCXX_ENABLE_THREADS is also set to OFF.")335endif()336 337if(NOT LIBCXX_ENABLE_THREADS)338 if(LIBCXX_HAS_PTHREAD_API)339 message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON"340 " when LIBCXX_ENABLE_THREADS is also set to ON.")341 endif()342 if(LIBCXX_HAS_EXTERNAL_THREAD_API)343 message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set to ON"344 " when LIBCXX_ENABLE_THREADS is also set to ON.")345 endif()346 if (LIBCXX_HAS_WIN32_THREAD_API)347 message(FATAL_ERROR "LIBCXX_HAS_WIN32_THREAD_API can only be set to ON"348 " when LIBCXX_ENABLE_THREADS is also set to ON.")349 endif()350 351endif()352 353if (LIBCXX_HAS_EXTERNAL_THREAD_API)354 if (LIBCXX_HAS_PTHREAD_API)355 message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"356 " and LIBCXX_HAS_PTHREAD_API cannot be both"357 " set to ON at the same time.")358 endif()359 if (LIBCXX_HAS_WIN32_THREAD_API)360 message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"361 " and LIBCXX_HAS_WIN32_THREAD_API cannot be both"362 " set to ON at the same time.")363 endif()364endif()365 366if (LIBCXX_HAS_PTHREAD_API)367 if (LIBCXX_HAS_WIN32_THREAD_API)368 message(FATAL_ERROR "The options LIBCXX_HAS_PTHREAD_API"369 " and LIBCXX_HAS_WIN32_THREAD_API cannot be both"370 " set to ON at the same time.")371 endif()372endif()373 374if (NOT LIBCXX_ENABLE_RTTI AND LIBCXX_ENABLE_EXCEPTIONS)375 message(FATAL_ERROR "Libc++ cannot be built with exceptions enabled but RTTI"376 " disabled, since that configuration is broken. See"377 " https://llvm.org/PR66117 for details.")378endif()379 380if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)381 if (APPLE)382 message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT cannot be used on APPLE targets")383 endif()384 if (NOT LIBCXX_ENABLE_SHARED)385 message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT is only available for shared library builds.")386 endif()387endif()388 389if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT)390 message(FATAL_ERROR "Conflicting options given.391 LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY cannot be specified with392 LIBCXX_ENABLE_ABI_LINKER_SCRIPT")393endif()394 395if (LIBCXX_ABI_FORCE_ITANIUM AND LIBCXX_ABI_FORCE_MICROSOFT)396 message(FATAL_ERROR "Only one of LIBCXX_ABI_FORCE_ITANIUM and LIBCXX_ABI_FORCE_MICROSOFT can be specified.")397endif ()398 399if (LIBCXX_ENABLE_SHARED AND CMAKE_MSVC_RUNTIME_LIBRARY AND400 (NOT CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL$"))401 message(WARNING "A static CRT linked into a shared libc++ doesn't work correctly.")402endif()403 404#===============================================================================405# Configure System406#===============================================================================407 408# TODO: Projects that depend on libc++ should use LIBCXX_GENERATED_INCLUDE_DIR409# instead of hard-coding include/c++/v1.410 411set(LIBCXX_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/c++/v1" CACHE STRING412 "Path where target-agnostic libc++ headers should be installed.")413set(LIBCXX_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING414 "Path where built libc++ runtime libraries should be installed.")415set(LIBCXX_INSTALL_MODULES_DIR "share/libc++/v1" CACHE STRING416 "Path where target-agnostic libc++ module source files should be installed.")417 418set(LIBCXX_SHARED_OUTPUT_NAME "c++" CACHE STRING "Output name for the shared libc++ runtime library.")419set(LIBCXX_STATIC_OUTPUT_NAME "c++" CACHE STRING "Output name for the static libc++ runtime library.")420 421if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)422 set(LIBCXX_TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE})423 if(LIBCXX_LIBDIR_SUBDIR)424 string(APPEND LIBCXX_TARGET_SUBDIR /${LIBCXX_LIBDIR_SUBDIR})425 endif()426 cmake_path(NORMAL_PATH LIBCXX_TARGET_SUBDIR)427 set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LIBCXX_TARGET_SUBDIR})428 set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")429 set(LIBCXX_GENERATED_MODULE_DIR "${LLVM_BINARY_DIR}/modules/c++/v1")430 set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LIBCXX_TARGET_SUBDIR}/c++/v1")431 set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LIBCXX_TARGET_SUBDIR} CACHE STRING432 "Path where built libc++ libraries should be installed.")433 set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${LIBCXX_TARGET_SUBDIR}/c++/v1" CACHE STRING434 "Path where target-specific libc++ headers should be installed.")435 unset(LIBCXX_TARGET_SUBDIR)436else()437 if(LLVM_LIBRARY_OUTPUT_INTDIR)438 set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})439 set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")440 set(LIBCXX_GENERATED_MODULE_DIR "${LLVM_BINARY_DIR}/modules/c++/v1")441 else()442 set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})443 set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1")444 set(LIBCXX_GENERATED_MODULE_DIR "${CMAKE_BINARY_DIR}/modules/c++/v1")445 endif()446 set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}")447 set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX} CACHE STRING448 "Path where built libc++ libraries should be installed.")449 set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${LIBCXX_INSTALL_INCLUDE_DIR}" CACHE STRING450 "Path where target-specific libc++ headers should be installed.")451endif()452 453set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})454set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})455set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})456 457# Declare libc++ configuration variables.458# They are intended for use as follows:459# LIBCXX_CXX_FLAGS: General flags for both the compiler and linker.460# LIBCXX_COMPILE_FLAGS: Compile only flags.461# LIBCXX_LINK_FLAGS: Linker only flags.462# LIBCXX_LIBRARIES: libraries libc++ is linked to.463set(LIBCXX_COMPILE_FLAGS "")464set(LIBCXX_LINK_FLAGS "")465set(LIBCXX_LIBRARIES "")466set(LIBCXX_ADDITIONAL_COMPILE_FLAGS "" CACHE STRING467 "Additional compile flags to use when building libc++. This should be a CMake ;-delimited list of individual468 compiler options to use. For options that must be passed as-is to the compiler without deduplication (e.g.469 `-Xclang -foo` option groups), consider using `SHELL:` (https://cmake.org/cmake/help/latest/command/add_compile_options.html#option-de-duplication).")470set(LIBCXX_ADDITIONAL_LIBRARIES "" CACHE STRING471 "Additional libraries libc++ is linked to which can be provided in cache")472 473# Include macros for adding and removing libc++ flags.474include(HandleLibcxxFlags)475 476# Target flags ================================================================477# These flags get added to CMAKE_CXX_FLAGS and CMAKE_C_FLAGS so that478# 'config-ix' use them during feature checks. It also adds them to both479# 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS'480 481if ("${CMAKE_SYSTEM_NAME}" MATCHES "AIX")482 add_flags_if_supported("-mdefault-visibility-export-mapping=explicit")483 set(CMAKE_AIX_EXPORT_ALL_SYMBOLS OFF)484endif()485 486# Configure compiler.487include(config-ix)488 489#===============================================================================490# Setup Compiler Flags491#===============================================================================492 493include(HandleLibC) # Setup the C library flags494include(HandleLibCXXABI) # Setup the ABI library flags495 496# FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC.497# Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors498# so they don't get transformed into -Wno and -errors respectively.499remove_flags(-Wno-pedantic -pedantic-errors -pedantic)500 501# Required flags ==============================================================502function(cxx_add_basic_build_flags target)503 504 # Use C++23 for all targets.505 set_target_properties(${target} PROPERTIES506 CXX_STANDARD 23507 CXX_STANDARD_REQUIRED OFF # TODO: Make this REQUIRED once we don't need to accommodate the LLVM documentation builders using an ancient CMake508 CXX_EXTENSIONS NO)509 510 # When building the dylib, don't warn for unavailable aligned allocation511 # functions based on the deployment target -- they are always available512 # because they are provided by the dylib itself with the exception of z/OS.513 if (ZOS)514 target_add_compile_flags_if_supported(${target} PRIVATE -fno-aligned-allocation)515 else()516 target_add_compile_flags_if_supported(${target} PRIVATE -faligned-allocation)517 endif()518 519 # On all systems the system c++ standard library headers need to be excluded.520 # MSVC only has -X, which disables all default includes; including the crt.521 # Thus, we do nothing and hope we don't accidentally include any of the C++522 # headers523 target_add_compile_flags_if_supported(${target} PUBLIC -nostdinc++)524 525 # Hide all inline function definitions which have not explicitly been marked526 # visible. This prevents new definitions for inline functions from appearing in527 # the dylib when get ODR used by another function.528 target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility-inlines-hidden)529 530 target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility=hidden)531 532 # Build with -fsized-deallocation, which is default in recent versions of Clang.533 # TODO(LLVM 21): This can be dropped once we only support Clang >= 19.534 target_add_compile_flags_if_supported(${target} PRIVATE -fsized-deallocation)535 536 # Let the library headers know they are currently being used to build the537 # library.538 target_compile_definitions(${target} PRIVATE -D_LIBCPP_BUILDING_LIBRARY)539 540 # Make sure the library can be build without transitive includes. This makes541 # it easier to upgrade the library to a newer language standard without build542 # errors.543 target_compile_definitions(${target} PRIVATE -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)544 545 if (C_SUPPORTS_COMMENT_LIB_PRAGMA)546 if (LIBCXX_HAS_PTHREAD_LIB)547 target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_PTHREAD_LIB)548 endif()549 if (LIBCXX_HAS_RT_LIB)550 target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_RT_LIB)551 endif()552 endif()553 target_compile_options(${target} PUBLIC "${LIBCXX_ADDITIONAL_COMPILE_FLAGS}")554endfunction()555 556# Exception flags =============================================================557function(cxx_add_exception_flags target)558 if (LIBCXX_ENABLE_EXCEPTIONS)559 # Catches C++ exceptions only and tells the compiler to assume that extern C560 # functions never throw a C++ exception.561 target_add_compile_flags_if_supported(${target} PUBLIC -EHsc)562 else()563 target_add_compile_flags_if_supported(${target} PUBLIC -EHs- -EHa-)564 target_add_compile_flags_if_supported(${target} PUBLIC -fno-exceptions)565 endif()566endfunction()567 568# RTTI flags ==================================================================569function(cxx_add_rtti_flags target)570 if (NOT LIBCXX_ENABLE_RTTI)571 if (MSVC)572 target_add_compile_flags_if_supported(${target} PUBLIC -GR-)573 else()574 target_add_compile_flags_if_supported(${target} PUBLIC -fno-rtti)575 endif()576 endif()577endfunction()578 579# Modules flags ===============================================================580# FIXME The libc++ sources are fundamentally non-modular. They need special581# versions of the headers in order to provide C++03 and legacy ABI definitions.582# NOTE: The public headers can be used with modules in all other contexts.583function(cxx_add_module_flags target)584 if (LLVM_ENABLE_MODULES)585 # Ignore that the rest of the modules flags are now unused.586 target_add_compile_flags_if_supported(${target} PUBLIC -Wno-unused-command-line-argument)587 target_compile_options(${target} PUBLIC -fno-modules)588 endif()589endfunction()590 591string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)592 593# Sanitizer flags =============================================================594 595function(get_sanitizer_flags OUT_VAR USE_SANITIZER)596 set(SANITIZER_FLAGS)597 set(USE_SANITIZER "${USE_SANITIZER}")598 # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC.599 # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do.600 if (USE_SANITIZER AND NOT MSVC)601 append_flags_if_supported(SANITIZER_FLAGS "-fno-omit-frame-pointer")602 append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only")603 604 if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND605 NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")606 append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only")607 endif()608 if (USE_SANITIZER STREQUAL "Address")609 append_flags(SANITIZER_FLAGS "-fsanitize=address")610 elseif (USE_SANITIZER STREQUAL "HWAddress")611 append_flags(SANITIZER_FLAGS "-fsanitize=hwaddress")612 elseif (USE_SANITIZER MATCHES "Memory(WithOrigins)?")613 append_flags(SANITIZER_FLAGS -fsanitize=memory)614 if (USE_SANITIZER STREQUAL "MemoryWithOrigins")615 append_flags(SANITIZER_FLAGS "-fsanitize-memory-track-origins")616 endif()617 elseif (USE_SANITIZER STREQUAL "Undefined")618 append_flags(SANITIZER_FLAGS "-fsanitize=undefined" "-fno-sanitize=vptr,function" "-fno-sanitize-recover=all")619 elseif (USE_SANITIZER STREQUAL "Address;Undefined" OR620 USE_SANITIZER STREQUAL "Undefined;Address")621 append_flags(SANITIZER_FLAGS "-fsanitize=address,undefined" "-fno-sanitize=vptr,function" "-fno-sanitize-recover=all")622 elseif (USE_SANITIZER STREQUAL "Thread")623 append_flags(SANITIZER_FLAGS -fsanitize=thread)624 elseif (USE_SANITIZER STREQUAL "DataFlow")625 append_flags(SANITIZER_FLAGS -fsanitize=dataflow)626 else()627 message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${USE_SANITIZER}")628 endif()629 elseif(USE_SANITIZER AND MSVC)630 message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.")631 endif()632 set(${OUT_VAR} "${SANITIZER_FLAGS}" PARENT_SCOPE)633endfunction()634 635get_sanitizer_flags(SANITIZER_FLAGS "${LLVM_USE_SANITIZER}")636add_library(cxx-sanitizer-flags INTERFACE)637target_compile_options(cxx-sanitizer-flags INTERFACE ${SANITIZER_FLAGS})638 639# _LIBCPP_INSTRUMENTED_WITH_ASAN informs that library was built with ASan.640# Defining _LIBCPP_INSTRUMENTED_WITH_ASAN while building the library with ASan is required.641# Normally, the _LIBCPP_INSTRUMENTED_WITH_ASAN flag is used to keep information whether642# dylibs are built with AddressSanitizer. However, when building libc++,643# this flag needs to be defined so that the resulting dylib has all ASan functionalities guarded by this flag.644# If the _LIBCPP_INSTRUMENTED_WITH_ASAN flag is not defined, then parts of the ASan instrumentation code in libc++645# will not be compiled into it, resulting in false positives.646# For context, read: https://github.com/llvm/llvm-project/pull/72677#pullrequestreview-1765402800647string(FIND "${LLVM_USE_SANITIZER}" "Address" building_with_asan)648if (NOT "${building_with_asan}" STREQUAL "-1")649 config_define(ON _LIBCPP_INSTRUMENTED_WITH_ASAN)650else()651 config_define(OFF _LIBCPP_INSTRUMENTED_WITH_ASAN)652endif()653 654# Link system libraries =======================================================655function(cxx_link_system_libraries target)656 if (NOT MSVC)657 target_link_libraries(${target} PRIVATE "-nostdlib++")658 endif()659 660 if (CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG AND LIBCXXABI_USE_LLVM_UNWINDER)661 # If we're linking directly against the libunwind that we're building662 # in the same invocation, don't try to link in the toolchain's663 # default libunwind (which may be missing still).664 target_add_link_flags_if_supported(${target} PRIVATE "--unwindlib=none")665 endif()666 667 if (MSVC)668 if (LIBCXX_USE_COMPILER_RT)669 find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY)670 if (LIBCXX_BUILTINS_LIBRARY)671 target_link_libraries(${target} PRIVATE "${LIBCXX_BUILTINS_LIBRARY}")672 endif()673 elseif (LIBCXX_HAS_GCC_LIB)674 target_link_libraries(${target} PRIVATE gcc)675 elseif (LIBCXX_HAS_GCC_S_LIB)676 target_link_libraries(${target} PRIVATE gcc_s)677 endif()678 endif()679 680 if (LIBCXX_HAS_ATOMIC_LIB)681 target_link_libraries(${target} PRIVATE atomic)682 endif()683 684 if (MINGW)685 target_link_libraries(${target} PRIVATE "${MINGW_LIBRARIES}")686 endif()687 688 if (MSVC)689 if ((NOT CMAKE_MSVC_RUNTIME_LIBRARY AND uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")690 OR (CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "Debug"))691 set(LIB_SUFFIX "d")692 else()693 set(LIB_SUFFIX "")694 endif()695 696 if (NOT CMAKE_MSVC_RUNTIME_LIBRARY OR CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL$")697 set(CRT_LIB "msvcrt")698 set(CXX_LIB "msvcprt")699 else()700 set(CRT_LIB "libcmt")701 set(CXX_LIB "libcpmt")702 endif()703 704 target_link_libraries(${target} PRIVATE ${CRT_LIB}${LIB_SUFFIX}) # C runtime startup files705 target_link_libraries(${target} PRIVATE ${CXX_LIB}${LIB_SUFFIX}) # C++ standard library. Required for exception_ptr internals.706 # Required for standards-complaint wide character formatting functions707 # (e.g. `printfw`/`scanfw`)708 target_link_libraries(${target} PRIVATE iso_stdio_wide_specifiers)709 endif()710 711 if (ANDROID AND ANDROID_PLATFORM_LEVEL LESS 21)712 target_link_libraries(${target} PUBLIC android_support)713 endif()714 target_link_libraries(${target} PUBLIC "${LIBCXX_ADDITIONAL_LIBRARIES}")715endfunction()716 717# Windows-related flags =======================================================718function(cxx_add_windows_flags target)719 if(WIN32 AND NOT MINGW)720 target_compile_definitions(${target} PRIVATE721 # Ignore the -MSC_VER mismatch, as we may build722 # with a different compatibility version.723 _ALLOW_MSC_VER_MISMATCH724 # Don't check the msvcprt iterator debug levels725 # as we will define the iterator types; libc++726 # uses a different macro to identify the debug727 # level.728 _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH729 # We are building the c++ runtime, don't pull in730 # msvcprt.731 _CRTBLD732 # Don't warn on the use of "deprecated"733 # "insecure" functions which are standards734 # specified.735 _CRT_SECURE_NO_WARNINGS736 # Use the ISO conforming behaviour for conversion737 # in printf, scanf.738 _CRT_STDIO_ISO_WIDE_SPECIFIERS)739 endif()740endfunction()741 742# Configuration file flags =====================================================743config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION)744config_define(${LIBCXX_ABI_NAMESPACE} _LIBCPP_ABI_NAMESPACE)745config_define(${LIBCXX_ABI_FORCE_ITANIUM} _LIBCPP_ABI_FORCE_ITANIUM)746config_define(${LIBCXX_ABI_FORCE_MICROSOFT} _LIBCPP_ABI_FORCE_MICROSOFT)747config_define(${LIBCXX_ENABLE_THREADS} _LIBCPP_HAS_THREADS)748config_define(${LIBCXX_ENABLE_MONOTONIC_CLOCK} _LIBCPP_HAS_MONOTONIC_CLOCK)749config_define(${LIBCXX_HAS_TERMINAL_AVAILABLE} _LIBCPP_HAS_TERMINAL)750if (NOT LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION STREQUAL "default")751 config_define("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION)752endif()753config_define(${LIBCXX_HAS_PTHREAD_API} _LIBCPP_HAS_THREAD_API_PTHREAD)754config_define(${LIBCXX_HAS_EXTERNAL_THREAD_API} _LIBCPP_HAS_THREAD_API_EXTERNAL)755config_define(${LIBCXX_HAS_WIN32_THREAD_API} _LIBCPP_HAS_THREAD_API_WIN32)756config_define(${LIBCXX_HAS_MUSL_LIBC} _LIBCPP_HAS_MUSL_LIBC)757config_define_if(LIBCXX_NO_VCRUNTIME _LIBCPP_NO_VCRUNTIME)758config_define(${LIBCXX_ENABLE_FILESYSTEM} _LIBCPP_HAS_FILESYSTEM)759config_define(${LIBCXX_ENABLE_RANDOM_DEVICE} _LIBCPP_HAS_RANDOM_DEVICE)760config_define(${LIBCXX_ENABLE_LOCALIZATION} _LIBCPP_HAS_LOCALIZATION)761config_define(${LIBCXX_ENABLE_UNICODE} _LIBCPP_HAS_UNICODE)762config_define(${LIBCXX_ENABLE_WIDE_CHARACTERS} _LIBCPP_HAS_WIDE_CHARACTERS)763config_define(${LIBCXX_ENABLE_TIME_ZONE_DATABASE} _LIBCPP_HAS_TIME_ZONE_DATABASE)764config_define(${LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS} _LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS)765 766# Set C library in use767if (RUNTIMES_USE_LIBC STREQUAL "picolibc")768 config_define(1 _LIBCPP_LIBC_PICOLIBC)769 # picolibc is derived from newlib and behaves the same in regards to libc++770 # so setting both here:771 # * _LIBCPP_LIBC_NEWLIB is used now772 # * _LIBCPP_LIBC_PICOLIBC can be used for further customizations later773 config_define(1 _LIBCPP_LIBC_NEWLIB)774elseif (RUNTIMES_USE_LIBC STREQUAL "newlib")775 config_define(1 _LIBCPP_LIBC_NEWLIB)776endif()777 778# TODO: Remove in LLVM 21. We're leaving an error to make this fail explicitly.779if (LIBCXX_ENABLE_ASSERTIONS)780 message(FATAL_ERROR "LIBCXX_ENABLE_ASSERTIONS has been removed. Please use LIBCXX_HARDENING_MODE instead.")781endif()782if (LIBCXX_HARDENING_MODE STREQUAL "none")783 config_define(2 _LIBCPP_HARDENING_MODE_DEFAULT)784elseif (LIBCXX_HARDENING_MODE STREQUAL "fast")785 config_define(4 _LIBCPP_HARDENING_MODE_DEFAULT)786elseif (LIBCXX_HARDENING_MODE STREQUAL "extensive")787 config_define(16 _LIBCPP_HARDENING_MODE_DEFAULT)788elseif (LIBCXX_HARDENING_MODE STREQUAL "debug")789 config_define(8 _LIBCPP_HARDENING_MODE_DEFAULT)790endif()791if (LIBCXX_ASSERTION_SEMANTIC STREQUAL "hardening_dependent")792 config_define(2 _LIBCPP_ASSERTION_SEMANTIC_DEFAULT)793elseif (LIBCXX_ASSERTION_SEMANTIC STREQUAL "ignore")794 config_define(4 _LIBCPP_ASSERTION_SEMANTIC_DEFAULT)795elseif (LIBCXX_ASSERTION_SEMANTIC STREQUAL "observe")796 config_define(8 _LIBCPP_ASSERTION_SEMANTIC_DEFAULT)797elseif (LIBCXX_ASSERTION_SEMANTIC STREQUAL "quick_enforce")798 config_define(16 _LIBCPP_ASSERTION_SEMANTIC_DEFAULT)799elseif (LIBCXX_ASSERTION_SEMANTIC STREQUAL "enforce")800 config_define(32 _LIBCPP_ASSERTION_SEMANTIC_DEFAULT)801endif()802 803if (LIBCXX_PSTL_BACKEND STREQUAL "serial")804 config_define(1 _LIBCPP_PSTL_BACKEND_SERIAL)805elseif(LIBCXX_PSTL_BACKEND STREQUAL "std_thread")806 config_define(1 _LIBCPP_PSTL_BACKEND_STD_THREAD)807elseif(LIBCXX_PSTL_BACKEND STREQUAL "libdispatch")808 config_define(1 _LIBCPP_PSTL_BACKEND_LIBDISPATCH)809else()810 message(FATAL_ERROR "LIBCXX_PSTL_BACKEND is set to ${LIBCXX_PSTL_BACKEND}, which is not a valid backend.811 Valid backends are: serial, std_thread and libdispatch")812endif()813 814if (LIBCXX_ABI_DEFINES)815 set(abi_defines)816 foreach (abi_define ${LIBCXX_ABI_DEFINES})817 if (NOT abi_define MATCHES "^_LIBCPP_ABI_")818 message(SEND_ERROR "Invalid ABI macro ${abi_define} in LIBCXX_ABI_DEFINES")819 endif()820 list(APPEND abi_defines "#define ${abi_define}")821 endforeach()822 string(REPLACE ";" "\n" abi_defines "${abi_defines}")823 config_define(${abi_defines} _LIBCPP_ABI_DEFINES)824endif()825 826if (LIBCXX_EXTRA_SITE_DEFINES)827 set(extra_site_defines)828 foreach (extra_site_define ${LIBCXX_EXTRA_SITE_DEFINES})829 # Allow defines such as DEFINE=VAL, transformed into "#define DEFINE VAL".830 string(REPLACE "=" " " extra_site_define "${extra_site_define}")831 list(APPEND extra_site_defines "#define ${extra_site_define}")832 endforeach()833 string(REPLACE ";" "\n" extra_site_defines "${extra_site_defines}")834 config_define(${extra_site_defines} _LIBCPP_EXTRA_SITE_DEFINES)835endif()836 837# By default libc++ on Windows expects to use a shared library, which requires838# the headers to use DLL import/export semantics. However when building a839# static library only we modify the headers to disable DLL import/export.840if (DEFINED WIN32 AND LIBCXX_ENABLE_STATIC AND NOT LIBCXX_ENABLE_SHARED)841 message(STATUS "Generating custom __config for non-DLL Windows build")842 config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)843endif()844 845if (WIN32 AND LIBCXX_ENABLE_STATIC_ABI_LIBRARY)846 # If linking libcxxabi statically into libcxx, skip the dllimport attributes847 # on symbols we refer to from libcxxabi.848 add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS)849endif()850 851# Setup all common build flags =================================================852function(cxx_add_common_build_flags target)853 cxx_add_basic_build_flags(${target})854 cxx_add_warning_flags(${target} ${LIBCXX_ENABLE_WERROR} ${LIBCXX_ENABLE_PEDANTIC})855 cxx_add_windows_flags(${target})856 cxx_add_exception_flags(${target})857 cxx_add_rtti_flags(${target})858 cxx_add_module_flags(${target})859 cxx_link_system_libraries(${target})860 target_link_libraries(${target} PRIVATE cxx-sanitizer-flags)861endfunction()862 863#===============================================================================864# Setup Source Code And Tests865#===============================================================================866add_custom_target(cxx-test-depends867 COMMENT "Build dependencies required to run the libc++ test suite.")868 869add_subdirectory(include)870add_subdirectory(src)871add_subdirectory(utils)872add_subdirectory(modules)873 874if (LIBCXX_INCLUDE_TESTS)875 add_subdirectory(test)876 add_subdirectory(lib/abi)877endif()878 879if (LIBCXX_INCLUDE_DOCS)880 add_subdirectory(docs)881endif()882