Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 1 | # See www/CMake.html for instructions on how to build libcxx with CMake. |
| 2 | |
| 3 | #=============================================================================== |
| 4 | # Setup Project |
| 5 | #=============================================================================== |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 6 | cmake_minimum_required(VERSION 2.8) |
| 7 | |
Eric Fiselier | e9d4b23 | 2015-01-26 21:56:45 | [diff] [blame] | 8 | if(POLICY CMP0042) |
| 9 | cmake_policy(SET CMP0042 NEW) # Set MACOSX_RPATH=YES by default |
| 10 | endif() |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 11 | if(POLICY CMP0022) |
| 12 | cmake_policy(SET CMP0022 NEW) # Required when interacting with LLVM and Clang |
| 13 | endif() |
| 14 | |
| 15 | project(libcxx CXX C) |
Eric Fiselier | e9d4b23 | 2015-01-26 21:56:45 | [diff] [blame] | 16 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 17 | set(PACKAGE_NAME libcxx) |
| 18 | set(PACKAGE_VERSION trunk-svn) |
| 19 | set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") |
Tanya Lattner | d08dbfc | 2015-08-05 03:59:14 | [diff] [blame] | 20 | set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org") |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 21 | |
| 22 | # Add path for custom modules |
| 23 | set(CMAKE_MODULE_PATH |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 24 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake" |
| 25 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" |
Alexey Samsonov | 179fa78 | 2013-09-30 09:10:01 | [diff] [blame] | 26 | ${CMAKE_MODULE_PATH} |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 27 | ) |
| 28 | |
| 29 | # Require out of source build. |
| 30 | include(MacroEnsureOutOfSourceBuild) |
| 31 | MACRO_ENSURE_OUT_OF_SOURCE_BUILD( |
| 32 | "${PROJECT_NAME} requires an out of source build. Please create a separate |
| 33 | build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there." |
| 34 | ) |
| 35 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 36 | # Find the LLVM sources and simulate LLVM CMake options. |
| 37 | include(HandleOutOfTreeLLVM) |
| 38 | if (LIBCXX_BUILT_STANDALONE AND NOT LLVM_FOUND) |
| 39 | message(WARNING "UNSUPPORTED LIBCXX CONFIGURATION DETECTED: " |
| 40 | "llvm-config not found and LLVM_PATH not defined.\n" |
| 41 | "Reconfigure with -DLLVM_CONFIG=path/to/llvm-config " |
| 42 | "or -DLLVM_PATH=path/to/llvm-source-root.") |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 43 | endif() |
Peter Collingbourne | 4c81b00 | 2013-10-03 21:58:25 | [diff] [blame] | 44 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 45 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 46 | #=============================================================================== |
| 47 | # Setup CMake Options |
| 48 | #=============================================================================== |
| 49 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 50 | # Basic options --------------------------------------------------------------- |
| 51 | option(LIBCXX_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON) |
| 52 | option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON) |
| 53 | |
| 54 | option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS}) |
Eric Fiselier | b9f425a | 2015-08-22 19:40:49 | [diff] [blame] | 55 | option(LIBCXX_INCLUDE_DOCS "Build the libc++ documentation." ${LLVM_INCLUDE_DOCS}) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 56 | set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING |
| 57 | "Define suffix of library directory name (32/64)") |
| 58 | option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON) |
Eric Fiselier | 961269d | 2015-08-26 20:18:21 | [diff] [blame] | 59 | option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 60 | option(LIBCXX_INSTALL_SUPPORT_HEADERS "Install libc++ support headers." ON) |
Evgeniy Stepanov | 4f01aa8 | 2015-10-13 23:48:28 | [diff] [blame] | 61 | set(LIBCXX_ABI_VERSION 1 CACHE STRING "ABI version of libc++.") |
| 62 | option(LIBCXX_ABI_UNSTABLE "Unstable ABI of libc++." OFF) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 63 | |
| 64 | # ABI Library options --------------------------------------------------------- |
| 65 | set(LIBCXX_CXX_ABI "${LIBCXX_CXX_ABI}" CACHE STRING |
| 66 | "Specify C++ ABI library to use." FORCE) |
| 67 | set(CXXABIS none libcxxabi libcxxrt libstdc++ libsupc++) |
| 68 | set_property(CACHE LIBCXX_CXX_ABI PROPERTY STRINGS ;${CXXABIS}) |
| 69 | |
| 70 | option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "Statically link the ABI library" OFF) |
| 71 | |
| 72 | # Build libc++abi with libunwind. We need this option to determine whether to |
| 73 | # link with libunwind or libgcc_s while running the test cases. |
| 74 | option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF) |
| 75 | |
| 76 | # Target options -------------------------------------------------------------- |
| 77 | option(LIBCXX_BUILD_32_BITS "Build 32 bit libc++." ${LLVM_BUILD_32_BITS}) |
| 78 | set(LIBCXX_SYSROOT "" CACHE STRING "Use alternate sysroot.") |
| 79 | set(LIBCXX_GCC_TOOLCHAIN "" CACHE STRING "Use alternate GCC toolchain.") |
| 80 | |
| 81 | # Feature options ------------------------------------------------------------- |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 82 | option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON) |
| 83 | option(LIBCXX_ENABLE_RTTI "Use run time type information." ON) |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 | [diff] [blame] | 84 | option(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE "Build libc++ with support for the global filesystem namespace." ON) |
Ed Schouten | abd06b4 | 2015-03-26 14:35:46 | [diff] [blame] | 85 | option(LIBCXX_ENABLE_STDIN "Build libc++ with support for stdin/std::cin." ON) |
| 86 | option(LIBCXX_ENABLE_STDOUT "Build libc++ with support for stdout/std::cout." ON) |
Eric Fiselier | 7330ed3 | 2014-12-06 21:02:58 | [diff] [blame] | 87 | option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON) |
Ed Schouten | 323ade3 | 2015-06-24 08:44:38 | [diff] [blame] | 88 | option(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS "Build libc++ with support for thread-unsafe C functions" ON) |
Eric Fiselier | 7330ed3 | 2014-12-06 21:02:58 | [diff] [blame] | 89 | option(LIBCXX_ENABLE_MONOTONIC_CLOCK |
| 90 | "Build libc++ with support for a monotonic clock. |
Jonathan Roelofs | 5e91fa1 | 2015-08-24 21:20:07 | [diff] [blame] | 91 | This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 92 | |
| 93 | # Misc options ---------------------------------------------------------------- |
Eric Fiselier | cb23a49 | 2015-10-10 03:34:52 | [diff] [blame] | 94 | # FIXME: Turn -pedantic back ON. It is currently off because it warns |
| 95 | # about #include_next which is used everywhere. |
| 96 | option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 97 | option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) |
| 98 | |
Eric Fiselier | bf9653d | 2015-03-31 04:15:45 | [diff] [blame] | 99 | option(LIBCXX_GENERATE_COVERAGE "Enable generating code coverage." OFF) |
| 100 | set(LIBCXX_COVERAGE_LIBRARY "" CACHE STRING |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 101 | "The Profile-rt library used to build with code coverage") |
| 102 | |
Eric Fiselier | 961269d | 2015-08-26 20:18:21 | [diff] [blame] | 103 | # Don't allow a user to accidentally overwrite the system libc++ installation on Darwin. |
| 104 | # If the user specifies -DCMAKE_INSTALL_PREFIX=/usr the install rules for libc++ |
| 105 | # will not be generated and a warning will be issued. |
| 106 | option(LIBCXX_OVERRIDE_DARWIN_INSTALL "Enable overwriting darwins libc++ installation." OFF) |
| 107 | mark_as_advanced(LIBCXX_OVERRIDE_DARWIN_INSTALL) # Don't show this option by default. |
| 108 | |
| 109 | if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT LIBCXX_OVERRIDE_DARWIN_INSTALL) |
| 110 | if ("${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr") |
| 111 | message(WARNING "Disabling libc++ install rules because installation would " |
| 112 | "overwrite the systems installation. Configure with " |
| 113 | "-DLIBCXX_OVERRIDE_DARWIN_INSTALL=ON to suppress this behaviour.") |
| 114 | mark_as_advanced(CLEAR LIBCXX_OVERRIDE_DARWIN_INSTALL) # Show the override option. |
| 115 | set(LIBCXX_INSTALL_HEADERS OFF) |
| 116 | set(LIBCXX_INSTALL_LIBRARY OFF) |
| 117 | endif() |
| 118 | endif() |
| 119 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 120 | #=============================================================================== |
| 121 | # Check option configurations |
| 122 | #=============================================================================== |
| 123 | |
| 124 | # Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON only when |
| 125 | # LIBCXX_ENABLE_THREADS is on. |
| 126 | if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_ENABLE_MONOTONIC_CLOCK) |
| 127 | message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF" |
| 128 | " when LIBCXX_ENABLE_THREADS is also set to OFF.") |
Eric Fiselier | 25a1516 | 2014-08-18 05:03:46 | [diff] [blame] | 129 | endif() |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 130 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 131 | # Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE |
| 132 | # is ON. |
| 133 | if (LLVM_USE_SANITIZER AND LIBCXX_GENERATE_COVERAGE) |
| 134 | message(FATAL_ERROR "LLVM_USE_SANITIZER cannot be used with LIBCXX_GENERATE_COVERAGE") |
| 135 | endif() |
| 136 | |
| 137 | # Set LIBCXX_BUILD_32_BITS to (LIBCXX_BUILD_32_BITS OR LLVM_BUILD_32_BITS) |
| 138 | # and check that we can build with 32 bits if requested. |
| 139 | if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32) |
| 140 | if (LIBCXX_BUILD_32_BITS AND NOT LLVM_BUILD_32_BITS) # Don't duplicate the output from LLVM |
| 141 | message(STATUS "Building 32 bits executables and libraries.") |
| 142 | endif() |
| 143 | elseif(LIBCXX_BUILD_32_BITS) |
| 144 | message(FATAL_ERROR "LIBCXX_BUILD_32_BITS=ON is not supported on this platform.") |
| 145 | endif() |
| 146 | |
| 147 | # Check that this option is not enabled on Apple and emit a usage warning. |
Eric Fiselier | c0b166e | 2015-03-03 15:59:51 | [diff] [blame] | 148 | if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) |
| 149 | if (APPLE) |
| 150 | message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is not supported on OS X") |
| 151 | else() |
| 152 | message(WARNING "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is an experimental option") |
| 153 | endif() |
| 154 | endif() |
| 155 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 156 | #=============================================================================== |
| 157 | # Configure System |
| 158 | #=============================================================================== |
| 159 | |
Eric Fiselier | 4778eed | 2014-12-20 03:16:55 | [diff] [blame] | 160 | set(LIBCXX_COMPILER ${CMAKE_CXX_COMPILER}) |
| 161 | set(LIBCXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 162 | set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
Chandler Carruth | 7a033ca | 2014-12-29 12:15:47 | [diff] [blame] | 163 | set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) |
Eric Fiselier | 4778eed | 2014-12-20 03:16:55 | [diff] [blame] | 164 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 165 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) |
| 166 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) |
| 167 | |
Eric Fiselier | 8e2855c | 2014-11-15 06:26:30 | [diff] [blame] | 168 | # Declare libc++ configuration variables. |
| 169 | # They are intended for use as follows: |
| 170 | # LIBCXX_CXX_FLAGS: General flags for both the compiler and linker. |
| 171 | # LIBCXX_COMPILE_FLAGS: Compile only flags. |
| 172 | # LIBCXX_LINK_FLAGS: Linker only flags. |
Eric Fiselier | 8e2855c | 2014-11-15 06:26:30 | [diff] [blame] | 173 | set(LIBCXX_COMPILE_FLAGS "") |
| 174 | set(LIBCXX_LINK_FLAGS "") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 175 | set(LIBCXX_LIBRARIES "") |
Eric Fiselier | 8e2855c | 2014-11-15 06:26:30 | [diff] [blame] | 176 | |
Eric Fiselier | 9a1468f | 2014-11-15 17:25:23 | [diff] [blame] | 177 | # Configure compiler. |
| 178 | include(config-ix) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 179 | |
Eric Fiselier | bf9653d | 2015-03-31 04:15:45 | [diff] [blame] | 180 | # Configure coverage options. |
| 181 | if (LIBCXX_GENERATE_COVERAGE) |
| 182 | include(CodeCoverage) |
| 183 | set(CMAKE_BUILD_TYPE "COVERAGE" CACHE STRING "" FORCE) |
| 184 | endif() |
Eric Fiselier | 9a1468f | 2014-11-15 17:25:23 | [diff] [blame] | 185 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 186 | string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) |
| 187 | |
Eric Fiselier | 9a1468f | 2014-11-15 17:25:23 | [diff] [blame] | 188 | #=============================================================================== |
| 189 | # Setup Compiler Flags |
| 190 | #=============================================================================== |
| 191 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 192 | include(HandleLibCXXABI) # Steup the ABI library flags |
| 193 | |
| 194 | # Include macros for adding and removing libc++ flags. |
| 195 | include(HandleLibcxxFlags) |
| 196 | |
| 197 | # Remove flags that may have snuck in. |
| 198 | remove_flags(-DNDEBUG -UNDEBUG -D_DEBUG |
| 199 | -stdlib=libc++ -stdlib=libstdc++ -lc++abi -m32) |
| 200 | |
Eric Fiselier | 499d878 | 2015-10-13 23:56:33 | [diff] [blame] | 201 | # FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC. |
| 202 | # Remove the -pedantic flag provided by LLVM. |
| 203 | remove_flags(-pedantic) |
| 204 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 205 | # Required flags ============================================================== |
| 206 | add_compile_flags_if_supported(-std=c++11) |
| 207 | if (NOT MSVC AND NOT LIBCXX_SUPPORTS_STD_EQ_CXX11_FLAG) |
| 208 | message(FATAL_ERROR "C++11 is required but the compiler does not support -std=c++11") |
| 209 | endif() |
| 210 | |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 211 | # On all systems the system c++ standard library headers need to be excluded. |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 212 | # MSVC only has -X, which disables all default includes; including the crt. |
| 213 | # Thus, we do nothing and hope we don't accidentally include any of the C++ |
| 214 | # headers |
| 215 | add_compile_flags_if_supported(-nostdinc++) |
Eric Fiselier | d74dee9 | 2015-07-29 21:07:28 | [diff] [blame] | 216 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 217 | # Target flags ================================================================ |
| 218 | add_flags_if(LIBCXX_BUILD_32_BITS -m32) |
| 219 | add_flags_if(LIBCXX_TARGET_TRIPLE "-target ${LIBCXX_TARGET_TRIPLE}") |
| 220 | add_flags_if(LIBCXX_SYSROOT "--sysroot ${LIBCXX_SYSROOT}") |
| 221 | add_flags_if(LIBCXX_GCC_TOOLCHAIN "-gcc-toolchain ${LIBCXX_GCC_TOOLCHAIN}") |
Eric Fiselier | 91eeba8 | 2015-07-29 00:03:51 | [diff] [blame] | 222 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 223 | # Warning flags =============================================================== |
Eric Fiselier | 692177d | 2015-07-18 20:40:46 | [diff] [blame] | 224 | add_definitions(-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 225 | add_compile_flags_if_supported( |
| 226 | -Wall -W -Wwrite-strings |
| 227 | -Wno-unused-parameter -Wno-long-long |
| 228 | -Werror=return-type) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 229 | if (LIBCXX_ENABLE_WERROR) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 230 | add_compile_flags_if_supported(-Werror) |
| 231 | add_compile_flags_if_supported(-WX) |
Eric Fiselier | 26d2390 | 2015-07-31 01:25:01 | [diff] [blame] | 232 | else() |
| 233 | # TODO(EricWF) Remove this. We shouldn't be suppressing errors when -Werror is |
| 234 | # added elsewhere. |
| 235 | add_compile_flags_if_supported(-Wno-error) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 236 | endif() |
| 237 | if (LIBCXX_ENABLE_PEDANTIC) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 238 | add_compile_flags_if_supported(-pedantic) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 239 | endif() |
| 240 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 241 | # Exception flags ============================================================= |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 242 | if (LIBCXX_ENABLE_EXCEPTIONS) |
| 243 | # Catches C++ exceptions only and tells the compiler to assume that extern C |
| 244 | # functions never throw a C++ exception. |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 245 | add_compile_flags_if_supported(-EHsc) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 246 | else() |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 247 | add_definitions(-D_LIBCPP_NO_EXCEPTIONS) |
| 248 | add_compile_flags_if_supported(-EHs- -EHa-) |
| 249 | add_compile_flags_if_supported(-fno-exceptions) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 250 | endif() |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 251 | |
| 252 | # RTTI flags ================================================================== |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 253 | if (NOT LIBCXX_ENABLE_RTTI) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 254 | add_definitions(-D_LIBCPP_NO_RTTI) |
| 255 | add_compile_flags_if_supported(-GR-) |
| 256 | add_compile_flags_if_supported(-fno-rtti) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 257 | endif() |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 258 | |
| 259 | # Assertion flags ============================================================= |
| 260 | define_if(LIBCXX_ENABLE_ASSERTIONS -UNDEBUG) |
| 261 | define_if_not(LIBCXX_ENABLE_ASSERTIONS -DNDEBUG) |
Howard Hinnant | e103a3d | 2012-08-05 17:37:39 | [diff] [blame] | 262 | if (LIBCXX_ENABLE_ASSERTIONS) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 263 | # MSVC doesn't like _DEBUG on release builds. See PR 4379. |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 264 | define_if_not(MSVC -D_DEBUG) |
Howard Hinnant | 4a0e74f | 2013-02-25 15:50:36 | [diff] [blame] | 265 | endif() |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 266 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 267 | # Feature flags =============================================================== |
| 268 | define_if(MSVC -D_CRT_SECURE_NO_WARNINGS) |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 269 | |
Jonathan Roelofs | 5e91fa1 | 2015-08-24 21:20:07 | [diff] [blame] | 270 | # Sanitizer flags ============================================================= |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 271 | |
| 272 | # Configure for sanitizers. If LIBCXX_BUILT_STANDALONE then we have to do |
| 273 | # the flag translation ourselves. Othewise LLVM's CMakeList.txt will handle it. |
| 274 | if (LIBCXX_BUILT_STANDALONE) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 275 | set(LLVM_USE_SANITIZER "" CACHE STRING |
| 276 | "Define the sanitizer used to build the library and tests") |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 277 | # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC. |
| 278 | # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do. |
| 279 | if (LLVM_USE_SANITIZER AND NOT MSVC) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 280 | add_flags_if_supported("-fno-omit-frame-pointer") |
| 281 | add_flags_if_supported("-gline-tables-only") |
| 282 | |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 283 | if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND |
| 284 | NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 285 | add_flags_if_supported("-gline-tables-only") |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 286 | endif() |
| 287 | if (LLVM_USE_SANITIZER STREQUAL "Address") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 288 | add_flags("-fsanitize=address") |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 289 | elseif (LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 290 | add_flags(-fsanitize=memory) |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 291 | if (LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 292 | add_flags("-fsanitize-memory-track-origins") |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 293 | endif() |
| 294 | elseif (LLVM_USE_SANITIZER STREQUAL "Undefined") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 295 | add_flags("-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all") |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 296 | elseif (LLVM_USE_SANITIZER STREQUAL "Thread") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 297 | add_flags(-fsanitize=thread) |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 298 | else() |
| 299 | message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}") |
| 300 | endif() |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 301 | elseif(LLVM_USE_SANITIZER AND MSVC) |
| 302 | message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.") |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 303 | endif() |
| 304 | endif() |
Eric Fiselier | 73ffc78 | 2015-10-13 22:12:02 | [diff] [blame] | 305 | |
| 306 | # Configuration file flags ===================================================== |
Evgeniy Stepanov | 4f01aa8 | 2015-10-13 23:48:28 | [diff] [blame] | 307 | if (NOT LIBCXX_ABI_VERSION EQUAL "1") |
| 308 | config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION) |
| 309 | endif() |
| 310 | config_define_if(LIBCXX_ABI_UNSTABLE _LIBCPP_ABI_UNSTABLE) |
| 311 | |
Eric Fiselier | 73ffc78 | 2015-10-13 22:12:02 | [diff] [blame] | 312 | config_define_if_not(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE) |
| 313 | config_define_if_not(LIBCXX_ENABLE_STDIN _LIBCPP_HAS_NO_STDIN) |
| 314 | config_define_if_not(LIBCXX_ENABLE_STDOUT _LIBCPP_HAS_NO_STDOUT) |
| 315 | config_define_if_not(LIBCXX_ENABLE_THREADS _LIBCPP_HAS_NO_THREADS) |
| 316 | config_define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK _LIBCPP_HAS_NO_MONOTONIC_CLOCK) |
| 317 | config_define_if_not(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS) |
| 318 | |
| 319 | if (LIBCXX_NEEDS_SITE_CONFIG) |
| 320 | configure_file( |
| 321 | include/__config_site.in |
| 322 | ${LIBCXX_BINARY_DIR}/__config_site |
| 323 | @ONLY) |
Eric Fiselier | a662279 | 2015-10-14 00:22:05 | [diff] [blame^] | 324 | # Provide the config definitions by included the generated __config_site |
| 325 | # file at compile time. |
| 326 | add_compile_flags("-include ${LIBCXX_BINARY_DIR}/__config_site") |
Eric Fiselier | 73ffc78 | 2015-10-13 22:12:02 | [diff] [blame] | 327 | endif() |
| 328 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 329 | #=============================================================================== |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 330 | # Setup Source Code And Tests |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 331 | #=============================================================================== |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 332 | include_directories(include) |
Howard Hinnant | c4962b3 | 2013-11-15 17:18:57 | [diff] [blame] | 333 | add_subdirectory(include) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 334 | add_subdirectory(lib) |
Eric Fiselier | b9f425a | 2015-08-22 19:40:49 | [diff] [blame] | 335 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 336 | if (LIBCXX_INCLUDE_TESTS) |
| 337 | add_subdirectory(test) |
| 338 | endif() |
Eric Fiselier | b9f425a | 2015-08-22 19:40:49 | [diff] [blame] | 339 | if (LIBCXX_INCLUDE_DOCS) |
| 340 | add_subdirectory(docs) |
| 341 | endif() |