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 | #=============================================================================== |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 6 | |
| 7 | project(libcxx CXX C) |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 8 | cmake_minimum_required(VERSION 2.8) |
| 9 | |
Eric Fiselier | 9af31a4 | 2015-01-26 21:56:45 +0000 | [diff] [blame] | 10 | if(POLICY CMP0042) |
| 11 | cmake_policy(SET CMP0042 NEW) # Set MACOSX_RPATH=YES by default |
| 12 | endif() |
| 13 | |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 14 | set(PACKAGE_NAME libcxx) |
| 15 | set(PACKAGE_VERSION trunk-svn) |
| 16 | set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") |
| 17 | set(PACKAGE_BUGREPORT "llvmbugs@cs.uiuc.edu") |
| 18 | |
| 19 | # Add path for custom modules |
| 20 | set(CMAKE_MODULE_PATH |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 21 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake" |
| 22 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" |
Alexey Samsonov | ea3ed97 | 2013-09-30 09:10:01 +0000 | [diff] [blame] | 23 | ${CMAKE_MODULE_PATH} |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 24 | ) |
| 25 | |
| 26 | # Require out of source build. |
| 27 | include(MacroEnsureOutOfSourceBuild) |
| 28 | MACRO_ENSURE_OUT_OF_SOURCE_BUILD( |
| 29 | "${PROJECT_NAME} requires an out of source build. Please create a separate |
| 30 | build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there." |
| 31 | ) |
| 32 | |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 33 | if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) |
| 34 | set(LIBCXX_LIBDIR_SUFFIX "" CACHE STRING |
| 35 | "Define suffix of library directory name (32/64)") |
Eric Fiselier | 1f984b0 | 2015-07-29 23:23:18 +0000 | [diff] [blame] | 36 | |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 37 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) |
| 38 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) |
| 39 | |
| 40 | set(LIBCXX_BUILT_STANDALONE 1) |
| 41 | else() |
| 42 | set(LIBCXX_LIBDIR_SUFFIX ${LLVM_LIBDIR_SUFFIX}) |
| 43 | endif() |
Peter Collingbourne | 6878142 | 2013-10-03 21:58:25 +0000 | [diff] [blame] | 44 | |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 45 | #=============================================================================== |
| 46 | # Setup CMake Options |
| 47 | #=============================================================================== |
| 48 | |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 49 | # Define options. |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 50 | option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON) |
| 51 | option(LIBCXX_ENABLE_RTTI "Use run time type information." ON) |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 52 | option(LIBCXX_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON) |
| 53 | option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." ON) |
| 54 | option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) |
| 55 | option(LIBCXX_ENABLE_CXX1Y "Enable -std=c++1y and use of c++1y language features if the compiler supports it." OFF) |
| 56 | option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON) |
Ed Schouten | 7009f4e | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 57 | 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] | 58 | option(LIBCXX_ENABLE_STDIN "Build libc++ with support for stdin/std::cin." ON) |
| 59 | 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] | 60 | option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON) |
Ed Schouten | 137c863 | 2015-06-24 08:44:38 +0000 | [diff] [blame] | 61 | option(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS "Build libc++ with support for thread-unsafe C functions" ON) |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 62 | option(LIBCXX_BUILD_32_BITS "Build 32 bit libc++" OFF) |
Eric Fiselier | 5b9755b | 2014-12-06 21:02:58 +0000 | [diff] [blame] | 63 | option(LIBCXX_ENABLE_MONOTONIC_CLOCK |
| 64 | "Build libc++ with support for a monotonic clock. |
| 65 | This option may only be used when LIBCXX_ENABLE_THREADS=OFF." ON) |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 66 | option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON) |
| 67 | option(LIBCXX_INSTALL_SUPPORT_HEADERS "Install libc++ support headers." ON) |
Eric Fiselier | bcd5d26 | 2015-03-31 04:15:45 +0000 | [diff] [blame] | 68 | option(LIBCXX_GENERATE_COVERAGE "Enable generating code coverage." OFF) |
| 69 | set(LIBCXX_COVERAGE_LIBRARY "" CACHE STRING |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 70 | "The Profile-rt library used to build with code coverage") |
| 71 | option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "Statically link the ABI library" OFF) |
| 72 | set(LIBCXX_SYSROOT "" CACHE STRING "Use alternate sysroot.") |
| 73 | set(LIBCXX_GCC_TOOLCHAIN "" CACHE STRING "Use alternate GCC toolchain.") |
| 74 | if (LIBCXX_BUILT_STANDALONE) |
| 75 | set(LLVM_USE_SANITIZER "" CACHE STRING |
| 76 | "Define the sanitizer used to build the library and tests") |
Eric Fiselier | 2ff6e5a | 2014-08-18 05:03:46 +0000 | [diff] [blame] | 77 | endif() |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 78 | |
Eric Fiselier | 070ed9a | 2015-03-03 15:59:51 +0000 | [diff] [blame] | 79 | if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) |
| 80 | if (APPLE) |
| 81 | message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is not supported on OS X") |
| 82 | else() |
| 83 | message(WARNING "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is an experimental option") |
| 84 | endif() |
| 85 | endif() |
| 86 | |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 87 | set(CXXABIS none libcxxabi libcxxrt libstdc++ libsupc++) |
| 88 | if (NOT LIBCXX_CXX_ABI) |
| 89 | if (NOT DEFINED LIBCXX_BUILT_STANDALONE AND |
| 90 | IS_DIRECTORY "${CMAKE_SOURCE_DIR}/projects/libcxxabi") |
| 91 | set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi") |
| 92 | set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${CMAKE_SOURCE_DIR}/projects/libcxxabi/include") |
| 93 | set(LIBCXX_CXX_ABI_INTREE 1) |
| 94 | else () |
| 95 | set(LIBCXX_CXX_ABI_LIBNAME "none") |
| 96 | endif () |
| 97 | else () |
| 98 | set(LIBCXX_CXX_ABI_LIBNAME "${LIBCXX_CXX_ABI}") |
| 99 | endif () |
| 100 | set(LIBCXX_CXX_ABI "${LIBCXX_CXX_ABI}" CACHE STRING |
| 101 | "Specify C++ ABI library to use." FORCE) |
| 102 | set_property(CACHE LIBCXX_CXX_ABI PROPERTY STRINGS ;${CXXABIS}) |
| 103 | |
| 104 | # Build libc++abi with libunwind. We need this option to determine whether to |
| 105 | # link with libunwind or libgcc_s while running the test cases. |
| 106 | option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF) |
| 107 | |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 108 | #=============================================================================== |
| 109 | # Configure System |
| 110 | #=============================================================================== |
| 111 | |
Eric Fiselier | 26dcc93 | 2014-12-20 03:16:55 +0000 | [diff] [blame] | 112 | set(LIBCXX_COMPILER ${CMAKE_CXX_COMPILER}) |
| 113 | set(LIBCXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 114 | set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
Chandler Carruth | ec54e10 | 2014-12-29 12:15:47 +0000 | [diff] [blame] | 115 | set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) |
Eric Fiselier | 26dcc93 | 2014-12-20 03:16:55 +0000 | [diff] [blame] | 116 | |
Eric Fiselier | 6a4f6ce | 2014-11-15 06:26:30 +0000 | [diff] [blame] | 117 | # Declare libc++ configuration variables. |
| 118 | # They are intended for use as follows: |
| 119 | # LIBCXX_CXX_FLAGS: General flags for both the compiler and linker. |
| 120 | # LIBCXX_COMPILE_FLAGS: Compile only flags. |
| 121 | # LIBCXX_LINK_FLAGS: Linker only flags. |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 122 | set(LIBCXX_CXX_FLAGS "") |
Eric Fiselier | 6a4f6ce | 2014-11-15 06:26:30 +0000 | [diff] [blame] | 123 | set(LIBCXX_COMPILE_FLAGS "") |
| 124 | set(LIBCXX_LINK_FLAGS "") |
| 125 | |
Eric Fiselier | d0e4e10 | 2014-11-15 17:25:23 +0000 | [diff] [blame] | 126 | # Configure compiler. |
| 127 | include(config-ix) |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 128 | # Configure ABI library |
| 129 | include(HandleLibCXXABI) |
Eric Fiselier | bcd5d26 | 2015-03-31 04:15:45 +0000 | [diff] [blame] | 130 | # Configure coverage options. |
| 131 | if (LIBCXX_GENERATE_COVERAGE) |
| 132 | include(CodeCoverage) |
| 133 | set(CMAKE_BUILD_TYPE "COVERAGE" CACHE STRING "" FORCE) |
| 134 | endif() |
Eric Fiselier | d0e4e10 | 2014-11-15 17:25:23 +0000 | [diff] [blame] | 135 | |
| 136 | #=============================================================================== |
| 137 | # Setup Compiler Flags |
| 138 | #=============================================================================== |
| 139 | |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 140 | # Get required flags. |
| 141 | # On all systems the system c++ standard library headers need to be excluded. |
| 142 | if (MSVC) |
| 143 | # MSVC only has -X, which disables all default includes; including the crt. |
| 144 | # Thus, we do nothing and hope we don't accidentally include any of the C++ |
| 145 | # headers. |
| 146 | else() |
| 147 | if (LIBCXX_HAS_NOSTDINCXX_FLAG) |
| 148 | list(APPEND LIBCXX_COMPILE_FLAGS -nostdinc++) |
| 149 | string(REPLACE "-stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 150 | string(REPLACE "-stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 151 | endif() |
| 152 | # If c++1y has been enabled then attempt to use it. Fail if it is no supported |
| 153 | # by the compiler. Otherwise choose c++11 and ensure the compiler supports it. |
| 154 | if (LIBCXX_ENABLE_CXX1Y) |
| 155 | if (LIBCXX_HAS_STDCXX1Y_FLAG) |
| 156 | set(LIBCXX_STD_VERSION c++1y) |
| 157 | else() |
| 158 | message(FATAL_ERROR "c++1y was enabled but the compiler does not support it.") |
| 159 | endif() |
| 160 | else() |
| 161 | if (LIBCXX_HAS_STDCXX11_FLAG) |
| 162 | set(LIBCXX_STD_VERSION c++11) |
| 163 | else() |
| 164 | message(FATAL_ERROR "c++11 is required by libc++ but is not supported by the compiler") |
| 165 | endif() |
| 166 | endif() |
| 167 | # LIBCXX_STD_VERSION should always be set at this point. |
| 168 | list(APPEND LIBCXX_CXX_FLAGS "-std=${LIBCXX_STD_VERSION}") |
Eric Fiselier | 285e796 | 2015-07-29 21:07:28 +0000 | [diff] [blame] | 169 | endif() |
| 170 | |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 171 | macro(append_if list condition var) |
| 172 | if (${condition}) |
| 173 | list(APPEND ${list} ${var}) |
| 174 | endif() |
| 175 | endmacro() |
Eric Fiselier | 64473a1 | 2015-07-29 00:03:51 +0000 | [diff] [blame] | 176 | |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 177 | # Get warning flags |
| 178 | # Disable the system header pragma. |
Eric Fiselier | e012bf2 | 2015-07-18 20:40:46 +0000 | [diff] [blame] | 179 | add_definitions(-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 180 | if (NOT MSVC) |
| 181 | append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WALL_FLAG -Wall) |
| 182 | list(APPEND LIBCXX_COMPILE_FLAGS -Werror=return-type) |
| 183 | endif() |
| 184 | |
| 185 | append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_W_FLAG -W) |
| 186 | append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WNO_UNUSED_PARAMETER_FLAG -Wno-unused-parameter) |
| 187 | append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WWRITE_STRINGS_FLAG -Wwrite-strings) |
| 188 | append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WNO_LONG_LONG_FLAG -Wno-long-long) |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 189 | if (LIBCXX_ENABLE_WERROR) |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 190 | append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WERROR_FLAG -Werror) |
| 191 | append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WX_FLAG -WX) |
| 192 | else() |
| 193 | append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WNO_ERROR_FLAG -Wno-error) |
| 194 | append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_NO_WX_FLAG -WX-) |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 195 | endif() |
| 196 | if (LIBCXX_ENABLE_PEDANTIC) |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 197 | append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_PEDANTIC_FLAG -pedantic) |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 198 | endif() |
| 199 | |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 200 | # Get feature flags. |
| 201 | # Exceptions |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 202 | if (LIBCXX_ENABLE_EXCEPTIONS) |
| 203 | # Catches C++ exceptions only and tells the compiler to assume that extern C |
| 204 | # functions never throw a C++ exception. |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 205 | append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_EHSC_FLAG -EHsc) |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 206 | else() |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 207 | list(APPEND LIBCXX_CXX_FLAGS -D_LIBCPP_NO_EXCEPTIONS) |
| 208 | append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_NO_EHS_FLAG -EHs-) |
| 209 | append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_NO_EHA_FLAG -EHa-) |
| 210 | append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_FNO_EXCEPTIONS_FLAG -fno-exceptions) |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 211 | endif() |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 212 | # RTTI |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 213 | if (NOT LIBCXX_ENABLE_RTTI) |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 214 | list(APPEND LIBCXX_CXX_FLAGS -D_LIBCPP_NO_RTTI) |
| 215 | append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_NO_GR_FLAG -GR-) |
| 216 | append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_FNO_RTTI_FLAG -fno-rtti) |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 217 | endif() |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 218 | # Assert |
| 219 | string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) |
Howard Hinnant | ec3bb02 | 2012-08-05 17:37:39 +0000 | [diff] [blame] | 220 | if (LIBCXX_ENABLE_ASSERTIONS) |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 221 | # MSVC doesn't like _DEBUG on release builds. See PR 4379. |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 222 | if (NOT MSVC) |
| 223 | list(APPEND LIBCXX_COMPILE_FLAGS -D_DEBUG) |
| 224 | endif() |
| 225 | # On Release builds cmake automatically defines NDEBUG, so we |
| 226 | # explicitly undefine it: |
| 227 | if (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE") |
| 228 | list(APPEND LIBCXX_COMPILE_FLAGS -UNDEBUG) |
| 229 | endif() |
| 230 | else() |
| 231 | if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE") |
| 232 | list(APPEND LIBCXX_COMPILE_FLAGS -DNDEBUG) |
| 233 | endif() |
| 234 | endif() |
| 235 | # Static library |
| 236 | if (NOT LIBCXX_ENABLE_SHARED) |
| 237 | list(APPEND LIBCXX_COMPILE_FLAGS -D_LIBCPP_BUILD_STATIC) |
Howard Hinnant | 807d633 | 2013-02-25 15:50:36 +0000 | [diff] [blame] | 238 | endif() |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 239 | |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 240 | if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32) |
| 241 | if (LIBCXX_BUILD_32_BITS) |
| 242 | message(STATUS "Building 32 bits executables and libraries.") |
| 243 | list(APPEND LIBCXX_CXX_FLAGS "-m32") |
| 244 | endif() |
| 245 | elseif(LIBCXX_BUILD_32_BITS) |
| 246 | message(FATAL_ERROR "LIBCXX_BUILD_32_BITS=ON is not supported on this platform.") |
| 247 | endif() |
| 248 | # This is the _ONLY_ place where add_definitions is called. |
| 249 | if (MSVC) |
| 250 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) |
| 251 | endif() |
| 252 | |
| 253 | # LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE configuration |
| 254 | if (NOT LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE) |
| 255 | add_definitions(-D_LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE) |
| 256 | endif() |
| 257 | |
| 258 | # LIBCXX_ENABLE_STDIN configuration |
| 259 | if (NOT LIBCXX_ENABLE_STDIN) |
| 260 | add_definitions(-D_LIBCPP_HAS_NO_STDIN) |
| 261 | endif() |
| 262 | |
| 263 | # LIBCXX_ENABLE_STDOUT configuration |
| 264 | if (NOT LIBCXX_ENABLE_STDOUT) |
| 265 | add_definitions(-D_LIBCPP_HAS_NO_STDOUT) |
| 266 | endif() |
| 267 | |
| 268 | # LIBCXX_ENABLE_THREADS configuration |
| 269 | if (NOT LIBCXX_ENABLE_THREADS) |
| 270 | add_definitions(-D_LIBCPP_HAS_NO_THREADS) |
| 271 | if (NOT LIBCXX_ENABLE_MONOTONIC_CLOCK) |
| 272 | add_definitions(-D_LIBCPP_HAS_NO_MONOTONIC_CLOCK) |
| 273 | endif() |
| 274 | # Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON. |
| 275 | elseif(NOT LIBCXX_ENABLE_MONOTONIC_CLOCK) |
| 276 | message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF" |
| 277 | " when LIBCXX_ENABLE_THREADS is also set to OFF.") |
| 278 | endif() |
| 279 | |
| 280 | # LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS configuration |
| 281 | if (NOT LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS) |
| 282 | add_definitions(-D_LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS) |
| 283 | endif() |
| 284 | |
| 285 | # Configure for sanitizers. If LIBCXX_BUILT_STANDALONE then we have to do |
| 286 | # the flag translation ourselves. Othewise LLVM's CMakeList.txt will handle it. |
| 287 | if (LIBCXX_BUILT_STANDALONE) |
| 288 | # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC. |
| 289 | # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do. |
| 290 | if (LLVM_USE_SANITIZER AND NOT MSVC) |
| 291 | append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_FNO_OMIT_FRAME_POINTER_FLAG |
| 292 | "-fno-omit-frame-pointer") |
| 293 | if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND |
| 294 | NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO") |
| 295 | append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_GLINE_TABLES_ONLY_FLAG |
| 296 | "-gline-tables-only") |
| 297 | endif() |
| 298 | if (LLVM_USE_SANITIZER STREQUAL "Address") |
| 299 | list(APPEND LIBCXX_CXX_FLAGS "-fsanitize=address") |
| 300 | elseif (LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?") |
| 301 | list(APPEND LIBCXX_CXX_FLAGS "-fsanitize=memory") |
| 302 | if (LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins") |
| 303 | list(APPEND LIBCXX_CXX_FLAGS "-fsanitize-memory-track-origins") |
| 304 | endif() |
| 305 | elseif (LLVM_USE_SANITIZER STREQUAL "Undefined") |
| 306 | list(APPEND LIBCXX_CXX_FLAGS |
| 307 | "-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover") |
| 308 | elseif (LLVM_USE_SANITIZER STREQUAL "Thread") |
| 309 | list(APPEND LIBCXX_CXX_FLAGS "-fsanitize=thread") |
| 310 | else() |
| 311 | message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}") |
| 312 | endif() |
| 313 | elseif(MSVC) |
| 314 | message(WARNING "LLVM_USE_SANITIZER is not supported with MSVC") |
| 315 | endif() |
| 316 | endif() |
| 317 | |
| 318 | append_if(LIBCXX_CXX_FLAGS LIBCXX_TARGET_TRIPLE |
| 319 | "-target ${LIBCXX_TARGET_TRIPLE}") |
| 320 | |
| 321 | append_if(LIBCXX_CXX_FLAGS LIBCXX_SYSROOT "--sysroot ${LIBCXX_SYSROOT}") |
| 322 | append_if(LIBCXX_CXX_FLAGS LIBCXX_GCC_TOOLCHAIN |
| 323 | "-gcc-toolchain ${LIBCXX_GCC_TOOLCHAIN}") |
| 324 | |
| 325 | if (LLVM_USE_SANITIZER AND LIBCXX_GENERATE_COVERAGE) |
| 326 | message(FATAL_ERROR "LLVM_USE_SANITIZER cannot be used with LIBCXX_GENERATE_COVERAGE") |
| 327 | endif() |
| 328 | |
| 329 | string(REPLACE ";" " " LIBCXX_CXX_FLAGS "${LIBCXX_CXX_FLAGS}") |
| 330 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXX_CXX_FLAGS}") |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 331 | |
| 332 | #=============================================================================== |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 333 | # Setup Source Code |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 334 | #=============================================================================== |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 335 | |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 336 | include_directories(include) |
Howard Hinnant | 6e207d5 | 2013-11-15 17:18:57 +0000 | [diff] [blame] | 337 | add_subdirectory(include) |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 338 | |
| 339 | # Add source code. This also contains all of the logic for deciding linker flags |
| 340 | # soname, etc... |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 341 | add_subdirectory(lib) |
Eric Fiselier | e50f82d | 2015-07-29 23:46:55 +0000 | [diff] [blame^] | 342 | |
| 343 | #=============================================================================== |
| 344 | # Setup Tests |
| 345 | #=============================================================================== |
| 346 | |
| 347 | add_subdirectory(test) |