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