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