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