1# See https://libcxx.llvm.org/docs/BuildingLibcxx.html for instructions on how 2# to build libcxx with CMake. 3 4if (NOT IS_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/../libcxxabi") 5 message(FATAL_ERROR "libc++ now requires being built in a monorepo layout with libcxxabi available") 6endif() 7 8#=============================================================================== 9# Setup Project 10#=============================================================================== 11cmake_minimum_required(VERSION 3.13.4) 12 13set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON) 14 15# Add path for custom modules 16set(CMAKE_MODULE_PATH 17 "${CMAKE_CURRENT_SOURCE_DIR}/cmake" 18 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" 19 ${CMAKE_MODULE_PATH} 20 ) 21 22set(CMAKE_FOLDER "libc++") 23 24set(LIBCXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) 25set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) 26set(LIBCXX_BINARY_INCLUDE_DIR "${LIBCXX_BINARY_DIR}/include/c++build") 27 28if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXX_STANDALONE_BUILD) 29 project(libcxx CXX C) 30 31 set(PACKAGE_NAME libcxx) 32 set(PACKAGE_VERSION 13.0.0git) 33 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") 34 set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org") 35 36 # In a standalone build, we don't have llvm to automatically generate the 37 # llvm-lit script for us. So we need to provide an explicit directory that 38 # the configurator should write the script into. 39 set(LIBCXX_STANDALONE_BUILD 1) 40 set(LLVM_LIT_OUTPUT_DIR "${LIBCXX_BINARY_DIR}/bin") 41 42 # Find the LLVM sources and simulate LLVM CMake options. 43 include(HandleOutOfTreeLLVM) 44endif() 45 46if (LIBCXX_STANDALONE_BUILD) 47 find_package(Python3 COMPONENTS Interpreter) 48 if(NOT Python3_Interpreter_FOUND) 49 message(WARNING "Python3 not found, using python2 as a fallback") 50 find_package(Python2 COMPONENTS Interpreter REQUIRED) 51 if(Python2_VERSION VERSION_LESS 2.7) 52 message(SEND_ERROR "Python 2.7 or newer is required") 53 endif() 54 55 # Treat python2 as python3 56 add_executable(Python3::Interpreter IMPORTED) 57 set_target_properties(Python3::Interpreter PROPERTIES 58 IMPORTED_LOCATION ${Python2_EXECUTABLE}) 59 set(Python3_EXECUTABLE ${Python2_EXECUTABLE}) 60 endif() 61endif() 62 63# Require out of source build. 64include(MacroEnsureOutOfSourceBuild) 65MACRO_ENSURE_OUT_OF_SOURCE_BUILD( 66 "${PROJECT_NAME} requires an out of source build. Please create a separate 67 build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there." 68 ) 69if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC") 70 message(STATUS "Configuring for clang-cl") 71 set(LIBCXX_TARGETING_CLANG_CL ON) 72endif() 73 74if (MSVC) 75 set(LIBCXX_TARGETING_MSVC ON) 76 message(STATUS "Configuring for MSVC") 77else() 78 set(LIBCXX_TARGETING_MSVC OFF) 79endif() 80 81#=============================================================================== 82# Setup CMake Options 83#=============================================================================== 84include(CMakeDependentOption) 85include(HandleCompilerRT) 86 87# Basic options --------------------------------------------------------------- 88option(LIBCXX_ENABLE_ASSERTIONS "Enable assertions independent of build mode." OFF) 89option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON) 90option(LIBCXX_ENABLE_STATIC "Build libc++ as a static library." ON) 91option(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY "Build libc++experimental.a" ON) 92set(ENABLE_FILESYSTEM_DEFAULT ON) 93if (WIN32 AND NOT MINGW) 94 # Filesystem is buildable for windows, but it requires __int128 helper 95 # functions, that currently are provided by libgcc or compiler_rt builtins. 96 # These are available in MinGW environments, but not currently in MSVC 97 # environments. 98 set(ENABLE_FILESYSTEM_DEFAULT OFF) 99endif() 100option(LIBCXX_ENABLE_FILESYSTEM "Build filesystem as part of the main libc++ library" 101 ${ENABLE_FILESYSTEM_DEFAULT}) 102option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS}) 103option(LIBCXX_ENABLE_PARALLEL_ALGORITHMS "Enable the parallel algorithms library. This requires the PSTL to be available." OFF) 104option(LIBCXX_ENABLE_DEBUG_MODE_SUPPORT 105 "Whether to include support for libc++'s debugging mode in the library. 106 By default, this is turned on. If you turn it off and try to enable the 107 debug mode when compiling a program against libc++, it will fail to link 108 since the required support isn't provided in the library." ON) 109option(LIBCXX_ENABLE_RANDOM_DEVICE 110 "Whether to include support for std::random_device in the library. Disabling 111 this can be useful when building the library for platforms that don't have 112 a source of randomness, such as some embedded platforms. When this is not 113 supported, most of <random> will still be available, but std::random_device 114 will not." ON) 115option(LIBCXX_ENABLE_LOCALIZATION 116 "Whether to include support for localization in the library. Disabling 117 localization can be useful when porting to platforms that don't support 118 the C locale API (e.g. embedded). When localization is not supported, 119 several parts of the library will be disabled: <iostream>, <regex>, <locale> 120 will be completely unusable, and other parts may be only partly available." ON) 121option(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS 122 "Whether to turn on vendor availability annotations on declarations that depend 123 on definitions in a shared library. By default, we assume that we're not building 124 libc++ for any specific vendor, and we disable those annotations. Vendors wishing 125 to provide compile-time errors when using features unavailable on some version of 126 the shared library they shipped should turn this on and see `include/__availability` 127 for more details." OFF) 128set(LIBCXX_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/configs/legacy.cfg.in" CACHE STRING 129 "The Lit testing configuration to use when running the tests.") 130set(LIBCXX_TEST_PARAMS "" CACHE STRING 131 "A list of parameters to run the Lit test suite with.") 132 133# Benchmark options ----------------------------------------------------------- 134option(LIBCXX_INCLUDE_BENCHMARKS "Build the libc++ benchmarks and their dependencies" ON) 135 136set(LIBCXX_BENCHMARK_TEST_ARGS_DEFAULT --benchmark_min_time=0.01) 137set(LIBCXX_BENCHMARK_TEST_ARGS "${LIBCXX_BENCHMARK_TEST_ARGS_DEFAULT}" CACHE STRING 138 "Arguments to pass when running the benchmarks using check-cxx-benchmarks") 139 140set(LIBCXX_BENCHMARK_NATIVE_STDLIB "" CACHE STRING 141 "Build the benchmarks against the specified native STL. 142 The value must be one of libc++/libstdc++") 143set(LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN "" CACHE STRING 144 "Use alternate GCC toolchain when building the native benchmarks") 145 146if (LIBCXX_BENCHMARK_NATIVE_STDLIB) 147 if (NOT (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libc++" 148 OR LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libstdc++")) 149 message(FATAL_ERROR "Invalid value for LIBCXX_BENCHMARK_NATIVE_STDLIB: " 150 "'${LIBCXX_BENCHMARK_NATIVE_STDLIB}'") 151 endif() 152endif() 153 154option(LIBCXX_INCLUDE_DOCS "Build the libc++ documentation." ${LLVM_INCLUDE_DOCS}) 155set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING 156 "Define suffix of library directory name (32/64)") 157option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON) 158option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON) 159cmake_dependent_option(LIBCXX_INSTALL_STATIC_LIBRARY 160 "Install the static libc++ library." ON 161 "LIBCXX_ENABLE_STATIC;LIBCXX_INSTALL_LIBRARY" OFF) 162cmake_dependent_option(LIBCXX_INSTALL_SHARED_LIBRARY 163 "Install the shared libc++ library." ON 164 "LIBCXX_ENABLE_SHARED;LIBCXX_INSTALL_LIBRARY" OFF) 165cmake_dependent_option(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY 166 "Install libc++experimental.a" ON 167 "LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY;LIBCXX_INSTALL_LIBRARY" OFF) 168 169set(LIBCXX_ABI_VERSION "1" CACHE STRING "ABI version of libc++. Can be either 1 or 2, where 2 is currently not stable. Defaults to 1.") 170set(LIBCXX_ABI_NAMESPACE "" CACHE STRING "The inline ABI namespace used by libc++. It defaults to __n where `n` is the current ABI version.") 171option(LIBCXX_ABI_UNSTABLE "Unstable ABI of libc++." OFF) 172option(LIBCXX_ABI_FORCE_ITANIUM "Ignore auto-detection and force use of the Itanium ABI.") 173option(LIBCXX_ABI_FORCE_MICROSOFT "Ignore auto-detection and force use of the Microsoft ABI.") 174 175set(LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION "default" CACHE STRING 176 "Override the implementation to use for comparing typeinfos. By default, this 177 is detected automatically by the library, but this option allows overriding 178 which implementation is used unconditionally. 179 180 See the documentation in <libcxx/include/typeinfo> for details on what each 181 value means.") 182set(TYPEINFO_COMPARISON_VALUES "default;1;2;3") 183if (NOT ("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" IN_LIST TYPEINFO_COMPARISON_VALUES)) 184 message(FATAL_ERROR "Value '${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}' is not a valid value for 185 LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION") 186endif() 187 188option(LIBCXX_HIDE_FROM_ABI_PER_TU_BY_DEFAULT "Enable per TU ABI insulation by default. To be used by vendors." OFF) 189set(LIBCXX_ABI_DEFINES "" CACHE STRING "A semicolon separated list of ABI macros to define in the site config header.") 190option(LIBCXX_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF) 191set(LIBCXX_LIBCPPABI_VERSION "2" CACHE STRING "Version of libc++abi's ABI to re-export from libc++ when re-exporting is enabled. 192 Note that this is not related to the version of libc++'s ABI itself!") 193 194# ABI Library options --------------------------------------------------------- 195set(LIBCXX_CXX_ABI "default" CACHE STRING "Specify C++ ABI library to use.") 196set(CXXABIS none default libcxxabi libcxxrt libstdc++ libsupc++ vcruntime) 197set_property(CACHE LIBCXX_CXX_ABI PROPERTY STRINGS ;${CXXABIS}) 198 199# Setup the default options if LIBCXX_CXX_ABI is not specified. 200if (LIBCXX_CXX_ABI STREQUAL "default") 201 if (LIBCXX_TARGETING_MSVC) 202 # FIXME: Figure out how to configure the ABI library on Windows. 203 set(LIBCXX_CXX_ABI_LIBNAME "vcruntime") 204 elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") 205 set(LIBCXX_CXX_ABI_LIBNAME "libcxxrt") 206 elseif (NOT LIBCXX_STANDALONE_BUILD OR HAVE_LIBCXXABI) 207 set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi") 208 else() 209 set(LIBCXX_CXX_ABI_LIBNAME "default") 210 endif() 211else() 212 set(LIBCXX_CXX_ABI_LIBNAME "${LIBCXX_CXX_ABI}") 213endif() 214 215option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY 216 "Use a static copy of the ABI library when linking libc++. 217 This option cannot be used with LIBCXX_ENABLE_ABI_LINKER_SCRIPT." OFF) 218 219cmake_dependent_option(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY 220 "Statically link the ABI library to static library" ON 221 "LIBCXX_ENABLE_STATIC_ABI_LIBRARY;LIBCXX_ENABLE_STATIC" OFF) 222 223cmake_dependent_option(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY 224 "Statically link the ABI library to shared library" ON 225 "LIBCXX_ENABLE_STATIC_ABI_LIBRARY;LIBCXX_ENABLE_SHARED" OFF) 226 227# Generate and install a linker script inplace of libc++.so. The linker script 228# will link libc++ to the correct ABI library. This option is on by default 229# on UNIX platforms other than Apple unless 'LIBCXX_ENABLE_STATIC_ABI_LIBRARY' 230# is on. This option is also disabled when the ABI library is not specified 231# or is specified to be "none". 232set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF) 233if (LLVM_HAVE_LINK_VERSION_SCRIPT AND NOT LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY 234 AND NOT LIBCXX_CXX_ABI_LIBNAME STREQUAL "none" 235 AND NOT LIBCXX_CXX_ABI_LIBNAME STREQUAL "default" 236 AND Python3_EXECUTABLE 237 AND LIBCXX_ENABLE_SHARED) 238 set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE ON) 239endif() 240 241option(LIBCXX_ENABLE_ABI_LINKER_SCRIPT 242 "Use and install a linker script for the given ABI library" 243 ${ENABLE_LINKER_SCRIPT_DEFAULT_VALUE}) 244 245option(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS 246 "Build libc++ with definitions for operator new/delete. These are normally 247 defined in libc++abi, but this option can be used to define them in libc++ 248 instead. If you define them in libc++, make sure they are NOT defined in 249 libc++abi. Doing otherwise is an ODR violation." OFF) 250# Build libc++abi with libunwind. We need this option to determine whether to 251# link with libunwind or libgcc_s while running the test cases. 252option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF) 253 254# Target options -------------------------------------------------------------- 255option(LIBCXX_BUILD_32_BITS "Build 32 bit libc++." ${LLVM_BUILD_32_BITS}) 256set(LIBCXX_TARGET_TRIPLE "" CACHE STRING "Use alternate target triple.") 257set(LIBCXX_SYSROOT "" CACHE STRING "Use alternate sysroot.") 258set(LIBCXX_GCC_TOOLCHAIN "" CACHE STRING "Use alternate GCC toolchain.") 259 260# Feature options ------------------------------------------------------------- 261option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON) 262option(LIBCXX_ENABLE_RTTI "Use run time type information." ON) 263option(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE "Build libc++ with support for the global filesystem namespace." ON) 264option(LIBCXX_ENABLE_STDIN "Build libc++ with support for stdin/std::cin." ON) 265option(LIBCXX_ENABLE_STDOUT "Build libc++ with support for stdout/std::cout." ON) 266option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON) 267option(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS "Build libc++ with support for thread-unsafe C functions" ON) 268option(LIBCXX_ENABLE_MONOTONIC_CLOCK 269 "Build libc++ with support for a monotonic clock. 270 This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON) 271option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF) 272option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF) 273option(LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32 thread API" OFF) 274option(LIBCXX_HAS_EXTERNAL_THREAD_API 275 "Build libc++ with an externalized threading API. 276 This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF) 277option(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY 278 "Build libc++ with an externalized threading library. 279 This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON" OFF) 280 281# Misc options ---------------------------------------------------------------- 282# FIXME: Turn -pedantic back ON. It is currently off because it warns 283# about #include_next which is used everywhere. 284option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF) 285option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) 286option(LIBCXX_DISABLE_MACRO_CONFLICT_WARNINGS "Disable #warnings about conflicting macros." OFF) 287 288option(LIBCXX_GENERATE_COVERAGE "Enable generating code coverage." OFF) 289set(LIBCXX_COVERAGE_LIBRARY "" CACHE STRING 290 "The Profile-rt library used to build with code coverage") 291 292set(LIBCXX_CONFIGURE_IDE_DEFAULT OFF) 293if (XCODE OR MSVC_IDE) 294 set(LIBCXX_CONFIGURE_IDE_DEFAULT ON) 295endif() 296option(LIBCXX_CONFIGURE_IDE "Configure libcxx for use within an IDE" 297 ${LIBCXX_CONFIGURE_IDE_DEFAULT}) 298 299option(LIBCXX_HERMETIC_STATIC_LIBRARY 300 "Do not export any symbols from the static library." OFF) 301 302#=============================================================================== 303# Check option configurations 304#=============================================================================== 305 306# Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON only when 307# LIBCXX_ENABLE_THREADS is on. 308if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_ENABLE_MONOTONIC_CLOCK) 309 message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF" 310 " when LIBCXX_ENABLE_THREADS is also set to OFF.") 311endif() 312 313if(NOT LIBCXX_ENABLE_THREADS) 314 if(LIBCXX_HAS_PTHREAD_API) 315 message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON" 316 " when LIBCXX_ENABLE_THREADS is also set to ON.") 317 endif() 318 if(LIBCXX_HAS_EXTERNAL_THREAD_API) 319 message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set to ON" 320 " when LIBCXX_ENABLE_THREADS is also set to ON.") 321 endif() 322 if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY) 323 message(FATAL_ERROR "LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY can only be set " 324 "to ON when LIBCXX_ENABLE_THREADS is also set to ON.") 325 endif() 326 if (LIBCXX_HAS_WIN32_THREAD_API) 327 message(FATAL_ERROR "LIBCXX_HAS_WIN32_THREAD_API can only be set to ON" 328 " when LIBCXX_ENABLE_THREADS is also set to ON.") 329 endif() 330 331endif() 332 333if (LIBCXX_HAS_EXTERNAL_THREAD_API) 334 if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY) 335 message(FATAL_ERROR "The options LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY and " 336 "LIBCXX_HAS_EXTERNAL_THREAD_API cannot both be ON at " 337 "the same time") 338 endif() 339 if (LIBCXX_HAS_PTHREAD_API) 340 message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API" 341 "and LIBCXX_HAS_PTHREAD_API cannot be both" 342 "set to ON at the same time.") 343 endif() 344 if (LIBCXX_HAS_WIN32_THREAD_API) 345 message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API" 346 "and LIBCXX_HAS_WIN32_THREAD_API cannot be both" 347 "set to ON at the same time.") 348 endif() 349endif() 350 351if (LIBCXX_HAS_PTHREAD_API) 352 if (LIBCXX_HAS_WIN32_THREAD_API) 353 message(FATAL_ERROR "The options LIBCXX_HAS_PTHREAD_API" 354 "and LIBCXX_HAS_WIN32_THREAD_API cannot be both" 355 "set to ON at the same time.") 356 endif() 357endif() 358 359# Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE 360# is ON. 361if (LLVM_USE_SANITIZER AND LIBCXX_GENERATE_COVERAGE) 362 message(FATAL_ERROR "LLVM_USE_SANITIZER cannot be used with LIBCXX_GENERATE_COVERAGE") 363endif() 364 365# Set LIBCXX_BUILD_32_BITS to (LIBCXX_BUILD_32_BITS OR LLVM_BUILD_32_BITS) 366# and check that we can build with 32 bits if requested. 367if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32) 368 if (LIBCXX_BUILD_32_BITS AND NOT LLVM_BUILD_32_BITS) # Don't duplicate the output from LLVM 369 message(STATUS "Building 32 bits executables and libraries.") 370 endif() 371elseif(LIBCXX_BUILD_32_BITS) 372 message(FATAL_ERROR "LIBCXX_BUILD_32_BITS=ON is not supported on this platform.") 373endif() 374 375# Warn users that LIBCXX_ENABLE_STATIC_ABI_LIBRARY is an experimental option. 376if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) 377 message(WARNING "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is an experimental option") 378 if (LIBCXX_ENABLE_STATIC AND NOT Python3_EXECUTABLE) 379 message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY requires python but it was not found.") 380 endif() 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_ENABLE_STATIC_ABI_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 402#=============================================================================== 403# Configure System 404#=============================================================================== 405 406# TODO: Projects that depend on libc++ should use LIBCXX_GENERATED_INCLUDE_DIR 407# instead of hard-coding include/c++/v1. 408if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) 409 set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}) 410 set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1") 411 set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1") 412 set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}) 413 set(LIBCXX_INSTALL_INCLUDE_DIR "include/c++/v1") 414 set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1") 415 if(LIBCXX_LIBDIR_SUBDIR) 416 string(APPEND LIBCXX_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR}) 417 string(APPEND LIBCXX_INSTALL_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR}) 418 endif() 419elseif(LLVM_LIBRARY_OUTPUT_INTDIR) 420 set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) 421 set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1") 422 set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}") 423 set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX}) 424 set(LIBCXX_INSTALL_INCLUDE_DIR "include/c++/v1") 425 set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${LIBCXX_INSTALL_INCLUDE_DIR}") 426else() 427 set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) 428 set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1") 429 set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}") 430 set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX}) 431 set(LIBCXX_INSTALL_INCLUDE_DIR "include/c++/v1") 432 set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${LIBCXX_INSTALL_INCLUDE_DIR}") 433endif() 434 435file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}") 436 437set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) 438set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) 439set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) 440 441# Declare libc++ configuration variables. 442# They are intended for use as follows: 443# LIBCXX_CXX_FLAGS: General flags for both the compiler and linker. 444# LIBCXX_COMPILE_FLAGS: Compile only flags. 445# LIBCXX_LINK_FLAGS: Linker only flags. 446# LIBCXX_LIBRARIES: libraries libc++ is linked to. 447set(LIBCXX_COMPILE_FLAGS "") 448set(LIBCXX_LINK_FLAGS "") 449set(LIBCXX_LIBRARIES "") 450 451# Include macros for adding and removing libc++ flags. 452include(HandleLibcxxFlags) 453 454# Target flags ================================================================ 455# These flags get added to CMAKE_CXX_FLAGS and CMAKE_C_FLAGS so that 456# 'config-ix' use them during feature checks. It also adds them to both 457# 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS' 458add_target_flags_if(LIBCXX_BUILD_32_BITS "-m32") 459 460if(LIBCXX_TARGET_TRIPLE) 461 add_target_flags("--target=${LIBCXX_TARGET_TRIPLE}") 462elseif(CMAKE_CXX_COMPILER_TARGET) 463 set(LIBCXX_TARGET_TRIPLE "${CMAKE_CXX_COMPILER_TARGET}") 464endif() 465if(LIBCXX_SYSROOT) 466 add_target_flags("--sysroot=${LIBCXX_SYSROOT}") 467elseif(CMAKE_SYSROOT) 468 set(LIBCXX_SYSROOT "${CMAKE_SYSROOT}") 469endif() 470if(LIBCXX_GCC_TOOLCHAIN) 471 add_target_flags("--gcc-toolchain=${LIBCXX_GCC_TOOLCHAIN}") 472elseif(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN) 473 set(LIBCXX_GCC_TOOLCHAIN "${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}") 474endif() 475 476if(LIBCXX_TARGET_TRIPLE) 477 set(TARGET_TRIPLE "${LIBCXX_TARGET_TRIPLE}") 478endif() 479 480# Configure compiler. 481include(config-ix) 482 483# Configure coverage options. 484if (LIBCXX_GENERATE_COVERAGE) 485 include(CodeCoverage) 486 set(CMAKE_BUILD_TYPE "COVERAGE" CACHE STRING "" FORCE) 487endif() 488 489string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) 490if (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") 491 set(LIBCXX_DEBUG_BUILD ON) 492else() 493 set(LIBCXX_DEBUG_BUILD OFF) 494endif() 495 496#=============================================================================== 497# Setup Compiler Flags 498#=============================================================================== 499 500include(HandleLibCXXABI) # Setup the ABI library flags 501 502if (NOT LIBCXX_STANDALONE_BUILD) 503 # Remove flags that may have snuck in. 504 remove_flags(-DNDEBUG -UNDEBUG -D_DEBUG 505 -lc++abi) 506endif() 507remove_flags(--stdlib=libc++ -stdlib=libc++ --stdlib=libstdc++ -stdlib=libstdc++) 508 509# FIXME: Remove all debug flags and flags that change which Windows 510# default libraries are linked. Currently we only support linking the 511# non-debug DLLs 512remove_flags("/D_DEBUG" "/MTd" "/MDd" "/MT" "/Md") 513 514# FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC. 515# Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors 516# so they don't get transformed into -Wno and -errors respectively. 517remove_flags(-Wno-pedantic -pedantic-errors -pedantic) 518 519# Required flags ============================================================== 520function(cxx_add_basic_build_flags target) 521 522 # Require C++20 for all targets. C++17 is needed to use aligned allocation 523 # in the dylib. C++20 is needed to use char8_t. 524 set_target_properties(${target} PROPERTIES 525 CXX_STANDARD 20 526 CXX_STANDARD_REQUIRED NO 527 CXX_EXTENSIONS NO) 528 529 # When building the dylib, don't warn for unavailable aligned allocation 530 # functions based on the deployment target -- they are always available 531 # because they are provided by the dylib itself with the excepton of z/OS. 532 if (ZOS) 533 target_add_compile_flags_if_supported(${target} PRIVATE -fno-aligned-allocation) 534 else() 535 target_add_compile_flags_if_supported(${target} PRIVATE -faligned-allocation) 536 endif() 537 538 # On all systems the system c++ standard library headers need to be excluded. 539 # MSVC only has -X, which disables all default includes; including the crt. 540 # Thus, we do nothing and hope we don't accidentally include any of the C++ 541 # headers 542 target_add_compile_flags_if_supported(${target} PUBLIC -nostdinc++) 543 544 # Hide all inline function definitions which have not explicitly been marked 545 # visible. This prevents new definitions for inline functions from appearing in 546 # the dylib when get ODR used by another function. 547 target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility-inlines-hidden) 548 549 # Our visibility annotations are not quite right for non-Clang compilers, 550 # so we end up not exporting all the symbols we should. In the future, we 551 # can improve the situation by providing an explicit list of exported 552 # symbols on all compilers. 553 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") 554 target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility=hidden) 555 endif() 556 557 if (LIBCXX_CONFIGURE_IDE) 558 # This simply allows IDE to process <experimental/coroutine> 559 target_add_compile_flags_if_supported(${target} PRIVATE -fcoroutines-ts) 560 endif() 561 562 # Let the library headers know they are currently being used to build the 563 # library. 564 target_compile_definitions(${target} PRIVATE -D_LIBCPP_BUILDING_LIBRARY) 565 566 if (NOT LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS) 567 target_compile_definitions(${target} PRIVATE -D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS) 568 endif() 569 570 if (LIBCXX_HAS_COMMENT_LIB_PRAGMA) 571 if (LIBCXX_HAS_PTHREAD_LIB) 572 target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_PTHREAD_LIB) 573 endif() 574 if (LIBCXX_HAS_RT_LIB) 575 target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_RT_LIB) 576 endif() 577 endif() 578endfunction() 579 580# Warning flags =============================================================== 581function(cxx_add_warning_flags target) 582 target_compile_definitions(${target} PUBLIC -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 583 if (MSVC) 584 # -W4 is the cl.exe/clang-cl equivalent of -Wall. (In cl.exe and clang-cl, 585 # -Wall is equivalent to -Weverything in GCC style compiler drivers.) 586 target_add_compile_flags_if_supported(${target} PRIVATE -W4) 587 else() 588 target_add_compile_flags_if_supported(${target} PRIVATE -Wall) 589 endif() 590 target_add_compile_flags_if_supported(${target} PRIVATE -Wextra -W -Wwrite-strings 591 -Wno-unused-parameter -Wno-long-long 592 -Werror=return-type -Wextra-semi -Wundef) 593 if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") 594 target_add_compile_flags_if_supported(${target} PRIVATE 595 -Wno-user-defined-literals 596 -Wno-covered-switch-default 597 -Wno-suggest-override 598 -Wno-ignored-attributes # FIXME: Caused by _LIBCPP_NODEBUG_TYPE not being supported on older clangs 599 ) 600 if (LIBCXX_TARGETING_CLANG_CL) 601 target_add_compile_flags_if_supported(${target} PRIVATE 602 -Wno-c++98-compat 603 -Wno-c++98-compat-pedantic 604 -Wno-c++11-compat 605 -Wno-undef 606 -Wno-reserved-id-macro 607 -Wno-gnu-include-next 608 -Wno-gcc-compat # For ignoring "'diagnose_if' is a clang extension" warnings 609 -Wno-zero-as-null-pointer-constant # FIXME: Remove this and fix all occurrences. 610 -Wno-deprecated-dynamic-exception-spec # For auto_ptr 611 -Wno-sign-conversion 612 -Wno-old-style-cast 613 -Wno-deprecated # FIXME: Remove this and fix all occurrences. 614 -Wno-shift-sign-overflow # FIXME: Why do we need this with clang-cl but not clang? 615 -Wno-double-promotion # FIXME: remove me 616 ) 617 endif() 618 elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") 619 target_add_compile_flags_if_supported(${target} PRIVATE 620 -Wno-literal-suffix 621 -Wno-c++14-compat 622 -Wno-noexcept-type 623 -Wno-suggest-override) 624 endif() 625 if (LIBCXX_ENABLE_WERROR) 626 target_add_compile_flags_if_supported(${target} PRIVATE -Werror) 627 target_add_compile_flags_if_supported(${target} PRIVATE -WX) 628 else() 629 # TODO(EricWF) Remove this. We shouldn't be suppressing errors when -Werror is 630 # added elsewhere. 631 target_add_compile_flags_if_supported(${target} PRIVATE -Wno-error) 632 endif() 633 if (LIBCXX_ENABLE_PEDANTIC) 634 target_add_compile_flags_if_supported(${target} PRIVATE -pedantic) 635 endif() 636 if (LIBCXX_DISABLE_MACRO_CONFLICT_WARNINGS) 637 target_compile_definitions(${target} PRIVATE -D_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS) 638 endif() 639endfunction() 640 641# Exception flags ============================================================= 642function(cxx_add_exception_flags target) 643 if (LIBCXX_ENABLE_EXCEPTIONS) 644 # Catches C++ exceptions only and tells the compiler to assume that extern C 645 # functions never throw a C++ exception. 646 target_add_compile_flags_if_supported(${target} PUBLIC -EHsc) 647 else() 648 target_add_compile_flags_if_supported(${target} PUBLIC -EHs- -EHa-) 649 target_add_compile_flags_if_supported(${target} PUBLIC -fno-exceptions) 650 endif() 651endfunction() 652 653# RTTI flags ================================================================== 654function(cxx_add_rtti_flags target) 655 if (NOT LIBCXX_ENABLE_RTTI) 656 target_add_compile_flags_if_supported(${target} PUBLIC -GR-) 657 target_add_compile_flags_if_supported(${target} PUBLIC -fno-rtti) 658 endif() 659endfunction() 660 661# Threading flags ============================================================= 662if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY AND LIBCXX_ENABLE_SHARED) 663 # Need to allow unresolved symbols if this is to work with shared library builds 664 if (APPLE) 665 add_link_flags("-undefined dynamic_lookup") 666 else() 667 # Relax this restriction from HandleLLVMOptions 668 string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") 669 endif() 670endif() 671 672# Assertion flags ============================================================= 673define_if(LIBCXX_ENABLE_ASSERTIONS -UNDEBUG) 674define_if_not(LIBCXX_ENABLE_ASSERTIONS -DNDEBUG) 675define_if(LIBCXX_ENABLE_ASSERTIONS -D_LIBCPP_DEBUG=0) 676define_if(LIBCXX_DEBUG_BUILD -D_DEBUG) 677if (LIBCXX_ENABLE_ASSERTIONS AND NOT LIBCXX_DEBUG_BUILD) 678 # MSVC doesn't like _DEBUG on release builds. See PR 4379. 679 define_if_not(LIBCXX_TARGETING_MSVC -D_DEBUG) 680endif() 681 682# Modules flags =============================================================== 683# FIXME The libc++ sources are fundamentally non-modular. They need special 684# versions of the headers in order to provide C++03 and legacy ABI definitions. 685# NOTE: The public headers can be used with modules in all other contexts. 686function(cxx_add_module_flags target) 687 if (LLVM_ENABLE_MODULES) 688 # Ignore that the rest of the modules flags are now unused. 689 target_add_compile_flags_if_supported(${target} PUBLIC -Wno-unused-command-line-argument) 690 target_compile_options(${target} PUBLIC -fno-modules) 691 endif() 692endfunction() 693 694# Sanitizer flags ============================================================= 695 696function(get_sanitizer_flags OUT_VAR USE_SANITIZER) 697 set(SANITIZER_FLAGS) 698 set(USE_SANITIZER "${USE_SANITIZER}") 699 # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC. 700 # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do. 701 if (USE_SANITIZER AND NOT MSVC) 702 append_flags_if_supported(SANITIZER_FLAGS "-fno-omit-frame-pointer") 703 append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only") 704 705 if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND 706 NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO") 707 append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only") 708 endif() 709 if (USE_SANITIZER STREQUAL "Address") 710 append_flags(SANITIZER_FLAGS "-fsanitize=address") 711 elseif (USE_SANITIZER MATCHES "Memory(WithOrigins)?") 712 append_flags(SANITIZER_FLAGS -fsanitize=memory) 713 if (USE_SANITIZER STREQUAL "MemoryWithOrigins") 714 append_flags(SANITIZER_FLAGS "-fsanitize-memory-track-origins") 715 endif() 716 elseif (USE_SANITIZER STREQUAL "Undefined") 717 append_flags(SANITIZER_FLAGS "-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all") 718 elseif (USE_SANITIZER STREQUAL "Address;Undefined" OR 719 USE_SANITIZER STREQUAL "Undefined;Address") 720 append_flags(SANITIZER_FLAGS "-fsanitize=address,undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all") 721 elseif (USE_SANITIZER STREQUAL "Thread") 722 append_flags(SANITIZER_FLAGS -fsanitize=thread) 723 elseif (USE_SANITIZER STREQUAL "DataFlow") 724 append_flags(SANITIZER_FLAGS -fsanitize=dataflow) 725 else() 726 message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${USE_SANITIZER}") 727 endif() 728 elseif(USE_SANITIZER AND MSVC) 729 message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.") 730 endif() 731 set(${OUT_VAR} "${SANITIZER_FLAGS}" PARENT_SCOPE) 732endfunction() 733 734# Configure for sanitizers. If LIBCXX_STANDALONE_BUILD then we have to do 735# the flag translation ourselves. Othewise LLVM's CMakeList.txt will handle it. 736if (LIBCXX_STANDALONE_BUILD) 737 set(LLVM_USE_SANITIZER "" CACHE STRING 738 "Define the sanitizer used to build the library and tests") 739endif() 740get_sanitizer_flags(SANITIZER_FLAGS "${LLVM_USE_SANITIZER}") 741if (LIBCXX_STANDALONE_BUILD AND SANITIZER_FLAGS) 742 add_flags(${SANITIZER_FLAGS}) 743endif() 744 745# Link system libraries ======================================================= 746function(cxx_link_system_libraries target) 747 748# In order to remove just libc++ from the link step 749# we need to use -nostdlib++ whenever it is supported. 750# Unfortunately this cannot be used universally because for example g++ supports 751# only -nodefaultlibs in which case all libraries will be removed and 752# all libraries but c++ have to be added in manually. 753 if (LIBCXX_SUPPORTS_NOSTDLIBXX_FLAG) 754 target_add_link_flags_if_supported(${target} PRIVATE "-nostdlib++") 755 else() 756 target_add_link_flags_if_supported(${target} PRIVATE "-nodefaultlibs") 757 target_add_compile_flags_if_supported(${target} PRIVATE "/Zl") 758 target_add_link_flags_if_supported(${target} PRIVATE "/nodefaultlib") 759 endif() 760 761 if (LIBCXX_HAS_SYSTEM_LIB) 762 target_link_libraries(${target} PRIVATE System) 763 endif() 764 765 if (LIBCXX_HAS_PTHREAD_LIB) 766 target_link_libraries(${target} PRIVATE pthread) 767 endif() 768 769 if (LIBCXX_HAS_C_LIB) 770 target_link_libraries(${target} PRIVATE c) 771 endif() 772 773 if (LIBCXX_HAS_M_LIB) 774 target_link_libraries(${target} PRIVATE m) 775 endif() 776 777 if (LIBCXX_HAS_RT_LIB) 778 target_link_libraries(${target} PRIVATE rt) 779 endif() 780 781 if (LIBCXX_USE_COMPILER_RT) 782 find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY) 783 if (LIBCXX_BUILTINS_LIBRARY) 784 target_link_libraries(${target} PRIVATE "${LIBCXX_BUILTINS_LIBRARY}") 785 endif() 786 elseif (LIBCXX_HAS_GCC_LIB) 787 target_link_libraries(${target} PRIVATE gcc) 788 elseif (LIBCXX_HAS_GCC_S_LIB) 789 target_link_libraries(${target} PRIVATE gcc_s) 790 endif() 791 792 if (LIBCXX_HAS_ATOMIC_LIB) 793 target_link_libraries(${target} PRIVATE atomic) 794 endif() 795 796 if (MINGW) 797 target_link_libraries(${target} PRIVATE "${MINGW_LIBRARIES}") 798 endif() 799 800 if (LIBCXX_TARGETING_MSVC) 801 if (LIBCXX_DEBUG_BUILD) 802 set(LIB_SUFFIX "d") 803 else() 804 set(LIB_SUFFIX "") 805 endif() 806 807 target_link_libraries(${target} PRIVATE ucrt${LIB_SUFFIX}) # Universal C runtime 808 target_link_libraries(${target} PRIVATE vcruntime${LIB_SUFFIX}) # C++ runtime 809 target_link_libraries(${target} PRIVATE msvcrt${LIB_SUFFIX}) # C runtime startup files 810 target_link_libraries(${target} PRIVATE msvcprt${LIB_SUFFIX}) # C++ standard library. Required for exception_ptr internals. 811 # Required for standards-complaint wide character formatting functions 812 # (e.g. `printfw`/`scanfw`) 813 target_link_libraries(${target} PRIVATE iso_stdio_wide_specifiers) 814 endif() 815 816 if (ANDROID AND ANDROID_PLATFORM_LEVEL LESS 21) 817 target_link_libraries(${target} PUBLIC android_support) 818 endif() 819endfunction() 820 821# Windows-related flags ======================================================= 822function(cxx_add_windows_flags target) 823 if(WIN32 AND NOT MINGW) 824 target_compile_definitions(${target} PRIVATE 825 # Ignore the -MSC_VER mismatch, as we may build 826 # with a different compatibility version. 827 _ALLOW_MSC_VER_MISMATCH 828 # Don't check the msvcprt iterator debug levels 829 # as we will define the iterator types; libc++ 830 # uses a different macro to identify the debug 831 # level. 832 _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH 833 # We are building the c++ runtime, don't pull in 834 # msvcprt. 835 _CRTBLD 836 # Don't warn on the use of "deprecated" 837 # "insecure" functions which are standards 838 # specified. 839 _CRT_SECURE_NO_WARNINGS 840 # Use the ISO conforming behaviour for conversion 841 # in printf, scanf. 842 _CRT_STDIO_ISO_WIDE_SPECIFIERS) 843 endif() 844endfunction() 845 846# Configuration file flags ===================================================== 847if (NOT LIBCXX_ABI_VERSION EQUAL 1) 848 config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION) 849endif() 850if (NOT LIBCXX_ABI_NAMESPACE STREQUAL "") 851 if (NOT LIBCXX_ABI_NAMESPACE MATCHES "__.*") 852 message(FATAL_ERROR "LIBCXX_ABI_NAMESPACE must be a reserved identifier.") 853 endif() 854 if (LIBCXX_ABI_NAMESPACE MATCHES "__[0-9]+$") 855 message(FATAL_ERROR "LIBCXX_ABI_NAMESPACE '${LIBCXX_ABI_NAMESPACE}' is reserved for use by libc++.") 856 endif() 857 config_define(${LIBCXX_ABI_NAMESPACE} _LIBCPP_ABI_NAMESPACE) 858endif() 859config_define_if(LIBCXX_ABI_UNSTABLE _LIBCPP_ABI_UNSTABLE) 860config_define_if(LIBCXX_ABI_FORCE_ITANIUM _LIBCPP_ABI_FORCE_ITANIUM) 861config_define_if(LIBCXX_ABI_FORCE_MICROSOFT _LIBCPP_ABI_FORCE_MICROSOFT) 862config_define_if(LIBCXX_HIDE_FROM_ABI_PER_TU_BY_DEFAULT _LIBCPP_HIDE_FROM_ABI_PER_TU_BY_DEFAULT) 863config_define_if_not(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE) 864config_define_if_not(LIBCXX_ENABLE_STDIN _LIBCPP_HAS_NO_STDIN) 865config_define_if_not(LIBCXX_ENABLE_STDOUT _LIBCPP_HAS_NO_STDOUT) 866config_define_if_not(LIBCXX_ENABLE_THREADS _LIBCPP_HAS_NO_THREADS) 867config_define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK _LIBCPP_HAS_NO_MONOTONIC_CLOCK) 868config_define_if_not(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS) 869if (NOT LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION STREQUAL "default") 870 config_define("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION) 871endif() 872config_define_if(LIBCXX_HAS_PTHREAD_API _LIBCPP_HAS_THREAD_API_PTHREAD) 873config_define_if(LIBCXX_HAS_EXTERNAL_THREAD_API _LIBCPP_HAS_THREAD_API_EXTERNAL) 874config_define_if(LIBCXX_HAS_WIN32_THREAD_API _LIBCPP_HAS_THREAD_API_WIN32) 875config_define_if(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) 876config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC) 877config_define_if(LIBCXX_NO_VCRUNTIME _LIBCPP_NO_VCRUNTIME) 878config_define_if(LIBCXX_ENABLE_PARALLEL_ALGORITHMS _LIBCPP_HAS_PARALLEL_ALGORITHMS) 879config_define_if_not(LIBCXX_ENABLE_FILESYSTEM _LIBCPP_HAS_NO_FILESYSTEM_LIBRARY) 880config_define_if_not(LIBCXX_ENABLE_RANDOM_DEVICE _LIBCPP_HAS_NO_RANDOM_DEVICE) 881config_define_if_not(LIBCXX_ENABLE_LOCALIZATION _LIBCPP_HAS_NO_LOCALIZATION) 882config_define_if_not(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS) 883 884if (LIBCXX_ABI_DEFINES) 885 set(abi_defines) 886 foreach (abi_define ${LIBCXX_ABI_DEFINES}) 887 if (NOT abi_define MATCHES "^_LIBCPP_ABI_") 888 message(SEND_ERROR "Invalid ABI macro ${abi_define} in LIBCXX_ABI_DEFINES") 889 endif() 890 list(APPEND abi_defines "#define ${abi_define}") 891 endforeach() 892 string(REPLACE ";" "\n" abi_defines "${abi_defines}") 893 config_define(${abi_defines} _LIBCPP_ABI_DEFINES) 894endif() 895 896# By default libc++ on Windows expects to use a shared library, which requires 897# the headers to use DLL import/export semantics. However when building a 898# static library only we modify the headers to disable DLL import/export. 899if (DEFINED WIN32 AND LIBCXX_ENABLE_STATIC AND NOT LIBCXX_ENABLE_SHARED) 900 message(STATUS "Generating custom __config for non-DLL Windows build") 901 config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 902endif() 903 904if (WIN32 AND LIBCXX_ENABLE_STATIC_ABI_LIBRARY) 905 # If linking libcxxabi statically into libcxx, skip the dllimport attributes 906 # on symbols we refer to from libcxxabi. 907 add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS) 908endif() 909 910# Setup all common build flags ================================================= 911function(cxx_add_common_build_flags target) 912 cxx_add_basic_build_flags(${target}) 913 cxx_add_warning_flags(${target}) 914 cxx_add_windows_flags(${target}) 915 cxx_add_exception_flags(${target}) 916 cxx_add_rtti_flags(${target}) 917 cxx_add_module_flags(${target}) 918 cxx_link_system_libraries(${target}) 919endfunction() 920 921#=============================================================================== 922# Setup Source Code And Tests 923#=============================================================================== 924add_subdirectory(include) 925add_subdirectory(src) 926 927set(LIBCXX_TEST_DEPS "") 928 929if (LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY) 930 list(APPEND LIBCXX_TEST_DEPS cxx_experimental) 931endif() 932 933if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY) 934 list(APPEND LIBCXX_TEST_DEPS cxx_external_threads) 935endif() 936 937if (LIBCXX_INCLUDE_BENCHMARKS) 938 add_subdirectory(benchmarks) 939endif() 940 941if (LIBCXX_INCLUDE_TESTS) 942 add_subdirectory(test) 943 add_subdirectory(lib/abi) 944 if (LIBCXX_STANDALONE_BUILD) 945 include(AddLLVM) # for get_llvm_lit_path 946 # Make sure the llvm-lit script is generated into the bin directory, and 947 # do it after adding all tests, since the generated script will only work 948 # correctly discovered tests against test locations from the source tree 949 # that have already been discovered. 950 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit 951 ${CMAKE_CURRENT_BINARY_DIR}/llvm-lit) 952 endif() 953endif() 954 955if (LIBCXX_INCLUDE_DOCS) 956 add_subdirectory(docs) 957endif() 958