Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 1 | # See www/CMake.html for instructions on how to build libcxx with CMake. |
Eric Fiselier | 7d6b2ad | 2017-05-04 06:28:34 | [diff] [blame] | 2 | |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 3 | #=============================================================================== |
| 4 | # Setup Project |
| 5 | #=============================================================================== |
Chris Bieneman | 752cd33 | 2016-05-31 20:21:52 | [diff] [blame] | 6 | cmake_minimum_required(VERSION 3.4.3) |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 7 | |
Eric Fiselier | 8e0dec7 | 2015-01-26 21:56:45 | [diff] [blame] | 8 | if(POLICY CMP0042) |
| 9 | cmake_policy(SET CMP0042 NEW) # Set MACOSX_RPATH=YES by default |
| 10 | endif() |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 11 | if(POLICY CMP0022) |
| 12 | cmake_policy(SET CMP0022 NEW) # Required when interacting with LLVM and Clang |
| 13 | endif() |
Eric Fiselier | 6a10864 | 2018-07-26 05:08:30 | [diff] [blame] | 14 | if(POLICY CMP0068) |
| 15 | cmake_policy(SET CMP0068 NEW) |
| 16 | set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON) |
| 17 | endif() |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 18 | |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 19 | # Add path for custom modules |
| 20 | set(CMAKE_MODULE_PATH |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 21 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake" |
| 22 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" |
Eric Fiselier | d888cf5 | 2015-12-30 03:39:03 | [diff] [blame] | 23 | ${CMAKE_MODULE_PATH} |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 24 | ) |
| 25 | |
Jonas Hahnfeld | 66c60d9 | 2019-02-17 12:16:20 | [diff] [blame] | 26 | if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXX_STANDALONE_BUILD) |
Saleem Abdulrasool | 163333f | 2016-02-08 03:50:18 | [diff] [blame] | 27 | project(libcxx CXX C) |
| 28 | |
| 29 | set(PACKAGE_NAME libcxx) |
Nick Desaulniers | 49fb4a9 | 2019-11-11 17:10:14 | [diff] [blame] | 30 | set(PACKAGE_VERSION 10.0.0git) |
Saleem Abdulrasool | 163333f | 2016-02-08 03:50:18 | [diff] [blame] | 31 | set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") |
| 32 | set(PACKAGE_BUGREPORT "[email protected]") |
Eric Fiselier | 28349f9 | 2016-11-14 02:43:12 | [diff] [blame] | 33 | |
| 34 | # Find the LLVM sources and simulate LLVM CMake options. |
| 35 | include(HandleOutOfTreeLLVM) |
Eugene Zelenko | 772d114 | 2016-08-08 18:01:50 | [diff] [blame] | 36 | endif() |
Saleem Abdulrasool | 163333f | 2016-02-08 03:50:18 | [diff] [blame] | 37 | |
Petr Hosek | daf3a69 | 2017-01-16 00:33:07 | [diff] [blame] | 38 | if (LIBCXX_STANDALONE_BUILD) |
| 39 | include(FindPythonInterp) |
| 40 | if( NOT PYTHONINTERP_FOUND ) |
| 41 | message(WARNING "Failed to find python interpreter. " |
| 42 | "The libc++ test suite will be disabled.") |
| 43 | set(LLVM_INCLUDE_TESTS OFF) |
| 44 | endif() |
| 45 | endif() |
| 46 | |
Saleem Abdulrasool | 163333f | 2016-02-08 03:50:18 | [diff] [blame] | 47 | # Require out of source build. |
| 48 | include(MacroEnsureOutOfSourceBuild) |
| 49 | MACRO_ENSURE_OUT_OF_SOURCE_BUILD( |
| 50 | "${PROJECT_NAME} requires an out of source build. Please create a separate |
| 51 | build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there." |
| 52 | ) |
Eric Fiselier | 5e0b8fc | 2018-10-01 01:31:23 | [diff] [blame] | 53 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC") |
| 54 | message(STATUS "Configuring for clang-cl") |
| 55 | set(LIBCXX_TARGETING_CLANG_CL ON) |
| 56 | endif() |
Saleem Abdulrasool | 163333f | 2016-02-08 03:50:18 | [diff] [blame] | 57 | |
Eric Fiselier | cc1f65c | 2017-01-14 06:06:47 | [diff] [blame] | 58 | if (MSVC) |
| 59 | set(LIBCXX_TARGETING_MSVC ON) |
Eric Fiselier | 11edd93 | 2018-10-01 01:00:11 | [diff] [blame] | 60 | message(STATUS "Configuring for MSVC") |
Eric Fiselier | cc1f65c | 2017-01-14 06:06:47 | [diff] [blame] | 61 | else() |
| 62 | set(LIBCXX_TARGETING_MSVC OFF) |
| 63 | endif() |
| 64 | |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 65 | #=============================================================================== |
| 66 | # Setup CMake Options |
| 67 | #=============================================================================== |
Eric Fiselier | 309a50a | 2016-09-07 01:15:10 | [diff] [blame] | 68 | include(CMakeDependentOption) |
Eric Fiselier | 2aeac46 | 2017-03-11 03:24:18 | [diff] [blame] | 69 | include(HandleCompilerRT) |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 70 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 71 | # Basic options --------------------------------------------------------------- |
Eric Fiselier | e49cdfb | 2017-02-04 23:22:28 | [diff] [blame] | 72 | option(LIBCXX_ENABLE_ASSERTIONS "Enable assertions independent of build mode." OFF) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 73 | option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON) |
Petr Hosek | 9e49a33 | 2016-08-08 22:57:25 | [diff] [blame] | 74 | option(LIBCXX_ENABLE_STATIC "Build libc++ as a static library." ON) |
Eric Fiselier | 27cb2f1 | 2016-05-03 21:30:18 | [diff] [blame] | 75 | option(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY "Build libc++experimental.a" ON) |
Eric Fiselier | f1d87f8 | 2019-03-21 00:04:31 | [diff] [blame] | 76 | set(ENABLE_FILESYSTEM_DEFAULT ON) |
| 77 | if (WIN32) |
| 78 | set(ENABLE_FILESYSTEM_DEFAULT OFF) |
| 79 | endif() |
| 80 | option(LIBCXX_ENABLE_FILESYSTEM "Build filesystem as part of the main libc++ library" |
| 81 | ${ENABLE_FILESYSTEM_DEFAULT}) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 82 | option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS}) |
Louis Dionne | 0a06eb9 | 2019-08-05 18:29:14 | [diff] [blame] | 83 | option(LIBCXX_ENABLE_PARALLEL_ALGORITHMS "Enable the parallel algorithms library. This requires the PSTL to be available." OFF) |
Sterling Augustine | b3e3934 | 2019-10-04 22:15:28 | [diff] [blame] | 84 | option(LIBCXX_TEST_GDB_PRETTY_PRINTERS "Test gdb pretty printers." OFF) |
Eric Fiselier | 3aa5478 | 2016-10-30 22:53:00 | [diff] [blame] | 85 | |
Eric Fiselier | 3aa5478 | 2016-10-30 22:53:00 | [diff] [blame] | 86 | # Benchmark options ----------------------------------------------------------- |
Louis Dionne | 9553008 | 2018-09-22 21:30:12 | [diff] [blame] | 87 | option(LIBCXX_INCLUDE_BENCHMARKS "Build the libc++ benchmarks and their dependencies" ON) |
Eric Fiselier | 336a1a6 | 2018-11-14 20:38:46 | [diff] [blame] | 88 | |
| 89 | set(LIBCXX_BENCHMARK_TEST_ARGS_DEFAULT --benchmark_min_time=0.01) |
| 90 | set(LIBCXX_BENCHMARK_TEST_ARGS "${LIBCXX_BENCHMARK_TEST_ARGS_DEFAULT}" CACHE STRING |
| 91 | "Arguments to pass when running the benchmarks using check-cxx-benchmarks") |
| 92 | |
Eric Fiselier | 3aa5478 | 2016-10-30 22:53:00 | [diff] [blame] | 93 | set(LIBCXX_BENCHMARK_NATIVE_STDLIB "" CACHE STRING |
| 94 | "Build the benchmarks against the specified native STL. |
| 95 | The value must be one of libc++/libstdc++") |
| 96 | set(LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN "" CACHE STRING |
| 97 | "Use alternate GCC toolchain when building the native benchmarks") |
| 98 | |
| 99 | if (LIBCXX_BENCHMARK_NATIVE_STDLIB) |
| 100 | if (NOT (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libc++" |
| 101 | OR LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libstdc++")) |
| 102 | message(FATAL_ERROR "Invalid value for LIBCXX_BENCHMARK_NATIVE_STDLIB: " |
| 103 | "'${LIBCXX_BENCHMARK_NATIVE_STDLIB}'") |
| 104 | endif() |
| 105 | endif() |
| 106 | |
Eric Fiselier | b17bb06 | 2015-08-22 19:40:49 | [diff] [blame] | 107 | option(LIBCXX_INCLUDE_DOCS "Build the libc++ documentation." ${LLVM_INCLUDE_DOCS}) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 108 | set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING |
| 109 | "Define suffix of library directory name (32/64)") |
| 110 | option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON) |
Eric Fiselier | d77135f | 2015-08-26 20:18:21 | [diff] [blame] | 111 | option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON) |
Petr Hosek | 4a1e14e | 2018-07-24 23:27:51 | [diff] [blame] | 112 | cmake_dependent_option(LIBCXX_INSTALL_STATIC_LIBRARY |
| 113 | "Install the static libc++ library." ON |
| 114 | "LIBCXX_ENABLE_STATIC;LIBCXX_INSTALL_LIBRARY" OFF) |
| 115 | cmake_dependent_option(LIBCXX_INSTALL_SHARED_LIBRARY |
| 116 | "Install the shared libc++ library." ON |
| 117 | "LIBCXX_ENABLE_SHARED;LIBCXX_INSTALL_LIBRARY" OFF) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 118 | option(LIBCXX_INSTALL_SUPPORT_HEADERS "Install libc++ support headers." ON) |
Eric Fiselier | 309a50a | 2016-09-07 01:15:10 | [diff] [blame] | 119 | cmake_dependent_option(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY |
| 120 | "Install libc++experimental.a" ON |
| 121 | "LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY;LIBCXX_INSTALL_LIBRARY" OFF) |
Eric Fiselier | 998a5c8 | 2018-07-27 03:07:09 | [diff] [blame] | 122 | |
Louis Dionne | f9a5290 | 2018-09-26 08:24:51 | [diff] [blame] | 123 | set(LIBCXX_ABI_VERSION "1" CACHE STRING "ABI version of libc++. Can be either 1 or 2, where 2 is currently not stable. Defaults to 1.") |
Eric Fiselier | fe13c13 | 2018-10-30 21:44:53 | [diff] [blame] | 124 | set(LIBCXX_ABI_NAMESPACE "" CACHE STRING "The inline ABI namespace used by libc++. It defaults to __n where `n` is the current ABI version.") |
Evgeniy Stepanov | a66a7b3 | 2015-10-13 23:48:28 | [diff] [blame] | 125 | option(LIBCXX_ABI_UNSTABLE "Unstable ABI of libc++." OFF) |
Shoaib Meenai | a4a3d40 | 2017-10-05 02:18:08 | [diff] [blame] | 126 | option(LIBCXX_ABI_FORCE_ITANIUM "Ignore auto-detection and force use of the Itanium ABI.") |
| 127 | option(LIBCXX_ABI_FORCE_MICROSOFT "Ignore auto-detection and force use of the Microsoft ABI.") |
Eric Fiselier | 2405bd6 | 2019-05-29 02:21:37 | [diff] [blame] | 128 | |
| 129 | |
| 130 | set(LIBCXX_HAS_MERGED_TYPEINFO_NAMES_DEFAULT "" CACHE STRING |
| 131 | "Whether typeinfo names are expected to be unique. Defining this option overrides the default configuration in the library.") |
| 132 | set(MERGED_TYPEINFO_VALUES ";ON;OFF") |
| 133 | set_property(CACHE LIBCXX_HAS_MERGED_TYPEINFO_NAMES_DEFAULT PROPERTY STRINGS ${MERGED_TYPEINFO_DEFAULTS}) |
| 134 | list(FIND MERGED_TYPEINFO_VALUES "${LIBCXX_HAS_MERGED_TYPEINFO_NAMES_DEFAULT}" IS_VALID_DEFAULT) |
| 135 | if (${IS_VALID_DEFAULT} EQUAL -1) |
| 136 | message(FATAL_ERROR "Value '${LIBCXX_HAS_MERGED_TYPEINFO_NAMES_DEFAULT}' is not a valid value for |
| 137 | LIBCXX_HAS_MERGED_TYPEINFO_NAMES_DEFAULT") |
| 138 | endif() |
| 139 | |
Louis Dionne | 61cd687 | 2018-08-16 12:44:28 | [diff] [blame] | 140 | option(LIBCXX_HIDE_FROM_ABI_PER_TU_BY_DEFAULT "Enable per TU ABI insulation by default. To be used by vendors." OFF) |
Shoaib Meenai | 8993753 | 2017-10-04 23:51:57 | [diff] [blame] | 141 | set(LIBCXX_ABI_DEFINES "" CACHE STRING "A semicolon separated list of ABI macros to define in the site config header.") |
Saleem Abdulrasool | e81fcb8 | 2016-08-24 04:22:52 | [diff] [blame] | 142 | option(LIBCXX_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF) |
Louis Dionne | 2d0b4d6 | 2019-03-20 18:16:24 | [diff] [blame] | 143 | set(LIBCXX_LIBCPPABI_VERSION "2" CACHE STRING "Version of libc++abi's ABI to re-export from libc++ when re-exporting is enabled. |
| 144 | Note that this is not related to the version of libc++'s ABI itself!") |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 145 | |
| 146 | # ABI Library options --------------------------------------------------------- |
Eric Fiselier | 1285e4d | 2017-01-03 01:18:48 | [diff] [blame] | 147 | set(LIBCXX_CXX_ABI "default" CACHE STRING |
| 148 | "Specify C++ ABI library to use.") |
Eric Fiselier | 1cd196e | 2017-01-16 20:47:35 | [diff] [blame] | 149 | set(CXXABIS none default libcxxabi libcxxrt libstdc++ libsupc++ vcruntime) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 150 | set_property(CACHE LIBCXX_CXX_ABI PROPERTY STRINGS ;${CXXABIS}) |
| 151 | |
Louis Dionne | bcab951 | 2019-10-01 19:27:38 | [diff] [blame] | 152 | # FIXME: This is a temporary hack to get the buildbots working while D63883 is in flight. |
| 153 | # Without this all the bots fail while building libc++ |
| 154 | if (DEFINED ENV{USER}) |
| 155 | if (("$ENV{USER}" STREQUAL "buildbot") OR (("$ENV{USER}" STREQUAL "llvmbb") OR ("$ENV{USER}" STREQUAL "buildslave"))) |
| 156 | if (LIBCXX_CXX_ABI STREQUAL "libcxxabi" AND NOT DEFINED LIBCXX_CXX_ABI_INCLUDE_PATHS) |
| 157 | message(WARNING "OVERRIDING BUILDBOT CONFIG") |
| 158 | set(LIBCXX_CXX_ABI "default" CACHE STRING "FIXME" FORCE) |
| 159 | endif() |
| 160 | endif() |
| 161 | endif() |
Eric Fiselier | bb90685 | 2015-10-22 20:54:27 | [diff] [blame] | 162 | # Setup the default options if LIBCXX_CXX_ABI is not specified. |
Eric Fiselier | 1285e4d | 2017-01-03 01:18:48 | [diff] [blame] | 163 | if (LIBCXX_CXX_ABI STREQUAL "default") |
Louis Dionne | 80ef2f0 | 2019-08-08 00:28:06 | [diff] [blame] | 164 | find_path( |
| 165 | LIBCXX_LIBCXXABI_INCLUDES_INTERNAL cxxabi.h |
| 166 | PATHS ${LLVM_MAIN_SRC_DIR}/projects/libcxxabi/include |
| 167 | ${LLVM_MAIN_SRC_DIR}/runtimes/libcxxabi/include |
| 168 | ${LLVM_MAIN_SRC_DIR}/../libcxxabi/include |
| 169 | NO_DEFAULT_PATH |
| 170 | NO_CMAKE_FIND_ROOT_PATH |
| 171 | ) |
Shoaib Meenai | 8048b44 | 2017-04-20 23:33:49 | [diff] [blame] | 172 | if (LIBCXX_TARGETING_MSVC) |
| 173 | # FIXME: Figure out how to configure the ABI library on Windows. |
| 174 | set(LIBCXX_CXX_ABI_LIBNAME "vcruntime") |
Louis Dionne | 80ef2f0 | 2019-08-08 00:28:06 | [diff] [blame] | 175 | elseif ((NOT LIBCXX_STANDALONE_BUILD OR HAVE_LIBCXXABI) AND |
| 176 | IS_DIRECTORY "${LIBCXX_LIBCXXABI_INCLUDES_INTERNAL}") |
| 177 | set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi") |
| 178 | set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${LIBCXX_LIBCXXABI_INCLUDES_INTERNAL}") |
| 179 | set(LIBCXX_CXX_ABI_INTREE 1) |
Shoaib Meenai | 8048b44 | 2017-04-20 23:33:49 | [diff] [blame] | 180 | elseif (APPLE) |
| 181 | set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi") |
| 182 | set(LIBCXX_CXX_ABI_SYSTEM 1) |
Dimitry Andric | 35479ff | 2018-02-11 22:31:05 | [diff] [blame] | 183 | elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") |
| 184 | set(LIBCXX_CXX_ABI_LIBNAME "libcxxrt") |
| 185 | set(LIBCXX_CXX_ABI_INCLUDE_PATHS "/usr/include/c++/v1") |
Eugene Zelenko | 772d114 | 2016-08-08 18:01:50 | [diff] [blame] | 186 | else() |
Shoaib Meenai | 8048b44 | 2017-04-20 23:33:49 | [diff] [blame] | 187 | set(LIBCXX_CXX_ABI_LIBNAME "default") |
Eugene Zelenko | 772d114 | 2016-08-08 18:01:50 | [diff] [blame] | 188 | endif() |
| 189 | else() |
Eric Fiselier | bb90685 | 2015-10-22 20:54:27 | [diff] [blame] | 190 | set(LIBCXX_CXX_ABI_LIBNAME "${LIBCXX_CXX_ABI}") |
Eugene Zelenko | 772d114 | 2016-08-08 18:01:50 | [diff] [blame] | 191 | endif() |
Eric Fiselier | bb90685 | 2015-10-22 20:54:27 | [diff] [blame] | 192 | |
Louis Dionne | 0c962cb | 2019-03-18 18:18:01 | [diff] [blame] | 193 | option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY |
| 194 | "Use a static copy of the ABI library when linking libc++. |
| 195 | This option cannot be used with LIBCXX_ENABLE_ABI_LINKER_SCRIPT." OFF) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 196 | |
Petr Hosek | 058c04c | 2018-07-24 07:06:17 | [diff] [blame] | 197 | cmake_dependent_option(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY |
| 198 | "Statically link the ABI library to static library" ON |
| 199 | "LIBCXX_ENABLE_STATIC_ABI_LIBRARY;LIBCXX_ENABLE_STATIC" OFF) |
| 200 | |
| 201 | cmake_dependent_option(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY |
| 202 | "Statically link the ABI library to shared library" ON |
Martin Storsjo | 3d2e5432 | 2018-08-14 17:33:10 | [diff] [blame] | 203 | "LIBCXX_ENABLE_STATIC_ABI_LIBRARY;LIBCXX_ENABLE_SHARED" OFF) |
Petr Hosek | 058c04c | 2018-07-24 07:06:17 | [diff] [blame] | 204 | |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 205 | # Generate and install a linker script inplace of libc++.so. The linker script |
Eric Fiselier | 1ab69fc | 2015-10-15 22:41:51 | [diff] [blame] | 206 | # will link libc++ to the correct ABI library. This option is on by default |
Shoaib Meenai | 84904fb | 2017-03-25 03:22:35 | [diff] [blame] | 207 | # on UNIX platforms other than Apple unless 'LIBCXX_ENABLE_STATIC_ABI_LIBRARY' |
Eric Fiselier | 571367e | 2015-10-22 20:50:07 | [diff] [blame] | 208 | # is on. This option is also disabled when the ABI library is not specified |
| 209 | # or is specified to be "none". |
Eric Fiselier | 1ab69fc | 2015-10-15 22:41:51 | [diff] [blame] | 210 | set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF) |
Petr Hosek | 4b59ed4 | 2018-07-26 05:10:24 | [diff] [blame] | 211 | if (LLVM_HAVE_LINK_VERSION_SCRIPT AND NOT LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY |
Eric Fiselier | bb90685 | 2015-10-22 20:54:27 | [diff] [blame] | 212 | AND NOT LIBCXX_CXX_ABI_LIBNAME STREQUAL "none" |
Eric Fiselier | 1285e4d | 2017-01-03 01:18:48 | [diff] [blame] | 213 | AND NOT LIBCXX_CXX_ABI_LIBNAME STREQUAL "default" |
Asiri Rathnayake | 28383a4 | 2016-05-14 23:58:11 | [diff] [blame] | 214 | AND PYTHONINTERP_FOUND |
| 215 | AND LIBCXX_ENABLE_SHARED) |
Eric Fiselier | 1ab69fc | 2015-10-15 22:41:51 | [diff] [blame] | 216 | set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE ON) |
| 217 | endif() |
| 218 | |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 219 | option(LIBCXX_ENABLE_ABI_LINKER_SCRIPT |
Eric Fiselier | 1ab69fc | 2015-10-15 22:41:51 | [diff] [blame] | 220 | "Use and install a linker script for the given ABI library" |
Eric Fiselier | a15785b | 2015-10-15 23:04:54 | [diff] [blame] | 221 | ${ENABLE_LINKER_SCRIPT_DEFAULT_VALUE}) |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 222 | |
Eric Fiselier | 3499263 | 2017-03-02 19:35:33 | [diff] [blame] | 223 | option(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS |
| 224 | "Build libc++ with definitions for operator new/delete. This option can |
Louis Dionne | 17a75f7 | 2019-04-18 14:47:46 | [diff] [blame] | 225 | be used to disable the definitions when libc++abi is expected to provide |
| 226 | them" ON) |
Eric Fiselier | 3499263 | 2017-03-02 19:35:33 | [diff] [blame] | 227 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 228 | # Build libc++abi with libunwind. We need this option to determine whether to |
| 229 | # link with libunwind or libgcc_s while running the test cases. |
| 230 | option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF) |
Petr Hosek | b494288 | 2017-02-09 02:19:43 | [diff] [blame] | 231 | option(LIBCXXABI_ENABLE_STATIC_UNWINDER "Statically link the LLVM unwinder." OFF) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 232 | |
| 233 | # Target options -------------------------------------------------------------- |
| 234 | option(LIBCXX_BUILD_32_BITS "Build 32 bit libc++." ${LLVM_BUILD_32_BITS}) |
Petr Hosek | 6fd4e7f | 2019-02-04 20:02:26 | [diff] [blame] | 235 | set(LIBCXX_TARGET_TRIPLE "" CACHE STRING "Use alternate target triple.") |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 236 | set(LIBCXX_SYSROOT "" CACHE STRING "Use alternate sysroot.") |
| 237 | set(LIBCXX_GCC_TOOLCHAIN "" CACHE STRING "Use alternate GCC toolchain.") |
| 238 | |
| 239 | # Feature options ------------------------------------------------------------- |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 240 | option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON) |
| 241 | option(LIBCXX_ENABLE_RTTI "Use run time type information." ON) |
Ed Schouten | 97fdea6 | 2015-03-12 15:44:39 | [diff] [blame] | 242 | option(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE "Build libc++ with support for the global filesystem namespace." ON) |
Ed Schouten | f4ac884 | 2015-03-26 14:35:46 | [diff] [blame] | 243 | option(LIBCXX_ENABLE_STDIN "Build libc++ with support for stdin/std::cin." ON) |
| 244 | option(LIBCXX_ENABLE_STDOUT "Build libc++ with support for stdout/std::cout." ON) |
Eric Fiselier | b9f9973 | 2014-12-06 21:02:58 | [diff] [blame] | 245 | option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON) |
Ed Schouten | e0cf3b9 | 2015-06-24 08:44:38 | [diff] [blame] | 246 | option(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS "Build libc++ with support for thread-unsafe C functions" ON) |
Eric Fiselier | b9f9973 | 2014-12-06 21:02:58 | [diff] [blame] | 247 | option(LIBCXX_ENABLE_MONOTONIC_CLOCK |
| 248 | "Build libc++ with support for a monotonic clock. |
Jonathan Roelofs | 91b3a5e | 2015-08-24 21:20:07 | [diff] [blame] | 249 | This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON) |
Vasileios Kalintiris | 8c58e92 | 2015-11-09 10:21:04 | [diff] [blame] | 250 | option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF) |
Ben Craig | b9599b1 | 2016-05-25 17:40:09 | [diff] [blame] | 251 | option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF) |
Martin Storsjo | bf02a09 | 2018-01-05 20:48:29 | [diff] [blame] | 252 | option(LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32 thread API" OFF) |
Asiri Rathnayake | 8c2bf45 | 2016-09-11 21:46:40 | [diff] [blame] | 253 | option(LIBCXX_HAS_EXTERNAL_THREAD_API |
| 254 | "Build libc++ with an externalized threading API. |
| 255 | This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF) |
Eric Fiselier | 00f6bea | 2017-01-06 20:05:40 | [diff] [blame] | 256 | option(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY |
| 257 | "Build libc++ with an externalized threading library. |
| 258 | This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON" OFF) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 259 | |
| 260 | # Misc options ---------------------------------------------------------------- |
Eric Fiselier | 6fb770a | 2015-10-10 03:34:52 | [diff] [blame] | 261 | # FIXME: Turn -pedantic back ON. It is currently off because it warns |
| 262 | # about #include_next which is used everywhere. |
| 263 | option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 264 | option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) |
Saleem Abdulrasool | 6fe3073 | 2016-07-12 14:39:13 | [diff] [blame] | 265 | option(LIBCXX_DISABLE_MACRO_CONFLICT_WARNINGS "Disable #warnings about conflicting macros." OFF) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 266 | |
Eric Fiselier | 78fdf2d | 2015-03-31 04:15:45 | [diff] [blame] | 267 | option(LIBCXX_GENERATE_COVERAGE "Enable generating code coverage." OFF) |
| 268 | set(LIBCXX_COVERAGE_LIBRARY "" CACHE STRING |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 269 | "The Profile-rt library used to build with code coverage") |
| 270 | |
Eric Fiselier | d77135f | 2015-08-26 20:18:21 | [diff] [blame] | 271 | # Don't allow a user to accidentally overwrite the system libc++ installation on Darwin. |
| 272 | # If the user specifies -DCMAKE_INSTALL_PREFIX=/usr the install rules for libc++ |
| 273 | # will not be generated and a warning will be issued. |
| 274 | option(LIBCXX_OVERRIDE_DARWIN_INSTALL "Enable overwriting darwins libc++ installation." OFF) |
| 275 | mark_as_advanced(LIBCXX_OVERRIDE_DARWIN_INSTALL) # Don't show this option by default. |
| 276 | |
| 277 | if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT LIBCXX_OVERRIDE_DARWIN_INSTALL) |
| 278 | if ("${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr") |
| 279 | message(WARNING "Disabling libc++ install rules because installation would " |
| 280 | "overwrite the systems installation. Configure with " |
| 281 | "-DLIBCXX_OVERRIDE_DARWIN_INSTALL=ON to suppress this behaviour.") |
| 282 | mark_as_advanced(CLEAR LIBCXX_OVERRIDE_DARWIN_INSTALL) # Show the override option. |
| 283 | set(LIBCXX_INSTALL_HEADERS OFF) |
| 284 | set(LIBCXX_INSTALL_LIBRARY OFF) |
| 285 | endif() |
| 286 | endif() |
| 287 | |
Eric Fiselier | 6627c70 | 2015-12-16 23:41:05 | [diff] [blame] | 288 | set(LIBCXX_CONFIGURE_IDE_DEFAULT OFF) |
| 289 | if (XCODE OR MSVC_IDE) |
| 290 | set(LIBCXX_CONFIGURE_IDE_DEFAULT ON) |
| 291 | endif() |
| 292 | option(LIBCXX_CONFIGURE_IDE "Configure libcxx for use within an IDE" |
| 293 | ${LIBCXX_CONFIGURE_IDE_DEFAULT}) |
| 294 | |
Petr Hosek | a2685cd | 2019-01-06 06:14:31 | [diff] [blame] | 295 | option(LIBCXX_HERMETIC_STATIC_LIBRARY |
| 296 | "Do not export any symbols from the static library." OFF) |
| 297 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 298 | #=============================================================================== |
| 299 | # Check option configurations |
| 300 | #=============================================================================== |
| 301 | |
| 302 | # Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON only when |
| 303 | # LIBCXX_ENABLE_THREADS is on. |
| 304 | if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_ENABLE_MONOTONIC_CLOCK) |
| 305 | message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF" |
| 306 | " when LIBCXX_ENABLE_THREADS is also set to OFF.") |
Eric Fiselier | 0058c80 | 2014-08-18 05:03:46 | [diff] [blame] | 307 | endif() |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 308 | |
Asiri Rathnayake | 205d7d3 | 2017-01-03 12:59:50 | [diff] [blame] | 309 | if(NOT LIBCXX_ENABLE_THREADS) |
| 310 | if(LIBCXX_HAS_PTHREAD_API) |
| 311 | message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON" |
| 312 | " when LIBCXX_ENABLE_THREADS is also set to ON.") |
| 313 | endif() |
| 314 | if(LIBCXX_HAS_EXTERNAL_THREAD_API) |
| 315 | message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set to ON" |
| 316 | " when LIBCXX_ENABLE_THREADS is also set to ON.") |
| 317 | endif() |
Eric Fiselier | 00f6bea | 2017-01-06 20:05:40 | [diff] [blame] | 318 | if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY) |
| 319 | message(FATAL_ERROR "LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY can only be set " |
| 320 | "to ON when LIBCXX_ENABLE_THREADS is also set to ON.") |
| 321 | endif() |
Martin Storsjo | bf02a09 | 2018-01-05 20:48:29 | [diff] [blame] | 322 | if (LIBCXX_HAS_WIN32_THREAD_API) |
| 323 | message(FATAL_ERROR "LIBCXX_HAS_WIN32_THREAD_API can only be set to ON" |
| 324 | " when LIBCXX_ENABLE_THREADS is also set to ON.") |
| 325 | endif() |
Eric Fiselier | 00f6bea | 2017-01-06 20:05:40 | [diff] [blame] | 326 | |
| 327 | endif() |
| 328 | |
Asiri Rathnayake | b71c899 | 2017-01-09 10:38:56 | [diff] [blame] | 329 | if (LIBCXX_HAS_EXTERNAL_THREAD_API) |
| 330 | if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY) |
| 331 | message(FATAL_ERROR "The options LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY and " |
| 332 | "LIBCXX_HAS_EXTERNAL_THREAD_API cannot both be ON at " |
| 333 | "the same time") |
| 334 | endif() |
| 335 | if (LIBCXX_HAS_PTHREAD_API) |
| 336 | message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API" |
| 337 | "and LIBCXX_HAS_PTHREAD_API cannot be both" |
| 338 | "set to ON at the same time.") |
| 339 | endif() |
Martin Storsjo | bf02a09 | 2018-01-05 20:48:29 | [diff] [blame] | 340 | if (LIBCXX_HAS_WIN32_THREAD_API) |
| 341 | message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API" |
| 342 | "and LIBCXX_HAS_WIN32_THREAD_API cannot be both" |
| 343 | "set to ON at the same time.") |
| 344 | endif() |
| 345 | endif() |
| 346 | |
| 347 | if (LIBCXX_HAS_PTHREAD_API) |
| 348 | if (LIBCXX_HAS_WIN32_THREAD_API) |
| 349 | message(FATAL_ERROR "The options LIBCXX_HAS_PTHREAD_API" |
| 350 | "and LIBCXX_HAS_WIN32_THREAD_API cannot be both" |
| 351 | "set to ON at the same time.") |
| 352 | endif() |
Asiri Rathnayake | 8c2bf45 | 2016-09-11 21:46:40 | [diff] [blame] | 353 | endif() |
| 354 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 355 | # Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE |
| 356 | # is ON. |
| 357 | if (LLVM_USE_SANITIZER AND LIBCXX_GENERATE_COVERAGE) |
| 358 | message(FATAL_ERROR "LLVM_USE_SANITIZER cannot be used with LIBCXX_GENERATE_COVERAGE") |
| 359 | endif() |
| 360 | |
| 361 | # Set LIBCXX_BUILD_32_BITS to (LIBCXX_BUILD_32_BITS OR LLVM_BUILD_32_BITS) |
| 362 | # and check that we can build with 32 bits if requested. |
| 363 | if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32) |
| 364 | if (LIBCXX_BUILD_32_BITS AND NOT LLVM_BUILD_32_BITS) # Don't duplicate the output from LLVM |
| 365 | message(STATUS "Building 32 bits executables and libraries.") |
| 366 | endif() |
| 367 | elseif(LIBCXX_BUILD_32_BITS) |
| 368 | message(FATAL_ERROR "LIBCXX_BUILD_32_BITS=ON is not supported on this platform.") |
| 369 | endif() |
| 370 | |
Louis Dionne | 9760737 | 2019-03-25 14:56:29 | [diff] [blame] | 371 | # Warn users that LIBCXX_ENABLE_STATIC_ABI_LIBRARY is an experimental option. |
Eric Fiselier | 0357171 | 2015-03-03 15:59:51 | [diff] [blame] | 372 | if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) |
Louis Dionne | 9760737 | 2019-03-25 14:56:29 | [diff] [blame] | 373 | message(WARNING "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is an experimental option") |
Eric Fiselier | bf58c8e | 2016-11-18 19:53:45 | [diff] [blame] | 374 | if (LIBCXX_ENABLE_STATIC AND NOT PYTHONINTERP_FOUND) |
| 375 | message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY requires python but it was not found.") |
| 376 | endif() |
Eric Fiselier | 0357171 | 2015-03-03 15:59:51 | [diff] [blame] | 377 | endif() |
| 378 | |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 379 | if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT) |
| 380 | if (APPLE) |
| 381 | message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT cannot be used on APPLE targets") |
| 382 | endif() |
Asiri Rathnayake | 28383a4 | 2016-05-14 23:58:11 | [diff] [blame] | 383 | if (NOT LIBCXX_ENABLE_SHARED) |
| 384 | message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT is only available for shared library builds.") |
| 385 | endif() |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 386 | endif() |
| 387 | |
Petr Hosek | 4b59ed4 | 2018-07-26 05:10:24 | [diff] [blame] | 388 | if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT) |
Eric Fiselier | 8241405 | 2015-10-14 19:54:03 | [diff] [blame] | 389 | message(FATAL_ERROR "Conflicting options given. |
| 390 | LIBCXX_ENABLE_STATIC_ABI_LIBRARY cannot be specified with |
| 391 | LIBCXX_ENABLE_ABI_LINKER_SCRIPT") |
| 392 | endif() |
| 393 | |
Vasileios Kalintiris | 8c58e92 | 2015-11-09 10:21:04 | [diff] [blame] | 394 | if (LIBCXX_HAS_MUSL_LIBC AND NOT LIBCXX_INSTALL_SUPPORT_HEADERS) |
| 395 | message(FATAL_ERROR "LIBCXX_INSTALL_SUPPORT_HEADERS can not be turned off" |
| 396 | "when building for Musl with LIBCXX_HAS_MUSL_LIBC.") |
| 397 | endif() |
| 398 | |
Shoaib Meenai | a4a3d40 | 2017-10-05 02:18:08 | [diff] [blame] | 399 | if (LIBCXX_ABI_FORCE_ITANIUM AND LIBCXX_ABI_FORCE_MICROSOFT) |
| 400 | message(FATAL_ERROR "Only one of LIBCXX_ABI_FORCE_ITANIUM and LIBCXX_ABI_FORCE_MICROSOFT can be specified.") |
Shoaib Meenai | d456385 | 2017-10-04 23:44:38 | [diff] [blame] | 401 | endif () |
| 402 | |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 403 | #=============================================================================== |
| 404 | # Configure System |
| 405 | #=============================================================================== |
| 406 | |
Eric Fiselier | a78a267 | 2014-12-20 03:16:55 | [diff] [blame] | 407 | set(LIBCXX_COMPILER ${CMAKE_CXX_COMPILER}) |
| 408 | set(LIBCXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 409 | set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
Eric Fiselier | 1cd196e | 2017-01-16 20:47:35 | [diff] [blame] | 410 | set(LIBCXX_BINARY_INCLUDE_DIR "${LIBCXX_BINARY_DIR}/include/c++build") |
Petr Hosek | 887f26d | 2018-06-28 03:11:52 | [diff] [blame] | 411 | |
| 412 | string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION |
| 413 | ${PACKAGE_VERSION}) |
| 414 | |
| 415 | if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) |
Petr Hosek | 81f433b | 2019-05-22 21:08:33 | [diff] [blame] | 416 | set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) |
| 417 | set(LIBCXX_HEADER_DIR ${LLVM_BINARY_DIR}) |
| 418 | set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) |
| 419 | if(LIBCXX_LIBDIR_SUBDIR) |
| 420 | string(APPEND LIBCXX_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR}) |
| 421 | string(APPEND LIBCXX_INSTALL_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR}) |
| 422 | endif() |
Petr Hosek | 887f26d | 2018-06-28 03:11:52 | [diff] [blame] | 423 | elseif(LLVM_LIBRARY_OUTPUT_INTDIR) |
Jonas Hahnfeld | 98a7f27 | 2017-05-04 06:02:50 | [diff] [blame] | 424 | set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) |
Petr Hosek | f8f2a78 | 2018-07-24 15:49:29 | [diff] [blame] | 425 | set(LIBCXX_HEADER_DIR ${LLVM_BINARY_DIR}) |
Petr Hosek | 81f433b | 2019-05-22 21:08:33 | [diff] [blame] | 426 | set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX}) |
Jonas Hahnfeld | 98a7f27 | 2017-05-04 06:02:50 | [diff] [blame] | 427 | else() |
| 428 | set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) |
Petr Hosek | 81f433b | 2019-05-22 21:08:33 | [diff] [blame] | 429 | set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX}) |
Jonas Hahnfeld | 98a7f27 | 2017-05-04 06:02:50 | [diff] [blame] | 430 | endif() |
Petr Hosek | 887f26d | 2018-06-28 03:11:52 | [diff] [blame] | 431 | |
Eric Fiselier | 1cd196e | 2017-01-16 20:47:35 | [diff] [blame] | 432 | file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}") |
Eric Fiselier | a78a267 | 2014-12-20 03:16:55 | [diff] [blame] | 433 | |
Petr Hosek | 81f433b | 2019-05-22 21:08:33 | [diff] [blame] | 434 | set(LIBCXX_INSTALL_PREFIX "" CACHE STRING "Define libc++ destination prefix.") |
| 435 | set(LIBCXX_INSTALL_HEADER_PREFIX "" CACHE STRING "Define libc++ header destination prefix.") |
Petr Hosek | 510e70f | 2017-07-11 02:39:50 | [diff] [blame] | 436 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 437 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) |
| 438 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) |
Shoaib Meenai | 6170765 | 2017-04-13 16:27:38 | [diff] [blame] | 439 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 440 | |
Eric Fiselier | 5aedca9 | 2014-11-15 06:26:30 | [diff] [blame] | 441 | # Declare libc++ configuration variables. |
| 442 | # They are intended for use as follows: |
| 443 | # LIBCXX_CXX_FLAGS: General flags for both the compiler and linker. |
| 444 | # LIBCXX_COMPILE_FLAGS: Compile only flags. |
| 445 | # LIBCXX_LINK_FLAGS: Linker only flags. |
Eric Fiselier | 054fc4c | 2016-10-09 21:34:03 | [diff] [blame] | 446 | # LIBCXX_LIBRARIES: libraries libc++ is linked to. |
Eric Fiselier | 5aedca9 | 2014-11-15 06:26:30 | [diff] [blame] | 447 | set(LIBCXX_COMPILE_FLAGS "") |
| 448 | set(LIBCXX_LINK_FLAGS "") |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 449 | set(LIBCXX_LIBRARIES "") |
Eric Fiselier | 5aedca9 | 2014-11-15 06:26:30 | [diff] [blame] | 450 | |
Eric Fiselier | a4f2460 | 2016-06-02 01:10:08 | [diff] [blame] | 451 | # Include macros for adding and removing libc++ flags. |
| 452 | include(HandleLibcxxFlags) |
| 453 | |
| 454 | # Target flags ================================================================ |
| 455 | # These flags get added to CMAKE_CXX_FLAGS and CMAKE_C_FLAGS so that |
| 456 | # 'config-ix' use them during feature checks. It also adds them to both |
| 457 | # 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS' |
| 458 | add_target_flags_if(LIBCXX_BUILD_32_BITS "-m32") |
Petr Hosek | 6fd4e7f | 2019-02-04 20:02:26 | [diff] [blame] | 459 | |
| 460 | if(LIBCXX_TARGET_TRIPLE) |
| 461 | add_target_flags("--target=${LIBCXX_TARGET_TRIPLE}") |
| 462 | elseif(CMAKE_CXX_COMPILER_TARGET) |
| 463 | set(LIBCXX_TARGET_TRIPLE "${CMAKE_CXX_COMPILER_TARGET}") |
| 464 | endif() |
| 465 | if(LIBCXX_SYSROOT) |
| 466 | add_target_flags("--sysroot=${LIBCXX_SYSROOT}") |
| 467 | elseif(CMAKE_SYSROOT) |
| 468 | set(LIBCXX_SYSROOT "${CMAKE_SYSROOT}") |
| 469 | endif() |
| 470 | if(LIBCXX_GCC_TOOLCHAIN) |
| 471 | add_target_flags("--gcc-toolchain=${LIBCXX_GCC_TOOLCHAIN}") |
| 472 | elseif(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN) |
| 473 | set(LIBCXX_GCC_TOOLCHAIN "${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}") |
| 474 | endif() |
| 475 | |
| 476 | if(LIBCXX_TARGET_TRIPLE) |
Eric Fiselier | 79ff8f03 | 2016-11-13 22:27:00 | [diff] [blame] | 477 | set(TARGET_TRIPLE "${LIBCXX_TARGET_TRIPLE}") |
| 478 | endif() |
Eric Fiselier | a4f2460 | 2016-06-02 01:10:08 | [diff] [blame] | 479 | |
Eric Fiselier | 382338d | 2014-11-15 17:25:23 | [diff] [blame] | 480 | # Configure compiler. |
| 481 | include(config-ix) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 482 | |
Eric Fiselier | 78fdf2d | 2015-03-31 04:15:45 | [diff] [blame] | 483 | # Configure coverage options. |
| 484 | if (LIBCXX_GENERATE_COVERAGE) |
| 485 | include(CodeCoverage) |
| 486 | set(CMAKE_BUILD_TYPE "COVERAGE" CACHE STRING "" FORCE) |
| 487 | endif() |
Eric Fiselier | 382338d | 2014-11-15 17:25:23 | [diff] [blame] | 488 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 489 | string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) |
Eric Fiselier | 7e3ee09 | 2017-01-14 07:54:39 | [diff] [blame] | 490 | if (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") |
| 491 | set(LIBCXX_DEBUG_BUILD ON) |
| 492 | else() |
| 493 | set(LIBCXX_DEBUG_BUILD OFF) |
| 494 | endif() |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 495 | |
Eric Fiselier | 382338d | 2014-11-15 17:25:23 | [diff] [blame] | 496 | #=============================================================================== |
| 497 | # Setup Compiler Flags |
| 498 | #=============================================================================== |
| 499 | |
JF Bastien | fc45f32 | 2016-03-05 14:22:02 | [diff] [blame] | 500 | include(HandleLibCXXABI) # Setup the ABI library flags |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 501 | |
Michal Gorny | ecc8864 | 2016-09-27 07:55:26 | [diff] [blame] | 502 | if (NOT LIBCXX_STANDALONE_BUILD) |
| 503 | # Remove flags that may have snuck in. |
| 504 | remove_flags(-DNDEBUG -UNDEBUG -D_DEBUG |
Eric Fiselier | 6dede18 | 2017-01-17 23:27:56 | [diff] [blame] | 505 | -lc++abi) |
Michal Gorny | ecc8864 | 2016-09-27 07:55:26 | [diff] [blame] | 506 | endif() |
| 507 | remove_flags(-stdlib=libc++ -stdlib=libstdc++) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 508 | |
Eric Fiselier | cc1f65c | 2017-01-14 06:06:47 | [diff] [blame] | 509 | # FIXME: Remove all debug flags and flags that change which Windows |
| 510 | # default libraries are linked. Currently we only support linking the |
| 511 | # non-debug DLLs |
Eric Fiselier | 7e3ee09 | 2017-01-14 07:54:39 | [diff] [blame] | 512 | remove_flags("/D_DEBUG" "/MTd" "/MDd" "/MT" "/Md") |
Eric Fiselier | cc1f65c | 2017-01-14 06:06:47 | [diff] [blame] | 513 | |
Shoaib Meenai | f88923d | 2017-03-25 03:42:20 | [diff] [blame] | 514 | # FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC. |
Eric Fiselier | f2be7c2 | 2015-10-15 20:27:15 | [diff] [blame] | 515 | # Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors |
Shoaib Meenai | f88923d | 2017-03-25 03:42:20 | [diff] [blame] | 516 | # so they don't get transformed into -Wno and -errors respectively. |
Eric Fiselier | f2be7c2 | 2015-10-15 20:27:15 | [diff] [blame] | 517 | remove_flags(-Wno-pedantic -pedantic-errors -pedantic) |
Eric Fiselier | f4bfd7c | 2015-10-13 23:56:33 | [diff] [blame] | 518 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 519 | # Required flags ============================================================== |
Louis Dionne | 925d9d2 | 2019-10-02 20:07:01 | [diff] [blame] | 520 | function(cxx_add_basic_build_flags target) |
Saleem Abdulrasol | 5ce2c6d | 2019-11-02 19:06:17 | [diff] [blame] | 521 | if(LIBCXX_HAS_MUSL_LIBC OR LIBCXX_TARGETING_CLANG_CL) |
| 522 | # musl's pthread implementations uses volatile types in their structs which |
| 523 | # is not a constexpr in C++11 but is in C++14, so we use C++14 with musl. |
| 524 | set_target_properties(${target} PROPERTIES |
| 525 | CXX_STANDARD 14 |
| 526 | CXX_STANDARD_REQUIRED YES |
| 527 | CXX_EXTENSIONS NO) |
Louis Dionne | 925d9d2 | 2019-10-02 20:07:01 | [diff] [blame] | 528 | else() |
Saleem Abdulrasol | 5ce2c6d | 2019-11-02 19:06:17 | [diff] [blame] | 529 | set_target_properties(${target} PROPERTIES |
| 530 | CXX_STANDARD 11 |
| 531 | CXX_STANDARD_REQUIRED YES |
| 532 | CXX_EXTENSIONS NO) |
Louis Dionne | 925d9d2 | 2019-10-02 20:07:01 | [diff] [blame] | 533 | endif() |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 534 | |
Louis Dionne | 925d9d2 | 2019-10-02 20:07:01 | [diff] [blame] | 535 | # On all systems the system c++ standard library headers need to be excluded. |
| 536 | # MSVC only has -X, which disables all default includes; including the crt. |
| 537 | # Thus, we do nothing and hope we don't accidentally include any of the C++ |
| 538 | # headers |
| 539 | target_add_compile_flags_if_supported(${target} PUBLIC -nostdinc++) |
Eric Fiselier | ff16b9a | 2015-07-29 21:07:28 | [diff] [blame] | 540 | |
Louis Dionne | 925d9d2 | 2019-10-02 20:07:01 | [diff] [blame] | 541 | # Hide all inline function definitions which have not explicitly been marked |
| 542 | # visible. This prevents new definitions for inline functions from appearing in |
| 543 | # the dylib when get ODR used by another function. |
| 544 | target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility-inlines-hidden) |
Eric Fiselier | 10b12f0 | 2016-10-25 19:43:44 | [diff] [blame] | 545 | |
Louis Dionne | 925d9d2 | 2019-10-02 20:07:01 | [diff] [blame] | 546 | # Our visibility annotations are not quite right for non-Clang compilers, |
| 547 | # so we end up not exporting all the symbols we should. In the future, we |
| 548 | # can improve the situation by providing an explicit list of exported |
| 549 | # symbols on all compilers. |
| 550 | if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 551 | target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility=hidden) |
| 552 | endif() |
Eric Fiselier | 3ca9185 | 2017-05-25 04:36:24 | [diff] [blame] | 553 | |
Louis Dionne | 925d9d2 | 2019-10-02 20:07:01 | [diff] [blame] | 554 | if (LIBCXX_CONFIGURE_IDE) |
| 555 | # This simply allows IDE to process <experimental/coroutine> |
| 556 | target_add_compile_flags_if_supported(${target} PRIVATE -fcoroutines-ts) |
| 557 | endif() |
Eric Fiselier | f8f31c4 | 2016-09-16 00:00:48 | [diff] [blame] | 558 | |
Louis Dionne | 925d9d2 | 2019-10-02 20:07:01 | [diff] [blame] | 559 | # Let the library headers know they are currently being used to build the |
| 560 | # library. |
| 561 | target_compile_definitions(${target} PRIVATE -D_LIBCPP_BUILDING_LIBRARY) |
Eric Fiselier | 3499263 | 2017-03-02 19:35:33 | [diff] [blame] | 562 | |
Louis Dionne | 925d9d2 | 2019-10-02 20:07:01 | [diff] [blame] | 563 | if (NOT LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS) |
| 564 | target_compile_definitions(${target} PRIVATE -D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS) |
| 565 | endif() |
| 566 | |
| 567 | if (LIBCXX_HAS_COMMENT_LIB_PRAGMA) |
Michał Górny | a9b5fff | 2019-12-02 10:49:20 | [diff] [blame^] | 568 | if (LIBCXX_HAS_PTHREAD_LIB) |
| 569 | target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_PTHREAD_LIB) |
| 570 | endif() |
| 571 | if (LIBCXX_HAS_RT_LIB) |
| 572 | target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_RT_LIB) |
| 573 | endif() |
Louis Dionne | 925d9d2 | 2019-10-02 20:07:01 | [diff] [blame] | 574 | endif() |
| 575 | endfunction() |
Petr Hosek | 789b7f0 | 2019-05-30 04:40:21 | [diff] [blame] | 576 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 577 | # Warning flags =============================================================== |
Louis Dionne | c78c0e0 | 2019-10-02 19:31:30 | [diff] [blame] | 578 | function(cxx_add_warning_flags target) |
| 579 | target_compile_definitions(${target} PUBLIC -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 580 | target_add_compile_flags_if_supported(${target} PRIVATE -Wall -Wextra -W -Wwrite-strings |
| 581 | -Wno-unused-parameter -Wno-long-long |
| 582 | -Werror=return-type -Wextra-semi) |
| 583 | if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") |
| 584 | target_add_compile_flags_if_supported(${target} PRIVATE |
| 585 | -Wno-user-defined-literals |
| 586 | -Wno-covered-switch-default |
| 587 | -Wno-ignored-attributes # FIXME: Caused by _LIBCPP_NODEBUG_TYPE not being supported on older clangs |
| 588 | ) |
Eric Fiselier | 0c8011f | 2018-10-01 01:15:50 | [diff] [blame] | 589 | if (LIBCXX_TARGETING_CLANG_CL) |
Louis Dionne | c78c0e0 | 2019-10-02 19:31:30 | [diff] [blame] | 590 | target_add_compile_flags_if_supported(${target} PRIVATE |
Eric Fiselier | 0c8011f | 2018-10-01 01:15:50 | [diff] [blame] | 591 | -Wno-c++98-compat |
Eric Fiselier | 5e0b8fc | 2018-10-01 01:31:23 | [diff] [blame] | 592 | -Wno-c++98-compat-pedantic |
Eric Fiselier | 0c8011f | 2018-10-01 01:15:50 | [diff] [blame] | 593 | -Wno-c++11-compat |
| 594 | -Wno-undef |
Eric Fiselier | 5e0b8fc | 2018-10-01 01:31:23 | [diff] [blame] | 595 | -Wno-reserved-id-macro |
| 596 | -Wno-gnu-include-next |
| 597 | -Wno-gcc-compat # For ignoring "'diagnose_if' is a clang extension" warnings |
Eric Fiselier | e60359e | 2018-10-01 01:47:23 | [diff] [blame] | 598 | -Wno-zero-as-null-pointer-constant # FIXME: Remove this and fix all occurrences. |
| 599 | -Wno-deprecated-dynamic-exception-spec # For auto_ptr |
| 600 | -Wno-sign-conversion |
| 601 | -Wno-old-style-cast |
| 602 | -Wno-deprecated # FIXME: Remove this and fix all occurrences. |
Eric Fiselier | 0b485f3 | 2018-10-01 01:59:37 | [diff] [blame] | 603 | -Wno-shift-sign-overflow # FIXME: Why do we need this with clang-cl but not clang? |
Eric Fiselier | 1f44fda | 2018-10-01 03:59:05 | [diff] [blame] | 604 | -Wno-double-promotion # FIXME: remove me |
Eric Fiselier | 0c8011f | 2018-10-01 01:15:50 | [diff] [blame] | 605 | ) |
| 606 | endif() |
Louis Dionne | c78c0e0 | 2019-10-02 19:31:30 | [diff] [blame] | 607 | elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") |
| 608 | target_add_compile_flags_if_supported(${target} PRIVATE |
| 609 | -Wno-literal-suffix |
| 610 | -Wno-c++14-compat |
| 611 | -Wno-noexcept-type) |
| 612 | endif() |
| 613 | if (LIBCXX_ENABLE_WERROR) |
| 614 | target_add_compile_flags_if_supported(${target} PRIVATE -Werror) |
| 615 | target_add_compile_flags_if_supported(${target} PRIVATE -WX) |
| 616 | else() |
| 617 | # TODO(EricWF) Remove this. We shouldn't be suppressing errors when -Werror is |
| 618 | # added elsewhere. |
| 619 | target_add_compile_flags_if_supported(${target} PRIVATE -Wno-error) |
| 620 | endif() |
| 621 | if (LIBCXX_ENABLE_PEDANTIC) |
| 622 | target_add_compile_flags_if_supported(${target} PRIVATE -pedantic) |
| 623 | endif() |
| 624 | if (LIBCXX_DISABLE_MACRO_CONFLICT_WARNINGS) |
| 625 | target_compile_definitions(${target} PRIVATE -D_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS) |
| 626 | endif() |
| 627 | endfunction() |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 628 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 629 | # Exception flags ============================================================= |
Louis Dionne | 432ae75 | 2019-10-04 18:03:17 | [diff] [blame] | 630 | function(cxx_add_exception_flags target) |
| 631 | if (LIBCXX_ENABLE_EXCEPTIONS) |
| 632 | # Catches C++ exceptions only and tells the compiler to assume that extern C |
| 633 | # functions never throw a C++ exception. |
| 634 | target_add_compile_flags_if_supported(${target} PUBLIC -EHsc) |
| 635 | else() |
| 636 | target_compile_definitions(${target} PUBLIC -D_LIBCPP_NO_EXCEPTIONS) |
| 637 | target_add_compile_flags_if_supported(${target} PUBLIC -EHs- -EHa-) |
| 638 | target_add_compile_flags_if_supported(${target} PUBLIC -fno-exceptions) |
| 639 | endif() |
| 640 | endfunction() |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 641 | |
| 642 | # RTTI flags ================================================================== |
Louis Dionne | 432ae75 | 2019-10-04 18:03:17 | [diff] [blame] | 643 | function(cxx_add_rtti_flags target) |
| 644 | if (NOT LIBCXX_ENABLE_RTTI) |
| 645 | target_compile_definitions(${target} PUBLIC -D_LIBCPP_NO_RTTI) |
| 646 | target_add_compile_flags_if_supported(${target} PUBLIC -GR-) |
| 647 | target_add_compile_flags_if_supported(${target} PUBLIC -fno-rtti) |
| 648 | endif() |
| 649 | endfunction() |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 650 | |
Asiri Rathnayake | 8c2bf45 | 2016-09-11 21:46:40 | [diff] [blame] | 651 | # Threading flags ============================================================= |
Asiri Rathnayake | b71c899 | 2017-01-09 10:38:56 | [diff] [blame] | 652 | if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY AND LIBCXX_ENABLE_SHARED) |
Asiri Rathnayake | 8c2bf45 | 2016-09-11 21:46:40 | [diff] [blame] | 653 | # Need to allow unresolved symbols if this is to work with shared library builds |
| 654 | if (APPLE) |
| 655 | add_link_flags("-undefined dynamic_lookup") |
| 656 | else() |
| 657 | # Relax this restriction from HandleLLVMOptions |
| 658 | string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") |
| 659 | endif() |
| 660 | endif() |
| 661 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 662 | # Assertion flags ============================================================= |
| 663 | define_if(LIBCXX_ENABLE_ASSERTIONS -UNDEBUG) |
| 664 | define_if_not(LIBCXX_ENABLE_ASSERTIONS -DNDEBUG) |
Eric Fiselier | e49cdfb | 2017-02-04 23:22:28 | [diff] [blame] | 665 | define_if(LIBCXX_ENABLE_ASSERTIONS -D_LIBCPP_DEBUG=0) |
Eric Fiselier | 7e3ee09 | 2017-01-14 07:54:39 | [diff] [blame] | 666 | define_if(LIBCXX_DEBUG_BUILD -D_DEBUG) |
| 667 | if (LIBCXX_ENABLE_ASSERTIONS AND NOT LIBCXX_DEBUG_BUILD) |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 668 | # MSVC doesn't like _DEBUG on release builds. See PR 4379. |
Eric Fiselier | cc1f65c | 2017-01-14 06:06:47 | [diff] [blame] | 669 | define_if_not(LIBCXX_TARGETING_MSVC -D_DEBUG) |
Howard Hinnant | a9f6980 | 2013-02-25 15:50:36 | [diff] [blame] | 670 | endif() |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 671 | |
Eric Fiselier | 194e027 | 2016-10-14 12:56:52 | [diff] [blame] | 672 | # Modules flags =============================================================== |
| 673 | # FIXME The libc++ sources are fundamentally non-modular. They need special |
| 674 | # versions of the headers in order to provide C++03 and legacy ABI definitions. |
| 675 | # NOTE: The public headers can be used with modules in all other contexts. |
Louis Dionne | 432ae75 | 2019-10-04 18:03:17 | [diff] [blame] | 676 | function(cxx_add_module_flags target) |
| 677 | if (LLVM_ENABLE_MODULES) |
| 678 | # Ignore that the rest of the modules flags are now unused. |
Louis Dionne | 13c4254 | 2019-10-04 19:10:56 | [diff] [blame] | 679 | target_add_compile_flags_if_supported(${target} PUBLIC -Wno-unused-command-line-argument) |
| 680 | target_compile_options(${target} PUBLIC -fno-modules) |
Louis Dionne | 432ae75 | 2019-10-04 18:03:17 | [diff] [blame] | 681 | endif() |
| 682 | endfunction() |
Eric Fiselier | 194e027 | 2016-10-14 12:56:52 | [diff] [blame] | 683 | |
Jonathan Roelofs | 91b3a5e | 2015-08-24 21:20:07 | [diff] [blame] | 684 | # Sanitizer flags ============================================================= |
Eric Fiselier | b98aa43 | 2015-07-29 23:46:55 | [diff] [blame] | 685 | |
Eric Fiselier | 02f8e7c35 | 2018-11-13 23:08:31 | [diff] [blame] | 686 | function(get_sanitizer_flags OUT_VAR USE_SANITIZER) |
| 687 | set(SANITIZER_FLAGS) |
| 688 | set(USE_SANITIZER "${USE_SANITIZER}") |
| 689 | # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC. |
| 690 | # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do. |
| 691 | if (USE_SANITIZER AND NOT MSVC) |
| 692 | append_flags_if_supported(SANITIZER_FLAGS "-fno-omit-frame-pointer") |
| 693 | append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only") |
| 694 | |
| 695 | if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND |
| 696 | NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO") |
| 697 | append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only") |
| 698 | endif() |
| 699 | if (USE_SANITIZER STREQUAL "Address") |
| 700 | append_flags(SANITIZER_FLAGS "-fsanitize=address") |
| 701 | elseif (USE_SANITIZER MATCHES "Memory(WithOrigins)?") |
| 702 | append_flags(SANITIZER_FLAGS -fsanitize=memory) |
| 703 | if (USE_SANITIZER STREQUAL "MemoryWithOrigins") |
| 704 | append_flags(SANITIZER_FLAGS "-fsanitize-memory-track-origins") |
| 705 | endif() |
| 706 | elseif (USE_SANITIZER STREQUAL "Undefined") |
| 707 | append_flags(SANITIZER_FLAGS "-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all") |
| 708 | elseif (USE_SANITIZER STREQUAL "Thread") |
| 709 | append_flags(SANITIZER_FLAGS -fsanitize=thread) |
| 710 | else() |
| 711 | message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${USE_SANITIZER}") |
| 712 | endif() |
| 713 | elseif(USE_SANITIZER AND MSVC) |
| 714 | message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.") |
| 715 | endif() |
| 716 | set(${OUT_VAR} "${SANITIZER_FLAGS}" PARENT_SCOPE) |
| 717 | endfunction() |
| 718 | |
Chris Bieneman | 12b134b | 2016-08-18 21:31:51 | [diff] [blame] | 719 | # Configure for sanitizers. If LIBCXX_STANDALONE_BUILD then we have to do |
Eric Fiselier | b98aa43 | 2015-07-29 23:46:55 | [diff] [blame] | 720 | # the flag translation ourselves. Othewise LLVM's CMakeList.txt will handle it. |
Chris Bieneman | 12b134b | 2016-08-18 21:31:51 | [diff] [blame] | 721 | if (LIBCXX_STANDALONE_BUILD) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 722 | set(LLVM_USE_SANITIZER "" CACHE STRING |
| 723 | "Define the sanitizer used to build the library and tests") |
Eric Fiselier | 02f8e7c35 | 2018-11-13 23:08:31 | [diff] [blame] | 724 | endif() |
| 725 | get_sanitizer_flags(SANITIZER_FLAGS "${LLVM_USE_SANITIZER}") |
| 726 | if (LIBCXX_STANDALONE_BUILD AND SANITIZER_FLAGS) |
| 727 | add_flags(${SANITIZER_FLAGS}) |
Eric Fiselier | b98aa43 | 2015-07-29 23:46:55 | [diff] [blame] | 728 | endif() |
Eric Fiselier | f9f796e | 2015-10-13 22:12:02 | [diff] [blame] | 729 | |
Louis Dionne | 3230087 | 2019-10-08 16:26:24 | [diff] [blame] | 730 | # Link system libraries ======================================================= |
| 731 | function(cxx_link_system_libraries target) |
| 732 | target_add_link_flags_if_supported(${target} PRIVATE "-nodefaultlibs") |
| 733 | target_add_compile_flags_if_supported(${target} PRIVATE "/Zl") |
| 734 | target_add_link_flags_if_supported(${target} PRIVATE "/nodefaultlib") |
| 735 | |
| 736 | if (LIBCXX_HAS_SYSTEM_LIB) |
| 737 | target_link_libraries(${target} PRIVATE System) |
| 738 | endif() |
| 739 | |
| 740 | if (LIBCXX_HAS_PTHREAD_LIB) |
| 741 | target_link_libraries(${target} PRIVATE pthread) |
| 742 | endif() |
| 743 | |
| 744 | if (LIBCXX_HAS_C_LIB) |
| 745 | target_link_libraries(${target} PRIVATE c) |
| 746 | endif() |
| 747 | |
| 748 | if (LIBCXX_HAS_M_LIB) |
| 749 | target_link_libraries(${target} PRIVATE m) |
| 750 | endif() |
| 751 | |
| 752 | if (LIBCXX_HAS_RT_LIB) |
| 753 | target_link_libraries(${target} PRIVATE rt) |
| 754 | endif() |
| 755 | |
| 756 | if (LIBCXX_USE_COMPILER_RT) |
| 757 | find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY) |
| 758 | if (LIBCXX_BUILTINS_LIBRARY) |
| 759 | target_link_libraries(${target} PRIVATE "${LIBCXX_BUILTINS_LIBRARY}") |
| 760 | endif() |
| 761 | elseif (LIBCXX_HAS_GCC_S_LIB) |
| 762 | target_link_libraries(${target} PRIVATE gcc_s) |
| 763 | endif() |
| 764 | |
| 765 | if (LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB) |
| 766 | target_link_libraries(${target} PRIVATE atomic) |
| 767 | endif() |
| 768 | |
| 769 | if (MINGW) |
| 770 | target_link_libraries(${target} PRIVATE "${MINGW_LIBRARIES}") |
| 771 | endif() |
| 772 | |
| 773 | if (LIBCXX_TARGETING_MSVC) |
| 774 | if (LIBCXX_DEBUG_BUILD) |
| 775 | set(LIB_SUFFIX "d") |
| 776 | else() |
| 777 | set(LIB_SUFFIX "") |
| 778 | endif() |
| 779 | |
| 780 | target_link_libraries(${target} PRIVATE ucrt${LIB_SUFFIX}) # Universal C runtime |
| 781 | target_link_libraries(${target} PRIVATE vcruntime${LIB_SUFFIX}) # C++ runtime |
| 782 | target_link_libraries(${target} PRIVATE msvcrt${LIB_SUFFIX}) # C runtime startup files |
| 783 | target_link_libraries(${target} PRIVATE msvcprt${LIB_SUFFIX}) # C++ standard library. Required for exception_ptr internals. |
| 784 | # Required for standards-complaint wide character formatting functions |
| 785 | # (e.g. `printfw`/`scanfw`) |
| 786 | target_link_libraries(${target} PRIVATE iso_stdio_wide_specifiers) |
| 787 | endif() |
| 788 | endfunction() |
| 789 | |
Louis Dionne | 925d9d2 | 2019-10-02 20:07:01 | [diff] [blame] | 790 | # Windows-related flags ======================================================= |
| 791 | function(cxx_add_windows_flags target) |
| 792 | if(WIN32 AND NOT MINGW) |
| 793 | target_compile_definitions(${target} PRIVATE |
| 794 | # Ignore the -MSC_VER mismatch, as we may build |
| 795 | # with a different compatibility version. |
| 796 | _ALLOW_MSC_VER_MISMATCH |
| 797 | # Don't check the msvcprt iterator debug levels |
| 798 | # as we will define the iterator types; libc++ |
| 799 | # uses a different macro to identify the debug |
| 800 | # level. |
| 801 | _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH |
| 802 | # We are building the c++ runtime, don't pull in |
| 803 | # msvcprt. |
| 804 | _CRTBLD |
| 805 | # Don't warn on the use of "deprecated" |
| 806 | # "insecure" functions which are standards |
| 807 | # specified. |
| 808 | _CRT_SECURE_NO_WARNINGS |
| 809 | # Use the ISO conforming behaviour for conversion |
| 810 | # in printf, scanf. |
| 811 | _CRT_STDIO_ISO_WIDE_SPECIFIERS) |
| 812 | endif() |
| 813 | endfunction() |
| 814 | |
Eric Fiselier | f9f796e | 2015-10-13 22:12:02 | [diff] [blame] | 815 | # Configuration file flags ===================================================== |
Louis Dionne | f9a5290 | 2018-09-26 08:24:51 | [diff] [blame] | 816 | if (NOT LIBCXX_ABI_VERSION EQUAL 1) |
Evgeniy Stepanov | a66a7b3 | 2015-10-13 23:48:28 | [diff] [blame] | 817 | config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION) |
| 818 | endif() |
Eric Fiselier | fe13c13 | 2018-10-30 21:44:53 | [diff] [blame] | 819 | if (NOT LIBCXX_ABI_NAMESPACE STREQUAL "") |
| 820 | if (NOT LIBCXX_ABI_NAMESPACE MATCHES "__.*") |
Louis Dionne | 3c9063f | 2019-10-24 21:16:37 | [diff] [blame] | 821 | message(FATAL_ERROR "LIBCXX_ABI_NAMESPACE must be a reserved identifier.") |
Eric Fiselier | fe13c13 | 2018-10-30 21:44:53 | [diff] [blame] | 822 | endif() |
| 823 | if (LIBCXX_ABI_NAMESPACE MATCHES "__[0-9]+$") |
| 824 | message(FATAL_ERROR "LIBCXX_ABI_NAMESPACE '${LIBCXX_ABI_NAMESPACE}' is reserved for use by libc++.") |
| 825 | endif() |
| 826 | config_define(${LIBCXX_ABI_NAMESPACE} _LIBCPP_ABI_NAMESPACE) |
| 827 | endif() |
Evgeniy Stepanov | a66a7b3 | 2015-10-13 23:48:28 | [diff] [blame] | 828 | config_define_if(LIBCXX_ABI_UNSTABLE _LIBCPP_ABI_UNSTABLE) |
Shoaib Meenai | a4a3d40 | 2017-10-05 02:18:08 | [diff] [blame] | 829 | config_define_if(LIBCXX_ABI_FORCE_ITANIUM _LIBCPP_ABI_FORCE_ITANIUM) |
| 830 | config_define_if(LIBCXX_ABI_FORCE_MICROSOFT _LIBCPP_ABI_FORCE_MICROSOFT) |
Louis Dionne | 61cd687 | 2018-08-16 12:44:28 | [diff] [blame] | 831 | config_define_if(LIBCXX_HIDE_FROM_ABI_PER_TU_BY_DEFAULT _LIBCPP_HIDE_FROM_ABI_PER_TU_BY_DEFAULT) |
Eric Fiselier | f9f796e | 2015-10-13 22:12:02 | [diff] [blame] | 832 | config_define_if_not(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE) |
| 833 | config_define_if_not(LIBCXX_ENABLE_STDIN _LIBCPP_HAS_NO_STDIN) |
| 834 | config_define_if_not(LIBCXX_ENABLE_STDOUT _LIBCPP_HAS_NO_STDOUT) |
| 835 | config_define_if_not(LIBCXX_ENABLE_THREADS _LIBCPP_HAS_NO_THREADS) |
| 836 | config_define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK _LIBCPP_HAS_NO_MONOTONIC_CLOCK) |
| 837 | config_define_if_not(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS) |
Eric Fiselier | 2405bd6 | 2019-05-29 02:21:37 | [diff] [blame] | 838 | if (NOT LIBCXX_HAS_MERGED_TYPEINFO_NAMES_DEFAULT STREQUAL "") |
| 839 | config_define("${LIBCXX_HAS_MERGED_TYPEINFO_NAMES_DEFAULT}" _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT) |
| 840 | endif() |
Eric Fiselier | f9f796e | 2015-10-13 22:12:02 | [diff] [blame] | 841 | |
Ben Craig | b9599b1 | 2016-05-25 17:40:09 | [diff] [blame] | 842 | config_define_if(LIBCXX_HAS_PTHREAD_API _LIBCPP_HAS_THREAD_API_PTHREAD) |
Asiri Rathnayake | 8c2bf45 | 2016-09-11 21:46:40 | [diff] [blame] | 843 | config_define_if(LIBCXX_HAS_EXTERNAL_THREAD_API _LIBCPP_HAS_THREAD_API_EXTERNAL) |
Martin Storsjo | bf02a09 | 2018-01-05 20:48:29 | [diff] [blame] | 844 | config_define_if(LIBCXX_HAS_WIN32_THREAD_API _LIBCPP_HAS_THREAD_API_WIN32) |
Eric Fiselier | 00f6bea | 2017-01-06 20:05:40 | [diff] [blame] | 845 | config_define_if(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) |
Vasileios Kalintiris | 8c58e92 | 2015-11-09 10:21:04 | [diff] [blame] | 846 | config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC) |
Shoaib Meenai | 492d713 | 2017-10-09 19:25:17 | [diff] [blame] | 847 | config_define_if(LIBCXX_NO_VCRUNTIME _LIBCPP_NO_VCRUNTIME) |
Louis Dionne | 0a06eb9 | 2019-08-05 18:29:14 | [diff] [blame] | 848 | config_define_if(LIBCXX_ENABLE_PARALLEL_ALGORITHMS _LIBCPP_HAS_PARALLEL_ALGORITHMS) |
Vasileios Kalintiris | 8c58e92 | 2015-11-09 10:21:04 | [diff] [blame] | 849 | |
Shoaib Meenai | 8e62812 | 2017-10-04 23:17:12 | [diff] [blame] | 850 | if (LIBCXX_ABI_DEFINES) |
| 851 | set(abi_defines) |
| 852 | foreach (abi_define ${LIBCXX_ABI_DEFINES}) |
| 853 | if (NOT abi_define MATCHES "^_LIBCPP_ABI_") |
| 854 | message(SEND_ERROR "Invalid ABI macro ${abi_define} in LIBCXX_ABI_DEFINES") |
| 855 | endif() |
| 856 | list(APPEND abi_defines "#define ${abi_define}") |
| 857 | endforeach() |
| 858 | string(REPLACE ";" "\n" abi_defines "${abi_defines}") |
| 859 | config_define(${abi_defines} _LIBCPP_ABI_DEFINES) |
| 860 | endif() |
| 861 | |
Eric Fiselier | 5464421 | 2016-09-26 22:19:41 | [diff] [blame] | 862 | # By default libc++ on Windows expects to use a shared library, which requires |
| 863 | # the headers to use DLL import/export semantics. However when building a |
| 864 | # static library only we modify the headers to disable DLL import/export. |
| 865 | if (DEFINED WIN32 AND LIBCXX_ENABLE_STATIC AND NOT LIBCXX_ENABLE_SHARED) |
| 866 | message(STATUS "Generating custom __config for non-DLL Windows build") |
Shoaib Meenai | fc6100c | 2016-12-05 19:40:12 | [diff] [blame] | 867 | config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) |
Eric Fiselier | 5464421 | 2016-09-26 22:19:41 | [diff] [blame] | 868 | endif() |
| 869 | |
Shoaib Meenai | 87fc458 | 2017-09-14 18:23:43 | [diff] [blame] | 870 | set(site_config_path "${LIBCXX_BINARY_DIR}/__config_site") |
Eric Fiselier | f9f796e | 2015-10-13 22:12:02 | [diff] [blame] | 871 | if (LIBCXX_NEEDS_SITE_CONFIG) |
Saleem Abdulrasool | 581bb5b | 2017-01-01 20:20:40 | [diff] [blame] | 872 | configure_file("include/__config_site.in" |
Shoaib Meenai | 87fc458 | 2017-09-14 18:23:43 | [diff] [blame] | 873 | "${site_config_path}" |
Saleem Abdulrasool | 581bb5b | 2017-01-01 20:20:40 | [diff] [blame] | 874 | @ONLY) |
Louis Dionne | c5b74bf | 2019-10-03 17:20:50 | [diff] [blame] | 875 | elseif(EXISTS "${site_config_path}") |
| 876 | message(STATUS "Removing stale site configuration ${site_config_path}") |
| 877 | file(REMOVE "${site_config_path}") |
Eric Fiselier | f9f796e | 2015-10-13 22:12:02 | [diff] [blame] | 878 | endif() |
| 879 | |
Louis Dionne | c5b74bf | 2019-10-03 17:20:50 | [diff] [blame] | 880 | function(cxx_add_config_site target) |
| 881 | if (LIBCXX_NEEDS_SITE_CONFIG) |
| 882 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC") |
| 883 | target_compile_options(${target} PUBLIC "/FI\"${site_config_path}\"") |
| 884 | else() |
Louis Dionne | 9918312 | 2019-11-18 21:27:42 | [diff] [blame] | 885 | target_compile_options(${target} PUBLIC -include "${site_config_path}") |
Louis Dionne | c5b74bf | 2019-10-03 17:20:50 | [diff] [blame] | 886 | endif() |
| 887 | endif() |
| 888 | endfunction() |
| 889 | |
Louis Dionne | fadc84a | 2019-10-04 22:50:23 | [diff] [blame] | 890 | # Setup all common build flags ================================================= |
| 891 | function(cxx_add_common_build_flags target) |
| 892 | cxx_add_basic_build_flags(${target}) |
| 893 | cxx_add_warning_flags(${target}) |
| 894 | cxx_add_windows_flags(${target}) |
| 895 | cxx_add_config_site(${target}) |
| 896 | cxx_add_exception_flags(${target}) |
| 897 | cxx_add_rtti_flags(${target}) |
| 898 | cxx_add_module_flags(${target}) |
Louis Dionne | 3230087 | 2019-10-08 16:26:24 | [diff] [blame] | 899 | cxx_link_system_libraries(${target}) |
Louis Dionne | fadc84a | 2019-10-04 22:50:23 | [diff] [blame] | 900 | endfunction() |
| 901 | |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 902 | #=============================================================================== |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 903 | # Setup Source Code And Tests |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 904 | #=============================================================================== |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 | [diff] [blame] | 905 | include_directories(include) |
Howard Hinnant | 6a0d6ce | 2013-11-15 17:18:57 | [diff] [blame] | 906 | add_subdirectory(include) |
Petr Hosek | f80c4b6 | 2019-05-01 06:40:36 | [diff] [blame] | 907 | add_subdirectory(src) |
Eric Fiselier | b17bb06 | 2015-08-22 19:40:49 | [diff] [blame] | 908 | |
Eric Fiselier | 336a1a6 | 2018-11-14 20:38:46 | [diff] [blame] | 909 | set(LIBCXX_TEST_DEPS "") |
| 910 | |
| 911 | if (LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY) |
| 912 | list(APPEND LIBCXX_TEST_DEPS cxx_experimental) |
| 913 | endif() |
Eric Fiselier | 336a1a6 | 2018-11-14 20:38:46 | [diff] [blame] | 914 | |
| 915 | if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY) |
| 916 | list(APPEND LIBCXX_TEST_DEPS cxx_external_threads) |
| 917 | endif() |
Eric Fiselier | 28349f9 | 2016-11-14 02:43:12 | [diff] [blame] | 918 | |
Eric Fiselier | b08d8b1 | 2016-07-19 23:07:03 | [diff] [blame] | 919 | if (LIBCXX_INCLUDE_BENCHMARKS) |
| 920 | add_subdirectory(benchmarks) |
| 921 | endif() |
Eric Fiselier | d94189d | 2017-03-01 21:53:30 | [diff] [blame] | 922 | |
| 923 | # Create the lit.site.cfg file even when LIBCXX_INCLUDE_TESTS is OFF or |
| 924 | # LLVM_FOUND is OFF. This allows users to run the tests manually using |
| 925 | # LIT without requiring a full LLVM checkout. |
Duncan P. N. Exon Smith | 8e5f040 | 2017-05-03 23:33:54 | [diff] [blame] | 926 | # |
| 927 | # However, since some submission systems strip test/ subdirectories, check for |
| 928 | # it before adding it. |
Zachary Turner | 50105d2 | 2017-09-19 17:19:10 | [diff] [blame] | 929 | |
Duncan P. N. Exon Smith | 8e5f040 | 2017-05-03 23:33:54 | [diff] [blame] | 930 | if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/test") |
| 931 | add_subdirectory(test) |
| 932 | endif() |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 933 | if (LIBCXX_INCLUDE_TESTS) |
Eric Fiselier | 28349f9 | 2016-11-14 02:43:12 | [diff] [blame] | 934 | add_subdirectory(lib/abi) |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 | [diff] [blame] | 935 | endif() |
Eric Fiselier | d94189d | 2017-03-01 21:53:30 | [diff] [blame] | 936 | |
Zachary Turner | 50105d2 | 2017-09-19 17:19:10 | [diff] [blame] | 937 | if (LIBCXX_STANDALONE_BUILD AND EXISTS "${LLVM_MAIN_SRC_DIR}/utils/llvm-lit") |
Petr Hosek | 363c631 | 2017-12-01 03:16:50 | [diff] [blame] | 938 | include(AddLLVM) # for get_llvm_lit_path |
Zachary Turner | 50105d2 | 2017-09-19 17:19:10 | [diff] [blame] | 939 | # Make sure the llvm-lit script is generated into the bin directory, and do |
| 940 | # it after adding all tests, since the generated script will only work |
| 941 | # correctly discovered tests against test locations from the source tree that |
| 942 | # have already been discovered. |
| 943 | add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit |
| 944 | ${CMAKE_CURRENT_BINARY_DIR}/llvm-lit) |
| 945 | endif() |
| 946 | |
Eric Fiselier | b17bb06 | 2015-08-22 19:40:49 | [diff] [blame] | 947 | if (LIBCXX_INCLUDE_DOCS) |
| 948 | add_subdirectory(docs) |
| 949 | endif() |