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