Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 1 | # See www/CMake.html for instructions on how to build libcxx with CMake. |
| 2 | |
| 3 | #=============================================================================== |
| 4 | # Setup Project |
| 5 | #=============================================================================== |
Chris Bieneman | cad86ff | 2016-05-31 20:21:52 +0000 | [diff] [blame] | 6 | cmake_minimum_required(VERSION 3.4.3) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 7 | |
Eric Fiselier | e9d4b23 | 2015-01-26 21:56:45 +0000 | [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 +0000 | [diff] [blame] | 11 | if(POLICY CMP0022) |
| 12 | cmake_policy(SET CMP0022 NEW) # Required when interacting with LLVM and Clang |
| 13 | endif() |
| 14 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 15 | # Add path for custom modules |
| 16 | set(CMAKE_MODULE_PATH |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 17 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake" |
| 18 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" |
Eric Fiselier | ce5695f | 2015-12-30 03:39:03 +0000 | [diff] [blame] | 19 | ${CMAKE_MODULE_PATH} |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 20 | ) |
| 21 | |
Saleem Abdulrasool | 7adfa03 | 2016-02-08 03:50:18 +0000 | [diff] [blame] | 22 | |
Eric Fiselier | 5e000c6 | 2016-11-14 02:43:12 +0000 | [diff] [blame] | 23 | if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) |
Saleem Abdulrasool | 7adfa03 | 2016-02-08 03:50:18 +0000 | [diff] [blame] | 24 | project(libcxx CXX C) |
| 25 | |
| 26 | set(PACKAGE_NAME libcxx) |
Eugene Zelenko | 96f1017 | 2016-08-08 18:01:50 +0000 | [diff] [blame] | 27 | set(PACKAGE_VERSION 4.0.0svn) |
Saleem Abdulrasool | 7adfa03 | 2016-02-08 03:50:18 +0000 | [diff] [blame] | 28 | set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") |
| 29 | set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org") |
Eric Fiselier | 5e000c6 | 2016-11-14 02:43:12 +0000 | [diff] [blame] | 30 | |
| 31 | # Find the LLVM sources and simulate LLVM CMake options. |
| 32 | include(HandleOutOfTreeLLVM) |
Eugene Zelenko | 96f1017 | 2016-08-08 18:01:50 +0000 | [diff] [blame] | 33 | endif() |
Saleem Abdulrasool | 7adfa03 | 2016-02-08 03:50:18 +0000 | [diff] [blame] | 34 | |
Petr Hosek | 39441fe | 2017-01-10 19:51:17 +0000 | [diff] [blame] | 35 | if (LIBCXX_STANDALONE_BUILD) |
| 36 | include(FindPythonInterp) |
| 37 | if( NOT PYTHONINTERP_FOUND ) |
| 38 | message(WARNING "Failed to find python interpreter. " |
| 39 | "The libc++ test suite will be disabled.") |
| 40 | set(LLVM_INCLUDE_TESTS OFF) |
| 41 | endif() |
| 42 | endif() |
| 43 | |
Saleem Abdulrasool | 7adfa03 | 2016-02-08 03:50:18 +0000 | [diff] [blame] | 44 | # Require out of source build. |
| 45 | include(MacroEnsureOutOfSourceBuild) |
| 46 | MACRO_ENSURE_OUT_OF_SOURCE_BUILD( |
| 47 | "${PROJECT_NAME} requires an out of source build. Please create a separate |
| 48 | build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there." |
| 49 | ) |
| 50 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 51 | #=============================================================================== |
| 52 | # Setup CMake Options |
| 53 | #=============================================================================== |
Eric Fiselier | 01609af | 2016-09-07 01:15:10 +0000 | [diff] [blame] | 54 | include(CMakeDependentOption) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 55 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 56 | # Basic options --------------------------------------------------------------- |
| 57 | option(LIBCXX_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON) |
| 58 | option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON) |
Petr Hosek | b640da0 | 2016-08-08 22:57:25 +0000 | [diff] [blame] | 59 | option(LIBCXX_ENABLE_STATIC "Build libc++ as a static library." ON) |
Eric Fiselier | 5e4698c | 2016-05-03 21:30:18 +0000 | [diff] [blame] | 60 | option(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY "Build libc++experimental.a" ON) |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 61 | option(LIBCXX_ENABLE_FILESYSTEM |
| 62 | "Build filesystem as part of libc++experimental.a" ${LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY}) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 63 | option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS}) |
Eric Fiselier | 2d2f0c0 | 2016-10-30 22:53:00 +0000 | [diff] [blame] | 64 | |
Eric Fiselier | 2d2f0c0 | 2016-10-30 22:53:00 +0000 | [diff] [blame] | 65 | # Benchmark options ----------------------------------------------------------- |
Eric Fiselier | 0a799bd | 2016-08-29 19:50:49 +0000 | [diff] [blame] | 66 | option(LIBCXX_INCLUDE_BENCHMARKS "Build the libc++ benchmarks and their dependancies" ON) |
Eric Fiselier | 2d2f0c0 | 2016-10-30 22:53:00 +0000 | [diff] [blame] | 67 | set(LIBCXX_BENCHMARK_NATIVE_STDLIB "" CACHE STRING |
| 68 | "Build the benchmarks against the specified native STL. |
| 69 | The value must be one of libc++/libstdc++") |
| 70 | set(LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN "" CACHE STRING |
| 71 | "Use alternate GCC toolchain when building the native benchmarks") |
| 72 | |
| 73 | if (LIBCXX_BENCHMARK_NATIVE_STDLIB) |
| 74 | if (NOT (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libc++" |
| 75 | OR LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libstdc++")) |
| 76 | message(FATAL_ERROR "Invalid value for LIBCXX_BENCHMARK_NATIVE_STDLIB: " |
| 77 | "'${LIBCXX_BENCHMARK_NATIVE_STDLIB}'") |
| 78 | endif() |
| 79 | endif() |
| 80 | |
Eric Fiselier | b9f425a | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 81 | option(LIBCXX_INCLUDE_DOCS "Build the libc++ documentation." ${LLVM_INCLUDE_DOCS}) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 82 | set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING |
| 83 | "Define suffix of library directory name (32/64)") |
| 84 | option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON) |
Eric Fiselier | 961269d | 2015-08-26 20:18:21 +0000 | [diff] [blame] | 85 | option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 86 | option(LIBCXX_INSTALL_SUPPORT_HEADERS "Install libc++ support headers." ON) |
Eric Fiselier | 01609af | 2016-09-07 01:15:10 +0000 | [diff] [blame] | 87 | cmake_dependent_option(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY |
| 88 | "Install libc++experimental.a" ON |
| 89 | "LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY;LIBCXX_INSTALL_LIBRARY" OFF) |
Evgeniy Stepanov | 4f01aa8 | 2015-10-13 23:48:28 +0000 | [diff] [blame] | 90 | set(LIBCXX_ABI_VERSION 1 CACHE STRING "ABI version of libc++.") |
| 91 | option(LIBCXX_ABI_UNSTABLE "Unstable ABI of libc++." OFF) |
Saleem Abdulrasool | e146f75 | 2016-08-24 04:22:52 +0000 | [diff] [blame] | 92 | option(LIBCXX_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 93 | |
Petr Hosek | b640da0 | 2016-08-08 22:57:25 +0000 | [diff] [blame] | 94 | if (NOT LIBCXX_ENABLE_SHARED AND NOT LIBCXX_ENABLE_STATIC) |
| 95 | message(FATAL_ERROR "libc++ must be built as either a shared or static library.") |
| 96 | endif() |
| 97 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 98 | # ABI Library options --------------------------------------------------------- |
Eric Fiselier | cfc5515 | 2017-01-03 01:18:48 +0000 | [diff] [blame] | 99 | set(LIBCXX_CXX_ABI "default" CACHE STRING |
| 100 | "Specify C++ ABI library to use.") |
| 101 | set(CXXABIS none default libcxxabi libcxxrt libstdc++ libsupc++) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 102 | set_property(CACHE LIBCXX_CXX_ABI PROPERTY STRINGS ;${CXXABIS}) |
| 103 | |
Eric Fiselier | cfc5515 | 2017-01-03 01:18:48 +0000 | [diff] [blame] | 104 | # FIXME: This is a temporary hack to force LLVM buildbots to store |
| 105 | # the fixed cache entry instead of the previous cache entry. This is needed |
| 106 | # because some LLVM buildbots don't clear their cache. It will be removed |
| 107 | # once all LLVM bots have been run. |
| 108 | if (LIBCXX_CXX_ABI STREQUAL "") |
| 109 | set(LIBCXX_CXX_ABI "default" CACHE STRING |
| 110 | "Specify the C++ ABI library to use." FORCE) |
| 111 | endif() |
| 112 | |
Eric Fiselier | 1cf5a81 | 2015-10-22 20:54:27 +0000 | [diff] [blame] | 113 | # Setup the default options if LIBCXX_CXX_ABI is not specified. |
Eric Fiselier | cfc5515 | 2017-01-03 01:18:48 +0000 | [diff] [blame] | 114 | if (LIBCXX_CXX_ABI STREQUAL "default") |
Petr Hosek | d842fed | 2016-11-09 03:22:28 +0000 | [diff] [blame] | 115 | find_path( |
| 116 | LIBCXX_LIBCXXABI_INCLUDES_INTERNAL |
| 117 | cxxabi.h |
| 118 | PATHS ${LLVM_MAIN_SRC_DIR}/projects/libcxxabi/include |
| 119 | ${LLVM_MAIN_SRC_DIR}/runtimes/libcxxabi/include |
| 120 | NO_DEFAULT_PATH |
| 121 | ) |
Petr Hosek | b81ce92 | 2017-01-11 23:56:31 +0000 | [diff] [blame^] | 122 | if (NOT DEFINED LIBCXX_STANDALONE_BUILD AND |
| 123 | IS_DIRECTORY "${LIBCXX_LIBCXXABI_INCLUDES_INTERNAL}") |
Eric Fiselier | 1cf5a81 | 2015-10-22 20:54:27 +0000 | [diff] [blame] | 124 | set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi") |
Petr Hosek | d842fed | 2016-11-09 03:22:28 +0000 | [diff] [blame] | 125 | set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${LIBCXX_LIBCXXABI_INCLUDES_INTERNAL}") |
Eric Fiselier | 1cf5a81 | 2015-10-22 20:54:27 +0000 | [diff] [blame] | 126 | set(LIBCXX_CXX_ABI_INTREE 1) |
Eugene Zelenko | 96f1017 | 2016-08-08 18:01:50 +0000 | [diff] [blame] | 127 | else() |
Eric Fiselier | bab7b41 | 2017-01-06 23:59:52 +0000 | [diff] [blame] | 128 | if (WIN32 AND NOT MINGW) |
| 129 | # FIXME: Figure out how to configure the ABI library on Windows. |
| 130 | set(LIBCXX_CXX_ABI_LIBNAME "none") |
| 131 | else() |
| 132 | set(LIBCXX_CXX_ABI_LIBNAME "default") |
| 133 | endif() |
Eugene Zelenko | 96f1017 | 2016-08-08 18:01:50 +0000 | [diff] [blame] | 134 | endif() |
| 135 | else() |
Eric Fiselier | 1cf5a81 | 2015-10-22 20:54:27 +0000 | [diff] [blame] | 136 | set(LIBCXX_CXX_ABI_LIBNAME "${LIBCXX_CXX_ABI}") |
Eugene Zelenko | 96f1017 | 2016-08-08 18:01:50 +0000 | [diff] [blame] | 137 | endif() |
Eric Fiselier | 1cf5a81 | 2015-10-22 20:54:27 +0000 | [diff] [blame] | 138 | |
Eric Fiselier | bb856cc | 2015-10-15 22:41:51 +0000 | [diff] [blame] | 139 | # Use a static copy of the ABI library when linking libc++. This option |
| 140 | # cannot be used with LIBCXX_ENABLE_ABI_LINKER_SCRIPT. |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 141 | option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "Statically link the ABI library" OFF) |
| 142 | |
Eric Fiselier | 8cbf020 | 2015-10-14 19:54:03 +0000 | [diff] [blame] | 143 | # Generate and install a linker script inplace of libc++.so. The linker script |
Eric Fiselier | bb856cc | 2015-10-15 22:41:51 +0000 | [diff] [blame] | 144 | # will link libc++ to the correct ABI library. This option is on by default |
| 145 | # On UNIX platforms other than Apple unless 'LIBCXX_ENABLE_STATIC_ABI_LIBRARY' |
Eric Fiselier | 5d5b59b | 2015-10-22 20:50:07 +0000 | [diff] [blame] | 146 | # is on. This option is also disabled when the ABI library is not specified |
| 147 | # or is specified to be "none". |
Eric Fiselier | bb856cc | 2015-10-15 22:41:51 +0000 | [diff] [blame] | 148 | set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF) |
Eric Fiselier | 1d3716a | 2015-10-15 23:04:54 +0000 | [diff] [blame] | 149 | if (LLVM_HAVE_LINK_VERSION_SCRIPT AND NOT LIBCXX_ENABLE_STATIC_ABI_LIBRARY |
Eric Fiselier | 1cf5a81 | 2015-10-22 20:54:27 +0000 | [diff] [blame] | 150 | AND NOT LIBCXX_CXX_ABI_LIBNAME STREQUAL "none" |
Eric Fiselier | cfc5515 | 2017-01-03 01:18:48 +0000 | [diff] [blame] | 151 | AND NOT LIBCXX_CXX_ABI_LIBNAME STREQUAL "default" |
Asiri Rathnayake | 10a6829 | 2016-05-14 23:58:11 +0000 | [diff] [blame] | 152 | AND PYTHONINTERP_FOUND |
| 153 | AND LIBCXX_ENABLE_SHARED) |
Eric Fiselier | bb856cc | 2015-10-15 22:41:51 +0000 | [diff] [blame] | 154 | set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE ON) |
| 155 | endif() |
| 156 | |
Eric Fiselier | 8cbf020 | 2015-10-14 19:54:03 +0000 | [diff] [blame] | 157 | option(LIBCXX_ENABLE_ABI_LINKER_SCRIPT |
Eric Fiselier | bb856cc | 2015-10-15 22:41:51 +0000 | [diff] [blame] | 158 | "Use and install a linker script for the given ABI library" |
Eric Fiselier | 1d3716a | 2015-10-15 23:04:54 +0000 | [diff] [blame] | 159 | ${ENABLE_LINKER_SCRIPT_DEFAULT_VALUE}) |
Eric Fiselier | 8cbf020 | 2015-10-14 19:54:03 +0000 | [diff] [blame] | 160 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 161 | # Build libc++abi with libunwind. We need this option to determine whether to |
| 162 | # link with libunwind or libgcc_s while running the test cases. |
| 163 | option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF) |
| 164 | |
| 165 | # Target options -------------------------------------------------------------- |
| 166 | option(LIBCXX_BUILD_32_BITS "Build 32 bit libc++." ${LLVM_BUILD_32_BITS}) |
| 167 | set(LIBCXX_SYSROOT "" CACHE STRING "Use alternate sysroot.") |
| 168 | set(LIBCXX_GCC_TOOLCHAIN "" CACHE STRING "Use alternate GCC toolchain.") |
| 169 | |
| 170 | # Feature options ------------------------------------------------------------- |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 171 | option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON) |
| 172 | option(LIBCXX_ENABLE_RTTI "Use run time type information." ON) |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 173 | 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 +0000 | [diff] [blame] | 174 | option(LIBCXX_ENABLE_STDIN "Build libc++ with support for stdin/std::cin." ON) |
| 175 | option(LIBCXX_ENABLE_STDOUT "Build libc++ with support for stdout/std::cout." ON) |
Eric Fiselier | 7330ed3 | 2014-12-06 21:02:58 +0000 | [diff] [blame] | 176 | option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON) |
Ed Schouten | 323ade3 | 2015-06-24 08:44:38 +0000 | [diff] [blame] | 177 | 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 +0000 | [diff] [blame] | 178 | option(LIBCXX_ENABLE_MONOTONIC_CLOCK |
| 179 | "Build libc++ with support for a monotonic clock. |
Jonathan Roelofs | 5e91fa1 | 2015-08-24 21:20:07 +0000 | [diff] [blame] | 180 | This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON) |
Vasileios Kalintiris | 579b42b | 2015-11-09 10:21:04 +0000 | [diff] [blame] | 181 | option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF) |
Ben Craig | 5163e46 | 2016-05-25 17:40:09 +0000 | [diff] [blame] | 182 | option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF) |
Asiri Rathnayake | 040945b | 2016-09-11 21:46:40 +0000 | [diff] [blame] | 183 | option(LIBCXX_HAS_EXTERNAL_THREAD_API |
| 184 | "Build libc++ with an externalized threading API. |
| 185 | This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF) |
Eric Fiselier | 66134e8 | 2017-01-06 20:05:40 +0000 | [diff] [blame] | 186 | option(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY |
| 187 | "Build libc++ with an externalized threading library. |
| 188 | This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON" OFF) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 189 | |
| 190 | # Misc options ---------------------------------------------------------------- |
Eric Fiselier | cb23a49 | 2015-10-10 03:34:52 +0000 | [diff] [blame] | 191 | # FIXME: Turn -pedantic back ON. It is currently off because it warns |
| 192 | # about #include_next which is used everywhere. |
| 193 | option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 194 | option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) |
Saleem Abdulrasool | ab008f7 | 2016-07-12 14:39:13 +0000 | [diff] [blame] | 195 | option(LIBCXX_DISABLE_MACRO_CONFLICT_WARNINGS "Disable #warnings about conflicting macros." OFF) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 196 | |
Eric Fiselier | bf9653d | 2015-03-31 04:15:45 +0000 | [diff] [blame] | 197 | option(LIBCXX_GENERATE_COVERAGE "Enable generating code coverage." OFF) |
| 198 | set(LIBCXX_COVERAGE_LIBRARY "" CACHE STRING |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 199 | "The Profile-rt library used to build with code coverage") |
| 200 | |
Eric Fiselier | 961269d | 2015-08-26 20:18:21 +0000 | [diff] [blame] | 201 | # Don't allow a user to accidentally overwrite the system libc++ installation on Darwin. |
| 202 | # If the user specifies -DCMAKE_INSTALL_PREFIX=/usr the install rules for libc++ |
| 203 | # will not be generated and a warning will be issued. |
| 204 | option(LIBCXX_OVERRIDE_DARWIN_INSTALL "Enable overwriting darwins libc++ installation." OFF) |
| 205 | mark_as_advanced(LIBCXX_OVERRIDE_DARWIN_INSTALL) # Don't show this option by default. |
| 206 | |
| 207 | if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT LIBCXX_OVERRIDE_DARWIN_INSTALL) |
| 208 | if ("${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr") |
| 209 | message(WARNING "Disabling libc++ install rules because installation would " |
| 210 | "overwrite the systems installation. Configure with " |
| 211 | "-DLIBCXX_OVERRIDE_DARWIN_INSTALL=ON to suppress this behaviour.") |
| 212 | mark_as_advanced(CLEAR LIBCXX_OVERRIDE_DARWIN_INSTALL) # Show the override option. |
| 213 | set(LIBCXX_INSTALL_HEADERS OFF) |
| 214 | set(LIBCXX_INSTALL_LIBRARY OFF) |
| 215 | endif() |
| 216 | endif() |
| 217 | |
Eric Fiselier | 85df7a8 | 2015-12-16 23:41:05 +0000 | [diff] [blame] | 218 | set(LIBCXX_CONFIGURE_IDE_DEFAULT OFF) |
| 219 | if (XCODE OR MSVC_IDE) |
| 220 | set(LIBCXX_CONFIGURE_IDE_DEFAULT ON) |
| 221 | endif() |
| 222 | option(LIBCXX_CONFIGURE_IDE "Configure libcxx for use within an IDE" |
| 223 | ${LIBCXX_CONFIGURE_IDE_DEFAULT}) |
| 224 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 225 | #=============================================================================== |
| 226 | # Check option configurations |
| 227 | #=============================================================================== |
| 228 | |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 229 | if (LIBCXX_ENABLE_FILESYSTEM AND NOT LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY) |
| 230 | message(FATAL_ERROR |
| 231 | "LIBCXX_ENABLE_FILESYSTEM cannot be turned on when LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF") |
| 232 | endif() |
| 233 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 234 | # Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON only when |
| 235 | # LIBCXX_ENABLE_THREADS is on. |
| 236 | if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_ENABLE_MONOTONIC_CLOCK) |
| 237 | message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF" |
| 238 | " when LIBCXX_ENABLE_THREADS is also set to OFF.") |
Eric Fiselier | 25a1516 | 2014-08-18 05:03:46 +0000 | [diff] [blame] | 239 | endif() |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 240 | |
Asiri Rathnayake | e262e7b | 2017-01-03 12:59:50 +0000 | [diff] [blame] | 241 | if(NOT LIBCXX_ENABLE_THREADS) |
| 242 | if(LIBCXX_HAS_PTHREAD_API) |
| 243 | message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON" |
| 244 | " when LIBCXX_ENABLE_THREADS is also set to ON.") |
| 245 | endif() |
| 246 | if(LIBCXX_HAS_EXTERNAL_THREAD_API) |
| 247 | message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set to ON" |
| 248 | " when LIBCXX_ENABLE_THREADS is also set to ON.") |
| 249 | endif() |
Eric Fiselier | 66134e8 | 2017-01-06 20:05:40 +0000 | [diff] [blame] | 250 | if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY) |
| 251 | message(FATAL_ERROR "LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY can only be set " |
| 252 | "to ON when LIBCXX_ENABLE_THREADS is also set to ON.") |
| 253 | endif() |
| 254 | |
| 255 | endif() |
| 256 | |
Asiri Rathnayake | da39f1b | 2017-01-09 10:38:56 +0000 | [diff] [blame] | 257 | if (LIBCXX_HAS_EXTERNAL_THREAD_API) |
| 258 | if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY) |
| 259 | message(FATAL_ERROR "The options LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY and " |
| 260 | "LIBCXX_HAS_EXTERNAL_THREAD_API cannot both be ON at " |
| 261 | "the same time") |
| 262 | endif() |
| 263 | if (LIBCXX_HAS_PTHREAD_API) |
| 264 | message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API" |
| 265 | "and LIBCXX_HAS_PTHREAD_API cannot be both" |
| 266 | "set to ON at the same time.") |
| 267 | endif() |
Asiri Rathnayake | 040945b | 2016-09-11 21:46:40 +0000 | [diff] [blame] | 268 | endif() |
| 269 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 270 | # Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE |
| 271 | # is ON. |
| 272 | if (LLVM_USE_SANITIZER AND LIBCXX_GENERATE_COVERAGE) |
| 273 | message(FATAL_ERROR "LLVM_USE_SANITIZER cannot be used with LIBCXX_GENERATE_COVERAGE") |
| 274 | endif() |
| 275 | |
| 276 | # Set LIBCXX_BUILD_32_BITS to (LIBCXX_BUILD_32_BITS OR LLVM_BUILD_32_BITS) |
| 277 | # and check that we can build with 32 bits if requested. |
| 278 | if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32) |
| 279 | if (LIBCXX_BUILD_32_BITS AND NOT LLVM_BUILD_32_BITS) # Don't duplicate the output from LLVM |
| 280 | message(STATUS "Building 32 bits executables and libraries.") |
| 281 | endif() |
| 282 | elseif(LIBCXX_BUILD_32_BITS) |
| 283 | message(FATAL_ERROR "LIBCXX_BUILD_32_BITS=ON is not supported on this platform.") |
| 284 | endif() |
| 285 | |
| 286 | # Check that this option is not enabled on Apple and emit a usage warning. |
Eric Fiselier | c0b166e | 2015-03-03 15:59:51 +0000 | [diff] [blame] | 287 | if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) |
| 288 | if (APPLE) |
| 289 | message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is not supported on OS X") |
| 290 | else() |
| 291 | message(WARNING "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is an experimental option") |
| 292 | endif() |
Eric Fiselier | 60479ea | 2016-11-18 19:53:45 +0000 | [diff] [blame] | 293 | if (LIBCXX_ENABLE_STATIC AND NOT PYTHONINTERP_FOUND) |
| 294 | message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY requires python but it was not found.") |
| 295 | endif() |
Eric Fiselier | c0b166e | 2015-03-03 15:59:51 +0000 | [diff] [blame] | 296 | endif() |
| 297 | |
Eric Fiselier | 8cbf020 | 2015-10-14 19:54:03 +0000 | [diff] [blame] | 298 | if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT) |
| 299 | if (APPLE) |
| 300 | message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT cannot be used on APPLE targets") |
| 301 | endif() |
| 302 | if (NOT PYTHONINTERP_FOUND) |
| 303 | message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT requires python but it was not found.") |
| 304 | endif() |
Asiri Rathnayake | 10a6829 | 2016-05-14 23:58:11 +0000 | [diff] [blame] | 305 | if (NOT LIBCXX_ENABLE_SHARED) |
| 306 | message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT is only available for shared library builds.") |
| 307 | endif() |
Eric Fiselier | 8cbf020 | 2015-10-14 19:54:03 +0000 | [diff] [blame] | 308 | endif() |
| 309 | |
| 310 | if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT) |
| 311 | message(FATAL_ERROR "Conflicting options given. |
| 312 | LIBCXX_ENABLE_STATIC_ABI_LIBRARY cannot be specified with |
| 313 | LIBCXX_ENABLE_ABI_LINKER_SCRIPT") |
| 314 | endif() |
| 315 | |
Vasileios Kalintiris | 579b42b | 2015-11-09 10:21:04 +0000 | [diff] [blame] | 316 | if (LIBCXX_HAS_MUSL_LIBC AND NOT LIBCXX_INSTALL_SUPPORT_HEADERS) |
| 317 | message(FATAL_ERROR "LIBCXX_INSTALL_SUPPORT_HEADERS can not be turned off" |
| 318 | "when building for Musl with LIBCXX_HAS_MUSL_LIBC.") |
| 319 | endif() |
| 320 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 321 | #=============================================================================== |
| 322 | # Configure System |
| 323 | #=============================================================================== |
| 324 | |
Eric Fiselier | 4778eed | 2014-12-20 03:16:55 +0000 | [diff] [blame] | 325 | set(LIBCXX_COMPILER ${CMAKE_CXX_COMPILER}) |
| 326 | set(LIBCXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 327 | set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
Chandler Carruth | 7a033ca | 2014-12-29 12:15:47 +0000 | [diff] [blame] | 328 | set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) |
Eric Fiselier | 4778eed | 2014-12-20 03:16:55 +0000 | [diff] [blame] | 329 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 330 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) |
| 331 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) |
| 332 | |
Eric Fiselier | 8e2855c | 2014-11-15 06:26:30 +0000 | [diff] [blame] | 333 | # Declare libc++ configuration variables. |
| 334 | # They are intended for use as follows: |
| 335 | # LIBCXX_CXX_FLAGS: General flags for both the compiler and linker. |
| 336 | # LIBCXX_COMPILE_FLAGS: Compile only flags. |
| 337 | # LIBCXX_LINK_FLAGS: Linker only flags. |
Eric Fiselier | 3bf8a9c | 2016-10-09 21:34:03 +0000 | [diff] [blame] | 338 | # LIBCXX_LIBRARIES: libraries libc++ is linked to. |
| 339 | # LIBCXX_INTERFACE_LIBRARIES: Libraries that must be linked when using libc++ |
Eric Fiselier | 742d878 | 2016-10-10 14:45:06 +0000 | [diff] [blame] | 340 | # These libraries are exposed in the linker script. |
Eric Fiselier | 8e2855c | 2014-11-15 06:26:30 +0000 | [diff] [blame] | 341 | set(LIBCXX_COMPILE_FLAGS "") |
| 342 | set(LIBCXX_LINK_FLAGS "") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 343 | set(LIBCXX_LIBRARIES "") |
Eric Fiselier | 3bf8a9c | 2016-10-09 21:34:03 +0000 | [diff] [blame] | 344 | set(LIBCXX_INTERFACE_LIBRARIES "") |
Eric Fiselier | 8e2855c | 2014-11-15 06:26:30 +0000 | [diff] [blame] | 345 | |
Eric Fiselier | a27cbf8 | 2016-06-02 01:10:08 +0000 | [diff] [blame] | 346 | # Include macros for adding and removing libc++ flags. |
| 347 | include(HandleLibcxxFlags) |
| 348 | |
| 349 | # Target flags ================================================================ |
| 350 | # These flags get added to CMAKE_CXX_FLAGS and CMAKE_C_FLAGS so that |
| 351 | # 'config-ix' use them during feature checks. It also adds them to both |
| 352 | # 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS' |
| 353 | add_target_flags_if(LIBCXX_BUILD_32_BITS "-m32") |
| 354 | add_target_flags_if(LIBCXX_TARGET_TRIPLE "-target ${LIBCXX_TARGET_TRIPLE}") |
| 355 | add_target_flags_if(LIBCXX_SYSROOT "--sysroot=${LIBCXX_SYSROOT}") |
| 356 | add_target_flags_if(LIBCXX_GCC_TOOLCHAIN "-gcc-toolchain ${LIBCXX_GCC_TOOLCHAIN}") |
Eric Fiselier | 6e467a8 | 2016-11-13 22:27:00 +0000 | [diff] [blame] | 357 | if (LIBCXX_TARGET_TRIPLE) |
| 358 | set(TARGET_TRIPLE "${LIBCXX_TARGET_TRIPLE}") |
| 359 | endif() |
Eric Fiselier | a27cbf8 | 2016-06-02 01:10:08 +0000 | [diff] [blame] | 360 | |
Eric Fiselier | 9a1468f | 2014-11-15 17:25:23 +0000 | [diff] [blame] | 361 | # Configure compiler. |
| 362 | include(config-ix) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 363 | |
Saleem Abdulrasool | e146f75 | 2016-08-24 04:22:52 +0000 | [diff] [blame] | 364 | if (LIBCXX_USE_COMPILER_RT) |
| 365 | list(APPEND LIBCXX_LINK_FLAGS "-rtlib=compiler-rt") |
| 366 | endif() |
| 367 | |
Eric Fiselier | bf9653d | 2015-03-31 04:15:45 +0000 | [diff] [blame] | 368 | # Configure coverage options. |
| 369 | if (LIBCXX_GENERATE_COVERAGE) |
| 370 | include(CodeCoverage) |
| 371 | set(CMAKE_BUILD_TYPE "COVERAGE" CACHE STRING "" FORCE) |
| 372 | endif() |
Eric Fiselier | 9a1468f | 2014-11-15 17:25:23 +0000 | [diff] [blame] | 373 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 374 | string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) |
| 375 | |
Eric Fiselier | 9a1468f | 2014-11-15 17:25:23 +0000 | [diff] [blame] | 376 | #=============================================================================== |
| 377 | # Setup Compiler Flags |
| 378 | #=============================================================================== |
| 379 | |
JF Bastien | c7c4c77 | 2016-03-05 14:22:02 +0000 | [diff] [blame] | 380 | include(HandleLibCXXABI) # Setup the ABI library flags |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 381 | |
Michal Gorny | b79ca0a | 2016-09-27 07:55:26 +0000 | [diff] [blame] | 382 | if (NOT LIBCXX_STANDALONE_BUILD) |
| 383 | # Remove flags that may have snuck in. |
| 384 | remove_flags(-DNDEBUG -UNDEBUG -D_DEBUG |
| 385 | -lc++abi -m32) |
| 386 | endif() |
| 387 | remove_flags(-stdlib=libc++ -stdlib=libstdc++) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 388 | |
Eric Fiselier | 499d878 | 2015-10-13 23:56:33 +0000 | [diff] [blame] | 389 | # FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC. |
Eric Fiselier | 7b081f6 | 2015-10-15 20:27:15 +0000 | [diff] [blame] | 390 | # Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors |
| 391 | # so they don't get transformed into -Wno and -errors respectivly. |
| 392 | remove_flags(-Wno-pedantic -pedantic-errors -pedantic) |
Eric Fiselier | 499d878 | 2015-10-13 23:56:33 +0000 | [diff] [blame] | 393 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 394 | # Required flags ============================================================== |
Eric Fiselier | c9e74dd | 2016-08-14 22:51:54 +0000 | [diff] [blame] | 395 | set(LIBCXX_STANDARD_VER c++11 CACHE INTERNAL "internal option to change build dialect") |
Petr Hosek | 44197a1 | 2016-10-23 21:48:27 +0000 | [diff] [blame] | 396 | if (LIBCXX_HAS_MUSL_LIBC) |
| 397 | # musl's pthread implementations uses volatile types in their structs which is |
| 398 | # not a constexpr in C++11 but is in C++14, so we use C++14 with musl. |
| 399 | set(LIBCXX_STANDARD_VER c++14 CACHE INTERNAL "internal option to change build dialect") |
| 400 | endif() |
Eric Fiselier | c9e74dd | 2016-08-14 22:51:54 +0000 | [diff] [blame] | 401 | add_compile_flags_if_supported(-std=${LIBCXX_STANDARD_VER}) |
| 402 | mangle_name("LIBCXX_SUPPORTS_STD_EQ_${LIBCXX_STANDARD_VER}_FLAG" SUPPORTS_DIALECT_NAME) |
Saleem Abdulrasool | 1ca3c45 | 2017-01-01 20:20:40 +0000 | [diff] [blame] | 403 | if(NOT ${SUPPORTS_DIALECT_NAME}) |
| 404 | if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" AND NOT "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC") |
| 405 | message(FATAL_ERROR "C++11 or greater is required but the compiler does not support ${LIBCXX_STANDARD_VER}") |
| 406 | endif() |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 407 | endif() |
| 408 | |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 409 | # On all systems the system c++ standard library headers need to be excluded. |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 410 | # MSVC only has -X, which disables all default includes; including the crt. |
| 411 | # Thus, we do nothing and hope we don't accidentally include any of the C++ |
| 412 | # headers |
| 413 | add_compile_flags_if_supported(-nostdinc++) |
Eric Fiselier | d74dee9 | 2015-07-29 21:07:28 +0000 | [diff] [blame] | 414 | |
Eric Fiselier | 8330b1e | 2016-10-25 19:43:44 +0000 | [diff] [blame] | 415 | # Hide all inline function definitions which have not explicitly been marked |
| 416 | # visible. This prevents new definitions for inline functions from appearing in |
| 417 | # the dylib when get ODR used by another function. |
| 418 | add_compile_flags_if_supported(-fvisibility-inlines-hidden) |
| 419 | |
Eric Fiselier | 74c9857 | 2016-09-26 22:19:41 +0000 | [diff] [blame] | 420 | # Let the library headers know they are currently being used to build the |
| 421 | # library. |
Eric Fiselier | 6dbed46 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 422 | add_definitions(-D_LIBCPP_BUILDING_LIBRARY) |
| 423 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 424 | # Warning flags =============================================================== |
Eric Fiselier | 692177d | 2015-07-18 20:40:46 +0000 | [diff] [blame] | 425 | add_definitions(-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 426 | add_compile_flags_if_supported( |
Eric Fiselier | 3ec6b84 | 2016-08-29 20:43:38 +0000 | [diff] [blame] | 427 | -Wall -Wextra -W -Wwrite-strings |
| 428 | -Wno-unused-parameter -Wno-long-long |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 429 | -Werror=return-type) |
Eric Fiselier | 3ec6b84 | 2016-08-29 20:43:38 +0000 | [diff] [blame] | 430 | if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") |
| 431 | add_compile_flags_if_supported( |
| 432 | -Wno-user-defined-literals |
| 433 | -Wno-covered-switch-default) |
| 434 | elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") |
| 435 | add_compile_flags_if_supported( |
Eric Fiselier | 3ec6b84 | 2016-08-29 20:43:38 +0000 | [diff] [blame] | 436 | -Wno-literal-suffix |
| 437 | -Wno-c++14-compat) |
| 438 | endif() |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 439 | if (LIBCXX_ENABLE_WERROR) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 440 | add_compile_flags_if_supported(-Werror) |
| 441 | add_compile_flags_if_supported(-WX) |
Eric Fiselier | 26d2390 | 2015-07-31 01:25:01 +0000 | [diff] [blame] | 442 | else() |
| 443 | # TODO(EricWF) Remove this. We shouldn't be suppressing errors when -Werror is |
| 444 | # added elsewhere. |
| 445 | add_compile_flags_if_supported(-Wno-error) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 446 | endif() |
| 447 | if (LIBCXX_ENABLE_PEDANTIC) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 448 | add_compile_flags_if_supported(-pedantic) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 449 | endif() |
Saleem Abdulrasool | ab008f7 | 2016-07-12 14:39:13 +0000 | [diff] [blame] | 450 | if (LIBCXX_DISABLE_MACRO_CONFLICT_WARNINGS) |
| 451 | add_definitions(-D_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS) |
| 452 | endif() |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 453 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 454 | # Exception flags ============================================================= |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 455 | if (LIBCXX_ENABLE_EXCEPTIONS) |
| 456 | # Catches C++ exceptions only and tells the compiler to assume that extern C |
| 457 | # functions never throw a C++ exception. |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 458 | add_compile_flags_if_supported(-EHsc) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 459 | else() |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 460 | add_definitions(-D_LIBCPP_NO_EXCEPTIONS) |
| 461 | add_compile_flags_if_supported(-EHs- -EHa-) |
| 462 | add_compile_flags_if_supported(-fno-exceptions) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 463 | endif() |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 464 | |
| 465 | # RTTI flags ================================================================== |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 466 | if (NOT LIBCXX_ENABLE_RTTI) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 467 | add_definitions(-D_LIBCPP_NO_RTTI) |
| 468 | add_compile_flags_if_supported(-GR-) |
| 469 | add_compile_flags_if_supported(-fno-rtti) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 470 | endif() |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 471 | |
Asiri Rathnayake | 040945b | 2016-09-11 21:46:40 +0000 | [diff] [blame] | 472 | # Threading flags ============================================================= |
Asiri Rathnayake | da39f1b | 2017-01-09 10:38:56 +0000 | [diff] [blame] | 473 | if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY AND LIBCXX_ENABLE_SHARED) |
Asiri Rathnayake | 040945b | 2016-09-11 21:46:40 +0000 | [diff] [blame] | 474 | # Need to allow unresolved symbols if this is to work with shared library builds |
| 475 | if (APPLE) |
| 476 | add_link_flags("-undefined dynamic_lookup") |
| 477 | else() |
| 478 | # Relax this restriction from HandleLLVMOptions |
| 479 | string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") |
| 480 | endif() |
| 481 | endif() |
| 482 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 483 | # Assertion flags ============================================================= |
| 484 | define_if(LIBCXX_ENABLE_ASSERTIONS -UNDEBUG) |
| 485 | define_if_not(LIBCXX_ENABLE_ASSERTIONS -DNDEBUG) |
Howard Hinnant | e103a3d | 2012-08-05 17:37:39 +0000 | [diff] [blame] | 486 | if (LIBCXX_ENABLE_ASSERTIONS) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 487 | # MSVC doesn't like _DEBUG on release builds. See PR 4379. |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 488 | define_if_not(MSVC -D_DEBUG) |
Howard Hinnant | 4a0e74f | 2013-02-25 15:50:36 +0000 | [diff] [blame] | 489 | endif() |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 490 | |
Eric Fiselier | 29026ad | 2016-10-14 12:56:52 +0000 | [diff] [blame] | 491 | # Modules flags =============================================================== |
| 492 | # FIXME The libc++ sources are fundamentally non-modular. They need special |
| 493 | # versions of the headers in order to provide C++03 and legacy ABI definitions. |
| 494 | # NOTE: The public headers can be used with modules in all other contexts. |
| 495 | if (LLVM_ENABLE_MODULES) |
| 496 | # Ignore that the rest of the modules flags are now unused. |
| 497 | add_compile_flags_if_supported(-Wno-unused-command-line-argument) |
| 498 | add_compile_flags(-fno-modules) |
| 499 | endif() |
| 500 | |
Jonathan Roelofs | 5e91fa1 | 2015-08-24 21:20:07 +0000 | [diff] [blame] | 501 | # Sanitizer flags ============================================================= |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 502 | |
Chris Bieneman | 8c22696 | 2016-08-18 21:31:51 +0000 | [diff] [blame] | 503 | # Configure for sanitizers. If LIBCXX_STANDALONE_BUILD then we have to do |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 504 | # the flag translation ourselves. Othewise LLVM's CMakeList.txt will handle it. |
Chris Bieneman | 8c22696 | 2016-08-18 21:31:51 +0000 | [diff] [blame] | 505 | if (LIBCXX_STANDALONE_BUILD) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 506 | set(LLVM_USE_SANITIZER "" CACHE STRING |
| 507 | "Define the sanitizer used to build the library and tests") |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 508 | # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC. |
| 509 | # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do. |
| 510 | if (LLVM_USE_SANITIZER AND NOT MSVC) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 511 | add_flags_if_supported("-fno-omit-frame-pointer") |
| 512 | add_flags_if_supported("-gline-tables-only") |
| 513 | |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 514 | if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND |
| 515 | NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 516 | add_flags_if_supported("-gline-tables-only") |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 517 | endif() |
| 518 | if (LLVM_USE_SANITIZER STREQUAL "Address") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 519 | add_flags("-fsanitize=address") |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 520 | elseif (LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 521 | add_flags(-fsanitize=memory) |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 522 | if (LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 523 | add_flags("-fsanitize-memory-track-origins") |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 524 | endif() |
| 525 | elseif (LLVM_USE_SANITIZER STREQUAL "Undefined") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 526 | add_flags("-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all") |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 527 | elseif (LLVM_USE_SANITIZER STREQUAL "Thread") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 528 | add_flags(-fsanitize=thread) |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 529 | else() |
| 530 | message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}") |
| 531 | endif() |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 532 | elseif(LLVM_USE_SANITIZER AND MSVC) |
| 533 | message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.") |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 534 | endif() |
| 535 | endif() |
Eric Fiselier | 73ffc78 | 2015-10-13 22:12:02 +0000 | [diff] [blame] | 536 | |
| 537 | # Configuration file flags ===================================================== |
Evgeniy Stepanov | 4f01aa8 | 2015-10-13 23:48:28 +0000 | [diff] [blame] | 538 | if (NOT LIBCXX_ABI_VERSION EQUAL "1") |
| 539 | config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION) |
| 540 | endif() |
| 541 | config_define_if(LIBCXX_ABI_UNSTABLE _LIBCPP_ABI_UNSTABLE) |
| 542 | |
Eric Fiselier | 73ffc78 | 2015-10-13 22:12:02 +0000 | [diff] [blame] | 543 | config_define_if_not(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE) |
| 544 | config_define_if_not(LIBCXX_ENABLE_STDIN _LIBCPP_HAS_NO_STDIN) |
| 545 | config_define_if_not(LIBCXX_ENABLE_STDOUT _LIBCPP_HAS_NO_STDOUT) |
| 546 | config_define_if_not(LIBCXX_ENABLE_THREADS _LIBCPP_HAS_NO_THREADS) |
| 547 | config_define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK _LIBCPP_HAS_NO_MONOTONIC_CLOCK) |
| 548 | config_define_if_not(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS) |
| 549 | |
Ben Craig | 5163e46 | 2016-05-25 17:40:09 +0000 | [diff] [blame] | 550 | config_define_if(LIBCXX_HAS_PTHREAD_API _LIBCPP_HAS_THREAD_API_PTHREAD) |
Asiri Rathnayake | 040945b | 2016-09-11 21:46:40 +0000 | [diff] [blame] | 551 | config_define_if(LIBCXX_HAS_EXTERNAL_THREAD_API _LIBCPP_HAS_THREAD_API_EXTERNAL) |
Eric Fiselier | 66134e8 | 2017-01-06 20:05:40 +0000 | [diff] [blame] | 552 | config_define_if(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) |
Vasileios Kalintiris | 579b42b | 2015-11-09 10:21:04 +0000 | [diff] [blame] | 553 | config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC) |
| 554 | |
Eric Fiselier | 74c9857 | 2016-09-26 22:19:41 +0000 | [diff] [blame] | 555 | # By default libc++ on Windows expects to use a shared library, which requires |
| 556 | # the headers to use DLL import/export semantics. However when building a |
| 557 | # static library only we modify the headers to disable DLL import/export. |
| 558 | if (DEFINED WIN32 AND LIBCXX_ENABLE_STATIC AND NOT LIBCXX_ENABLE_SHARED) |
| 559 | message(STATUS "Generating custom __config for non-DLL Windows build") |
Shoaib Meenai | c6d8e8a | 2016-12-05 19:40:12 +0000 | [diff] [blame] | 560 | config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) |
Eric Fiselier | 74c9857 | 2016-09-26 22:19:41 +0000 | [diff] [blame] | 561 | endif() |
| 562 | |
Eric Fiselier | 73ffc78 | 2015-10-13 22:12:02 +0000 | [diff] [blame] | 563 | if (LIBCXX_NEEDS_SITE_CONFIG) |
Saleem Abdulrasool | 1ca3c45 | 2017-01-01 20:20:40 +0000 | [diff] [blame] | 564 | configure_file("include/__config_site.in" |
| 565 | "${LIBCXX_BINARY_DIR}/__config_site" |
| 566 | @ONLY) |
| 567 | |
Eric Fiselier | a662279 | 2015-10-14 00:22:05 +0000 | [diff] [blame] | 568 | # Provide the config definitions by included the generated __config_site |
| 569 | # file at compile time. |
Saleem Abdulrasool | 1ca3c45 | 2017-01-01 20:20:40 +0000 | [diff] [blame] | 570 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC") |
| 571 | add_compile_flags("/FI\"${LIBCXX_BINARY_DIR}/__config_site\"") |
| 572 | else() |
| 573 | add_compile_flags("-include ${LIBCXX_BINARY_DIR}/__config_site") |
| 574 | endif() |
Eric Fiselier | 73ffc78 | 2015-10-13 22:12:02 +0000 | [diff] [blame] | 575 | endif() |
| 576 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 577 | #=============================================================================== |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 578 | # Setup Source Code And Tests |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 579 | #=============================================================================== |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 580 | include_directories(include) |
Howard Hinnant | c4962b3 | 2013-11-15 17:18:57 +0000 | [diff] [blame] | 581 | add_subdirectory(include) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 582 | add_subdirectory(lib) |
Eric Fiselier | b9f425a | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 583 | |
Eric Fiselier | 5e000c6 | 2016-11-14 02:43:12 +0000 | [diff] [blame] | 584 | |
Eric Fiselier | d9b9ef7 | 2016-07-19 23:07:03 +0000 | [diff] [blame] | 585 | if (LIBCXX_INCLUDE_BENCHMARKS) |
| 586 | add_subdirectory(benchmarks) |
| 587 | endif() |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 588 | if (LIBCXX_INCLUDE_TESTS) |
| 589 | add_subdirectory(test) |
Eric Fiselier | 5e000c6 | 2016-11-14 02:43:12 +0000 | [diff] [blame] | 590 | add_subdirectory(lib/abi) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 591 | endif() |
Eric Fiselier | b9f425a | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 592 | if (LIBCXX_INCLUDE_DOCS) |
| 593 | add_subdirectory(docs) |
| 594 | endif() |