blob: 9c16dbed52426179ea52a82767ed3d0f6f7b131d [file] [log] [blame]
Michael J. Spencer626916f2010-12-10 19:47:541# See www/CMake.html for instructions on how to build libcxx with CMake.
2
3#===============================================================================
4# Setup Project
5#===============================================================================
Chris Bienemancad86ff2016-05-31 20:21:526cmake_minimum_required(VERSION 3.4.3)
Michael J. Spencer626916f2010-12-10 19:47:547
Eric Fiseliere9d4b232015-01-26 21:56:458if(POLICY CMP0042)
9 cmake_policy(SET CMP0042 NEW) # Set MACOSX_RPATH=YES by default
10endif()
Eric Fiseliereb6e2ea2015-07-30 22:30:3411if(POLICY CMP0022)
12 cmake_policy(SET CMP0022 NEW) # Required when interacting with LLVM and Clang
13endif()
14
Michael J. Spencer626916f2010-12-10 19:47:5415# Add path for custom modules
16set(CMAKE_MODULE_PATH
Michael J. Spencer626916f2010-12-10 19:47:5417 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
18 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
Eric Fiselierce5695f2015-12-30 03:39:0319 ${CMAKE_MODULE_PATH}
Michael J. Spencer626916f2010-12-10 19:47:5420 )
21
Eric Fiselier5e000c62016-11-14 02:43:1222if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
Saleem Abdulrasool7adfa032016-02-08 03:50:1823 project(libcxx CXX C)
24
25 set(PACKAGE_NAME libcxx)
Shoaib Meenai5b0087f2017-03-25 03:12:3726 set(PACKAGE_VERSION 5.0.0svn)
Saleem Abdulrasool7adfa032016-02-08 03:50:1827 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
28 set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org")
Eric Fiselier5e000c62016-11-14 02:43:1229
30 # Find the LLVM sources and simulate LLVM CMake options.
31 include(HandleOutOfTreeLLVM)
Eugene Zelenko96f10172016-08-08 18:01:5032endif()
Saleem Abdulrasool7adfa032016-02-08 03:50:1833
Petr Hosek3508e7a2017-01-16 00:33:0734if (LIBCXX_STANDALONE_BUILD)
35 include(FindPythonInterp)
36 if( NOT PYTHONINTERP_FOUND )
37 message(WARNING "Failed to find python interpreter. "
38 "The libc++ test suite will be disabled.")
39 set(LLVM_INCLUDE_TESTS OFF)
40 endif()
41endif()
42
Saleem Abdulrasool7adfa032016-02-08 03:50:1843# Require out of source build.
44include(MacroEnsureOutOfSourceBuild)
45MACRO_ENSURE_OUT_OF_SOURCE_BUILD(
46 "${PROJECT_NAME} requires an out of source build. Please create a separate
47 build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there."
48 )
49
Eric Fiselierfdd3c912017-01-14 06:06:4750if (MSVC)
51 set(LIBCXX_TARGETING_MSVC ON)
52else()
53 set(LIBCXX_TARGETING_MSVC OFF)
54endif()
55
Michael J. Spencer626916f2010-12-10 19:47:5456#===============================================================================
57# Setup CMake Options
58#===============================================================================
Eric Fiselier01609af2016-09-07 01:15:1059include(CMakeDependentOption)
Eric Fiselierc51e0d22017-03-11 03:24:1860include(HandleCompilerRT)
Michael J. Spencer626916f2010-12-10 19:47:5461
Eric Fiseliereb6e2ea2015-07-30 22:30:3462# Basic options ---------------------------------------------------------------
Eric Fiselierb89eba02017-02-04 23:22:2863option(LIBCXX_ENABLE_ASSERTIONS "Enable assertions independent of build mode." OFF)
Eric Fiseliereb6e2ea2015-07-30 22:30:3464option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON)
Petr Hosekb640da02016-08-08 22:57:2565option(LIBCXX_ENABLE_STATIC "Build libc++ as a static library." ON)
Eric Fiselier5e4698c2016-05-03 21:30:1866option(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY "Build libc++experimental.a" ON)
Eric Fiselier6e9a6942016-06-17 19:46:4067option(LIBCXX_ENABLE_FILESYSTEM
68 "Build filesystem as part of libc++experimental.a" ${LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY})
Eric Fiseliereb6e2ea2015-07-30 22:30:3469option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS})
Eric Fiselier2d2f0c02016-10-30 22:53:0070
Eric Fiselier2d2f0c02016-10-30 22:53:0071# Benchmark options -----------------------------------------------------------
Eric Fiselier0a799bd2016-08-29 19:50:4972option(LIBCXX_INCLUDE_BENCHMARKS "Build the libc++ benchmarks and their dependancies" ON)
Eric Fiselier2d2f0c02016-10-30 22:53:0073set(LIBCXX_BENCHMARK_NATIVE_STDLIB "" CACHE STRING
74 "Build the benchmarks against the specified native STL.
75 The value must be one of libc++/libstdc++")
76set(LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN "" CACHE STRING
77 "Use alternate GCC toolchain when building the native benchmarks")
78
79if (LIBCXX_BENCHMARK_NATIVE_STDLIB)
80 if (NOT (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libc++"
81 OR LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libstdc++"))
82 message(FATAL_ERROR "Invalid value for LIBCXX_BENCHMARK_NATIVE_STDLIB: "
83 "'${LIBCXX_BENCHMARK_NATIVE_STDLIB}'")
84 endif()
85endif()
86
Eric Fiselierb9f425a2015-08-22 19:40:4987option(LIBCXX_INCLUDE_DOCS "Build the libc++ documentation." ${LLVM_INCLUDE_DOCS})
Eric Fiseliereb6e2ea2015-07-30 22:30:3488set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
89 "Define suffix of library directory name (32/64)")
90option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON)
Eric Fiselier961269d2015-08-26 20:18:2191option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON)
Eric Fiseliereb6e2ea2015-07-30 22:30:3492option(LIBCXX_INSTALL_SUPPORT_HEADERS "Install libc++ support headers." ON)
Eric Fiselier01609af2016-09-07 01:15:1093cmake_dependent_option(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY
94 "Install libc++experimental.a" ON
95 "LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY;LIBCXX_INSTALL_LIBRARY" OFF)
Evgeniy Stepanov4f01aa82015-10-13 23:48:2896set(LIBCXX_ABI_VERSION 1 CACHE STRING "ABI version of libc++.")
97option(LIBCXX_ABI_UNSTABLE "Unstable ABI of libc++." OFF)
Saleem Abdulrasoole146f752016-08-24 04:22:5298option(LIBCXX_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
Eric Fiseliereb6e2ea2015-07-30 22:30:3499
Petr Hosekb640da02016-08-08 22:57:25100if (NOT LIBCXX_ENABLE_SHARED AND NOT LIBCXX_ENABLE_STATIC)
101 message(FATAL_ERROR "libc++ must be built as either a shared or static library.")
102endif()
103
Eric Fiseliereb6e2ea2015-07-30 22:30:34104# ABI Library options ---------------------------------------------------------
Eric Fiseliercfc55152017-01-03 01:18:48105set(LIBCXX_CXX_ABI "default" CACHE STRING
106 "Specify C++ ABI library to use.")
Eric Fiselierbde28712017-01-16 20:47:35107set(CXXABIS none default libcxxabi libcxxrt libstdc++ libsupc++ vcruntime)
Eric Fiseliereb6e2ea2015-07-30 22:30:34108set_property(CACHE LIBCXX_CXX_ABI PROPERTY STRINGS ;${CXXABIS})
109
Eric Fiselier1cf5a812015-10-22 20:54:27110# Setup the default options if LIBCXX_CXX_ABI is not specified.
Eric Fiseliercfc55152017-01-03 01:18:48111if (LIBCXX_CXX_ABI STREQUAL "default")
Petr Hosekd842fed2016-11-09 03:22:28112 find_path(
113 LIBCXX_LIBCXXABI_INCLUDES_INTERNAL
114 cxxabi.h
115 PATHS ${LLVM_MAIN_SRC_DIR}/projects/libcxxabi/include
116 ${LLVM_MAIN_SRC_DIR}/runtimes/libcxxabi/include
117 NO_DEFAULT_PATH
118 )
Petr Hosek6948dbe2017-01-16 00:33:11119 if ((NOT LIBCXX_STANDALONE_BUILD OR HAVE_LIBCXXABI) AND
120 IS_DIRECTORY "${LIBCXX_LIBCXXABI_INCLUDES_INTERNAL}")
Eric Fiselier1cf5a812015-10-22 20:54:27121 set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi")
Petr Hosekd842fed2016-11-09 03:22:28122 set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${LIBCXX_LIBCXXABI_INCLUDES_INTERNAL}")
Eric Fiselier1cf5a812015-10-22 20:54:27123 set(LIBCXX_CXX_ABI_INTREE 1)
Eugene Zelenko96f10172016-08-08 18:01:50124 else()
Eric Fiselierbde28712017-01-16 20:47:35125 if (LIBCXX_TARGETING_MSVC)
Eric Fiselierbab7b412017-01-06 23:59:52126 # FIXME: Figure out how to configure the ABI library on Windows.
Eric Fiselierbde28712017-01-16 20:47:35127 set(LIBCXX_CXX_ABI_LIBNAME "vcruntime")
Eric Fiselier1edf3162017-02-10 08:57:35128 elseif(APPLE)
129 set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi")
130 set(LIBCXX_CXX_ABI_SYSTEM 1)
Eric Fiselierbab7b412017-01-06 23:59:52131 else()
132 set(LIBCXX_CXX_ABI_LIBNAME "default")
133 endif()
Eugene Zelenko96f10172016-08-08 18:01:50134 endif()
135else()
Eric Fiselier1cf5a812015-10-22 20:54:27136 set(LIBCXX_CXX_ABI_LIBNAME "${LIBCXX_CXX_ABI}")
Eugene Zelenko96f10172016-08-08 18:01:50137endif()
Eric Fiselier1cf5a812015-10-22 20:54:27138
Eric Fiselierbb856cc2015-10-15 22:41:51139# Use a static copy of the ABI library when linking libc++. This option
140# cannot be used with LIBCXX_ENABLE_ABI_LINKER_SCRIPT.
Eric Fiseliereb6e2ea2015-07-30 22:30:34141option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "Statically link the ABI library" OFF)
142
Eric Fiselier8cbf0202015-10-14 19:54:03143# Generate and install a linker script inplace of libc++.so. The linker script
Eric Fiselierbb856cc2015-10-15 22:41:51144# will link libc++ to the correct ABI library. This option is on by default
Shoaib Meenaie5774012017-03-25 03:22:35145# on UNIX platforms other than Apple unless 'LIBCXX_ENABLE_STATIC_ABI_LIBRARY'
Eric Fiselier5d5b59b2015-10-22 20:50:07146# is on. This option is also disabled when the ABI library is not specified
147# or is specified to be "none".
Eric Fiselierbb856cc2015-10-15 22:41:51148set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF)
Eric Fiselier1d3716a2015-10-15 23:04:54149if (LLVM_HAVE_LINK_VERSION_SCRIPT AND NOT LIBCXX_ENABLE_STATIC_ABI_LIBRARY
Eric Fiselier1cf5a812015-10-22 20:54:27150 AND NOT LIBCXX_CXX_ABI_LIBNAME STREQUAL "none"
Eric Fiseliercfc55152017-01-03 01:18:48151 AND NOT LIBCXX_CXX_ABI_LIBNAME STREQUAL "default"
Asiri Rathnayake10a68292016-05-14 23:58:11152 AND PYTHONINTERP_FOUND
153 AND LIBCXX_ENABLE_SHARED)
Eric Fiselierbb856cc2015-10-15 22:41:51154 set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE ON)
155endif()
156
Eric Fiselier8cbf0202015-10-14 19:54:03157option(LIBCXX_ENABLE_ABI_LINKER_SCRIPT
Eric Fiselierbb856cc2015-10-15 22:41:51158 "Use and install a linker script for the given ABI library"
Eric Fiselier1d3716a2015-10-15 23:04:54159 ${ENABLE_LINKER_SCRIPT_DEFAULT_VALUE})
Eric Fiselier8cbf0202015-10-14 19:54:03160
Eric Fiselierdc69aac2017-03-02 19:35:33161set(ENABLE_NEW_DELETE_DEFAULT ON)
162if (LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS)
Eric Fiselier0cbd39f2017-03-02 21:55:03163# FIXME: This option should default to off. Unfortunatly GCC 4.9 fails to link
Shoaib Meenaif23e2812017-03-25 03:29:51164# programs due to undefined references to new/delete in libc++abi so to work
Eric Fiselier0cbd39f2017-03-02 21:55:03165# around this libc++abi currently defaults LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS
166# to ON. Once the GCC bug has been worked around this option should be changed
167# back to OFF.
168 set(ENABLE_NEW_DELETE_DEFAULT ON)
Eric Fiselierdc69aac2017-03-02 19:35:33169endif()
170
171option(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS
172 "Build libc++ with definitions for operator new/delete. This option can
173 be used to disable the definitions when libc++abi is expected to provide
174 them" ${ENABLE_NEW_DELETE_DEFAULT})
175
Eric Fiseliereb6e2ea2015-07-30 22:30:34176# Build libc++abi with libunwind. We need this option to determine whether to
177# link with libunwind or libgcc_s while running the test cases.
178option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF)
Petr Hosekf4699a52017-02-09 02:19:43179option(LIBCXXABI_ENABLE_STATIC_UNWINDER "Statically link the LLVM unwinder." OFF)
Eric Fiseliereb6e2ea2015-07-30 22:30:34180
181# Target options --------------------------------------------------------------
182option(LIBCXX_BUILD_32_BITS "Build 32 bit libc++." ${LLVM_BUILD_32_BITS})
183set(LIBCXX_SYSROOT "" CACHE STRING "Use alternate sysroot.")
184set(LIBCXX_GCC_TOOLCHAIN "" CACHE STRING "Use alternate GCC toolchain.")
185
186# Feature options -------------------------------------------------------------
Michael J. Spencer626916f2010-12-10 19:47:54187option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON)
188option(LIBCXX_ENABLE_RTTI "Use run time type information." ON)
Ed Schoutenb33ae5b2015-03-12 15:44:39189option(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE "Build libc++ with support for the global filesystem namespace." ON)
Ed Schoutenabd06b42015-03-26 14:35:46190option(LIBCXX_ENABLE_STDIN "Build libc++ with support for stdin/std::cin." ON)
191option(LIBCXX_ENABLE_STDOUT "Build libc++ with support for stdout/std::cout." ON)
Eric Fiselier7330ed32014-12-06 21:02:58192option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON)
Ed Schouten323ade32015-06-24 08:44:38193option(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS "Build libc++ with support for thread-unsafe C functions" ON)
Eric Fiselier7330ed32014-12-06 21:02:58194option(LIBCXX_ENABLE_MONOTONIC_CLOCK
195 "Build libc++ with support for a monotonic clock.
Jonathan Roelofs5e91fa12015-08-24 21:20:07196 This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON)
Vasileios Kalintiris579b42b2015-11-09 10:21:04197option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF)
Ben Craig5163e462016-05-25 17:40:09198option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF)
Asiri Rathnayake040945b2016-09-11 21:46:40199option(LIBCXX_HAS_EXTERNAL_THREAD_API
200 "Build libc++ with an externalized threading API.
201 This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF)
Eric Fiselier66134e82017-01-06 20:05:40202option(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY
203 "Build libc++ with an externalized threading library.
204 This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON" OFF)
Eric Fiseliereb6e2ea2015-07-30 22:30:34205
206# Misc options ----------------------------------------------------------------
Eric Fiseliercb23a492015-10-10 03:34:52207# FIXME: Turn -pedantic back ON. It is currently off because it warns
208# about #include_next which is used everywhere.
209option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF)
Eric Fiseliereb6e2ea2015-07-30 22:30:34210option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
Saleem Abdulrasoolab008f72016-07-12 14:39:13211option(LIBCXX_DISABLE_MACRO_CONFLICT_WARNINGS "Disable #warnings about conflicting macros." OFF)
Eric Fiseliereb6e2ea2015-07-30 22:30:34212
Eric Fiselierbf9653d2015-03-31 04:15:45213option(LIBCXX_GENERATE_COVERAGE "Enable generating code coverage." OFF)
214set(LIBCXX_COVERAGE_LIBRARY "" CACHE STRING
Eric Fiseliereb6e2ea2015-07-30 22:30:34215 "The Profile-rt library used to build with code coverage")
216
Eric Fiselier961269d2015-08-26 20:18:21217# Don't allow a user to accidentally overwrite the system libc++ installation on Darwin.
218# If the user specifies -DCMAKE_INSTALL_PREFIX=/usr the install rules for libc++
219# will not be generated and a warning will be issued.
220option(LIBCXX_OVERRIDE_DARWIN_INSTALL "Enable overwriting darwins libc++ installation." OFF)
221mark_as_advanced(LIBCXX_OVERRIDE_DARWIN_INSTALL) # Don't show this option by default.
222
223if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT LIBCXX_OVERRIDE_DARWIN_INSTALL)
224 if ("${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr")
225 message(WARNING "Disabling libc++ install rules because installation would "
226 "overwrite the systems installation. Configure with "
227 "-DLIBCXX_OVERRIDE_DARWIN_INSTALL=ON to suppress this behaviour.")
228 mark_as_advanced(CLEAR LIBCXX_OVERRIDE_DARWIN_INSTALL) # Show the override option.
229 set(LIBCXX_INSTALL_HEADERS OFF)
230 set(LIBCXX_INSTALL_LIBRARY OFF)
231 endif()
232endif()
233
Eric Fiselier85df7a82015-12-16 23:41:05234set(LIBCXX_CONFIGURE_IDE_DEFAULT OFF)
235if (XCODE OR MSVC_IDE)
236 set(LIBCXX_CONFIGURE_IDE_DEFAULT ON)
237endif()
238option(LIBCXX_CONFIGURE_IDE "Configure libcxx for use within an IDE"
239 ${LIBCXX_CONFIGURE_IDE_DEFAULT})
240
Eric Fiseliereb6e2ea2015-07-30 22:30:34241#===============================================================================
242# Check option configurations
243#===============================================================================
244
Eric Fiselier6e9a6942016-06-17 19:46:40245if (LIBCXX_ENABLE_FILESYSTEM AND NOT LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY)
246 message(FATAL_ERROR
247 "LIBCXX_ENABLE_FILESYSTEM cannot be turned on when LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF")
248endif()
249
Eric Fiseliereb6e2ea2015-07-30 22:30:34250# Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON only when
251# LIBCXX_ENABLE_THREADS is on.
252if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_ENABLE_MONOTONIC_CLOCK)
253 message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF"
254 " when LIBCXX_ENABLE_THREADS is also set to OFF.")
Eric Fiselier25a15162014-08-18 05:03:46255endif()
Michael J. Spencer626916f2010-12-10 19:47:54256
Asiri Rathnayakee262e7b2017-01-03 12:59:50257if(NOT LIBCXX_ENABLE_THREADS)
258 if(LIBCXX_HAS_PTHREAD_API)
259 message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON"
260 " when LIBCXX_ENABLE_THREADS is also set to ON.")
261 endif()
262 if(LIBCXX_HAS_EXTERNAL_THREAD_API)
263 message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set to ON"
264 " when LIBCXX_ENABLE_THREADS is also set to ON.")
265 endif()
Eric Fiselier66134e82017-01-06 20:05:40266 if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY)
267 message(FATAL_ERROR "LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY can only be set "
268 "to ON when LIBCXX_ENABLE_THREADS is also set to ON.")
269 endif()
270
271endif()
272
Asiri Rathnayakeda39f1b2017-01-09 10:38:56273if (LIBCXX_HAS_EXTERNAL_THREAD_API)
274 if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY)
275 message(FATAL_ERROR "The options LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY and "
276 "LIBCXX_HAS_EXTERNAL_THREAD_API cannot both be ON at "
277 "the same time")
278 endif()
279 if (LIBCXX_HAS_PTHREAD_API)
280 message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
281 "and LIBCXX_HAS_PTHREAD_API cannot be both"
282 "set to ON at the same time.")
283 endif()
Asiri Rathnayake040945b2016-09-11 21:46:40284endif()
285
Eric Fiseliereb6e2ea2015-07-30 22:30:34286# Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE
287# is ON.
288if (LLVM_USE_SANITIZER AND LIBCXX_GENERATE_COVERAGE)
289 message(FATAL_ERROR "LLVM_USE_SANITIZER cannot be used with LIBCXX_GENERATE_COVERAGE")
290endif()
291
292# Set LIBCXX_BUILD_32_BITS to (LIBCXX_BUILD_32_BITS OR LLVM_BUILD_32_BITS)
293# and check that we can build with 32 bits if requested.
294if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32)
295 if (LIBCXX_BUILD_32_BITS AND NOT LLVM_BUILD_32_BITS) # Don't duplicate the output from LLVM
296 message(STATUS "Building 32 bits executables and libraries.")
297 endif()
298elseif(LIBCXX_BUILD_32_BITS)
299 message(FATAL_ERROR "LIBCXX_BUILD_32_BITS=ON is not supported on this platform.")
300endif()
301
302# Check that this option is not enabled on Apple and emit a usage warning.
Eric Fiselierc0b166e2015-03-03 15:59:51303if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
304 if (APPLE)
305 message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is not supported on OS X")
306 else()
307 message(WARNING "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is an experimental option")
308 endif()
Eric Fiselier60479ea2016-11-18 19:53:45309 if (LIBCXX_ENABLE_STATIC AND NOT PYTHONINTERP_FOUND)
310 message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY requires python but it was not found.")
311 endif()
Eric Fiselierc0b166e2015-03-03 15:59:51312endif()
313
Eric Fiselier8cbf0202015-10-14 19:54:03314if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
315 if (APPLE)
316 message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT cannot be used on APPLE targets")
317 endif()
318 if (NOT PYTHONINTERP_FOUND)
319 message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT requires python but it was not found.")
320 endif()
Asiri Rathnayake10a68292016-05-14 23:58:11321 if (NOT LIBCXX_ENABLE_SHARED)
322 message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT is only available for shared library builds.")
323 endif()
Eric Fiselier8cbf0202015-10-14 19:54:03324endif()
325
326if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
327 message(FATAL_ERROR "Conflicting options given.
328 LIBCXX_ENABLE_STATIC_ABI_LIBRARY cannot be specified with
329 LIBCXX_ENABLE_ABI_LINKER_SCRIPT")
330endif()
331
Vasileios Kalintiris579b42b2015-11-09 10:21:04332if (LIBCXX_HAS_MUSL_LIBC AND NOT LIBCXX_INSTALL_SUPPORT_HEADERS)
333 message(FATAL_ERROR "LIBCXX_INSTALL_SUPPORT_HEADERS can not be turned off"
334 "when building for Musl with LIBCXX_HAS_MUSL_LIBC.")
335endif()
336
Michael J. Spencer626916f2010-12-10 19:47:54337#===============================================================================
338# Configure System
339#===============================================================================
340
Eric Fiselier4778eed2014-12-20 03:16:55341set(LIBCXX_COMPILER ${CMAKE_CXX_COMPILER})
342set(LIBCXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
343set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
Eric Fiselierbde28712017-01-16 20:47:35344set(LIBCXX_BINARY_INCLUDE_DIR "${LIBCXX_BINARY_DIR}/include/c++build")
Chandler Carruth7a033ca2014-12-29 12:15:47345set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
Eric Fiselierbde28712017-01-16 20:47:35346file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}")
Eric Fiselier4778eed2014-12-20 03:16:55347
Eric Fiseliereb6e2ea2015-07-30 22:30:34348set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
349set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
Shoaib Meenaib975b452017-04-13 16:27:38350set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
Eric Fiseliereb6e2ea2015-07-30 22:30:34351
Eric Fiselier8e2855c2014-11-15 06:26:30352# Declare libc++ configuration variables.
353# They are intended for use as follows:
354# LIBCXX_CXX_FLAGS: General flags for both the compiler and linker.
355# LIBCXX_COMPILE_FLAGS: Compile only flags.
356# LIBCXX_LINK_FLAGS: Linker only flags.
Eric Fiselier3bf8a9c2016-10-09 21:34:03357# LIBCXX_LIBRARIES: libraries libc++ is linked to.
358# LIBCXX_INTERFACE_LIBRARIES: Libraries that must be linked when using libc++
Eric Fiselier742d8782016-10-10 14:45:06359# These libraries are exposed in the linker script.
Eric Fiselier8e2855c2014-11-15 06:26:30360set(LIBCXX_COMPILE_FLAGS "")
361set(LIBCXX_LINK_FLAGS "")
Eric Fiseliereb6e2ea2015-07-30 22:30:34362set(LIBCXX_LIBRARIES "")
Eric Fiselier3bf8a9c2016-10-09 21:34:03363set(LIBCXX_INTERFACE_LIBRARIES "")
Eric Fiselier8e2855c2014-11-15 06:26:30364
Eric Fiseliera27cbf82016-06-02 01:10:08365# Include macros for adding and removing libc++ flags.
366include(HandleLibcxxFlags)
367
368# Target flags ================================================================
369# These flags get added to CMAKE_CXX_FLAGS and CMAKE_C_FLAGS so that
370# 'config-ix' use them during feature checks. It also adds them to both
371# 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS'
372add_target_flags_if(LIBCXX_BUILD_32_BITS "-m32")
373add_target_flags_if(LIBCXX_TARGET_TRIPLE "-target ${LIBCXX_TARGET_TRIPLE}")
374add_target_flags_if(LIBCXX_SYSROOT "--sysroot=${LIBCXX_SYSROOT}")
375add_target_flags_if(LIBCXX_GCC_TOOLCHAIN "-gcc-toolchain ${LIBCXX_GCC_TOOLCHAIN}")
Eric Fiselier6e467a82016-11-13 22:27:00376if (LIBCXX_TARGET_TRIPLE)
377 set(TARGET_TRIPLE "${LIBCXX_TARGET_TRIPLE}")
378endif()
Eric Fiseliera27cbf82016-06-02 01:10:08379
Eric Fiselier9a1468f2014-11-15 17:25:23380# Configure compiler.
381include(config-ix)
Eric Fiseliereb6e2ea2015-07-30 22:30:34382
Saleem Abdulrasoole146f752016-08-24 04:22:52383if (LIBCXX_USE_COMPILER_RT)
384 list(APPEND LIBCXX_LINK_FLAGS "-rtlib=compiler-rt")
385endif()
386
Eric Fiselierbf9653d2015-03-31 04:15:45387# Configure coverage options.
388if (LIBCXX_GENERATE_COVERAGE)
389 include(CodeCoverage)
390 set(CMAKE_BUILD_TYPE "COVERAGE" CACHE STRING "" FORCE)
391endif()
Eric Fiselier9a1468f2014-11-15 17:25:23392
Eric Fiseliereb6e2ea2015-07-30 22:30:34393string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
Eric Fiselier157fd342017-01-14 07:54:39394if (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
395 set(LIBCXX_DEBUG_BUILD ON)
396else()
397 set(LIBCXX_DEBUG_BUILD OFF)
398endif()
Eric Fiseliereb6e2ea2015-07-30 22:30:34399
Eric Fiselier9a1468f2014-11-15 17:25:23400#===============================================================================
401# Setup Compiler Flags
402#===============================================================================
403
JF Bastienc7c4c772016-03-05 14:22:02404include(HandleLibCXXABI) # Setup the ABI library flags
Eric Fiseliereb6e2ea2015-07-30 22:30:34405
Michal Gornyb79ca0a2016-09-27 07:55:26406if (NOT LIBCXX_STANDALONE_BUILD)
407 # Remove flags that may have snuck in.
408 remove_flags(-DNDEBUG -UNDEBUG -D_DEBUG
Eric Fiselier8e395592017-01-17 23:27:56409 -lc++abi)
Michal Gornyb79ca0a2016-09-27 07:55:26410endif()
411remove_flags(-stdlib=libc++ -stdlib=libstdc++)
Eric Fiseliereb6e2ea2015-07-30 22:30:34412
Eric Fiselierfdd3c912017-01-14 06:06:47413# FIXME: Remove all debug flags and flags that change which Windows
414# default libraries are linked. Currently we only support linking the
415# non-debug DLLs
Eric Fiselier157fd342017-01-14 07:54:39416remove_flags("/D_DEBUG" "/MTd" "/MDd" "/MT" "/Md")
Eric Fiselierfdd3c912017-01-14 06:06:47417
Shoaib Meenai68fdad62017-03-25 03:42:20418# FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC.
Eric Fiselier7b081f62015-10-15 20:27:15419# Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors
Shoaib Meenai68fdad62017-03-25 03:42:20420# so they don't get transformed into -Wno and -errors respectively.
Eric Fiselier7b081f62015-10-15 20:27:15421remove_flags(-Wno-pedantic -pedantic-errors -pedantic)
Eric Fiselier499d8782015-10-13 23:56:33422
Eric Fiseliereb6e2ea2015-07-30 22:30:34423# Required flags ==============================================================
Eric Fiselierc9e74dd2016-08-14 22:51:54424set(LIBCXX_STANDARD_VER c++11 CACHE INTERNAL "internal option to change build dialect")
Petr Hosek44197a12016-10-23 21:48:27425if (LIBCXX_HAS_MUSL_LIBC)
426 # musl's pthread implementations uses volatile types in their structs which is
427 # not a constexpr in C++11 but is in C++14, so we use C++14 with musl.
428 set(LIBCXX_STANDARD_VER c++14 CACHE INTERNAL "internal option to change build dialect")
429endif()
Eric Fiselierc9e74dd2016-08-14 22:51:54430add_compile_flags_if_supported(-std=${LIBCXX_STANDARD_VER})
431mangle_name("LIBCXX_SUPPORTS_STD_EQ_${LIBCXX_STANDARD_VER}_FLAG" SUPPORTS_DIALECT_NAME)
Saleem Abdulrasool1ca3c452017-01-01 20:20:40432if(NOT ${SUPPORTS_DIALECT_NAME})
433 if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" AND NOT "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
434 message(FATAL_ERROR "C++11 or greater is required but the compiler does not support ${LIBCXX_STANDARD_VER}")
435 endif()
Eric Fiseliereb6e2ea2015-07-30 22:30:34436endif()
437
Eric Fiselier5514d362015-07-29 23:46:55438# On all systems the system c++ standard library headers need to be excluded.
Eric Fiseliereb6e2ea2015-07-30 22:30:34439# MSVC only has -X, which disables all default includes; including the crt.
440# Thus, we do nothing and hope we don't accidentally include any of the C++
441# headers
442add_compile_flags_if_supported(-nostdinc++)
Eric Fiselierd74dee92015-07-29 21:07:28443
Eric Fiselier8330b1e2016-10-25 19:43:44444# Hide all inline function definitions which have not explicitly been marked
445# visible. This prevents new definitions for inline functions from appearing in
446# the dylib when get ODR used by another function.
447add_compile_flags_if_supported(-fvisibility-inlines-hidden)
448
Eric Fiselier74c98572016-09-26 22:19:41449# Let the library headers know they are currently being used to build the
450# library.
Eric Fiselier6dbed462016-09-16 00:00:48451add_definitions(-D_LIBCPP_BUILDING_LIBRARY)
452
Eric Fiselierdc69aac2017-03-02 19:35:33453if (NOT LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS)
454 add_definitions(-D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS)
455endif()
456
Eric Fiseliereb6e2ea2015-07-30 22:30:34457# Warning flags ===============================================================
Eric Fiselier692177d2015-07-18 20:40:46458add_definitions(-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Eric Fiseliereb6e2ea2015-07-30 22:30:34459add_compile_flags_if_supported(
Eric Fiselier3ec6b842016-08-29 20:43:38460 -Wall -Wextra -W -Wwrite-strings
461 -Wno-unused-parameter -Wno-long-long
Eric Fiseliereb6e2ea2015-07-30 22:30:34462 -Werror=return-type)
Eric Fiselier3ec6b842016-08-29 20:43:38463if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
464 add_compile_flags_if_supported(
465 -Wno-user-defined-literals
466 -Wno-covered-switch-default)
467elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
468 add_compile_flags_if_supported(
Eric Fiselier3ec6b842016-08-29 20:43:38469 -Wno-literal-suffix
Eric Fiselierf3b3a652017-04-03 20:53:15470 -Wno-c++14-compat
471 -Wno-noexcept-type)
Eric Fiselier3ec6b842016-08-29 20:43:38472endif()
Michael J. Spencer626916f2010-12-10 19:47:54473if (LIBCXX_ENABLE_WERROR)
Eric Fiseliereb6e2ea2015-07-30 22:30:34474 add_compile_flags_if_supported(-Werror)
475 add_compile_flags_if_supported(-WX)
Eric Fiselier26d23902015-07-31 01:25:01476else()
477 # TODO(EricWF) Remove this. We shouldn't be suppressing errors when -Werror is
478 # added elsewhere.
479 add_compile_flags_if_supported(-Wno-error)
Michael J. Spencer626916f2010-12-10 19:47:54480endif()
481if (LIBCXX_ENABLE_PEDANTIC)
Eric Fiseliereb6e2ea2015-07-30 22:30:34482 add_compile_flags_if_supported(-pedantic)
Michael J. Spencer626916f2010-12-10 19:47:54483endif()
Saleem Abdulrasoolab008f72016-07-12 14:39:13484if (LIBCXX_DISABLE_MACRO_CONFLICT_WARNINGS)
485 add_definitions(-D_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS)
486endif()
Michael J. Spencer626916f2010-12-10 19:47:54487
Eric Fiseliereb6e2ea2015-07-30 22:30:34488# Exception flags =============================================================
Michael J. Spencer626916f2010-12-10 19:47:54489if (LIBCXX_ENABLE_EXCEPTIONS)
490 # Catches C++ exceptions only and tells the compiler to assume that extern C
491 # functions never throw a C++ exception.
Eric Fiseliereb6e2ea2015-07-30 22:30:34492 add_compile_flags_if_supported(-EHsc)
Michael J. Spencer626916f2010-12-10 19:47:54493else()
Eric Fiseliereb6e2ea2015-07-30 22:30:34494 add_definitions(-D_LIBCPP_NO_EXCEPTIONS)
495 add_compile_flags_if_supported(-EHs- -EHa-)
496 add_compile_flags_if_supported(-fno-exceptions)
Michael J. Spencer626916f2010-12-10 19:47:54497endif()
Eric Fiseliereb6e2ea2015-07-30 22:30:34498
499# RTTI flags ==================================================================
Michael J. Spencer626916f2010-12-10 19:47:54500if (NOT LIBCXX_ENABLE_RTTI)
Eric Fiseliereb6e2ea2015-07-30 22:30:34501 add_definitions(-D_LIBCPP_NO_RTTI)
502 add_compile_flags_if_supported(-GR-)
503 add_compile_flags_if_supported(-fno-rtti)
Michael J. Spencer626916f2010-12-10 19:47:54504endif()
Eric Fiseliereb6e2ea2015-07-30 22:30:34505
Asiri Rathnayake040945b2016-09-11 21:46:40506# Threading flags =============================================================
Asiri Rathnayakeda39f1b2017-01-09 10:38:56507if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY AND LIBCXX_ENABLE_SHARED)
Asiri Rathnayake040945b2016-09-11 21:46:40508 # Need to allow unresolved symbols if this is to work with shared library builds
509 if (APPLE)
510 add_link_flags("-undefined dynamic_lookup")
511 else()
512 # Relax this restriction from HandleLLVMOptions
513 string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
514 endif()
515endif()
516
Eric Fiseliereb6e2ea2015-07-30 22:30:34517# Assertion flags =============================================================
518define_if(LIBCXX_ENABLE_ASSERTIONS -UNDEBUG)
519define_if_not(LIBCXX_ENABLE_ASSERTIONS -DNDEBUG)
Eric Fiselierb89eba02017-02-04 23:22:28520define_if(LIBCXX_ENABLE_ASSERTIONS -D_LIBCPP_DEBUG=0)
Eric Fiselier157fd342017-01-14 07:54:39521define_if(LIBCXX_DEBUG_BUILD -D_DEBUG)
522if (LIBCXX_ENABLE_ASSERTIONS AND NOT LIBCXX_DEBUG_BUILD)
Michael J. Spencer626916f2010-12-10 19:47:54523 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
Eric Fiselierfdd3c912017-01-14 06:06:47524 define_if_not(LIBCXX_TARGETING_MSVC -D_DEBUG)
Howard Hinnant4a0e74f2013-02-25 15:50:36525endif()
Michael J. Spencer626916f2010-12-10 19:47:54526
Eric Fiselier29026ad2016-10-14 12:56:52527# Modules flags ===============================================================
528# FIXME The libc++ sources are fundamentally non-modular. They need special
529# versions of the headers in order to provide C++03 and legacy ABI definitions.
530# NOTE: The public headers can be used with modules in all other contexts.
531if (LLVM_ENABLE_MODULES)
532 # Ignore that the rest of the modules flags are now unused.
533 add_compile_flags_if_supported(-Wno-unused-command-line-argument)
534 add_compile_flags(-fno-modules)
535endif()
536
Jonathan Roelofs5e91fa12015-08-24 21:20:07537# Sanitizer flags =============================================================
Eric Fiselier5514d362015-07-29 23:46:55538
Chris Bieneman8c226962016-08-18 21:31:51539# Configure for sanitizers. If LIBCXX_STANDALONE_BUILD then we have to do
Eric Fiselier5514d362015-07-29 23:46:55540# the flag translation ourselves. Othewise LLVM's CMakeList.txt will handle it.
Chris Bieneman8c226962016-08-18 21:31:51541if (LIBCXX_STANDALONE_BUILD)
Eric Fiseliereb6e2ea2015-07-30 22:30:34542 set(LLVM_USE_SANITIZER "" CACHE STRING
543 "Define the sanitizer used to build the library and tests")
Eric Fiselier5514d362015-07-29 23:46:55544 # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC.
545 # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do.
546 if (LLVM_USE_SANITIZER AND NOT MSVC)
Eric Fiseliereb6e2ea2015-07-30 22:30:34547 add_flags_if_supported("-fno-omit-frame-pointer")
548 add_flags_if_supported("-gline-tables-only")
549
Eric Fiselier5514d362015-07-29 23:46:55550 if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND
551 NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
Eric Fiseliereb6e2ea2015-07-30 22:30:34552 add_flags_if_supported("-gline-tables-only")
Eric Fiselier5514d362015-07-29 23:46:55553 endif()
554 if (LLVM_USE_SANITIZER STREQUAL "Address")
Eric Fiseliereb6e2ea2015-07-30 22:30:34555 add_flags("-fsanitize=address")
Eric Fiselier5514d362015-07-29 23:46:55556 elseif (LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?")
Eric Fiseliereb6e2ea2015-07-30 22:30:34557 add_flags(-fsanitize=memory)
Eric Fiselier5514d362015-07-29 23:46:55558 if (LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins")
Eric Fiseliereb6e2ea2015-07-30 22:30:34559 add_flags("-fsanitize-memory-track-origins")
Eric Fiselier5514d362015-07-29 23:46:55560 endif()
561 elseif (LLVM_USE_SANITIZER STREQUAL "Undefined")
Eric Fiseliereb6e2ea2015-07-30 22:30:34562 add_flags("-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all")
Eric Fiselier5514d362015-07-29 23:46:55563 elseif (LLVM_USE_SANITIZER STREQUAL "Thread")
Eric Fiseliereb6e2ea2015-07-30 22:30:34564 add_flags(-fsanitize=thread)
Eric Fiselier5514d362015-07-29 23:46:55565 else()
566 message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}")
567 endif()
Eric Fiseliereb6e2ea2015-07-30 22:30:34568 elseif(LLVM_USE_SANITIZER AND MSVC)
569 message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.")
Eric Fiselier5514d362015-07-29 23:46:55570 endif()
571endif()
Eric Fiselier73ffc782015-10-13 22:12:02572
573# Configuration file flags =====================================================
Evgeniy Stepanov4f01aa82015-10-13 23:48:28574if (NOT LIBCXX_ABI_VERSION EQUAL "1")
575 config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION)
576endif()
577config_define_if(LIBCXX_ABI_UNSTABLE _LIBCPP_ABI_UNSTABLE)
578
Eric Fiselier73ffc782015-10-13 22:12:02579config_define_if_not(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE)
580config_define_if_not(LIBCXX_ENABLE_STDIN _LIBCPP_HAS_NO_STDIN)
581config_define_if_not(LIBCXX_ENABLE_STDOUT _LIBCPP_HAS_NO_STDOUT)
582config_define_if_not(LIBCXX_ENABLE_THREADS _LIBCPP_HAS_NO_THREADS)
583config_define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK _LIBCPP_HAS_NO_MONOTONIC_CLOCK)
584config_define_if_not(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS)
585
Ben Craig5163e462016-05-25 17:40:09586config_define_if(LIBCXX_HAS_PTHREAD_API _LIBCPP_HAS_THREAD_API_PTHREAD)
Asiri Rathnayake040945b2016-09-11 21:46:40587config_define_if(LIBCXX_HAS_EXTERNAL_THREAD_API _LIBCPP_HAS_THREAD_API_EXTERNAL)
Eric Fiselier66134e82017-01-06 20:05:40588config_define_if(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL)
Vasileios Kalintiris579b42b2015-11-09 10:21:04589config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC)
590
Eric Fiselier74c98572016-09-26 22:19:41591# By default libc++ on Windows expects to use a shared library, which requires
592# the headers to use DLL import/export semantics. However when building a
593# static library only we modify the headers to disable DLL import/export.
594if (DEFINED WIN32 AND LIBCXX_ENABLE_STATIC AND NOT LIBCXX_ENABLE_SHARED)
595 message(STATUS "Generating custom __config for non-DLL Windows build")
Shoaib Meenaic6d8e8a2016-12-05 19:40:12596 config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
Eric Fiselier74c98572016-09-26 22:19:41597endif()
598
Eric Fiselier73ffc782015-10-13 22:12:02599if (LIBCXX_NEEDS_SITE_CONFIG)
Saleem Abdulrasool1ca3c452017-01-01 20:20:40600 configure_file("include/__config_site.in"
601 "${LIBCXX_BINARY_DIR}/__config_site"
602 @ONLY)
603
Eric Fiseliera6622792015-10-14 00:22:05604 # Provide the config definitions by included the generated __config_site
605 # file at compile time.
Saleem Abdulrasool1ca3c452017-01-01 20:20:40606 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
607 add_compile_flags("/FI\"${LIBCXX_BINARY_DIR}/__config_site\"")
608 else()
609 add_compile_flags("-include ${LIBCXX_BINARY_DIR}/__config_site")
610 endif()
Eric Fiselier73ffc782015-10-13 22:12:02611endif()
612
Michael J. Spencer626916f2010-12-10 19:47:54613#===============================================================================
Eric Fiseliereb6e2ea2015-07-30 22:30:34614# Setup Source Code And Tests
Michael J. Spencer626916f2010-12-10 19:47:54615#===============================================================================
Michael J. Spencer626916f2010-12-10 19:47:54616include_directories(include)
Howard Hinnantc4962b32013-11-15 17:18:57617add_subdirectory(include)
Michael J. Spencer626916f2010-12-10 19:47:54618add_subdirectory(lib)
Eric Fiselierb9f425a2015-08-22 19:40:49619
Eric Fiselier5e000c62016-11-14 02:43:12620
Eric Fiselierd9b9ef72016-07-19 23:07:03621if (LIBCXX_INCLUDE_BENCHMARKS)
622 add_subdirectory(benchmarks)
623endif()
Eric Fiselierc57fb582017-03-01 21:53:30624
625# Create the lit.site.cfg file even when LIBCXX_INCLUDE_TESTS is OFF or
626# LLVM_FOUND is OFF. This allows users to run the tests manually using
627# LIT without requiring a full LLVM checkout.
628add_subdirectory(test)
Eric Fiseliereb6e2ea2015-07-30 22:30:34629if (LIBCXX_INCLUDE_TESTS)
Eric Fiselier5e000c62016-11-14 02:43:12630 add_subdirectory(lib/abi)
Eric Fiseliereb6e2ea2015-07-30 22:30:34631endif()
Eric Fiselierc57fb582017-03-01 21:53:30632
Eric Fiselierb9f425a2015-08-22 19:40:49633if (LIBCXX_INCLUDE_DOCS)
634 add_subdirectory(docs)
635endif()