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