1 # See www/CMake.html for instructions on how to build libcxxabi with CMake.
3 if (NOT IS_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/../libcxx")
4 message(FATAL_ERROR "libc++abi now requires being built in a monorepo layout with libcxx available")
7 #===============================================================================
9 #===============================================================================
11 cmake_minimum_required(VERSION 3.13.4)
13 set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
15 # Add path for custom modules
16 list(INSERT CMAKE_MODULE_PATH 0
17 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
18 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
19 "${LLVM_COMMON_CMAKE_UTILS}"
20 "${LLVM_COMMON_CMAKE_UTILS}/Modules"
23 set(CMAKE_FOLDER "libc++")
25 set(LIBCXXABI_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
26 set(LIBCXXABI_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
27 set(LIBCXXABI_LIBCXX_PATH "${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH
28 "Specify path to libc++ source.")
30 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXXABI_STANDALONE_BUILD)
31 message(FATAL_ERROR "The Standalone build has been deprecated since LLVM 14, and it is not supported anymore. "
32 "Please use one of the ways described at https://libcxx.llvm.org/BuildingLibcxx.html for "
33 "building libc++abi.")
35 project(libcxxabi CXX C)
37 set(PACKAGE_NAME libcxxabi)
38 set(PACKAGE_VERSION 11.0.0git)
39 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
40 set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org")
42 set(LIBCXXABI_STANDALONE_BUILD TRUE)
44 # In a standalone build, we don't have llvm to automatically generate the
45 # llvm-lit script for us. So we need to provide an explicit directory that
46 # the configurator should write the script into.
47 set(LLVM_LIT_OUTPUT_DIR "${LIBCXXABI_BINARY_DIR}/bin")
50 # Must go below project(..)
51 include(GNUInstallDirs)
53 if (LIBCXXABI_STANDALONE_BUILD)
54 # Find the LLVM sources and simulate LLVM CMake options.
55 include(HandleOutOfTreeLLVM)
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")
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})
73 # Require out of source build.
74 include(MacroEnsureOutOfSourceBuild)
75 MACRO_ENSURE_OUT_OF_SOURCE_BUILD(
76 "${PROJECT_NAME} requires an out of source build. Please create a separate
77 build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there."
80 #===============================================================================
82 #===============================================================================
83 include(CMakeDependentOption)
84 include(HandleCompilerRT)
87 option(LIBCXXABI_ENABLE_EXCEPTIONS
88 "Provide support for exceptions in the runtime.
89 When disabled, libc++abi does not support stack unwinding and other exceptions-related features." ON)
90 option(LIBCXXABI_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
91 option(LIBCXXABI_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
92 option(LIBCXXABI_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
93 option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF)
94 option(LIBCXXABI_ENABLE_STATIC_UNWINDER "Statically link the LLVM unwinder." OFF)
95 option(LIBCXXABI_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
96 option(LIBCXXABI_ENABLE_THREADS "Build with threads enabled" ON)
97 option(LIBCXXABI_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF)
98 option(LIBCXXABI_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32 thread API" OFF)
99 option(LIBCXXABI_HAS_EXTERNAL_THREAD_API
100 "Build libc++abi with an externalized threading API.
101 This option may only be set to ON when LIBCXXABI_ENABLE_THREADS=ON." OFF)
102 option(LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY
103 "Build libc++abi with an externalized threading library.
104 This option may only be set to ON when LIBCXXABI_ENABLE_THREADS=ON" OFF)
105 option(LIBCXXABI_ENABLE_FORGIVING_DYNAMIC_CAST
106 "Make dynamic_cast more forgiving when type_info's mistakenly have hidden \
107 visibility, and thus multiple type_infos can exist for a single type. \
108 When the dynamic_cast would normally fail, this option will cause the \
109 library to try comparing the type_info names to see if they are equal \
112 option(LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS
113 "Build libc++abi with definitions for operator new/delete. These are normally
114 defined in libc++abi, but it is also possible to define them in libc++, in
115 which case the definition in libc++abi should be turned off." ON)
116 option(LIBCXXABI_BUILD_32_BITS "Build 32 bit multilib libc++abi. This option is not supported anymore when building the runtimes. Please specify a full triple instead." ${LLVM_BUILD_32_BITS})
117 if (LIBCXXABI_BUILD_32_BITS)
118 message(FATAL_ERROR "LIBCXXABI_BUILD_32_BITS is not supported anymore when building the runtimes, please specify a full triple instead.")
121 option(LIBCXXABI_INCLUDE_TESTS "Generate build targets for the libc++abi unit tests." ${LLVM_INCLUDE_TESTS})
122 set(LIBCXXABI_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
123 "Define suffix of library directory name (32/64)")
124 option(LIBCXXABI_INSTALL_LIBRARY "Install the libc++abi library." ON)
126 if(CMAKE_CXX_COMPILER_TARGET)
127 set(LIBCXXABI_DEFAULT_TARGET_TRIPLE "${CMAKE_CXX_COMPILER_TARGET}")
129 set(LIBCXXABI_DEFAULT_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
131 set(LIBCXXABI_TARGET_TRIPLE "${LIBCXXABI_DEFAULT_TARGET_TRIPLE}" CACHE STRING "Target triple for cross compiling.")
132 set(LIBCXXABI_GCC_TOOLCHAIN "${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}" CACHE PATH "GCC toolchain for cross compiling.")
133 set(LIBCXXABI_SYSROOT "${CMAKE_SYSROOT}" CACHE PATH "Sysroot for cross compiling.")
135 if(NOT CMAKE_SYSROOT AND LIBCXXABI_SYSROOT)
136 message(WARNING "LIBCXXABI_SYSROOT is deprecated, please use CMAKE_SYSROOT instead")
138 if(NOT CMAKE_CXX_COMPILER_TARGET AND LIBCXXABI_TARGET_TRIPLE)
139 message(WARNING "LIBCXXABI_TARGET_TRIPLE is deprecated, please use CMAKE_CXX_COMPILER_TARGET instead")
141 if(NOT CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN AND LIBCXXABI_GCC_TOOLCHAIN)
142 message(WARNING "LIBCXXABI_GCC_TOOLCHAIN is deprecated, please use CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN instead")
145 set(LIBCXXABI_LIBCXX_LIBRARY_PATH "" CACHE PATH "The path to libc++ library.")
146 set(LIBCXXABI_LIBRARY_VERSION "1.0" CACHE STRING
147 "Version of libc++abi. This will be reflected in the name of the shared \
148 library produced. For example, -DLIBCXXABI_LIBRARY_VERSION=x.y will \
149 result in the library being named libc++abi.x.y.dylib, along with the \
150 usual symlinks pointing to that.")
152 # Default to building a shared library so that the default options still test
153 # the libc++abi that is being built. There are two problems with testing a
154 # static libc++abi. In the case of a standalone build, the tests will link the
155 # system's libc++, which might not have been built against our libc++abi. In the
156 # case of an in tree build, libc++ will prefer a dynamic libc++abi from the
157 # system over a static libc++abi from the output directory.
158 option(LIBCXXABI_ENABLE_SHARED "Build libc++abi as a shared library." ON)
159 option(LIBCXXABI_ENABLE_STATIC "Build libc++abi as a static library." ON)
161 cmake_dependent_option(LIBCXXABI_INSTALL_STATIC_LIBRARY
162 "Install the static libc++abi library." ON
163 "LIBCXXABI_ENABLE_STATIC;LIBCXXABI_INSTALL_LIBRARY" OFF)
164 cmake_dependent_option(LIBCXXABI_INSTALL_SHARED_LIBRARY
165 "Install the shared libc++abi library." ON
166 "LIBCXXABI_ENABLE_SHARED;LIBCXXABI_INSTALL_LIBRARY" OFF)
168 cmake_dependent_option(LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY
169 "Statically link the LLVM unwinder to static library" ON
170 "LIBCXXABI_ENABLE_STATIC_UNWINDER;LIBCXXABI_ENABLE_STATIC" OFF)
171 cmake_dependent_option(LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY
172 "Statically link the LLVM unwinder to shared library" ON
173 "LIBCXXABI_ENABLE_STATIC_UNWINDER;LIBCXXABI_ENABLE_SHARED" OFF)
175 option(LIBCXXABI_BAREMETAL "Build libc++abi for baremetal targets." OFF)
176 # The default terminate handler attempts to demangle uncaught exceptions, which
177 # causes extra I/O and demangling code to be pulled in.
178 option(LIBCXXABI_SILENT_TERMINATE "Set this to make the terminate handler default to a silent alternative" OFF)
179 option(LIBCXXABI_NON_DEMANGLING_TERMINATE "Set this to make the terminate handler
180 avoid demangling" OFF)
182 if (NOT LIBCXXABI_ENABLE_SHARED AND NOT LIBCXXABI_ENABLE_STATIC)
183 message(FATAL_ERROR "libc++abi must be built as either a shared or static library.")
186 # TODO: This is a workaround for the fact that Standalone builds can't use
187 # targets from the other runtimes (so the cxx-headers target doesn't exist).
188 set(LIBCXXABI_LIBCXX_INCLUDES "" CACHE PATH
189 "Specify path to libc++ includes.")
190 if (LIBCXXABI_STANDALONE_BUILD)
191 if (NOT IS_DIRECTORY ${LIBCXXABI_LIBCXX_INCLUDES})
193 "LIBCXXABI_LIBCXX_INCLUDES=${LIBCXXABI_LIBCXX_INCLUDES} is not a valid directory. "
194 "Please provide the path to where the libc++ headers have been installed.")
196 add_library(cxx-headers INTERFACE)
197 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
198 target_compile_options(cxx-headers INTERFACE /I "${LIBCXXABI_LIBCXX_INCLUDES}")
200 target_compile_options(cxx-headers INTERFACE -I "${LIBCXXABI_LIBCXX_INCLUDES}")
204 option(LIBCXXABI_HERMETIC_STATIC_LIBRARY
205 "Do not export any symbols from the static library." OFF)
207 set(LIBCXXABI_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/lit.site.cfg.in" CACHE STRING
208 "The path to the Lit testing configuration to use when running the tests.
209 If a relative path is provided, it is assumed to be relative to '<monorepo>/libcxxabi/test/configs'.")
210 if (NOT IS_ABSOLUTE "${LIBCXXABI_TEST_CONFIG}")
211 set(LIBCXXABI_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/configs/${LIBCXXABI_TEST_CONFIG}")
213 set(LIBCXXABI_TEST_PARAMS "" CACHE STRING
214 "A list of parameters to run the Lit test suite with.")
216 #===============================================================================
218 #===============================================================================
220 # Add path for custom modules
221 set(CMAKE_MODULE_PATH
222 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
223 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
227 set(LIBCXXABI_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH
228 "Path where built libc++abi runtime libraries should be installed.")
230 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
231 set(LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR})
232 set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
233 set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH
234 "Path where built libc++abi libraries should be installed.")
235 if(LIBCXX_LIBDIR_SUBDIR)
236 string(APPEND LIBCXXABI_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR})
237 string(APPEND LIBCXXABI_INSTALL_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR})
240 if(LLVM_LIBRARY_OUTPUT_INTDIR)
241 set(LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR})
242 set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
244 set(LIBCXXABI_HEADER_DIR ${CMAKE_BINARY_DIR})
245 set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX})
247 set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX} CACHE PATH
248 "Path where built libc++abi libraries should be installed.")
251 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR})
252 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR})
253 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR})
255 # By default, for non-standalone builds, libcxx and libcxxabi share a library
257 if (NOT LIBCXXABI_LIBCXX_LIBRARY_PATH)
258 set(LIBCXXABI_LIBCXX_LIBRARY_PATH "${LIBCXXABI_LIBRARY_DIR}" CACHE PATH
259 "The path to libc++ library." FORCE)
262 # Declare libc++abi configuration variables.
263 # They are intended for use as follows:
264 # LIBCXXABI_C_FLAGS: General flags for both the c++ compiler and linker.
265 # LIBCXXABI_CXX_FLAGS: General flags for both the c++ compiler and linker.
266 # LIBCXXABI_COMPILE_FLAGS: Compile only flags.
267 # LIBCXXABI_LINK_FLAGS: Linker only flags.
268 # LIBCXXABI_LIBRARIES: libraries libc++abi is linked to.
270 set(LIBCXXABI_C_FLAGS "")
271 set(LIBCXXABI_CXX_FLAGS "")
272 set(LIBCXXABI_COMPILE_FLAGS "")
273 set(LIBCXXABI_LINK_FLAGS "")
274 set(LIBCXXABI_LIBRARIES "")
276 # Include macros for adding and removing libc++abi flags.
277 include(HandleLibcxxabiFlags)
279 #===============================================================================
280 # Setup Compiler Flags
281 #===============================================================================
283 # Configure target flags
285 add_target_flags_if_supported("-fzos-le-char-mode=ebcdic")
287 if(LIBCXXABI_TARGET_TRIPLE)
288 add_target_flags_if_supported("--target=${LIBCXXABI_TARGET_TRIPLE}")
290 if(LIBCXXABI_GCC_TOOLCHAIN)
291 add_target_flags_if_supported("--gcc-toolchain=${LIBCXXABI_GCC_TOOLCHAIN}")
293 if(LIBCXXABI_SYSROOT)
294 add_target_flags_if_supported("--sysroot=${LIBCXXABI_SYSROOT}")
297 # Configure compiler. Must happen after setting the target flags.
300 if (LIBCXXABI_HAS_NOSTDINCXX_FLAG)
301 list(APPEND LIBCXXABI_COMPILE_FLAGS -nostdinc++)
302 # cmake 3.14 and above remove system include paths that are explicitly
303 # passed on the command line. We build with -nostdinc++ and explicitly add
304 # just the libcxx system include paths with -I on the command line.
305 # Setting CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES effectively prevents cmake
306 # from removing these.
307 # See: https://gitlab.kitware.com/cmake/cmake/issues/19227
308 set(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES "")
309 # Remove -stdlib flags to prevent them from causing an unused flag warning.
310 string(REPLACE "--stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
311 string(REPLACE "--stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
312 string(REPLACE "-stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
313 string(REPLACE "-stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
316 # Let the library headers know they are currently being used to build the
318 add_definitions(-D_LIBCXXABI_BUILDING_LIBRARY)
320 # libcxxabi needs to, for various reasons, include the libcpp headers as if
321 # it is being built as part of libcxx.
322 add_definitions(-D_LIBCPP_BUILDING_LIBRARY)
324 # Disable DLL annotations on Windows for static builds.
325 if (WIN32 AND LIBCXXABI_ENABLE_STATIC AND NOT LIBCXXABI_ENABLE_SHARED)
326 if (LIBCXX_ENABLE_SHARED AND LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
327 # Building libcxxabi statically, but intending for it to be statically
328 # linked into a shared libcxx; keep dllexport enabled within libcxxabi,
329 # as the symbols will need to be exported from libcxx.
331 # Regular static build; disable dllexports.
332 add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS)
336 add_compile_flags_if_supported(-Werror=return-type)
339 add_compile_flags_if_supported(-W)
340 add_compile_flags_if_supported(-Wall)
341 add_compile_flags_if_supported(-Wchar-subscripts)
342 add_compile_flags_if_supported(-Wconversion)
343 add_compile_flags_if_supported(-Wmismatched-tags)
344 add_compile_flags_if_supported(-Wmissing-braces)
345 add_compile_flags_if_supported(-Wnewline-eof)
346 add_compile_flags_if_supported(-Wunused-function)
347 add_compile_flags_if_supported(-Wshadow)
348 add_compile_flags_if_supported(-Wshorten-64-to-32)
349 add_compile_flags_if_supported(-Wsign-compare)
350 add_compile_flags_if_supported(-Wsign-conversion)
351 add_compile_flags_if_supported(-Wstrict-aliasing=2)
352 add_compile_flags_if_supported(-Wstrict-overflow=4)
353 add_compile_flags_if_supported(-Wunused-parameter)
354 add_compile_flags_if_supported(-Wunused-variable)
355 add_compile_flags_if_supported(-Wwrite-strings)
356 add_compile_flags_if_supported(-Wundef)
358 add_compile_flags_if_supported(-Wno-suggest-override)
360 if (LIBCXXABI_ENABLE_WERROR)
361 add_compile_flags_if_supported(-Werror)
362 add_compile_flags_if_supported(-WX)
364 add_compile_flags_if_supported(-Wno-error)
365 add_compile_flags_if_supported(-WX-)
367 if (LIBCXXABI_ENABLE_PEDANTIC)
368 add_compile_flags_if_supported(-pedantic)
372 add_compile_flags_if_supported(-fstrict-aliasing)
375 if (LIBCXXABI_ENABLE_EXCEPTIONS)
376 # Catches C++ exceptions only and tells the compiler to assume that extern C
377 # functions never throw a C++ exception.
378 add_compile_flags_if_supported(-EHsc)
379 # Do we really need to be run through the C compiler ?
380 add_c_compile_flags_if_supported(-funwind-tables)
382 add_compile_flags_if_supported(-fno-exceptions)
383 add_compile_flags_if_supported(-EHs-)
384 add_compile_flags_if_supported(-EHa-)
388 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
389 if (LIBCXXABI_ENABLE_ASSERTIONS)
390 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
392 list(APPEND LIBCXXABI_COMPILE_FLAGS -D_DEBUG)
394 # On Release builds cmake automatically defines NDEBUG, so we
395 # explicitly undefine it:
396 if (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
397 list(APPEND LIBCXXABI_COMPILE_FLAGS -UNDEBUG)
400 if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
401 list(APPEND LIBCXXABI_COMPILE_FLAGS -DNDEBUG)
406 if (NOT LIBCXXABI_ENABLE_THREADS)
407 if (LIBCXXABI_HAS_PTHREAD_API)
408 message(FATAL_ERROR "LIBCXXABI_HAS_PTHREAD_API can only"
409 " be set to ON when LIBCXXABI_ENABLE_THREADS"
410 " is also set to ON.")
412 if (LIBCXXABI_HAS_WIN32_THREAD_API)
413 message(FATAL_ERROR "LIBCXXABI_HAS_WIN32_THREAD_API can only"
414 " be set to ON when LIBCXXABI_ENABLE_THREADS"
415 " is also set to ON.")
417 if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
418 message(FATAL_ERROR "LIBCXXABI_HAS_EXTERNAL_THREAD_API can only"
419 " be set to ON when LIBCXXABI_ENABLE_THREADS"
420 " is also set to ON.")
422 if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY)
423 message(FATAL_ERROR "LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY can only"
424 " be set to ON when LIBCXXABI_ENABLE_THREADS"
425 " is also set to ON.")
427 add_definitions(-D_LIBCXXABI_HAS_NO_THREADS)
430 if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
431 if (LIBCXXABI_HAS_PTHREAD_API)
432 message(FATAL_ERROR "The options LIBCXXABI_HAS_EXTERNAL_THREAD_API"
433 " and LIBCXXABI_HAS_PTHREAD_API cannot be both"
434 " set to ON at the same time.")
436 if (LIBCXXABI_HAS_WIN32_THREAD_API)
437 message(FATAL_ERROR "The options LIBCXXABI_HAS_EXTERNAL_THREAD_API"
438 " and LIBCXXABI_HAS_WIN32_THREAD_API cannot be both"
439 " set to ON at the same time.")
441 if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY)
442 message(FATAL_ERROR "The options LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY"
443 " and LIBCXXABI_HAS_EXTERNAL_THREAD_API cannot be both"
444 " set to ON at the same time.")
448 if (LIBCXXABI_HAS_PTHREAD_API)
449 if (LIBCXXABI_HAS_WIN32_THREAD_API)
450 message(FATAL_ERROR "The options LIBCXXABI_HAS_PTHREAD_API"
451 "and LIBCXXABI_HAS_WIN32_THREAD_API cannot be both"
452 "set to ON at the same time.")
456 if (LLVM_ENABLE_MODULES)
457 # Ignore that the rest of the modules flags are now unused.
458 add_compile_flags_if_supported(-Wno-unused-command-line-argument)
459 add_compile_flags(-fno-modules)
462 set(LIBCXXABI_HAS_UNDEFINED_SYMBOLS OFF)
463 if ((NOT LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS)
464 OR (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY AND LIBCXXABI_ENABLE_SHARED)
466 set(LIBCXXABI_HAS_UNDEFINED_SYMBOLS ON)
469 if (LIBCXXABI_HAS_UNDEFINED_SYMBOLS)
470 # Need to allow unresolved symbols if this is to work with shared library builds
472 list(APPEND LIBCXXABI_LINK_FLAGS "-undefined dynamic_lookup")
474 # Relax this restriction from HandleLLVMOptions
475 string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
479 if (LIBCXXABI_HAS_PTHREAD_API)
480 add_definitions(-D_LIBCPP_HAS_THREAD_API_PTHREAD)
483 if (LIBCXXABI_HAS_WIN32_THREAD_API)
484 add_definitions(-D_LIBCPP_HAS_THREAD_API_WIN32)
487 if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
488 add_definitions(-D_LIBCPP_HAS_THREAD_API_EXTERNAL)
491 if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY)
492 add_definitions(-D_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL)
495 # Prevent libc++abi from having library dependencies on libc++
496 add_definitions(-D_LIBCPP_DISABLE_EXTERN_TEMPLATE)
499 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
502 # Define LIBCXXABI_USE_LLVM_UNWINDER for conditional compilation.
503 if (LIBCXXABI_USE_LLVM_UNWINDER)
504 add_definitions(-DLIBCXXABI_USE_LLVM_UNWINDER)
507 if (LIBCXXABI_SILENT_TERMINATE)
508 add_definitions(-DLIBCXXABI_SILENT_TERMINATE)
511 if (LIBCXXABI_NON_DEMANGLING_TERMINATE)
512 add_definitions(-DLIBCXXABI_NON_DEMANGLING_TERMINATE)
515 if (LIBCXXABI_BAREMETAL)
516 add_definitions(-DLIBCXXABI_BAREMETAL)
519 if (LIBCXXABI_HAS_COMMENT_LIB_PRAGMA)
520 if (LIBCXXABI_HAS_PTHREAD_LIB)
521 add_definitions(-D_LIBCXXABI_LINK_PTHREAD_LIB)
525 string(REPLACE ";" " " LIBCXXABI_CXX_FLAGS "${LIBCXXABI_CXX_FLAGS}")
526 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXXABI_CXX_FLAGS}")
527 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBCXXABI_C_FLAGS}")
529 # On AIX, avoid picking up VMX extensions(i.e. vec_malloc) which would change
530 # the default alignment of the allocators here.
531 if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
532 add_definitions("-D_XOPEN_SOURCE=700")
535 #===============================================================================
537 #===============================================================================
539 set(LIBCXXABI_LIBUNWIND_INCLUDES "${LIBCXXABI_LIBUNWIND_INCLUDES}" CACHE PATH
540 "Specify path to libunwind includes." FORCE)
541 set(LIBCXXABI_LIBUNWIND_PATH "${LIBCXXABI_LIBUNWIND_PATH}" CACHE PATH
542 "Specify path to libunwind source." FORCE)
544 include_directories(include)
545 if (LIBCXXABI_USE_LLVM_UNWINDER OR LLVM_NATIVE_ARCH MATCHES ARM)
546 find_path(LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL libunwind.h
547 PATHS ${LIBCXXABI_LIBUNWIND_INCLUDES}
548 ${LIBCXXABI_LIBUNWIND_PATH}/include
549 ${CMAKE_BINARY_DIR}/${LIBCXXABI_LIBUNWIND_INCLUDES}
550 ${LLVM_MAIN_SRC_DIR}/projects/libunwind/include
551 ${LLVM_MAIN_SRC_DIR}/runtimes/libunwind/include
552 ${LLVM_MAIN_SRC_DIR}/../libunwind/include
554 NO_CMAKE_FIND_ROOT_PATH
557 if (LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL "LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL-NOTFOUND")
558 set(LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL "")
561 if (NOT LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL "")
562 include_directories("${LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL}")
566 # Add source code. This also contains all of the logic for deciding linker flags
568 add_subdirectory(src)
570 if (LIBCXXABI_INCLUDE_TESTS)
571 add_subdirectory(test)
572 add_subdirectory(fuzz)