[Dexter][NFC] Add Missing Commands to Commands.md Contents
[llvm-project.git] / libcxxabi / CMakeLists.txt
blob923b3c6fda895cdcabbfd61420b913d551fceaed
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")
5 endif()
7 #===============================================================================
8 # Setup Project
9 #===============================================================================
11 cmake_minimum_required(VERSION 3.13.4)
13 if(POLICY CMP0042)
14   cmake_policy(SET CMP0042 NEW) # Set MACOSX_RPATH=YES by default
15 endif()
17 # Add path for custom modules
18 set(CMAKE_MODULE_PATH
19   "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
20   "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
21   ${CMAKE_MODULE_PATH}
22   )
24 set(LIBCXXABI_SOURCE_DIR  ${CMAKE_CURRENT_SOURCE_DIR})
25 set(LIBCXXABI_BINARY_DIR  ${CMAKE_CURRENT_BINARY_DIR})
26 set(LIBCXXABI_LIBCXX_PATH "${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH
27         "Specify path to libc++ source.")
29 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXXABI_STANDALONE_BUILD)
30   project(libcxxabi CXX C)
32   set(PACKAGE_NAME libcxxabi)
33   set(PACKAGE_VERSION 11.0.0git)
34   set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
35   set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org")
37   # Add the CMake module path of libcxx so we can reuse HandleOutOfTreeLLVM.cmake
38   set(LIBCXXABI_LIBCXX_CMAKE_PATH "${LIBCXXABI_LIBCXX_PATH}/cmake/Modules")
39   list(APPEND CMAKE_MODULE_PATH "${LIBCXXABI_LIBCXX_CMAKE_PATH}")
41   # In a standalone build, we don't have llvm to automatically generate the
42   # llvm-lit script for us.  So we need to provide an explicit directory that
43   # the configurator should write the script into.
44   set(LIBCXXABI_STANDALONE_BUILD 1)
45   set(LLVM_LIT_OUTPUT_DIR "${LIBCXXABI_BINARY_DIR}/bin")
47   # Find the LLVM sources and simulate LLVM CMake options.
48   include(HandleOutOfTreeLLVM)
49 endif()
51 # Require out of source build.
52 include(MacroEnsureOutOfSourceBuild)
53 MACRO_ENSURE_OUT_OF_SOURCE_BUILD(
54  "${PROJECT_NAME} requires an out of source build. Please create a separate
55  build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there."
56  )
58 #===============================================================================
59 # Setup CMake Options
60 #===============================================================================
61 include(CMakeDependentOption)
62 include(HandleCompilerRT)
64 # Define options.
65 option(LIBCXXABI_ENABLE_EXCEPTIONS
66   "Provide support for exceptions in the runtime.
67   When disabled, libc++abi does not support stack unwinding and other exceptions-related features." ON)
68 option(LIBCXXABI_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
69 option(LIBCXXABI_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
70 option(LIBCXXABI_ENABLE_PIC "Build Position-Independent Code, even in static library" ON)
71 option(LIBCXXABI_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
72 option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF)
73 option(LIBCXXABI_ENABLE_STATIC_UNWINDER "Statically link the LLVM unwinder." OFF)
74 option(LIBCXXABI_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
75 option(LIBCXXABI_ENABLE_THREADS "Build with threads enabled" ON)
76 option(LIBCXXABI_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF)
77 option(LIBCXXABI_HAS_EXTERNAL_THREAD_API
78   "Build libc++abi with an externalized threading API.
79   This option may only be set to ON when LIBCXXABI_ENABLE_THREADS=ON." OFF)
80 option(LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY
81   "Build libc++abi with an externalized threading library.
82    This option may only be set to ON when LIBCXXABI_ENABLE_THREADS=ON" OFF)
83 option(LIBCXXABI_ENABLE_FORGIVING_DYNAMIC_CAST
84 "Make dynamic_cast more forgiving when type_info's mistakenly have hidden \
85 visibility, and thus multiple type_infos can exist for a single type. \
86 When the dynamic_cast would normally fail, this option will cause the \
87 library to try comparing the type_info names to see if they are equal \
88 instead." OFF)
90 option(LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS
91   "Build libc++abi with definitions for operator new/delete. These are normally
92    defined in libc++abi, but it is also possible to define them in libc++, in
93    which case the definition in libc++abi should be turned off." ON)
94 option(LIBCXXABI_BUILD_32_BITS "Build 32 bit libc++abi." ${LLVM_BUILD_32_BITS})
95 option(LIBCXXABI_INCLUDE_TESTS "Generate build targets for the libc++abi unit tests." ${LLVM_INCLUDE_TESTS})
96 set(LIBCXXABI_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
97     "Define suffix of library directory name (32/64)")
98 option(LIBCXXABI_INSTALL_LIBRARY "Install the libc++abi library." ON)
99 set(LIBCXXABI_TARGET_TRIPLE "" CACHE STRING "Target triple for cross compiling.")
100 set(LIBCXXABI_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
101 set(LIBCXXABI_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")
102 set(LIBCXXABI_LIBCXX_LIBRARY_PATH "" CACHE PATH "The path to libc++ library.")
103 set(LIBCXXABI_LIBRARY_VERSION "1.0" CACHE STRING
104 "Version of libc++abi. This will be reflected in the name of the shared \
105 library produced. For example, -DLIBCXXABI_LIBRARY_VERSION=x.y will \
106 result in the library being named libc++abi.x.y.dylib, along with the \
107 usual symlinks pointing to that.")
109 # Default to building a shared library so that the default options still test
110 # the libc++abi that is being built. There are two problems with testing a
111 # static libc++abi. In the case of a standalone build, the tests will link the
112 # system's libc++, which might not have been built against our libc++abi. In the
113 # case of an in tree build, libc++ will prefer a dynamic libc++abi from the
114 # system over a static libc++abi from the output directory.
115 option(LIBCXXABI_ENABLE_SHARED "Build libc++abi as a shared library." ON)
116 option(LIBCXXABI_ENABLE_STATIC "Build libc++abi as a static library." ON)
118 cmake_dependent_option(LIBCXXABI_INSTALL_STATIC_LIBRARY
119   "Install the static libc++abi library." ON
120   "LIBCXXABI_ENABLE_STATIC;LIBCXXABI_INSTALL_LIBRARY" OFF)
121 cmake_dependent_option(LIBCXXABI_INSTALL_SHARED_LIBRARY
122   "Install the shared libc++abi library." ON
123   "LIBCXXABI_ENABLE_SHARED;LIBCXXABI_INSTALL_LIBRARY" OFF)
125 cmake_dependent_option(LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY
126   "Statically link the LLVM unwinder to static library" ON
127   "LIBCXXABI_ENABLE_STATIC_UNWINDER;LIBCXXABI_ENABLE_STATIC" OFF)
128 cmake_dependent_option(LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY
129   "Statically link the LLVM unwinder to shared library" ON
130   "LIBCXXABI_ENABLE_STATIC_UNWINDER;LIBCXXABI_ENABLE_SHARED" OFF)
132 option(LIBCXXABI_BAREMETAL "Build libc++abi for baremetal targets." OFF)
133 # The default terminate handler attempts to demangle uncaught exceptions, which
134 # causes extra I/O and demangling code to be pulled in.
135 option(LIBCXXABI_SILENT_TERMINATE "Set this to make the terminate handler default to a silent alternative" OFF)
137 if (NOT LIBCXXABI_ENABLE_SHARED AND NOT LIBCXXABI_ENABLE_STATIC)
138   message(FATAL_ERROR "libc++abi must be built as either a shared or static library.")
139 endif()
141 set(LIBCXXABI_LIBCXX_INCLUDES "${LIBCXXABI_LIBCXX_PATH}/include" CACHE PATH
142     "Specify path to libc++ includes.")
143 message(STATUS "Libc++abi will be using libc++ includes from ${LIBCXXABI_LIBCXX_INCLUDES}")
145 option(LIBCXXABI_HERMETIC_STATIC_LIBRARY
146   "Do not export any symbols from the static library." OFF)
148 set(LIBCXXABI_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/lit.site.cfg.in" CACHE STRING
149     "The Lit testing configuration to use when running the tests.")
150 set(LIBCXXABI_TEST_PARAMS "" CACHE STRING
151     "A list of parameters to run the Lit test suite with.")
153 #===============================================================================
154 # Configure System
155 #===============================================================================
157 # Add path for custom modules
158 set(CMAKE_MODULE_PATH
159   "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
160   "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
161   ${CMAKE_MODULE_PATH}
162   )
164 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
165   set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++)
166   set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++)
167   if(LIBCXX_LIBDIR_SUBDIR)
168     string(APPEND LIBCXXABI_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR})
169     string(APPEND LIBCXXABI_INSTALL_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR})
170   endif()
171 elseif(LLVM_LIBRARY_OUTPUT_INTDIR)
172   set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
173   set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX})
174 else()
175   set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX})
176   set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX})
177 endif()
179 set(LIBCXXABI_INSTALL_PREFIX "" CACHE STRING "Define libc++abi destination prefix.")
181 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR})
182 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR})
183 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR})
185 # By default, for non-standalone builds, libcxx and libcxxabi share a library
186 # directory.
187 if (NOT LIBCXXABI_LIBCXX_LIBRARY_PATH)
188   set(LIBCXXABI_LIBCXX_LIBRARY_PATH "${LIBCXXABI_LIBRARY_DIR}" CACHE PATH
189       "The path to libc++ library." FORCE)
190 endif()
192 # Check that we can build with 32 bits if requested.
193 if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32)
194   if (LIBCXXABI_BUILD_32_BITS AND NOT LLVM_BUILD_32_BITS) # Don't duplicate the output from LLVM
195     message(STATUS "Building 32 bits executables and libraries.")
196   endif()
197 elseif(LIBCXXABI_BUILD_32_BITS)
198   message(FATAL_ERROR "LIBCXXABI_BUILD_32_BITS=ON is not supported on this platform.")
199 endif()
201 # Declare libc++abi configuration variables.
202 # They are intended for use as follows:
203 # LIBCXXABI_C_FLAGS: General flags for both the c++ compiler and linker.
204 # LIBCXXABI_CXX_FLAGS: General flags for both the c++ compiler and linker.
205 # LIBCXXABI_COMPILE_FLAGS: Compile only flags.
206 # LIBCXXABI_LINK_FLAGS: Linker only flags.
207 # LIBCXXABI_LIBRARIES: libraries libc++abi is linked to.
209 set(LIBCXXABI_C_FLAGS "")
210 set(LIBCXXABI_CXX_FLAGS "")
211 set(LIBCXXABI_COMPILE_FLAGS "")
212 set(LIBCXXABI_LINK_FLAGS "")
213 set(LIBCXXABI_LIBRARIES "")
215 # Include macros for adding and removing libc++abi flags.
216 include(HandleLibcxxabiFlags)
218 #===============================================================================
219 # Setup Compiler Flags
220 #===============================================================================
222 # Configure target flags
223 add_target_flags_if(LIBCXXABI_BUILD_32_BITS "-m32")
225 if(LIBCXXABI_TARGET_TRIPLE)
226   add_target_flags("--target=${LIBCXXABI_TARGET_TRIPLE}")
227 elseif(CMAKE_CXX_COMPILER_TARGET)
228   set(LIBCXXABI_TARGET_TRIPLE "${CMAKE_CXX_COMPILER_TARGET}")
229 endif()
230 if(LIBCXX_GCC_TOOLCHAIN)
231   add_target_flags("--gcc-toolchain=${LIBCXXABI_GCC_TOOLCHAIN}")
232 elseif(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN)
233   set(LIBCXXABI_GCC_TOOLCHAIN "${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}")
234 endif()
235 if(LIBCXXABI_SYSROOT)
236   add_target_flags("--sysroot=${LIBCXXABI_SYSROOT}")
237 elseif(CMAKE_SYSROOT)
238   set(LIBCXXABI_SYSROOT "${CMAKE_SYSROOT}")
239 endif()
241 if (LIBCXXABI_TARGET_TRIPLE)
242   set(TARGET_TRIPLE "${LIBCXXABI_TARGET_TRIPLE}")
243 endif()
245 # Configure compiler. Must happen after setting the target flags.
246 include(config-ix)
248 if (LIBCXXABI_HAS_NOSTDINCXX_FLAG)
249   list(APPEND LIBCXXABI_COMPILE_FLAGS -nostdinc++)
250   # cmake 3.14 and above remove system include paths that are explicitly
251   # passed on the command line.  We build with -nostdinc++ and explicitly add
252   # just the libcxx system include paths with -I on the command line.
253   # Setting CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES effectively prevents cmake
254   # from removing these.
255   # See: https://gitlab.kitware.com/cmake/cmake/issues/19227
256   set(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES "")
257   # Remove -stdlib flags to prevent them from causing an unused flag warning.
258   string(REPLACE "--stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
259   string(REPLACE "--stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
260   string(REPLACE "-stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
261   string(REPLACE "-stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
262 endif()
264 # Let the library headers know they are currently being used to build the
265 # library.
266 add_definitions(-D_LIBCXXABI_BUILDING_LIBRARY)
268 # Disable DLL annotations on Windows for static builds.
269 if (WIN32 AND LIBCXXABI_ENABLE_STATIC AND NOT LIBCXXABI_ENABLE_SHARED)
270   add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS)
271 endif()
273 add_compile_flags_if_supported(-Werror=return-type)
275 # Get warning flags
276 add_compile_flags_if_supported(-W)
277 add_compile_flags_if_supported(-Wall)
278 add_compile_flags_if_supported(-Wchar-subscripts)
279 add_compile_flags_if_supported(-Wconversion)
280 add_compile_flags_if_supported(-Wmismatched-tags)
281 add_compile_flags_if_supported(-Wmissing-braces)
282 add_compile_flags_if_supported(-Wnewline-eof)
283 add_compile_flags_if_supported(-Wunused-function)
284 add_compile_flags_if_supported(-Wshadow)
285 add_compile_flags_if_supported(-Wshorten-64-to-32)
286 add_compile_flags_if_supported(-Wsign-compare)
287 add_compile_flags_if_supported(-Wsign-conversion)
288 add_compile_flags_if_supported(-Wstrict-aliasing=2)
289 add_compile_flags_if_supported(-Wstrict-overflow=4)
290 add_compile_flags_if_supported(-Wunused-parameter)
291 add_compile_flags_if_supported(-Wunused-variable)
292 add_compile_flags_if_supported(-Wwrite-strings)
293 add_compile_flags_if_supported(-Wundef)
295 add_compile_flags_if_supported(-Wno-suggest-override)
297 if (LIBCXXABI_ENABLE_WERROR)
298   add_compile_flags_if_supported(-Werror)
299   add_compile_flags_if_supported(-WX)
300 else()
301   add_compile_flags_if_supported(-Wno-error)
302   add_compile_flags_if_supported(-WX-)
303 endif()
304 if (LIBCXXABI_ENABLE_PEDANTIC)
305   add_compile_flags_if_supported(-pedantic)
306 endif()
308 # Get feature flags.
309 add_compile_flags_if_supported(-fstrict-aliasing)
311 # Exceptions
312 if (LIBCXXABI_ENABLE_EXCEPTIONS)
313   # Catches C++ exceptions only and tells the compiler to assume that extern C
314   # functions never throw a C++ exception.
315   add_compile_flags_if_supported(-EHsc)
316   # Do we really need to be run through the C compiler ?
317   add_c_compile_flags_if_supported(-funwind-tables)
318 else()
319   add_compile_flags_if_supported(-fno-exceptions)
320   add_compile_flags_if_supported(-EHs-)
321   add_compile_flags_if_supported(-EHa-)
322 endif()
324 # Assert
325 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
326 if (LIBCXXABI_ENABLE_ASSERTIONS)
327   # MSVC doesn't like _DEBUG on release builds. See PR 4379.
328   if (NOT MSVC)
329     list(APPEND LIBCXXABI_COMPILE_FLAGS -D_DEBUG)
330   endif()
331   # On Release builds cmake automatically defines NDEBUG, so we
332   # explicitly undefine it:
333   if (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
334     list(APPEND LIBCXXABI_COMPILE_FLAGS -UNDEBUG)
335   endif()
336 else()
337   if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
338     list(APPEND LIBCXXABI_COMPILE_FLAGS -DNDEBUG)
339   endif()
340 endif()
341 # Static library
342 if (NOT LIBCXXABI_ENABLE_SHARED)
343   list(APPEND LIBCXXABI_COMPILE_FLAGS -D_LIBCPP_BUILD_STATIC)
344 endif()
346 # Threading
347 if (NOT LIBCXXABI_ENABLE_THREADS)
348   if (LIBCXXABI_HAS_PTHREAD_API)
349     message(FATAL_ERROR "LIBCXXABI_HAS_PTHREAD_API can only"
350                         " be set to ON when LIBCXXABI_ENABLE_THREADS"
351                         " is also set to ON.")
352   endif()
353   if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
354     message(FATAL_ERROR "LIBCXXABI_HAS_EXTERNAL_THREAD_API can only"
355                         " be set to ON when LIBCXXABI_ENABLE_THREADS"
356                         " is also set to ON.")
357   endif()
358   if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY)
359     message(FATAL_ERROR "LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY can only"
360                         " be set to ON when LIBCXXABI_ENABLE_THREADS"
361                         " is also set to ON.")
362   endif()
363   add_definitions(-D_LIBCXXABI_HAS_NO_THREADS)
364   add_definitions(-D_LIBCPP_HAS_NO_THREADS)
365 endif()
367 if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
368   if (LIBCXXABI_HAS_PTHREAD_API)
369     message(FATAL_ERROR "The options LIBCXXABI_HAS_EXTERNAL_THREAD_API"
370                         " and LIBCXXABI_HAS_PTHREAD_API cannot be both"
371                         " set to ON at the same time.")
372   endif()
373   if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY)
374     message(FATAL_ERROR "The options LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY"
375                         " and LIBCXXABI_HAS_EXTERNAL_THREAD_API cannot be both"
376                         " set to ON at the same time.")
377   endif()
378 endif()
380 if (LLVM_ENABLE_MODULES)
381   # Ignore that the rest of the modules flags are now unused.
382   add_compile_flags_if_supported(-Wno-unused-command-line-argument)
383   add_compile_flags(-fno-modules)
384 endif()
386 set(LIBCXXABI_HAS_UNDEFINED_SYMBOLS OFF)
387 if ((NOT LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS)
388     OR (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY AND LIBCXXABI_ENABLE_SHARED)
389     OR MINGW)
390   set(LIBCXXABI_HAS_UNDEFINED_SYMBOLS ON)
391 endif()
393 if (LIBCXXABI_HAS_UNDEFINED_SYMBOLS)
394   # Need to allow unresolved symbols if this is to work with shared library builds
395   if (APPLE)
396     list(APPEND LIBCXXABI_LINK_FLAGS "-undefined dynamic_lookup")
397   else()
398     # Relax this restriction from HandleLLVMOptions
399     string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
400   endif()
401 endif()
403 if (LIBCXXABI_HAS_PTHREAD_API)
404   add_definitions(-D_LIBCPP_HAS_THREAD_API_PTHREAD)
405 endif()
407 if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
408   add_definitions(-D_LIBCPP_HAS_THREAD_API_EXTERNAL)
409 endif()
411 if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY)
412   add_definitions(-D_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL)
413 endif()
415 # Prevent libc++abi from having library dependencies on libc++
416 add_definitions(-D_LIBCPP_DISABLE_EXTERN_TEMPLATE)
418 # Bring back `std::unexpected`, which is removed in C++17, to support
419 # pre-C++17.
420 add_definitions(-D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS)
422 if (MSVC)
423   add_definitions(-D_CRT_SECURE_NO_WARNINGS)
424 endif()
426 # Define LIBCXXABI_USE_LLVM_UNWINDER for conditional compilation.
427 if (LIBCXXABI_USE_LLVM_UNWINDER)
428   add_definitions(-DLIBCXXABI_USE_LLVM_UNWINDER)
429 endif()
431 if (LIBCXXABI_SILENT_TERMINATE)
432   add_definitions(-DLIBCXXABI_SILENT_TERMINATE)
433 endif()
435 if (LIBCXXABI_BAREMETAL)
436     add_definitions(-DLIBCXXABI_BAREMETAL)
437 endif()
439 if (LIBCXXABI_HAS_COMMENT_LIB_PRAGMA)
440   if (LIBCXXABI_HAS_PTHREAD_LIB)
441     add_definitions(-D_LIBCXXABI_LINK_PTHREAD_LIB)
442   endif()
443 endif()
445 string(REPLACE ";" " " LIBCXXABI_CXX_FLAGS "${LIBCXXABI_CXX_FLAGS}")
446 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXXABI_CXX_FLAGS}")
447 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBCXXABI_C_FLAGS}")
449 #===============================================================================
450 # Setup Source Code
451 #===============================================================================
453 set(LIBCXXABI_LIBUNWIND_INCLUDES "${LIBCXXABI_LIBUNWIND_INCLUDES}" CACHE PATH
454     "Specify path to libunwind includes." FORCE)
455 set(LIBCXXABI_LIBUNWIND_PATH "${LIBCXXABI_LIBUNWIND_PATH}" CACHE PATH
456     "Specify path to libunwind source." FORCE)
458 include_directories(include)
459 if (LIBCXXABI_USE_LLVM_UNWINDER OR LLVM_NATIVE_ARCH MATCHES ARM)
460   find_path(LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL libunwind.h
461     PATHS ${LIBCXXABI_LIBUNWIND_INCLUDES}
462           ${LIBCXXABI_LIBUNWIND_PATH}/include
463           ${CMAKE_BINARY_DIR}/${LIBCXXABI_LIBUNWIND_INCLUDES}
464           ${LLVM_MAIN_SRC_DIR}/projects/libunwind/include
465           ${LLVM_MAIN_SRC_DIR}/runtimes/libunwind/include
466           ${LLVM_MAIN_SRC_DIR}/../libunwind/include
467     NO_DEFAULT_PATH
468     NO_CMAKE_FIND_ROOT_PATH
469   )
471   if (LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL "LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL-NOTFOUND")
472     set(LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL "")
473   endif()
475   if (NOT LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL "")
476     include_directories("${LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL}")
477   endif()
478 endif()
480 # Add source code. This also contains all of the logic for deciding linker flags
481 # soname, etc...
482 add_subdirectory(src)
484 if (LIBCXXABI_INCLUDE_TESTS)
485   add_subdirectory(test)
486   add_subdirectory(fuzz)
487 endif()