Martell Malone | 062f8f0 | 2017-06-01 00:09:20 | [diff] [blame] | 1 | # See www/CMake.html for instructions on how to build libcxxabi with CMake. |
| 2 | |
Louis Dionne | 19aec8c | 2020-03-12 22:01:20 | [diff] [blame] | 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 | |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 7 | #=============================================================================== |
| 8 | # Setup Project |
| 9 | #=============================================================================== |
| 10 | |
Chris Bieneman | 1d72b89 | 2016-05-31 20:21:53 | [diff] [blame] | 11 | cmake_minimum_required(VERSION 3.4.3) |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 12 | |
Eric Fiselier | 42c8f93 | 2015-01-26 22:00:30 | [diff] [blame] | 13 | if(POLICY CMP0042) |
| 14 | cmake_policy(SET CMP0042 NEW) # Set MACOSX_RPATH=YES by default |
| 15 | endif() |
| 16 | |
Petr Hosek | 5f3d5be | 2017-04-07 20:10:41 | [diff] [blame] | 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 | |
Jonas Hahnfeld | 66c60d9 | 2019-02-17 12:16:20 | [diff] [blame] | 24 | if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXXABI_STANDALONE_BUILD) |
Martell Malone | 062f8f0 | 2017-06-01 00:09:20 | [diff] [blame] | 25 | project(libcxxabi CXX C) |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 26 | |
| 27 | set(PACKAGE_NAME libcxxabi) |
Alex Langford | effa0bc | 2020-01-30 20:18:24 | [diff] [blame] | 28 | set(PACKAGE_VERSION 11.0.0git) |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 29 | set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") |
Tanya Lattner | be2225f | 2015-08-05 04:01:26 | [diff] [blame] | 30 | set(PACKAGE_BUGREPORT "[email protected]") |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 31 | |
Martell Malone | 062f8f0 | 2017-06-01 00:09:20 | [diff] [blame] | 32 | # Find the LLVM sources and simulate LLVM CMake options. |
| 33 | include(HandleOutOfTreeLLVM) |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 34 | endif() |
| 35 | |
Martell Malone | 062f8f0 | 2017-06-01 00:09:20 | [diff] [blame] | 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 | |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 43 | #=============================================================================== |
| 44 | # Setup CMake Options |
| 45 | #=============================================================================== |
Martell Malone | 062f8f0 | 2017-06-01 00:09:20 | [diff] [blame] | 46 | include(CMakeDependentOption) |
Petr Hosek | 5f3d5be | 2017-04-07 20:10:41 | [diff] [blame] | 47 | include(HandleCompilerRT) |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 48 | |
| 49 | # Define options. |
Petr Hosek | 2e398f1 | 2019-07-12 19:10:59 | [diff] [blame] | 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) |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 53 | option(LIBCXXABI_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON) |
| 54 | option(LIBCXXABI_ENABLE_PEDANTIC "Compile with pedantic enabled." ON) |
Sam Clegg | 31d7394 | 2019-04-03 00:34:12 | [diff] [blame] | 55 | option(LIBCXXABI_ENABLE_PIC "Build Position-Independent Code, even in static library" ON) |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 56 | option(LIBCXXABI_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) |
Saleem Abdulrasool | e5f6e2b | 2015-04-28 02:09:53 | [diff] [blame] | 57 | option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF) |
Petr Hosek | ef6f231 | 2017-02-09 02:19:30 | [diff] [blame] | 58 | option(LIBCXXABI_ENABLE_STATIC_UNWINDER "Statically link the LLVM unwinder." OFF) |
Saleem Abdulrasool | 6e2aa5e | 2016-07-15 00:49:42 | [diff] [blame] | 59 | option(LIBCXXABI_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF) |
Eric Fiselier | 559f867 | 2014-11-24 22:42:03 | [diff] [blame] | 60 | option(LIBCXXABI_ENABLE_THREADS "Build with threads enabled" ON) |
Ben Craig | 24a9861 | 2016-05-25 17:37:38 | [diff] [blame] | 61 | option(LIBCXXABI_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF) |
Asiri Rathnayake | 97ba9fa | 2017-01-03 12:58:34 | [diff] [blame] | 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) |
Asiri Rathnayake | a573fe2 | 2017-01-09 11:57:21 | [diff] [blame] | 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) |
Eric Fiselier | 38643b9 | 2017-03-02 21:55:17 | [diff] [blame] | 68 | |
| 69 | # FIXME: This option should default to off. Unfortunatly GCC 4.9 fails to link |
| 70 | # programs to due undefined references to new/delete in libc++abi. Once this |
| 71 | # has been fixed or worked around the default value should be changed. |
Eric Fiselier | 2ee1d90 | 2017-03-02 19:34:35 | [diff] [blame] | 72 | option(LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS |
| 73 | "Build libc++abi with definitions for operator new/delete. Normally libc++ |
Eric Fiselier | 38643b9 | 2017-03-02 21:55:17 | [diff] [blame] | 74 | provides these definitions" ON) |
Eric Fiselier | ffd1893 | 2016-06-02 02:18:31 | [diff] [blame] | 75 | option(LIBCXXABI_BUILD_32_BITS "Build 32 bit libc++abi." ${LLVM_BUILD_32_BITS}) |
Bryant Wong | 66b5441 | 2017-01-07 22:14:04 | [diff] [blame] | 76 | option(LIBCXXABI_INCLUDE_TESTS "Generate build targets for the libc++abi unit tests." ${LLVM_INCLUDE_TESTS}) |
Ismail Donmez | dea7590 | 2017-06-13 08:16:44 | [diff] [blame] | 77 | set(LIBCXXABI_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING |
| 78 | "Define suffix of library directory name (32/64)") |
Petr Hosek | aa96d2e | 2017-11-17 23:25:09 | [diff] [blame] | 79 | option(LIBCXXABI_INSTALL_LIBRARY "Install the libc++abi library." ON) |
Eric Fiselier | ffd1893 | 2016-06-02 02:18:31 | [diff] [blame] | 80 | set(LIBCXXABI_TARGET_TRIPLE "" CACHE STRING "Target triple for cross compiling.") |
Ben Craig | 658310b | 2016-06-01 12:50:30 | [diff] [blame] | 81 | set(LIBCXXABI_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.") |
| 82 | set(LIBCXXABI_SYSROOT "" CACHE PATH "Sysroot for cross compiling.") |
| 83 | set(LIBCXXABI_LIBCXX_LIBRARY_PATH "" CACHE PATH "The path to libc++ library.") |
Louis Dionne | be52ff9 | 2019-10-07 19:22:04 | [diff] [blame] | 84 | set(LIBCXXABI_LIBRARY_VERSION "1.0" CACHE STRING |
| 85 | "Version of libc++abi. This will be reflected in the name of the shared \ |
| 86 | library produced. For example, -DLIBCXXABI_LIBRARY_VERSION=x.y will \ |
| 87 | result in the library being named libc++abi.x.y.dylib, along with the \ |
| 88 | usual symlinks pointing to that.") |
Dan Albert | a770f9d | 2014-07-10 02:20:11 | [diff] [blame] | 89 | |
| 90 | # Default to building a shared library so that the default options still test |
| 91 | # the libc++abi that is being built. There are two problems with testing a |
| 92 | # static libc++abi. In the case of a standalone build, the tests will link the |
| 93 | # system's libc++, which might not have been built against our libc++abi. In the |
| 94 | # case of an in tree build, libc++ will prefer a dynamic libc++abi from the |
| 95 | # system over a static libc++abi from the output directory. |
| 96 | option(LIBCXXABI_ENABLE_SHARED "Build libc++abi as a shared library." ON) |
Eric Fiselier | 14dbeaa | 2015-03-03 15:59:09 | [diff] [blame] | 97 | option(LIBCXXABI_ENABLE_STATIC "Build libc++abi as a static library." ON) |
| 98 | |
Sam Clegg | 77c99ee | 2018-07-25 23:13:00 | [diff] [blame] | 99 | cmake_dependent_option(LIBCXXABI_INSTALL_STATIC_LIBRARY |
| 100 | "Install the static libc++abi library." ON |
| 101 | "LIBCXXABI_ENABLE_STATIC;LIBCXXABI_INSTALL_LIBRARY" OFF) |
| 102 | cmake_dependent_option(LIBCXXABI_INSTALL_SHARED_LIBRARY |
| 103 | "Install the shared libc++abi library." ON |
| 104 | "LIBCXXABI_ENABLE_SHARED;LIBCXXABI_INSTALL_LIBRARY" OFF) |
| 105 | |
Petr Hosek | 058c04c | 2018-07-24 07:06:17 | [diff] [blame] | 106 | cmake_dependent_option(LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY |
| 107 | "Statically link the LLVM unwinder to static library" ON |
| 108 | "LIBCXXABI_ENABLE_STATIC_UNWINDER;LIBCXXABI_ENABLE_STATIC" OFF) |
| 109 | cmake_dependent_option(LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY |
| 110 | "Statically link the LLVM unwinder to shared library" ON |
| 111 | "LIBCXXABI_ENABLE_STATIC_UNWINDER;LIBCXXABI_ENABLE_SHARED" OFF) |
| 112 | |
Ranjeet Singh | ef6e672 | 2017-03-01 11:42:01 | [diff] [blame] | 113 | option(LIBCXXABI_BAREMETAL "Build libc++abi for baremetal targets." OFF) |
| 114 | # The default terminate handler attempts to demangle uncaught exceptions, which |
| 115 | # causes extra I/O and demangling code to be pulled in. |
| 116 | option(LIBCXXABI_SILENT_TERMINATE "Set this to make the terminate handler default to a silent alternative" OFF) |
| 117 | |
Eric Fiselier | 14dbeaa | 2015-03-03 15:59:09 | [diff] [blame] | 118 | if (NOT LIBCXXABI_ENABLE_SHARED AND NOT LIBCXXABI_ENABLE_STATIC) |
| 119 | message(FATAL_ERROR "libc++abi must be built as either a shared or static library.") |
| 120 | endif() |
Dan Albert | a770f9d | 2014-07-10 02:20:11 | [diff] [blame] | 121 | |
Mehdi Amini | c1f152d | 2016-11-07 22:07:43 | [diff] [blame] | 122 | if (LLVM_EXTERNAL_LIBCXX_SOURCE_DIR) |
Petr Hosek | bfb371a | 2016-11-11 19:12:58 | [diff] [blame] | 123 | set(LIBCXXABI_LIBCXX_SRC_DIRS ${LLVM_EXTERNAL_LIBCXX_SOURCE_DIR}) |
Mehdi Amini | c1f152d | 2016-11-07 22:07:43 | [diff] [blame] | 124 | else() |
Petr Hosek | bfb371a | 2016-11-11 19:12:58 | [diff] [blame] | 125 | set(LIBCXXABI_LIBCXX_SRC_DIRS |
| 126 | "${LLVM_MAIN_SRC_DIR}/projects/libcxx" |
| 127 | "${LLVM_MAIN_SRC_DIR}/runtimes/libcxx" |
Petr Hosek | 86a9ddc | 2018-04-04 17:40:59 | [diff] [blame] | 128 | "${LLVM_MAIN_SRC_DIR}/../libcxx" |
Petr Hosek | bfb371a | 2016-11-11 19:12:58 | [diff] [blame] | 129 | ) |
Mehdi Amini | c1f152d | 2016-11-07 22:07:43 | [diff] [blame] | 130 | endif() |
| 131 | |
Petr Hosek | bfb371a | 2016-11-11 19:12:58 | [diff] [blame] | 132 | set(LIBCXXABI_LIBCXX_INCLUDE_DIRS "") |
| 133 | foreach(dir ${LIBCXXABI_LIBCXX_SRC_DIRS}) |
| 134 | list(APPEND LIBCXXABI_LIBCXX_INCLUDE_DIRS "${dir}/include") |
| 135 | endforeach() |
| 136 | |
Dan Albert | a770f9d | 2014-07-10 02:20:11 | [diff] [blame] | 137 | find_path( |
| 138 | LIBCXXABI_LIBCXX_INCLUDES |
Shoaib Meenai | 51d5cc9 | 2018-06-30 01:25:47 | [diff] [blame] | 139 | __config |
Dan Albert | a770f9d | 2014-07-10 02:20:11 | [diff] [blame] | 140 | PATHS ${LIBCXXABI_LIBCXX_INCLUDES} |
Eric Fiselier | 753f7c3 | 2015-01-22 20:00:06 | [diff] [blame] | 141 | ${LIBCXXABI_LIBCXX_PATH}/include |
Dan Albert | a770f9d | 2014-07-10 02:20:11 | [diff] [blame] | 142 | ${CMAKE_BINARY_DIR}/${LIBCXXABI_LIBCXX_INCLUDES} |
Petr Hosek | bfb371a | 2016-11-11 19:12:58 | [diff] [blame] | 143 | ${LIBCXXABI_LIBCXX_INCLUDE_DIRS} |
Dan Albert | a770f9d | 2014-07-10 02:20:11 | [diff] [blame] | 144 | ${LLVM_INCLUDE_DIR}/c++/v1 |
Shoaib Meenai | 777ec37 | 2018-06-30 01:04:50 | [diff] [blame] | 145 | NO_DEFAULT_PATH |
Don Hinton | ae858bf | 2018-01-22 19:41:05 | [diff] [blame] | 146 | NO_CMAKE_FIND_ROOT_PATH |
Dan Albert | a770f9d | 2014-07-10 02:20:11 | [diff] [blame] | 147 | ) |
| 148 | |
Eric Fiselier | 753f7c3 | 2015-01-22 20:00:06 | [diff] [blame] | 149 | set(LIBCXXABI_LIBCXX_INCLUDES "${LIBCXXABI_LIBCXX_INCLUDES}" CACHE PATH |
Dan Albert | a770f9d | 2014-07-10 02:20:11 | [diff] [blame] | 150 | "Specify path to libc++ includes." FORCE) |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 151 | |
Eric Fiselier | 753f7c3 | 2015-01-22 20:00:06 | [diff] [blame] | 152 | find_path( |
| 153 | LIBCXXABI_LIBCXX_PATH |
Petr Hosek | 460af4b | 2017-02-18 04:37:59 | [diff] [blame] | 154 | utils/libcxx/test/__init__.py |
Eric Fiselier | 753f7c3 | 2015-01-22 20:00:06 | [diff] [blame] | 155 | PATHS ${LIBCXXABI_LIBCXX_PATH} |
| 156 | ${LIBCXXABI_LIBCXX_INCLUDES}/../ |
Petr Hosek | bfb371a | 2016-11-11 19:12:58 | [diff] [blame] | 157 | ${LIBCXXABI_LIBCXX_SRC_DIRS} |
Eric Fiselier | 753f7c3 | 2015-01-22 20:00:06 | [diff] [blame] | 158 | NO_DEFAULT_PATH |
Don Hinton | ae858bf | 2018-01-22 19:41:05 | [diff] [blame] | 159 | NO_CMAKE_FIND_ROOT_PATH |
Eric Fiselier | 753f7c3 | 2015-01-22 20:00:06 | [diff] [blame] | 160 | ) |
| 161 | |
| 162 | if (LIBCXXABI_LIBCXX_PATH STREQUAL "LIBCXXABI_LIBCXX_PATH-NOTFOUND") |
| 163 | message(WARNING "LIBCXXABI_LIBCXX_PATH was not specified and couldn't be infered.") |
| 164 | set(LIBCXXABI_LIBCXX_PATH "") |
| 165 | endif() |
| 166 | |
| 167 | set(LIBCXXABI_LIBCXX_PATH "${LIBCXXABI_LIBCXX_PATH}" CACHE PATH |
| 168 | "Specify path to libc++ source." FORCE) |
| 169 | |
Petr Hosek | 8807db3 | 2019-01-24 03:18:29 | [diff] [blame] | 170 | option(LIBCXXABI_HERMETIC_STATIC_LIBRARY |
| 171 | "Do not export any symbols from the static library." OFF) |
| 172 | |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 173 | #=============================================================================== |
| 174 | # Configure System |
| 175 | #=============================================================================== |
| 176 | |
| 177 | # Add path for custom modules |
| 178 | set(CMAKE_MODULE_PATH |
| 179 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake" |
| 180 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" |
| 181 | ${CMAKE_MODULE_PATH} |
| 182 | ) |
| 183 | |
Chandler Carruth | 24a6b05 | 2014-12-29 12:22:04 | [diff] [blame] | 184 | set(LIBCXXABI_COMPILER ${CMAKE_CXX_COMPILER}) |
| 185 | set(LIBCXXABI_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 186 | set(LIBCXXABI_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
Petr Hosek | 887f26d | 2018-06-28 03:11:52 | [diff] [blame] | 187 | |
| 188 | string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION |
| 189 | ${PACKAGE_VERSION}) |
| 190 | |
| 191 | if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) |
Petr Hosek | 81f433b | 2019-05-22 21:08:33 | [diff] [blame] | 192 | set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) |
| 193 | set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) |
| 194 | if(LIBCXX_LIBDIR_SUBDIR) |
| 195 | string(APPEND LIBCXXABI_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR}) |
| 196 | string(APPEND LIBCXXABI_INSTALL_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR}) |
| 197 | endif() |
Petr Hosek | 887f26d | 2018-06-28 03:11:52 | [diff] [blame] | 198 | elseif(LLVM_LIBRARY_OUTPUT_INTDIR) |
Jonas Hahnfeld | 57aa0d4 | 2017-05-04 06:04:49 | [diff] [blame] | 199 | set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) |
Petr Hosek | 81f433b | 2019-05-22 21:08:33 | [diff] [blame] | 200 | set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX}) |
Jonas Hahnfeld | 57aa0d4 | 2017-05-04 06:04:49 | [diff] [blame] | 201 | else() |
Petr Hosek | cbb4313 | 2018-07-25 16:51:00 | [diff] [blame] | 202 | set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX}) |
Petr Hosek | 81f433b | 2019-05-22 21:08:33 | [diff] [blame] | 203 | set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX}) |
Jonas Hahnfeld | 57aa0d4 | 2017-05-04 06:04:49 | [diff] [blame] | 204 | endif() |
Chandler Carruth | 24a6b05 | 2014-12-29 12:22:04 | [diff] [blame] | 205 | |
Petr Hosek | 81f433b | 2019-05-22 21:08:33 | [diff] [blame] | 206 | set(LIBCXXABI_INSTALL_PREFIX "" CACHE STRING "Define libc++abi destination prefix.") |
Petr Hosek | 60fe579 | 2017-07-11 01:42:26 | [diff] [blame] | 207 | |
Ben Craig | ab56c40 | 2016-04-18 13:30:38 | [diff] [blame] | 208 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR}) |
| 209 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR}) |
Martell Malone | 062f8f0 | 2017-06-01 00:09:20 | [diff] [blame] | 210 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR}) |
Ben Craig | ab56c40 | 2016-04-18 13:30:38 | [diff] [blame] | 211 | |
Ben Craig | 658310b | 2016-06-01 12:50:30 | [diff] [blame] | 212 | # By default, for non-standalone builds, libcxx and libcxxabi share a library |
| 213 | # directory. |
| 214 | if (NOT LIBCXXABI_LIBCXX_LIBRARY_PATH) |
| 215 | set(LIBCXXABI_LIBCXX_LIBRARY_PATH "${LIBCXXABI_LIBRARY_DIR}" CACHE PATH |
Sergej Jaskiewicz | fb76c79 | 2019-12-26 09:28:39 | [diff] [blame] | 216 | "The path to libc++ library." FORCE) |
Eugene Zelenko | 9d09275 | 2016-08-08 17:59:02 | [diff] [blame] | 217 | endif() |
Eric Fiselier | ffd1893 | 2016-06-02 02:18:31 | [diff] [blame] | 218 | |
| 219 | # Check that we can build with 32 bits if requested. |
| 220 | if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32) |
| 221 | if (LIBCXXABI_BUILD_32_BITS AND NOT LLVM_BUILD_32_BITS) # Don't duplicate the output from LLVM |
| 222 | message(STATUS "Building 32 bits executables and libraries.") |
| 223 | endif() |
| 224 | elseif(LIBCXXABI_BUILD_32_BITS) |
| 225 | message(FATAL_ERROR "LIBCXXABI_BUILD_32_BITS=ON is not supported on this platform.") |
| 226 | endif() |
| 227 | |
Martell Malone | 062f8f0 | 2017-06-01 00:09:20 | [diff] [blame] | 228 | # Declare libc++abi configuration variables. |
| 229 | # They are intended for use as follows: |
| 230 | # LIBCXXABI_C_FLAGS: General flags for both the c++ compiler and linker. |
| 231 | # LIBCXXABI_CXX_FLAGS: General flags for both the c++ compiler and linker. |
| 232 | # LIBCXXABI_COMPILE_FLAGS: Compile only flags. |
| 233 | # LIBCXXABI_LINK_FLAGS: Linker only flags. |
| 234 | # LIBCXXABI_LIBRARIES: libraries libc++abi is linked to. |
Eric Fiselier | ffd1893 | 2016-06-02 02:18:31 | [diff] [blame] | 235 | |
Logan Chien | dbcd7a3 | 2015-01-22 13:39:08 | [diff] [blame] | 236 | set(LIBCXXABI_C_FLAGS "") |
Eric Fiselier | 5cb5051 | 2014-11-18 20:37:53 | [diff] [blame] | 237 | set(LIBCXXABI_CXX_FLAGS "") |
| 238 | set(LIBCXXABI_COMPILE_FLAGS "") |
| 239 | set(LIBCXXABI_LINK_FLAGS "") |
Martell Malone | 062f8f0 | 2017-06-01 00:09:20 | [diff] [blame] | 240 | set(LIBCXXABI_LIBRARIES "") |
| 241 | |
| 242 | # Include macros for adding and removing libc++abi flags. |
| 243 | include(HandleLibcxxabiFlags) |
| 244 | |
| 245 | #=============================================================================== |
| 246 | # Setup Compiler Flags |
| 247 | #=============================================================================== |
Eric Fiselier | 5cb5051 | 2014-11-18 20:37:53 | [diff] [blame] | 248 | |
Eric Fiselier | ffd1893 | 2016-06-02 02:18:31 | [diff] [blame] | 249 | # Configure target flags |
| 250 | add_target_flags_if(LIBCXXABI_BUILD_32_BITS "-m32") |
Petr Hosek | 6fd4e7f | 2019-02-04 20:02:26 | [diff] [blame] | 251 | |
| 252 | if(LIBCXXABI_TARGET_TRIPLE) |
| 253 | add_target_flags("--target=${LIBCXXABI_TARGET_TRIPLE}") |
| 254 | elseif(CMAKE_CXX_COMPILER_TARGET) |
| 255 | set(LIBCXXABI_TARGET_TRIPLE "${CMAKE_CXX_COMPILER_TARGET}") |
| 256 | endif() |
| 257 | if(LIBCXX_GCC_TOOLCHAIN) |
| 258 | add_target_flags("--gcc-toolchain=${LIBCXXABI_GCC_TOOLCHAIN}") |
| 259 | elseif(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN) |
| 260 | set(LIBCXXABI_GCC_TOOLCHAIN "${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}") |
| 261 | endif() |
| 262 | if(LIBCXXABI_SYSROOT) |
| 263 | add_target_flags("--sysroot=${LIBCXXABI_SYSROOT}") |
| 264 | elseif(CMAKE_SYSROOT) |
| 265 | set(LIBCXXABI_SYSROOT "${CMAKE_SYSROOT}") |
| 266 | endif() |
Eric Fiselier | ffd1893 | 2016-06-02 02:18:31 | [diff] [blame] | 267 | |
Eric Fiselier | 79ff8f03 | 2016-11-13 22:27:00 | [diff] [blame] | 268 | if (LIBCXXABI_TARGET_TRIPLE) |
| 269 | set(TARGET_TRIPLE "${LIBCXXABI_TARGET_TRIPLE}") |
| 270 | endif() |
| 271 | |
Eric Fiselier | ffd1893 | 2016-06-02 02:18:31 | [diff] [blame] | 272 | # Configure compiler. Must happen after setting the target flags. |
| 273 | include(config-ix) |
Eric Fiselier | 5cb5051 | 2014-11-18 20:37:53 | [diff] [blame] | 274 | |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 275 | if (LIBCXXABI_HAS_NOSTDINCXX_FLAG) |
Eric Fiselier | 5cb5051 | 2014-11-18 20:37:53 | [diff] [blame] | 276 | list(APPEND LIBCXXABI_COMPILE_FLAGS -nostdinc++) |
Sam Clegg | 4230fa9 | 2019-11-07 22:51:25 | [diff] [blame] | 277 | # cmake 3.14 and above remove system include paths that are explicitly |
| 278 | # passed on the command line. We build with -nostdinc++ and explicitly add |
| 279 | # just the libcxx system include paths with -I on the command line. |
| 280 | # Setting CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES effectively prevents cmake |
| 281 | # from removing these. |
| 282 | # See: https://gitlab.kitware.com/cmake/cmake/issues/19227 |
| 283 | set(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES "") |
Eric Fiselier | 5cb5051 | 2014-11-18 20:37:53 | [diff] [blame] | 284 | # Remove -stdlib flags to prevent them from causing an unused flag warning. |
| 285 | string(REPLACE "-stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 286 | string(REPLACE "-stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 287 | endif() |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 288 | |
Shoaib Meenai | 88c6acf | 2016-09-27 03:44:09 | [diff] [blame] | 289 | # Let the library headers know they are currently being used to build the |
| 290 | # library. |
| 291 | add_definitions(-D_LIBCXXABI_BUILDING_LIBRARY) |
| 292 | |
| 293 | # Disable DLL annotations on Windows for static builds. |
| 294 | if (WIN32 AND LIBCXXABI_ENABLE_STATIC AND NOT LIBCXXABI_ENABLE_SHARED) |
Martell Malone | 41119cd | 2017-05-28 22:46:50 | [diff] [blame] | 295 | add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS) |
Shoaib Meenai | 88c6acf | 2016-09-27 03:44:09 | [diff] [blame] | 296 | endif() |
| 297 | |
Martell Malone | 062f8f0 | 2017-06-01 00:09:20 | [diff] [blame] | 298 | add_compile_flags_if_supported(-Werror=return-type) |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 299 | |
| 300 | # Get warning flags |
Martell Malone | 062f8f0 | 2017-06-01 00:09:20 | [diff] [blame] | 301 | add_compile_flags_if_supported(-W) |
| 302 | add_compile_flags_if_supported(-Wall) |
| 303 | add_compile_flags_if_supported(-Wchar-subscripts) |
| 304 | add_compile_flags_if_supported(-Wconversion) |
| 305 | add_compile_flags_if_supported(-Wmismatched-tags) |
| 306 | add_compile_flags_if_supported(-Wmissing-braces) |
| 307 | add_compile_flags_if_supported(-Wnewline-eof) |
| 308 | add_compile_flags_if_supported(-Wunused-function) |
| 309 | add_compile_flags_if_supported(-Wshadow) |
| 310 | add_compile_flags_if_supported(-Wshorten-64-to-32) |
| 311 | add_compile_flags_if_supported(-Wsign-compare) |
| 312 | add_compile_flags_if_supported(-Wsign-conversion) |
| 313 | add_compile_flags_if_supported(-Wstrict-aliasing=2) |
| 314 | add_compile_flags_if_supported(-Wstrict-overflow=4) |
| 315 | add_compile_flags_if_supported(-Wunused-parameter) |
| 316 | add_compile_flags_if_supported(-Wunused-variable) |
| 317 | add_compile_flags_if_supported(-Wwrite-strings) |
| 318 | add_compile_flags_if_supported(-Wundef) |
Dan Albert | 3c4780e | 2014-07-10 22:23:03 | [diff] [blame] | 319 | |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 320 | if (LIBCXXABI_ENABLE_WERROR) |
Martell Malone | 062f8f0 | 2017-06-01 00:09:20 | [diff] [blame] | 321 | add_compile_flags_if_supported(-Werror) |
| 322 | add_compile_flags_if_supported(-WX) |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 323 | else() |
Martell Malone | 062f8f0 | 2017-06-01 00:09:20 | [diff] [blame] | 324 | add_compile_flags_if_supported(-Wno-error) |
| 325 | add_compile_flags_if_supported(-WX-) |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 326 | endif() |
| 327 | if (LIBCXXABI_ENABLE_PEDANTIC) |
Martell Malone | 062f8f0 | 2017-06-01 00:09:20 | [diff] [blame] | 328 | add_compile_flags_if_supported(-pedantic) |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 329 | endif() |
| 330 | |
| 331 | # Get feature flags. |
Martell Malone | 062f8f0 | 2017-06-01 00:09:20 | [diff] [blame] | 332 | add_compile_flags_if_supported(-fstrict-aliasing) |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 333 | |
Asiri Rathnayake | 57e446d | 2016-05-31 12:01:32 | [diff] [blame] | 334 | # Exceptions |
| 335 | if (LIBCXXABI_ENABLE_EXCEPTIONS) |
| 336 | # Catches C++ exceptions only and tells the compiler to assume that extern C |
| 337 | # functions never throw a C++ exception. |
Martell Malone | 062f8f0 | 2017-06-01 00:09:20 | [diff] [blame] | 338 | add_compile_flags_if_supported(-EHsc) |
| 339 | # Do we really need to be run through the C compiler ? |
| 340 | add_c_compile_flags_if_supported(-funwind-tables) |
Asiri Rathnayake | 57e446d | 2016-05-31 12:01:32 | [diff] [blame] | 341 | else() |
| 342 | add_definitions(-D_LIBCXXABI_NO_EXCEPTIONS) |
Martell Malone | 062f8f0 | 2017-06-01 00:09:20 | [diff] [blame] | 343 | add_compile_flags_if_supported(-fno-exceptions) |
| 344 | add_compile_flags_if_supported(-EHs-) |
| 345 | add_compile_flags_if_supported(-EHa-) |
Asiri Rathnayake | 57e446d | 2016-05-31 12:01:32 | [diff] [blame] | 346 | endif() |
Logan Chien | dbcd7a3 | 2015-01-22 13:39:08 | [diff] [blame] | 347 | |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 348 | # Assert |
| 349 | string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) |
| 350 | if (LIBCXXABI_ENABLE_ASSERTIONS) |
| 351 | # MSVC doesn't like _DEBUG on release builds. See PR 4379. |
| 352 | if (NOT MSVC) |
Eric Fiselier | 5cb5051 | 2014-11-18 20:37:53 | [diff] [blame] | 353 | list(APPEND LIBCXXABI_COMPILE_FLAGS -D_DEBUG) |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 354 | endif() |
| 355 | # On Release builds cmake automatically defines NDEBUG, so we |
| 356 | # explicitly undefine it: |
| 357 | if (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE") |
Eric Fiselier | 5cb5051 | 2014-11-18 20:37:53 | [diff] [blame] | 358 | list(APPEND LIBCXXABI_COMPILE_FLAGS -UNDEBUG) |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 359 | endif() |
| 360 | else() |
| 361 | if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE") |
Eric Fiselier | 5cb5051 | 2014-11-18 20:37:53 | [diff] [blame] | 362 | list(APPEND LIBCXXABI_COMPILE_FLAGS -DNDEBUG) |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 363 | endif() |
| 364 | endif() |
| 365 | # Static library |
| 366 | if (NOT LIBCXXABI_ENABLE_SHARED) |
Eric Fiselier | 5cb5051 | 2014-11-18 20:37:53 | [diff] [blame] | 367 | list(APPEND LIBCXXABI_COMPILE_FLAGS -D_LIBCPP_BUILD_STATIC) |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 368 | endif() |
| 369 | |
Asiri Rathnayake | 97ba9fa | 2017-01-03 12:58:34 | [diff] [blame] | 370 | # Threading |
Eric Fiselier | 559f867 | 2014-11-24 22:42:03 | [diff] [blame] | 371 | if (NOT LIBCXXABI_ENABLE_THREADS) |
Ben Craig | 24a9861 | 2016-05-25 17:37:38 | [diff] [blame] | 372 | if (LIBCXXABI_HAS_PTHREAD_API) |
| 373 | message(FATAL_ERROR "LIBCXXABI_HAS_PTHREAD_API can only" |
| 374 | " be set to ON when LIBCXXABI_ENABLE_THREADS" |
| 375 | " is also set to ON.") |
| 376 | endif() |
Asiri Rathnayake | 97ba9fa | 2017-01-03 12:58:34 | [diff] [blame] | 377 | if (LIBCXXABI_HAS_EXTERNAL_THREAD_API) |
| 378 | message(FATAL_ERROR "LIBCXXABI_HAS_EXTERNAL_THREAD_API can only" |
| 379 | " be set to ON when LIBCXXABI_ENABLE_THREADS" |
| 380 | " is also set to ON.") |
| 381 | endif() |
Asiri Rathnayake | a573fe2 | 2017-01-09 11:57:21 | [diff] [blame] | 382 | if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY) |
| 383 | message(FATAL_ERROR "LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY can only" |
| 384 | " be set to ON when LIBCXXABI_ENABLE_THREADS" |
| 385 | " is also set to ON.") |
| 386 | endif() |
Asiri Rathnayake | 7c98baa | 2016-09-21 09:09:32 | [diff] [blame] | 387 | add_definitions(-D_LIBCXXABI_HAS_NO_THREADS) |
Eric Fiselier | 559f867 | 2014-11-24 22:42:03 | [diff] [blame] | 388 | endif() |
| 389 | |
Asiri Rathnayake | a573fe2 | 2017-01-09 11:57:21 | [diff] [blame] | 390 | if (LIBCXXABI_HAS_EXTERNAL_THREAD_API) |
| 391 | if (LIBCXXABI_HAS_PTHREAD_API) |
| 392 | message(FATAL_ERROR "The options LIBCXXABI_HAS_EXTERNAL_THREAD_API" |
| 393 | " and LIBCXXABI_HAS_PTHREAD_API cannot be both" |
| 394 | " set to ON at the same time.") |
| 395 | endif() |
| 396 | if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY) |
| 397 | message(FATAL_ERROR "The options LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY" |
| 398 | " and LIBCXXABI_HAS_EXTERNAL_THREAD_API cannot be both" |
| 399 | " set to ON at the same time.") |
| 400 | endif() |
Asiri Rathnayake | 97ba9fa | 2017-01-03 12:58:34 | [diff] [blame] | 401 | endif() |
| 402 | |
NAKAMURA Takumi | 83105a4 | 2017-07-31 09:35:08 | [diff] [blame] | 403 | if (LLVM_ENABLE_MODULES) |
| 404 | # Ignore that the rest of the modules flags are now unused. |
| 405 | add_compile_flags_if_supported(-Wno-unused-command-line-argument) |
| 406 | add_compile_flags(-fno-modules) |
| 407 | endif() |
| 408 | |
Eric Fiselier | 6f8d62d | 2017-03-04 02:15:37 | [diff] [blame] | 409 | set(LIBCXXABI_HAS_UNDEFINED_SYMBOLS OFF) |
| 410 | if ((NOT LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS) |
Eric Fiselier | 70c2b1c | 2017-05-11 03:49:48 | [diff] [blame] | 411 | OR (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY AND LIBCXXABI_ENABLE_SHARED) |
| 412 | OR MINGW) |
Eric Fiselier | 6f8d62d | 2017-03-04 02:15:37 | [diff] [blame] | 413 | set(LIBCXXABI_HAS_UNDEFINED_SYMBOLS ON) |
| 414 | endif() |
Eric Fiselier | 2ee1d90 | 2017-03-02 19:34:35 | [diff] [blame] | 415 | |
| 416 | if (LIBCXXABI_HAS_UNDEFINED_SYMBOLS) |
Asiri Rathnayake | 97ba9fa | 2017-01-03 12:58:34 | [diff] [blame] | 417 | # Need to allow unresolved symbols if this is to work with shared library builds |
| 418 | if (APPLE) |
Eric Fiselier | 6f8d62d | 2017-03-04 02:15:37 | [diff] [blame] | 419 | list(APPEND LIBCXXABI_LINK_FLAGS "-undefined dynamic_lookup") |
Asiri Rathnayake | 97ba9fa | 2017-01-03 12:58:34 | [diff] [blame] | 420 | else() |
| 421 | # Relax this restriction from HandleLLVMOptions |
| 422 | string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") |
| 423 | endif() |
| 424 | endif() |
| 425 | |
Ben Craig | 24a9861 | 2016-05-25 17:37:38 | [diff] [blame] | 426 | if (LIBCXXABI_HAS_PTHREAD_API) |
| 427 | add_definitions(-D_LIBCPP_HAS_THREAD_API_PTHREAD) |
| 428 | endif() |
| 429 | |
Asiri Rathnayake | 97ba9fa | 2017-01-03 12:58:34 | [diff] [blame] | 430 | if (LIBCXXABI_HAS_EXTERNAL_THREAD_API) |
Asiri Rathnayake | a573fe2 | 2017-01-09 11:57:21 | [diff] [blame] | 431 | add_definitions(-D_LIBCPP_HAS_THREAD_API_EXTERNAL) |
| 432 | endif() |
| 433 | |
| 434 | if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY) |
| 435 | add_definitions(-D_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) |
Asiri Rathnayake | 97ba9fa | 2017-01-03 12:58:34 | [diff] [blame] | 436 | endif() |
| 437 | |
Shoaib Meenai | f43726c | 2017-05-10 21:52:39 | [diff] [blame] | 438 | # Prevent libc++abi from having library dependencies on libc++ |
| 439 | add_definitions(-D_LIBCPP_DISABLE_EXTERN_TEMPLATE) |
| 440 | |
Nico Weber | 297ec32 | 2018-04-29 23:05:11 | [diff] [blame] | 441 | # Bring back `std::unexpected`, which is removed in C++17, to support |
| 442 | # pre-C++17. |
| 443 | add_definitions(-D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS) |
| 444 | |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 445 | if (MSVC) |
| 446 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) |
| 447 | endif() |
| 448 | |
Logan Chien | 4947eb6 | 2015-01-22 13:27:36 | [diff] [blame] | 449 | # Define LIBCXXABI_USE_LLVM_UNWINDER for conditional compilation. |
Logan Chien | 71cdd30 | 2016-11-13 14:42:15 | [diff] [blame] | 450 | if (LIBCXXABI_USE_LLVM_UNWINDER) |
Ranjeet Singh | ef6e672 | 2017-03-01 11:42:01 | [diff] [blame] | 451 | add_definitions(-DLIBCXXABI_USE_LLVM_UNWINDER) |
Logan Chien | 4947eb6 | 2015-01-22 13:27:36 | [diff] [blame] | 452 | endif() |
| 453 | |
James Y Knight | 0d3145f | 2017-01-13 19:22:26 | [diff] [blame] | 454 | if (LIBCXXABI_SILENT_TERMINATE) |
Ranjeet Singh | ef6e672 | 2017-03-01 11:42:01 | [diff] [blame] | 455 | add_definitions(-DLIBCXXABI_SILENT_TERMINATE) |
| 456 | endif() |
| 457 | |
| 458 | if (LIBCXXABI_BAREMETAL) |
| 459 | add_definitions(-DLIBCXXABI_BAREMETAL) |
James Y Knight | 0d3145f | 2017-01-13 19:22:26 | [diff] [blame] | 460 | endif() |
| 461 | |
Petr Hosek | 789b7f0 | 2019-05-30 04:40:21 | [diff] [blame] | 462 | if (LIBCXXABI_HAS_COMMENT_LIB_PRAGMA) |
Michał Górny | a9b5fff | 2019-12-02 10:49:20 | [diff] [blame] | 463 | if (LIBCXXABI_HAS_PTHREAD_LIB) |
| 464 | add_definitions(-D_LIBCXXABI_LINK_PTHREAD_LIB) |
| 465 | endif() |
Petr Hosek | 789b7f0 | 2019-05-30 04:40:21 | [diff] [blame] | 466 | endif() |
| 467 | |
Eric Fiselier | 5cb5051 | 2014-11-18 20:37:53 | [diff] [blame] | 468 | string(REPLACE ";" " " LIBCXXABI_CXX_FLAGS "${LIBCXXABI_CXX_FLAGS}") |
| 469 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXXABI_CXX_FLAGS}") |
Logan Chien | dbcd7a3 | 2015-01-22 13:39:08 | [diff] [blame] | 470 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBCXXABI_C_FLAGS}") |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 471 | |
| 472 | #=============================================================================== |
| 473 | # Setup Source Code |
| 474 | #=============================================================================== |
| 475 | |
Anton Korobeynikov | d3b50dc | 2015-05-08 16:10:11 | [diff] [blame] | 476 | set(LIBCXXABI_LIBUNWIND_INCLUDES "${LIBCXXABI_LIBUNWIND_INCLUDES}" CACHE PATH |
| 477 | "Specify path to libunwind includes." FORCE) |
| 478 | set(LIBCXXABI_LIBUNWIND_PATH "${LIBCXXABI_LIBUNWIND_PATH}" CACHE PATH |
| 479 | "Specify path to libunwind source." FORCE) |
| 480 | |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 481 | include_directories(include) |
Eric Fiselier | 9429684 | 2015-04-29 15:53:03 | [diff] [blame] | 482 | if (LIBCXXABI_USE_LLVM_UNWINDER OR LLVM_NATIVE_ARCH MATCHES ARM) |
Petr Hosek | 4fe63c7 | 2019-05-02 17:29:39 | [diff] [blame] | 483 | find_path(LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL libunwind.h |
Anton Korobeynikov | d3b50dc | 2015-05-08 16:10:11 | [diff] [blame] | 484 | PATHS ${LIBCXXABI_LIBUNWIND_INCLUDES} |
| 485 | ${LIBCXXABI_LIBUNWIND_PATH}/include |
| 486 | ${CMAKE_BINARY_DIR}/${LIBCXXABI_LIBUNWIND_INCLUDES} |
| 487 | ${LLVM_MAIN_SRC_DIR}/projects/libunwind/include |
Petr Hosek | bfb371a | 2016-11-11 19:12:58 | [diff] [blame] | 488 | ${LLVM_MAIN_SRC_DIR}/runtimes/libunwind/include |
Petr Hosek | 86a9ddc | 2018-04-04 17:40:59 | [diff] [blame] | 489 | ${LLVM_MAIN_SRC_DIR}/../libunwind/include |
Anton Korobeynikov | 1af9c7b | 2015-05-09 21:03:01 | [diff] [blame] | 490 | NO_DEFAULT_PATH |
Don Hinton | ae858bf | 2018-01-22 19:41:05 | [diff] [blame] | 491 | NO_CMAKE_FIND_ROOT_PATH |
Anton Korobeynikov | d3b50dc | 2015-05-08 16:10:11 | [diff] [blame] | 492 | ) |
| 493 | |
Asiri Rathnayake | 4cc78d7 | 2017-04-04 14:03:54 | [diff] [blame] | 494 | if (LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL "LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL-NOTFOUND") |
| 495 | set(LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL "") |
| 496 | endif() |
| 497 | |
| 498 | if (NOT LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL "") |
Michal Gorny | 40180b0 | 2017-01-14 17:05:16 | [diff] [blame] | 499 | include_directories("${LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL}") |
| 500 | endif() |
Eugene Zelenko | 9d09275 | 2016-08-08 17:59:02 | [diff] [blame] | 501 | endif() |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 | [diff] [blame] | 502 | |
| 503 | # Add source code. This also contains all of the logic for deciding linker flags |
| 504 | # soname, etc... |
| 505 | add_subdirectory(src) |
Dan Albert | a770f9d | 2014-07-10 02:20:11 | [diff] [blame] | 506 | |
Don Hinton | 964ea50 | 2018-01-18 18:29:36 | [diff] [blame] | 507 | if (LIBCXXABI_INCLUDE_TESTS) |
| 508 | if (LIBCXXABI_STANDALONE_BUILD AND NOT LIBCXXABI_ENABLE_SHARED) |
| 509 | # We can't reasonably test the system C++ library with a static |
| 510 | # libc++abi. We either need to be able to replace libc++abi at |
| 511 | # run time (with a shared libc++abi), or we need to be able to |
| 512 | # replace the C++ runtime (with a non- standalone build). |
| 513 | message(WARNING "The libc++abi tests aren't valid when libc++abi " |
| 514 | "is built standalone (i.e. outside of " |
| 515 | "llvm/projects/libcxxabi ) and is built without " |
| 516 | "a shared library. Either build a shared " |
| 517 | "library, build libc++abi at the same time as " |
| 518 | "you build libc++, or do without testing. No " |
| 519 | "check target will be available!") |
| 520 | else() |
| 521 | add_subdirectory(test) |
| 522 | add_subdirectory(fuzz) |
| 523 | endif() |
Dan Albert | a770f9d | 2014-07-10 02:20:11 | [diff] [blame] | 524 | endif() |