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