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