Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 1 | # See www/CMake.html for instructions on how to build libcxx with CMake. |
| 2 | |
| 3 | #=============================================================================== |
| 4 | # Setup Project |
| 5 | #=============================================================================== |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 6 | cmake_minimum_required(VERSION 2.8) |
| 7 | |
Eric Fiselier | e9d4b23 | 2015-01-26 21:56:45 +0000 | [diff] [blame] | 8 | if(POLICY CMP0042) |
| 9 | cmake_policy(SET CMP0042 NEW) # Set MACOSX_RPATH=YES by default |
| 10 | endif() |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 11 | if(POLICY CMP0022) |
| 12 | cmake_policy(SET CMP0022 NEW) # Required when interacting with LLVM and Clang |
| 13 | endif() |
| 14 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 15 | project(libcxx CXX C) |
| 16 | |
| 17 | set(PACKAGE_NAME libcxx) |
| 18 | set(PACKAGE_VERSION trunk-svn) |
| 19 | set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") |
| 20 | set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org") |
| 21 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 22 | # Add path for custom modules |
| 23 | set(CMAKE_MODULE_PATH |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 24 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake" |
| 25 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" |
Eric Fiselier | ce5695f | 2015-12-30 03:39:03 +0000 | [diff] [blame] | 26 | ${CMAKE_MODULE_PATH} |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 27 | ) |
| 28 | |
Saleem Abdulrasool | 7adfa03 | 2016-02-08 03:50:18 +0000 | [diff] [blame] | 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 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [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.") |
| 43 | endif() |
| 44 | |
| 45 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 46 | #=============================================================================== |
| 47 | # Setup CMake Options |
| 48 | #=============================================================================== |
| 49 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [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) |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 53 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 54 | option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS}) |
| 55 | set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING |
| 56 | "Define suffix of library directory name (32/64)") |
| 57 | option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON) |
| 58 | option(LIBCXX_INSTALL_SUPPORT_HEADERS "Install libc++ support headers." ON) |
| 59 | |
| 60 | # ABI Library options --------------------------------------------------------- |
| 61 | set(LIBCXX_CXX_ABI "${LIBCXX_CXX_ABI}" CACHE STRING |
| 62 | "Specify C++ ABI library to use." FORCE) |
| 63 | set(CXXABIS none libcxxabi libcxxrt libstdc++ libsupc++) |
| 64 | set_property(CACHE LIBCXX_CXX_ABI PROPERTY STRINGS ;${CXXABIS}) |
| 65 | |
| 66 | option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "Statically link the ABI library" OFF) |
| 67 | |
| 68 | # Build libc++abi with libunwind. We need this option to determine whether to |
| 69 | # link with libunwind or libgcc_s while running the test cases. |
| 70 | option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF) |
| 71 | |
| 72 | # Target options -------------------------------------------------------------- |
| 73 | option(LIBCXX_BUILD_32_BITS "Build 32 bit libc++." ${LLVM_BUILD_32_BITS}) |
| 74 | set(LIBCXX_SYSROOT "" CACHE STRING "Use alternate sysroot.") |
| 75 | set(LIBCXX_GCC_TOOLCHAIN "" CACHE STRING "Use alternate GCC toolchain.") |
| 76 | |
| 77 | # Feature options ------------------------------------------------------------- |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 78 | option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON) |
| 79 | option(LIBCXX_ENABLE_RTTI "Use run time type information." ON) |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 80 | option(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE "Build libc++ with support for the global filesystem namespace." ON) |
Ed Schouten | abd06b4 | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 81 | option(LIBCXX_ENABLE_STDIN "Build libc++ with support for stdin/std::cin." ON) |
| 82 | option(LIBCXX_ENABLE_STDOUT "Build libc++ with support for stdout/std::cout." ON) |
Eric Fiselier | 7330ed3 | 2014-12-06 21:02:58 +0000 | [diff] [blame] | 83 | option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON) |
Ed Schouten | 323ade3 | 2015-06-24 08:44:38 +0000 | [diff] [blame] | 84 | option(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS "Build libc++ with support for thread-unsafe C functions" ON) |
Eric Fiselier | 7330ed3 | 2014-12-06 21:02:58 +0000 | [diff] [blame] | 85 | option(LIBCXX_ENABLE_MONOTONIC_CLOCK |
| 86 | "Build libc++ with support for a monotonic clock. |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 87 | This option may only be used when LIBCXX_ENABLE_THREADS=OFF." ON) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 88 | |
| 89 | # Misc options ---------------------------------------------------------------- |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 90 | option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." ON) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 91 | option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) |
| 92 | |
Eric Fiselier | bf9653d | 2015-03-31 04:15:45 +0000 | [diff] [blame] | 93 | option(LIBCXX_GENERATE_COVERAGE "Enable generating code coverage." OFF) |
| 94 | set(LIBCXX_COVERAGE_LIBRARY "" CACHE STRING |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 95 | "The Profile-rt library used to build with code coverage") |
| 96 | |
| 97 | #=============================================================================== |
| 98 | # Check option configurations |
| 99 | #=============================================================================== |
| 100 | |
| 101 | # Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON only when |
| 102 | # LIBCXX_ENABLE_THREADS is on. |
| 103 | if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_ENABLE_MONOTONIC_CLOCK) |
| 104 | message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF" |
| 105 | " when LIBCXX_ENABLE_THREADS is also set to OFF.") |
Eric Fiselier | 25a1516 | 2014-08-18 05:03:46 +0000 | [diff] [blame] | 106 | endif() |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 107 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 108 | # Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE |
| 109 | # is ON. |
| 110 | if (LLVM_USE_SANITIZER AND LIBCXX_GENERATE_COVERAGE) |
| 111 | message(FATAL_ERROR "LLVM_USE_SANITIZER cannot be used with LIBCXX_GENERATE_COVERAGE") |
| 112 | endif() |
| 113 | |
| 114 | # Set LIBCXX_BUILD_32_BITS to (LIBCXX_BUILD_32_BITS OR LLVM_BUILD_32_BITS) |
| 115 | # and check that we can build with 32 bits if requested. |
| 116 | if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32) |
| 117 | if (LIBCXX_BUILD_32_BITS AND NOT LLVM_BUILD_32_BITS) # Don't duplicate the output from LLVM |
| 118 | message(STATUS "Building 32 bits executables and libraries.") |
| 119 | endif() |
| 120 | elseif(LIBCXX_BUILD_32_BITS) |
| 121 | message(FATAL_ERROR "LIBCXX_BUILD_32_BITS=ON is not supported on this platform.") |
| 122 | endif() |
| 123 | |
| 124 | # Check that this option is not enabled on Apple and emit a usage warning. |
Eric Fiselier | c0b166e | 2015-03-03 15:59:51 +0000 | [diff] [blame] | 125 | if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) |
| 126 | if (APPLE) |
| 127 | message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is not supported on OS X") |
| 128 | else() |
| 129 | message(WARNING "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is an experimental option") |
| 130 | endif() |
| 131 | endif() |
| 132 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 133 | #=============================================================================== |
| 134 | # Configure System |
| 135 | #=============================================================================== |
| 136 | |
Eric Fiselier | 4778eed | 2014-12-20 03:16:55 +0000 | [diff] [blame] | 137 | set(LIBCXX_COMPILER ${CMAKE_CXX_COMPILER}) |
| 138 | set(LIBCXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 139 | set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
Chandler Carruth | 7a033ca | 2014-12-29 12:15:47 +0000 | [diff] [blame] | 140 | set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) |
Eric Fiselier | 4778eed | 2014-12-20 03:16:55 +0000 | [diff] [blame] | 141 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 142 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) |
| 143 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) |
| 144 | |
Eric Fiselier | 8e2855c | 2014-11-15 06:26:30 +0000 | [diff] [blame] | 145 | # Declare libc++ configuration variables. |
| 146 | # They are intended for use as follows: |
| 147 | # LIBCXX_CXX_FLAGS: General flags for both the compiler and linker. |
| 148 | # LIBCXX_COMPILE_FLAGS: Compile only flags. |
| 149 | # LIBCXX_LINK_FLAGS: Linker only flags. |
Eric Fiselier | 8e2855c | 2014-11-15 06:26:30 +0000 | [diff] [blame] | 150 | set(LIBCXX_COMPILE_FLAGS "") |
| 151 | set(LIBCXX_LINK_FLAGS "") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 152 | set(LIBCXX_LIBRARIES "") |
Eric Fiselier | 8e2855c | 2014-11-15 06:26:30 +0000 | [diff] [blame] | 153 | |
Eric Fiselier | 9a1468f | 2014-11-15 17:25:23 +0000 | [diff] [blame] | 154 | # Configure compiler. |
| 155 | include(config-ix) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 156 | |
Eric Fiselier | bf9653d | 2015-03-31 04:15:45 +0000 | [diff] [blame] | 157 | # Configure coverage options. |
| 158 | if (LIBCXX_GENERATE_COVERAGE) |
| 159 | include(CodeCoverage) |
| 160 | set(CMAKE_BUILD_TYPE "COVERAGE" CACHE STRING "" FORCE) |
| 161 | endif() |
Eric Fiselier | 9a1468f | 2014-11-15 17:25:23 +0000 | [diff] [blame] | 162 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 163 | string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) |
| 164 | |
Eric Fiselier | 9a1468f | 2014-11-15 17:25:23 +0000 | [diff] [blame] | 165 | #=============================================================================== |
| 166 | # Setup Compiler Flags |
| 167 | #=============================================================================== |
| 168 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 169 | include(HandleLibCXXABI) # Steup the ABI library flags |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 170 | |
| 171 | # Include macros for adding and removing libc++ flags. |
| 172 | include(HandleLibcxxFlags) |
| 173 | |
| 174 | # Remove flags that may have snuck in. |
| 175 | remove_flags(-DNDEBUG -UNDEBUG -D_DEBUG |
| 176 | -stdlib=libc++ -stdlib=libstdc++ -lc++abi -m32) |
| 177 | |
| 178 | # Required flags ============================================================== |
| 179 | add_compile_flags_if_supported(-std=c++11) |
| 180 | if (NOT MSVC AND NOT LIBCXX_SUPPORTS_STD_EQ_CXX11_FLAG) |
| 181 | message(FATAL_ERROR "C++11 is required but the compiler does not support -std=c++11") |
| 182 | endif() |
| 183 | |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 184 | # On all systems the system c++ standard library headers need to be excluded. |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 185 | # MSVC only has -X, which disables all default includes; including the crt. |
| 186 | # Thus, we do nothing and hope we don't accidentally include any of the C++ |
| 187 | # headers |
| 188 | add_compile_flags_if_supported(-nostdinc++) |
Eric Fiselier | d74dee9 | 2015-07-29 21:07:28 +0000 | [diff] [blame] | 189 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 190 | # Target flags ================================================================ |
| 191 | add_flags_if(LIBCXX_BUILD_32_BITS -m32) |
| 192 | add_flags_if(LIBCXX_TARGET_TRIPLE "-target ${LIBCXX_TARGET_TRIPLE}") |
| 193 | add_flags_if(LIBCXX_SYSROOT "--sysroot ${LIBCXX_SYSROOT}") |
| 194 | add_flags_if(LIBCXX_GCC_TOOLCHAIN "-gcc-toolchain ${LIBCXX_GCC_TOOLCHAIN}") |
Eric Fiselier | 91eeba8 | 2015-07-29 00:03:51 +0000 | [diff] [blame] | 195 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 196 | # Warning flags =============================================================== |
Eric Fiselier | 692177d | 2015-07-18 20:40:46 +0000 | [diff] [blame] | 197 | add_definitions(-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 198 | add_compile_flags_if_supported( |
| 199 | -Wall -W -Wwrite-strings |
| 200 | -Wno-unused-parameter -Wno-long-long |
| 201 | -Werror=return-type) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 202 | if (LIBCXX_ENABLE_WERROR) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 203 | add_compile_flags_if_supported(-Werror) |
| 204 | add_compile_flags_if_supported(-WX) |
Eric Fiselier | 26d2390 | 2015-07-31 01:25:01 +0000 | [diff] [blame] | 205 | else() |
| 206 | # TODO(EricWF) Remove this. We shouldn't be suppressing errors when -Werror is |
| 207 | # added elsewhere. |
| 208 | add_compile_flags_if_supported(-Wno-error) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 209 | endif() |
| 210 | if (LIBCXX_ENABLE_PEDANTIC) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 211 | add_compile_flags_if_supported(-pedantic) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 212 | endif() |
| 213 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 214 | # Exception flags ============================================================= |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 215 | if (LIBCXX_ENABLE_EXCEPTIONS) |
| 216 | # Catches C++ exceptions only and tells the compiler to assume that extern C |
| 217 | # functions never throw a C++ exception. |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 218 | add_compile_flags_if_supported(-EHsc) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 219 | else() |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 220 | add_definitions(-D_LIBCPP_NO_EXCEPTIONS) |
| 221 | add_compile_flags_if_supported(-EHs- -EHa-) |
| 222 | add_compile_flags_if_supported(-fno-exceptions) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 223 | endif() |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 224 | |
| 225 | # RTTI flags ================================================================== |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 226 | if (NOT LIBCXX_ENABLE_RTTI) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 227 | add_definitions(-D_LIBCPP_NO_RTTI) |
| 228 | add_compile_flags_if_supported(-GR-) |
| 229 | add_compile_flags_if_supported(-fno-rtti) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 230 | endif() |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 231 | |
| 232 | # Assertion flags ============================================================= |
| 233 | define_if(LIBCXX_ENABLE_ASSERTIONS -UNDEBUG) |
| 234 | define_if_not(LIBCXX_ENABLE_ASSERTIONS -DNDEBUG) |
Howard Hinnant | e103a3d | 2012-08-05 17:37:39 +0000 | [diff] [blame] | 235 | if (LIBCXX_ENABLE_ASSERTIONS) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 236 | # MSVC doesn't like _DEBUG on release builds. See PR 4379. |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 237 | define_if_not(MSVC -D_DEBUG) |
Howard Hinnant | 4a0e74f | 2013-02-25 15:50:36 +0000 | [diff] [blame] | 238 | endif() |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 239 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 240 | # Feature flags =============================================================== |
| 241 | define_if(MSVC -D_CRT_SECURE_NO_WARNINGS) |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 242 | define_if_not(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE -D_LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE) |
| 243 | define_if_not(LIBCXX_ENABLE_STDIN -D_LIBCPP_HAS_NO_STDIN) |
| 244 | define_if_not(LIBCXX_ENABLE_STDOUT -D_LIBCPP_HAS_NO_STDOUT) |
| 245 | define_if_not(LIBCXX_ENABLE_THREADS -D_LIBCPP_HAS_NO_THREADS) |
| 246 | define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK -D_LIBCPP_HAS_NO_MONOTONIC_CLOCK) |
| 247 | define_if_not(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS -D_LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS) |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 248 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 249 | |
| 250 | # Sanitizer flags |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 251 | |
| 252 | # Configure for sanitizers. If LIBCXX_BUILT_STANDALONE then we have to do |
| 253 | # the flag translation ourselves. Othewise LLVM's CMakeList.txt will handle it. |
| 254 | if (LIBCXX_BUILT_STANDALONE) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 255 | set(LLVM_USE_SANITIZER "" CACHE STRING |
| 256 | "Define the sanitizer used to build the library and tests") |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 257 | # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC. |
| 258 | # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do. |
| 259 | if (LLVM_USE_SANITIZER AND NOT MSVC) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 260 | add_flags_if_supported("-fno-omit-frame-pointer") |
| 261 | add_flags_if_supported("-gline-tables-only") |
| 262 | |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 263 | if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND |
| 264 | NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 265 | add_flags_if_supported("-gline-tables-only") |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 266 | endif() |
| 267 | if (LLVM_USE_SANITIZER STREQUAL "Address") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 268 | add_flags("-fsanitize=address") |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 269 | elseif (LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 270 | add_flags(-fsanitize=memory) |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 271 | if (LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 272 | add_flags("-fsanitize-memory-track-origins") |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 273 | endif() |
| 274 | elseif (LLVM_USE_SANITIZER STREQUAL "Undefined") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 275 | add_flags("-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all") |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 276 | elseif (LLVM_USE_SANITIZER STREQUAL "Thread") |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 277 | add_flags(-fsanitize=thread) |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 278 | else() |
| 279 | message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}") |
| 280 | endif() |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 281 | elseif(LLVM_USE_SANITIZER AND MSVC) |
| 282 | message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.") |
Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 +0000 | [diff] [blame] | 283 | endif() |
| 284 | endif() |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 285 | #=============================================================================== |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 286 | # Setup Source Code And Tests |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 287 | #=============================================================================== |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 288 | include_directories(include) |
Howard Hinnant | c4962b3 | 2013-11-15 17:18:57 +0000 | [diff] [blame] | 289 | add_subdirectory(include) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 290 | add_subdirectory(lib) |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 291 | if (LIBCXX_INCLUDE_TESTS) |
| 292 | add_subdirectory(test) |
| 293 | endif() |