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