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