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