Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 1 | # See www/CMake.html for instructions on how to build libcxx with CMake. |
Eric Fiselier | 74abe0b | 2017-05-04 06:28:34 | [diff] [blame] | 2 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 3 | #=============================================================================== |
| 4 | # Setup Project |
| 5 | #=============================================================================== |
Chris Bieneman | cad86ff | 2016-05-31 20:21:52 | [diff] [blame] | 6 | cmake_minimum_required(VERSION 3.4.3) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 7 | |
Eric Fiselier | e9d4b23 | 2015-01-26 21:56:45 | [diff] [blame] | 8 | if(POLICY CMP0042) |
| 9 | cmake_policy(SET CMP0042 NEW) # Set MACOSX_RPATH=YES by default |
| 10 | endif() |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 11 | if(POLICY CMP0022) |
| 12 | cmake_policy(SET CMP0022 NEW) # Required when interacting with LLVM and Clang |
| 13 | endif() |
Eric Fiselier | 14535e3 | 2018-07-26 05:08:30 | [diff] [blame] | 14 | if(POLICY CMP0068) |
| 15 | cmake_policy(SET CMP0068 NEW) |
| 16 | set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON) |
| 17 | endif() |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 18 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 19 | # Add path for custom modules |
| 20 | set(CMAKE_MODULE_PATH |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 21 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake" |
| 22 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" |
Eric Fiselier | ce5695f | 2015-12-30 03:39:03 | [diff] [blame] | 23 | ${CMAKE_MODULE_PATH} |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 24 | ) |
| 25 | |
Eric Fiselier | 5e000c6 | 2016-11-14 02:43:12 | [diff] [blame] | 26 | if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) |
Saleem Abdulrasool | 7adfa03 | 2016-02-08 03:50:18 | [diff] [blame] | 27 | project(libcxx CXX C) |
| 28 | |
| 29 | set(PACKAGE_NAME libcxx) |
Hans Wennborg | db9b3d8 | 2018-08-01 13:54:28 | [diff] [blame] | 30 | set(PACKAGE_VERSION 8.0.0svn) |
Saleem Abdulrasool | 7adfa03 | 2016-02-08 03:50:18 | [diff] [blame] | 31 | set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") |
| 32 | set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org") |
Eric Fiselier | 5e000c6 | 2016-11-14 02:43:12 | [diff] [blame] | 33 | |
| 34 | # Find the LLVM sources and simulate LLVM CMake options. |
| 35 | include(HandleOutOfTreeLLVM) |
Eugene Zelenko | 96f1017 | 2016-08-08 18:01:50 | [diff] [blame] | 36 | endif() |
Saleem Abdulrasool | 7adfa03 | 2016-02-08 03:50:18 | [diff] [blame] | 37 | |
Petr Hosek | 3508e7a | 2017-01-16 00:33:07 | [diff] [blame] | 38 | if (LIBCXX_STANDALONE_BUILD) |
| 39 | include(FindPythonInterp) |
| 40 | if( NOT PYTHONINTERP_FOUND ) |
| 41 | message(WARNING "Failed to find python interpreter. " |
| 42 | "The libc++ test suite will be disabled.") |
| 43 | set(LLVM_INCLUDE_TESTS OFF) |
| 44 | endif() |
| 45 | endif() |
| 46 | |
Saleem Abdulrasool | 7adfa03 | 2016-02-08 03:50:18 | [diff] [blame] | 47 | # Require out of source build. |
| 48 | include(MacroEnsureOutOfSourceBuild) |
| 49 | MACRO_ENSURE_OUT_OF_SOURCE_BUILD( |
| 50 | "${PROJECT_NAME} requires an out of source build. Please create a separate |
| 51 | build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there." |
| 52 | ) |
Eric Fiselier | 2641c80 | 2018-10-01 01:31:23 | [diff] [blame] | 53 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC") |
| 54 | message(STATUS "Configuring for clang-cl") |
| 55 | set(LIBCXX_TARGETING_CLANG_CL ON) |
| 56 | endif() |
Saleem Abdulrasool | 7adfa03 | 2016-02-08 03:50:18 | [diff] [blame] | 57 | |
Eric Fiselier | fdd3c91 | 2017-01-14 06:06:47 | [diff] [blame] | 58 | if (MSVC) |
| 59 | set(LIBCXX_TARGETING_MSVC ON) |
Eric Fiselier | 63f54c0 | 2018-10-01 01:00:11 | [diff] [blame] | 60 | message(STATUS "Configuring for MSVC") |
Eric Fiselier | fdd3c91 | 2017-01-14 06:06:47 | [diff] [blame] | 61 | else() |
| 62 | set(LIBCXX_TARGETING_MSVC OFF) |
| 63 | endif() |
| 64 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 65 | #=============================================================================== |
| 66 | # Setup CMake Options |
| 67 | #=============================================================================== |
Eric Fiselier | 01609af | 2016-09-07 01:15:10 | [diff] [blame] | 68 | include(CMakeDependentOption) |
Eric Fiselier | c51e0d2 | 2017-03-11 03:24:18 | [diff] [blame] | 69 | include(HandleCompilerRT) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 70 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 71 | # Basic options --------------------------------------------------------------- |
Eric Fiselier | b89eba0 | 2017-02-04 23:22:28 | [diff] [blame] | 72 | option(LIBCXX_ENABLE_ASSERTIONS "Enable assertions independent of build mode." OFF) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 73 | option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON) |
Petr Hosek | b640da0 | 2016-08-08 22:57:25 | [diff] [blame] | 74 | option(LIBCXX_ENABLE_STATIC "Build libc++ as a static library." ON) |
Eric Fiselier | 5e4698c | 2016-05-03 21:30:18 | [diff] [blame] | 75 | option(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY "Build libc++experimental.a" ON) |
Eric Fiselier | 5bf8bed | 2017-04-20 04:24:29 | [diff] [blame] | 76 | set(ENABLE_FILESYSTEM_DEFAULT ${LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY}) |
| 77 | if (WIN32) |
| 78 | set(ENABLE_FILESYSTEM_DEFAULT OFF) |
| 79 | endif() |
Eric Fiselier | 0be5527 | 2018-07-27 03:42:58 | [diff] [blame] | 80 | option(LIBCXX_ENABLE_FILESYSTEM "Build filesystem as part of libc++fs.a" |
Eric Fiselier | 5bf8bed | 2017-04-20 04:24:29 | [diff] [blame] | 81 | ${ENABLE_FILESYSTEM_DEFAULT}) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 82 | option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS}) |
Eric Fiselier | 2d2f0c0 | 2016-10-30 22:53:00 | [diff] [blame] | 83 | |
Eric Fiselier | 2d2f0c0 | 2016-10-30 22:53:00 | [diff] [blame] | 84 | # Benchmark options ----------------------------------------------------------- |
Louis Dionne | 6adb8a3 | 2018-09-22 21:30:12 | [diff] [blame] | 85 | option(LIBCXX_INCLUDE_BENCHMARKS "Build the libc++ benchmarks and their dependencies" ON) |
Eric Fiselier | 2d2f0c0 | 2016-10-30 22:53:00 | [diff] [blame] | 86 | set(LIBCXX_BENCHMARK_NATIVE_STDLIB "" CACHE STRING |
| 87 | "Build the benchmarks against the specified native STL. |
| 88 | The value must be one of libc++/libstdc++") |
| 89 | set(LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN "" CACHE STRING |
| 90 | "Use alternate GCC toolchain when building the native benchmarks") |
| 91 | |
| 92 | if (LIBCXX_BENCHMARK_NATIVE_STDLIB) |
| 93 | if (NOT (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libc++" |
| 94 | OR LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libstdc++")) |
| 95 | message(FATAL_ERROR "Invalid value for LIBCXX_BENCHMARK_NATIVE_STDLIB: " |
| 96 | "'${LIBCXX_BENCHMARK_NATIVE_STDLIB}'") |
| 97 | endif() |
| 98 | endif() |
| 99 | |
Eric Fiselier | b9f425a | 2015-08-22 19:40:49 | [diff] [blame] | 100 | option(LIBCXX_INCLUDE_DOCS "Build the libc++ documentation." ${LLVM_INCLUDE_DOCS}) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 101 | set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING |
| 102 | "Define suffix of library directory name (32/64)") |
| 103 | option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON) |
Eric Fiselier | 961269d | 2015-08-26 20:18:21 | [diff] [blame] | 104 | option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON) |
Petr Hosek | 89d973a | 2018-07-24 23:27:51 | [diff] [blame] | 105 | cmake_dependent_option(LIBCXX_INSTALL_STATIC_LIBRARY |
| 106 | "Install the static libc++ library." ON |
| 107 | "LIBCXX_ENABLE_STATIC;LIBCXX_INSTALL_LIBRARY" OFF) |
| 108 | cmake_dependent_option(LIBCXX_INSTALL_SHARED_LIBRARY |
| 109 | "Install the shared libc++ library." ON |
| 110 | "LIBCXX_ENABLE_SHARED;LIBCXX_INSTALL_LIBRARY" OFF) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 111 | option(LIBCXX_INSTALL_SUPPORT_HEADERS "Install libc++ support headers." ON) |
Eric Fiselier | 01609af | 2016-09-07 01:15:10 | [diff] [blame] | 112 | cmake_dependent_option(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY |
| 113 | "Install libc++experimental.a" ON |
| 114 | "LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY;LIBCXX_INSTALL_LIBRARY" OFF) |
Eric Fiselier | a0866c5 | 2018-07-27 03:07:09 | [diff] [blame] | 115 | cmake_dependent_option(LIBCXX_INSTALL_FILESYSTEM_LIBRARY |
| 116 | "Install libc++fs.a" ON |
Eric Fiselier | 0be5527 | 2018-07-27 03:42:58 | [diff] [blame] | 117 | "LIBCXX_ENABLE_FILESYSTEM;LIBCXX_INSTALL_LIBRARY" OFF) |
Eric Fiselier | a0866c5 | 2018-07-27 03:07:09 | [diff] [blame] | 118 | |
Louis Dionne | 16357ee | 2018-09-26 08:24:51 | [diff] [blame] | 119 | set(LIBCXX_ABI_VERSION "1" CACHE STRING "ABI version of libc++. Can be either 1 or 2, where 2 is currently not stable. Defaults to 1.") |
Evgeniy Stepanov | 4f01aa8 | 2015-10-13 23:48:28 | [diff] [blame] | 120 | option(LIBCXX_ABI_UNSTABLE "Unstable ABI of libc++." OFF) |
Shoaib Meenai | 7762784 | 2017-10-05 02:18:08 | [diff] [blame] | 121 | option(LIBCXX_ABI_FORCE_ITANIUM "Ignore auto-detection and force use of the Itanium ABI.") |
| 122 | option(LIBCXX_ABI_FORCE_MICROSOFT "Ignore auto-detection and force use of the Microsoft ABI.") |
Louis Dionne | 61b0a00 | 2018-08-16 12:44:28 | [diff] [blame] | 123 | option(LIBCXX_HIDE_FROM_ABI_PER_TU_BY_DEFAULT "Enable per TU ABI insulation by default. To be used by vendors." OFF) |
Shoaib Meenai | f7e9063 | 2017-10-04 23:51:57 | [diff] [blame] | 124 | set(LIBCXX_ABI_DEFINES "" CACHE STRING "A semicolon separated list of ABI macros to define in the site config header.") |
Saleem Abdulrasool | e146f75 | 2016-08-24 04:22:52 | [diff] [blame] | 125 | option(LIBCXX_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 126 | |
Petr Hosek | b640da0 | 2016-08-08 22:57:25 | [diff] [blame] | 127 | if (NOT LIBCXX_ENABLE_SHARED AND NOT LIBCXX_ENABLE_STATIC) |
| 128 | message(FATAL_ERROR "libc++ must be built as either a shared or static library.") |
| 129 | endif() |
| 130 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 131 | # ABI Library options --------------------------------------------------------- |
Eric Fiselier | cfc5515 | 2017-01-03 01:18:48 | [diff] [blame] | 132 | set(LIBCXX_CXX_ABI "default" CACHE STRING |
| 133 | "Specify C++ ABI library to use.") |
Eric Fiselier | bde2871 | 2017-01-16 20:47:35 | [diff] [blame] | 134 | set(CXXABIS none default libcxxabi libcxxrt libstdc++ libsupc++ vcruntime) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 135 | set_property(CACHE LIBCXX_CXX_ABI PROPERTY STRINGS ;${CXXABIS}) |
| 136 | |
Eric Fiselier | 1cf5a81 | 2015-10-22 20:54:27 | [diff] [blame] | 137 | # Setup the default options if LIBCXX_CXX_ABI is not specified. |
Eric Fiselier | cfc5515 | 2017-01-03 01:18:48 | [diff] [blame] | 138 | if (LIBCXX_CXX_ABI STREQUAL "default") |
Petr Hosek | d842fed | 2016-11-09 03:22:28 | [diff] [blame] | 139 | find_path( |
| 140 | LIBCXX_LIBCXXABI_INCLUDES_INTERNAL |
| 141 | cxxabi.h |
| 142 | PATHS ${LLVM_MAIN_SRC_DIR}/projects/libcxxabi/include |
| 143 | ${LLVM_MAIN_SRC_DIR}/runtimes/libcxxabi/include |
Reid Kleckner | bfe423e | 2017-06-20 20:34:13 | [diff] [blame] | 144 | ${LLVM_MAIN_SRC_DIR}/../libcxxabi/include |
Petr Hosek | d842fed | 2016-11-09 03:22:28 | [diff] [blame] | 145 | NO_DEFAULT_PATH |
Don Hinton | 65d4ee3 | 2018-01-22 19:26:38 | [diff] [blame] | 146 | NO_CMAKE_FIND_ROOT_PATH |
Petr Hosek | d842fed | 2016-11-09 03:22:28 | [diff] [blame] | 147 | ) |
Shoaib Meenai | 3d1d1ea | 2017-04-20 23:33:49 | [diff] [blame] | 148 | if (LIBCXX_TARGETING_MSVC) |
| 149 | # FIXME: Figure out how to configure the ABI library on Windows. |
| 150 | set(LIBCXX_CXX_ABI_LIBNAME "vcruntime") |
| 151 | elseif ((NOT LIBCXX_STANDALONE_BUILD OR HAVE_LIBCXXABI) AND |
| 152 | IS_DIRECTORY "${LIBCXX_LIBCXXABI_INCLUDES_INTERNAL}") |
Eric Fiselier | 1cf5a81 | 2015-10-22 20:54:27 | [diff] [blame] | 153 | set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi") |
Petr Hosek | d842fed | 2016-11-09 03:22:28 | [diff] [blame] | 154 | set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${LIBCXX_LIBCXXABI_INCLUDES_INTERNAL}") |
Eric Fiselier | 1cf5a81 | 2015-10-22 20:54:27 | [diff] [blame] | 155 | set(LIBCXX_CXX_ABI_INTREE 1) |
Shoaib Meenai | 3d1d1ea | 2017-04-20 23:33:49 | [diff] [blame] | 156 | elseif (APPLE) |
| 157 | set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi") |
| 158 | set(LIBCXX_CXX_ABI_SYSTEM 1) |
Dimitry Andric | 524afae | 2018-02-11 22:31:05 | [diff] [blame] | 159 | elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") |
| 160 | set(LIBCXX_CXX_ABI_LIBNAME "libcxxrt") |
| 161 | set(LIBCXX_CXX_ABI_INCLUDE_PATHS "/usr/include/c++/v1") |
Eugene Zelenko | 96f1017 | 2016-08-08 18:01:50 | [diff] [blame] | 162 | else() |
Shoaib Meenai | 3d1d1ea | 2017-04-20 23:33:49 | [diff] [blame] | 163 | set(LIBCXX_CXX_ABI_LIBNAME "default") |
Eugene Zelenko | 96f1017 | 2016-08-08 18:01:50 | [diff] [blame] | 164 | endif() |
| 165 | else() |
Eric Fiselier | 1cf5a81 | 2015-10-22 20:54:27 | [diff] [blame] | 166 | set(LIBCXX_CXX_ABI_LIBNAME "${LIBCXX_CXX_ABI}") |
Eugene Zelenko | 96f1017 | 2016-08-08 18:01:50 | [diff] [blame] | 167 | endif() |
Eric Fiselier | 1cf5a81 | 2015-10-22 20:54:27 | [diff] [blame] | 168 | |
Eric Fiselier | bb856cc | 2015-10-15 22:41:51 | [diff] [blame] | 169 | # Use a static copy of the ABI library when linking libc++. This option |
| 170 | # cannot be used with LIBCXX_ENABLE_ABI_LINKER_SCRIPT. |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 171 | option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "Statically link the ABI library" OFF) |
| 172 | |
Petr Hosek | 44ef94a | 2018-07-24 07:06:17 | [diff] [blame] | 173 | cmake_dependent_option(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY |
| 174 | "Statically link the ABI library to static library" ON |
| 175 | "LIBCXX_ENABLE_STATIC_ABI_LIBRARY;LIBCXX_ENABLE_STATIC" OFF) |
| 176 | |
| 177 | cmake_dependent_option(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY |
| 178 | "Statically link the ABI library to shared library" ON |
Martin Storsjo | 8ddc6c6 | 2018-08-14 17:33:10 | [diff] [blame] | 179 | "LIBCXX_ENABLE_STATIC_ABI_LIBRARY;LIBCXX_ENABLE_SHARED" OFF) |
Petr Hosek | 44ef94a | 2018-07-24 07:06:17 | [diff] [blame] | 180 | |
Eric Fiselier | 8cbf020 | 2015-10-14 19:54:03 | [diff] [blame] | 181 | # Generate and install a linker script inplace of libc++.so. The linker script |
Eric Fiselier | bb856cc | 2015-10-15 22:41:51 | [diff] [blame] | 182 | # will link libc++ to the correct ABI library. This option is on by default |
Shoaib Meenai | e577401 | 2017-03-25 03:22:35 | [diff] [blame] | 183 | # on UNIX platforms other than Apple unless 'LIBCXX_ENABLE_STATIC_ABI_LIBRARY' |
Eric Fiselier | 5d5b59b | 2015-10-22 20:50:07 | [diff] [blame] | 184 | # is on. This option is also disabled when the ABI library is not specified |
| 185 | # or is specified to be "none". |
Eric Fiselier | bb856cc | 2015-10-15 22:41:51 | [diff] [blame] | 186 | set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF) |
Petr Hosek | 47d2a98 | 2018-07-26 05:10:24 | [diff] [blame] | 187 | if (LLVM_HAVE_LINK_VERSION_SCRIPT AND NOT LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY |
Eric Fiselier | 1cf5a81 | 2015-10-22 20:54:27 | [diff] [blame] | 188 | AND NOT LIBCXX_CXX_ABI_LIBNAME STREQUAL "none" |
Eric Fiselier | cfc5515 | 2017-01-03 01:18:48 | [diff] [blame] | 189 | AND NOT LIBCXX_CXX_ABI_LIBNAME STREQUAL "default" |
Asiri Rathnayake | 10a6829 | 2016-05-14 23:58:11 | [diff] [blame] | 190 | AND PYTHONINTERP_FOUND |
| 191 | AND LIBCXX_ENABLE_SHARED) |
Eric Fiselier | bb856cc | 2015-10-15 22:41:51 | [diff] [blame] | 192 | set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE ON) |
| 193 | endif() |
| 194 | |
Eric Fiselier | 8cbf020 | 2015-10-14 19:54:03 | [diff] [blame] | 195 | option(LIBCXX_ENABLE_ABI_LINKER_SCRIPT |
Eric Fiselier | bb856cc | 2015-10-15 22:41:51 | [diff] [blame] | 196 | "Use and install a linker script for the given ABI library" |
Eric Fiselier | 1d3716a | 2015-10-15 23:04:54 | [diff] [blame] | 197 | ${ENABLE_LINKER_SCRIPT_DEFAULT_VALUE}) |
Eric Fiselier | 8cbf020 | 2015-10-14 19:54:03 | [diff] [blame] | 198 | |
Eric Fiselier | dc69aac | 2017-03-02 19:35:33 | [diff] [blame] | 199 | set(ENABLE_NEW_DELETE_DEFAULT ON) |
| 200 | if (LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS) |
Eric Fiselier | 0cbd39f | 2017-03-02 21:55:03 | [diff] [blame] | 201 | # FIXME: This option should default to off. Unfortunatly GCC 4.9 fails to link |
Shoaib Meenai | f23e281 | 2017-03-25 03:29:51 | [diff] [blame] | 202 | # programs due to undefined references to new/delete in libc++abi so to work |
Eric Fiselier | 0cbd39f | 2017-03-02 21:55:03 | [diff] [blame] | 203 | # around this libc++abi currently defaults LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS |
| 204 | # to ON. Once the GCC bug has been worked around this option should be changed |
| 205 | # back to OFF. |
| 206 | set(ENABLE_NEW_DELETE_DEFAULT ON) |
Eric Fiselier | dc69aac | 2017-03-02 19:35:33 | [diff] [blame] | 207 | endif() |
| 208 | |
| 209 | option(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS |
| 210 | "Build libc++ with definitions for operator new/delete. This option can |
| 211 | be used to disable the definitions when libc++abi is expected to provide |
| 212 | them" ${ENABLE_NEW_DELETE_DEFAULT}) |
| 213 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 214 | # Build libc++abi with libunwind. We need this option to determine whether to |
| 215 | # link with libunwind or libgcc_s while running the test cases. |
| 216 | option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF) |
Petr Hosek | f4699a5 | 2017-02-09 02:19:43 | [diff] [blame] | 217 | option(LIBCXXABI_ENABLE_STATIC_UNWINDER "Statically link the LLVM unwinder." OFF) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 218 | |
| 219 | # Target options -------------------------------------------------------------- |
| 220 | option(LIBCXX_BUILD_32_BITS "Build 32 bit libc++." ${LLVM_BUILD_32_BITS}) |
| 221 | set(LIBCXX_SYSROOT "" CACHE STRING "Use alternate sysroot.") |
| 222 | set(LIBCXX_GCC_TOOLCHAIN "" CACHE STRING "Use alternate GCC toolchain.") |
| 223 | |
| 224 | # Feature options ------------------------------------------------------------- |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 225 | option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON) |
| 226 | option(LIBCXX_ENABLE_RTTI "Use run time type information." ON) |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 | [diff] [blame] | 227 | option(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE "Build libc++ with support for the global filesystem namespace." ON) |
Ed Schouten | abd06b4 | 2015-03-26 14:35:46 | [diff] [blame] | 228 | option(LIBCXX_ENABLE_STDIN "Build libc++ with support for stdin/std::cin." ON) |
| 229 | option(LIBCXX_ENABLE_STDOUT "Build libc++ with support for stdout/std::cout." ON) |
Eric Fiselier | 7330ed3 | 2014-12-06 21:02:58 | [diff] [blame] | 230 | option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON) |
Ed Schouten | 323ade3 | 2015-06-24 08:44:38 | [diff] [blame] | 231 | option(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS "Build libc++ with support for thread-unsafe C functions" ON) |
Eric Fiselier | 7330ed3 | 2014-12-06 21:02:58 | [diff] [blame] | 232 | option(LIBCXX_ENABLE_MONOTONIC_CLOCK |
| 233 | "Build libc++ with support for a monotonic clock. |
Jonathan Roelofs | 5e91fa1 | 2015-08-24 21:20:07 | [diff] [blame] | 234 | This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON) |
Vasileios Kalintiris | 579b42b | 2015-11-09 10:21:04 | [diff] [blame] | 235 | option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF) |
Ben Craig | 5163e46 | 2016-05-25 17:40:09 | [diff] [blame] | 236 | option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF) |
Martin Storsjo | 16eb426 | 2018-01-05 20:48:29 | [diff] [blame] | 237 | option(LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32 thread API" OFF) |
Asiri Rathnayake | 040945b | 2016-09-11 21:46:40 | [diff] [blame] | 238 | option(LIBCXX_HAS_EXTERNAL_THREAD_API |
| 239 | "Build libc++ with an externalized threading API. |
| 240 | This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF) |
Eric Fiselier | 66134e8 | 2017-01-06 20:05:40 | [diff] [blame] | 241 | option(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY |
| 242 | "Build libc++ with an externalized threading library. |
| 243 | This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON" OFF) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 244 | |
| 245 | # Misc options ---------------------------------------------------------------- |
Eric Fiselier | cb23a49 | 2015-10-10 03:34:52 | [diff] [blame] | 246 | # FIXME: Turn -pedantic back ON. It is currently off because it warns |
| 247 | # about #include_next which is used everywhere. |
| 248 | option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 249 | option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) |
Saleem Abdulrasool | ab008f7 | 2016-07-12 14:39:13 | [diff] [blame] | 250 | option(LIBCXX_DISABLE_MACRO_CONFLICT_WARNINGS "Disable #warnings about conflicting macros." OFF) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 251 | |
Eric Fiselier | bf9653d | 2015-03-31 04:15:45 | [diff] [blame] | 252 | option(LIBCXX_GENERATE_COVERAGE "Enable generating code coverage." OFF) |
| 253 | set(LIBCXX_COVERAGE_LIBRARY "" CACHE STRING |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 254 | "The Profile-rt library used to build with code coverage") |
| 255 | |
Eric Fiselier | 961269d | 2015-08-26 20:18:21 | [diff] [blame] | 256 | # Don't allow a user to accidentally overwrite the system libc++ installation on Darwin. |
| 257 | # If the user specifies -DCMAKE_INSTALL_PREFIX=/usr the install rules for libc++ |
| 258 | # will not be generated and a warning will be issued. |
| 259 | option(LIBCXX_OVERRIDE_DARWIN_INSTALL "Enable overwriting darwins libc++ installation." OFF) |
| 260 | mark_as_advanced(LIBCXX_OVERRIDE_DARWIN_INSTALL) # Don't show this option by default. |
| 261 | |
| 262 | if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT LIBCXX_OVERRIDE_DARWIN_INSTALL) |
| 263 | if ("${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr") |
| 264 | message(WARNING "Disabling libc++ install rules because installation would " |
| 265 | "overwrite the systems installation. Configure with " |
| 266 | "-DLIBCXX_OVERRIDE_DARWIN_INSTALL=ON to suppress this behaviour.") |
| 267 | mark_as_advanced(CLEAR LIBCXX_OVERRIDE_DARWIN_INSTALL) # Show the override option. |
| 268 | set(LIBCXX_INSTALL_HEADERS OFF) |
| 269 | set(LIBCXX_INSTALL_LIBRARY OFF) |
| 270 | endif() |
| 271 | endif() |
| 272 | |
Eric Fiselier | 85df7a8 | 2015-12-16 23:41:05 | [diff] [blame] | 273 | set(LIBCXX_CONFIGURE_IDE_DEFAULT OFF) |
| 274 | if (XCODE OR MSVC_IDE) |
| 275 | set(LIBCXX_CONFIGURE_IDE_DEFAULT ON) |
| 276 | endif() |
| 277 | option(LIBCXX_CONFIGURE_IDE "Configure libcxx for use within an IDE" |
| 278 | ${LIBCXX_CONFIGURE_IDE_DEFAULT}) |
| 279 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 280 | #=============================================================================== |
| 281 | # Check option configurations |
| 282 | #=============================================================================== |
| 283 | |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 | [diff] [blame] | 284 | if (LIBCXX_ENABLE_FILESYSTEM AND NOT LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY) |
| 285 | message(FATAL_ERROR |
| 286 | "LIBCXX_ENABLE_FILESYSTEM cannot be turned on when LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF") |
| 287 | endif() |
| 288 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 289 | # Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON only when |
| 290 | # LIBCXX_ENABLE_THREADS is on. |
| 291 | if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_ENABLE_MONOTONIC_CLOCK) |
| 292 | message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF" |
| 293 | " when LIBCXX_ENABLE_THREADS is also set to OFF.") |
Eric Fiselier | 25a1516 | 2014-08-18 05:03:46 | [diff] [blame] | 294 | endif() |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 295 | |
Asiri Rathnayake | e262e7b | 2017-01-03 12:59:50 | [diff] [blame] | 296 | if(NOT LIBCXX_ENABLE_THREADS) |
| 297 | if(LIBCXX_HAS_PTHREAD_API) |
| 298 | message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON" |
| 299 | " when LIBCXX_ENABLE_THREADS is also set to ON.") |
| 300 | endif() |
| 301 | if(LIBCXX_HAS_EXTERNAL_THREAD_API) |
| 302 | message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set to ON" |
| 303 | " when LIBCXX_ENABLE_THREADS is also set to ON.") |
| 304 | endif() |
Eric Fiselier | 66134e8 | 2017-01-06 20:05:40 | [diff] [blame] | 305 | if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY) |
| 306 | message(FATAL_ERROR "LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY can only be set " |
| 307 | "to ON when LIBCXX_ENABLE_THREADS is also set to ON.") |
| 308 | endif() |
Martin Storsjo | 16eb426 | 2018-01-05 20:48:29 | [diff] [blame] | 309 | if (LIBCXX_HAS_WIN32_THREAD_API) |
| 310 | message(FATAL_ERROR "LIBCXX_HAS_WIN32_THREAD_API can only be set to ON" |
| 311 | " when LIBCXX_ENABLE_THREADS is also set to ON.") |
| 312 | endif() |
Eric Fiselier | 66134e8 | 2017-01-06 20:05:40 | [diff] [blame] | 313 | |
| 314 | endif() |
| 315 | |
Asiri Rathnayake | da39f1b | 2017-01-09 10:38:56 | [diff] [blame] | 316 | if (LIBCXX_HAS_EXTERNAL_THREAD_API) |
| 317 | if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY) |
| 318 | message(FATAL_ERROR "The options LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY and " |
| 319 | "LIBCXX_HAS_EXTERNAL_THREAD_API cannot both be ON at " |
| 320 | "the same time") |
| 321 | endif() |
| 322 | if (LIBCXX_HAS_PTHREAD_API) |
| 323 | message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API" |
| 324 | "and LIBCXX_HAS_PTHREAD_API cannot be both" |
| 325 | "set to ON at the same time.") |
| 326 | endif() |
Martin Storsjo | 16eb426 | 2018-01-05 20:48:29 | [diff] [blame] | 327 | if (LIBCXX_HAS_WIN32_THREAD_API) |
| 328 | message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API" |
| 329 | "and LIBCXX_HAS_WIN32_THREAD_API cannot be both" |
| 330 | "set to ON at the same time.") |
| 331 | endif() |
| 332 | endif() |
| 333 | |
| 334 | if (LIBCXX_HAS_PTHREAD_API) |
| 335 | if (LIBCXX_HAS_WIN32_THREAD_API) |
| 336 | message(FATAL_ERROR "The options LIBCXX_HAS_PTHREAD_API" |
| 337 | "and LIBCXX_HAS_WIN32_THREAD_API cannot be both" |
| 338 | "set to ON at the same time.") |
| 339 | endif() |
Asiri Rathnayake | 040945b | 2016-09-11 21:46:40 | [diff] [blame] | 340 | endif() |
| 341 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 342 | # Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE |
| 343 | # is ON. |
| 344 | if (LLVM_USE_SANITIZER AND LIBCXX_GENERATE_COVERAGE) |
| 345 | message(FATAL_ERROR "LLVM_USE_SANITIZER cannot be used with LIBCXX_GENERATE_COVERAGE") |
| 346 | endif() |
| 347 | |
| 348 | # Set LIBCXX_BUILD_32_BITS to (LIBCXX_BUILD_32_BITS OR LLVM_BUILD_32_BITS) |
| 349 | # and check that we can build with 32 bits if requested. |
| 350 | if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32) |
| 351 | if (LIBCXX_BUILD_32_BITS AND NOT LLVM_BUILD_32_BITS) # Don't duplicate the output from LLVM |
| 352 | message(STATUS "Building 32 bits executables and libraries.") |
| 353 | endif() |
| 354 | elseif(LIBCXX_BUILD_32_BITS) |
| 355 | message(FATAL_ERROR "LIBCXX_BUILD_32_BITS=ON is not supported on this platform.") |
| 356 | endif() |
| 357 | |
| 358 | # Check that this option is not enabled on Apple and emit a usage warning. |
Eric Fiselier | c0b166e | 2015-03-03 15:59:51 | [diff] [blame] | 359 | if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) |
| 360 | if (APPLE) |
| 361 | message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is not supported on OS X") |
| 362 | else() |
| 363 | message(WARNING "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is an experimental option") |
| 364 | endif() |
Eric Fiselier | 60479ea | 2016-11-18 19:53:45 | [diff] [blame] | 365 | if (LIBCXX_ENABLE_STATIC AND NOT PYTHONINTERP_FOUND) |
| 366 | message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY requires python but it was not found.") |
| 367 | endif() |
Eric Fiselier | c0b166e | 2015-03-03 15:59:51 | [diff] [blame] | 368 | endif() |
| 369 | |
Eric Fiselier | 8cbf020 | 2015-10-14 19:54:03 | [diff] [blame] | 370 | if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT) |
| 371 | if (APPLE) |
| 372 | message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT cannot be used on APPLE targets") |
| 373 | endif() |
| 374 | if (NOT PYTHONINTERP_FOUND) |
| 375 | message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT requires python but it was not found.") |
| 376 | endif() |
Asiri Rathnayake | 10a6829 | 2016-05-14 23:58:11 | [diff] [blame] | 377 | if (NOT LIBCXX_ENABLE_SHARED) |
| 378 | message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT is only available for shared library builds.") |
| 379 | endif() |
Eric Fiselier | 8cbf020 | 2015-10-14 19:54:03 | [diff] [blame] | 380 | endif() |
| 381 | |
Petr Hosek | 47d2a98 | 2018-07-26 05:10:24 | [diff] [blame] | 382 | if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT) |
Eric Fiselier | 8cbf020 | 2015-10-14 19:54:03 | [diff] [blame] | 383 | message(FATAL_ERROR "Conflicting options given. |
| 384 | LIBCXX_ENABLE_STATIC_ABI_LIBRARY cannot be specified with |
| 385 | LIBCXX_ENABLE_ABI_LINKER_SCRIPT") |
| 386 | endif() |
| 387 | |
Vasileios Kalintiris | 579b42b | 2015-11-09 10:21:04 | [diff] [blame] | 388 | if (LIBCXX_HAS_MUSL_LIBC AND NOT LIBCXX_INSTALL_SUPPORT_HEADERS) |
| 389 | message(FATAL_ERROR "LIBCXX_INSTALL_SUPPORT_HEADERS can not be turned off" |
| 390 | "when building for Musl with LIBCXX_HAS_MUSL_LIBC.") |
| 391 | endif() |
| 392 | |
Shoaib Meenai | 7762784 | 2017-10-05 02:18:08 | [diff] [blame] | 393 | if (LIBCXX_ABI_FORCE_ITANIUM AND LIBCXX_ABI_FORCE_MICROSOFT) |
| 394 | message(FATAL_ERROR "Only one of LIBCXX_ABI_FORCE_ITANIUM and LIBCXX_ABI_FORCE_MICROSOFT can be specified.") |
Shoaib Meenai | 36d0ee6 | 2017-10-04 23:44:38 | [diff] [blame] | 395 | endif () |
| 396 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 397 | #=============================================================================== |
| 398 | # Configure System |
| 399 | #=============================================================================== |
| 400 | |
Eric Fiselier | 4778eed | 2014-12-20 03:16:55 | [diff] [blame] | 401 | set(LIBCXX_COMPILER ${CMAKE_CXX_COMPILER}) |
| 402 | set(LIBCXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 403 | set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
Eric Fiselier | bde2871 | 2017-01-16 20:47:35 | [diff] [blame] | 404 | set(LIBCXX_BINARY_INCLUDE_DIR "${LIBCXX_BINARY_DIR}/include/c++build") |
Petr Hosek | 4d66f09 | 2018-06-28 03:11:52 | [diff] [blame] | 405 | |
| 406 | string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION |
| 407 | ${PACKAGE_VERSION}) |
| 408 | |
| 409 | if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) |
| 410 | set(DEFAULT_INSTALL_PREFIX lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/${LLVM_DEFAULT_TARGET_TRIPLE}/) |
| 411 | set(DEFAULT_INSTALL_HEADER_PREFIX lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/) |
Petr Hosek | f51cf5e | 2018-07-10 19:13:33 | [diff] [blame] | 412 | set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION}/${LLVM_DEFAULT_TARGET_TRIPLE}/lib${LIBCXX_LIBDIR_SUFFIX}) |
Petr Hosek | 4d66f09 | 2018-06-28 03:11:52 | [diff] [blame] | 413 | set(LIBCXX_HEADER_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION}) |
| 414 | elseif(LLVM_LIBRARY_OUTPUT_INTDIR) |
Jonas Hahnfeld | f77a7df | 2017-05-04 06:02:50 | [diff] [blame] | 415 | set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) |
Petr Hosek | 83f3cdc | 2018-07-24 15:49:29 | [diff] [blame] | 416 | set(LIBCXX_HEADER_DIR ${LLVM_BINARY_DIR}) |
Jonas Hahnfeld | f77a7df | 2017-05-04 06:02:50 | [diff] [blame] | 417 | else() |
| 418 | set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) |
| 419 | endif() |
Petr Hosek | 4d66f09 | 2018-06-28 03:11:52 | [diff] [blame] | 420 | |
Eric Fiselier | bde2871 | 2017-01-16 20:47:35 | [diff] [blame] | 421 | file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}") |
Eric Fiselier | 4778eed | 2014-12-20 03:16:55 | [diff] [blame] | 422 | |
Petr Hosek | 4d66f09 | 2018-06-28 03:11:52 | [diff] [blame] | 423 | set(LIBCXX_INSTALL_PREFIX ${DEFAULT_INSTALL_PREFIX} CACHE STRING |
Petr Hosek | 347be61 | 2017-07-11 02:39:50 | [diff] [blame] | 424 | "Define libc++ destination prefix.") |
| 425 | |
Petr Hosek | 4d66f09 | 2018-06-28 03:11:52 | [diff] [blame] | 426 | set(LIBCXX_INSTALL_HEADER_PREFIX ${DEFAULT_INSTALL_HEADER_PREFIX} CACHE STRING |
| 427 | "Define libc++ header destination prefix.") |
Petr Hosek | 347be61 | 2017-07-11 02:39:50 | [diff] [blame] | 428 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 429 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) |
| 430 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) |
Shoaib Meenai | b975b45 | 2017-04-13 16:27:38 | [diff] [blame] | 431 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 432 | |
Eric Fiselier | 8e2855c | 2014-11-15 06:26:30 | [diff] [blame] | 433 | # Declare libc++ configuration variables. |
| 434 | # They are intended for use as follows: |
| 435 | # LIBCXX_CXX_FLAGS: General flags for both the compiler and linker. |
| 436 | # LIBCXX_COMPILE_FLAGS: Compile only flags. |
| 437 | # LIBCXX_LINK_FLAGS: Linker only flags. |
Eric Fiselier | 3bf8a9c | 2016-10-09 21:34:03 | [diff] [blame] | 438 | # LIBCXX_LIBRARIES: libraries libc++ is linked to. |
| 439 | # LIBCXX_INTERFACE_LIBRARIES: Libraries that must be linked when using libc++ |
Eric Fiselier | 742d878 | 2016-10-10 14:45:06 | [diff] [blame] | 440 | # These libraries are exposed in the linker script. |
Eric Fiselier | 8e2855c | 2014-11-15 06:26:30 | [diff] [blame] | 441 | set(LIBCXX_COMPILE_FLAGS "") |
| 442 | set(LIBCXX_LINK_FLAGS "") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 443 | set(LIBCXX_LIBRARIES "") |
Eric Fiselier | 3bf8a9c | 2016-10-09 21:34:03 | [diff] [blame] | 444 | set(LIBCXX_INTERFACE_LIBRARIES "") |
Eric Fiselier | 8e2855c | 2014-11-15 06:26:30 | [diff] [blame] | 445 | |
Eric Fiselier | a27cbf8 | 2016-06-02 01:10:08 | [diff] [blame] | 446 | # Include macros for adding and removing libc++ flags. |
| 447 | include(HandleLibcxxFlags) |
| 448 | |
| 449 | # Target flags ================================================================ |
| 450 | # These flags get added to CMAKE_CXX_FLAGS and CMAKE_C_FLAGS so that |
| 451 | # 'config-ix' use them during feature checks. It also adds them to both |
| 452 | # 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS' |
| 453 | add_target_flags_if(LIBCXX_BUILD_32_BITS "-m32") |
Petr Hosek | cebb3e9 | 2017-04-16 02:25:55 | [diff] [blame] | 454 | add_target_flags_if(LIBCXX_TARGET_TRIPLE "--target=${LIBCXX_TARGET_TRIPLE}") |
Eric Fiselier | a27cbf8 | 2016-06-02 01:10:08 | [diff] [blame] | 455 | add_target_flags_if(LIBCXX_SYSROOT "--sysroot=${LIBCXX_SYSROOT}") |
Petr Hosek | cebb3e9 | 2017-04-16 02:25:55 | [diff] [blame] | 456 | add_target_flags_if(LIBCXX_GCC_TOOLCHAIN "--gcc-toolchain=${LIBCXX_GCC_TOOLCHAIN}") |
Eric Fiselier | 6e467a8 | 2016-11-13 22:27:00 | [diff] [blame] | 457 | if (LIBCXX_TARGET_TRIPLE) |
| 458 | set(TARGET_TRIPLE "${LIBCXX_TARGET_TRIPLE}") |
| 459 | endif() |
Eric Fiselier | a27cbf8 | 2016-06-02 01:10:08 | [diff] [blame] | 460 | |
Eric Fiselier | 9a1468f | 2014-11-15 17:25:23 | [diff] [blame] | 461 | # Configure compiler. |
| 462 | include(config-ix) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 463 | |
Saleem Abdulrasool | e146f75 | 2016-08-24 04:22:52 | [diff] [blame] | 464 | if (LIBCXX_USE_COMPILER_RT) |
| 465 | list(APPEND LIBCXX_LINK_FLAGS "-rtlib=compiler-rt") |
| 466 | endif() |
| 467 | |
Eric Fiselier | bf9653d | 2015-03-31 04:15:45 | [diff] [blame] | 468 | # Configure coverage options. |
| 469 | if (LIBCXX_GENERATE_COVERAGE) |
| 470 | include(CodeCoverage) |
| 471 | set(CMAKE_BUILD_TYPE "COVERAGE" CACHE STRING "" FORCE) |
| 472 | endif() |
Eric Fiselier | 9a1468f | 2014-11-15 17:25:23 | [diff] [blame] | 473 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 474 | string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) |
Eric Fiselier | 157fd34 | 2017-01-14 07:54:39 | [diff] [blame] | 475 | if (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") |
| 476 | set(LIBCXX_DEBUG_BUILD ON) |
| 477 | else() |
| 478 | set(LIBCXX_DEBUG_BUILD OFF) |
| 479 | endif() |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 480 | |
Eric Fiselier | 9a1468f | 2014-11-15 17:25:23 | [diff] [blame] | 481 | #=============================================================================== |
| 482 | # Setup Compiler Flags |
| 483 | #=============================================================================== |
| 484 | |
JF Bastien | c7c4c77 | 2016-03-05 14:22:02 | [diff] [blame] | 485 | include(HandleLibCXXABI) # Setup the ABI library flags |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 486 | |
Michal Gorny | b79ca0a | 2016-09-27 07:55:26 | [diff] [blame] | 487 | if (NOT LIBCXX_STANDALONE_BUILD) |
| 488 | # Remove flags that may have snuck in. |
| 489 | remove_flags(-DNDEBUG -UNDEBUG -D_DEBUG |
Eric Fiselier | 8e39559 | 2017-01-17 23:27:56 | [diff] [blame] | 490 | -lc++abi) |
Michal Gorny | b79ca0a | 2016-09-27 07:55:26 | [diff] [blame] | 491 | endif() |
| 492 | remove_flags(-stdlib=libc++ -stdlib=libstdc++) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 493 | |
Eric Fiselier | fdd3c91 | 2017-01-14 06:06:47 | [diff] [blame] | 494 | # FIXME: Remove all debug flags and flags that change which Windows |
| 495 | # default libraries are linked. Currently we only support linking the |
| 496 | # non-debug DLLs |
Eric Fiselier | 157fd34 | 2017-01-14 07:54:39 | [diff] [blame] | 497 | remove_flags("/D_DEBUG" "/MTd" "/MDd" "/MT" "/Md") |
Eric Fiselier | fdd3c91 | 2017-01-14 06:06:47 | [diff] [blame] | 498 | |
Shoaib Meenai | 68fdad6 | 2017-03-25 03:42:20 | [diff] [blame] | 499 | # FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC. |
Eric Fiselier | 7b081f6 | 2015-10-15 20:27:15 | [diff] [blame] | 500 | # Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors |
Shoaib Meenai | 68fdad6 | 2017-03-25 03:42:20 | [diff] [blame] | 501 | # so they don't get transformed into -Wno and -errors respectively. |
Eric Fiselier | 7b081f6 | 2015-10-15 20:27:15 | [diff] [blame] | 502 | remove_flags(-Wno-pedantic -pedantic-errors -pedantic) |
Eric Fiselier | 499d878 | 2015-10-13 23:56:33 | [diff] [blame] | 503 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 504 | # Required flags ============================================================== |
Eric Fiselier | c9e74dd | 2016-08-14 22:51:54 | [diff] [blame] | 505 | set(LIBCXX_STANDARD_VER c++11 CACHE INTERNAL "internal option to change build dialect") |
Petr Hosek | 44197a1 | 2016-10-23 21:48:27 | [diff] [blame] | 506 | if (LIBCXX_HAS_MUSL_LIBC) |
| 507 | # musl's pthread implementations uses volatile types in their structs which is |
| 508 | # not a constexpr in C++11 but is in C++14, so we use C++14 with musl. |
| 509 | set(LIBCXX_STANDARD_VER c++14 CACHE INTERNAL "internal option to change build dialect") |
| 510 | endif() |
Eric Fiselier | c9e74dd | 2016-08-14 22:51:54 | [diff] [blame] | 511 | add_compile_flags_if_supported(-std=${LIBCXX_STANDARD_VER}) |
Eric Fiselier | 63f54c0 | 2018-10-01 01:00:11 | [diff] [blame] | 512 | add_compile_flags_if_supported("/std:${LIBCXX_STANDARD_VER}") |
Eric Fiselier | c9e74dd | 2016-08-14 22:51:54 | [diff] [blame] | 513 | mangle_name("LIBCXX_SUPPORTS_STD_EQ_${LIBCXX_STANDARD_VER}_FLAG" SUPPORTS_DIALECT_NAME) |
Eric Fiselier | 63f54c0 | 2018-10-01 01:00:11 | [diff] [blame] | 514 | mangle_name("LIBCXX_SUPPORTS_STD_COLON_${LIBCXX_STANDARD_VER}_FLAG" SUPPORTS_DIALECT_NAME_MSVC) |
| 515 | if(NOT ${SUPPORTS_DIALECT_NAME} AND NOT ${SUPPORTS_DIALECT_NAME_MSVC}) |
Saleem Abdulrasool | 1ca3c45 | 2017-01-01 20:20:40 | [diff] [blame] | 516 | if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" AND NOT "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC") |
| 517 | message(FATAL_ERROR "C++11 or greater is required but the compiler does not support ${LIBCXX_STANDARD_VER}") |
| 518 | endif() |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 519 | endif() |
| 520 | |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 521 | # On all systems the system c++ standard library headers need to be excluded. |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 522 | # MSVC only has -X, which disables all default includes; including the crt. |
| 523 | # Thus, we do nothing and hope we don't accidentally include any of the C++ |
| 524 | # headers |
| 525 | add_compile_flags_if_supported(-nostdinc++) |
Eric Fiselier | d74dee9 | 2015-07-29 21:07:28 | [diff] [blame] | 526 | |
Eric Fiselier | 8330b1e | 2016-10-25 19:43:44 | [diff] [blame] | 527 | # Hide all inline function definitions which have not explicitly been marked |
| 528 | # visible. This prevents new definitions for inline functions from appearing in |
| 529 | # the dylib when get ODR used by another function. |
| 530 | add_compile_flags_if_supported(-fvisibility-inlines-hidden) |
| 531 | |
Eric Fiselier | 737c3bf | 2017-05-25 04:36:24 | [diff] [blame] | 532 | if (LIBCXX_CONFIGURE_IDE) |
| 533 | # This simply allows IDE to process <experimental/coroutine> |
| 534 | add_compile_flags_if_supported(-fcoroutines-ts) |
| 535 | endif() |
| 536 | |
Eric Fiselier | 74c9857 | 2016-09-26 22:19:41 | [diff] [blame] | 537 | # Let the library headers know they are currently being used to build the |
| 538 | # library. |
Eric Fiselier | 6dbed46 | 2016-09-16 00:00:48 | [diff] [blame] | 539 | add_definitions(-D_LIBCPP_BUILDING_LIBRARY) |
| 540 | |
Eric Fiselier | dc69aac | 2017-03-02 19:35:33 | [diff] [blame] | 541 | if (NOT LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS) |
| 542 | add_definitions(-D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS) |
| 543 | endif() |
| 544 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 545 | # Warning flags =============================================================== |
Eric Fiselier | 692177d | 2015-07-18 20:40:46 | [diff] [blame] | 546 | add_definitions(-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 547 | add_compile_flags_if_supported( |
Eric Fiselier | 3ec6b84 | 2016-08-29 20:43:38 | [diff] [blame] | 548 | -Wall -Wextra -W -Wwrite-strings |
| 549 | -Wno-unused-parameter -Wno-long-long |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 550 | -Werror=return-type) |
Eric Fiselier | 3ec6b84 | 2016-08-29 20:43:38 | [diff] [blame] | 551 | if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") |
| 552 | add_compile_flags_if_supported( |
| 553 | -Wno-user-defined-literals |
| 554 | -Wno-covered-switch-default) |
Eric Fiselier | 76bd3e0 | 2018-10-01 01:15:50 | [diff] [blame] | 555 | if (LIBCXX_TARGETING_CLANG_CL) |
| 556 | add_compile_flags_if_supported( |
| 557 | -Wno-c++98-compat |
Eric Fiselier | 2641c80 | 2018-10-01 01:31:23 | [diff] [blame] | 558 | -Wno-c++98-compat-pedantic |
Eric Fiselier | 76bd3e0 | 2018-10-01 01:15:50 | [diff] [blame] | 559 | -Wno-c++11-compat |
| 560 | -Wno-undef |
Eric Fiselier | 2641c80 | 2018-10-01 01:31:23 | [diff] [blame] | 561 | -Wno-reserved-id-macro |
| 562 | -Wno-gnu-include-next |
| 563 | -Wno-gcc-compat # For ignoring "'diagnose_if' is a clang extension" warnings |
Eric Fiselier | e961cd6 | 2018-10-01 01:47:23 | [diff] [blame^] | 564 | -Wno-zero-as-null-pointer-constant # FIXME: Remove this and fix all occurrences. |
| 565 | -Wno-deprecated-dynamic-exception-spec # For auto_ptr |
| 566 | -Wno-sign-conversion |
| 567 | -Wno-old-style-cast |
| 568 | -Wno-deprecated # FIXME: Remove this and fix all occurrences. |
Eric Fiselier | 76bd3e0 | 2018-10-01 01:15:50 | [diff] [blame] | 569 | ) |
| 570 | endif() |
Eric Fiselier | 3ec6b84 | 2016-08-29 20:43:38 | [diff] [blame] | 571 | elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") |
| 572 | add_compile_flags_if_supported( |
Eric Fiselier | 3ec6b84 | 2016-08-29 20:43:38 | [diff] [blame] | 573 | -Wno-literal-suffix |
Eric Fiselier | f3b3a65 | 2017-04-03 20:53:15 | [diff] [blame] | 574 | -Wno-c++14-compat |
| 575 | -Wno-noexcept-type) |
Eric Fiselier | 3ec6b84 | 2016-08-29 20:43:38 | [diff] [blame] | 576 | endif() |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 577 | if (LIBCXX_ENABLE_WERROR) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 578 | add_compile_flags_if_supported(-Werror) |
| 579 | add_compile_flags_if_supported(-WX) |
Eric Fiselier | 26d2390 | 2015-07-31 01:25:01 | [diff] [blame] | 580 | else() |
| 581 | # TODO(EricWF) Remove this. We shouldn't be suppressing errors when -Werror is |
| 582 | # added elsewhere. |
| 583 | add_compile_flags_if_supported(-Wno-error) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 584 | endif() |
| 585 | if (LIBCXX_ENABLE_PEDANTIC) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 586 | add_compile_flags_if_supported(-pedantic) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 587 | endif() |
Saleem Abdulrasool | ab008f7 | 2016-07-12 14:39:13 | [diff] [blame] | 588 | if (LIBCXX_DISABLE_MACRO_CONFLICT_WARNINGS) |
| 589 | add_definitions(-D_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS) |
| 590 | endif() |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 591 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 592 | # Exception flags ============================================================= |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 593 | if (LIBCXX_ENABLE_EXCEPTIONS) |
| 594 | # Catches C++ exceptions only and tells the compiler to assume that extern C |
| 595 | # functions never throw a C++ exception. |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 596 | add_compile_flags_if_supported(-EHsc) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 597 | else() |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 598 | add_definitions(-D_LIBCPP_NO_EXCEPTIONS) |
| 599 | add_compile_flags_if_supported(-EHs- -EHa-) |
| 600 | add_compile_flags_if_supported(-fno-exceptions) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 601 | endif() |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 602 | |
| 603 | # RTTI flags ================================================================== |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 604 | if (NOT LIBCXX_ENABLE_RTTI) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 605 | add_definitions(-D_LIBCPP_NO_RTTI) |
| 606 | add_compile_flags_if_supported(-GR-) |
| 607 | add_compile_flags_if_supported(-fno-rtti) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 608 | endif() |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 609 | |
Asiri Rathnayake | 040945b | 2016-09-11 21:46:40 | [diff] [blame] | 610 | # Threading flags ============================================================= |
Asiri Rathnayake | da39f1b | 2017-01-09 10:38:56 | [diff] [blame] | 611 | if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY AND LIBCXX_ENABLE_SHARED) |
Asiri Rathnayake | 040945b | 2016-09-11 21:46:40 | [diff] [blame] | 612 | # Need to allow unresolved symbols if this is to work with shared library builds |
| 613 | if (APPLE) |
| 614 | add_link_flags("-undefined dynamic_lookup") |
| 615 | else() |
| 616 | # Relax this restriction from HandleLLVMOptions |
| 617 | string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") |
| 618 | endif() |
| 619 | endif() |
| 620 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 621 | # Assertion flags ============================================================= |
| 622 | define_if(LIBCXX_ENABLE_ASSERTIONS -UNDEBUG) |
| 623 | define_if_not(LIBCXX_ENABLE_ASSERTIONS -DNDEBUG) |
Eric Fiselier | b89eba0 | 2017-02-04 23:22:28 | [diff] [blame] | 624 | define_if(LIBCXX_ENABLE_ASSERTIONS -D_LIBCPP_DEBUG=0) |
Eric Fiselier | 157fd34 | 2017-01-14 07:54:39 | [diff] [blame] | 625 | define_if(LIBCXX_DEBUG_BUILD -D_DEBUG) |
| 626 | if (LIBCXX_ENABLE_ASSERTIONS AND NOT LIBCXX_DEBUG_BUILD) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 627 | # MSVC doesn't like _DEBUG on release builds. See PR 4379. |
Eric Fiselier | fdd3c91 | 2017-01-14 06:06:47 | [diff] [blame] | 628 | define_if_not(LIBCXX_TARGETING_MSVC -D_DEBUG) |
Howard Hinnant | 4a0e74f | 2013-02-25 15:50:36 | [diff] [blame] | 629 | endif() |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 630 | |
Eric Fiselier | 29026ad | 2016-10-14 12:56:52 | [diff] [blame] | 631 | # Modules flags =============================================================== |
| 632 | # FIXME The libc++ sources are fundamentally non-modular. They need special |
| 633 | # versions of the headers in order to provide C++03 and legacy ABI definitions. |
| 634 | # NOTE: The public headers can be used with modules in all other contexts. |
| 635 | if (LLVM_ENABLE_MODULES) |
| 636 | # Ignore that the rest of the modules flags are now unused. |
| 637 | add_compile_flags_if_supported(-Wno-unused-command-line-argument) |
| 638 | add_compile_flags(-fno-modules) |
| 639 | endif() |
| 640 | |
Jonathan Roelofs | 5e91fa1 | 2015-08-24 21:20:07 | [diff] [blame] | 641 | # Sanitizer flags ============================================================= |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 642 | |
Chris Bieneman | 8c22696 | 2016-08-18 21:31:51 | [diff] [blame] | 643 | # Configure for sanitizers. If LIBCXX_STANDALONE_BUILD then we have to do |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 644 | # the flag translation ourselves. Othewise LLVM's CMakeList.txt will handle it. |
Chris Bieneman | 8c22696 | 2016-08-18 21:31:51 | [diff] [blame] | 645 | if (LIBCXX_STANDALONE_BUILD) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 646 | set(LLVM_USE_SANITIZER "" CACHE STRING |
| 647 | "Define the sanitizer used to build the library and tests") |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 648 | # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC. |
| 649 | # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do. |
| 650 | if (LLVM_USE_SANITIZER AND NOT MSVC) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 651 | add_flags_if_supported("-fno-omit-frame-pointer") |
| 652 | add_flags_if_supported("-gline-tables-only") |
| 653 | |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 654 | if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND |
| 655 | NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 656 | add_flags_if_supported("-gline-tables-only") |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 657 | endif() |
| 658 | if (LLVM_USE_SANITIZER STREQUAL "Address") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 659 | add_flags("-fsanitize=address") |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 660 | elseif (LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 661 | add_flags(-fsanitize=memory) |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 662 | if (LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 663 | add_flags("-fsanitize-memory-track-origins") |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 664 | endif() |
| 665 | elseif (LLVM_USE_SANITIZER STREQUAL "Undefined") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 666 | add_flags("-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all") |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 667 | elseif (LLVM_USE_SANITIZER STREQUAL "Thread") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 668 | add_flags(-fsanitize=thread) |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 669 | else() |
| 670 | message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}") |
| 671 | endif() |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 672 | elseif(LLVM_USE_SANITIZER AND MSVC) |
| 673 | message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.") |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 674 | endif() |
| 675 | endif() |
Eric Fiselier | 73ffc78 | 2015-10-13 22:12:02 | [diff] [blame] | 676 | |
| 677 | # Configuration file flags ===================================================== |
Louis Dionne | 16357ee | 2018-09-26 08:24:51 | [diff] [blame] | 678 | if (NOT LIBCXX_ABI_VERSION EQUAL 1) |
Evgeniy Stepanov | 4f01aa8 | 2015-10-13 23:48:28 | [diff] [blame] | 679 | config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION) |
| 680 | endif() |
| 681 | config_define_if(LIBCXX_ABI_UNSTABLE _LIBCPP_ABI_UNSTABLE) |
Shoaib Meenai | 7762784 | 2017-10-05 02:18:08 | [diff] [blame] | 682 | config_define_if(LIBCXX_ABI_FORCE_ITANIUM _LIBCPP_ABI_FORCE_ITANIUM) |
| 683 | config_define_if(LIBCXX_ABI_FORCE_MICROSOFT _LIBCPP_ABI_FORCE_MICROSOFT) |
Louis Dionne | 61b0a00 | 2018-08-16 12:44:28 | [diff] [blame] | 684 | config_define_if(LIBCXX_HIDE_FROM_ABI_PER_TU_BY_DEFAULT _LIBCPP_HIDE_FROM_ABI_PER_TU_BY_DEFAULT) |
Evgeniy Stepanov | 4f01aa8 | 2015-10-13 23:48:28 | [diff] [blame] | 685 | |
Eric Fiselier | 73ffc78 | 2015-10-13 22:12:02 | [diff] [blame] | 686 | config_define_if_not(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE) |
| 687 | config_define_if_not(LIBCXX_ENABLE_STDIN _LIBCPP_HAS_NO_STDIN) |
| 688 | config_define_if_not(LIBCXX_ENABLE_STDOUT _LIBCPP_HAS_NO_STDOUT) |
| 689 | config_define_if_not(LIBCXX_ENABLE_THREADS _LIBCPP_HAS_NO_THREADS) |
| 690 | config_define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK _LIBCPP_HAS_NO_MONOTONIC_CLOCK) |
| 691 | config_define_if_not(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS) |
| 692 | |
Ben Craig | 5163e46 | 2016-05-25 17:40:09 | [diff] [blame] | 693 | config_define_if(LIBCXX_HAS_PTHREAD_API _LIBCPP_HAS_THREAD_API_PTHREAD) |
Asiri Rathnayake | 040945b | 2016-09-11 21:46:40 | [diff] [blame] | 694 | config_define_if(LIBCXX_HAS_EXTERNAL_THREAD_API _LIBCPP_HAS_THREAD_API_EXTERNAL) |
Martin Storsjo | 16eb426 | 2018-01-05 20:48:29 | [diff] [blame] | 695 | config_define_if(LIBCXX_HAS_WIN32_THREAD_API _LIBCPP_HAS_THREAD_API_WIN32) |
Eric Fiselier | 66134e8 | 2017-01-06 20:05:40 | [diff] [blame] | 696 | config_define_if(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) |
Vasileios Kalintiris | 579b42b | 2015-11-09 10:21:04 | [diff] [blame] | 697 | config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC) |
Shoaib Meenai | 18dba06 | 2017-10-09 19:25:17 | [diff] [blame] | 698 | config_define_if(LIBCXX_NO_VCRUNTIME _LIBCPP_NO_VCRUNTIME) |
Vasileios Kalintiris | 579b42b | 2015-11-09 10:21:04 | [diff] [blame] | 699 | |
Shoaib Meenai | 2bba98e | 2017-10-04 23:17:12 | [diff] [blame] | 700 | if (LIBCXX_ABI_DEFINES) |
| 701 | set(abi_defines) |
| 702 | foreach (abi_define ${LIBCXX_ABI_DEFINES}) |
| 703 | if (NOT abi_define MATCHES "^_LIBCPP_ABI_") |
| 704 | message(SEND_ERROR "Invalid ABI macro ${abi_define} in LIBCXX_ABI_DEFINES") |
| 705 | endif() |
| 706 | list(APPEND abi_defines "#define ${abi_define}") |
| 707 | endforeach() |
| 708 | string(REPLACE ";" "\n" abi_defines "${abi_defines}") |
| 709 | config_define(${abi_defines} _LIBCPP_ABI_DEFINES) |
| 710 | endif() |
| 711 | |
Eric Fiselier | 74c9857 | 2016-09-26 22:19:41 | [diff] [blame] | 712 | # By default libc++ on Windows expects to use a shared library, which requires |
| 713 | # the headers to use DLL import/export semantics. However when building a |
| 714 | # static library only we modify the headers to disable DLL import/export. |
| 715 | if (DEFINED WIN32 AND LIBCXX_ENABLE_STATIC AND NOT LIBCXX_ENABLE_SHARED) |
| 716 | message(STATUS "Generating custom __config for non-DLL Windows build") |
Shoaib Meenai | c6d8e8a | 2016-12-05 19:40:12 | [diff] [blame] | 717 | config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) |
Eric Fiselier | 74c9857 | 2016-09-26 22:19:41 | [diff] [blame] | 718 | endif() |
| 719 | |
Shoaib Meenai | 0a2af12 | 2017-09-14 18:23:43 | [diff] [blame] | 720 | set(site_config_path "${LIBCXX_BINARY_DIR}/__config_site") |
Eric Fiselier | 73ffc78 | 2015-10-13 22:12:02 | [diff] [blame] | 721 | if (LIBCXX_NEEDS_SITE_CONFIG) |
Saleem Abdulrasool | 1ca3c45 | 2017-01-01 20:20:40 | [diff] [blame] | 722 | configure_file("include/__config_site.in" |
Shoaib Meenai | 0a2af12 | 2017-09-14 18:23:43 | [diff] [blame] | 723 | "${site_config_path}" |
Saleem Abdulrasool | 1ca3c45 | 2017-01-01 20:20:40 | [diff] [blame] | 724 | @ONLY) |
| 725 | |
Eric Fiselier | a662279 | 2015-10-14 00:22:05 | [diff] [blame] | 726 | # Provide the config definitions by included the generated __config_site |
| 727 | # file at compile time. |
Saleem Abdulrasool | 1ca3c45 | 2017-01-01 20:20:40 | [diff] [blame] | 728 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC") |
| 729 | add_compile_flags("/FI\"${LIBCXX_BINARY_DIR}/__config_site\"") |
| 730 | else() |
| 731 | add_compile_flags("-include ${LIBCXX_BINARY_DIR}/__config_site") |
| 732 | endif() |
Shoaib Meenai | 0a2af12 | 2017-09-14 18:23:43 | [diff] [blame] | 733 | else() |
| 734 | if (EXISTS "${site_config_path}") |
| 735 | message(STATUS "Removing stale site configuration ${site_config_path}") |
| 736 | file(REMOVE "${site_config_path}") |
| 737 | endif() |
Eric Fiselier | 73ffc78 | 2015-10-13 22:12:02 | [diff] [blame] | 738 | endif() |
| 739 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 740 | #=============================================================================== |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 741 | # Setup Source Code And Tests |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 742 | #=============================================================================== |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 743 | include_directories(include) |
Howard Hinnant | c4962b3 | 2013-11-15 17:18:57 | [diff] [blame] | 744 | add_subdirectory(include) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 745 | add_subdirectory(lib) |
Eric Fiselier | b9f425a | 2015-08-22 19:40:49 | [diff] [blame] | 746 | |
Eric Fiselier | 5e000c6 | 2016-11-14 02:43:12 | [diff] [blame] | 747 | |
Eric Fiselier | d9b9ef7 | 2016-07-19 23:07:03 | [diff] [blame] | 748 | if (LIBCXX_INCLUDE_BENCHMARKS) |
| 749 | add_subdirectory(benchmarks) |
| 750 | endif() |
Eric Fiselier | c57fb58 | 2017-03-01 21:53:30 | [diff] [blame] | 751 | |
| 752 | # Create the lit.site.cfg file even when LIBCXX_INCLUDE_TESTS is OFF or |
| 753 | # LLVM_FOUND is OFF. This allows users to run the tests manually using |
| 754 | # LIT without requiring a full LLVM checkout. |
Duncan P. N. Exon Smith | 59a094f | 2017-05-03 23:33:54 | [diff] [blame] | 755 | # |
| 756 | # However, since some submission systems strip test/ subdirectories, check for |
| 757 | # it before adding it. |
Zachary Turner | 7a87049 | 2017-09-19 17:19:10 | [diff] [blame] | 758 | |
Duncan P. N. Exon Smith | 59a094f | 2017-05-03 23:33:54 | [diff] [blame] | 759 | if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/test") |
| 760 | add_subdirectory(test) |
| 761 | endif() |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 762 | if (LIBCXX_INCLUDE_TESTS) |
Eric Fiselier | 5e000c6 | 2016-11-14 02:43:12 | [diff] [blame] | 763 | add_subdirectory(lib/abi) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 764 | endif() |
Eric Fiselier | c57fb58 | 2017-03-01 21:53:30 | [diff] [blame] | 765 | |
Zachary Turner | 7a87049 | 2017-09-19 17:19:10 | [diff] [blame] | 766 | if (LIBCXX_STANDALONE_BUILD AND EXISTS "${LLVM_MAIN_SRC_DIR}/utils/llvm-lit") |
Petr Hosek | aec189a | 2017-12-01 03:16:50 | [diff] [blame] | 767 | include(AddLLVM) # for get_llvm_lit_path |
Zachary Turner | 7a87049 | 2017-09-19 17:19:10 | [diff] [blame] | 768 | # Make sure the llvm-lit script is generated into the bin directory, and do |
| 769 | # it after adding all tests, since the generated script will only work |
| 770 | # correctly discovered tests against test locations from the source tree that |
| 771 | # have already been discovered. |
| 772 | add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit |
| 773 | ${CMAKE_CURRENT_BINARY_DIR}/llvm-lit) |
| 774 | endif() |
| 775 | |
Eric Fiselier | b9f425a | 2015-08-22 19:40:49 | [diff] [blame] | 776 | if (LIBCXX_INCLUDE_DOCS) |
| 777 | add_subdirectory(docs) |
| 778 | endif() |