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