[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / libcxxabi / CMakeLists.txt
blobb8326d08d23a8f743870b47b3733f39568e8f800
1 # See www/CMake.html for instructions on how to build libcxxabi with CMake.
3 #===============================================================================
4 # Setup Project
5 #===============================================================================
7 cmake_minimum_required(VERSION 3.13.4)
9 set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
11 # Add path for custom modules
12 list(INSERT CMAKE_MODULE_PATH 0
13   "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
14   "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
15   "${LLVM_COMMON_CMAKE_UTILS}"
16   "${LLVM_COMMON_CMAKE_UTILS}/Modules"
17   )
19 set(CMAKE_FOLDER "libc++")
21 set(LIBCXXABI_SOURCE_DIR  ${CMAKE_CURRENT_SOURCE_DIR})
22 set(LIBCXXABI_BINARY_DIR  ${CMAKE_CURRENT_BINARY_DIR})
23 set(LIBCXXABI_LIBCXX_PATH "${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH
24         "Specify path to libc++ source.")
26 include(GNUInstallDirs)
28 # Require out of source build.
29 include(MacroEnsureOutOfSourceBuild)
30 MACRO_ENSURE_OUT_OF_SOURCE_BUILD(
31  "${PROJECT_NAME} requires an out of source build. Please create a separate
32  build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there."
33  )
35 #===============================================================================
36 # Setup CMake Options
37 #===============================================================================
38 include(CMakeDependentOption)
39 include(HandleCompilerRT)
41 # Define options.
42 option(LIBCXXABI_ENABLE_EXCEPTIONS
43   "Provide support for exceptions in the runtime.
44   When disabled, libc++abi does not support stack unwinding and other exceptions-related features." ON)
45 option(LIBCXXABI_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
46 option(LIBCXXABI_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
47 option(LIBCXXABI_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
48 option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF)
49 option(LIBCXXABI_ENABLE_STATIC_UNWINDER "Statically link the LLVM unwinder." OFF)
50 option(LIBCXXABI_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
51 option(LIBCXXABI_ENABLE_THREADS "Build with threads enabled" ON)
52 option(LIBCXXABI_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF)
53 option(LIBCXXABI_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32 thread API" OFF)
54 option(LIBCXXABI_HAS_EXTERNAL_THREAD_API
55   "Build libc++abi with an externalized threading API.
56   This option may only be set to ON when LIBCXXABI_ENABLE_THREADS=ON." OFF)
57 option(LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY
58   "Build libc++abi with an externalized threading library.
59    This option may only be set to ON when LIBCXXABI_ENABLE_THREADS=ON" OFF)
60 option(LIBCXXABI_ENABLE_FORGIVING_DYNAMIC_CAST
61 "Make dynamic_cast more forgiving when type_info's mistakenly have hidden \
62 visibility, and thus multiple type_infos can exist for a single type. \
63 When the dynamic_cast would normally fail, this option will cause the \
64 library to try comparing the type_info names to see if they are equal \
65 instead." OFF)
67 option(LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS
68   "Build libc++abi with definitions for operator new/delete. These are normally
69    defined in libc++abi, but it is also possible to define them in libc++, in
70    which case the definition in libc++abi should be turned off." ON)
71 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})
72 if (LIBCXXABI_BUILD_32_BITS)
73   message(FATAL_ERROR "LIBCXXABI_BUILD_32_BITS is not supported anymore when building the runtimes, please specify a full triple instead.")
74 endif()
76 option(LIBCXXABI_INCLUDE_TESTS "Generate build targets for the libc++abi unit tests." ${LLVM_INCLUDE_TESTS})
77 set(LIBCXXABI_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
78     "Define suffix of library directory name (32/64)")
79 option(LIBCXXABI_INSTALL_HEADERS "Install the libc++abi headers." ON)
80 option(LIBCXXABI_INSTALL_LIBRARY "Install the libc++abi library." ON)
82 set(LIBCXXABI_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/c++/v1" CACHE PATH "Path to install the libc++abi headers at.")
84 if(LLVM_LIBRARY_OUTPUT_INTDIR)
85   set(LIBCXXABI_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
86 else()
87   set(LIBCXXABI_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1")
88 endif()
90 # TODO: Remove this after branching for LLVM 15
91 if(LIBCXXABI_SYSROOT OR LIBCXXABI_TARGET_TRIPLE OR LIBCXXABI_GCC_TOOLCHAIN)
92   message(WARNING "LIBCXXABI_SYSROOT, LIBCXXABI_TARGET_TRIPLE and LIBCXXABI_GCC_TOOLCHAIN are not supported anymore, please use the native CMake equivalents instead")
93 endif()
95 set(LIBCXXABI_LIBCXX_LIBRARY_PATH "" CACHE PATH "The path to libc++ library.")
96 set(LIBCXXABI_LIBRARY_VERSION "1.0" CACHE STRING
97 "Version of libc++abi. This will be reflected in the name of the shared \
98 library produced. For example, -DLIBCXXABI_LIBRARY_VERSION=x.y will \
99 result in the library being named libc++abi.x.y.dylib, along with the \
100 usual symlinks pointing to that.")
102 # Default to building a shared library so that the default options still test
103 # the libc++abi that is being built. The problem with testing a static libc++abi
104 # is that libc++ will prefer a dynamic libc++abi from the system over a static
105 # libc++abi from the output directory.
106 option(LIBCXXABI_ENABLE_SHARED "Build libc++abi as a shared library." ON)
107 option(LIBCXXABI_ENABLE_STATIC "Build libc++abi as a static library." ON)
109 cmake_dependent_option(LIBCXXABI_INSTALL_STATIC_LIBRARY
110   "Install the static libc++abi library." ON
111   "LIBCXXABI_ENABLE_STATIC;LIBCXXABI_INSTALL_LIBRARY" OFF)
112 cmake_dependent_option(LIBCXXABI_INSTALL_SHARED_LIBRARY
113   "Install the shared libc++abi library." ON
114   "LIBCXXABI_ENABLE_SHARED;LIBCXXABI_INSTALL_LIBRARY" OFF)
116 cmake_dependent_option(LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY
117   "Statically link the LLVM unwinder to static library" ON
118   "LIBCXXABI_ENABLE_STATIC_UNWINDER" OFF)
119 cmake_dependent_option(LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY
120   "Statically link the LLVM unwinder to shared library" ON
121   "LIBCXXABI_ENABLE_STATIC_UNWINDER" OFF)
123 option(LIBCXXABI_BAREMETAL "Build libc++abi for baremetal targets." OFF)
124 # The default terminate handler attempts to demangle uncaught exceptions, which
125 # causes extra I/O and demangling code to be pulled in.
126 option(LIBCXXABI_SILENT_TERMINATE "Set this to make the terminate handler default to a silent alternative" OFF)
127 option(LIBCXXABI_NON_DEMANGLING_TERMINATE "Set this to make the terminate handler
128 avoid demangling" OFF)
130 if (NOT LIBCXXABI_ENABLE_SHARED AND NOT LIBCXXABI_ENABLE_STATIC)
131   message(FATAL_ERROR "libc++abi must be built as either a shared or static library.")
132 endif()
134 # TODO: Remove this, which shouldn't be necessary since we know we're being built
135 #       side-by-side with libc++.
136 set(LIBCXXABI_LIBCXX_INCLUDES "" CACHE PATH
137     "Specify path to libc++ includes.")
139 set(LIBCXXABI_HERMETIC_STATIC_LIBRARY_DEFAULT OFF)
140 if (WIN32)
141   set(LIBCXXABI_HERMETIC_STATIC_LIBRARY_DEFAULT ON)
142 endif()
143 option(LIBCXXABI_HERMETIC_STATIC_LIBRARY
144   "Do not export any symbols from the static library." ${LIBCXXABI_HERMETIC_STATIC_LIBRARY_DEFAULT})
146 if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
147   set(LIBCXXABI_DEFAULT_TEST_CONFIG "llvm-libc++abi-shared-gcc.cfg.in")
148 elseif(MINGW)
149   set(LIBCXXABI_DEFAULT_TEST_CONFIG "llvm-libc++abi-mingw.cfg.in")
150 elseif(WIN32) # clang-cl
151   if (LIBCXXABI_ENABLE_SHARED)
152     set(LIBCXXABI_DEFAULT_TEST_CONFIG "llvm-libc++abi-shared-clangcl.cfg.in")
153   else()
154     set(LIBCXXABI_DEFAULT_TEST_CONFIG "llvm-libc++abi-static-clangcl.cfg.in")
155   endif()
156 else()
157   if (LIBCXXABI_ENABLE_SHARED)
158     set(LIBCXXABI_DEFAULT_TEST_CONFIG "llvm-libc++abi-shared.cfg.in")
159   else()
160     set(LIBCXXABI_DEFAULT_TEST_CONFIG "llvm-libc++abi-static.cfg.in")
161   endif()
162 endif()
163 set(LIBCXXABI_TEST_CONFIG "${LIBCXXABI_DEFAULT_TEST_CONFIG}" CACHE STRING
164   "The path to the Lit testing configuration to use when running the tests.
165    If a relative path is provided, it is assumed to be relative to '<monorepo>/libcxxabi/test/configs'.")
166 if (NOT IS_ABSOLUTE "${LIBCXXABI_TEST_CONFIG}")
167   set(LIBCXXABI_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/configs/${LIBCXXABI_TEST_CONFIG}")
168 endif()
169 message(STATUS "Using libc++abi testing configuration: ${LIBCXXABI_TEST_CONFIG}")
170 set(LIBCXXABI_TEST_PARAMS "" CACHE STRING
171     "A list of parameters to run the Lit test suite with.")
173 #===============================================================================
174 # Configure System
175 #===============================================================================
177 # Add path for custom modules
178 set(CMAKE_MODULE_PATH
179   "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
180   "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
181   ${CMAKE_MODULE_PATH}
182   )
184 set(LIBCXXABI_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH
185     "Path where built libc++abi runtime libraries should be installed.")
187 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
188   set(LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR})
189   set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
190   set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH
191       "Path where built libc++abi libraries should be installed.")
192   if(LIBCXX_LIBDIR_SUBDIR)
193     string(APPEND LIBCXXABI_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR})
194     string(APPEND LIBCXXABI_INSTALL_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR})
195   endif()
196 else()
197   if(LLVM_LIBRARY_OUTPUT_INTDIR)
198     set(LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR})
199     set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
200   else()
201     set(LIBCXXABI_HEADER_DIR ${CMAKE_BINARY_DIR})
202     set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX})
203   endif()
204   set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX} CACHE PATH
205       "Path where built libc++abi libraries should be installed.")
206 endif()
208 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR})
209 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR})
210 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR})
212 # By default, libcxx and libcxxabi share a library directory.
213 if (NOT LIBCXXABI_LIBCXX_LIBRARY_PATH)
214   set(LIBCXXABI_LIBCXX_LIBRARY_PATH "${LIBCXXABI_LIBRARY_DIR}" CACHE PATH
215       "The path to libc++ library." FORCE)
216 endif()
218 # Declare libc++abi configuration variables.
219 # They are intended for use as follows:
220 # LIBCXXABI_C_FLAGS: General flags for both the c++ compiler and linker.
221 # LIBCXXABI_CXX_FLAGS: General flags for both the c++ compiler and linker.
222 # LIBCXXABI_COMPILE_FLAGS: Compile only flags.
223 # LIBCXXABI_LINK_FLAGS: Linker only flags.
224 # LIBCXXABI_LIBRARIES: libraries libc++abi is linked to.
226 set(LIBCXXABI_C_FLAGS "")
227 set(LIBCXXABI_CXX_FLAGS "")
228 set(LIBCXXABI_COMPILE_FLAGS "")
229 set(LIBCXXABI_LINK_FLAGS "")
230 set(LIBCXXABI_LIBRARIES "")
232 # Include macros for adding and removing libc++abi flags.
233 include(HandleLibcxxabiFlags)
235 #===============================================================================
236 # Setup Compiler Flags
237 #===============================================================================
239 # Configure target flags
240 if(ZOS)
241   add_target_flags_if_supported("-fzos-le-char-mode=ebcdic")
242 endif()
244 if (${CMAKE_SYSTEM_NAME} MATCHES "AIX")
245   add_target_flags_if_supported("-mdefault-visibility-export-mapping=explicit")
246   set(CMAKE_AIX_EXPORT_ALL_SYMBOLS OFF)
247 endif()
249 # Configure compiler. Must happen after setting the target flags.
250 include(config-ix)
252 if (CXX_SUPPORTS_NOSTDINCXX_FLAG)
253   list(APPEND LIBCXXABI_COMPILE_FLAGS -nostdinc++)
254   # cmake 3.14 and above remove system include paths that are explicitly
255   # passed on the command line.  We build with -nostdinc++ and explicitly add
256   # just the libcxx system include paths with -I on the command line.
257   # Setting CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES effectively prevents cmake
258   # from removing these.
259   # See: https://gitlab.kitware.com/cmake/cmake/issues/19227
260   set(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES "")
261   # Remove -stdlib flags to prevent them from causing an unused flag warning.
262   string(REPLACE "--stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
263   string(REPLACE "--stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
264   string(REPLACE "-stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
265   string(REPLACE "-stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
266 endif()
268 # Let the library headers know they are currently being used to build the
269 # library.
270 add_definitions(-D_LIBCXXABI_BUILDING_LIBRARY)
272 # libcxxabi needs to, for various reasons, include the libcpp headers as if
273 # it is being built as part of libcxx.
274 add_definitions(-D_LIBCPP_BUILDING_LIBRARY)
276 add_compile_flags_if_supported(-Werror=return-type)
278 # Get warning flags
279 add_compile_flags_if_supported(-W)
280 add_compile_flags_if_supported(-Wall)
281 add_compile_flags_if_supported(-Wchar-subscripts)
282 add_compile_flags_if_supported(-Wconversion)
283 add_compile_flags_if_supported(-Wmismatched-tags)
284 add_compile_flags_if_supported(-Wmissing-braces)
285 add_compile_flags_if_supported(-Wnewline-eof)
286 add_compile_flags_if_supported(-Wunused-function)
287 add_compile_flags_if_supported(-Wshadow)
288 add_compile_flags_if_supported(-Wshorten-64-to-32)
289 add_compile_flags_if_supported(-Wsign-compare)
290 add_compile_flags_if_supported(-Wsign-conversion)
291 add_compile_flags_if_supported(-Wstrict-aliasing=2)
292 add_compile_flags_if_supported(-Wstrict-overflow=4)
293 add_compile_flags_if_supported(-Wunused-parameter)
294 add_compile_flags_if_supported(-Wunused-variable)
295 add_compile_flags_if_supported(-Wwrite-strings)
296 add_compile_flags_if_supported(-Wundef)
298 add_compile_flags_if_supported(-Wno-suggest-override)
300 if (LIBCXXABI_ENABLE_WERROR)
301   add_compile_flags_if_supported(-Werror)
302   add_compile_flags_if_supported(-WX)
303 else()
304   add_compile_flags_if_supported(-Wno-error)
305   add_compile_flags_if_supported(-WX-)
306 endif()
307 if (LIBCXXABI_ENABLE_PEDANTIC)
308   add_compile_flags_if_supported(-pedantic)
309 endif()
311 # Get feature flags.
312 add_compile_flags_if_supported(-fstrict-aliasing)
314 # Exceptions
315 if (LIBCXXABI_ENABLE_EXCEPTIONS)
316   # Catches C++ exceptions only and tells the compiler to assume that extern C
317   # functions never throw a C++ exception.
318   add_compile_flags_if_supported(-EHsc)
319   # Do we really need to be run through the C compiler ?
320   add_c_compile_flags_if_supported(-funwind-tables)
321 else()
322   add_compile_flags_if_supported(-fno-exceptions)
323   add_compile_flags_if_supported(-EHs-)
324   add_compile_flags_if_supported(-EHa-)
325 endif()
327 # Assert
328 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
329 if (LIBCXXABI_ENABLE_ASSERTIONS)
330   # MSVC doesn't like _DEBUG on release builds. See PR 4379.
331   if (NOT MSVC)
332     list(APPEND LIBCXXABI_COMPILE_FLAGS -D_DEBUG)
333   endif()
334   # On Release builds cmake automatically defines NDEBUG, so we
335   # explicitly undefine it:
336   if (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
337     list(APPEND LIBCXXABI_COMPILE_FLAGS -UNDEBUG)
338   endif()
339 else()
340   if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
341     list(APPEND LIBCXXABI_COMPILE_FLAGS -DNDEBUG)
342   endif()
343 endif()
345 # Threading
346 if (NOT LIBCXXABI_ENABLE_THREADS)
347   if (LIBCXXABI_HAS_PTHREAD_API)
348     message(FATAL_ERROR "LIBCXXABI_HAS_PTHREAD_API can only"
349                         " be set to ON when LIBCXXABI_ENABLE_THREADS"
350                         " is also set to ON.")
351   endif()
352   if (LIBCXXABI_HAS_WIN32_THREAD_API)
353     message(FATAL_ERROR "LIBCXXABI_HAS_WIN32_THREAD_API can only"
354                         " be set to ON when LIBCXXABI_ENABLE_THREADS"
355                         " is also set to ON.")
356   endif()
357   if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
358     message(FATAL_ERROR "LIBCXXABI_HAS_EXTERNAL_THREAD_API can only"
359                         " be set to ON when LIBCXXABI_ENABLE_THREADS"
360                         " is also set to ON.")
361   endif()
362   if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY)
363     message(FATAL_ERROR "LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY can only"
364                         " be set to ON when LIBCXXABI_ENABLE_THREADS"
365                         " is also set to ON.")
366   endif()
367   add_definitions(-D_LIBCXXABI_HAS_NO_THREADS)
368 endif()
370 if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
371   if (LIBCXXABI_HAS_PTHREAD_API)
372     message(FATAL_ERROR "The options LIBCXXABI_HAS_EXTERNAL_THREAD_API"
373                         " and LIBCXXABI_HAS_PTHREAD_API cannot be both"
374                         " set to ON at the same time.")
375   endif()
376   if (LIBCXXABI_HAS_WIN32_THREAD_API)
377     message(FATAL_ERROR "The options LIBCXXABI_HAS_EXTERNAL_THREAD_API"
378                         " and LIBCXXABI_HAS_WIN32_THREAD_API cannot be both"
379                         " set to ON at the same time.")
380   endif()
381   if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY)
382     message(FATAL_ERROR "The options LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY"
383                         " and LIBCXXABI_HAS_EXTERNAL_THREAD_API cannot be both"
384                         " set to ON at the same time.")
385   endif()
386 endif()
388 if (LIBCXXABI_HAS_PTHREAD_API)
389   if (LIBCXXABI_HAS_WIN32_THREAD_API)
390     message(FATAL_ERROR "The options LIBCXXABI_HAS_PTHREAD_API"
391             "and LIBCXXABI_HAS_WIN32_THREAD_API cannot be both"
392             "set to ON at the same time.")
393   endif()
394 endif()
396 if (LLVM_ENABLE_MODULES)
397   # Ignore that the rest of the modules flags are now unused.
398   add_compile_flags_if_supported(-Wno-unused-command-line-argument)
399   add_compile_flags(-fno-modules)
400 endif()
402 set(LIBCXXABI_HAS_UNDEFINED_SYMBOLS OFF)
403 if ((NOT LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS)
404     OR (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY AND LIBCXXABI_ENABLE_SHARED)
405     OR MINGW)
406   set(LIBCXXABI_HAS_UNDEFINED_SYMBOLS ON)
407 endif()
409 if (LIBCXXABI_HAS_UNDEFINED_SYMBOLS)
410   # Need to allow unresolved symbols if this is to work with shared library builds
411   if (APPLE)
412     list(APPEND LIBCXXABI_LINK_FLAGS "-undefined dynamic_lookup")
413   else()
414     # Relax this restriction from HandleLLVMOptions
415     string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
416   endif()
417 endif()
419 if (LIBCXXABI_HAS_PTHREAD_API)
420   add_definitions(-D_LIBCPP_HAS_THREAD_API_PTHREAD)
421 endif()
423 if (LIBCXXABI_HAS_WIN32_THREAD_API)
424   add_definitions(-D_LIBCPP_HAS_THREAD_API_WIN32)
425 endif()
427 if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
428   add_definitions(-D_LIBCPP_HAS_THREAD_API_EXTERNAL)
429 endif()
431 if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY)
432   add_definitions(-D_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL)
433 endif()
435 if (MSVC)
436   add_definitions(-D_CRT_SECURE_NO_WARNINGS)
437 endif()
439 if (LIBCXXABI_SILENT_TERMINATE)
440   add_definitions(-DLIBCXXABI_SILENT_TERMINATE)
441 endif()
443 if (LIBCXXABI_NON_DEMANGLING_TERMINATE)
444   add_definitions(-DLIBCXXABI_NON_DEMANGLING_TERMINATE)
445 endif()
447 if (LIBCXXABI_BAREMETAL)
448     add_definitions(-DLIBCXXABI_BAREMETAL)
449 endif()
451 if (C_SUPPORTS_COMMENT_LIB_PRAGMA)
452   if (LIBCXXABI_HAS_PTHREAD_LIB)
453     add_definitions(-D_LIBCXXABI_LINK_PTHREAD_LIB)
454   endif()
455 endif()
457 string(REPLACE ";" " " LIBCXXABI_CXX_FLAGS "${LIBCXXABI_CXX_FLAGS}")
458 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXXABI_CXX_FLAGS}")
459 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBCXXABI_C_FLAGS}")
461 # On AIX, avoid picking up VMX extensions(i.e. vec_malloc) which would change
462 # the default alignment of the allocators here.
463 if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
464   add_definitions("-D_XOPEN_SOURCE=700")
465 endif()
467 #===============================================================================
468 # Setup Source Code
469 #===============================================================================
471 set(LIBCXXABI_LIBUNWIND_INCLUDES "${LIBCXXABI_LIBUNWIND_INCLUDES}" CACHE PATH
472     "Specify path to libunwind includes." FORCE)
473 set(LIBCXXABI_LIBUNWIND_PATH "${LIBCXXABI_LIBUNWIND_PATH}" CACHE PATH
474     "Specify path to libunwind source." FORCE)
476 if (LIBCXXABI_USE_LLVM_UNWINDER OR LLVM_NATIVE_ARCH MATCHES ARM)
477   find_path(LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL libunwind.h
478     PATHS ${LIBCXXABI_LIBUNWIND_INCLUDES}
479           ${LIBCXXABI_LIBUNWIND_PATH}/include
480           ${CMAKE_BINARY_DIR}/${LIBCXXABI_LIBUNWIND_INCLUDES}
481           ${LLVM_MAIN_SRC_DIR}/projects/libunwind/include
482           ${LLVM_MAIN_SRC_DIR}/runtimes/libunwind/include
483           ${LLVM_MAIN_SRC_DIR}/../libunwind/include
484     NO_DEFAULT_PATH
485     NO_CMAKE_FIND_ROOT_PATH
486   )
488   if (LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL "LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL-NOTFOUND")
489     set(LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL "")
490   endif()
492   if (NOT LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL "")
493     include_directories("${LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL}")
494   endif()
495 endif()
497 # Add source code. This also contains all of the logic for deciding linker flags
498 # soname, etc...
499 add_subdirectory(include)
500 add_subdirectory(src)
502 if (LIBCXXABI_INCLUDE_TESTS)
503   add_subdirectory(test)
504   add_subdirectory(fuzz)
505 endif()