blob: 6cc36e0161b19c91280612c34eeb1064a91c1e67 [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#===============================================================================
Michael J. Spencer626916f2010-12-10 19:47:546cmake_minimum_required(VERSION 2.8)
7
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
15project(libcxx CXX C)
Eric Fiseliere9d4b232015-01-26 21:56:4516
Michael J. Spencer626916f2010-12-10 19:47:5417set(PACKAGE_NAME libcxx)
18set(PACKAGE_VERSION trunk-svn)
19set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
Tanya Lattnerd08dbfc2015-08-05 03:59:1420set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org")
Michael J. Spencer626916f2010-12-10 19:47:5421
22# Add path for custom modules
23set(CMAKE_MODULE_PATH
Michael J. Spencer626916f2010-12-10 19:47:5424 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
25 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
Alexey Samsonov179fa782013-09-30 09:10:0126 ${CMAKE_MODULE_PATH}
Michael J. Spencer626916f2010-12-10 19:47:5427 )
28
29# Require out of source build.
30include(MacroEnsureOutOfSourceBuild)
31MACRO_ENSURE_OUT_OF_SOURCE_BUILD(
32 "${PROJECT_NAME} requires an out of source build. Please create a separate
33 build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there."
34 )
35
Eric Fiseliereb6e2ea2015-07-30 22:30:3436# Find the LLVM sources and simulate LLVM CMake options.
37include(HandleOutOfTreeLLVM)
38if (LIBCXX_BUILT_STANDALONE AND NOT LLVM_FOUND)
39 message(WARNING "UNSUPPORTED LIBCXX CONFIGURATION DETECTED: "
40 "llvm-config not found and LLVM_PATH not defined.\n"
41 "Reconfigure with -DLLVM_CONFIG=path/to/llvm-config "
42 "or -DLLVM_PATH=path/to/llvm-source-root.")
Eric Fiselier5514d362015-07-29 23:46:5543endif()
Peter Collingbourne4c81b002013-10-03 21:58:2544
Eric Fiseliereb6e2ea2015-07-30 22:30:3445
Michael J. Spencer626916f2010-12-10 19:47:5446#===============================================================================
47# Setup CMake Options
48#===============================================================================
49
Eric Fiseliereb6e2ea2015-07-30 22:30:3450# Basic options ---------------------------------------------------------------
51option(LIBCXX_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
52option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON)
53
54option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS})
Eric Fiselierb9f425a2015-08-22 19:40:4955option(LIBCXX_INCLUDE_DOCS "Build the libc++ documentation." ${LLVM_INCLUDE_DOCS})
Eric Fiseliereb6e2ea2015-07-30 22:30:3456set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
57 "Define suffix of library directory name (32/64)")
58option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON)
Eric Fiselier961269d2015-08-26 20:18:2159option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON)
Eric Fiseliereb6e2ea2015-07-30 22:30:3460option(LIBCXX_INSTALL_SUPPORT_HEADERS "Install libc++ support headers." ON)
Evgeniy Stepanov4f01aa82015-10-13 23:48:2861set(LIBCXX_ABI_VERSION 1 CACHE STRING "ABI version of libc++.")
62option(LIBCXX_ABI_UNSTABLE "Unstable ABI of libc++." OFF)
Eric Fiseliereb6e2ea2015-07-30 22:30:3463
64# ABI Library options ---------------------------------------------------------
65set(LIBCXX_CXX_ABI "${LIBCXX_CXX_ABI}" CACHE STRING
66 "Specify C++ ABI library to use." FORCE)
67set(CXXABIS none libcxxabi libcxxrt libstdc++ libsupc++)
68set_property(CACHE LIBCXX_CXX_ABI PROPERTY STRINGS ;${CXXABIS})
69
Eric Fiselier1cf5a812015-10-22 20:54:2770# Setup the default options if LIBCXX_CXX_ABI is not specified.
71if (NOT LIBCXX_CXX_ABI)
72 if (NOT DEFINED LIBCXX_BUILT_STANDALONE AND
73 IS_DIRECTORY "${CMAKE_SOURCE_DIR}/projects/libcxxabi")
74 set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi")
75 set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${CMAKE_SOURCE_DIR}/projects/libcxxabi/include")
76 set(LIBCXX_CXX_ABI_INTREE 1)
77 else ()
78 set(LIBCXX_CXX_ABI_LIBNAME "none")
79 endif ()
80else ()
81 set(LIBCXX_CXX_ABI_LIBNAME "${LIBCXX_CXX_ABI}")
82endif ()
83
Eric Fiselierbb856cc2015-10-15 22:41:5184# Use a static copy of the ABI library when linking libc++. This option
85# cannot be used with LIBCXX_ENABLE_ABI_LINKER_SCRIPT.
Eric Fiseliereb6e2ea2015-07-30 22:30:3486option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "Statically link the ABI library" OFF)
87
Eric Fiselier8cbf0202015-10-14 19:54:0388# Generate and install a linker script inplace of libc++.so. The linker script
Eric Fiselierbb856cc2015-10-15 22:41:5189# will link libc++ to the correct ABI library. This option is on by default
90# On UNIX platforms other than Apple unless 'LIBCXX_ENABLE_STATIC_ABI_LIBRARY'
Eric Fiselier5d5b59b2015-10-22 20:50:0791# is on. This option is also disabled when the ABI library is not specified
92# or is specified to be "none".
Eric Fiselierbb856cc2015-10-15 22:41:5193set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF)
Eric Fiselier1d3716a2015-10-15 23:04:5494if (LLVM_HAVE_LINK_VERSION_SCRIPT AND NOT LIBCXX_ENABLE_STATIC_ABI_LIBRARY
Eric Fiselier1cf5a812015-10-22 20:54:2795 AND NOT LIBCXX_CXX_ABI_LIBNAME STREQUAL "none"
Eric Fiselier1d3716a2015-10-15 23:04:5496 AND PYTHONINTERP_FOUND)
Eric Fiselierbb856cc2015-10-15 22:41:5197 set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE ON)
98endif()
99
Eric Fiselier8cbf0202015-10-14 19:54:03100option(LIBCXX_ENABLE_ABI_LINKER_SCRIPT
Eric Fiselierbb856cc2015-10-15 22:41:51101 "Use and install a linker script for the given ABI library"
Eric Fiselier1d3716a2015-10-15 23:04:54102 ${ENABLE_LINKER_SCRIPT_DEFAULT_VALUE})
Eric Fiselier8cbf0202015-10-14 19:54:03103
Eric Fiseliereb6e2ea2015-07-30 22:30:34104# Build libc++abi with libunwind. We need this option to determine whether to
105# link with libunwind or libgcc_s while running the test cases.
106option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF)
107
108# Target options --------------------------------------------------------------
109option(LIBCXX_BUILD_32_BITS "Build 32 bit libc++." ${LLVM_BUILD_32_BITS})
110set(LIBCXX_SYSROOT "" CACHE STRING "Use alternate sysroot.")
111set(LIBCXX_GCC_TOOLCHAIN "" CACHE STRING "Use alternate GCC toolchain.")
112
113# Feature options -------------------------------------------------------------
Michael J. Spencer626916f2010-12-10 19:47:54114option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON)
115option(LIBCXX_ENABLE_RTTI "Use run time type information." ON)
Ed Schoutenb33ae5b2015-03-12 15:44:39116option(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE "Build libc++ with support for the global filesystem namespace." ON)
Ed Schoutenabd06b42015-03-26 14:35:46117option(LIBCXX_ENABLE_STDIN "Build libc++ with support for stdin/std::cin." ON)
118option(LIBCXX_ENABLE_STDOUT "Build libc++ with support for stdout/std::cout." ON)
Eric Fiselier7330ed32014-12-06 21:02:58119option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON)
Ed Schouten323ade32015-06-24 08:44:38120option(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS "Build libc++ with support for thread-unsafe C functions" ON)
Eric Fiselier7330ed32014-12-06 21:02:58121option(LIBCXX_ENABLE_MONOTONIC_CLOCK
122 "Build libc++ with support for a monotonic clock.
Jonathan Roelofs5e91fa12015-08-24 21:20:07123 This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON)
Eric Fiseliereb6e2ea2015-07-30 22:30:34124
125# Misc options ----------------------------------------------------------------
Eric Fiseliercb23a492015-10-10 03:34:52126# FIXME: Turn -pedantic back ON. It is currently off because it warns
127# about #include_next which is used everywhere.
128option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF)
Eric Fiseliereb6e2ea2015-07-30 22:30:34129option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
130
Eric Fiselierbf9653d2015-03-31 04:15:45131option(LIBCXX_GENERATE_COVERAGE "Enable generating code coverage." OFF)
132set(LIBCXX_COVERAGE_LIBRARY "" CACHE STRING
Eric Fiseliereb6e2ea2015-07-30 22:30:34133 "The Profile-rt library used to build with code coverage")
134
Eric Fiselier961269d2015-08-26 20:18:21135# Don't allow a user to accidentally overwrite the system libc++ installation on Darwin.
136# If the user specifies -DCMAKE_INSTALL_PREFIX=/usr the install rules for libc++
137# will not be generated and a warning will be issued.
138option(LIBCXX_OVERRIDE_DARWIN_INSTALL "Enable overwriting darwins libc++ installation." OFF)
139mark_as_advanced(LIBCXX_OVERRIDE_DARWIN_INSTALL) # Don't show this option by default.
140
141if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT LIBCXX_OVERRIDE_DARWIN_INSTALL)
142 if ("${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr")
143 message(WARNING "Disabling libc++ install rules because installation would "
144 "overwrite the systems installation. Configure with "
145 "-DLIBCXX_OVERRIDE_DARWIN_INSTALL=ON to suppress this behaviour.")
146 mark_as_advanced(CLEAR LIBCXX_OVERRIDE_DARWIN_INSTALL) # Show the override option.
147 set(LIBCXX_INSTALL_HEADERS OFF)
148 set(LIBCXX_INSTALL_LIBRARY OFF)
149 endif()
150endif()
151
Eric Fiseliereb6e2ea2015-07-30 22:30:34152#===============================================================================
153# Check option configurations
154#===============================================================================
155
156# Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON only when
157# LIBCXX_ENABLE_THREADS is on.
158if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_ENABLE_MONOTONIC_CLOCK)
159 message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF"
160 " when LIBCXX_ENABLE_THREADS is also set to OFF.")
Eric Fiselier25a15162014-08-18 05:03:46161endif()
Michael J. Spencer626916f2010-12-10 19:47:54162
Eric Fiseliereb6e2ea2015-07-30 22:30:34163# Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE
164# is ON.
165if (LLVM_USE_SANITIZER AND LIBCXX_GENERATE_COVERAGE)
166 message(FATAL_ERROR "LLVM_USE_SANITIZER cannot be used with LIBCXX_GENERATE_COVERAGE")
167endif()
168
169# Set LIBCXX_BUILD_32_BITS to (LIBCXX_BUILD_32_BITS OR LLVM_BUILD_32_BITS)
170# and check that we can build with 32 bits if requested.
171if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32)
172 if (LIBCXX_BUILD_32_BITS AND NOT LLVM_BUILD_32_BITS) # Don't duplicate the output from LLVM
173 message(STATUS "Building 32 bits executables and libraries.")
174 endif()
175elseif(LIBCXX_BUILD_32_BITS)
176 message(FATAL_ERROR "LIBCXX_BUILD_32_BITS=ON is not supported on this platform.")
177endif()
178
179# Check that this option is not enabled on Apple and emit a usage warning.
Eric Fiselierc0b166e2015-03-03 15:59:51180if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
181 if (APPLE)
182 message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is not supported on OS X")
183 else()
184 message(WARNING "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is an experimental option")
185 endif()
186endif()
187
Eric Fiselier8cbf0202015-10-14 19:54:03188if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
189 if (APPLE)
190 message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT cannot be used on APPLE targets")
191 endif()
192 if (NOT PYTHONINTERP_FOUND)
193 message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT requires python but it was not found.")
194 endif()
195endif()
196
197if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
198 message(FATAL_ERROR "Conflicting options given.
199 LIBCXX_ENABLE_STATIC_ABI_LIBRARY cannot be specified with
200 LIBCXX_ENABLE_ABI_LINKER_SCRIPT")
201endif()
202
Michael J. Spencer626916f2010-12-10 19:47:54203#===============================================================================
204# Configure System
205#===============================================================================
206
Eric Fiselier4778eed2014-12-20 03:16:55207set(LIBCXX_COMPILER ${CMAKE_CXX_COMPILER})
208set(LIBCXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
209set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
Chandler Carruth7a033ca2014-12-29 12:15:47210set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
Eric Fiselier4778eed2014-12-20 03:16:55211
Eric Fiseliereb6e2ea2015-07-30 22:30:34212set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
213set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
214
Eric Fiselier8e2855c2014-11-15 06:26:30215# Declare libc++ configuration variables.
216# They are intended for use as follows:
217# LIBCXX_CXX_FLAGS: General flags for both the compiler and linker.
218# LIBCXX_COMPILE_FLAGS: Compile only flags.
219# LIBCXX_LINK_FLAGS: Linker only flags.
Eric Fiselier8e2855c2014-11-15 06:26:30220set(LIBCXX_COMPILE_FLAGS "")
221set(LIBCXX_LINK_FLAGS "")
Eric Fiseliereb6e2ea2015-07-30 22:30:34222set(LIBCXX_LIBRARIES "")
Eric Fiselier8e2855c2014-11-15 06:26:30223
Eric Fiselier9a1468f2014-11-15 17:25:23224# Configure compiler.
225include(config-ix)
Eric Fiseliereb6e2ea2015-07-30 22:30:34226
Eric Fiselierbf9653d2015-03-31 04:15:45227# Configure coverage options.
228if (LIBCXX_GENERATE_COVERAGE)
229 include(CodeCoverage)
230 set(CMAKE_BUILD_TYPE "COVERAGE" CACHE STRING "" FORCE)
231endif()
Eric Fiselier9a1468f2014-11-15 17:25:23232
Eric Fiseliereb6e2ea2015-07-30 22:30:34233string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
234
Eric Fiselier9a1468f2014-11-15 17:25:23235#===============================================================================
236# Setup Compiler Flags
237#===============================================================================
238
Eric Fiseliereb6e2ea2015-07-30 22:30:34239include(HandleLibCXXABI) # Steup the ABI library flags
240
241# Include macros for adding and removing libc++ flags.
242include(HandleLibcxxFlags)
243
244# Remove flags that may have snuck in.
245remove_flags(-DNDEBUG -UNDEBUG -D_DEBUG
246 -stdlib=libc++ -stdlib=libstdc++ -lc++abi -m32)
247
Eric Fiselier499d8782015-10-13 23:56:33248# FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC.
Eric Fiselier7b081f62015-10-15 20:27:15249# Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors
250# so they don't get transformed into -Wno and -errors respectivly.
251remove_flags(-Wno-pedantic -pedantic-errors -pedantic)
Eric Fiselier499d8782015-10-13 23:56:33252
Eric Fiseliereb6e2ea2015-07-30 22:30:34253# Required flags ==============================================================
254add_compile_flags_if_supported(-std=c++11)
255if (NOT MSVC AND NOT LIBCXX_SUPPORTS_STD_EQ_CXX11_FLAG)
256 message(FATAL_ERROR "C++11 is required but the compiler does not support -std=c++11")
257endif()
258
Eric Fiselier5514d362015-07-29 23:46:55259# On all systems the system c++ standard library headers need to be excluded.
Eric Fiseliereb6e2ea2015-07-30 22:30:34260# MSVC only has -X, which disables all default includes; including the crt.
261# Thus, we do nothing and hope we don't accidentally include any of the C++
262# headers
263add_compile_flags_if_supported(-nostdinc++)
Eric Fiselierd74dee92015-07-29 21:07:28264
Eric Fiseliereb6e2ea2015-07-30 22:30:34265# Target flags ================================================================
266add_flags_if(LIBCXX_BUILD_32_BITS -m32)
267add_flags_if(LIBCXX_TARGET_TRIPLE "-target ${LIBCXX_TARGET_TRIPLE}")
268add_flags_if(LIBCXX_SYSROOT "--sysroot ${LIBCXX_SYSROOT}")
269add_flags_if(LIBCXX_GCC_TOOLCHAIN "-gcc-toolchain ${LIBCXX_GCC_TOOLCHAIN}")
Eric Fiselier91eeba82015-07-29 00:03:51270
Eric Fiseliereb6e2ea2015-07-30 22:30:34271# Warning flags ===============================================================
Eric Fiselier692177d2015-07-18 20:40:46272add_definitions(-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Eric Fiseliereb6e2ea2015-07-30 22:30:34273add_compile_flags_if_supported(
274 -Wall -W -Wwrite-strings
275 -Wno-unused-parameter -Wno-long-long
276 -Werror=return-type)
Michael J. Spencer626916f2010-12-10 19:47:54277if (LIBCXX_ENABLE_WERROR)
Eric Fiseliereb6e2ea2015-07-30 22:30:34278 add_compile_flags_if_supported(-Werror)
279 add_compile_flags_if_supported(-WX)
Eric Fiselier26d23902015-07-31 01:25:01280else()
281 # TODO(EricWF) Remove this. We shouldn't be suppressing errors when -Werror is
282 # added elsewhere.
283 add_compile_flags_if_supported(-Wno-error)
Michael J. Spencer626916f2010-12-10 19:47:54284endif()
285if (LIBCXX_ENABLE_PEDANTIC)
Eric Fiseliereb6e2ea2015-07-30 22:30:34286 add_compile_flags_if_supported(-pedantic)
Michael J. Spencer626916f2010-12-10 19:47:54287endif()
288
Eric Fiseliereb6e2ea2015-07-30 22:30:34289# Exception flags =============================================================
Michael J. Spencer626916f2010-12-10 19:47:54290if (LIBCXX_ENABLE_EXCEPTIONS)
291 # Catches C++ exceptions only and tells the compiler to assume that extern C
292 # functions never throw a C++ exception.
Eric Fiseliereb6e2ea2015-07-30 22:30:34293 add_compile_flags_if_supported(-EHsc)
Michael J. Spencer626916f2010-12-10 19:47:54294else()
Eric Fiseliereb6e2ea2015-07-30 22:30:34295 add_definitions(-D_LIBCPP_NO_EXCEPTIONS)
296 add_compile_flags_if_supported(-EHs- -EHa-)
297 add_compile_flags_if_supported(-fno-exceptions)
Michael J. Spencer626916f2010-12-10 19:47:54298endif()
Eric Fiseliereb6e2ea2015-07-30 22:30:34299
300# RTTI flags ==================================================================
Michael J. Spencer626916f2010-12-10 19:47:54301if (NOT LIBCXX_ENABLE_RTTI)
Eric Fiseliereb6e2ea2015-07-30 22:30:34302 add_definitions(-D_LIBCPP_NO_RTTI)
303 add_compile_flags_if_supported(-GR-)
304 add_compile_flags_if_supported(-fno-rtti)
Michael J. Spencer626916f2010-12-10 19:47:54305endif()
Eric Fiseliereb6e2ea2015-07-30 22:30:34306
307# Assertion flags =============================================================
308define_if(LIBCXX_ENABLE_ASSERTIONS -UNDEBUG)
309define_if_not(LIBCXX_ENABLE_ASSERTIONS -DNDEBUG)
Howard Hinnante103a3d2012-08-05 17:37:39310if (LIBCXX_ENABLE_ASSERTIONS)
Michael J. Spencer626916f2010-12-10 19:47:54311 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
Eric Fiseliereb6e2ea2015-07-30 22:30:34312 define_if_not(MSVC -D_DEBUG)
Howard Hinnant4a0e74f2013-02-25 15:50:36313endif()
Michael J. Spencer626916f2010-12-10 19:47:54314
Eric Fiseliereb6e2ea2015-07-30 22:30:34315# Feature flags ===============================================================
316define_if(MSVC -D_CRT_SECURE_NO_WARNINGS)
Eric Fiselier5514d362015-07-29 23:46:55317
Jonathan Roelofs5e91fa12015-08-24 21:20:07318# Sanitizer flags =============================================================
Eric Fiselier5514d362015-07-29 23:46:55319
320# Configure for sanitizers. If LIBCXX_BUILT_STANDALONE then we have to do
321# the flag translation ourselves. Othewise LLVM's CMakeList.txt will handle it.
322if (LIBCXX_BUILT_STANDALONE)
Eric Fiseliereb6e2ea2015-07-30 22:30:34323 set(LLVM_USE_SANITIZER "" CACHE STRING
324 "Define the sanitizer used to build the library and tests")
Eric Fiselier5514d362015-07-29 23:46:55325 # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC.
326 # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do.
327 if (LLVM_USE_SANITIZER AND NOT MSVC)
Eric Fiseliereb6e2ea2015-07-30 22:30:34328 add_flags_if_supported("-fno-omit-frame-pointer")
329 add_flags_if_supported("-gline-tables-only")
330
Eric Fiselier5514d362015-07-29 23:46:55331 if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND
332 NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
Eric Fiseliereb6e2ea2015-07-30 22:30:34333 add_flags_if_supported("-gline-tables-only")
Eric Fiselier5514d362015-07-29 23:46:55334 endif()
335 if (LLVM_USE_SANITIZER STREQUAL "Address")
Eric Fiseliereb6e2ea2015-07-30 22:30:34336 add_flags("-fsanitize=address")
Eric Fiselier5514d362015-07-29 23:46:55337 elseif (LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?")
Eric Fiseliereb6e2ea2015-07-30 22:30:34338 add_flags(-fsanitize=memory)
Eric Fiselier5514d362015-07-29 23:46:55339 if (LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins")
Eric Fiseliereb6e2ea2015-07-30 22:30:34340 add_flags("-fsanitize-memory-track-origins")
Eric Fiselier5514d362015-07-29 23:46:55341 endif()
342 elseif (LLVM_USE_SANITIZER STREQUAL "Undefined")
Eric Fiseliereb6e2ea2015-07-30 22:30:34343 add_flags("-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all")
Eric Fiselier5514d362015-07-29 23:46:55344 elseif (LLVM_USE_SANITIZER STREQUAL "Thread")
Eric Fiseliereb6e2ea2015-07-30 22:30:34345 add_flags(-fsanitize=thread)
Eric Fiselier5514d362015-07-29 23:46:55346 else()
347 message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}")
348 endif()
Eric Fiseliereb6e2ea2015-07-30 22:30:34349 elseif(LLVM_USE_SANITIZER AND MSVC)
350 message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.")
Eric Fiselier5514d362015-07-29 23:46:55351 endif()
352endif()
Eric Fiselier73ffc782015-10-13 22:12:02353
354# Configuration file flags =====================================================
Evgeniy Stepanov4f01aa82015-10-13 23:48:28355if (NOT LIBCXX_ABI_VERSION EQUAL "1")
356 config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION)
357endif()
358config_define_if(LIBCXX_ABI_UNSTABLE _LIBCPP_ABI_UNSTABLE)
359
Eric Fiselier73ffc782015-10-13 22:12:02360config_define_if_not(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE)
361config_define_if_not(LIBCXX_ENABLE_STDIN _LIBCPP_HAS_NO_STDIN)
362config_define_if_not(LIBCXX_ENABLE_STDOUT _LIBCPP_HAS_NO_STDOUT)
363config_define_if_not(LIBCXX_ENABLE_THREADS _LIBCPP_HAS_NO_THREADS)
364config_define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK _LIBCPP_HAS_NO_MONOTONIC_CLOCK)
365config_define_if_not(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS)
366
367if (LIBCXX_NEEDS_SITE_CONFIG)
368 configure_file(
369 include/__config_site.in
370 ${LIBCXX_BINARY_DIR}/__config_site
371 @ONLY)
Eric Fiseliera6622792015-10-14 00:22:05372 # Provide the config definitions by included the generated __config_site
373 # file at compile time.
374 add_compile_flags("-include ${LIBCXX_BINARY_DIR}/__config_site")
Eric Fiselier73ffc782015-10-13 22:12:02375endif()
376
Michael J. Spencer626916f2010-12-10 19:47:54377#===============================================================================
Eric Fiseliereb6e2ea2015-07-30 22:30:34378# Setup Source Code And Tests
Michael J. Spencer626916f2010-12-10 19:47:54379#===============================================================================
Michael J. Spencer626916f2010-12-10 19:47:54380include_directories(include)
Howard Hinnantc4962b32013-11-15 17:18:57381add_subdirectory(include)
Michael J. Spencer626916f2010-12-10 19:47:54382add_subdirectory(lib)
Eric Fiselierb9f425a2015-08-22 19:40:49383
Eric Fiseliereb6e2ea2015-07-30 22:30:34384if (LIBCXX_INCLUDE_TESTS)
385 add_subdirectory(test)
386endif()
Eric Fiselierb9f425a2015-08-22 19:40:49387if (LIBCXX_INCLUDE_DOCS)
388 add_subdirectory(docs)
389endif()