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