Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 1 | #=============================================================================== |
| 2 | # Setup Project |
| 3 | #=============================================================================== |
Mark de Wever | cbaa359 | 2023-05-24 16:12:32 | [diff] [blame] | 4 | cmake_minimum_required(VERSION 3.20.0) |
Michael Kruse | e14f5f2 | 2024-05-25 15:41:21 | [diff] [blame] | 5 | set(LLVM_SUBPROJECT_TITLE "libc++") |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 6 | |
John Ericson | 949bbd0 | 2022-01-01 07:03:31 | [diff] [blame] | 7 | set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake") |
| 8 | |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 9 | # Add path for custom modules |
John Ericson | 949bbd0 | 2022-01-01 07:03:31 | [diff] [blame] | 10 | list(INSERT CMAKE_MODULE_PATH 0 |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 11 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake" |
| 12 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" |
Nikolas Klauser | 0af67d1 | 2023-02-20 15:26:19 | [diff] [blame] | 13 | "${CMAKE_CURRENT_SOURCE_DIR}/../runtimes/cmake/Modules" |
John Ericson | 949bbd0 | 2022-01-01 07:03:31 | [diff] [blame] | 14 | "${LLVM_COMMON_CMAKE_UTILS}" |
| 15 | "${LLVM_COMMON_CMAKE_UTILS}/Modules" |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 16 | ) |
| 17 | |
Marek Kurdej | 5e7a93a | 2021-01-25 08:50:03 | [diff] [blame] | 18 | set(CMAKE_FOLDER "libc++") |
| 19 | |
Dominik Montada | 8c03fdf | 2020-08-24 09:01:05 | [diff] [blame] | 20 | set(LIBCXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 21 | set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
Dominik Montada | 8c03fdf | 2020-08-24 09:01:05 | [diff] [blame] | 22 | |
John Ericson | df31ff1 | 2022-01-19 06:45:07 | [diff] [blame] | 23 | include(GNUInstallDirs) |
Nikolas Klauser | a7aade1 | 2023-02-17 10:31:41 | [diff] [blame] | 24 | include(WarningFlags) |
John Ericson | df31ff1 | 2022-01-19 06:45:07 | [diff] [blame] | 25 | |
Saleem Abdulrasool | 163333f | 2016-02-08 03:50:18 | [diff] [blame] | 26 | # Require out of source build. |
| 27 | include(MacroEnsureOutOfSourceBuild) |
| 28 | MACRO_ENSURE_OUT_OF_SOURCE_BUILD( |
| 29 | "${PROJECT_NAME} requires an out of source build. Please create a separate |
| 30 | build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there." |
| 31 | ) |
Eric Fiselier | 5e0b8fc | 2018-10-01 01:31:23 | [diff] [blame] | 32 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC") |
| 33 | message(STATUS "Configuring for clang-cl") |
| 34 | set(LIBCXX_TARGETING_CLANG_CL ON) |
| 35 | endif() |
Saleem Abdulrasool | 163333f | 2016-02-08 03:50:18 | [diff] [blame] | 36 | |
Eric Fiselier | cc1f65c | 2017-01-14 06:06:47 | [diff] [blame] | 37 | if (MSVC) |
Eric Fiselier | 11edd93 | 2018-10-01 01:00:11 | [diff] [blame] | 38 | message(STATUS "Configuring for MSVC") |
Eric Fiselier | cc1f65c | 2017-01-14 06:06:47 | [diff] [blame] | 39 | endif() |
| 40 | |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 41 | #=============================================================================== |
| 42 | # Setup CMake Options |
| 43 | #=============================================================================== |
Eric Fiselier | 309a50a | 2016-09-07 01:15:10 | [diff] [blame] | 44 | include(CMakeDependentOption) |
Eric Fiselier | 2aeac46 | 2017-03-11 03:24:18 | [diff] [blame] | 45 | include(HandleCompilerRT) |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 46 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 47 | # Basic options --------------------------------------------------------------- |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 48 | option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON) |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 49 | option(LIBCXX_ENABLE_STATIC "Build libc++ as a static library." ON) |
Louis Dionne | e589496 | 2024-11-14 12:06:43 | [diff] [blame] | 50 | option(LIBCXX_ENABLE_EXCEPTIONS "Enable exceptions in the built library." ON) |
| 51 | option(LIBCXX_ENABLE_RTTI |
| 52 | "Use runtime type information. |
| 53 | This option may only be set to OFF when LIBCXX_ENABLE_EXCEPTIONS=OFF." ON) |
Louis Dionne | 66a562d | 2023-05-31 18:20:24 | [diff] [blame] | 54 | option(LIBCXX_ENABLE_FILESYSTEM |
| 55 | "Whether to include support for parts of the library that rely on a filesystem being |
| 56 | available on the platform. This includes things like most parts of <filesystem> and |
| 57 | others like <fstream>" ON) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 58 | option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS}) |
Konstantin Varlamov | 64d413e | 2023-11-08 19:10:00 | [diff] [blame] | 59 | set(LIBCXX_SUPPORTED_HARDENING_MODES none fast extensive debug) |
| 60 | set(LIBCXX_HARDENING_MODE "none" CACHE STRING |
varconst | d1367ca | 2023-07-12 17:12:51 | [diff] [blame] | 61 | "Specify the default hardening mode to use. This mode will be used inside the |
| 62 | compiled library and will be the default when compiling user code. Note that |
| 63 | users can override this setting in their own code. This does not affect the |
| 64 | ABI. Supported values are ${LIBCXX_SUPPORTED_HARDENING_MODES}.") |
| 65 | if (NOT "${LIBCXX_HARDENING_MODE}" IN_LIST LIBCXX_SUPPORTED_HARDENING_MODES) |
| 66 | message(FATAL_ERROR |
| 67 | "Unsupported hardening mode: '${LIBCXX_HARDENING_MODE}'. Supported values are ${LIBCXX_SUPPORTED_HARDENING_MODES}.") |
| 68 | endif() |
Konstantin Varlamov | 8dfc67d | 2024-01-18 02:56:07 | [diff] [blame] | 69 | set(LIBCXX_ASSERTION_HANDLER_FILE |
Louis Dionne | 046a177 | 2024-07-24 16:03:52 | [diff] [blame] | 70 | "vendor/llvm/default_assertion_handler.in" |
Konstantin Varlamov | 8dfc67d | 2024-01-18 02:56:07 | [diff] [blame] | 71 | CACHE STRING |
| 72 | "Specify the path to a header that contains a custom implementation of the |
| 73 | assertion handler that gets invoked when a hardening assertion fails. If |
| 74 | provided, this header will be included by the library, replacing the |
Louis Dionne | 046a177 | 2024-07-24 16:03:52 | [diff] [blame] | 75 | default assertion handler. If this is specified as a relative path, it |
| 76 | is assumed to be relative to '<monorepo>/libcxx'.") |
| 77 | if (NOT IS_ABSOLUTE "${LIBCXX_ASSERTION_HANDLER_FILE}") |
| 78 | set(LIBCXX_ASSERTION_HANDLER_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${LIBCXX_ASSERTION_HANDLER_FILE}") |
| 79 | endif() |
Louis Dionne | e0d0129 | 2020-10-15 14:32:09 | [diff] [blame] | 80 | option(LIBCXX_ENABLE_RANDOM_DEVICE |
| 81 | "Whether to include support for std::random_device in the library. Disabling |
| 82 | this can be useful when building the library for platforms that don't have |
| 83 | a source of randomness, such as some embedded platforms. When this is not |
| 84 | supported, most of <random> will still be available, but std::random_device |
| 85 | will not." ON) |
Louis Dionne | 88ffc72 | 2020-10-09 19:31:05 | [diff] [blame] | 86 | option(LIBCXX_ENABLE_LOCALIZATION |
| 87 | "Whether to include support for localization in the library. Disabling |
| 88 | localization can be useful when porting to platforms that don't support |
| 89 | the C locale API (e.g. embedded). When localization is not supported, |
| 90 | several parts of the library will be disabled: <iostream>, <regex>, <locale> |
| 91 | will be completely unusable, and other parts may be only partly available." ON) |
Mark de Wever | df2af99 | 2021-05-25 18:11:08 | [diff] [blame] | 92 | option(LIBCXX_ENABLE_UNICODE |
| 93 | "Whether to include support for Unicode in the library. Disabling Unicode can |
Louis Dionne | cf765b1 | 2021-09-09 15:14:33 | [diff] [blame] | 94 | be useful when porting to platforms that don't support UTF-8 encoding (e.g. |
| 95 | embedded)." ON) |
Joseph Huber | 7ad7f8f | 2024-08-21 13:48:53 | [diff] [blame] | 96 | option(LIBCXX_HAS_TERMINAL_AVAILABLE |
| 97 | "Build libc++ with support for checking whether a stream is a terminal." ON) |
Louis Dionne | f4c1258 | 2021-08-23 19:32:36 | [diff] [blame] | 98 | option(LIBCXX_ENABLE_WIDE_CHARACTERS |
| 99 | "Whether to include support for wide characters in the library. Disabling |
| 100 | wide character support can be useful when porting to platforms that don't |
| 101 | support the C functionality for wide characters. When wide characters are |
| 102 | not supported, several parts of the library will be disabled, notably the |
| 103 | wide character specializations of std::basic_string." ON) |
Louis Dionne | e589496 | 2024-11-14 12:06:43 | [diff] [blame] | 104 | option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON) |
| 105 | option(LIBCXX_ENABLE_MONOTONIC_CLOCK |
| 106 | "Build libc++ with support for a monotonic clock. |
| 107 | This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON) |
Mark de Wever | f78f93b | 2022-09-23 16:33:20 | [diff] [blame] | 108 | |
| 109 | # To use time zone support in libc++ the platform needs to have the IANA |
| 110 | # database installed. Libc++ will fail to build if this is enabled on a |
| 111 | # platform that does not provide the IANA database. The default is set to the |
| 112 | # current implementation state on the different platforms. |
| 113 | # |
| 114 | # TODO TZDB make the default always ON when most platforms ship with the IANA |
| 115 | # database. |
| 116 | if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") |
| 117 | set(ENABLE_TIME_ZONE_DATABASE_DEFAULT ON) |
| 118 | else() |
| 119 | set(ENABLE_TIME_ZONE_DATABASE_DEFAULT OFF) |
| 120 | endif() |
| 121 | option(LIBCXX_ENABLE_TIME_ZONE_DATABASE |
| 122 | "Whether to include support for time zones in the library. Disabling |
| 123 | time zone support can be useful when porting to platforms that don't |
| 124 | ship the IANA time zone database. When time zones are not supported, |
| 125 | time zone support in <chrono> will be disabled." ${ENABLE_TIME_ZONE_DATABASE_DEFAULT}) |
Louis Dionne | 2eadbc8 | 2020-11-04 20:01:25 | [diff] [blame] | 126 | option(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS |
| 127 | "Whether to turn on vendor availability annotations on declarations that depend |
| 128 | on definitions in a shared library. By default, we assume that we're not building |
| 129 | libc++ for any specific vendor, and we disable those annotations. Vendors wishing |
| 130 | to provide compile-time errors when using features unavailable on some version of |
Louis Dionne | 04f01a2 | 2024-05-29 01:29:11 | [diff] [blame] | 131 | the shared library they shipped should turn this on and see `include/__configuration/availability.h` |
Louis Dionne | 2eadbc8 | 2020-11-04 20:01:25 | [diff] [blame] | 132 | for more details." OFF) |
Louis Dionne | d0af427 | 2022-03-14 18:23:38 | [diff] [blame] | 133 | |
| 134 | if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 135 | set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-gcc.cfg.in") |
| 136 | elseif(MINGW) |
Martin Storsjö | 9fb2378 | 2024-10-10 06:13:47 | [diff] [blame] | 137 | set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-mingw.cfg.in") |
Louis Dionne | d0af427 | 2022-03-14 18:23:38 | [diff] [blame] | 138 | elseif(WIN32) # clang-cl |
| 139 | if (LIBCXX_ENABLE_SHARED) |
| 140 | set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-clangcl.cfg.in") |
| 141 | else() |
| 142 | set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-static-clangcl.cfg.in") |
| 143 | endif() |
| 144 | else() |
| 145 | if (LIBCXX_ENABLE_SHARED) |
| 146 | set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared.cfg.in") |
| 147 | else() |
| 148 | set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-static.cfg.in") |
| 149 | endif() |
| 150 | endif() |
| 151 | set(LIBCXX_TEST_CONFIG "${LIBCXX_DEFAULT_TEST_CONFIG}" CACHE STRING |
Louis Dionne | 54a8a0d | 2021-09-29 19:26:05 | [diff] [blame] | 152 | "The path to the Lit testing configuration to use when running the tests. |
| 153 | If a relative path is provided, it is assumed to be relative to '<monorepo>/libcxx/test/configs'.") |
| 154 | if (NOT IS_ABSOLUTE "${LIBCXX_TEST_CONFIG}") |
| 155 | set(LIBCXX_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/configs/${LIBCXX_TEST_CONFIG}") |
| 156 | endif() |
Louis Dionne | d0af427 | 2022-03-14 18:23:38 | [diff] [blame] | 157 | message(STATUS "Using libc++ testing configuration: ${LIBCXX_TEST_CONFIG}") |
Louis Dionne | 6f69318 | 2020-07-09 15:54:09 | [diff] [blame] | 158 | set(LIBCXX_TEST_PARAMS "" CACHE STRING |
| 159 | "A list of parameters to run the Lit test suite with.") |
Eric Fiselier | 3aa5478 | 2016-10-30 22:53:00 | [diff] [blame] | 160 | |
Louis Dionne | e236a52 | 2024-11-07 14:07:50 | [diff] [blame] | 161 | # TODO: Figure out how to build GoogleBenchmark on those platforms, and how to build when exceptions or RTTI is disabled |
| 162 | if (WIN32 OR MINGW OR ANDROID OR ${CMAKE_SYSTEM_NAME} MATCHES "AIX" |
| 163 | OR NOT LIBCXX_ENABLE_LOCALIZATION |
| 164 | OR NOT LIBCXX_ENABLE_THREADS |
| 165 | OR NOT LIBCXX_ENABLE_FILESYSTEM |
| 166 | OR NOT LIBCXX_ENABLE_RANDOM_DEVICE |
| 167 | OR NOT LIBCXX_ENABLE_EXCEPTIONS |
| 168 | OR NOT LIBCXX_ENABLE_RTTI) |
| 169 | set(_include_benchmarks OFF) |
| 170 | else() |
| 171 | set(_include_benchmarks ON) |
| 172 | endif() |
| 173 | option(LIBCXX_INCLUDE_BENCHMARKS "Build the libc++ benchmarks and their dependencies" ${_include_benchmarks}) |
Eric Fiselier | 336a1a6 | 2018-11-14 20:38:46 | [diff] [blame] | 174 | |
Eric Fiselier | b17bb06 | 2015-08-22 19:40:49 | [diff] [blame] | 175 | option(LIBCXX_INCLUDE_DOCS "Build the libc++ documentation." ${LLVM_INCLUDE_DOCS}) |
John Ericson | e941b03 | 2022-08-19 02:44:46 | [diff] [blame] | 176 | set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING |
| 177 | "Define suffix of library directory name (32/64)") |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 178 | option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON) |
Eric Fiselier | d77135f | 2015-08-26 20:18:21 | [diff] [blame] | 179 | option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON) |
Mark de Wever | 8b47bb6 | 2024-01-21 11:16:22 | [diff] [blame] | 180 | option(LIBCXX_INSTALL_MODULES |
Mark de Wever | 19d2d3f | 2024-04-28 12:12:27 | [diff] [blame] | 181 | "Install the libc++ C++20 module source files (experimental)." ON |
Mark de Wever | 8b47bb6 | 2024-01-21 11:16:22 | [diff] [blame] | 182 | ) |
Petr Hosek | 4a1e14e | 2018-07-24 23:27:51 | [diff] [blame] | 183 | cmake_dependent_option(LIBCXX_INSTALL_STATIC_LIBRARY |
| 184 | "Install the static libc++ library." ON |
| 185 | "LIBCXX_ENABLE_STATIC;LIBCXX_INSTALL_LIBRARY" OFF) |
| 186 | cmake_dependent_option(LIBCXX_INSTALL_SHARED_LIBRARY |
| 187 | "Install the shared libc++ library." ON |
| 188 | "LIBCXX_ENABLE_SHARED;LIBCXX_INSTALL_LIBRARY" OFF) |
Eric Fiselier | 998a5c8 | 2018-07-27 03:07:09 | [diff] [blame] | 189 | |
Louis Dionne | 817d897 | 2022-02-07 19:52:17 | [diff] [blame] | 190 | option(LIBCXX_ABI_UNSTABLE "Use the unstable ABI of libc++. This is equivalent to specifying LIBCXX_ABI_VERSION=n, where n is the not-yet-stable version." OFF) |
| 191 | if (LIBCXX_ABI_UNSTABLE) |
| 192 | set(abi_version "2") |
| 193 | else() |
| 194 | set(abi_version "1") |
| 195 | endif() |
Louis Dionne | 6de59ca | 2022-05-16 13:50:56 | [diff] [blame] | 196 | set(LIBCXX_ABI_VERSION "${abi_version}" CACHE STRING |
| 197 | "ABI version of libc++. Can be either 1 or 2, where 2 is currently the unstable ABI. |
| 198 | Defaults to 1 unless LIBCXX_ABI_UNSTABLE is specified, in which case this is 2.") |
| 199 | set(LIBCXX_LIBRARY_VERSION "${LIBCXX_ABI_VERSION}.0" CACHE STRING |
| 200 | "Version of libc++. This will be reflected in the name of the shared library produced. |
| 201 | For example, -DLIBCXX_LIBRARY_VERSION=x.y will result in the library being named |
| 202 | libc++.x.y.dylib, along with the usual symlinks pointing to that. On Apple platforms, |
| 203 | this also controls the linker's 'current_version' property.") |
Louis Dionne | 817d897 | 2022-02-07 19:52:17 | [diff] [blame] | 204 | set(LIBCXX_ABI_NAMESPACE "__${LIBCXX_ABI_VERSION}" CACHE STRING "The inline ABI namespace used by libc++. It defaults to __n where `n` is the current ABI version.") |
| 205 | if (NOT LIBCXX_ABI_NAMESPACE MATCHES "__.*") |
Florian Mayer | 4110c2c | 2022-06-09 15:49:03 | [diff] [blame] | 206 | message(FATAL_ERROR "LIBCXX_ABI_NAMESPACE must be a reserved identifier, got '${LIBCXX_ABI_NAMESPACE}'.") |
Louis Dionne | 817d897 | 2022-02-07 19:52:17 | [diff] [blame] | 207 | endif() |
Shoaib Meenai | a4a3d40 | 2017-10-05 02:18:08 | [diff] [blame] | 208 | option(LIBCXX_ABI_FORCE_ITANIUM "Ignore auto-detection and force use of the Itanium ABI.") |
| 209 | option(LIBCXX_ABI_FORCE_MICROSOFT "Ignore auto-detection and force use of the Microsoft ABI.") |
Eric Fiselier | 2405bd6 | 2019-05-29 02:21:37 | [diff] [blame] | 210 | |
Louis Dionne | be00e88 | 2020-11-16 23:13:43 | [diff] [blame] | 211 | set(LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION "default" CACHE STRING |
| 212 | "Override the implementation to use for comparing typeinfos. By default, this |
| 213 | is detected automatically by the library, but this option allows overriding |
| 214 | which implementation is used unconditionally. |
Eric Fiselier | 2405bd6 | 2019-05-29 02:21:37 | [diff] [blame] | 215 | |
Louis Dionne | be00e88 | 2020-11-16 23:13:43 | [diff] [blame] | 216 | See the documentation in <libcxx/include/typeinfo> for details on what each |
| 217 | value means.") |
| 218 | set(TYPEINFO_COMPARISON_VALUES "default;1;2;3") |
| 219 | if (NOT ("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" IN_LIST TYPEINFO_COMPARISON_VALUES)) |
Louis Dionne | d0fcdcd | 2020-05-15 19:58:19 | [diff] [blame] | 220 | message(FATAL_ERROR "Value '${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}' is not a valid value for |
Louis Dionne | be00e88 | 2020-11-16 23:13:43 | [diff] [blame] | 221 | LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION") |
Eric Fiselier | 2405bd6 | 2019-05-29 02:21:37 | [diff] [blame] | 222 | endif() |
| 223 | |
Shoaib Meenai | 8993753 | 2017-10-04 23:51:57 | [diff] [blame] | 224 | set(LIBCXX_ABI_DEFINES "" CACHE STRING "A semicolon separated list of ABI macros to define in the site config header.") |
Louis Dionne | 760261a | 2023-08-14 22:14:02 | [diff] [blame] | 225 | set(LIBCXX_EXTRA_SITE_DEFINES "" CACHE STRING "Extra defines to add into __config_site") |
Saleem Abdulrasool | e81fcb8 | 2016-08-24 04:22:52 | [diff] [blame] | 226 | option(LIBCXX_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 227 | |
Petr Hosek | 3b78dfa | 2024-07-19 05:17:42 | [diff] [blame] | 228 | # C Library options ----------------------------------------------------------- |
| 229 | |
| 230 | set(LIBCXX_SUPPORTED_C_LIBRARIES system llvm-libc) |
| 231 | set(LIBCXX_LIBC "system" CACHE STRING "Specify C library to use. Supported values are ${LIBCXX_SUPPORTED_C_LIBRARIES}.") |
| 232 | if (NOT "${LIBCXX_LIBC}" IN_LIST LIBCXX_SUPPORTED_C_LIBRARIES) |
Raul Tambre | 58d4ebb | 2025-05-06 20:07:49 | [diff] [blame] | 233 | message(FATAL_ERROR "Unsupported C library: '${LIBCXX_LIBC}'. Supported values are ${LIBCXX_SUPPORTED_C_LIBRARIES}.") |
Petr Hosek | 3b78dfa | 2024-07-19 05:17:42 | [diff] [blame] | 234 | endif() |
| 235 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 236 | # ABI Library options --------------------------------------------------------- |
David Spickett | 43cfc78 | 2023-07-07 09:55:36 | [diff] [blame] | 237 | if (MSVC) |
Louis Dionne | a80e65e | 2022-03-01 13:42:13 | [diff] [blame] | 238 | set(LIBCXX_DEFAULT_ABI_LIBRARY "vcruntime") |
Eugene Zelenko | 772d114 | 2016-08-08 18:01:50 | [diff] [blame] | 239 | else() |
Louis Dionne | a80e65e | 2022-03-01 13:42:13 | [diff] [blame] | 240 | set(LIBCXX_DEFAULT_ABI_LIBRARY "libcxxabi") |
| 241 | endif() |
| 242 | |
| 243 | set(LIBCXX_SUPPORTED_ABI_LIBRARIES none libcxxabi system-libcxxabi libcxxrt libstdc++ libsupc++ vcruntime) |
| 244 | set(LIBCXX_CXX_ABI "${LIBCXX_DEFAULT_ABI_LIBRARY}" CACHE STRING "Specify C++ ABI library to use. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}.") |
Louis Dionne | a80e65e | 2022-03-01 13:42:13 | [diff] [blame] | 245 | if (NOT "${LIBCXX_CXX_ABI}" IN_LIST LIBCXX_SUPPORTED_ABI_LIBRARIES) |
| 246 | message(FATAL_ERROR "Unsupported C++ ABI library: '${LIBCXX_CXX_ABI}'. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}.") |
Eugene Zelenko | 772d114 | 2016-08-08 18:01:50 | [diff] [blame] | 247 | endif() |
Eric Fiselier | bb90685 | 2015-10-22 20:54:27 | [diff] [blame] | 248 | |
Louis Dionne | 0c962cb | 2019-03-18 18:18:01 | [diff] [blame] | 249 | option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY |
| 250 | "Use a static copy of the ABI library when linking libc++. |
| 251 | This option cannot be used with LIBCXX_ENABLE_ABI_LINKER_SCRIPT." OFF) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 252 | |
Nikita Popov | e911ece | 2022-09-26 13:42:35 | [diff] [blame] | 253 | option(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY |
| 254 | "Statically link the ABI library to static library" |
| 255 | ${LIBCXX_ENABLE_STATIC_ABI_LIBRARY}) |
Petr Hosek | 058c04c | 2018-07-24 07:06:17 | [diff] [blame] | 256 | |
Nikita Popov | e911ece | 2022-09-26 13:42:35 | [diff] [blame] | 257 | option(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY |
| 258 | "Statically link the ABI library to shared library" |
| 259 | ${LIBCXX_ENABLE_STATIC_ABI_LIBRARY}) |
Petr Hosek | 058c04c | 2018-07-24 07:06:17 | [diff] [blame] | 260 | |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 261 | # Generate and install a linker script inplace of libc++.so. The linker script |
Eric Fiselier | 1ab69fc | 2015-10-15 22:41:51 | [diff] [blame] | 262 | # will link libc++ to the correct ABI library. This option is on by default |
Haowei | 1f8f9e3 | 2023-12-01 20:37:04 | [diff] [blame] | 263 | # on UNIX platforms other than Apple, and on the Fuchsia platform unless we |
| 264 | # statically link libc++abi inside libc++.so, we don't build libc++.so at all |
| 265 | # or we don't have any ABI library. |
Louis Dionne | 4b1fe09 | 2023-11-23 15:15:03 | [diff] [blame] | 266 | if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY |
| 267 | OR NOT LIBCXX_ENABLE_SHARED |
| 268 | OR LIBCXX_CXX_ABI STREQUAL "none") |
| 269 | set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF) |
Haowei | 1f8f9e3 | 2023-12-01 20:37:04 | [diff] [blame] | 270 | elseif((UNIX OR FUCHSIA) AND NOT APPLE) |
Louis Dionne | 4b1fe09 | 2023-11-23 15:15:03 | [diff] [blame] | 271 | set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE ON) |
| 272 | else() |
| 273 | set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF) |
Eric Fiselier | 1ab69fc | 2015-10-15 22:41:51 | [diff] [blame] | 274 | endif() |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 275 | option(LIBCXX_ENABLE_ABI_LINKER_SCRIPT |
Eric Fiselier | 1ab69fc | 2015-10-15 22:41:51 | [diff] [blame] | 276 | "Use and install a linker script for the given ABI library" |
Eric Fiselier | a15785b | 2015-10-15 23:04:54 | [diff] [blame] | 277 | ${ENABLE_LINKER_SCRIPT_DEFAULT_VALUE}) |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 278 | |
Eric Fiselier | 3499263 | 2017-03-02 19:35:33 | [diff] [blame] | 279 | option(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS |
Louis Dionne | 9b40ee8 | 2019-10-01 13:34:58 | [diff] [blame] | 280 | "Build libc++ with definitions for operator new/delete. These are normally |
| 281 | defined in libc++abi, but this option can be used to define them in libc++ |
| 282 | instead. If you define them in libc++, make sure they are NOT defined in |
| 283 | libc++abi. Doing otherwise is an ODR violation." OFF) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 284 | # Build libc++abi with libunwind. We need this option to determine whether to |
| 285 | # link with libunwind or libgcc_s while running the test cases. |
Louis Dionne | 8f90e69 | 2024-01-11 15:13:21 | [diff] [blame] | 286 | option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." ON) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 287 | |
| 288 | # Target options -------------------------------------------------------------- |
Louis Dionne | fa1c077 | 2021-11-23 21:34:09 | [diff] [blame] | 289 | 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}) |
| 290 | if (LIBCXX_BUILD_32_BITS) |
Louis Dionne | dc1244d | 2021-12-01 17:57:30 | [diff] [blame] | 291 | 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 21:34:09 | [diff] [blame] | 292 | endif() |
Louis Dionne | 72117f2 | 2021-10-12 19:59:08 | [diff] [blame] | 293 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 294 | # Feature options ------------------------------------------------------------- |
Vasileios Kalintiris | 8c58e92 | 2015-11-09 10:21:04 | [diff] [blame] | 295 | option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF) |
Ben Craig | b9599b1 | 2016-05-25 17:40:09 | [diff] [blame] | 296 | option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF) |
Martin Storsjo | bf02a09 | 2018-01-05 20:48:29 | [diff] [blame] | 297 | 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 | [diff] [blame] | 298 | option(LIBCXX_HAS_EXTERNAL_THREAD_API |
| 299 | "Build libc++ with an externalized threading API. |
| 300 | This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 301 | |
Nikolas Klauser | e837f4b | 2023-05-24 22:33:38 | [diff] [blame] | 302 | if (LIBCXX_ENABLE_THREADS) |
Louis Dionne | d423d80 | 2024-04-17 17:36:53 | [diff] [blame] | 303 | set(LIBCXX_PSTL_BACKEND "std_thread" CACHE STRING "Which PSTL backend to use") |
Nikolas Klauser | e837f4b | 2023-05-24 22:33:38 | [diff] [blame] | 304 | else() |
Louis Dionne | d423d80 | 2024-04-17 17:36:53 | [diff] [blame] | 305 | set(LIBCXX_PSTL_BACKEND "serial" CACHE STRING "Which PSTL backend to use") |
Nikolas Klauser | e837f4b | 2023-05-24 22:33:38 | [diff] [blame] | 306 | endif() |
| 307 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 308 | # Misc options ---------------------------------------------------------------- |
Eric Fiselier | 6fb770a | 2015-10-10 03:34:52 | [diff] [blame] | 309 | # FIXME: Turn -pedantic back ON. It is currently off because it warns |
| 310 | # about #include_next which is used everywhere. |
| 311 | option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 312 | option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) |
| 313 | |
Martin Storsjö | bedf657 | 2022-04-09 20:40:07 | [diff] [blame] | 314 | set(LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT OFF) |
| 315 | if (WIN32) |
| 316 | set(LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT ON) |
| 317 | endif() |
Petr Hosek | a2685cd | 2019-01-06 06:14:31 | [diff] [blame] | 318 | option(LIBCXX_HERMETIC_STATIC_LIBRARY |
Martin Storsjö | bedf657 | 2022-04-09 20:40:07 | [diff] [blame] | 319 | "Do not export any symbols from the static library." ${LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT}) |
Petr Hosek | a2685cd | 2019-01-06 06:14:31 | [diff] [blame] | 320 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [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 | [diff] [blame] | 330 | endif() |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 331 | |
Asiri Rathnayake | 205d7d3 | 2017-01-03 12:59:50 | [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() |
Martin Storsjo | bf02a09 | 2018-01-05 20:48:29 | [diff] [blame] | 341 | if (LIBCXX_HAS_WIN32_THREAD_API) |
| 342 | message(FATAL_ERROR "LIBCXX_HAS_WIN32_THREAD_API can only be set to ON" |
| 343 | " when LIBCXX_ENABLE_THREADS is also set to ON.") |
| 344 | endif() |
Eric Fiselier | 00f6bea | 2017-01-06 20:05:40 | [diff] [blame] | 345 | |
| 346 | endif() |
| 347 | |
Asiri Rathnayake | b71c899 | 2017-01-09 10:38:56 | [diff] [blame] | 348 | if (LIBCXX_HAS_EXTERNAL_THREAD_API) |
Asiri Rathnayake | b71c899 | 2017-01-09 10:38:56 | [diff] [blame] | 349 | if (LIBCXX_HAS_PTHREAD_API) |
| 350 | message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API" |
Mark de Wever | 0735a6e | 2023-09-06 18:54:43 | [diff] [blame] | 351 | " and LIBCXX_HAS_PTHREAD_API cannot be both" |
| 352 | " set to ON at the same time.") |
Asiri Rathnayake | b71c899 | 2017-01-09 10:38:56 | [diff] [blame] | 353 | endif() |
Martin Storsjo | bf02a09 | 2018-01-05 20:48:29 | [diff] [blame] | 354 | if (LIBCXX_HAS_WIN32_THREAD_API) |
| 355 | message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API" |
Mark de Wever | 0735a6e | 2023-09-06 18:54:43 | [diff] [blame] | 356 | " and LIBCXX_HAS_WIN32_THREAD_API cannot be both" |
| 357 | " set to ON at the same time.") |
Martin Storsjo | bf02a09 | 2018-01-05 20:48:29 | [diff] [blame] | 358 | endif() |
| 359 | endif() |
| 360 | |
| 361 | if (LIBCXX_HAS_PTHREAD_API) |
| 362 | if (LIBCXX_HAS_WIN32_THREAD_API) |
| 363 | message(FATAL_ERROR "The options LIBCXX_HAS_PTHREAD_API" |
Mark de Wever | 0735a6e | 2023-09-06 18:54:43 | [diff] [blame] | 364 | " and LIBCXX_HAS_WIN32_THREAD_API cannot be both" |
| 365 | " set to ON at the same time.") |
Martin Storsjo | bf02a09 | 2018-01-05 20:48:29 | [diff] [blame] | 366 | endif() |
Asiri Rathnayake | 8c2bf45 | 2016-09-11 21:46:40 | [diff] [blame] | 367 | endif() |
| 368 | |
Mark de Wever | ed210f9 | 2023-12-12 16:11:53 | [diff] [blame] | 369 | if (NOT LIBCXX_ENABLE_RTTI AND LIBCXX_ENABLE_EXCEPTIONS) |
| 370 | message(FATAL_ERROR "Libc++ cannot be built with exceptions enabled but RTTI" |
| 371 | " disabled, since that configuration is broken. See" |
| 372 | " https://github.com/llvm/llvm-project/issues/66117" |
| 373 | " for details.") |
| 374 | endif() |
| 375 | |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 376 | if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT) |
| 377 | if (APPLE) |
| 378 | message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT cannot be used on APPLE targets") |
| 379 | endif() |
Asiri Rathnayake | 28383a4 | 2016-05-14 23:58:11 | [diff] [blame] | 380 | if (NOT LIBCXX_ENABLE_SHARED) |
| 381 | message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT is only available for shared library builds.") |
| 382 | endif() |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 383 | endif() |
| 384 | |
Petr Hosek | 4b59ed4 | 2018-07-26 05:10:24 | [diff] [blame] | 385 | if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT) |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 386 | message(FATAL_ERROR "Conflicting options given. |
Nikita Popov | e911ece | 2022-09-26 13:42:35 | [diff] [blame] | 387 | LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY cannot be specified with |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 388 | LIBCXX_ENABLE_ABI_LINKER_SCRIPT") |
| 389 | endif() |
| 390 | |
Shoaib Meenai | a4a3d40 | 2017-10-05 02:18:08 | [diff] [blame] | 391 | if (LIBCXX_ABI_FORCE_ITANIUM AND LIBCXX_ABI_FORCE_MICROSOFT) |
| 392 | 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 | [diff] [blame] | 393 | endif () |
| 394 | |
Martin Storsjö | e777e44 | 2023-07-17 09:52:47 | [diff] [blame] | 395 | if (LIBCXX_ENABLE_SHARED AND CMAKE_MSVC_RUNTIME_LIBRARY AND |
| 396 | (NOT CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL$")) |
| 397 | message(WARNING "A static CRT linked into a shared libc++ doesn't work correctly.") |
| 398 | endif() |
| 399 | |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 400 | #=============================================================================== |
| 401 | # Configure System |
| 402 | #=============================================================================== |
| 403 | |
Louis Dionne | c06a8f9 | 2020-06-26 16:08:59 | [diff] [blame] | 404 | # TODO: Projects that depend on libc++ should use LIBCXX_GENERATED_INCLUDE_DIR |
| 405 | # instead of hard-coding include/c++/v1. |
John Ericson | 0a8d15a | 2022-01-11 03:03:21 | [diff] [blame] | 406 | |
Louis Dionne | 760261a | 2023-08-14 22:14:02 | [diff] [blame] | 407 | set(LIBCXX_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/c++/v1" CACHE STRING |
John Ericson | 0a8d15a | 2022-01-11 03:03:21 | [diff] [blame] | 408 | "Path where target-agnostic libc++ headers should be installed.") |
Louis Dionne | 760261a | 2023-08-14 22:14:02 | [diff] [blame] | 409 | set(LIBCXX_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING |
John Ericson | 0a8d15a | 2022-01-11 03:03:21 | [diff] [blame] | 410 | "Path where built libc++ runtime libraries should be installed.") |
Mark de Wever | 8b47bb6 | 2024-01-21 11:16:22 | [diff] [blame] | 411 | set(LIBCXX_INSTALL_MODULES_DIR "share/libc++/v1" CACHE STRING |
| 412 | "Path where target-agnostic libc++ module source files should be installed.") |
John Ericson | 0a8d15a | 2022-01-11 03:03:21 | [diff] [blame] | 413 | |
Louis Dionne | 10378b3 | 2022-10-11 14:05:56 | [diff] [blame] | 414 | set(LIBCXX_SHARED_OUTPUT_NAME "c++" CACHE STRING "Output name for the shared libc++ runtime library.") |
| 415 | set(LIBCXX_STATIC_OUTPUT_NAME "c++" CACHE STRING "Output name for the static libc++ runtime library.") |
Zibi Sarbinowski | 36dde91 | 2022-10-03 21:41:58 | [diff] [blame] | 416 | |
Petr Hosek | 887f26d | 2018-06-28 03:11:52 | [diff] [blame] | 417 | if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) |
Petr Hosek | ed155f3 | 2024-05-31 18:48:45 | [diff] [blame] | 418 | set(LIBCXX_TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE}) |
| 419 | if(LIBCXX_LIBDIR_SUBDIR) |
| 420 | string(APPEND LIBCXX_TARGET_SUBDIR /${LIBCXX_LIBDIR_SUBDIR}) |
| 421 | endif() |
| 422 | set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LIBCXX_TARGET_SUBDIR}) |
Kirill Stoimenov | 576b538 | 2025-01-14 18:23:07 | [diff] [blame] | 423 | set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1") |
| 424 | set(LIBCXX_GENERATED_MODULE_DIR "${LLVM_BINARY_DIR}/modules/c++/v1") |
| 425 | set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LIBCXX_TARGET_SUBDIR}/c++/v1") |
Petr Hosek | ed155f3 | 2024-05-31 18:48:45 | [diff] [blame] | 426 | set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LIBCXX_TARGET_SUBDIR} CACHE STRING |
John Ericson | 1e03c37 | 2021-04-28 22:36:47 | [diff] [blame] | 427 | "Path where built libc++ libraries should be installed.") |
Petr Hosek | ed155f3 | 2024-05-31 18:48:45 | [diff] [blame] | 428 | set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${LIBCXX_TARGET_SUBDIR}/c++/v1" CACHE STRING |
John Ericson | 1e03c37 | 2021-04-28 22:36:47 | [diff] [blame] | 429 | "Path where target-specific libc++ headers should be installed.") |
Petr Hosek | ed155f3 | 2024-05-31 18:48:45 | [diff] [blame] | 430 | unset(LIBCXX_TARGET_SUBDIR) |
Jonas Hahnfeld | 98a7f27 | 2017-05-04 06:02:50 | [diff] [blame] | 431 | else() |
John Ericson | 0a8d15a | 2022-01-11 03:03:21 | [diff] [blame] | 432 | if(LLVM_LIBRARY_OUTPUT_INTDIR) |
| 433 | set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) |
Kirill Stoimenov | 576b538 | 2025-01-14 18:23:07 | [diff] [blame] | 434 | set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1") |
| 435 | set(LIBCXX_GENERATED_MODULE_DIR "${LLVM_BINARY_DIR}/modules/c++/v1") |
John Ericson | 0a8d15a | 2022-01-11 03:03:21 | [diff] [blame] | 436 | else() |
John Ericson | e941b03 | 2022-08-19 02:44:46 | [diff] [blame] | 437 | set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) |
Kirill Stoimenov | 576b538 | 2025-01-14 18:23:07 | [diff] [blame] | 438 | set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1") |
| 439 | set(LIBCXX_GENERATED_MODULE_DIR "${CMAKE_BINARY_DIR}/modules/c++/v1") |
John Ericson | 0a8d15a | 2022-01-11 03:03:21 | [diff] [blame] | 440 | endif() |
Petr Hosek | ea12d77 | 2020-07-15 21:10:56 | [diff] [blame] | 441 | set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}") |
Louis Dionne | 760261a | 2023-08-14 22:14:02 | [diff] [blame] | 442 | set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX} CACHE STRING |
John Ericson | 1e03c37 | 2021-04-28 22:36:47 | [diff] [blame] | 443 | "Path where built libc++ libraries should be installed.") |
Louis Dionne | 760261a | 2023-08-14 22:14:02 | [diff] [blame] | 444 | set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${LIBCXX_INSTALL_INCLUDE_DIR}" CACHE STRING |
John Ericson | 1e03c37 | 2021-04-28 22:36:47 | [diff] [blame] | 445 | "Path where target-specific libc++ headers should be installed.") |
Jonas Hahnfeld | 98a7f27 | 2017-05-04 06:02:50 | [diff] [blame] | 446 | endif() |
Petr Hosek | 887f26d | 2018-06-28 03:11:52 | [diff] [blame] | 447 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 448 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) |
| 449 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) |
Shoaib Meenai | 6170765 | 2017-04-13 16:27:38 | [diff] [blame] | 450 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 451 | |
Eric Fiselier | 5aedca9 | 2014-11-15 06:26:30 | [diff] [blame] | 452 | # Declare libc++ configuration variables. |
| 453 | # They are intended for use as follows: |
| 454 | # LIBCXX_CXX_FLAGS: General flags for both the compiler and linker. |
| 455 | # LIBCXX_COMPILE_FLAGS: Compile only flags. |
| 456 | # LIBCXX_LINK_FLAGS: Linker only flags. |
Eric Fiselier | 054fc4c | 2016-10-09 21:34:03 | [diff] [blame] | 457 | # LIBCXX_LIBRARIES: libraries libc++ is linked to. |
Eric Fiselier | 5aedca9 | 2014-11-15 06:26:30 | [diff] [blame] | 458 | set(LIBCXX_COMPILE_FLAGS "") |
| 459 | set(LIBCXX_LINK_FLAGS "") |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 460 | set(LIBCXX_LIBRARIES "") |
Zibi Sarbinowski | 36dde91 | 2022-10-03 21:41:58 | [diff] [blame] | 461 | set(LIBCXX_ADDITIONAL_COMPILE_FLAGS "" CACHE STRING |
Louis Dionne | e674424 | 2024-10-17 20:17:40 | [diff] [blame] | 462 | "Additional compile flags to use when building libc++. This should be a CMake ;-delimited list of individual |
| 463 | compiler options to use. For options that must be passed as-is to the compiler without deduplication (e.g. |
| 464 | `-Xclang -foo` option groups), consider using `SHELL:` (https://cmake.org/cmake/help/latest/command/add_compile_options.html#option-de-duplication).") |
Zibi Sarbinowski | 36dde91 | 2022-10-03 21:41:58 | [diff] [blame] | 465 | set(LIBCXX_ADDITIONAL_LIBRARIES "" CACHE STRING |
| 466 | "Additional libraries libc++ is linked to which can be provided in cache") |
Eric Fiselier | 5aedca9 | 2014-11-15 06:26:30 | [diff] [blame] | 467 | |
Eric Fiselier | a4f2460 | 2016-06-02 01:10:08 | [diff] [blame] | 468 | # Include macros for adding and removing libc++ flags. |
| 469 | include(HandleLibcxxFlags) |
| 470 | |
| 471 | # Target flags ================================================================ |
| 472 | # These flags get added to CMAKE_CXX_FLAGS and CMAKE_C_FLAGS so that |
| 473 | # 'config-ix' use them during feature checks. It also adds them to both |
| 474 | # 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS' |
Petr Hosek | 6fd4e7f | 2019-02-04 20:02:26 | [diff] [blame] | 475 | |
Jake Egan | 1cf4113 | 2022-06-14 01:44:58 | [diff] [blame] | 476 | if (${CMAKE_SYSTEM_NAME} MATCHES "AIX") |
Nikolas Klauser | d0e95fe | 2023-02-20 15:47:34 | [diff] [blame] | 477 | add_flags_if_supported("-mdefault-visibility-export-mapping=explicit") |
Jake Egan | 1cf4113 | 2022-06-14 01:44:58 | [diff] [blame] | 478 | set(CMAKE_AIX_EXPORT_ALL_SYMBOLS OFF) |
| 479 | endif() |
| 480 | |
Eric Fiselier | 382338d | 2014-11-15 17:25:23 | [diff] [blame] | 481 | # Configure compiler. |
| 482 | include(config-ix) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 483 | |
Eric Fiselier | 382338d | 2014-11-15 17:25:23 | [diff] [blame] | 484 | #=============================================================================== |
| 485 | # Setup Compiler Flags |
| 486 | #=============================================================================== |
| 487 | |
Petr Hosek | 3b78dfa | 2024-07-19 05:17:42 | [diff] [blame] | 488 | include(HandleLibC) # Setup the C library flags |
JF Bastien | fc45f32 | 2016-03-05 14:22:02 | [diff] [blame] | 489 | include(HandleLibCXXABI) # Setup the ABI library flags |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 490 | |
Shoaib Meenai | f88923d | 2017-03-25 03:42:20 | [diff] [blame] | 491 | # FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC. |
Eric Fiselier | f2be7c2 | 2015-10-15 20:27:15 | [diff] [blame] | 492 | # Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors |
Shoaib Meenai | f88923d | 2017-03-25 03:42:20 | [diff] [blame] | 493 | # so they don't get transformed into -Wno and -errors respectively. |
Eric Fiselier | f2be7c2 | 2015-10-15 20:27:15 | [diff] [blame] | 494 | remove_flags(-Wno-pedantic -pedantic-errors -pedantic) |
Eric Fiselier | f4bfd7c | 2015-10-13 23:56:33 | [diff] [blame] | 495 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 496 | # Required flags ============================================================== |
Louis Dionne | 925d9d2 | 2019-10-02 20:07:01 | [diff] [blame] | 497 | function(cxx_add_basic_build_flags target) |
Eric Fiselier | 72b41e6 | 2019-12-12 01:26:30 | [diff] [blame] | 498 | |
Louis Dionne | 8a7846f | 2023-11-05 13:40:51 | [diff] [blame] | 499 | # Use C++23 for all targets. |
Eric Fiselier | 72b41e6 | 2019-12-12 01:26:30 | [diff] [blame] | 500 | set_target_properties(${target} PROPERTIES |
Louis Dionne | 8a7846f | 2023-11-05 13:40:51 | [diff] [blame] | 501 | CXX_STANDARD 23 |
Louis Dionne | f97a579 | 2023-11-16 19:58:36 | [diff] [blame] | 502 | CXX_STANDARD_REQUIRED OFF # TODO: Make this REQUIRED once we don't need to accommodate the LLVM documentation builders using an ancient CMake |
Eric Fiselier | 72b41e6 | 2019-12-12 01:26:30 | [diff] [blame] | 503 | CXX_EXTENSIONS NO) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 504 | |
Louis Dionne | 918ba93 | 2020-07-23 15:05:47 | [diff] [blame] | 505 | # When building the dylib, don't warn for unavailable aligned allocation |
| 506 | # functions based on the deployment target -- they are always available |
Gabriel Ravier | c23e2c0 | 2022-08-02 10:42:04 | [diff] [blame] | 507 | # because they are provided by the dylib itself with the exception of z/OS. |
Zbigniew Sarbinowski | aa8a5b8 | 2020-11-12 19:40:35 | [diff] [blame] | 508 | if (ZOS) |
| 509 | target_add_compile_flags_if_supported(${target} PRIVATE -fno-aligned-allocation) |
| 510 | else() |
| 511 | target_add_compile_flags_if_supported(${target} PRIVATE -faligned-allocation) |
| 512 | endif() |
Louis Dionne | 918ba93 | 2020-07-23 15:05:47 | [diff] [blame] | 513 | |
Louis Dionne | 925d9d2 | 2019-10-02 20:07:01 | [diff] [blame] | 514 | # On all systems the system c++ standard library headers need to be excluded. |
| 515 | # MSVC only has -X, which disables all default includes; including the crt. |
| 516 | # Thus, we do nothing and hope we don't accidentally include any of the C++ |
| 517 | # headers |
| 518 | target_add_compile_flags_if_supported(${target} PUBLIC -nostdinc++) |
Eric Fiselier | ff16b9a | 2015-07-29 21:07:28 | [diff] [blame] | 519 | |
Louis Dionne | 925d9d2 | 2019-10-02 20:07:01 | [diff] [blame] | 520 | # Hide all inline function definitions which have not explicitly been marked |
| 521 | # visible. This prevents new definitions for inline functions from appearing in |
| 522 | # the dylib when get ODR used by another function. |
| 523 | target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility-inlines-hidden) |
Eric Fiselier | 10b12f0 | 2016-10-25 19:43:44 | [diff] [blame] | 524 | |
Nikolas Klauser | 7334024 | 2025-03-25 14:43:48 | [diff] [blame] | 525 | target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility=hidden) |
Eric Fiselier | 3ca9185 | 2017-05-25 04:36:24 | [diff] [blame] | 526 | |
Louis Dionne | d2864d1 | 2024-06-24 21:26:03 | [diff] [blame] | 527 | # Build with -fsized-deallocation, which is default in recent versions of Clang. |
| 528 | # TODO(LLVM 21): This can be dropped once we only support Clang >= 19. |
| 529 | target_add_compile_flags_if_supported(${target} PRIVATE -fsized-deallocation) |
| 530 | |
Louis Dionne | 925d9d2 | 2019-10-02 20:07:01 | [diff] [blame] | 531 | # Let the library headers know they are currently being used to build the |
| 532 | # library. |
| 533 | target_compile_definitions(${target} PRIVATE -D_LIBCPP_BUILDING_LIBRARY) |
Eric Fiselier | 3499263 | 2017-03-02 19:35:33 | [diff] [blame] | 534 | |
Mark de Wever | c416234 | 2023-03-10 16:31:58 | [diff] [blame] | 535 | # Make sure the library can be build without transitive includes. This makes |
| 536 | # it easier to upgrade the library to a newer language standard without build |
| 537 | # errors. |
| 538 | target_compile_definitions(${target} PRIVATE -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) |
| 539 | |
Petr Hosek | b3df14b | 2022-03-10 09:47:09 | [diff] [blame] | 540 | if (C_SUPPORTS_COMMENT_LIB_PRAGMA) |
Michał Górny | a9b5fff | 2019-12-02 10:49:20 | [diff] [blame] | 541 | if (LIBCXX_HAS_PTHREAD_LIB) |
| 542 | target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_PTHREAD_LIB) |
| 543 | endif() |
| 544 | if (LIBCXX_HAS_RT_LIB) |
| 545 | target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_RT_LIB) |
| 546 | endif() |
Louis Dionne | 925d9d2 | 2019-10-02 20:07:01 | [diff] [blame] | 547 | endif() |
Zibi Sarbinowski | 36dde91 | 2022-10-03 21:41:58 | [diff] [blame] | 548 | target_compile_options(${target} PUBLIC "${LIBCXX_ADDITIONAL_COMPILE_FLAGS}") |
Louis Dionne | 925d9d2 | 2019-10-02 20:07:01 | [diff] [blame] | 549 | endfunction() |
Petr Hosek | 789b7f0 | 2019-05-30 04:40:21 | [diff] [blame] | 550 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 551 | # Exception flags ============================================================= |
Louis Dionne | 432ae75 | 2019-10-04 18:03:17 | [diff] [blame] | 552 | function(cxx_add_exception_flags target) |
| 553 | if (LIBCXX_ENABLE_EXCEPTIONS) |
| 554 | # Catches C++ exceptions only and tells the compiler to assume that extern C |
| 555 | # functions never throw a C++ exception. |
| 556 | target_add_compile_flags_if_supported(${target} PUBLIC -EHsc) |
| 557 | else() |
Louis Dionne | 432ae75 | 2019-10-04 18:03:17 | [diff] [blame] | 558 | target_add_compile_flags_if_supported(${target} PUBLIC -EHs- -EHa-) |
| 559 | target_add_compile_flags_if_supported(${target} PUBLIC -fno-exceptions) |
| 560 | endif() |
| 561 | endfunction() |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 562 | |
| 563 | # RTTI flags ================================================================== |
Louis Dionne | 432ae75 | 2019-10-04 18:03:17 | [diff] [blame] | 564 | function(cxx_add_rtti_flags target) |
| 565 | if (NOT LIBCXX_ENABLE_RTTI) |
David Spickett | 43cfc78 | 2023-07-07 09:55:36 | [diff] [blame] | 566 | if (MSVC) |
David Spickett | 36df92d | 2023-07-06 08:49:33 | [diff] [blame] | 567 | target_add_compile_flags_if_supported(${target} PUBLIC -GR-) |
| 568 | else() |
| 569 | target_add_compile_flags_if_supported(${target} PUBLIC -fno-rtti) |
| 570 | endif() |
Louis Dionne | 432ae75 | 2019-10-04 18:03:17 | [diff] [blame] | 571 | endif() |
| 572 | endfunction() |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 573 | |
Eric Fiselier | 194e027 | 2016-10-14 12:56:52 | [diff] [blame] | 574 | # Modules flags =============================================================== |
| 575 | # FIXME The libc++ sources are fundamentally non-modular. They need special |
| 576 | # versions of the headers in order to provide C++03 and legacy ABI definitions. |
| 577 | # NOTE: The public headers can be used with modules in all other contexts. |
Louis Dionne | 432ae75 | 2019-10-04 18:03:17 | [diff] [blame] | 578 | function(cxx_add_module_flags target) |
| 579 | if (LLVM_ENABLE_MODULES) |
| 580 | # Ignore that the rest of the modules flags are now unused. |
Louis Dionne | 13c4254 | 2019-10-04 19:10:56 | [diff] [blame] | 581 | target_add_compile_flags_if_supported(${target} PUBLIC -Wno-unused-command-line-argument) |
| 582 | target_compile_options(${target} PUBLIC -fno-modules) |
Louis Dionne | 432ae75 | 2019-10-04 18:03:17 | [diff] [blame] | 583 | endif() |
| 584 | endfunction() |
Eric Fiselier | 194e027 | 2016-10-14 12:56:52 | [diff] [blame] | 585 | |
varconst | 1ba514c | 2023-07-12 03:18:20 | [diff] [blame] | 586 | string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) |
| 587 | |
Jonathan Roelofs | 91b3a5e | 2015-08-24 21:20:07 | [diff] [blame] | 588 | # Sanitizer flags ============================================================= |
Eric Fiselier | b98aa43 | 2015-07-29 23:46:55 | [diff] [blame] | 589 | |
Eric Fiselier | 02f8e7c35 | 2018-11-13 23:08:31 | [diff] [blame] | 590 | function(get_sanitizer_flags OUT_VAR USE_SANITIZER) |
| 591 | set(SANITIZER_FLAGS) |
| 592 | set(USE_SANITIZER "${USE_SANITIZER}") |
| 593 | # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC. |
| 594 | # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do. |
| 595 | if (USE_SANITIZER AND NOT MSVC) |
| 596 | append_flags_if_supported(SANITIZER_FLAGS "-fno-omit-frame-pointer") |
| 597 | append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only") |
| 598 | |
| 599 | if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND |
| 600 | NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO") |
| 601 | append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only") |
| 602 | endif() |
| 603 | if (USE_SANITIZER STREQUAL "Address") |
| 604 | append_flags(SANITIZER_FLAGS "-fsanitize=address") |
Vitaly Buka | 18014fe | 2022-08-13 05:12:28 | [diff] [blame] | 605 | elseif (USE_SANITIZER STREQUAL "HWAddress") |
| 606 | append_flags(SANITIZER_FLAGS "-fsanitize=hwaddress") |
Eric Fiselier | 02f8e7c35 | 2018-11-13 23:08:31 | [diff] [blame] | 607 | elseif (USE_SANITIZER MATCHES "Memory(WithOrigins)?") |
Mark de Wever | d563df8 | 2022-04-30 11:17:17 | [diff] [blame] | 608 | append_flags(SANITIZER_FLAGS -fsanitize=memory) |
Eric Fiselier | 02f8e7c35 | 2018-11-13 23:08:31 | [diff] [blame] | 609 | if (USE_SANITIZER STREQUAL "MemoryWithOrigins") |
| 610 | append_flags(SANITIZER_FLAGS "-fsanitize-memory-track-origins") |
| 611 | endif() |
| 612 | elseif (USE_SANITIZER STREQUAL "Undefined") |
Louis Dionne | fa712b0 | 2023-11-29 14:29:44 | [diff] [blame] | 613 | append_flags(SANITIZER_FLAGS "-fsanitize=undefined" "-fno-sanitize=vptr,function" "-fno-sanitize-recover=all") |
Brian Gesiak | 54176d1 | 2020-04-04 17:01:32 | [diff] [blame] | 614 | elseif (USE_SANITIZER STREQUAL "Address;Undefined" OR |
| 615 | USE_SANITIZER STREQUAL "Undefined;Address") |
Louis Dionne | fa712b0 | 2023-11-29 14:29:44 | [diff] [blame] | 616 | append_flags(SANITIZER_FLAGS "-fsanitize=address,undefined" "-fno-sanitize=vptr,function" "-fno-sanitize-recover=all") |
Eric Fiselier | 02f8e7c35 | 2018-11-13 23:08:31 | [diff] [blame] | 617 | elseif (USE_SANITIZER STREQUAL "Thread") |
| 618 | append_flags(SANITIZER_FLAGS -fsanitize=thread) |
Zola Bridges | 0f12480 | 2020-04-17 17:15:58 | [diff] [blame] | 619 | elseif (USE_SANITIZER STREQUAL "DataFlow") |
| 620 | append_flags(SANITIZER_FLAGS -fsanitize=dataflow) |
Eric Fiselier | 02f8e7c35 | 2018-11-13 23:08:31 | [diff] [blame] | 621 | else() |
| 622 | message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${USE_SANITIZER}") |
| 623 | endif() |
| 624 | elseif(USE_SANITIZER AND MSVC) |
| 625 | message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.") |
| 626 | endif() |
| 627 | set(${OUT_VAR} "${SANITIZER_FLAGS}" PARENT_SCOPE) |
| 628 | endfunction() |
| 629 | |
Eric Fiselier | 02f8e7c35 | 2018-11-13 23:08:31 | [diff] [blame] | 630 | get_sanitizer_flags(SANITIZER_FLAGS "${LLVM_USE_SANITIZER}") |
Louis Dionne | fa712b0 | 2023-11-29 14:29:44 | [diff] [blame] | 631 | add_library(cxx-sanitizer-flags INTERFACE) |
| 632 | target_compile_options(cxx-sanitizer-flags INTERFACE ${SANITIZER_FLAGS}) |
Eric Fiselier | f9f796e | 2015-10-13 22:12:02 | [diff] [blame] | 633 | |
Tacet | 9ed2056 | 2023-12-13 05:05:34 | [diff] [blame] | 634 | # _LIBCPP_INSTRUMENTED_WITH_ASAN informs that library was built with ASan. |
| 635 | # Defining _LIBCPP_INSTRUMENTED_WITH_ASAN while building the library with ASan is required. |
| 636 | # Normally, the _LIBCPP_INSTRUMENTED_WITH_ASAN flag is used to keep information whether |
| 637 | # dylibs are built with AddressSanitizer. However, when building libc++, |
| 638 | # this flag needs to be defined so that the resulting dylib has all ASan functionalities guarded by this flag. |
| 639 | # If the _LIBCPP_INSTRUMENTED_WITH_ASAN flag is not defined, then parts of the ASan instrumentation code in libc++ |
| 640 | # will not be compiled into it, resulting in false positives. |
| 641 | # For context, read: https://github.com/llvm/llvm-project/pull/72677#pullrequestreview-1765402800 |
| 642 | string(FIND "${LLVM_USE_SANITIZER}" "Address" building_with_asan) |
| 643 | if (NOT "${building_with_asan}" STREQUAL "-1") |
| 644 | config_define(ON _LIBCPP_INSTRUMENTED_WITH_ASAN) |
Nikolas Klauser | c6f3b7b | 2024-11-06 09:39:19 | [diff] [blame] | 645 | else() |
| 646 | config_define(OFF _LIBCPP_INSTRUMENTED_WITH_ASAN) |
Tacet | 9ed2056 | 2023-12-13 05:05:34 | [diff] [blame] | 647 | endif() |
| 648 | |
Louis Dionne | 3230087 | 2019-10-08 16:26:24 | [diff] [blame] | 649 | # Link system libraries ======================================================= |
| 650 | function(cxx_link_system_libraries target) |
Louis Dionne | 36bb134 | 2023-10-13 18:53:57 | [diff] [blame] | 651 | if (NOT MSVC) |
| 652 | target_link_libraries(${target} PRIVATE "-nostdlib++") |
Zbigniew Sarbinowski | 5f9be2c | 2021-02-16 18:02:22 | [diff] [blame] | 653 | endif() |
Louis Dionne | 3230087 | 2019-10-08 16:26:24 | [diff] [blame] | 654 | |
Petr Hosek | b3df14b | 2022-03-10 09:47:09 | [diff] [blame] | 655 | if (CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG AND LIBCXXABI_USE_LLVM_UNWINDER) |
Martin Storsjö | 529a793 | 2021-10-23 22:11:20 | [diff] [blame] | 656 | # If we're linking directly against the libunwind that we're building |
| 657 | # in the same invocation, don't try to link in the toolchain's |
| 658 | # default libunwind (which may be missing still). |
| 659 | target_add_link_flags_if_supported(${target} PRIVATE "--unwindlib=none") |
| 660 | endif() |
| 661 | |
Louis Dionne | a4336f2 | 2023-12-13 18:57:48 | [diff] [blame] | 662 | if (MSVC) |
| 663 | if (LIBCXX_USE_COMPILER_RT) |
| 664 | find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY) |
| 665 | if (LIBCXX_BUILTINS_LIBRARY) |
| 666 | target_link_libraries(${target} PRIVATE "${LIBCXX_BUILTINS_LIBRARY}") |
| 667 | endif() |
| 668 | elseif (LIBCXX_HAS_GCC_LIB) |
| 669 | target_link_libraries(${target} PRIVATE gcc) |
| 670 | elseif (LIBCXX_HAS_GCC_S_LIB) |
| 671 | target_link_libraries(${target} PRIVATE gcc_s) |
Louis Dionne | 3230087 | 2019-10-08 16:26:24 | [diff] [blame] | 672 | endif() |
Louis Dionne | 3230087 | 2019-10-08 16:26:24 | [diff] [blame] | 673 | endif() |
| 674 | |
Louis Dionne | e018435 | 2020-06-04 18:54:38 | [diff] [blame] | 675 | if (LIBCXX_HAS_ATOMIC_LIB) |
Louis Dionne | 3230087 | 2019-10-08 16:26:24 | [diff] [blame] | 676 | target_link_libraries(${target} PRIVATE atomic) |
| 677 | endif() |
| 678 | |
| 679 | if (MINGW) |
| 680 | target_link_libraries(${target} PRIVATE "${MINGW_LIBRARIES}") |
| 681 | endif() |
| 682 | |
David Spickett | 43cfc78 | 2023-07-07 09:55:36 | [diff] [blame] | 683 | if (MSVC) |
Martin Storsjö | 9b02e8d | 2023-07-17 09:50:35 | [diff] [blame] | 684 | if ((NOT CMAKE_MSVC_RUNTIME_LIBRARY AND uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") |
| 685 | OR (CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "Debug")) |
Louis Dionne | 3230087 | 2019-10-08 16:26:24 | [diff] [blame] | 686 | set(LIB_SUFFIX "d") |
| 687 | else() |
| 688 | set(LIB_SUFFIX "") |
| 689 | endif() |
| 690 | |
Martin Storsjö | e777e44 | 2023-07-17 09:52:47 | [diff] [blame] | 691 | if (NOT CMAKE_MSVC_RUNTIME_LIBRARY OR CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL$") |
| 692 | set(CRT_LIB "msvcrt") |
| 693 | set(CXX_LIB "msvcprt") |
| 694 | else() |
| 695 | set(CRT_LIB "libcmt") |
| 696 | set(CXX_LIB "libcpmt") |
| 697 | endif() |
| 698 | |
| 699 | target_link_libraries(${target} PRIVATE ${CRT_LIB}${LIB_SUFFIX}) # C runtime startup files |
| 700 | target_link_libraries(${target} PRIVATE ${CXX_LIB}${LIB_SUFFIX}) # C++ standard library. Required for exception_ptr internals. |
Louis Dionne | 3230087 | 2019-10-08 16:26:24 | [diff] [blame] | 701 | # Required for standards-complaint wide character formatting functions |
| 702 | # (e.g. `printfw`/`scanfw`) |
| 703 | target_link_libraries(${target} PRIVATE iso_stdio_wide_specifiers) |
| 704 | endif() |
Shoaib Meenai | 076da52 | 2020-01-28 01:29:41 | [diff] [blame] | 705 | |
| 706 | if (ANDROID AND ANDROID_PLATFORM_LEVEL LESS 21) |
| 707 | target_link_libraries(${target} PUBLIC android_support) |
| 708 | endif() |
Zibi Sarbinowski | 36dde91 | 2022-10-03 21:41:58 | [diff] [blame] | 709 | target_link_libraries(${target} PUBLIC "${LIBCXX_ADDITIONAL_LIBRARIES}") |
Louis Dionne | 3230087 | 2019-10-08 16:26:24 | [diff] [blame] | 710 | endfunction() |
| 711 | |
Louis Dionne | 925d9d2 | 2019-10-02 20:07:01 | [diff] [blame] | 712 | # Windows-related flags ======================================================= |
| 713 | function(cxx_add_windows_flags target) |
| 714 | if(WIN32 AND NOT MINGW) |
| 715 | target_compile_definitions(${target} PRIVATE |
| 716 | # Ignore the -MSC_VER mismatch, as we may build |
| 717 | # with a different compatibility version. |
| 718 | _ALLOW_MSC_VER_MISMATCH |
| 719 | # Don't check the msvcprt iterator debug levels |
| 720 | # as we will define the iterator types; libc++ |
| 721 | # uses a different macro to identify the debug |
| 722 | # level. |
| 723 | _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH |
| 724 | # We are building the c++ runtime, don't pull in |
| 725 | # msvcprt. |
| 726 | _CRTBLD |
| 727 | # Don't warn on the use of "deprecated" |
| 728 | # "insecure" functions which are standards |
| 729 | # specified. |
| 730 | _CRT_SECURE_NO_WARNINGS |
| 731 | # Use the ISO conforming behaviour for conversion |
| 732 | # in printf, scanf. |
| 733 | _CRT_STDIO_ISO_WIDE_SPECIFIERS) |
| 734 | endif() |
| 735 | endfunction() |
| 736 | |
Eric Fiselier | f9f796e | 2015-10-13 22:12:02 | [diff] [blame] | 737 | # Configuration file flags ===================================================== |
Louis Dionne | 817d897 | 2022-02-07 19:52:17 | [diff] [blame] | 738 | config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION) |
| 739 | config_define(${LIBCXX_ABI_NAMESPACE} _LIBCPP_ABI_NAMESPACE) |
Nikolas Klauser | c6f3b7b | 2024-11-06 09:39:19 | [diff] [blame] | 740 | config_define(${LIBCXX_ABI_FORCE_ITANIUM} _LIBCPP_ABI_FORCE_ITANIUM) |
| 741 | config_define(${LIBCXX_ABI_FORCE_MICROSOFT} _LIBCPP_ABI_FORCE_MICROSOFT) |
| 742 | config_define(${LIBCXX_ENABLE_THREADS} _LIBCPP_HAS_THREADS) |
| 743 | config_define(${LIBCXX_ENABLE_MONOTONIC_CLOCK} _LIBCPP_HAS_MONOTONIC_CLOCK) |
| 744 | config_define(${LIBCXX_HAS_TERMINAL_AVAILABLE} _LIBCPP_HAS_TERMINAL) |
Louis Dionne | be00e88 | 2020-11-16 23:13:43 | [diff] [blame] | 745 | if (NOT LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION STREQUAL "default") |
Louis Dionne | d0fcdcd | 2020-05-15 19:58:19 | [diff] [blame] | 746 | config_define("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION) |
Eric Fiselier | 2405bd6 | 2019-05-29 02:21:37 | [diff] [blame] | 747 | endif() |
Nikolas Klauser | c6f3b7b | 2024-11-06 09:39:19 | [diff] [blame] | 748 | config_define(${LIBCXX_HAS_PTHREAD_API} _LIBCPP_HAS_THREAD_API_PTHREAD) |
| 749 | config_define(${LIBCXX_HAS_EXTERNAL_THREAD_API} _LIBCPP_HAS_THREAD_API_EXTERNAL) |
| 750 | config_define(${LIBCXX_HAS_WIN32_THREAD_API} _LIBCPP_HAS_THREAD_API_WIN32) |
| 751 | config_define(${LIBCXX_HAS_MUSL_LIBC} _LIBCPP_HAS_MUSL_LIBC) |
Shoaib Meenai | 492d713 | 2017-10-09 19:25:17 | [diff] [blame] | 752 | config_define_if(LIBCXX_NO_VCRUNTIME _LIBCPP_NO_VCRUNTIME) |
Nikolas Klauser | c6f3b7b | 2024-11-06 09:39:19 | [diff] [blame] | 753 | config_define(${LIBCXX_ENABLE_FILESYSTEM} _LIBCPP_HAS_FILESYSTEM) |
| 754 | config_define(${LIBCXX_ENABLE_RANDOM_DEVICE} _LIBCPP_HAS_RANDOM_DEVICE) |
| 755 | config_define(${LIBCXX_ENABLE_LOCALIZATION} _LIBCPP_HAS_LOCALIZATION) |
| 756 | config_define(${LIBCXX_ENABLE_UNICODE} _LIBCPP_HAS_UNICODE) |
| 757 | config_define(${LIBCXX_ENABLE_WIDE_CHARACTERS} _LIBCPP_HAS_WIDE_CHARACTERS) |
| 758 | config_define(${LIBCXX_ENABLE_TIME_ZONE_DATABASE} _LIBCPP_HAS_TIME_ZONE_DATABASE) |
| 759 | config_define(${LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS} _LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS) |
Konstantin Varlamov | c6151f5 | 2023-10-10 18:10:18 | [diff] [blame] | 760 | |
Louis Dionne | c9d9dc9 | 2024-10-29 14:48:18 | [diff] [blame] | 761 | # TODO: Remove in LLVM 21. We're leaving an error to make this fail explicitly. |
Konstantin Varlamov | c6151f5 | 2023-10-10 18:10:18 | [diff] [blame] | 762 | if (LIBCXX_ENABLE_ASSERTIONS) |
Louis Dionne | c9d9dc9 | 2024-10-29 14:48:18 | [diff] [blame] | 763 | message(FATAL_ERROR "LIBCXX_ENABLE_ASSERTIONS has been removed. Please use LIBCXX_HARDENING_MODE instead.") |
Konstantin Varlamov | c6151f5 | 2023-10-10 18:10:18 | [diff] [blame] | 764 | endif() |
Konstantin Varlamov | 64d413e | 2023-11-08 19:10:00 | [diff] [blame] | 765 | if (LIBCXX_HARDENING_MODE STREQUAL "none") |
| 766 | config_define(2 _LIBCPP_HARDENING_MODE_DEFAULT) |
| 767 | elseif (LIBCXX_HARDENING_MODE STREQUAL "fast") |
| 768 | config_define(4 _LIBCPP_HARDENING_MODE_DEFAULT) |
| 769 | elseif (LIBCXX_HARDENING_MODE STREQUAL "extensive") |
| 770 | config_define(16 _LIBCPP_HARDENING_MODE_DEFAULT) |
varconst | d1367ca | 2023-07-12 17:12:51 | [diff] [blame] | 771 | elseif (LIBCXX_HARDENING_MODE STREQUAL "debug") |
Konstantin Varlamov | 64d413e | 2023-11-08 19:10:00 | [diff] [blame] | 772 | config_define(8 _LIBCPP_HARDENING_MODE_DEFAULT) |
varconst | d1367ca | 2023-07-12 17:12:51 | [diff] [blame] | 773 | endif() |
Vasileios Kalintiris | 8c58e92 | 2015-11-09 10:21:04 | [diff] [blame] | 774 | |
Louis Dionne | d423d80 | 2024-04-17 17:36:53 | [diff] [blame] | 775 | if (LIBCXX_PSTL_BACKEND STREQUAL "serial") |
| 776 | config_define(1 _LIBCPP_PSTL_BACKEND_SERIAL) |
| 777 | elseif(LIBCXX_PSTL_BACKEND STREQUAL "std_thread") |
| 778 | config_define(1 _LIBCPP_PSTL_BACKEND_STD_THREAD) |
| 779 | elseif(LIBCXX_PSTL_BACKEND STREQUAL "libdispatch") |
| 780 | config_define(1 _LIBCPP_PSTL_BACKEND_LIBDISPATCH) |
Nikolas Klauser | e837f4b | 2023-05-24 22:33:38 | [diff] [blame] | 781 | else() |
Louis Dionne | d423d80 | 2024-04-17 17:36:53 | [diff] [blame] | 782 | message(FATAL_ERROR "LIBCXX_PSTL_BACKEND is set to ${LIBCXX_PSTL_BACKEND}, which is not a valid backend. |
Nikolas Klauser | 2b2e7f6 | 2023-07-12 20:24:57 | [diff] [blame] | 783 | Valid backends are: serial, std_thread and libdispatch") |
Nikolas Klauser | e837f4b | 2023-05-24 22:33:38 | [diff] [blame] | 784 | endif() |
| 785 | |
Shoaib Meenai | 8e62812 | 2017-10-04 23:17:12 | [diff] [blame] | 786 | if (LIBCXX_ABI_DEFINES) |
| 787 | set(abi_defines) |
| 788 | foreach (abi_define ${LIBCXX_ABI_DEFINES}) |
| 789 | if (NOT abi_define MATCHES "^_LIBCPP_ABI_") |
| 790 | message(SEND_ERROR "Invalid ABI macro ${abi_define} in LIBCXX_ABI_DEFINES") |
| 791 | endif() |
| 792 | list(APPEND abi_defines "#define ${abi_define}") |
| 793 | endforeach() |
| 794 | string(REPLACE ";" "\n" abi_defines "${abi_defines}") |
| 795 | config_define(${abi_defines} _LIBCPP_ABI_DEFINES) |
| 796 | endif() |
| 797 | |
Martin Storsjö | f68e890 | 2021-12-20 23:19:34 | [diff] [blame] | 798 | if (LIBCXX_EXTRA_SITE_DEFINES) |
| 799 | set(extra_site_defines) |
| 800 | foreach (extra_site_define ${LIBCXX_EXTRA_SITE_DEFINES}) |
| 801 | # Allow defines such as DEFINE=VAL, transformed into "#define DEFINE VAL". |
| 802 | string(REPLACE "=" " " extra_site_define "${extra_site_define}") |
| 803 | list(APPEND extra_site_defines "#define ${extra_site_define}") |
| 804 | endforeach() |
| 805 | string(REPLACE ";" "\n" extra_site_defines "${extra_site_defines}") |
| 806 | config_define(${extra_site_defines} _LIBCPP_EXTRA_SITE_DEFINES) |
| 807 | endif() |
| 808 | |
Eric Fiselier | 5464421 | 2016-09-26 22:19:41 | [diff] [blame] | 809 | # By default libc++ on Windows expects to use a shared library, which requires |
| 810 | # the headers to use DLL import/export semantics. However when building a |
| 811 | # static library only we modify the headers to disable DLL import/export. |
| 812 | if (DEFINED WIN32 AND LIBCXX_ENABLE_STATIC AND NOT LIBCXX_ENABLE_SHARED) |
| 813 | message(STATUS "Generating custom __config for non-DLL Windows build") |
Shoaib Meenai | fc6100c | 2016-12-05 19:40:12 | [diff] [blame] | 814 | config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) |
Eric Fiselier | 5464421 | 2016-09-26 22:19:41 | [diff] [blame] | 815 | endif() |
| 816 | |
Martin Storsjö | 8a73aa8 | 2020-10-23 07:54:02 | [diff] [blame] | 817 | if (WIN32 AND LIBCXX_ENABLE_STATIC_ABI_LIBRARY) |
| 818 | # If linking libcxxabi statically into libcxx, skip the dllimport attributes |
| 819 | # on symbols we refer to from libcxxabi. |
| 820 | add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS) |
| 821 | endif() |
| 822 | |
Louis Dionne | fadc84a | 2019-10-04 22:50:23 | [diff] [blame] | 823 | # Setup all common build flags ================================================= |
| 824 | function(cxx_add_common_build_flags target) |
| 825 | cxx_add_basic_build_flags(${target}) |
Nikolas Klauser | a7aade1 | 2023-02-17 10:31:41 | [diff] [blame] | 826 | cxx_add_warning_flags(${target} ${LIBCXX_ENABLE_WERROR} ${LIBCXX_ENABLE_PEDANTIC}) |
Louis Dionne | fadc84a | 2019-10-04 22:50:23 | [diff] [blame] | 827 | cxx_add_windows_flags(${target}) |
Louis Dionne | fadc84a | 2019-10-04 22:50:23 | [diff] [blame] | 828 | cxx_add_exception_flags(${target}) |
| 829 | cxx_add_rtti_flags(${target}) |
| 830 | cxx_add_module_flags(${target}) |
Louis Dionne | 3230087 | 2019-10-08 16:26:24 | [diff] [blame] | 831 | cxx_link_system_libraries(${target}) |
Louis Dionne | fa712b0 | 2023-11-29 14:29:44 | [diff] [blame] | 832 | target_link_libraries(${target} PRIVATE cxx-sanitizer-flags) |
Louis Dionne | fadc84a | 2019-10-04 22:50:23 | [diff] [blame] | 833 | endfunction() |
| 834 | |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 835 | #=============================================================================== |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 836 | # Setup Source Code And Tests |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 837 | #=============================================================================== |
Louis Dionne | bd135c3 | 2024-05-29 01:31:01 | [diff] [blame] | 838 | add_custom_target(cxx-test-depends |
| 839 | COMMENT "Build dependencies required to run the libc++ test suite.") |
| 840 | |
Howard Hinnant | 6a0d6ce | 2013-11-15 17:18:57 | [diff] [blame] | 841 | add_subdirectory(include) |
Petr Hosek | f80c4b6 | 2019-05-01 06:40:36 | [diff] [blame] | 842 | add_subdirectory(src) |
Louis Dionne | 1f8e286 | 2021-07-15 14:19:39 | [diff] [blame] | 843 | add_subdirectory(utils) |
Mark de Wever | 1d6b613 | 2024-01-21 11:02:39 | [diff] [blame] | 844 | add_subdirectory(modules) |
Eric Fiselier | b17bb06 | 2015-08-22 19:40:49 | [diff] [blame] | 845 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 846 | if (LIBCXX_INCLUDE_TESTS) |
Louis Dionne | eb68a0a | 2020-06-29 15:51:15 | [diff] [blame] | 847 | add_subdirectory(test) |
Eric Fiselier | 28349f9 | 2016-11-14 02:43:12 | [diff] [blame] | 848 | add_subdirectory(lib/abi) |
Zachary Turner | 50105d2 | 2017-09-19 17:19:10 | [diff] [blame] | 849 | endif() |
| 850 | |
Eric Fiselier | b17bb06 | 2015-08-22 19:40:49 | [diff] [blame] | 851 | if (LIBCXX_INCLUDE_DOCS) |
| 852 | add_subdirectory(docs) |
| 853 | endif() |