blob: 95a7d10f055ea70fefc2a2321e7827ab23de35bd [file] [log] [blame]
Michael J. Spencerf5799be2010-12-10 19:47:54 +00001#===============================================================================
2# Setup Project
3#===============================================================================
Mark de Wevercbaa3592023-05-24 18:12:32 +02004cmake_minimum_required(VERSION 3.20.0)
Michael Krusee14f5f22024-05-25 17:41:21 +02005set(LLVM_SUBPROJECT_TITLE "libc++")
Michael J. Spencerf5799be2010-12-10 19:47:54 +00006
John Ericson949bbd02022-01-01 07:03:31 +00007set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
8
Michael J. Spencerf5799be2010-12-10 19:47:54 +00009# Add path for custom modules
John Ericson949bbd02022-01-01 07:03:31 +000010list(INSERT CMAKE_MODULE_PATH 0
Michael J. Spencerf5799be2010-12-10 19:47:54 +000011 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
12 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
Nikolas Klauser0af67d12023-02-20 16:26:19 +010013 "${CMAKE_CURRENT_SOURCE_DIR}/../runtimes/cmake/Modules"
John Ericson949bbd02022-01-01 07:03:31 +000014 "${LLVM_COMMON_CMAKE_UTILS}"
15 "${LLVM_COMMON_CMAKE_UTILS}/Modules"
Michael J. Spencerf5799be2010-12-10 19:47:54 +000016 )
17
Marek Kurdej5e7a93a2021-01-25 09:50:03 +010018set(CMAKE_FOLDER "libc++")
19
Dominik Montada8c03fdf2020-08-24 11:01:05 +020020set(LIBCXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
21set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
Dominik Montada8c03fdf2020-08-24 11:01:05 +020022
John Ericsondf31ff12022-01-19 06:45:07 +000023include(GNUInstallDirs)
Nikolas Klausera7aade12023-02-17 11:31:41 +010024include(WarningFlags)
John Ericsondf31ff12022-01-19 06:45:07 +000025
Saleem Abdulrasool163333f2016-02-08 03:50:18 +000026# Require out of source build.
27include(MacroEnsureOutOfSourceBuild)
28MACRO_ENSURE_OUT_OF_SOURCE_BUILD(
29 "${PROJECT_NAME} requires an out of source build. Please create a separate
30 build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there."
31 )
Eric Fiselier5e0b8fc2018-10-01 01:31:23 +000032if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
33 message(STATUS "Configuring for clang-cl")
34 set(LIBCXX_TARGETING_CLANG_CL ON)
35endif()
Saleem Abdulrasool163333f2016-02-08 03:50:18 +000036
Eric Fiseliercc1f65c2017-01-14 06:06:47 +000037if (MSVC)
Eric Fiselier11edd932018-10-01 01:00:11 +000038 message(STATUS "Configuring for MSVC")
Eric Fiseliercc1f65c2017-01-14 06:06:47 +000039endif()
40
Michael J. Spencerf5799be2010-12-10 19:47:54 +000041#===============================================================================
42# Setup CMake Options
43#===============================================================================
Eric Fiselier309a50a2016-09-07 01:15:10 +000044include(CMakeDependentOption)
Eric Fiselier2aeac462017-03-11 03:24:18 +000045include(HandleCompilerRT)
Michael J. Spencerf5799be2010-12-10 19:47:54 +000046
Eric Fiselier10ed6c32015-07-30 22:30:34 +000047# Basic options ---------------------------------------------------------------
Eric Fiselier10ed6c32015-07-30 22:30:34 +000048option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON)
Petr Hosek9e49a332016-08-08 22:57:25 +000049option(LIBCXX_ENABLE_STATIC "Build libc++ as a static library." ON)
Louis Dionne66a562d2023-05-31 11:20:24 -070050option(LIBCXX_ENABLE_FILESYSTEM
51 "Whether to include support for parts of the library that rely on a filesystem being
52 available on the platform. This includes things like most parts of <filesystem> and
53 others like <fstream>" ON)
Eric Fiselier10ed6c32015-07-30 22:30:34 +000054option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS})
Konstantin Varlamov64d413e2023-11-08 09:10:00 -100055set(LIBCXX_SUPPORTED_HARDENING_MODES none fast extensive debug)
56set(LIBCXX_HARDENING_MODE "none" CACHE STRING
varconstd1367ca2023-07-12 10:12:51 -070057 "Specify the default hardening mode to use. This mode will be used inside the
58 compiled library and will be the default when compiling user code. Note that
59 users can override this setting in their own code. This does not affect the
60 ABI. Supported values are ${LIBCXX_SUPPORTED_HARDENING_MODES}.")
61if (NOT "${LIBCXX_HARDENING_MODE}" IN_LIST LIBCXX_SUPPORTED_HARDENING_MODES)
62 message(FATAL_ERROR
63 "Unsupported hardening mode: '${LIBCXX_HARDENING_MODE}'. Supported values are ${LIBCXX_SUPPORTED_HARDENING_MODES}.")
64endif()
Konstantin Varlamov8dfc67d2024-01-17 18:56:07 -080065set(LIBCXX_ASSERTION_HANDLER_FILE
Louis Dionne046a1772024-07-24 11:03:52 -050066 "vendor/llvm/default_assertion_handler.in"
Konstantin Varlamov8dfc67d2024-01-17 18:56:07 -080067 CACHE STRING
68 "Specify the path to a header that contains a custom implementation of the
69 assertion handler that gets invoked when a hardening assertion fails. If
70 provided, this header will be included by the library, replacing the
Louis Dionne046a1772024-07-24 11:03:52 -050071 default assertion handler. If this is specified as a relative path, it
72 is assumed to be relative to '<monorepo>/libcxx'.")
73if (NOT IS_ABSOLUTE "${LIBCXX_ASSERTION_HANDLER_FILE}")
74 set(LIBCXX_ASSERTION_HANDLER_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${LIBCXX_ASSERTION_HANDLER_FILE}")
75endif()
Louis Dionnee0d01292020-10-15 10:32:09 -040076option(LIBCXX_ENABLE_RANDOM_DEVICE
77 "Whether to include support for std::random_device in the library. Disabling
78 this can be useful when building the library for platforms that don't have
79 a source of randomness, such as some embedded platforms. When this is not
80 supported, most of <random> will still be available, but std::random_device
81 will not." ON)
Louis Dionne88ffc722020-10-09 15:31:05 -040082option(LIBCXX_ENABLE_LOCALIZATION
83 "Whether to include support for localization in the library. Disabling
84 localization can be useful when porting to platforms that don't support
85 the C locale API (e.g. embedded). When localization is not supported,
86 several parts of the library will be disabled: <iostream>, <regex>, <locale>
87 will be completely unusable, and other parts may be only partly available." ON)
Mark de Weverdf2af992021-05-25 20:11:08 +020088option(LIBCXX_ENABLE_UNICODE
89 "Whether to include support for Unicode in the library. Disabling Unicode can
Louis Dionnecf765b12021-09-09 11:14:33 -040090 be useful when porting to platforms that don't support UTF-8 encoding (e.g.
91 embedded)." ON)
Joseph Huber7ad7f8f2024-08-21 08:48:53 -050092option(LIBCXX_HAS_TERMINAL_AVAILABLE
93 "Build libc++ with support for checking whether a stream is a terminal." ON)
Louis Dionnef4c12582021-08-23 15:32:36 -040094option(LIBCXX_ENABLE_WIDE_CHARACTERS
95 "Whether to include support for wide characters in the library. Disabling
96 wide character support can be useful when porting to platforms that don't
97 support the C functionality for wide characters. When wide characters are
98 not supported, several parts of the library will be disabled, notably the
99 wide character specializations of std::basic_string." ON)
Mark de Weverf78f93b2022-09-23 18:33:20 +0200100
101# To use time zone support in libc++ the platform needs to have the IANA
102# database installed. Libc++ will fail to build if this is enabled on a
103# platform that does not provide the IANA database. The default is set to the
104# current implementation state on the different platforms.
105#
106# TODO TZDB make the default always ON when most platforms ship with the IANA
107# database.
108if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
109 set(ENABLE_TIME_ZONE_DATABASE_DEFAULT ON)
110else()
111 set(ENABLE_TIME_ZONE_DATABASE_DEFAULT OFF)
112endif()
113option(LIBCXX_ENABLE_TIME_ZONE_DATABASE
114 "Whether to include support for time zones in the library. Disabling
115 time zone support can be useful when porting to platforms that don't
116 ship the IANA time zone database. When time zones are not supported,
117 time zone support in <chrono> will be disabled." ${ENABLE_TIME_ZONE_DATABASE_DEFAULT})
Louis Dionne2eadbc82020-11-04 15:01:25 -0500118option(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS
119 "Whether to turn on vendor availability annotations on declarations that depend
120 on definitions in a shared library. By default, we assume that we're not building
121 libc++ for any specific vendor, and we disable those annotations. Vendors wishing
122 to provide compile-time errors when using features unavailable on some version of
Louis Dionne04f01a22024-05-28 18:29:11 -0700123 the shared library they shipped should turn this on and see `include/__configuration/availability.h`
Louis Dionne2eadbc82020-11-04 15:01:25 -0500124 for more details." OFF)
Louis Dionned0af4272022-03-14 14:23:38 -0400125
126if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
127 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-gcc.cfg.in")
128elseif(MINGW)
Martin Storsjö9fb23782024-10-10 09:13:47 +0300129 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-mingw.cfg.in")
Louis Dionned0af4272022-03-14 14:23:38 -0400130elseif(WIN32) # clang-cl
131 if (LIBCXX_ENABLE_SHARED)
132 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-clangcl.cfg.in")
133 else()
134 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-static-clangcl.cfg.in")
135 endif()
136else()
137 if (LIBCXX_ENABLE_SHARED)
138 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared.cfg.in")
139 else()
140 set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-static.cfg.in")
141 endif()
142endif()
143set(LIBCXX_TEST_CONFIG "${LIBCXX_DEFAULT_TEST_CONFIG}" CACHE STRING
Louis Dionne54a8a0d2021-09-29 15:26:05 -0400144 "The path to the Lit testing configuration to use when running the tests.
145 If a relative path is provided, it is assumed to be relative to '<monorepo>/libcxx/test/configs'.")
146if (NOT IS_ABSOLUTE "${LIBCXX_TEST_CONFIG}")
147 set(LIBCXX_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/configs/${LIBCXX_TEST_CONFIG}")
148endif()
Louis Dionned0af4272022-03-14 14:23:38 -0400149message(STATUS "Using libc++ testing configuration: ${LIBCXX_TEST_CONFIG}")
Louis Dionne6f693182020-07-09 11:54:09 -0400150set(LIBCXX_TEST_PARAMS "" CACHE STRING
151 "A list of parameters to run the Lit test suite with.")
Eric Fiselier3aa54782016-10-30 22:53:00 +0000152
Eric Fiselier3aa54782016-10-30 22:53:00 +0000153# Benchmark options -----------------------------------------------------------
Louis Dionne95530082018-09-22 21:30:12 +0000154option(LIBCXX_INCLUDE_BENCHMARKS "Build the libc++ benchmarks and their dependencies" ON)
Eric Fiselier336a1a62018-11-14 20:38:46 +0000155
156set(LIBCXX_BENCHMARK_TEST_ARGS_DEFAULT --benchmark_min_time=0.01)
157set(LIBCXX_BENCHMARK_TEST_ARGS "${LIBCXX_BENCHMARK_TEST_ARGS_DEFAULT}" CACHE STRING
158 "Arguments to pass when running the benchmarks using check-cxx-benchmarks")
159
Eric Fiselierb17bb062015-08-22 19:40:49 +0000160option(LIBCXX_INCLUDE_DOCS "Build the libc++ documentation." ${LLVM_INCLUDE_DOCS})
John Ericsone941b032022-08-18 22:44:46 -0400161set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
162 "Define suffix of library directory name (32/64)")
Eric Fiselier10ed6c32015-07-30 22:30:34 +0000163option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON)
Eric Fiselierd77135f2015-08-26 20:18:21 +0000164option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON)
Mark de Wever8b47bb62024-01-21 12:16:22 +0100165option(LIBCXX_INSTALL_MODULES
Mark de Wever19d2d3f2024-04-28 14:12:27 +0200166 "Install the libc++ C++20 module source files (experimental)." ON
Mark de Wever8b47bb62024-01-21 12:16:22 +0100167)
Petr Hosek4a1e14e2018-07-24 23:27:51 +0000168cmake_dependent_option(LIBCXX_INSTALL_STATIC_LIBRARY
169 "Install the static libc++ library." ON
170 "LIBCXX_ENABLE_STATIC;LIBCXX_INSTALL_LIBRARY" OFF)
171cmake_dependent_option(LIBCXX_INSTALL_SHARED_LIBRARY
172 "Install the shared libc++ library." ON
173 "LIBCXX_ENABLE_SHARED;LIBCXX_INSTALL_LIBRARY" OFF)
Eric Fiselier998a5c82018-07-27 03:07:09 +0000174
Louis Dionne817d8972022-02-07 14:52:17 -0500175option(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)
176if (LIBCXX_ABI_UNSTABLE)
177 set(abi_version "2")
178else()
179 set(abi_version "1")
180endif()
Louis Dionne6de59ca2022-05-16 09:50:56 -0400181set(LIBCXX_ABI_VERSION "${abi_version}" CACHE STRING
182 "ABI version of libc++. Can be either 1 or 2, where 2 is currently the unstable ABI.
183 Defaults to 1 unless LIBCXX_ABI_UNSTABLE is specified, in which case this is 2.")
184set(LIBCXX_LIBRARY_VERSION "${LIBCXX_ABI_VERSION}.0" CACHE STRING
185 "Version of libc++. This will be reflected in the name of the shared library produced.
186 For example, -DLIBCXX_LIBRARY_VERSION=x.y will result in the library being named
187 libc++.x.y.dylib, along with the usual symlinks pointing to that. On Apple platforms,
188 this also controls the linker's 'current_version' property.")
Louis Dionne817d8972022-02-07 14:52:17 -0500189set(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.")
190if (NOT LIBCXX_ABI_NAMESPACE MATCHES "__.*")
Florian Mayer4110c2c2022-06-09 08:49:03 -0700191 message(FATAL_ERROR "LIBCXX_ABI_NAMESPACE must be a reserved identifier, got '${LIBCXX_ABI_NAMESPACE}'.")
Louis Dionne817d8972022-02-07 14:52:17 -0500192endif()
Shoaib Meenaia4a3d402017-10-05 02:18:08 +0000193option(LIBCXX_ABI_FORCE_ITANIUM "Ignore auto-detection and force use of the Itanium ABI.")
194option(LIBCXX_ABI_FORCE_MICROSOFT "Ignore auto-detection and force use of the Microsoft ABI.")
Eric Fiselier2405bd62019-05-29 02:21:37 +0000195
Louis Dionnebe00e882020-11-16 18:13:43 -0500196set(LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION "default" CACHE STRING
197 "Override the implementation to use for comparing typeinfos. By default, this
198 is detected automatically by the library, but this option allows overriding
199 which implementation is used unconditionally.
Eric Fiselier2405bd62019-05-29 02:21:37 +0000200
Louis Dionnebe00e882020-11-16 18:13:43 -0500201 See the documentation in <libcxx/include/typeinfo> for details on what each
202 value means.")
203set(TYPEINFO_COMPARISON_VALUES "default;1;2;3")
204if (NOT ("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" IN_LIST TYPEINFO_COMPARISON_VALUES))
Louis Dionned0fcdcd2020-05-15 15:58:19 -0400205 message(FATAL_ERROR "Value '${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}' is not a valid value for
Louis Dionnebe00e882020-11-16 18:13:43 -0500206 LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION")
Eric Fiselier2405bd62019-05-29 02:21:37 +0000207endif()
208
Shoaib Meenai89937532017-10-04 23:51:57 +0000209set(LIBCXX_ABI_DEFINES "" CACHE STRING "A semicolon separated list of ABI macros to define in the site config header.")
Louis Dionne760261a2023-08-14 18:14:02 -0400210set(LIBCXX_EXTRA_SITE_DEFINES "" CACHE STRING "Extra defines to add into __config_site")
Saleem Abdulrasoole81fcb82016-08-24 04:22:52 +0000211option(LIBCXX_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
Eric Fiselier10ed6c32015-07-30 22:30:34 +0000212
Petr Hosek3b78dfa2024-07-18 22:17:42 -0700213# C Library options -----------------------------------------------------------
214
215set(LIBCXX_SUPPORTED_C_LIBRARIES system llvm-libc)
216set(LIBCXX_LIBC "system" CACHE STRING "Specify C library to use. Supported values are ${LIBCXX_SUPPORTED_C_LIBRARIES}.")
217if (NOT "${LIBCXX_LIBC}" IN_LIST LIBCXX_SUPPORTED_C_LIBRARIES)
218 message(FATAL_ERROR "Unsupported C library: '${LIBCXX_CXX_ABI}'. Supported values are ${LIBCXX_SUPPORTED_C_LIBRARIES}.")
219endif()
220
Eric Fiselier10ed6c32015-07-30 22:30:34 +0000221# ABI Library options ---------------------------------------------------------
David Spickett43cfc782023-07-07 09:55:36 +0000222if (MSVC)
Louis Dionnea80e65e2022-03-01 08:42:13 -0500223 set(LIBCXX_DEFAULT_ABI_LIBRARY "vcruntime")
Eugene Zelenko772d1142016-08-08 18:01:50 +0000224else()
Louis Dionnea80e65e2022-03-01 08:42:13 -0500225 set(LIBCXX_DEFAULT_ABI_LIBRARY "libcxxabi")
226endif()
227
228set(LIBCXX_SUPPORTED_ABI_LIBRARIES none libcxxabi system-libcxxabi libcxxrt libstdc++ libsupc++ vcruntime)
229set(LIBCXX_CXX_ABI "${LIBCXX_DEFAULT_ABI_LIBRARY}" CACHE STRING "Specify C++ ABI library to use. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}.")
Louis Dionnea80e65e2022-03-01 08:42:13 -0500230if (NOT "${LIBCXX_CXX_ABI}" IN_LIST LIBCXX_SUPPORTED_ABI_LIBRARIES)
231 message(FATAL_ERROR "Unsupported C++ ABI library: '${LIBCXX_CXX_ABI}'. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}.")
Eugene Zelenko772d1142016-08-08 18:01:50 +0000232endif()
Eric Fiselierbb906852015-10-22 20:54:27 +0000233
Louis Dionne0c962cb2019-03-18 18:18:01 +0000234option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY
235 "Use a static copy of the ABI library when linking libc++.
236 This option cannot be used with LIBCXX_ENABLE_ABI_LINKER_SCRIPT." OFF)
Eric Fiselier10ed6c32015-07-30 22:30:34 +0000237
Nikita Popove911ece2022-09-26 15:42:35 +0200238option(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY
239 "Statically link the ABI library to static library"
240 ${LIBCXX_ENABLE_STATIC_ABI_LIBRARY})
Petr Hosek058c04c2018-07-24 07:06:17 +0000241
Nikita Popove911ece2022-09-26 15:42:35 +0200242option(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY
243 "Statically link the ABI library to shared library"
244 ${LIBCXX_ENABLE_STATIC_ABI_LIBRARY})
Petr Hosek058c04c2018-07-24 07:06:17 +0000245
Eric Fiselier82414052015-10-14 19:54:03 +0000246# Generate and install a linker script inplace of libc++.so. The linker script
Eric Fiselier1ab69fc2015-10-15 22:41:51 +0000247# will link libc++ to the correct ABI library. This option is on by default
Haowei1f8f9e32023-12-01 12:37:04 -0800248# on UNIX platforms other than Apple, and on the Fuchsia platform unless we
249# statically link libc++abi inside libc++.so, we don't build libc++.so at all
250# or we don't have any ABI library.
Louis Dionne4b1fe092023-11-23 05:15:03 -1000251if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY
252 OR NOT LIBCXX_ENABLE_SHARED
253 OR LIBCXX_CXX_ABI STREQUAL "none")
254 set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF)
Haowei1f8f9e32023-12-01 12:37:04 -0800255elseif((UNIX OR FUCHSIA) AND NOT APPLE)
Louis Dionne4b1fe092023-11-23 05:15:03 -1000256 set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE ON)
257else()
258 set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF)
Eric Fiselier1ab69fc2015-10-15 22:41:51 +0000259endif()
Eric Fiselier82414052015-10-14 19:54:03 +0000260option(LIBCXX_ENABLE_ABI_LINKER_SCRIPT
Eric Fiselier1ab69fc2015-10-15 22:41:51 +0000261 "Use and install a linker script for the given ABI library"
Eric Fiseliera15785b2015-10-15 23:04:54 +0000262 ${ENABLE_LINKER_SCRIPT_DEFAULT_VALUE})
Eric Fiselier82414052015-10-14 19:54:03 +0000263
Eric Fiselier34992632017-03-02 19:35:33 +0000264option(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS
Louis Dionne9b40ee82019-10-01 09:34:58 -0400265 "Build libc++ with definitions for operator new/delete. These are normally
266 defined in libc++abi, but this option can be used to define them in libc++
267 instead. If you define them in libc++, make sure they are NOT defined in
268 libc++abi. Doing otherwise is an ODR violation." OFF)
Eric Fiselier10ed6c32015-07-30 22:30:34 +0000269# Build libc++abi with libunwind. We need this option to determine whether to
270# link with libunwind or libgcc_s while running the test cases.
Louis Dionne8f90e692024-01-11 10:13:21 -0500271option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." ON)
Eric Fiselier10ed6c32015-07-30 22:30:34 +0000272
273# Target options --------------------------------------------------------------
Louis Dionnefa1c0772021-11-23 16:34:09 -0500274option(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})
275if (LIBCXX_BUILD_32_BITS)
Louis Dionnedc1244d2021-12-01 12:57:30 -0500276 message(FATAL_ERROR "LIBCXX_BUILD_32_BITS is not supported anymore when building the runtimes, please specify a full triple instead.")
Louis Dionnefa1c0772021-11-23 16:34:09 -0500277endif()
Louis Dionne72117f22021-10-12 15:59:08 -0400278
Eric Fiselier10ed6c32015-07-30 22:30:34 +0000279# Feature options -------------------------------------------------------------
Michael J. Spencerf5799be2010-12-10 19:47:54 +0000280option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON)
Mark de Wevered210f92023-12-12 17:11:53 +0100281option(LIBCXX_ENABLE_RTTI
282 "Use runtime type information.
283 This option may only be set to OFF when LIBCXX_ENABLE_EXCEPTIONS=OFF." ON)
Eric Fiselierb9f99732014-12-06 21:02:58 +0000284option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON)
285option(LIBCXX_ENABLE_MONOTONIC_CLOCK
286 "Build libc++ with support for a monotonic clock.
Jonathan Roelofs91b3a5e2015-08-24 21:20:07 +0000287 This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON)
Vasileios Kalintiris8c58e922015-11-09 10:21:04 +0000288option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF)
Ben Craigb9599b12016-05-25 17:40:09 +0000289option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF)
Martin Storsjobf02a092018-01-05 20:48:29 +0000290option(LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32 thread API" OFF)
Asiri Rathnayake8c2bf452016-09-11 21:46:40 +0000291option(LIBCXX_HAS_EXTERNAL_THREAD_API
292 "Build libc++ with an externalized threading API.
293 This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF)
Eric Fiselier10ed6c32015-07-30 22:30:34 +0000294
Nikolas Klausere837f4b2023-05-24 15:33:38 -0700295if (LIBCXX_ENABLE_THREADS)
Louis Dionned423d802024-04-17 13:36:53 -0400296 set(LIBCXX_PSTL_BACKEND "std_thread" CACHE STRING "Which PSTL backend to use")
Nikolas Klausere837f4b2023-05-24 15:33:38 -0700297else()
Louis Dionned423d802024-04-17 13:36:53 -0400298 set(LIBCXX_PSTL_BACKEND "serial" CACHE STRING "Which PSTL backend to use")
Nikolas Klausere837f4b2023-05-24 15:33:38 -0700299endif()
300
Eric Fiselier10ed6c32015-07-30 22:30:34 +0000301# Misc options ----------------------------------------------------------------
Eric Fiselier6fb770a2015-10-10 03:34:52 +0000302# FIXME: Turn -pedantic back ON. It is currently off because it warns
303# about #include_next which is used everywhere.
304option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF)
Eric Fiselier10ed6c32015-07-30 22:30:34 +0000305option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
306
Martin Storsjöbedf6572022-04-09 23:40:07 +0300307set(LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT OFF)
308if (WIN32)
309 set(LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT ON)
310endif()
Petr Hoseka2685cd2019-01-06 06:14:31 +0000311option(LIBCXX_HERMETIC_STATIC_LIBRARY
Martin Storsjöbedf6572022-04-09 23:40:07 +0300312 "Do not export any symbols from the static library." ${LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT})
Petr Hoseka2685cd2019-01-06 06:14:31 +0000313
Eric Fiselier10ed6c32015-07-30 22:30:34 +0000314#===============================================================================
315# Check option configurations
316#===============================================================================
317
318# Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON only when
319# LIBCXX_ENABLE_THREADS is on.
320if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_ENABLE_MONOTONIC_CLOCK)
321 message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF"
322 " when LIBCXX_ENABLE_THREADS is also set to OFF.")
Eric Fiselier0058c802014-08-18 05:03:46 +0000323endif()
Michael J. Spencerf5799be2010-12-10 19:47:54 +0000324
Asiri Rathnayake205d7d32017-01-03 12:59:50 +0000325if(NOT LIBCXX_ENABLE_THREADS)
326 if(LIBCXX_HAS_PTHREAD_API)
327 message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON"
328 " when LIBCXX_ENABLE_THREADS is also set to ON.")
329 endif()
330 if(LIBCXX_HAS_EXTERNAL_THREAD_API)
331 message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set to ON"
332 " when LIBCXX_ENABLE_THREADS is also set to ON.")
333 endif()
Martin Storsjobf02a092018-01-05 20:48:29 +0000334 if (LIBCXX_HAS_WIN32_THREAD_API)
335 message(FATAL_ERROR "LIBCXX_HAS_WIN32_THREAD_API can only be set to ON"
336 " when LIBCXX_ENABLE_THREADS is also set to ON.")
337 endif()
Eric Fiselier00f6bea2017-01-06 20:05:40 +0000338
339endif()
340
Asiri Rathnayakeb71c8992017-01-09 10:38:56 +0000341if (LIBCXX_HAS_EXTERNAL_THREAD_API)
Asiri Rathnayakeb71c8992017-01-09 10:38:56 +0000342 if (LIBCXX_HAS_PTHREAD_API)
343 message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
Mark de Wever0735a6e2023-09-06 20:54:43 +0200344 " and LIBCXX_HAS_PTHREAD_API cannot be both"
345 " set to ON at the same time.")
Asiri Rathnayakeb71c8992017-01-09 10:38:56 +0000346 endif()
Martin Storsjobf02a092018-01-05 20:48:29 +0000347 if (LIBCXX_HAS_WIN32_THREAD_API)
348 message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
Mark de Wever0735a6e2023-09-06 20:54:43 +0200349 " and LIBCXX_HAS_WIN32_THREAD_API cannot be both"
350 " set to ON at the same time.")
Martin Storsjobf02a092018-01-05 20:48:29 +0000351 endif()
352endif()
353
354if (LIBCXX_HAS_PTHREAD_API)
355 if (LIBCXX_HAS_WIN32_THREAD_API)
356 message(FATAL_ERROR "The options LIBCXX_HAS_PTHREAD_API"
Mark de Wever0735a6e2023-09-06 20:54:43 +0200357 " and LIBCXX_HAS_WIN32_THREAD_API cannot be both"
358 " set to ON at the same time.")
Martin Storsjobf02a092018-01-05 20:48:29 +0000359 endif()
Asiri Rathnayake8c2bf452016-09-11 21:46:40 +0000360endif()
361
Mark de Wevered210f92023-12-12 17:11:53 +0100362if (NOT LIBCXX_ENABLE_RTTI AND LIBCXX_ENABLE_EXCEPTIONS)
363 message(FATAL_ERROR "Libc++ cannot be built with exceptions enabled but RTTI"
364 " disabled, since that configuration is broken. See"
365 " https://github.com/llvm/llvm-project/issues/66117"
366 " for details.")
367endif()
368
Eric Fiselier82414052015-10-14 19:54:03 +0000369if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
370 if (APPLE)
371 message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT cannot be used on APPLE targets")
372 endif()
Asiri Rathnayake28383a42016-05-14 23:58:11 +0000373 if (NOT LIBCXX_ENABLE_SHARED)
374 message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT is only available for shared library builds.")
375 endif()
Eric Fiselier82414052015-10-14 19:54:03 +0000376endif()
377
Petr Hosek4b59ed42018-07-26 05:10:24 +0000378if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
Eric Fiselier82414052015-10-14 19:54:03 +0000379 message(FATAL_ERROR "Conflicting options given.
Nikita Popove911ece2022-09-26 15:42:35 +0200380 LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY cannot be specified with
Eric Fiselier82414052015-10-14 19:54:03 +0000381 LIBCXX_ENABLE_ABI_LINKER_SCRIPT")
382endif()
383
Shoaib Meenaia4a3d402017-10-05 02:18:08 +0000384if (LIBCXX_ABI_FORCE_ITANIUM AND LIBCXX_ABI_FORCE_MICROSOFT)
385 message(FATAL_ERROR "Only one of LIBCXX_ABI_FORCE_ITANIUM and LIBCXX_ABI_FORCE_MICROSOFT can be specified.")
Shoaib Meenaid4563852017-10-04 23:44:38 +0000386endif ()
387
Martin Storsjöe777e442023-07-17 12:52:47 +0300388if (LIBCXX_ENABLE_SHARED AND CMAKE_MSVC_RUNTIME_LIBRARY AND
389 (NOT CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL$"))
390 message(WARNING "A static CRT linked into a shared libc++ doesn't work correctly.")
391endif()
392
Michael J. Spencerf5799be2010-12-10 19:47:54 +0000393#===============================================================================
394# Configure System
395#===============================================================================
396
Louis Dionnec06a8f92020-06-26 12:08:59 -0400397# TODO: Projects that depend on libc++ should use LIBCXX_GENERATED_INCLUDE_DIR
398# instead of hard-coding include/c++/v1.
John Ericson0a8d15a2022-01-11 03:03:21 +0000399
Louis Dionne760261a2023-08-14 18:14:02 -0400400set(LIBCXX_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/c++/v1" CACHE STRING
John Ericson0a8d15a2022-01-11 03:03:21 +0000401 "Path where target-agnostic libc++ headers should be installed.")
Louis Dionne760261a2023-08-14 18:14:02 -0400402set(LIBCXX_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING
John Ericson0a8d15a2022-01-11 03:03:21 +0000403 "Path where built libc++ runtime libraries should be installed.")
Mark de Wever8b47bb62024-01-21 12:16:22 +0100404set(LIBCXX_INSTALL_MODULES_DIR "share/libc++/v1" CACHE STRING
405 "Path where target-agnostic libc++ module source files should be installed.")
John Ericson0a8d15a2022-01-11 03:03:21 +0000406
Louis Dionne10378b32022-10-11 10:05:56 -0400407set(LIBCXX_SHARED_OUTPUT_NAME "c++" CACHE STRING "Output name for the shared libc++ runtime library.")
408set(LIBCXX_STATIC_OUTPUT_NAME "c++" CACHE STRING "Output name for the static libc++ runtime library.")
Zibi Sarbinowski36dde912022-10-03 16:41:58 -0500409
Petr Hosek887f26d2018-06-28 03:11:52 +0000410if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
Petr Hoseked155f32024-05-31 11:48:45 -0700411 set(LIBCXX_TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE})
412 if(LIBCXX_LIBDIR_SUBDIR)
413 string(APPEND LIBCXX_TARGET_SUBDIR /${LIBCXX_LIBDIR_SUBDIR})
414 endif()
415 set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LIBCXX_TARGET_SUBDIR})
Louis Dionnec06a8f92020-06-26 12:08:59 -0400416 set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
Mark de Wever9b08c8a2023-02-28 20:29:26 +0100417 set(LIBCXX_GENERATED_MODULE_DIR "${LLVM_BINARY_DIR}/modules/c++/v1")
Petr Hoseked155f32024-05-31 11:48:45 -0700418 set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LIBCXX_TARGET_SUBDIR}/c++/v1")
419 set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LIBCXX_TARGET_SUBDIR} CACHE STRING
John Ericson1e03c372021-04-28 22:36:47 +0000420 "Path where built libc++ libraries should be installed.")
Petr Hoseked155f32024-05-31 11:48:45 -0700421 set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${LIBCXX_TARGET_SUBDIR}/c++/v1" CACHE STRING
John Ericson1e03c372021-04-28 22:36:47 +0000422 "Path where target-specific libc++ headers should be installed.")
Petr Hoseked155f32024-05-31 11:48:45 -0700423 unset(LIBCXX_TARGET_SUBDIR)
Jonas Hahnfeld98a7f272017-05-04 06:02:50 +0000424else()
John Ericson0a8d15a2022-01-11 03:03:21 +0000425 if(LLVM_LIBRARY_OUTPUT_INTDIR)
426 set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
427 set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
Mark de Wever9b08c8a2023-02-28 20:29:26 +0100428 set(LIBCXX_GENERATED_MODULE_DIR "${LLVM_BINARY_DIR}/modules/c++/v1")
John Ericson0a8d15a2022-01-11 03:03:21 +0000429 else()
John Ericsone941b032022-08-18 22:44:46 -0400430 set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
John Ericson0a8d15a2022-01-11 03:03:21 +0000431 set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1")
Mark de Wever9b08c8a2023-02-28 20:29:26 +0100432 set(LIBCXX_GENERATED_MODULE_DIR "${CMAKE_BINARY_DIR}/modules/c++/v1")
John Ericson0a8d15a2022-01-11 03:03:21 +0000433 endif()
Petr Hosekea12d772020-07-15 14:10:56 -0700434 set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}")
Louis Dionne760261a2023-08-14 18:14:02 -0400435 set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX} CACHE STRING
John Ericson1e03c372021-04-28 22:36:47 +0000436 "Path where built libc++ libraries should be installed.")
Louis Dionne760261a2023-08-14 18:14:02 -0400437 set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${LIBCXX_INSTALL_INCLUDE_DIR}" CACHE STRING
John Ericson1e03c372021-04-28 22:36:47 +0000438 "Path where target-specific libc++ headers should be installed.")
Jonas Hahnfeld98a7f272017-05-04 06:02:50 +0000439endif()
Petr Hosek887f26d2018-06-28 03:11:52 +0000440
Eric Fiselier10ed6c32015-07-30 22:30:34 +0000441set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
442set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
Shoaib Meenai61707652017-04-13 16:27:38 +0000443set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
Eric Fiselier10ed6c32015-07-30 22:30:34 +0000444
Eric Fiselier5aedca92014-11-15 06:26:30 +0000445# Declare libc++ configuration variables.
446# They are intended for use as follows:
447# LIBCXX_CXX_FLAGS: General flags for both the compiler and linker.
448# LIBCXX_COMPILE_FLAGS: Compile only flags.
449# LIBCXX_LINK_FLAGS: Linker only flags.
Eric Fiselier054fc4c2016-10-09 21:34:03 +0000450# LIBCXX_LIBRARIES: libraries libc++ is linked to.
Eric Fiselier5aedca92014-11-15 06:26:30 +0000451set(LIBCXX_COMPILE_FLAGS "")
452set(LIBCXX_LINK_FLAGS "")
Eric Fiselier10ed6c32015-07-30 22:30:34 +0000453set(LIBCXX_LIBRARIES "")
Zibi Sarbinowski36dde912022-10-03 16:41:58 -0500454set(LIBCXX_ADDITIONAL_COMPILE_FLAGS "" CACHE STRING
Louis Dionnee6744242024-10-17 16:17:40 -0400455 "Additional compile flags to use when building libc++. This should be a CMake ;-delimited list of individual
456 compiler options to use. For options that must be passed as-is to the compiler without deduplication (e.g.
457 `-Xclang -foo` option groups), consider using `SHELL:` (https://cmake.org/cmake/help/latest/command/add_compile_options.html#option-de-duplication).")
Zibi Sarbinowski36dde912022-10-03 16:41:58 -0500458set(LIBCXX_ADDITIONAL_LIBRARIES "" CACHE STRING
459 "Additional libraries libc++ is linked to which can be provided in cache")
Eric Fiselier5aedca92014-11-15 06:26:30 +0000460
Eric Fiseliera4f24602016-06-02 01:10:08 +0000461# Include macros for adding and removing libc++ flags.
462include(HandleLibcxxFlags)
463
464# Target flags ================================================================
465# These flags get added to CMAKE_CXX_FLAGS and CMAKE_C_FLAGS so that
466# 'config-ix' use them during feature checks. It also adds them to both
467# 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS'
Petr Hosek6fd4e7f2019-02-04 20:02:26 +0000468
Jake Egan1cf41132022-06-13 21:44:58 -0400469if (${CMAKE_SYSTEM_NAME} MATCHES "AIX")
Nikolas Klauserd0e95fe2023-02-20 16:47:34 +0100470 add_flags_if_supported("-mdefault-visibility-export-mapping=explicit")
Jake Egan1cf41132022-06-13 21:44:58 -0400471 set(CMAKE_AIX_EXPORT_ALL_SYMBOLS OFF)
472endif()
473
Eric Fiselier382338d2014-11-15 17:25:23 +0000474# Configure compiler.
475include(config-ix)
Eric Fiselier10ed6c32015-07-30 22:30:34 +0000476
Eric Fiselier382338d2014-11-15 17:25:23 +0000477#===============================================================================
478# Setup Compiler Flags
479#===============================================================================
480
Petr Hosek3b78dfa2024-07-18 22:17:42 -0700481include(HandleLibC) # Setup the C library flags
JF Bastienfc45f322016-03-05 14:22:02 +0000482include(HandleLibCXXABI) # Setup the ABI library flags
Eric Fiselier10ed6c32015-07-30 22:30:34 +0000483
Shoaib Meenaif88923d2017-03-25 03:42:20 +0000484# FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC.
Eric Fiselierf2be7c22015-10-15 20:27:15 +0000485# Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors
Shoaib Meenaif88923d2017-03-25 03:42:20 +0000486# so they don't get transformed into -Wno and -errors respectively.
Eric Fiselierf2be7c22015-10-15 20:27:15 +0000487remove_flags(-Wno-pedantic -pedantic-errors -pedantic)
Eric Fiselierf4bfd7c2015-10-13 23:56:33 +0000488
Eric Fiselier10ed6c32015-07-30 22:30:34 +0000489# Required flags ==============================================================
Louis Dionne925d9d22019-10-02 20:07:01 +0000490function(cxx_add_basic_build_flags target)
Eric Fiselier72b41e62019-12-11 20:26:30 -0500491
Louis Dionne8a7846f2023-11-05 08:40:51 -0500492 # Use C++23 for all targets.
Eric Fiselier72b41e62019-12-11 20:26:30 -0500493 set_target_properties(${target} PROPERTIES
Louis Dionne8a7846f2023-11-05 08:40:51 -0500494 CXX_STANDARD 23
Louis Dionnef97a5792023-11-16 14:58:36 -0500495 CXX_STANDARD_REQUIRED OFF # TODO: Make this REQUIRED once we don't need to accommodate the LLVM documentation builders using an ancient CMake
Eric Fiselier72b41e62019-12-11 20:26:30 -0500496 CXX_EXTENSIONS NO)
Eric Fiselier10ed6c32015-07-30 22:30:34 +0000497
Louis Dionne918ba932020-07-23 11:05:47 -0400498 # When building the dylib, don't warn for unavailable aligned allocation
499 # functions based on the deployment target -- they are always available
Gabriel Ravierc23e2c02022-08-02 12:42:04 +0200500 # because they are provided by the dylib itself with the exception of z/OS.
Zbigniew Sarbinowskiaa8a5b82020-11-12 14:40:35 -0500501 if (ZOS)
502 target_add_compile_flags_if_supported(${target} PRIVATE -fno-aligned-allocation)
503 else()
504 target_add_compile_flags_if_supported(${target} PRIVATE -faligned-allocation)
505 endif()
Louis Dionne918ba932020-07-23 11:05:47 -0400506
Louis Dionne925d9d22019-10-02 20:07:01 +0000507 # On all systems the system c++ standard library headers need to be excluded.
508 # MSVC only has -X, which disables all default includes; including the crt.
509 # Thus, we do nothing and hope we don't accidentally include any of the C++
510 # headers
511 target_add_compile_flags_if_supported(${target} PUBLIC -nostdinc++)
Eric Fiselierff16b9a2015-07-29 21:07:28 +0000512
Louis Dionne925d9d22019-10-02 20:07:01 +0000513 # Hide all inline function definitions which have not explicitly been marked
514 # visible. This prevents new definitions for inline functions from appearing in
515 # the dylib when get ODR used by another function.
516 target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility-inlines-hidden)
Eric Fiselier10b12f02016-10-25 19:43:44 +0000517
Louis Dionne925d9d22019-10-02 20:07:01 +0000518 # Our visibility annotations are not quite right for non-Clang compilers,
519 # so we end up not exporting all the symbols we should. In the future, we
520 # can improve the situation by providing an explicit list of exported
521 # symbols on all compilers.
522 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
523 target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility=hidden)
524 endif()
Eric Fiselier3ca91852017-05-25 04:36:24 +0000525
Louis Dionned2864d12024-06-24 17:26:03 -0400526 # Build with -fsized-deallocation, which is default in recent versions of Clang.
527 # TODO(LLVM 21): This can be dropped once we only support Clang >= 19.
528 target_add_compile_flags_if_supported(${target} PRIVATE -fsized-deallocation)
529
Louis Dionne925d9d22019-10-02 20:07:01 +0000530 # Let the library headers know they are currently being used to build the
531 # library.
532 target_compile_definitions(${target} PRIVATE -D_LIBCPP_BUILDING_LIBRARY)
Eric Fiselier34992632017-03-02 19:35:33 +0000533
Mark de Weverc4162342023-03-10 17:31:58 +0100534 # Make sure the library can be build without transitive includes. This makes
535 # it easier to upgrade the library to a newer language standard without build
536 # errors.
537 target_compile_definitions(${target} PRIVATE -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
538
Petr Hosekb3df14b2022-03-10 11:47:09 +0200539 if (C_SUPPORTS_COMMENT_LIB_PRAGMA)
Michał Górnya9b5fff2019-12-02 11:49:20 +0100540 if (LIBCXX_HAS_PTHREAD_LIB)
541 target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_PTHREAD_LIB)
542 endif()
543 if (LIBCXX_HAS_RT_LIB)
544 target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_RT_LIB)
545 endif()
Louis Dionne925d9d22019-10-02 20:07:01 +0000546 endif()
Zibi Sarbinowski36dde912022-10-03 16:41:58 -0500547 target_compile_options(${target} PUBLIC "${LIBCXX_ADDITIONAL_COMPILE_FLAGS}")
Louis Dionne925d9d22019-10-02 20:07:01 +0000548endfunction()
Petr Hosek789b7f02019-05-30 04:40:21 +0000549
Eric Fiselier10ed6c32015-07-30 22:30:34 +0000550# Exception flags =============================================================
Louis Dionne432ae752019-10-04 18:03:17 +0000551function(cxx_add_exception_flags target)
552 if (LIBCXX_ENABLE_EXCEPTIONS)
553 # Catches C++ exceptions only and tells the compiler to assume that extern C
554 # functions never throw a C++ exception.
555 target_add_compile_flags_if_supported(${target} PUBLIC -EHsc)
556 else()
Louis Dionne432ae752019-10-04 18:03:17 +0000557 target_add_compile_flags_if_supported(${target} PUBLIC -EHs- -EHa-)
558 target_add_compile_flags_if_supported(${target} PUBLIC -fno-exceptions)
559 endif()
560endfunction()
Eric Fiselier10ed6c32015-07-30 22:30:34 +0000561
562# RTTI flags ==================================================================
Louis Dionne432ae752019-10-04 18:03:17 +0000563function(cxx_add_rtti_flags target)
564 if (NOT LIBCXX_ENABLE_RTTI)
David Spickett43cfc782023-07-07 09:55:36 +0000565 if (MSVC)
David Spickett36df92d2023-07-06 08:49:33 +0000566 target_add_compile_flags_if_supported(${target} PUBLIC -GR-)
567 else()
568 target_add_compile_flags_if_supported(${target} PUBLIC -fno-rtti)
569 endif()
Louis Dionne432ae752019-10-04 18:03:17 +0000570 endif()
571endfunction()
Eric Fiselier10ed6c32015-07-30 22:30:34 +0000572
Eric Fiselier194e0272016-10-14 12:56:52 +0000573# Modules flags ===============================================================
574# FIXME The libc++ sources are fundamentally non-modular. They need special
575# versions of the headers in order to provide C++03 and legacy ABI definitions.
576# NOTE: The public headers can be used with modules in all other contexts.
Louis Dionne432ae752019-10-04 18:03:17 +0000577function(cxx_add_module_flags target)
578 if (LLVM_ENABLE_MODULES)
579 # Ignore that the rest of the modules flags are now unused.
Louis Dionne13c42542019-10-04 19:10:56 +0000580 target_add_compile_flags_if_supported(${target} PUBLIC -Wno-unused-command-line-argument)
581 target_compile_options(${target} PUBLIC -fno-modules)
Louis Dionne432ae752019-10-04 18:03:17 +0000582 endif()
583endfunction()
Eric Fiselier194e0272016-10-14 12:56:52 +0000584
varconst1ba514c2023-07-11 20:18:20 -0700585string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
586
Jonathan Roelofs91b3a5e2015-08-24 21:20:07 +0000587# Sanitizer flags =============================================================
Eric Fiselierb98aa432015-07-29 23:46:55 +0000588
Eric Fiselier02f8e7c352018-11-13 23:08:31 +0000589function(get_sanitizer_flags OUT_VAR USE_SANITIZER)
590 set(SANITIZER_FLAGS)
591 set(USE_SANITIZER "${USE_SANITIZER}")
592 # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC.
593 # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do.
594 if (USE_SANITIZER AND NOT MSVC)
595 append_flags_if_supported(SANITIZER_FLAGS "-fno-omit-frame-pointer")
596 append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only")
597
598 if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND
599 NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
600 append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only")
601 endif()
602 if (USE_SANITIZER STREQUAL "Address")
603 append_flags(SANITIZER_FLAGS "-fsanitize=address")
Vitaly Buka18014fe2022-08-12 22:12:28 -0700604 elseif (USE_SANITIZER STREQUAL "HWAddress")
605 append_flags(SANITIZER_FLAGS "-fsanitize=hwaddress")
Eric Fiselier02f8e7c352018-11-13 23:08:31 +0000606 elseif (USE_SANITIZER MATCHES "Memory(WithOrigins)?")
Mark de Weverd563df82022-04-30 13:17:17 +0200607 append_flags(SANITIZER_FLAGS -fsanitize=memory)
Eric Fiselier02f8e7c352018-11-13 23:08:31 +0000608 if (USE_SANITIZER STREQUAL "MemoryWithOrigins")
609 append_flags(SANITIZER_FLAGS "-fsanitize-memory-track-origins")
610 endif()
611 elseif (USE_SANITIZER STREQUAL "Undefined")
Louis Dionnefa712b02023-11-29 09:29:44 -0500612 append_flags(SANITIZER_FLAGS "-fsanitize=undefined" "-fno-sanitize=vptr,function" "-fno-sanitize-recover=all")
Brian Gesiak54176d12020-04-04 13:01:32 -0400613 elseif (USE_SANITIZER STREQUAL "Address;Undefined" OR
614 USE_SANITIZER STREQUAL "Undefined;Address")
Louis Dionnefa712b02023-11-29 09:29:44 -0500615 append_flags(SANITIZER_FLAGS "-fsanitize=address,undefined" "-fno-sanitize=vptr,function" "-fno-sanitize-recover=all")
Eric Fiselier02f8e7c352018-11-13 23:08:31 +0000616 elseif (USE_SANITIZER STREQUAL "Thread")
617 append_flags(SANITIZER_FLAGS -fsanitize=thread)
Zola Bridges0f124802020-04-17 10:15:58 -0700618 elseif (USE_SANITIZER STREQUAL "DataFlow")
619 append_flags(SANITIZER_FLAGS -fsanitize=dataflow)
Eric Fiselier02f8e7c352018-11-13 23:08:31 +0000620 else()
621 message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${USE_SANITIZER}")
622 endif()
623 elseif(USE_SANITIZER AND MSVC)
624 message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.")
625 endif()
626 set(${OUT_VAR} "${SANITIZER_FLAGS}" PARENT_SCOPE)
627endfunction()
628
Eric Fiselier02f8e7c352018-11-13 23:08:31 +0000629get_sanitizer_flags(SANITIZER_FLAGS "${LLVM_USE_SANITIZER}")
Louis Dionnefa712b02023-11-29 09:29:44 -0500630add_library(cxx-sanitizer-flags INTERFACE)
631target_compile_options(cxx-sanitizer-flags INTERFACE ${SANITIZER_FLAGS})
Eric Fiselierf9f796e2015-10-13 22:12:02 +0000632
Tacet9ed20562023-12-13 06:05:34 +0100633# _LIBCPP_INSTRUMENTED_WITH_ASAN informs that library was built with ASan.
634# Defining _LIBCPP_INSTRUMENTED_WITH_ASAN while building the library with ASan is required.
635# Normally, the _LIBCPP_INSTRUMENTED_WITH_ASAN flag is used to keep information whether
636# dylibs are built with AddressSanitizer. However, when building libc++,
637# this flag needs to be defined so that the resulting dylib has all ASan functionalities guarded by this flag.
638# If the _LIBCPP_INSTRUMENTED_WITH_ASAN flag is not defined, then parts of the ASan instrumentation code in libc++
639# will not be compiled into it, resulting in false positives.
640# For context, read: https://github.com/llvm/llvm-project/pull/72677#pullrequestreview-1765402800
641string(FIND "${LLVM_USE_SANITIZER}" "Address" building_with_asan)
642if (NOT "${building_with_asan}" STREQUAL "-1")
643 config_define(ON _LIBCPP_INSTRUMENTED_WITH_ASAN)
644endif()
645
Louis Dionne32300872019-10-08 16:26:24 +0000646# Link system libraries =======================================================
647function(cxx_link_system_libraries target)
Louis Dionne36bb1342023-10-13 11:53:57 -0700648 if (NOT MSVC)
649 target_link_libraries(${target} PRIVATE "-nostdlib++")
Zbigniew Sarbinowski5f9be2c2021-02-16 18:02:22 +0000650 endif()
Louis Dionne32300872019-10-08 16:26:24 +0000651
Petr Hosekb3df14b2022-03-10 11:47:09 +0200652 if (CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG AND LIBCXXABI_USE_LLVM_UNWINDER)
Martin Storsjö529a7932021-10-24 01:11:20 +0300653 # If we're linking directly against the libunwind that we're building
654 # in the same invocation, don't try to link in the toolchain's
655 # default libunwind (which may be missing still).
656 target_add_link_flags_if_supported(${target} PRIVATE "--unwindlib=none")
657 endif()
658
Louis Dionnea4336f22023-12-13 13:57:48 -0500659 if (MSVC)
660 if (LIBCXX_USE_COMPILER_RT)
661 find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY)
662 if (LIBCXX_BUILTINS_LIBRARY)
663 target_link_libraries(${target} PRIVATE "${LIBCXX_BUILTINS_LIBRARY}")
664 endif()
665 elseif (LIBCXX_HAS_GCC_LIB)
666 target_link_libraries(${target} PRIVATE gcc)
667 elseif (LIBCXX_HAS_GCC_S_LIB)
668 target_link_libraries(${target} PRIVATE gcc_s)
Louis Dionne32300872019-10-08 16:26:24 +0000669 endif()
Louis Dionne32300872019-10-08 16:26:24 +0000670 endif()
671
Louis Dionnee0184352020-06-04 14:54:38 -0400672 if (LIBCXX_HAS_ATOMIC_LIB)
Louis Dionne32300872019-10-08 16:26:24 +0000673 target_link_libraries(${target} PRIVATE atomic)
674 endif()
675
676 if (MINGW)
677 target_link_libraries(${target} PRIVATE "${MINGW_LIBRARIES}")
678 endif()
679
David Spickett43cfc782023-07-07 09:55:36 +0000680 if (MSVC)
Martin Storsjö9b02e8d2023-07-17 12:50:35 +0300681 if ((NOT CMAKE_MSVC_RUNTIME_LIBRARY AND uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
682 OR (CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "Debug"))
Louis Dionne32300872019-10-08 16:26:24 +0000683 set(LIB_SUFFIX "d")
684 else()
685 set(LIB_SUFFIX "")
686 endif()
687
Martin Storsjöe777e442023-07-17 12:52:47 +0300688 if (NOT CMAKE_MSVC_RUNTIME_LIBRARY OR CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL$")
689 set(CRT_LIB "msvcrt")
690 set(CXX_LIB "msvcprt")
691 else()
692 set(CRT_LIB "libcmt")
693 set(CXX_LIB "libcpmt")
694 endif()
695
696 target_link_libraries(${target} PRIVATE ${CRT_LIB}${LIB_SUFFIX}) # C runtime startup files
697 target_link_libraries(${target} PRIVATE ${CXX_LIB}${LIB_SUFFIX}) # C++ standard library. Required for exception_ptr internals.
Louis Dionne32300872019-10-08 16:26:24 +0000698 # Required for standards-complaint wide character formatting functions
699 # (e.g. `printfw`/`scanfw`)
700 target_link_libraries(${target} PRIVATE iso_stdio_wide_specifiers)
701 endif()
Shoaib Meenai076da522020-01-27 17:29:41 -0800702
703 if (ANDROID AND ANDROID_PLATFORM_LEVEL LESS 21)
704 target_link_libraries(${target} PUBLIC android_support)
705 endif()
Zibi Sarbinowski36dde912022-10-03 16:41:58 -0500706 target_link_libraries(${target} PUBLIC "${LIBCXX_ADDITIONAL_LIBRARIES}")
Louis Dionne32300872019-10-08 16:26:24 +0000707endfunction()
708
Louis Dionne925d9d22019-10-02 20:07:01 +0000709# Windows-related flags =======================================================
710function(cxx_add_windows_flags target)
711 if(WIN32 AND NOT MINGW)
712 target_compile_definitions(${target} PRIVATE
713 # Ignore the -MSC_VER mismatch, as we may build
714 # with a different compatibility version.
715 _ALLOW_MSC_VER_MISMATCH
716 # Don't check the msvcprt iterator debug levels
717 # as we will define the iterator types; libc++
718 # uses a different macro to identify the debug
719 # level.
720 _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH
721 # We are building the c++ runtime, don't pull in
722 # msvcprt.
723 _CRTBLD
724 # Don't warn on the use of "deprecated"
725 # "insecure" functions which are standards
726 # specified.
727 _CRT_SECURE_NO_WARNINGS
728 # Use the ISO conforming behaviour for conversion
729 # in printf, scanf.
730 _CRT_STDIO_ISO_WIDE_SPECIFIERS)
731 endif()
732endfunction()
733
Eric Fiselierf9f796e2015-10-13 22:12:02 +0000734# Configuration file flags =====================================================
Louis Dionne817d8972022-02-07 14:52:17 -0500735config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION)
736config_define(${LIBCXX_ABI_NAMESPACE} _LIBCPP_ABI_NAMESPACE)
Shoaib Meenaia4a3d402017-10-05 02:18:08 +0000737config_define_if(LIBCXX_ABI_FORCE_ITANIUM _LIBCPP_ABI_FORCE_ITANIUM)
738config_define_if(LIBCXX_ABI_FORCE_MICROSOFT _LIBCPP_ABI_FORCE_MICROSOFT)
Eric Fiselierf9f796e2015-10-13 22:12:02 +0000739config_define_if_not(LIBCXX_ENABLE_THREADS _LIBCPP_HAS_NO_THREADS)
740config_define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK _LIBCPP_HAS_NO_MONOTONIC_CLOCK)
Joseph Huber7ad7f8f2024-08-21 08:48:53 -0500741config_define_if_not(LIBCXX_HAS_TERMINAL_AVAILABLE _LIBCPP_HAS_NO_TERMINAL)
Louis Dionnebe00e882020-11-16 18:13:43 -0500742if (NOT LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION STREQUAL "default")
Louis Dionned0fcdcd2020-05-15 15:58:19 -0400743 config_define("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION)
Eric Fiselier2405bd62019-05-29 02:21:37 +0000744endif()
Ben Craigb9599b12016-05-25 17:40:09 +0000745config_define_if(LIBCXX_HAS_PTHREAD_API _LIBCPP_HAS_THREAD_API_PTHREAD)
Asiri Rathnayake8c2bf452016-09-11 21:46:40 +0000746config_define_if(LIBCXX_HAS_EXTERNAL_THREAD_API _LIBCPP_HAS_THREAD_API_EXTERNAL)
Martin Storsjobf02a092018-01-05 20:48:29 +0000747config_define_if(LIBCXX_HAS_WIN32_THREAD_API _LIBCPP_HAS_THREAD_API_WIN32)
Vasileios Kalintiris8c58e922015-11-09 10:21:04 +0000748config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC)
Shoaib Meenai492d7132017-10-09 19:25:17 +0000749config_define_if(LIBCXX_NO_VCRUNTIME _LIBCPP_NO_VCRUNTIME)
Louis Dionne66a562d2023-05-31 11:20:24 -0700750config_define_if_not(LIBCXX_ENABLE_FILESYSTEM _LIBCPP_HAS_NO_FILESYSTEM)
Louis Dionnee0d01292020-10-15 10:32:09 -0400751config_define_if_not(LIBCXX_ENABLE_RANDOM_DEVICE _LIBCPP_HAS_NO_RANDOM_DEVICE)
Louis Dionne88ffc722020-10-09 15:31:05 -0400752config_define_if_not(LIBCXX_ENABLE_LOCALIZATION _LIBCPP_HAS_NO_LOCALIZATION)
Mark de Weverdf2af992021-05-25 20:11:08 +0200753config_define_if_not(LIBCXX_ENABLE_UNICODE _LIBCPP_HAS_NO_UNICODE)
Louis Dionnef4c12582021-08-23 15:32:36 -0400754config_define_if_not(LIBCXX_ENABLE_WIDE_CHARACTERS _LIBCPP_HAS_NO_WIDE_CHARACTERS)
Mark de Weverf78f93b2022-09-23 18:33:20 +0200755config_define_if_not(LIBCXX_ENABLE_TIME_ZONE_DATABASE _LIBCPP_HAS_NO_TIME_ZONE_DATABASE)
Louis Dionne2eadbc82020-11-04 15:01:25 -0500756config_define_if_not(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)
Konstantin Varlamovc6151f52023-10-10 11:10:18 -0700757
Louis Dionnec9d9dc92024-10-29 10:48:18 -0400758# TODO: Remove in LLVM 21. We're leaving an error to make this fail explicitly.
Konstantin Varlamovc6151f52023-10-10 11:10:18 -0700759if (LIBCXX_ENABLE_ASSERTIONS)
Louis Dionnec9d9dc92024-10-29 10:48:18 -0400760 message(FATAL_ERROR "LIBCXX_ENABLE_ASSERTIONS has been removed. Please use LIBCXX_HARDENING_MODE instead.")
Konstantin Varlamovc6151f52023-10-10 11:10:18 -0700761endif()
Konstantin Varlamov64d413e2023-11-08 09:10:00 -1000762if (LIBCXX_HARDENING_MODE STREQUAL "none")
763 config_define(2 _LIBCPP_HARDENING_MODE_DEFAULT)
764elseif (LIBCXX_HARDENING_MODE STREQUAL "fast")
765 config_define(4 _LIBCPP_HARDENING_MODE_DEFAULT)
766elseif (LIBCXX_HARDENING_MODE STREQUAL "extensive")
767 config_define(16 _LIBCPP_HARDENING_MODE_DEFAULT)
varconstd1367ca2023-07-12 10:12:51 -0700768elseif (LIBCXX_HARDENING_MODE STREQUAL "debug")
Konstantin Varlamov64d413e2023-11-08 09:10:00 -1000769 config_define(8 _LIBCPP_HARDENING_MODE_DEFAULT)
varconstd1367ca2023-07-12 10:12:51 -0700770endif()
Vasileios Kalintiris8c58e922015-11-09 10:21:04 +0000771
Louis Dionned423d802024-04-17 13:36:53 -0400772if (LIBCXX_PSTL_BACKEND STREQUAL "serial")
773 config_define(1 _LIBCPP_PSTL_BACKEND_SERIAL)
774elseif(LIBCXX_PSTL_BACKEND STREQUAL "std_thread")
775 config_define(1 _LIBCPP_PSTL_BACKEND_STD_THREAD)
776elseif(LIBCXX_PSTL_BACKEND STREQUAL "libdispatch")
777 config_define(1 _LIBCPP_PSTL_BACKEND_LIBDISPATCH)
Nikolas Klausere837f4b2023-05-24 15:33:38 -0700778else()
Louis Dionned423d802024-04-17 13:36:53 -0400779 message(FATAL_ERROR "LIBCXX_PSTL_BACKEND is set to ${LIBCXX_PSTL_BACKEND}, which is not a valid backend.
Nikolas Klauser2b2e7f62023-07-12 13:24:57 -0700780 Valid backends are: serial, std_thread and libdispatch")
Nikolas Klausere837f4b2023-05-24 15:33:38 -0700781endif()
782
Shoaib Meenai8e628122017-10-04 23:17:12 +0000783if (LIBCXX_ABI_DEFINES)
784 set(abi_defines)
785 foreach (abi_define ${LIBCXX_ABI_DEFINES})
786 if (NOT abi_define MATCHES "^_LIBCPP_ABI_")
787 message(SEND_ERROR "Invalid ABI macro ${abi_define} in LIBCXX_ABI_DEFINES")
788 endif()
789 list(APPEND abi_defines "#define ${abi_define}")
790 endforeach()
791 string(REPLACE ";" "\n" abi_defines "${abi_defines}")
792 config_define(${abi_defines} _LIBCPP_ABI_DEFINES)
793endif()
794
Martin Storsjöf68e8902021-12-21 01:19:34 +0200795if (LIBCXX_EXTRA_SITE_DEFINES)
796 set(extra_site_defines)
797 foreach (extra_site_define ${LIBCXX_EXTRA_SITE_DEFINES})
798 # Allow defines such as DEFINE=VAL, transformed into "#define DEFINE VAL".
799 string(REPLACE "=" " " extra_site_define "${extra_site_define}")
800 list(APPEND extra_site_defines "#define ${extra_site_define}")
801 endforeach()
802 string(REPLACE ";" "\n" extra_site_defines "${extra_site_defines}")
803 config_define(${extra_site_defines} _LIBCPP_EXTRA_SITE_DEFINES)
804endif()
805
Eric Fiselier54644212016-09-26 22:19:41 +0000806# By default libc++ on Windows expects to use a shared library, which requires
807# the headers to use DLL import/export semantics. However when building a
808# static library only we modify the headers to disable DLL import/export.
809if (DEFINED WIN32 AND LIBCXX_ENABLE_STATIC AND NOT LIBCXX_ENABLE_SHARED)
810 message(STATUS "Generating custom __config for non-DLL Windows build")
Shoaib Meenaifc6100c2016-12-05 19:40:12 +0000811 config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
Eric Fiselier54644212016-09-26 22:19:41 +0000812endif()
813
Martin Storsjö8a73aa82020-10-23 10:54:02 +0300814if (WIN32 AND LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
815 # If linking libcxxabi statically into libcxx, skip the dllimport attributes
816 # on symbols we refer to from libcxxabi.
817 add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS)
818endif()
819
Louis Dionnefadc84a2019-10-04 22:50:23 +0000820# Setup all common build flags =================================================
821function(cxx_add_common_build_flags target)
822 cxx_add_basic_build_flags(${target})
Nikolas Klausera7aade12023-02-17 11:31:41 +0100823 cxx_add_warning_flags(${target} ${LIBCXX_ENABLE_WERROR} ${LIBCXX_ENABLE_PEDANTIC})
Louis Dionnefadc84a2019-10-04 22:50:23 +0000824 cxx_add_windows_flags(${target})
Louis Dionnefadc84a2019-10-04 22:50:23 +0000825 cxx_add_exception_flags(${target})
826 cxx_add_rtti_flags(${target})
827 cxx_add_module_flags(${target})
Louis Dionne32300872019-10-08 16:26:24 +0000828 cxx_link_system_libraries(${target})
Louis Dionnefa712b02023-11-29 09:29:44 -0500829 target_link_libraries(${target} PRIVATE cxx-sanitizer-flags)
Louis Dionnefadc84a2019-10-04 22:50:23 +0000830endfunction()
831
Michael J. Spencerf5799be2010-12-10 19:47:54 +0000832#===============================================================================
Eric Fiselier10ed6c32015-07-30 22:30:34 +0000833# Setup Source Code And Tests
Michael J. Spencerf5799be2010-12-10 19:47:54 +0000834#===============================================================================
Louis Dionnebd135c32024-05-28 18:31:01 -0700835add_custom_target(cxx-test-depends
836 COMMENT "Build dependencies required to run the libc++ test suite.")
837
Howard Hinnant6a0d6ce2013-11-15 17:18:57 +0000838add_subdirectory(include)
Petr Hosekf80c4b62019-05-01 06:40:36 +0000839add_subdirectory(src)
Louis Dionne1f8e2862021-07-15 10:19:39 -0400840add_subdirectory(utils)
Mark de Wever1d6b6132024-01-21 12:02:39 +0100841add_subdirectory(modules)
Eric Fiselierb17bb062015-08-22 19:40:49 +0000842
Eric Fiselier10ed6c32015-07-30 22:30:34 +0000843if (LIBCXX_INCLUDE_TESTS)
Louis Dionneeb68a0a2020-06-29 11:51:15 -0400844 add_subdirectory(test)
Eric Fiselier28349f92016-11-14 02:43:12 +0000845 add_subdirectory(lib/abi)
Zachary Turner50105d22017-09-19 17:19:10 +0000846endif()
847
Eric Fiselierb17bb062015-08-22 19:40:49 +0000848if (LIBCXX_INCLUDE_DOCS)
849 add_subdirectory(docs)
850endif()