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