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 | #=============================================================================== |
| 6 | |
| 7 | project(libcxx CXX C) |
| 8 | cmake_minimum_required(VERSION 2.8) |
| 9 | |
| 10 | set(PACKAGE_NAME libcxx) |
| 11 | set(PACKAGE_VERSION trunk-svn) |
| 12 | set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") |
| 13 | set(PACKAGE_BUGREPORT "llvmbugs@cs.uiuc.edu") |
| 14 | |
| 15 | # Add path for custom modules |
| 16 | set(CMAKE_MODULE_PATH |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 17 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake" |
| 18 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" |
Alexey Samsonov | 179fa78 | 2013-09-30 09:10:01 +0000 | [diff] [blame] | 19 | ${CMAKE_MODULE_PATH} |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 20 | ) |
| 21 | |
| 22 | # Require out of source build. |
| 23 | include(MacroEnsureOutOfSourceBuild) |
| 24 | MACRO_ENSURE_OUT_OF_SOURCE_BUILD( |
| 25 | "${PROJECT_NAME} requires an out of source build. Please create a separate |
| 26 | build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there." |
| 27 | ) |
| 28 | |
Peter Collingbourne | 4c81b00 | 2013-10-03 21:58:25 +0000 | [diff] [blame] | 29 | if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) |
| 30 | set(LIBCXX_BUILT_STANDALONE 1) |
| 31 | endif() |
| 32 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 33 | #=============================================================================== |
| 34 | # Setup CMake Options |
| 35 | #=============================================================================== |
| 36 | |
| 37 | # Define options. |
| 38 | option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON) |
| 39 | option(LIBCXX_ENABLE_RTTI "Use run time type information." ON) |
| 40 | option(LIBCXX_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON) |
| 41 | option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." ON) |
| 42 | option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) |
Eric Fiselier | dfe5e72 | 2014-08-16 01:35:36 +0000 | [diff] [blame] | 43 | option(LIBCXX_ENABLE_CXX1Y "Enable -std=c++1y and use of c++1y language features if the compiler supports it." OFF) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 44 | option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON) |
Michael Gottesman | c64c980 | 2013-09-02 07:28:05 +0000 | [diff] [blame] | 45 | option(LIBCXX_INSTALL_SUPPORT_HEADERS "Install libc++ support headers." ON) |
Eric Fiselier | 25a1516 | 2014-08-18 05:03:46 +0000 | [diff] [blame] | 46 | if (LIBCXX_BUILT_STANDALONE) |
| 47 | set(LLVM_USE_SANITIZER "" CACHE STRING |
| 48 | "Define the sanitizer used to build the library and tests") |
| 49 | endif() |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 50 | |
Peter Collingbourne | d0d308f | 2013-10-06 22:13:19 +0000 | [diff] [blame] | 51 | set(CXXABIS none libcxxabi libcxxrt libstdc++ libsupc++) |
Viktor Kutuzov | f2e8c04 | 2014-08-08 06:53:30 +0000 | [diff] [blame] | 52 | if (NOT LIBCXX_CXX_ABI) |
| 53 | if (NOT DEFINED LIBCXX_BUILT_STANDALONE AND |
| 54 | IS_DIRECTORY "${CMAKE_SOURCE_DIR}/projects/libcxxabi") |
| 55 | set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi") |
Dan Albert | 0c6d1a8 | 2014-07-26 23:08:33 +0000 | [diff] [blame] | 56 | set(LIBCXX_LIBCXXABI_INCLUDE_PATHS "${CMAKE_SOURCE_DIR}/projects/libcxxabi/include") |
| 57 | set(LIBCXX_CXX_ABI_INTREE 1) |
| 58 | else () |
Viktor Kutuzov | f2e8c04 | 2014-08-08 06:53:30 +0000 | [diff] [blame] | 59 | set(LIBCXX_CXX_ABI_LIBNAME "none") |
Dan Albert | 0c6d1a8 | 2014-07-26 23:08:33 +0000 | [diff] [blame] | 60 | endif () |
Viktor Kutuzov | f2e8c04 | 2014-08-08 06:53:30 +0000 | [diff] [blame] | 61 | else () |
| 62 | set(LIBCXX_CXX_ABI_LIBNAME "${LIBCXX_CXX_ABI}") |
| 63 | endif () |
Michael J. Spencer | a358fbe | 2012-11-30 21:02:29 +0000 | [diff] [blame] | 64 | set(LIBCXX_CXX_ABI "${LIBCXX_CXX_ABI}" CACHE STRING |
| 65 | "Specify C++ ABI library to use." FORCE) |
Howard Hinnant | 9c07b14 | 2013-08-19 21:42:07 +0000 | [diff] [blame] | 66 | set_property(CACHE LIBCXX_CXX_ABI PROPERTY STRINGS ;${CXXABIS}) |
Michael J. Spencer | a358fbe | 2012-11-30 21:02:29 +0000 | [diff] [blame] | 67 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 68 | #=============================================================================== |
| 69 | # Configure System |
| 70 | #=============================================================================== |
| 71 | |
| 72 | # Get triples. |
| 73 | include(GetTriple) |
| 74 | get_host_triple(LIBCXX_HOST_TRIPLE |
| 75 | LIBCXX_HOST_ARCH |
| 76 | LIBCXX_HOST_VENDOR |
| 77 | LIBCXX_HOST_OS |
| 78 | ) |
| 79 | set(LIBCXX_HOST_TRIPLE ${LIBCXX_HOST_TRIPLE} CACHE STRING "Host triple.") |
| 80 | get_target_triple(LIBCXX_TARGET_TRIPLE |
| 81 | LIBCXX_TARGET_ARCH |
| 82 | LIBCXX_TARGET_VENDOR |
| 83 | LIBCXX_TARGET_OS |
| 84 | ) |
| 85 | set(LIBCXX_TARGET_TRIPLE ${LIBCXX_TARGET_TRIPLE} CACHE STRING "Target triple.") |
| 86 | |
Howard Hinnant | b85dea3 | 2013-02-08 19:04:53 +0000 | [diff] [blame] | 87 | #=============================================================================== |
| 88 | # Add an ABI library if appropriate |
| 89 | #=============================================================================== |
| 90 | |
| 91 | # |
| 92 | # _setup_abi: Set up the build to use an ABI library |
| 93 | # |
| 94 | # Parameters: |
| 95 | # abidefines: A list of defines needed to compile libc++ with the ABI library |
| 96 | # abilibs : A list of libraries to link against |
| 97 | # abifiles : A list of files (which may be relative paths) to copy into the |
| 98 | # libc++ build tree for the build. These files will also be |
| 99 | # installed alongside the libc++ headers. |
| 100 | # abidirs : A list of relative paths to create under an include directory |
| 101 | # in the libc++ build directory. |
| 102 | # |
| 103 | macro(setup_abi_lib abipathvar abidefines abilibs abifiles abidirs) |
| 104 | list(APPEND LIBCXX_CXX_FEATURE_FLAGS ${abidefines}) |
| 105 | set(${abipathvar} "${${abipathvar}}" |
David Fang | 44ead61 | 2014-06-24 20:32:11 +0000 | [diff] [blame] | 106 | CACHE PATH |
| 107 | "Paths to C++ ABI header directories separated by ';'." FORCE |
Howard Hinnant | b85dea3 | 2013-02-08 19:04:53 +0000 | [diff] [blame] | 108 | ) |
| 109 | set(LIBCXX_CXX_ABI_LIBRARIES ${abilibs}) |
| 110 | set(LIBCXX_ABILIB_FILES ${abifiles}) |
David Fang | 44ead61 | 2014-06-24 20:32:11 +0000 | [diff] [blame] | 111 | |
Michael J. Spencer | db8a030 | 2012-12-31 19:34:21 +0000 | [diff] [blame] | 112 | file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include") |
Howard Hinnant | b85dea3 | 2013-02-08 19:04:53 +0000 | [diff] [blame] | 113 | foreach(_d ${abidirs}) |
| 114 | file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/${_d}") |
| 115 | endforeach() |
David Fang | 44ead61 | 2014-06-24 20:32:11 +0000 | [diff] [blame] | 116 | |
Howard Hinnant | b85dea3 | 2013-02-08 19:04:53 +0000 | [diff] [blame] | 117 | foreach(fpath ${LIBCXX_ABILIB_FILES}) |
Michael J. Spencer | a358fbe | 2012-11-30 21:02:29 +0000 | [diff] [blame] | 118 | set(found FALSE) |
Howard Hinnant | b85dea3 | 2013-02-08 19:04:53 +0000 | [diff] [blame] | 119 | foreach(incpath ${${abipathvar}}) |
| 120 | if (EXISTS "${incpath}/${fpath}") |
Michael J. Spencer | a358fbe | 2012-11-30 21:02:29 +0000 | [diff] [blame] | 121 | set(found TRUE) |
Howard Hinnant | b85dea3 | 2013-02-08 19:04:53 +0000 | [diff] [blame] | 122 | get_filename_component(dstdir ${fpath} PATH) |
| 123 | get_filename_component(ifile ${fpath} NAME) |
David Fang | 44ead61 | 2014-06-24 20:32:11 +0000 | [diff] [blame] | 124 | file(COPY "${incpath}/${fpath}" |
| 125 | DESTINATION "${CMAKE_BINARY_DIR}/include/${dstdir}" |
Michael J. Spencer | a358fbe | 2012-11-30 21:02:29 +0000 | [diff] [blame] | 126 | ) |
David Fang | 44ead61 | 2014-06-24 20:32:11 +0000 | [diff] [blame] | 127 | list(APPEND abilib_headers "${CMAKE_BINARY_DIR}/include/${fpath}") |
Michael J. Spencer | a358fbe | 2012-11-30 21:02:29 +0000 | [diff] [blame] | 128 | endif() |
| 129 | endforeach() |
| 130 | if (NOT found) |
Howard Hinnant | b85dea3 | 2013-02-08 19:04:53 +0000 | [diff] [blame] | 131 | message(FATAL_ERROR "Failed to find ${fpath}") |
Michael J. Spencer | a358fbe | 2012-11-30 21:02:29 +0000 | [diff] [blame] | 132 | endif() |
| 133 | endforeach() |
David Fang | 44ead61 | 2014-06-24 20:32:11 +0000 | [diff] [blame] | 134 | |
| 135 | add_custom_target(LIBCXX_CXX_ABI_DEPS DEPENDS ${abilib_headers}) |
Michael J. Spencer | a358fbe | 2012-11-30 21:02:29 +0000 | [diff] [blame] | 136 | include_directories("${CMAKE_BINARY_DIR}/include") |
David Fang | 44ead61 | 2014-06-24 20:32:11 +0000 | [diff] [blame] | 137 | |
| 138 | install(FILES ${abilib_headers} |
Michael J. Spencer | a358fbe | 2012-11-30 21:02:29 +0000 | [diff] [blame] | 139 | DESTINATION include/c++/v1 |
David Fang | 44ead61 | 2014-06-24 20:32:11 +0000 | [diff] [blame] | 140 | PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ |
Michael J. Spencer | a358fbe | 2012-11-30 21:02:29 +0000 | [diff] [blame] | 141 | ) |
Howard Hinnant | b85dea3 | 2013-02-08 19:04:53 +0000 | [diff] [blame] | 142 | endmacro() |
| 143 | |
Viktor Kutuzov | f2e8c04 | 2014-08-08 06:53:30 +0000 | [diff] [blame] | 144 | if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++" OR |
| 145 | "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libsupc++") |
Howard Hinnant | b85dea3 | 2013-02-08 19:04:53 +0000 | [diff] [blame] | 146 | set(_LIBSUPCXX_INCLUDE_FILES |
| 147 | cxxabi.h bits/c++config.h bits/os_defines.h bits/cpu_defines.h |
| 148 | bits/cxxabi_tweaks.h bits/cxxabi_forced.h |
| 149 | ) |
Viktor Kutuzov | f2e8c04 | 2014-08-08 06:53:30 +0000 | [diff] [blame] | 150 | if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++") |
Peter Collingbourne | d0d308f | 2013-10-06 22:13:19 +0000 | [diff] [blame] | 151 | set(_LIBSUPCXX_DEFINES "-DLIBSTDCXX") |
| 152 | set(_LIBSUPCXX_LIBNAME stdc++) |
| 153 | else() |
| 154 | set(_LIBSUPCXX_DEFINES "") |
| 155 | set(_LIBSUPCXX_LIBNAME supc++) |
| 156 | endif() |
| 157 | setup_abi_lib("LIBCXX_LIBSUPCXX_INCLUDE_PATHS" |
| 158 | "-D__GLIBCXX__ ${_LIBSUPCXX_DEFINES}" |
| 159 | "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_INCLUDE_FILES}" "bits" |
Howard Hinnant | b85dea3 | 2013-02-08 19:04:53 +0000 | [diff] [blame] | 160 | ) |
Viktor Kutuzov | f2e8c04 | 2014-08-08 06:53:30 +0000 | [diff] [blame] | 161 | elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxabi") |
Dan Albert | 0c6d1a8 | 2014-07-26 23:08:33 +0000 | [diff] [blame] | 162 | if (LIBCXX_CXX_ABI_INTREE) |
Alexey Samsonov | e515bbd | 2014-07-28 19:25:44 +0000 | [diff] [blame] | 163 | # Link against just-built "cxxabi" target. |
| 164 | set(CXXABI_LIBNAME cxxabi) |
| 165 | else() |
| 166 | # Assume c++abi is installed in the system, rely on -lc++abi link flag. |
| 167 | set(CXXABI_LIBNAME "c++abi") |
| 168 | endif() |
| 169 | setup_abi_lib("LIBCXX_LIBCXXABI_INCLUDE_PATHS" "" |
| 170 | ${CXXABI_LIBNAME} "cxxabi.h" "" |
| 171 | ) |
Viktor Kutuzov | f2e8c04 | 2014-08-08 06:53:30 +0000 | [diff] [blame] | 172 | elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxrt") |
Howard Hinnant | b85dea3 | 2013-02-08 19:04:53 +0000 | [diff] [blame] | 173 | setup_abi_lib("LIBCXX_LIBCXXRT_INCLUDE_PATHS" "-DLIBCXXRT" |
| 174 | "cxxrt" "cxxabi.h;unwind.h;unwind-arm.h;unwind-itanium.h" "" |
Howard Hinnant | 46c49d1 | 2013-02-07 15:27:39 +0000 | [diff] [blame] | 175 | ) |
Viktor Kutuzov | f2e8c04 | 2014-08-08 06:53:30 +0000 | [diff] [blame] | 176 | elseif (NOT "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "none") |
Michael J. Spencer | a358fbe | 2012-11-30 21:02:29 +0000 | [diff] [blame] | 177 | message(FATAL_ERROR |
Peter Collingbourne | d0d308f | 2013-10-06 22:13:19 +0000 | [diff] [blame] | 178 | "Currently libstdc++, libsupc++, libcxxabi, libcxxrt and none are " |
Howard Hinnant | b85dea3 | 2013-02-08 19:04:53 +0000 | [diff] [blame] | 179 | "supported for c++ abi." |
| 180 | ) |
Michael J. Spencer | a358fbe | 2012-11-30 21:02:29 +0000 | [diff] [blame] | 181 | endif () |
| 182 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 183 | # Configure compiler. |
| 184 | include(config-ix) |
| 185 | |
| 186 | #=============================================================================== |
| 187 | # Setup Compiler Flags |
| 188 | #=============================================================================== |
| 189 | |
| 190 | # Get required flags. |
| 191 | # On all systems the system c++ standard library headers need to be excluded. |
| 192 | if (MSVC) |
| 193 | # MSVC only has -X, which disables all default includes; including the crt. |
| 194 | # Thus, we do nothing and hope we don't accidentally include any of the C++ |
| 195 | # headers. |
| 196 | else() |
| 197 | if (LIBCXX_HAS_NOSTDINCXX_FLAG) |
Saleem Abdulrasool | eb54781 | 2014-03-12 04:11:31 +0000 | [diff] [blame] | 198 | list(APPEND LIBCXX_CXX_REQUIRED_FLAGS -nostdinc++) |
David Fang | 44ead61 | 2014-06-24 20:32:11 +0000 | [diff] [blame] | 199 | string(REPLACE "-stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 200 | endif() |
Eric Fiselier | dfe5e72 | 2014-08-16 01:35:36 +0000 | [diff] [blame] | 201 | # If c++1y has been enabled then attempt to use it. Fail if it is no supported |
| 202 | # by the compiler. Otherwise choose c++11 and ensure the compiler supports it. |
| 203 | if (LIBCXX_ENABLE_CXX1Y) |
| 204 | if (LIBCXX_HAS_STDCXX1Y_FLAG) |
| 205 | set(LIBCXX_STD_VERSION c++1y) |
| 206 | else() |
| 207 | message(FATAL_ERROR "c++1y was enabled but the compiler does not support it.") |
| 208 | endif() |
| 209 | else() |
| 210 | if (LIBCXX_HAS_STDCXX11_FLAG) |
| 211 | set(LIBCXX_STD_VERSION c++11) |
| 212 | else() |
| 213 | message(FATAL_ERROR "c++11 is required by libc++ but is not supported by the compiler") |
| 214 | endif() |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 215 | endif() |
Eric Fiselier | dfe5e72 | 2014-08-16 01:35:36 +0000 | [diff] [blame] | 216 | # LIBCXX_STD_VERSION should always be set at this point. |
| 217 | list(APPEND LIBCXX_CXX_REQUIRED_FLAGS "-std=${LIBCXX_STD_VERSION}") |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 218 | endif() |
| 219 | |
| 220 | macro(append_if list condition var) |
| 221 | if (${condition}) |
| 222 | list(APPEND ${list} ${var}) |
| 223 | endif() |
| 224 | endmacro() |
| 225 | |
| 226 | # Get warning flags |
Howard Hinnant | adb73b1 | 2013-10-05 00:07:35 +0000 | [diff] [blame] | 227 | if (NOT MSVC) |
| 228 | append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_WALL_FLAG -Wall) |
Saleem Abdulrasool | eb54781 | 2014-03-12 04:11:31 +0000 | [diff] [blame] | 229 | list(APPEND LIBCXX_CXX_REQUIRED_FLAGS -Werror=return-type) |
Howard Hinnant | adb73b1 | 2013-10-05 00:07:35 +0000 | [diff] [blame] | 230 | endif() |
Marshall Clow | 0f7afe7 | 2013-10-21 15:56:35 +0000 | [diff] [blame] | 231 | |
Douglas Gregor | f9b6e7e | 2012-06-07 22:26:00 +0000 | [diff] [blame] | 232 | append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_W_FLAG -W) |
| 233 | append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_WNO_UNUSED_PARAMETER_FLAG -Wno-unused-parameter) |
| 234 | append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_WWRITE_STRINGS_FLAG -Wwrite-strings) |
| 235 | append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_WNO_LONG_LONG_FLAG -Wno-long-long) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 236 | if (LIBCXX_ENABLE_WERROR) |
Douglas Gregor | f9b6e7e | 2012-06-07 22:26:00 +0000 | [diff] [blame] | 237 | append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_WERROR_FLAG -Werror) |
| 238 | append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_WX_FLAG -WX) |
Alexey Samsonov | f7eb573 | 2013-10-02 07:44:19 +0000 | [diff] [blame] | 239 | else() |
| 240 | append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_WNO_ERROR_FLAG -Wno-error) |
| 241 | append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_NO_WX_FLAG -WX-) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 242 | endif() |
| 243 | if (LIBCXX_ENABLE_PEDANTIC) |
Douglas Gregor | f9b6e7e | 2012-06-07 22:26:00 +0000 | [diff] [blame] | 244 | append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_PEDANTIC_FLAG -pedantic) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 245 | endif() |
| 246 | |
| 247 | # Get feature flags. |
| 248 | # Exceptions |
| 249 | if (LIBCXX_ENABLE_EXCEPTIONS) |
| 250 | # Catches C++ exceptions only and tells the compiler to assume that extern C |
| 251 | # functions never throw a C++ exception. |
| 252 | append_if(LIBCXX_CXX_FEATURE_FLAGS LIBCXX_HAS_EHSC_FLAG -EHsc) |
| 253 | else() |
| 254 | list(APPEND LIBCXX_CXX_FEATURE_FLAGS -D_LIBCPP_NO_EXCEPTIONS) |
| 255 | append_if(LIBCXX_CXX_FEATURE_FLAGS LIBCXX_HAS_NO_EHS_FLAG -EHs-) |
| 256 | append_if(LIBCXX_CXX_FEATURE_FLAGS LIBCXX_HAS_NO_EHA_FLAG -EHa-) |
| 257 | append_if(LIBCXX_CXX_FEATURE_FLAGS LIBCXX_HAS_FNO_EXCEPTIONS_FLAG -fno-exceptions) |
| 258 | endif() |
| 259 | # RTTI |
| 260 | if (NOT LIBCXX_ENABLE_RTTI) |
| 261 | list(APPEND LIBCXX_CXX_FEATURE_FLAGS -D_LIBCPP_NO_RTTI) |
| 262 | append_if(LIBCXX_CXX_FEATURE_FLAGS LIBCXX_HAS_NO_GR_FLAG -GR-) |
| 263 | append_if(LIBCXX_CXX_FEATURE_FLAGS LIBCXX_HAS_FNO_RTTI_FLAG -fno-rtti) |
| 264 | endif() |
| 265 | # Assert |
Howard Hinnant | e103a3d | 2012-08-05 17:37:39 +0000 | [diff] [blame] | 266 | string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) |
| 267 | if (LIBCXX_ENABLE_ASSERTIONS) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 268 | # MSVC doesn't like _DEBUG on release builds. See PR 4379. |
| 269 | if (NOT MSVC) |
| 270 | list(APPEND LIBCXX_CXX_FEATURE_FLAGS -D_DEBUG) |
| 271 | endif() |
| 272 | # On Release builds cmake automatically defines NDEBUG, so we |
| 273 | # explicitly undefine it: |
| 274 | if (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE") |
| 275 | list(APPEND LIBCXX_CXX_FEATURE_FLAGS -UNDEBUG) |
| 276 | endif() |
| 277 | else() |
| 278 | if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE") |
| 279 | list(APPEND LIBCXX_CXX_FEATURE_FLAGS -DNDEBUG) |
| 280 | endif() |
| 281 | endif() |
Howard Hinnant | 4a0e74f | 2013-02-25 15:50:36 +0000 | [diff] [blame] | 282 | # Static library |
| 283 | if (NOT LIBCXX_ENABLE_SHARED) |
| 284 | list(APPEND LIBCXX_CXX_FEATURE_FLAGS -D_LIBCPP_BUILD_STATIC) |
| 285 | endif() |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 286 | |
| 287 | # This is the _ONLY_ place where add_definitions is called. |
Marshall Clow | 0f7afe7 | 2013-10-21 15:56:35 +0000 | [diff] [blame] | 288 | if (MSVC) |
| 289 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) |
| 290 | endif() |
| 291 | |
Eric Fiselier | 25a1516 | 2014-08-18 05:03:46 +0000 | [diff] [blame] | 292 | # Configure for sanitizers. If LIBCXX_BUILT_STANDALONE then we have to do |
| 293 | # the flag translation ourselves. Othewise LLVM's CMakeList.txt will handle it. |
| 294 | if (LIBCXX_BUILT_STANDALONE) |
| 295 | # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC. |
| 296 | # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do. |
| 297 | if (LLVM_USE_SANITIZER AND NOT MSVC) |
| 298 | append_if(LIBCXX_CXX_FEATURE_FLAGS LIBCXX_HAS_NO_OMIT_FRAME_POINTER_FLAG |
| 299 | "-fno-omit-frame-pointer") |
| 300 | if (LLVM_USE_SANITIZER STREQUAL "Address") |
| 301 | list(APPEND LIBCXX_CXX_FEATURE_FLAGS "-fsanitize=address") |
| 302 | elseif (LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?") |
| 303 | list(APPEND LIBCXX_CXX_FEATURE_FLAGS "-fsanitize=memory") |
| 304 | if (LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins") |
| 305 | list(APPEND LIBCXX_CXX_FEATURE_FLAGS "-fsanitize-memory-track-origins") |
| 306 | endif() |
| 307 | else() |
| 308 | message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}") |
| 309 | endif() |
| 310 | elseif(MSVC) |
| 311 | message(WARNING "LLVM_USE_SANITIZER is not supported with MSVC") |
| 312 | endif() |
| 313 | endif() |
| 314 | |
Saleem Abdulrasool | 89a52ff | 2014-03-12 04:11:28 +0000 | [diff] [blame] | 315 | string(REPLACE ";" " " LIBCXX_CXX_REQUIRED_FLAGS "${LIBCXX_CXX_REQUIRED_FLAGS}") |
| 316 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXX_CXX_REQUIRED_FLAGS}") |
| 317 | |
| 318 | string(REPLACE ";" " " LIBCXX_CXX_WARNING_FLAGS "${LIBCXX_CXX_WARNING_FLAGS}") |
| 319 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXX_CXX_WARNING_FLAGS}") |
| 320 | |
| 321 | string(REPLACE ";" " " LIBCXX_CXX_FEATURE_FLAGS "${LIBCXX_CXX_FEATURE_FLAGS}") |
| 322 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXX_CXX_FEATURE_FLAGS}") |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 323 | |
| 324 | #=============================================================================== |
| 325 | # Setup Source Code |
| 326 | #=============================================================================== |
| 327 | |
| 328 | include_directories(include) |
Howard Hinnant | c4962b3 | 2013-11-15 17:18:57 +0000 | [diff] [blame] | 329 | add_subdirectory(include) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 330 | |
| 331 | # Add source code. This also contains all of the logic for deciding linker flags |
| 332 | # soname, etc... |
| 333 | add_subdirectory(lib) |
| 334 | |
| 335 | #=============================================================================== |
| 336 | # Setup Tests |
| 337 | #=============================================================================== |
| 338 | |
| 339 | add_subdirectory(test) |