Martell Malone | 380a70a | 2017-06-01 00:09:20 +0000 | [diff] [blame] | 1 | # See www/CMake.html for instructions on how to build libcxxabi with CMake. |
| 2 | |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 3 | #=============================================================================== |
| 4 | # Setup Project |
| 5 | #=============================================================================== |
| 6 | |
Chris Bieneman | 1fc2ce8 | 2016-05-31 20:21:53 +0000 | [diff] [blame] | 7 | cmake_minimum_required(VERSION 3.4.3) |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 8 | |
Eric Fiselier | ff417a5 | 2015-01-26 22:00:30 +0000 | [diff] [blame] | 9 | if(POLICY CMP0042) |
| 10 | cmake_policy(SET CMP0042 NEW) # Set MACOSX_RPATH=YES by default |
| 11 | endif() |
| 12 | |
Petr Hosek | a917419 | 2017-04-07 20:10:41 +0000 | [diff] [blame] | 13 | # Add path for custom modules |
| 14 | set(CMAKE_MODULE_PATH |
| 15 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake" |
| 16 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" |
| 17 | ${CMAKE_MODULE_PATH} |
| 18 | ) |
| 19 | |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 20 | if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) |
Martell Malone | 380a70a | 2017-06-01 00:09:20 +0000 | [diff] [blame] | 21 | project(libcxxabi CXX C) |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 22 | |
| 23 | set(PACKAGE_NAME libcxxabi) |
Hans Wennborg | 7974233 | 2017-01-12 21:36:22 +0000 | [diff] [blame] | 24 | set(PACKAGE_VERSION 5.0.0svn) |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 25 | set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") |
Tanya Lattner | d8093df | 2015-08-05 04:01:26 +0000 | [diff] [blame] | 26 | set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org") |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 27 | |
Martell Malone | 380a70a | 2017-06-01 00:09:20 +0000 | [diff] [blame] | 28 | # Find the LLVM sources and simulate LLVM CMake options. |
| 29 | include(HandleOutOfTreeLLVM) |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 30 | endif() |
| 31 | |
Martell Malone | 380a70a | 2017-06-01 00:09:20 +0000 | [diff] [blame] | 32 | # Require out of source build. |
| 33 | include(MacroEnsureOutOfSourceBuild) |
| 34 | MACRO_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 | |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 39 | #=============================================================================== |
| 40 | # Setup CMake Options |
| 41 | #=============================================================================== |
Martell Malone | 380a70a | 2017-06-01 00:09:20 +0000 | [diff] [blame] | 42 | include(CMakeDependentOption) |
Petr Hosek | a917419 | 2017-04-07 20:10:41 +0000 | [diff] [blame] | 43 | include(HandleCompilerRT) |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 44 | |
| 45 | # Define options. |
Asiri Rathnayake | 4174e8b | 2016-05-31 12:01:32 +0000 | [diff] [blame] | 46 | option(LIBCXXABI_ENABLE_EXCEPTIONS "Use exceptions." ON) |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 47 | option(LIBCXXABI_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON) |
| 48 | option(LIBCXXABI_ENABLE_PEDANTIC "Compile with pedantic enabled." ON) |
| 49 | option(LIBCXXABI_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) |
Saleem Abdulrasool | 352f134 | 2015-04-28 02:09:53 +0000 | [diff] [blame] | 50 | option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF) |
Petr Hosek | b052fac | 2017-02-09 02:19:30 +0000 | [diff] [blame] | 51 | option(LIBCXXABI_ENABLE_STATIC_UNWINDER "Statically link the LLVM unwinder." OFF) |
Saleem Abdulrasool | f0a2620 | 2016-07-15 00:49:42 +0000 | [diff] [blame] | 52 | option(LIBCXXABI_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF) |
Eric Fiselier | d872a69 | 2014-11-24 22:42:03 +0000 | [diff] [blame] | 53 | option(LIBCXXABI_ENABLE_THREADS "Build with threads enabled" ON) |
Ben Craig | b06c53c | 2016-05-25 17:37:38 +0000 | [diff] [blame] | 54 | option(LIBCXXABI_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF) |
Asiri Rathnayake | 71ba287 | 2017-01-03 12:58:34 +0000 | [diff] [blame] | 55 | option(LIBCXXABI_HAS_EXTERNAL_THREAD_API |
| 56 | "Build libc++abi with an externalized threading API. |
| 57 | This option may only be set to ON when LIBCXXABI_ENABLE_THREADS=ON." OFF) |
Asiri Rathnayake | 1f4def2 | 2017-01-09 11:57:21 +0000 | [diff] [blame] | 58 | option(LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY |
| 59 | "Build libc++abi with an externalized threading library. |
| 60 | This option may only be set to ON when LIBCXXABI_ENABLE_THREADS=ON" OFF) |
Eric Fiselier | ed5abb1 | 2017-03-02 21:55:17 +0000 | [diff] [blame] | 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. |
Eric Fiselier | 4841062 | 2017-03-02 19:34:35 +0000 | [diff] [blame] | 65 | option(LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS |
| 66 | "Build libc++abi with definitions for operator new/delete. Normally libc++ |
Eric Fiselier | ed5abb1 | 2017-03-02 21:55:17 +0000 | [diff] [blame] | 67 | provides these definitions" ON) |
Eric Fiselier | 046d2fc | 2016-06-02 02:18:31 +0000 | [diff] [blame] | 68 | option(LIBCXXABI_BUILD_32_BITS "Build 32 bit libc++abi." ${LLVM_BUILD_32_BITS}) |
Bryant Wong | ebc9aca | 2017-01-07 22:14:04 +0000 | [diff] [blame] | 69 | option(LIBCXXABI_INCLUDE_TESTS "Generate build targets for the libc++abi unit tests." ${LLVM_INCLUDE_TESTS}) |
Ismail Donmez | 878d4bb | 2017-06-13 08:16:44 +0000 | [diff] [blame^] | 70 | set(LIBCXXABI_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING |
| 71 | "Define suffix of library directory name (32/64)") |
Eric Fiselier | 046d2fc | 2016-06-02 02:18:31 +0000 | [diff] [blame] | 72 | set(LIBCXXABI_TARGET_TRIPLE "" CACHE STRING "Target triple for cross compiling.") |
Ben Craig | 4ed725d | 2016-06-01 12:50:30 +0000 | [diff] [blame] | 73 | set(LIBCXXABI_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.") |
| 74 | set(LIBCXXABI_SYSROOT "" CACHE PATH "Sysroot for cross compiling.") |
| 75 | set(LIBCXXABI_LIBCXX_LIBRARY_PATH "" CACHE PATH "The path to libc++ library.") |
Dan Albert | fd961bd | 2014-07-10 02:20:11 +0000 | [diff] [blame] | 76 | |
| 77 | # Default to building a shared library so that the default options still test |
| 78 | # the libc++abi that is being built. There are two problems with testing a |
| 79 | # static libc++abi. In the case of a standalone build, the tests will link the |
| 80 | # system's libc++, which might not have been built against our libc++abi. In the |
| 81 | # case of an in tree build, libc++ will prefer a dynamic libc++abi from the |
| 82 | # system over a static libc++abi from the output directory. |
| 83 | option(LIBCXXABI_ENABLE_SHARED "Build libc++abi as a shared library." ON) |
Eric Fiselier | d95080e | 2015-03-03 15:59:09 +0000 | [diff] [blame] | 84 | option(LIBCXXABI_ENABLE_STATIC "Build libc++abi as a static library." ON) |
| 85 | |
Ranjeet Singh | 2ecb4ee | 2017-03-01 11:42:01 +0000 | [diff] [blame] | 86 | option(LIBCXXABI_BAREMETAL "Build libc++abi for baremetal targets." OFF) |
| 87 | # The default terminate handler attempts to demangle uncaught exceptions, which |
| 88 | # causes extra I/O and demangling code to be pulled in. |
| 89 | option(LIBCXXABI_SILENT_TERMINATE "Set this to make the terminate handler default to a silent alternative" OFF) |
| 90 | |
Eric Fiselier | d95080e | 2015-03-03 15:59:09 +0000 | [diff] [blame] | 91 | if (NOT LIBCXXABI_ENABLE_SHARED AND NOT LIBCXXABI_ENABLE_STATIC) |
| 92 | message(FATAL_ERROR "libc++abi must be built as either a shared or static library.") |
| 93 | endif() |
Dan Albert | fd961bd | 2014-07-10 02:20:11 +0000 | [diff] [blame] | 94 | |
Mehdi Amini | 6dc7581 | 2016-11-07 22:07:43 +0000 | [diff] [blame] | 95 | if (LLVM_EXTERNAL_LIBCXX_SOURCE_DIR) |
Petr Hosek | 4d14bc0 | 2016-11-11 19:12:58 +0000 | [diff] [blame] | 96 | set(LIBCXXABI_LIBCXX_SRC_DIRS ${LLVM_EXTERNAL_LIBCXX_SOURCE_DIR}) |
Mehdi Amini | 6dc7581 | 2016-11-07 22:07:43 +0000 | [diff] [blame] | 97 | else() |
Petr Hosek | 4d14bc0 | 2016-11-11 19:12:58 +0000 | [diff] [blame] | 98 | set(LIBCXXABI_LIBCXX_SRC_DIRS |
| 99 | "${LLVM_MAIN_SRC_DIR}/projects/libcxx" |
| 100 | "${LLVM_MAIN_SRC_DIR}/runtimes/libcxx" |
| 101 | ) |
Mehdi Amini | 6dc7581 | 2016-11-07 22:07:43 +0000 | [diff] [blame] | 102 | endif() |
| 103 | |
Petr Hosek | 4d14bc0 | 2016-11-11 19:12:58 +0000 | [diff] [blame] | 104 | set(LIBCXXABI_LIBCXX_INCLUDE_DIRS "") |
| 105 | foreach(dir ${LIBCXXABI_LIBCXX_SRC_DIRS}) |
| 106 | list(APPEND LIBCXXABI_LIBCXX_INCLUDE_DIRS "${dir}/include") |
| 107 | endforeach() |
| 108 | |
Dan Albert | fd961bd | 2014-07-10 02:20:11 +0000 | [diff] [blame] | 109 | find_path( |
| 110 | LIBCXXABI_LIBCXX_INCLUDES |
| 111 | vector |
| 112 | PATHS ${LIBCXXABI_LIBCXX_INCLUDES} |
Eric Fiselier | 9a9e939 | 2015-01-22 20:00:06 +0000 | [diff] [blame] | 113 | ${LIBCXXABI_LIBCXX_PATH}/include |
Dan Albert | fd961bd | 2014-07-10 02:20:11 +0000 | [diff] [blame] | 114 | ${CMAKE_BINARY_DIR}/${LIBCXXABI_LIBCXX_INCLUDES} |
Petr Hosek | 4d14bc0 | 2016-11-11 19:12:58 +0000 | [diff] [blame] | 115 | ${LIBCXXABI_LIBCXX_INCLUDE_DIRS} |
Dan Albert | fd961bd | 2014-07-10 02:20:11 +0000 | [diff] [blame] | 116 | ${LLVM_INCLUDE_DIR}/c++/v1 |
| 117 | ) |
| 118 | |
Eric Fiselier | 9a9e939 | 2015-01-22 20:00:06 +0000 | [diff] [blame] | 119 | set(LIBCXXABI_LIBCXX_INCLUDES "${LIBCXXABI_LIBCXX_INCLUDES}" CACHE PATH |
Dan Albert | fd961bd | 2014-07-10 02:20:11 +0000 | [diff] [blame] | 120 | "Specify path to libc++ includes." FORCE) |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 121 | |
Eric Fiselier | 9a9e939 | 2015-01-22 20:00:06 +0000 | [diff] [blame] | 122 | find_path( |
| 123 | LIBCXXABI_LIBCXX_PATH |
Petr Hosek | f0f0257 | 2017-02-18 04:37:59 +0000 | [diff] [blame] | 124 | utils/libcxx/test/__init__.py |
Eric Fiselier | 9a9e939 | 2015-01-22 20:00:06 +0000 | [diff] [blame] | 125 | PATHS ${LIBCXXABI_LIBCXX_PATH} |
| 126 | ${LIBCXXABI_LIBCXX_INCLUDES}/../ |
Petr Hosek | 4d14bc0 | 2016-11-11 19:12:58 +0000 | [diff] [blame] | 127 | ${LIBCXXABI_LIBCXX_SRC_DIRS} |
Eric Fiselier | 9a9e939 | 2015-01-22 20:00:06 +0000 | [diff] [blame] | 128 | NO_DEFAULT_PATH |
| 129 | ) |
| 130 | |
| 131 | if (LIBCXXABI_LIBCXX_PATH STREQUAL "LIBCXXABI_LIBCXX_PATH-NOTFOUND") |
| 132 | message(WARNING "LIBCXXABI_LIBCXX_PATH was not specified and couldn't be infered.") |
| 133 | set(LIBCXXABI_LIBCXX_PATH "") |
| 134 | endif() |
| 135 | |
| 136 | set(LIBCXXABI_LIBCXX_PATH "${LIBCXXABI_LIBCXX_PATH}" CACHE PATH |
| 137 | "Specify path to libc++ source." FORCE) |
| 138 | |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 139 | #=============================================================================== |
| 140 | # Configure System |
| 141 | #=============================================================================== |
| 142 | |
| 143 | # Add path for custom modules |
| 144 | set(CMAKE_MODULE_PATH |
| 145 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake" |
| 146 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" |
| 147 | ${CMAKE_MODULE_PATH} |
| 148 | ) |
| 149 | |
Chandler Carruth | 343559e | 2014-12-29 12:22:04 +0000 | [diff] [blame] | 150 | set(LIBCXXABI_COMPILER ${CMAKE_CXX_COMPILER}) |
| 151 | set(LIBCXXABI_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 152 | set(LIBCXXABI_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
Jonas Hahnfeld | a4c4545 | 2017-05-04 06:04:49 +0000 | [diff] [blame] | 153 | if (LLVM_LIBRARY_OUTPUT_INTDIR) |
| 154 | set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) |
| 155 | else() |
| 156 | set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX}) |
| 157 | endif() |
Chandler Carruth | 343559e | 2014-12-29 12:22:04 +0000 | [diff] [blame] | 158 | |
Ben Craig | 80b6b68 | 2016-04-18 13:30:38 +0000 | [diff] [blame] | 159 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR}) |
| 160 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR}) |
Martell Malone | 380a70a | 2017-06-01 00:09:20 +0000 | [diff] [blame] | 161 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR}) |
Ben Craig | 80b6b68 | 2016-04-18 13:30:38 +0000 | [diff] [blame] | 162 | |
Ben Craig | 4ed725d | 2016-06-01 12:50:30 +0000 | [diff] [blame] | 163 | # By default, for non-standalone builds, libcxx and libcxxabi share a library |
| 164 | # directory. |
| 165 | if (NOT LIBCXXABI_LIBCXX_LIBRARY_PATH) |
| 166 | set(LIBCXXABI_LIBCXX_LIBRARY_PATH "${LIBCXXABI_LIBRARY_DIR}" CACHE PATH |
| 167 | "The path to libc++ library.") |
Eugene Zelenko | 9987410 | 2016-08-08 17:59:02 +0000 | [diff] [blame] | 168 | endif() |
Eric Fiselier | 046d2fc | 2016-06-02 02:18:31 +0000 | [diff] [blame] | 169 | |
| 170 | # Check that we can build with 32 bits if requested. |
| 171 | if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32) |
| 172 | if (LIBCXXABI_BUILD_32_BITS AND NOT LLVM_BUILD_32_BITS) # Don't duplicate the output from LLVM |
| 173 | message(STATUS "Building 32 bits executables and libraries.") |
| 174 | endif() |
| 175 | elseif(LIBCXXABI_BUILD_32_BITS) |
| 176 | message(FATAL_ERROR "LIBCXXABI_BUILD_32_BITS=ON is not supported on this platform.") |
| 177 | endif() |
| 178 | |
Martell Malone | 380a70a | 2017-06-01 00:09:20 +0000 | [diff] [blame] | 179 | # Declare libc++abi configuration variables. |
| 180 | # They are intended for use as follows: |
| 181 | # LIBCXXABI_C_FLAGS: General flags for both the c++ compiler and linker. |
| 182 | # LIBCXXABI_CXX_FLAGS: General flags for both the c++ compiler and linker. |
| 183 | # LIBCXXABI_COMPILE_FLAGS: Compile only flags. |
| 184 | # LIBCXXABI_LINK_FLAGS: Linker only flags. |
| 185 | # LIBCXXABI_LIBRARIES: libraries libc++abi is linked to. |
Eric Fiselier | 046d2fc | 2016-06-02 02:18:31 +0000 | [diff] [blame] | 186 | |
Logan Chien | 1c5ae13 | 2015-01-22 13:39:08 +0000 | [diff] [blame] | 187 | set(LIBCXXABI_C_FLAGS "") |
Eric Fiselier | c365bb5 | 2014-11-18 20:37:53 +0000 | [diff] [blame] | 188 | set(LIBCXXABI_CXX_FLAGS "") |
| 189 | set(LIBCXXABI_COMPILE_FLAGS "") |
| 190 | set(LIBCXXABI_LINK_FLAGS "") |
Martell Malone | 380a70a | 2017-06-01 00:09:20 +0000 | [diff] [blame] | 191 | set(LIBCXXABI_LIBRARIES "") |
| 192 | |
| 193 | # Include macros for adding and removing libc++abi flags. |
| 194 | include(HandleLibcxxabiFlags) |
| 195 | |
| 196 | #=============================================================================== |
| 197 | # Setup Compiler Flags |
| 198 | #=============================================================================== |
Eric Fiselier | c365bb5 | 2014-11-18 20:37:53 +0000 | [diff] [blame] | 199 | |
Eric Fiselier | 046d2fc | 2016-06-02 02:18:31 +0000 | [diff] [blame] | 200 | # Configure target flags |
| 201 | add_target_flags_if(LIBCXXABI_BUILD_32_BITS "-m32") |
| 202 | add_target_flags_if(LIBCXXABI_TARGET_TRIPLE |
Petr Hosek | 2ef575d | 2017-04-16 06:08:34 +0000 | [diff] [blame] | 203 | "--target=${LIBCXXABI_TARGET_TRIPLE}") |
Eric Fiselier | 046d2fc | 2016-06-02 02:18:31 +0000 | [diff] [blame] | 204 | add_target_flags_if(LIBCXXABI_GCC_TOOLCHAIN |
Petr Hosek | 2ef575d | 2017-04-16 06:08:34 +0000 | [diff] [blame] | 205 | "--gcc-toolchain=${LIBCXXABI_GCC_TOOLCHAIN}") |
Eric Fiselier | 046d2fc | 2016-06-02 02:18:31 +0000 | [diff] [blame] | 206 | add_target_flags_if(LIBCXXABI_SYSROOT |
| 207 | "--sysroot=${LIBCXXABI_SYSROOT}") |
| 208 | |
Eric Fiselier | 1105202 | 2016-11-13 22:27:00 +0000 | [diff] [blame] | 209 | if (LIBCXXABI_TARGET_TRIPLE) |
| 210 | set(TARGET_TRIPLE "${LIBCXXABI_TARGET_TRIPLE}") |
| 211 | endif() |
| 212 | |
Eric Fiselier | 046d2fc | 2016-06-02 02:18:31 +0000 | [diff] [blame] | 213 | # Configure compiler. Must happen after setting the target flags. |
| 214 | include(config-ix) |
Eric Fiselier | c365bb5 | 2014-11-18 20:37:53 +0000 | [diff] [blame] | 215 | |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 216 | if (LIBCXXABI_HAS_NOSTDINCXX_FLAG) |
Eric Fiselier | c365bb5 | 2014-11-18 20:37:53 +0000 | [diff] [blame] | 217 | list(APPEND LIBCXXABI_COMPILE_FLAGS -nostdinc++) |
| 218 | # Remove -stdlib flags to prevent them from causing an unused flag warning. |
| 219 | string(REPLACE "-stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 220 | string(REPLACE "-stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 221 | endif() |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 222 | |
Saleem Abdulrasool | f0a2620 | 2016-07-15 00:49:42 +0000 | [diff] [blame] | 223 | if (LIBCXXABI_USE_COMPILER_RT) |
| 224 | list(APPEND LIBCXXABI_LINK_FLAGS "-rtlib=compiler-rt") |
Eugene Zelenko | 9987410 | 2016-08-08 17:59:02 +0000 | [diff] [blame] | 225 | endif() |
Eric Fiselier | c365bb5 | 2014-11-18 20:37:53 +0000 | [diff] [blame] | 226 | |
Shoaib Meenai | a086331 | 2016-09-27 03:44:09 +0000 | [diff] [blame] | 227 | # Let the library headers know they are currently being used to build the |
| 228 | # library. |
| 229 | add_definitions(-D_LIBCXXABI_BUILDING_LIBRARY) |
| 230 | |
| 231 | # Disable DLL annotations on Windows for static builds. |
| 232 | if (WIN32 AND LIBCXXABI_ENABLE_STATIC AND NOT LIBCXXABI_ENABLE_SHARED) |
Martell Malone | 9111b9c | 2017-05-28 22:46:50 +0000 | [diff] [blame] | 233 | add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS) |
Shoaib Meenai | a086331 | 2016-09-27 03:44:09 +0000 | [diff] [blame] | 234 | endif() |
| 235 | |
Martell Malone | 380a70a | 2017-06-01 00:09:20 +0000 | [diff] [blame] | 236 | add_compile_flags_if_supported(-Werror=return-type) |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 237 | |
| 238 | # Get warning flags |
Martell Malone | 380a70a | 2017-06-01 00:09:20 +0000 | [diff] [blame] | 239 | add_compile_flags_if_supported(-W) |
| 240 | add_compile_flags_if_supported(-Wall) |
| 241 | add_compile_flags_if_supported(-Wchar-subscripts) |
| 242 | add_compile_flags_if_supported(-Wconversion) |
| 243 | add_compile_flags_if_supported(-Wmismatched-tags) |
| 244 | add_compile_flags_if_supported(-Wmissing-braces) |
| 245 | add_compile_flags_if_supported(-Wnewline-eof) |
| 246 | add_compile_flags_if_supported(-Wunused-function) |
| 247 | add_compile_flags_if_supported(-Wshadow) |
| 248 | add_compile_flags_if_supported(-Wshorten-64-to-32) |
| 249 | add_compile_flags_if_supported(-Wsign-compare) |
| 250 | add_compile_flags_if_supported(-Wsign-conversion) |
| 251 | add_compile_flags_if_supported(-Wstrict-aliasing=2) |
| 252 | add_compile_flags_if_supported(-Wstrict-overflow=4) |
| 253 | add_compile_flags_if_supported(-Wunused-parameter) |
| 254 | add_compile_flags_if_supported(-Wunused-variable) |
| 255 | add_compile_flags_if_supported(-Wwrite-strings) |
| 256 | add_compile_flags_if_supported(-Wundef) |
Dan Albert | f198219 | 2014-07-10 22:23:03 +0000 | [diff] [blame] | 257 | |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 258 | if (LIBCXXABI_ENABLE_WERROR) |
Martell Malone | 380a70a | 2017-06-01 00:09:20 +0000 | [diff] [blame] | 259 | add_compile_flags_if_supported(-Werror) |
| 260 | add_compile_flags_if_supported(-WX) |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 261 | else() |
Martell Malone | 380a70a | 2017-06-01 00:09:20 +0000 | [diff] [blame] | 262 | add_compile_flags_if_supported(-Wno-error) |
| 263 | add_compile_flags_if_supported(-WX-) |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 264 | endif() |
| 265 | if (LIBCXXABI_ENABLE_PEDANTIC) |
Martell Malone | 380a70a | 2017-06-01 00:09:20 +0000 | [diff] [blame] | 266 | add_compile_flags_if_supported(-pedantic) |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 267 | endif() |
| 268 | |
| 269 | # Get feature flags. |
Martell Malone | 380a70a | 2017-06-01 00:09:20 +0000 | [diff] [blame] | 270 | add_compile_flags_if_supported(-fstrict-aliasing) |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 271 | |
Asiri Rathnayake | 4174e8b | 2016-05-31 12:01:32 +0000 | [diff] [blame] | 272 | # Exceptions |
| 273 | if (LIBCXXABI_ENABLE_EXCEPTIONS) |
| 274 | # Catches C++ exceptions only and tells the compiler to assume that extern C |
| 275 | # functions never throw a C++ exception. |
Martell Malone | 380a70a | 2017-06-01 00:09:20 +0000 | [diff] [blame] | 276 | add_compile_flags_if_supported(-EHsc) |
| 277 | # Do we really need to be run through the C compiler ? |
| 278 | add_c_compile_flags_if_supported(-funwind-tables) |
Asiri Rathnayake | 4174e8b | 2016-05-31 12:01:32 +0000 | [diff] [blame] | 279 | else() |
| 280 | add_definitions(-D_LIBCXXABI_NO_EXCEPTIONS) |
Martell Malone | 380a70a | 2017-06-01 00:09:20 +0000 | [diff] [blame] | 281 | add_compile_flags_if_supported(-fno-exceptions) |
| 282 | add_compile_flags_if_supported(-EHs-) |
| 283 | add_compile_flags_if_supported(-EHa-) |
Asiri Rathnayake | 4174e8b | 2016-05-31 12:01:32 +0000 | [diff] [blame] | 284 | endif() |
Logan Chien | 1c5ae13 | 2015-01-22 13:39:08 +0000 | [diff] [blame] | 285 | |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 286 | # Assert |
| 287 | string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) |
| 288 | if (LIBCXXABI_ENABLE_ASSERTIONS) |
| 289 | # MSVC doesn't like _DEBUG on release builds. See PR 4379. |
| 290 | if (NOT MSVC) |
Eric Fiselier | c365bb5 | 2014-11-18 20:37:53 +0000 | [diff] [blame] | 291 | list(APPEND LIBCXXABI_COMPILE_FLAGS -D_DEBUG) |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 292 | endif() |
| 293 | # On Release builds cmake automatically defines NDEBUG, so we |
| 294 | # explicitly undefine it: |
| 295 | if (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE") |
Eric Fiselier | c365bb5 | 2014-11-18 20:37:53 +0000 | [diff] [blame] | 296 | list(APPEND LIBCXXABI_COMPILE_FLAGS -UNDEBUG) |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 297 | endif() |
| 298 | else() |
| 299 | if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE") |
Eric Fiselier | c365bb5 | 2014-11-18 20:37:53 +0000 | [diff] [blame] | 300 | list(APPEND LIBCXXABI_COMPILE_FLAGS -DNDEBUG) |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 301 | endif() |
| 302 | endif() |
| 303 | # Static library |
| 304 | if (NOT LIBCXXABI_ENABLE_SHARED) |
Eric Fiselier | c365bb5 | 2014-11-18 20:37:53 +0000 | [diff] [blame] | 305 | list(APPEND LIBCXXABI_COMPILE_FLAGS -D_LIBCPP_BUILD_STATIC) |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 306 | endif() |
| 307 | |
Asiri Rathnayake | 71ba287 | 2017-01-03 12:58:34 +0000 | [diff] [blame] | 308 | # Threading |
Eric Fiselier | d872a69 | 2014-11-24 22:42:03 +0000 | [diff] [blame] | 309 | if (NOT LIBCXXABI_ENABLE_THREADS) |
Ben Craig | b06c53c | 2016-05-25 17:37:38 +0000 | [diff] [blame] | 310 | if (LIBCXXABI_HAS_PTHREAD_API) |
| 311 | message(FATAL_ERROR "LIBCXXABI_HAS_PTHREAD_API can only" |
| 312 | " be set to ON when LIBCXXABI_ENABLE_THREADS" |
| 313 | " is also set to ON.") |
| 314 | endif() |
Asiri Rathnayake | 71ba287 | 2017-01-03 12:58:34 +0000 | [diff] [blame] | 315 | if (LIBCXXABI_HAS_EXTERNAL_THREAD_API) |
| 316 | message(FATAL_ERROR "LIBCXXABI_HAS_EXTERNAL_THREAD_API can only" |
| 317 | " be set to ON when LIBCXXABI_ENABLE_THREADS" |
| 318 | " is also set to ON.") |
| 319 | endif() |
Asiri Rathnayake | 1f4def2 | 2017-01-09 11:57:21 +0000 | [diff] [blame] | 320 | if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY) |
| 321 | message(FATAL_ERROR "LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY can only" |
| 322 | " be set to ON when LIBCXXABI_ENABLE_THREADS" |
| 323 | " is also set to ON.") |
| 324 | endif() |
Asiri Rathnayake | b62a4dd | 2016-09-21 09:09:32 +0000 | [diff] [blame] | 325 | add_definitions(-D_LIBCXXABI_HAS_NO_THREADS) |
Eric Fiselier | d872a69 | 2014-11-24 22:42:03 +0000 | [diff] [blame] | 326 | endif() |
| 327 | |
Asiri Rathnayake | 1f4def2 | 2017-01-09 11:57:21 +0000 | [diff] [blame] | 328 | if (LIBCXXABI_HAS_EXTERNAL_THREAD_API) |
| 329 | if (LIBCXXABI_HAS_PTHREAD_API) |
| 330 | message(FATAL_ERROR "The options LIBCXXABI_HAS_EXTERNAL_THREAD_API" |
| 331 | " and LIBCXXABI_HAS_PTHREAD_API cannot be both" |
| 332 | " set to ON at the same time.") |
| 333 | endif() |
| 334 | if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY) |
| 335 | message(FATAL_ERROR "The options LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY" |
| 336 | " and LIBCXXABI_HAS_EXTERNAL_THREAD_API cannot be both" |
| 337 | " set to ON at the same time.") |
| 338 | endif() |
Asiri Rathnayake | 71ba287 | 2017-01-03 12:58:34 +0000 | [diff] [blame] | 339 | endif() |
| 340 | |
Eric Fiselier | 0368af0 | 2017-03-04 02:15:37 +0000 | [diff] [blame] | 341 | set(LIBCXXABI_HAS_UNDEFINED_SYMBOLS OFF) |
| 342 | if ((NOT LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS) |
Eric Fiselier | 2d38329 | 2017-05-11 03:49:48 +0000 | [diff] [blame] | 343 | OR (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY AND LIBCXXABI_ENABLE_SHARED) |
| 344 | OR MINGW) |
Eric Fiselier | 0368af0 | 2017-03-04 02:15:37 +0000 | [diff] [blame] | 345 | set(LIBCXXABI_HAS_UNDEFINED_SYMBOLS ON) |
| 346 | endif() |
Eric Fiselier | 4841062 | 2017-03-02 19:34:35 +0000 | [diff] [blame] | 347 | |
| 348 | if (LIBCXXABI_HAS_UNDEFINED_SYMBOLS) |
Asiri Rathnayake | 71ba287 | 2017-01-03 12:58:34 +0000 | [diff] [blame] | 349 | # Need to allow unresolved symbols if this is to work with shared library builds |
| 350 | if (APPLE) |
Eric Fiselier | 0368af0 | 2017-03-04 02:15:37 +0000 | [diff] [blame] | 351 | list(APPEND LIBCXXABI_LINK_FLAGS "-undefined dynamic_lookup") |
Asiri Rathnayake | 71ba287 | 2017-01-03 12:58:34 +0000 | [diff] [blame] | 352 | else() |
| 353 | # Relax this restriction from HandleLLVMOptions |
| 354 | string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") |
| 355 | endif() |
| 356 | endif() |
| 357 | |
Ben Craig | b06c53c | 2016-05-25 17:37:38 +0000 | [diff] [blame] | 358 | if (LIBCXXABI_HAS_PTHREAD_API) |
| 359 | add_definitions(-D_LIBCPP_HAS_THREAD_API_PTHREAD) |
| 360 | endif() |
| 361 | |
Asiri Rathnayake | 71ba287 | 2017-01-03 12:58:34 +0000 | [diff] [blame] | 362 | if (LIBCXXABI_HAS_EXTERNAL_THREAD_API) |
Asiri Rathnayake | 1f4def2 | 2017-01-09 11:57:21 +0000 | [diff] [blame] | 363 | add_definitions(-D_LIBCPP_HAS_THREAD_API_EXTERNAL) |
| 364 | endif() |
| 365 | |
| 366 | if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY) |
| 367 | add_definitions(-D_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) |
Asiri Rathnayake | 71ba287 | 2017-01-03 12:58:34 +0000 | [diff] [blame] | 368 | endif() |
| 369 | |
Shoaib Meenai | 03d803f | 2017-05-10 21:52:39 +0000 | [diff] [blame] | 370 | # Prevent libc++abi from having library dependencies on libc++ |
| 371 | add_definitions(-D_LIBCPP_DISABLE_EXTERN_TEMPLATE) |
| 372 | |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 373 | if (MSVC) |
| 374 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) |
| 375 | endif() |
| 376 | |
Logan Chien | 083506f | 2015-01-22 13:27:36 +0000 | [diff] [blame] | 377 | # Define LIBCXXABI_USE_LLVM_UNWINDER for conditional compilation. |
Logan Chien | 6962eb3 | 2016-11-13 14:42:15 +0000 | [diff] [blame] | 378 | if (LIBCXXABI_USE_LLVM_UNWINDER) |
Ranjeet Singh | 2ecb4ee | 2017-03-01 11:42:01 +0000 | [diff] [blame] | 379 | add_definitions(-DLIBCXXABI_USE_LLVM_UNWINDER) |
Logan Chien | 083506f | 2015-01-22 13:27:36 +0000 | [diff] [blame] | 380 | endif() |
| 381 | |
James Y Knight | 0ecfd76 | 2017-01-13 19:22:26 +0000 | [diff] [blame] | 382 | if (LIBCXXABI_SILENT_TERMINATE) |
Ranjeet Singh | 2ecb4ee | 2017-03-01 11:42:01 +0000 | [diff] [blame] | 383 | add_definitions(-DLIBCXXABI_SILENT_TERMINATE) |
| 384 | endif() |
| 385 | |
| 386 | if (LIBCXXABI_BAREMETAL) |
| 387 | add_definitions(-DLIBCXXABI_BAREMETAL) |
James Y Knight | 0ecfd76 | 2017-01-13 19:22:26 +0000 | [diff] [blame] | 388 | endif() |
| 389 | |
Eric Fiselier | c365bb5 | 2014-11-18 20:37:53 +0000 | [diff] [blame] | 390 | string(REPLACE ";" " " LIBCXXABI_CXX_FLAGS "${LIBCXXABI_CXX_FLAGS}") |
| 391 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXXABI_CXX_FLAGS}") |
Logan Chien | 1c5ae13 | 2015-01-22 13:39:08 +0000 | [diff] [blame] | 392 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBCXXABI_C_FLAGS}") |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 393 | |
| 394 | #=============================================================================== |
| 395 | # Setup Source Code |
| 396 | #=============================================================================== |
| 397 | |
Anton Korobeynikov | c509660 | 2015-05-08 16:10:11 +0000 | [diff] [blame] | 398 | set(LIBCXXABI_LIBUNWIND_INCLUDES "${LIBCXXABI_LIBUNWIND_INCLUDES}" CACHE PATH |
| 399 | "Specify path to libunwind includes." FORCE) |
| 400 | set(LIBCXXABI_LIBUNWIND_PATH "${LIBCXXABI_LIBUNWIND_PATH}" CACHE PATH |
| 401 | "Specify path to libunwind source." FORCE) |
| 402 | |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 403 | include_directories(include) |
Eric Fiselier | 3641403 | 2015-04-29 15:53:03 +0000 | [diff] [blame] | 404 | if (LIBCXXABI_USE_LLVM_UNWINDER OR LLVM_NATIVE_ARCH MATCHES ARM) |
Anton Korobeynikov | c509660 | 2015-05-08 16:10:11 +0000 | [diff] [blame] | 405 | find_path( |
Anton Korobeynikov | f662666 | 2015-05-09 21:03:01 +0000 | [diff] [blame] | 406 | LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL |
Anton Korobeynikov | c509660 | 2015-05-08 16:10:11 +0000 | [diff] [blame] | 407 | libunwind.h |
| 408 | PATHS ${LIBCXXABI_LIBUNWIND_INCLUDES} |
| 409 | ${LIBCXXABI_LIBUNWIND_PATH}/include |
| 410 | ${CMAKE_BINARY_DIR}/${LIBCXXABI_LIBUNWIND_INCLUDES} |
| 411 | ${LLVM_MAIN_SRC_DIR}/projects/libunwind/include |
Petr Hosek | 4d14bc0 | 2016-11-11 19:12:58 +0000 | [diff] [blame] | 412 | ${LLVM_MAIN_SRC_DIR}/runtimes/libunwind/include |
Anton Korobeynikov | f662666 | 2015-05-09 21:03:01 +0000 | [diff] [blame] | 413 | NO_DEFAULT_PATH |
Anton Korobeynikov | c509660 | 2015-05-08 16:10:11 +0000 | [diff] [blame] | 414 | ) |
| 415 | |
Asiri Rathnayake | 0a3a1a8 | 2017-04-04 14:03:54 +0000 | [diff] [blame] | 416 | if (LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL "LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL-NOTFOUND") |
| 417 | set(LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL "") |
| 418 | endif() |
| 419 | |
| 420 | if (NOT LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL "") |
Michal Gorny | ed61102 | 2017-01-14 17:05:16 +0000 | [diff] [blame] | 421 | include_directories("${LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL}") |
| 422 | endif() |
Eugene Zelenko | 9987410 | 2016-08-08 17:59:02 +0000 | [diff] [blame] | 423 | endif() |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 424 | |
| 425 | # Add source code. This also contains all of the logic for deciding linker flags |
| 426 | # soname, etc... |
| 427 | add_subdirectory(src) |
Dan Albert | fd961bd | 2014-07-10 02:20:11 +0000 | [diff] [blame] | 428 | |
Bryant Wong | ebc9aca | 2017-01-07 22:14:04 +0000 | [diff] [blame] | 429 | if (NOT LIBCXXABI_INCLUDE_TESTS OR (LIBCXXABI_STANDALONE_BUILD AND NOT LIBCXXABI_ENABLE_SHARED)) |
Ben Craig | 4ed725d | 2016-06-01 12:50:30 +0000 | [diff] [blame] | 430 | # We can't reasonably test the system C++ library with a static libc++abi. |
| 431 | # We either need to be able to replace libc++abi at run time (with a shared |
| 432 | # libc++abi), or we need to be able to replace the C++ runtime (with a non- |
| 433 | # standalone build). |
| 434 | message(WARNING "The libc++abi tests aren't valid when libc++abi is built " |
| 435 | "standalone (i.e. outside of llvm/projects/libcxxabi ) and " |
| 436 | "is built without a shared library. Either build a shared " |
| 437 | "library, build libc++abi at the same time as you build " |
| 438 | "libc++, or do without testing. No check target will be " |
Dan Albert | fd961bd | 2014-07-10 02:20:11 +0000 | [diff] [blame] | 439 | "available!") |
| 440 | else() |
| 441 | add_subdirectory(test) |
Kostya Serebryany | 6e0f5ef | 2016-12-28 03:28:29 +0000 | [diff] [blame] | 442 | add_subdirectory(fuzz) |
Dan Albert | fd961bd | 2014-07-10 02:20:11 +0000 | [diff] [blame] | 443 | endif() |