Michael J. Spencer | 8d8164e | 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 | e490006 | 2016-05-31 20:21:52 +0000 | [diff] [blame^] | 6 | cmake_minimum_required(VERSION 3.4.3) |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 7 | |
Eric Fiselier | 9af31a4 | 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 | 156a46d | 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 | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 15 | # Add path for custom modules |
| 16 | set(CMAKE_MODULE_PATH |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 17 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake" |
| 18 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" |
Eric Fiselier | 0f932cb | 2015-12-30 03:39:03 +0000 | [diff] [blame] | 19 | ${CMAKE_MODULE_PATH} |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 20 | ) |
| 21 | |
Eric Fiselier | 0f932cb | 2015-12-30 03:39:03 +0000 | [diff] [blame] | 22 | # Find the LLVM sources and simulate LLVM CMake options. |
| 23 | include(HandleOutOfTreeLLVM) |
Saleem Abdulrasool | 115c9a9 | 2016-02-08 03:50:18 +0000 | [diff] [blame] | 24 | |
| 25 | if (LIBCXX_BUILT_STANDALONE) |
| 26 | project(libcxx CXX C) |
| 27 | |
| 28 | set(PACKAGE_NAME libcxx) |
| 29 | set(PACKAGE_VERSION trunk-svn) |
| 30 | set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") |
| 31 | set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org") |
| 32 | endif () |
| 33 | |
Eric Fiselier | 0f932cb | 2015-12-30 03:39:03 +0000 | [diff] [blame] | 34 | if (LIBCXX_BUILT_STANDALONE AND NOT LLVM_FOUND) |
| 35 | message(WARNING "UNSUPPORTED LIBCXX CONFIGURATION DETECTED: " |
| 36 | "llvm-config not found and LLVM_PATH not defined.\n" |
| 37 | "Reconfigure with -DLLVM_CONFIG=path/to/llvm-config " |
| 38 | "or -DLLVM_PATH=path/to/llvm-source-root.") |
| 39 | endif() |
| 40 | |
Saleem Abdulrasool | 115c9a9 | 2016-02-08 03:50:18 +0000 | [diff] [blame] | 41 | # Require out of source build. |
| 42 | include(MacroEnsureOutOfSourceBuild) |
| 43 | MACRO_ENSURE_OUT_OF_SOURCE_BUILD( |
| 44 | "${PROJECT_NAME} requires an out of source build. Please create a separate |
| 45 | build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there." |
| 46 | ) |
| 47 | |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 48 | #=============================================================================== |
| 49 | # Setup CMake Options |
| 50 | #=============================================================================== |
| 51 | |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 52 | # Basic options --------------------------------------------------------------- |
| 53 | option(LIBCXX_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON) |
| 54 | option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON) |
Eric Fiselier | 35950a5 | 2016-05-03 21:30:18 +0000 | [diff] [blame] | 55 | option(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY "Build libc++experimental.a" ON) |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 56 | option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS}) |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 57 | option(LIBCXX_INCLUDE_DOCS "Build the libc++ documentation." ${LLVM_INCLUDE_DOCS}) |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 58 | set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING |
| 59 | "Define suffix of library directory name (32/64)") |
| 60 | option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON) |
Eric Fiselier | 68205ee | 2015-08-26 20:18:21 +0000 | [diff] [blame] | 61 | option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON) |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 62 | option(LIBCXX_INSTALL_SUPPORT_HEADERS "Install libc++ support headers." ON) |
Eric Fiselier | 35950a5 | 2016-05-03 21:30:18 +0000 | [diff] [blame] | 63 | option(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY "Install libc++experimental.a" OFF) |
Evgeniy Stepanov | da2ff7e | 2015-10-13 23:48:28 +0000 | [diff] [blame] | 64 | set(LIBCXX_ABI_VERSION 1 CACHE STRING "ABI version of libc++.") |
| 65 | option(LIBCXX_ABI_UNSTABLE "Unstable ABI of libc++." OFF) |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 66 | |
| 67 | # ABI Library options --------------------------------------------------------- |
| 68 | set(LIBCXX_CXX_ABI "${LIBCXX_CXX_ABI}" CACHE STRING |
| 69 | "Specify C++ ABI library to use." FORCE) |
| 70 | set(CXXABIS none libcxxabi libcxxrt libstdc++ libsupc++) |
| 71 | set_property(CACHE LIBCXX_CXX_ABI PROPERTY STRINGS ;${CXXABIS}) |
| 72 | |
Eric Fiselier | 10cb09b | 2015-10-22 20:54:27 +0000 | [diff] [blame] | 73 | # Setup the default options if LIBCXX_CXX_ABI is not specified. |
| 74 | if (NOT LIBCXX_CXX_ABI) |
| 75 | if (NOT DEFINED LIBCXX_BUILT_STANDALONE AND |
| 76 | IS_DIRECTORY "${CMAKE_SOURCE_DIR}/projects/libcxxabi") |
| 77 | set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi") |
| 78 | set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${CMAKE_SOURCE_DIR}/projects/libcxxabi/include") |
| 79 | set(LIBCXX_CXX_ABI_INTREE 1) |
| 80 | else () |
| 81 | set(LIBCXX_CXX_ABI_LIBNAME "none") |
| 82 | endif () |
| 83 | else () |
| 84 | set(LIBCXX_CXX_ABI_LIBNAME "${LIBCXX_CXX_ABI}") |
| 85 | endif () |
| 86 | |
Eric Fiselier | 0b09dd1 | 2015-10-15 22:41:51 +0000 | [diff] [blame] | 87 | # Use a static copy of the ABI library when linking libc++. This option |
| 88 | # cannot be used with LIBCXX_ENABLE_ABI_LINKER_SCRIPT. |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 89 | option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "Statically link the ABI library" OFF) |
| 90 | |
Eric Fiselier | 2c16786 | 2015-10-14 19:54:03 +0000 | [diff] [blame] | 91 | # Generate and install a linker script inplace of libc++.so. The linker script |
Eric Fiselier | 0b09dd1 | 2015-10-15 22:41:51 +0000 | [diff] [blame] | 92 | # will link libc++ to the correct ABI library. This option is on by default |
| 93 | # On UNIX platforms other than Apple unless 'LIBCXX_ENABLE_STATIC_ABI_LIBRARY' |
Eric Fiselier | ea5fc6c | 2015-10-22 20:50:07 +0000 | [diff] [blame] | 94 | # is on. This option is also disabled when the ABI library is not specified |
| 95 | # or is specified to be "none". |
Eric Fiselier | 0b09dd1 | 2015-10-15 22:41:51 +0000 | [diff] [blame] | 96 | set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF) |
Eric Fiselier | 16a3c82 | 2015-10-15 23:04:54 +0000 | [diff] [blame] | 97 | if (LLVM_HAVE_LINK_VERSION_SCRIPT AND NOT LIBCXX_ENABLE_STATIC_ABI_LIBRARY |
Eric Fiselier | 10cb09b | 2015-10-22 20:54:27 +0000 | [diff] [blame] | 98 | AND NOT LIBCXX_CXX_ABI_LIBNAME STREQUAL "none" |
Asiri Rathnayake | 4fa5b8c | 2016-05-14 23:58:11 +0000 | [diff] [blame] | 99 | AND PYTHONINTERP_FOUND |
| 100 | AND LIBCXX_ENABLE_SHARED) |
Eric Fiselier | 0b09dd1 | 2015-10-15 22:41:51 +0000 | [diff] [blame] | 101 | set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE ON) |
| 102 | endif() |
| 103 | |
Eric Fiselier | 2c16786 | 2015-10-14 19:54:03 +0000 | [diff] [blame] | 104 | option(LIBCXX_ENABLE_ABI_LINKER_SCRIPT |
Eric Fiselier | 0b09dd1 | 2015-10-15 22:41:51 +0000 | [diff] [blame] | 105 | "Use and install a linker script for the given ABI library" |
Eric Fiselier | 16a3c82 | 2015-10-15 23:04:54 +0000 | [diff] [blame] | 106 | ${ENABLE_LINKER_SCRIPT_DEFAULT_VALUE}) |
Eric Fiselier | 2c16786 | 2015-10-14 19:54:03 +0000 | [diff] [blame] | 107 | |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 108 | # Build libc++abi with libunwind. We need this option to determine whether to |
| 109 | # link with libunwind or libgcc_s while running the test cases. |
| 110 | option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF) |
| 111 | |
| 112 | # Target options -------------------------------------------------------------- |
| 113 | option(LIBCXX_BUILD_32_BITS "Build 32 bit libc++." ${LLVM_BUILD_32_BITS}) |
| 114 | set(LIBCXX_SYSROOT "" CACHE STRING "Use alternate sysroot.") |
| 115 | set(LIBCXX_GCC_TOOLCHAIN "" CACHE STRING "Use alternate GCC toolchain.") |
| 116 | |
| 117 | # Feature options ------------------------------------------------------------- |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 118 | option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON) |
| 119 | option(LIBCXX_ENABLE_RTTI "Use run time type information." ON) |
Ed Schouten | 7009f4e | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 120 | option(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE "Build libc++ with support for the global filesystem namespace." ON) |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 121 | option(LIBCXX_ENABLE_STDIN "Build libc++ with support for stdin/std::cin." ON) |
| 122 | option(LIBCXX_ENABLE_STDOUT "Build libc++ with support for stdout/std::cout." ON) |
Eric Fiselier | 5b9755b | 2014-12-06 21:02:58 +0000 | [diff] [blame] | 123 | option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON) |
Ed Schouten | 137c863 | 2015-06-24 08:44:38 +0000 | [diff] [blame] | 124 | option(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS "Build libc++ with support for thread-unsafe C functions" ON) |
Eric Fiselier | 5b9755b | 2014-12-06 21:02:58 +0000 | [diff] [blame] | 125 | option(LIBCXX_ENABLE_MONOTONIC_CLOCK |
| 126 | "Build libc++ with support for a monotonic clock. |
Jonathan Roelofs | b6a8286 | 2015-08-24 21:20:07 +0000 | [diff] [blame] | 127 | This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON) |
Vasileios Kalintiris | 281b4cf | 2015-11-09 10:21:04 +0000 | [diff] [blame] | 128 | option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF) |
Ben Craig | 5593c4f | 2016-05-25 17:40:09 +0000 | [diff] [blame] | 129 | option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF) |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 130 | |
| 131 | # Misc options ---------------------------------------------------------------- |
Eric Fiselier | 62b5097 | 2015-10-10 03:34:52 +0000 | [diff] [blame] | 132 | # FIXME: Turn -pedantic back ON. It is currently off because it warns |
| 133 | # about #include_next which is used everywhere. |
| 134 | option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF) |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 135 | option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) |
| 136 | |
Eric Fiselier | bcd5d26 | 2015-03-31 04:15:45 +0000 | [diff] [blame] | 137 | option(LIBCXX_GENERATE_COVERAGE "Enable generating code coverage." OFF) |
| 138 | set(LIBCXX_COVERAGE_LIBRARY "" CACHE STRING |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 139 | "The Profile-rt library used to build with code coverage") |
| 140 | |
Eric Fiselier | 68205ee | 2015-08-26 20:18:21 +0000 | [diff] [blame] | 141 | # Don't allow a user to accidentally overwrite the system libc++ installation on Darwin. |
| 142 | # If the user specifies -DCMAKE_INSTALL_PREFIX=/usr the install rules for libc++ |
| 143 | # will not be generated and a warning will be issued. |
| 144 | option(LIBCXX_OVERRIDE_DARWIN_INSTALL "Enable overwriting darwins libc++ installation." OFF) |
| 145 | mark_as_advanced(LIBCXX_OVERRIDE_DARWIN_INSTALL) # Don't show this option by default. |
| 146 | |
| 147 | if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT LIBCXX_OVERRIDE_DARWIN_INSTALL) |
| 148 | if ("${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr") |
| 149 | message(WARNING "Disabling libc++ install rules because installation would " |
| 150 | "overwrite the systems installation. Configure with " |
| 151 | "-DLIBCXX_OVERRIDE_DARWIN_INSTALL=ON to suppress this behaviour.") |
| 152 | mark_as_advanced(CLEAR LIBCXX_OVERRIDE_DARWIN_INSTALL) # Show the override option. |
| 153 | set(LIBCXX_INSTALL_HEADERS OFF) |
| 154 | set(LIBCXX_INSTALL_LIBRARY OFF) |
| 155 | endif() |
| 156 | endif() |
| 157 | |
Eric Fiselier | 884539e | 2015-12-16 23:41:05 +0000 | [diff] [blame] | 158 | set(LIBCXX_CONFIGURE_IDE_DEFAULT OFF) |
| 159 | if (XCODE OR MSVC_IDE) |
| 160 | set(LIBCXX_CONFIGURE_IDE_DEFAULT ON) |
| 161 | endif() |
| 162 | option(LIBCXX_CONFIGURE_IDE "Configure libcxx for use within an IDE" |
| 163 | ${LIBCXX_CONFIGURE_IDE_DEFAULT}) |
| 164 | |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 165 | #=============================================================================== |
| 166 | # Check option configurations |
| 167 | #=============================================================================== |
| 168 | |
| 169 | # Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON only when |
| 170 | # LIBCXX_ENABLE_THREADS is on. |
| 171 | if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_ENABLE_MONOTONIC_CLOCK) |
| 172 | message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF" |
| 173 | " when LIBCXX_ENABLE_THREADS is also set to OFF.") |
Eric Fiselier | 2ff6e5a | 2014-08-18 05:03:46 +0000 | [diff] [blame] | 174 | endif() |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 175 | |
Ben Craig | 5593c4f | 2016-05-25 17:40:09 +0000 | [diff] [blame] | 176 | if(LIBCXX_HAS_PTHREAD_API AND NOT LIBCXX_ENABLE_THREADS) |
| 177 | message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON" |
| 178 | " when LIBCXX_ENABLE_THREADS is also set to ON.") |
| 179 | endif() |
| 180 | |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 181 | # Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE |
| 182 | # is ON. |
| 183 | if (LLVM_USE_SANITIZER AND LIBCXX_GENERATE_COVERAGE) |
| 184 | message(FATAL_ERROR "LLVM_USE_SANITIZER cannot be used with LIBCXX_GENERATE_COVERAGE") |
| 185 | endif() |
| 186 | |
| 187 | # Set LIBCXX_BUILD_32_BITS to (LIBCXX_BUILD_32_BITS OR LLVM_BUILD_32_BITS) |
| 188 | # and check that we can build with 32 bits if requested. |
| 189 | if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32) |
| 190 | if (LIBCXX_BUILD_32_BITS AND NOT LLVM_BUILD_32_BITS) # Don't duplicate the output from LLVM |
| 191 | message(STATUS "Building 32 bits executables and libraries.") |
| 192 | endif() |
| 193 | elseif(LIBCXX_BUILD_32_BITS) |
| 194 | message(FATAL_ERROR "LIBCXX_BUILD_32_BITS=ON is not supported on this platform.") |
| 195 | endif() |
| 196 | |
| 197 | # Check that this option is not enabled on Apple and emit a usage warning. |
Eric Fiselier | 070ed9a | 2015-03-03 15:59:51 +0000 | [diff] [blame] | 198 | if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) |
| 199 | if (APPLE) |
| 200 | message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is not supported on OS X") |
| 201 | else() |
| 202 | message(WARNING "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is an experimental option") |
| 203 | endif() |
| 204 | endif() |
| 205 | |
Eric Fiselier | 2c16786 | 2015-10-14 19:54:03 +0000 | [diff] [blame] | 206 | if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT) |
| 207 | if (APPLE) |
| 208 | message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT cannot be used on APPLE targets") |
| 209 | endif() |
| 210 | if (NOT PYTHONINTERP_FOUND) |
| 211 | message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT requires python but it was not found.") |
| 212 | endif() |
Asiri Rathnayake | 4fa5b8c | 2016-05-14 23:58:11 +0000 | [diff] [blame] | 213 | if (NOT LIBCXX_ENABLE_SHARED) |
| 214 | message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT is only available for shared library builds.") |
| 215 | endif() |
Eric Fiselier | 2c16786 | 2015-10-14 19:54:03 +0000 | [diff] [blame] | 216 | endif() |
| 217 | |
| 218 | if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT) |
| 219 | message(FATAL_ERROR "Conflicting options given. |
| 220 | LIBCXX_ENABLE_STATIC_ABI_LIBRARY cannot be specified with |
| 221 | LIBCXX_ENABLE_ABI_LINKER_SCRIPT") |
| 222 | endif() |
| 223 | |
Vasileios Kalintiris | 281b4cf | 2015-11-09 10:21:04 +0000 | [diff] [blame] | 224 | if (LIBCXX_HAS_MUSL_LIBC AND NOT LIBCXX_INSTALL_SUPPORT_HEADERS) |
| 225 | message(FATAL_ERROR "LIBCXX_INSTALL_SUPPORT_HEADERS can not be turned off" |
| 226 | "when building for Musl with LIBCXX_HAS_MUSL_LIBC.") |
| 227 | endif() |
| 228 | |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 229 | #=============================================================================== |
| 230 | # Configure System |
| 231 | #=============================================================================== |
| 232 | |
Eric Fiselier | 26dcc93 | 2014-12-20 03:16:55 +0000 | [diff] [blame] | 233 | set(LIBCXX_COMPILER ${CMAKE_CXX_COMPILER}) |
| 234 | set(LIBCXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 235 | set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
Chandler Carruth | ec54e10 | 2014-12-29 12:15:47 +0000 | [diff] [blame] | 236 | set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) |
Eric Fiselier | 26dcc93 | 2014-12-20 03:16:55 +0000 | [diff] [blame] | 237 | |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 238 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) |
| 239 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) |
| 240 | |
Eric Fiselier | 6a4f6ce | 2014-11-15 06:26:30 +0000 | [diff] [blame] | 241 | # Declare libc++ configuration variables. |
| 242 | # They are intended for use as follows: |
| 243 | # LIBCXX_CXX_FLAGS: General flags for both the compiler and linker. |
| 244 | # LIBCXX_COMPILE_FLAGS: Compile only flags. |
| 245 | # LIBCXX_LINK_FLAGS: Linker only flags. |
Eric Fiselier | 6a4f6ce | 2014-11-15 06:26:30 +0000 | [diff] [blame] | 246 | set(LIBCXX_COMPILE_FLAGS "") |
| 247 | set(LIBCXX_LINK_FLAGS "") |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 248 | set(LIBCXX_LIBRARIES "") |
Eric Fiselier | 6a4f6ce | 2014-11-15 06:26:30 +0000 | [diff] [blame] | 249 | |
Eric Fiselier | d0e4e10 | 2014-11-15 17:25:23 +0000 | [diff] [blame] | 250 | # Configure compiler. |
| 251 | include(config-ix) |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 252 | |
Eric Fiselier | bcd5d26 | 2015-03-31 04:15:45 +0000 | [diff] [blame] | 253 | # Configure coverage options. |
| 254 | if (LIBCXX_GENERATE_COVERAGE) |
| 255 | include(CodeCoverage) |
| 256 | set(CMAKE_BUILD_TYPE "COVERAGE" CACHE STRING "" FORCE) |
| 257 | endif() |
Eric Fiselier | d0e4e10 | 2014-11-15 17:25:23 +0000 | [diff] [blame] | 258 | |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 259 | string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) |
| 260 | |
Eric Fiselier | d0e4e10 | 2014-11-15 17:25:23 +0000 | [diff] [blame] | 261 | #=============================================================================== |
| 262 | # Setup Compiler Flags |
| 263 | #=============================================================================== |
| 264 | |
JF Bastien | bffc6cf | 2016-03-05 14:22:02 +0000 | [diff] [blame] | 265 | include(HandleLibCXXABI) # Setup the ABI library flags |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 266 | |
| 267 | # Include macros for adding and removing libc++ flags. |
| 268 | include(HandleLibcxxFlags) |
| 269 | |
| 270 | # Remove flags that may have snuck in. |
| 271 | remove_flags(-DNDEBUG -UNDEBUG -D_DEBUG |
| 272 | -stdlib=libc++ -stdlib=libstdc++ -lc++abi -m32) |
| 273 | |
Eric Fiselier | 25426b9 | 2015-10-13 23:56:33 +0000 | [diff] [blame] | 274 | # FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC. |
Eric Fiselier | cadda54 | 2015-10-15 20:27:15 +0000 | [diff] [blame] | 275 | # Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors |
| 276 | # so they don't get transformed into -Wno and -errors respectivly. |
| 277 | remove_flags(-Wno-pedantic -pedantic-errors -pedantic) |
Eric Fiselier | 25426b9 | 2015-10-13 23:56:33 +0000 | [diff] [blame] | 278 | |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 279 | # Required flags ============================================================== |
| 280 | add_compile_flags_if_supported(-std=c++11) |
| 281 | if (NOT MSVC AND NOT LIBCXX_SUPPORTS_STD_EQ_CXX11_FLAG) |
| 282 | message(FATAL_ERROR "C++11 is required but the compiler does not support -std=c++11") |
| 283 | endif() |
| 284 | |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 285 | # On all systems the system c++ standard library headers need to be excluded. |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 286 | # MSVC only has -X, which disables all default includes; including the crt. |
| 287 | # Thus, we do nothing and hope we don't accidentally include any of the C++ |
| 288 | # headers |
| 289 | add_compile_flags_if_supported(-nostdinc++) |
Eric Fiselier | 285e796 | 2015-07-29 21:07:28 +0000 | [diff] [blame] | 290 | |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 291 | # Target flags ================================================================ |
| 292 | add_flags_if(LIBCXX_BUILD_32_BITS -m32) |
| 293 | add_flags_if(LIBCXX_TARGET_TRIPLE "-target ${LIBCXX_TARGET_TRIPLE}") |
| 294 | add_flags_if(LIBCXX_SYSROOT "--sysroot ${LIBCXX_SYSROOT}") |
| 295 | add_flags_if(LIBCXX_GCC_TOOLCHAIN "-gcc-toolchain ${LIBCXX_GCC_TOOLCHAIN}") |
Eric Fiselier | 64473a1 | 2015-07-29 00:03:51 +0000 | [diff] [blame] | 296 | |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 297 | # Warning flags =============================================================== |
Eric Fiselier | e012bf2 | 2015-07-18 20:40:46 +0000 | [diff] [blame] | 298 | add_definitions(-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 299 | add_compile_flags_if_supported( |
| 300 | -Wall -W -Wwrite-strings |
| 301 | -Wno-unused-parameter -Wno-long-long |
| 302 | -Werror=return-type) |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 303 | if (LIBCXX_ENABLE_WERROR) |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 304 | add_compile_flags_if_supported(-Werror) |
| 305 | add_compile_flags_if_supported(-WX) |
Eric Fiselier | 4959dd9 | 2015-07-31 01:25:01 +0000 | [diff] [blame] | 306 | else() |
| 307 | # TODO(EricWF) Remove this. We shouldn't be suppressing errors when -Werror is |
| 308 | # added elsewhere. |
| 309 | add_compile_flags_if_supported(-Wno-error) |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 310 | endif() |
| 311 | if (LIBCXX_ENABLE_PEDANTIC) |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 312 | add_compile_flags_if_supported(-pedantic) |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 313 | endif() |
| 314 | |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 315 | # Exception flags ============================================================= |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 316 | if (LIBCXX_ENABLE_EXCEPTIONS) |
| 317 | # Catches C++ exceptions only and tells the compiler to assume that extern C |
| 318 | # functions never throw a C++ exception. |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 319 | add_compile_flags_if_supported(-EHsc) |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 320 | else() |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 321 | add_definitions(-D_LIBCPP_NO_EXCEPTIONS) |
| 322 | add_compile_flags_if_supported(-EHs- -EHa-) |
| 323 | add_compile_flags_if_supported(-fno-exceptions) |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 324 | endif() |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 325 | |
| 326 | # RTTI flags ================================================================== |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 327 | if (NOT LIBCXX_ENABLE_RTTI) |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 328 | add_definitions(-D_LIBCPP_NO_RTTI) |
| 329 | add_compile_flags_if_supported(-GR-) |
| 330 | add_compile_flags_if_supported(-fno-rtti) |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 331 | endif() |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 332 | |
| 333 | # Assertion flags ============================================================= |
| 334 | define_if(LIBCXX_ENABLE_ASSERTIONS -UNDEBUG) |
| 335 | define_if_not(LIBCXX_ENABLE_ASSERTIONS -DNDEBUG) |
Howard Hinnant | ec3bb02 | 2012-08-05 17:37:39 +0000 | [diff] [blame] | 336 | if (LIBCXX_ENABLE_ASSERTIONS) |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 337 | # MSVC doesn't like _DEBUG on release builds. See PR 4379. |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 338 | define_if_not(MSVC -D_DEBUG) |
Howard Hinnant | 807d633 | 2013-02-25 15:50:36 +0000 | [diff] [blame] | 339 | endif() |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 340 | |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 341 | # Feature flags =============================================================== |
| 342 | define_if(MSVC -D_CRT_SECURE_NO_WARNINGS) |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 343 | |
Jonathan Roelofs | b6a8286 | 2015-08-24 21:20:07 +0000 | [diff] [blame] | 344 | # Sanitizer flags ============================================================= |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 345 | |
| 346 | # Configure for sanitizers. If LIBCXX_BUILT_STANDALONE then we have to do |
| 347 | # the flag translation ourselves. Othewise LLVM's CMakeList.txt will handle it. |
| 348 | if (LIBCXX_BUILT_STANDALONE) |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 349 | set(LLVM_USE_SANITIZER "" CACHE STRING |
| 350 | "Define the sanitizer used to build the library and tests") |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 351 | # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC. |
| 352 | # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do. |
| 353 | if (LLVM_USE_SANITIZER AND NOT MSVC) |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 354 | add_flags_if_supported("-fno-omit-frame-pointer") |
| 355 | add_flags_if_supported("-gline-tables-only") |
| 356 | |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 357 | if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND |
| 358 | NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO") |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 359 | add_flags_if_supported("-gline-tables-only") |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 360 | endif() |
| 361 | if (LLVM_USE_SANITIZER STREQUAL "Address") |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 362 | add_flags("-fsanitize=address") |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 363 | elseif (LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?") |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 364 | add_flags(-fsanitize=memory) |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 365 | if (LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins") |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 366 | add_flags("-fsanitize-memory-track-origins") |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 367 | endif() |
| 368 | elseif (LLVM_USE_SANITIZER STREQUAL "Undefined") |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 369 | add_flags("-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all") |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 370 | elseif (LLVM_USE_SANITIZER STREQUAL "Thread") |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 371 | add_flags(-fsanitize=thread) |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 372 | else() |
| 373 | message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}") |
| 374 | endif() |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 375 | elseif(LLVM_USE_SANITIZER AND MSVC) |
| 376 | message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.") |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 377 | endif() |
| 378 | endif() |
Eric Fiselier | 5cf9a82 | 2015-10-13 22:12:02 +0000 | [diff] [blame] | 379 | |
| 380 | # Configuration file flags ===================================================== |
Evgeniy Stepanov | da2ff7e | 2015-10-13 23:48:28 +0000 | [diff] [blame] | 381 | if (NOT LIBCXX_ABI_VERSION EQUAL "1") |
| 382 | config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION) |
| 383 | endif() |
| 384 | config_define_if(LIBCXX_ABI_UNSTABLE _LIBCPP_ABI_UNSTABLE) |
| 385 | |
Eric Fiselier | 5cf9a82 | 2015-10-13 22:12:02 +0000 | [diff] [blame] | 386 | config_define_if_not(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE) |
| 387 | config_define_if_not(LIBCXX_ENABLE_STDIN _LIBCPP_HAS_NO_STDIN) |
| 388 | config_define_if_not(LIBCXX_ENABLE_STDOUT _LIBCPP_HAS_NO_STDOUT) |
| 389 | config_define_if_not(LIBCXX_ENABLE_THREADS _LIBCPP_HAS_NO_THREADS) |
| 390 | config_define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK _LIBCPP_HAS_NO_MONOTONIC_CLOCK) |
| 391 | config_define_if_not(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS) |
| 392 | |
Ben Craig | 5593c4f | 2016-05-25 17:40:09 +0000 | [diff] [blame] | 393 | config_define_if(LIBCXX_HAS_PTHREAD_API _LIBCPP_HAS_THREAD_API_PTHREAD) |
Vasileios Kalintiris | 281b4cf | 2015-11-09 10:21:04 +0000 | [diff] [blame] | 394 | config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC) |
| 395 | |
Eric Fiselier | 5cf9a82 | 2015-10-13 22:12:02 +0000 | [diff] [blame] | 396 | if (LIBCXX_NEEDS_SITE_CONFIG) |
| 397 | configure_file( |
| 398 | include/__config_site.in |
| 399 | ${LIBCXX_BINARY_DIR}/__config_site |
| 400 | @ONLY) |
Eric Fiselier | 1a1c74b | 2015-10-14 00:22:05 +0000 | [diff] [blame] | 401 | # Provide the config definitions by included the generated __config_site |
| 402 | # file at compile time. |
| 403 | add_compile_flags("-include ${LIBCXX_BINARY_DIR}/__config_site") |
Eric Fiselier | 5cf9a82 | 2015-10-13 22:12:02 +0000 | [diff] [blame] | 404 | endif() |
| 405 | |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 406 | #=============================================================================== |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 407 | # Setup Source Code And Tests |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 408 | #=============================================================================== |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 409 | include_directories(include) |
Howard Hinnant | 6e207d5 | 2013-11-15 17:18:57 +0000 | [diff] [blame] | 410 | add_subdirectory(include) |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 411 | add_subdirectory(lib) |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 412 | |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 413 | if (LIBCXX_INCLUDE_TESTS) |
| 414 | add_subdirectory(test) |
| 415 | endif() |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 416 | if (LIBCXX_INCLUDE_DOCS) |
| 417 | add_subdirectory(docs) |
| 418 | endif() |