blob: 35eb13036ef51a22a31366a4efe8f4681e1fd29d [file] [log] [blame]
Martell Malone380a70a2017-06-01 00:09:20 +00001# See www/CMake.html for instructions on how to build libcxxabi with CMake.
2
Dan Alberte11c1a72014-07-03 19:35:48 +00003#===============================================================================
4# Setup Project
5#===============================================================================
6
Chris Bieneman1fc2ce82016-05-31 20:21:53 +00007cmake_minimum_required(VERSION 3.4.3)
Dan Alberte11c1a72014-07-03 19:35:48 +00008
Eric Fiselierff417a52015-01-26 22:00:30 +00009if(POLICY CMP0042)
10 cmake_policy(SET CMP0042 NEW) # Set MACOSX_RPATH=YES by default
11endif()
12
Petr Hoseka9174192017-04-07 20:10:41 +000013# Add path for custom modules
14set(CMAKE_MODULE_PATH
15 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
16 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
17 ${CMAKE_MODULE_PATH}
18 )
19
Dan Alberte11c1a72014-07-03 19:35:48 +000020if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
Martell Malone380a70a2017-06-01 00:09:20 +000021 project(libcxxabi CXX C)
Dan Alberte11c1a72014-07-03 19:35:48 +000022
23 set(PACKAGE_NAME libcxxabi)
Hans Wennborgfaa22f32018-01-03 15:42:34 +000024 set(PACKAGE_VERSION 7.0.0svn)
Dan Alberte11c1a72014-07-03 19:35:48 +000025 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
Tanya Lattnerd8093df2015-08-05 04:01:26 +000026 set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org")
Dan Alberte11c1a72014-07-03 19:35:48 +000027
Martell Malone380a70a2017-06-01 00:09:20 +000028 # Find the LLVM sources and simulate LLVM CMake options.
29 include(HandleOutOfTreeLLVM)
Dan Alberte11c1a72014-07-03 19:35:48 +000030endif()
31
Martell Malone380a70a2017-06-01 00:09:20 +000032# Require out of source build.
33include(MacroEnsureOutOfSourceBuild)
34MACRO_ENSURE_OUT_OF_SOURCE_BUILD(
35 "${PROJECT_NAME} requires an out of source build. Please create a separate
36 build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there."
37 )
38
Dan Alberte11c1a72014-07-03 19:35:48 +000039#===============================================================================
40# Setup CMake Options
41#===============================================================================
Martell Malone380a70a2017-06-01 00:09:20 +000042include(CMakeDependentOption)
Petr Hoseka9174192017-04-07 20:10:41 +000043include(HandleCompilerRT)
Dan Alberte11c1a72014-07-03 19:35:48 +000044
45# Define options.
Asiri Rathnayake4174e8b2016-05-31 12:01:32 +000046option(LIBCXXABI_ENABLE_EXCEPTIONS "Use exceptions." ON)
Dan Alberte11c1a72014-07-03 19:35:48 +000047option(LIBCXXABI_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
48option(LIBCXXABI_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
49option(LIBCXXABI_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
Saleem Abdulrasool352f1342015-04-28 02:09:53 +000050option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF)
Petr Hosekb052fac2017-02-09 02:19:30 +000051option(LIBCXXABI_ENABLE_STATIC_UNWINDER "Statically link the LLVM unwinder." OFF)
Saleem Abdulrasoolf0a26202016-07-15 00:49:42 +000052option(LIBCXXABI_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
Eric Fiselierd872a692014-11-24 22:42:03 +000053option(LIBCXXABI_ENABLE_THREADS "Build with threads enabled" ON)
Ben Craigb06c53c2016-05-25 17:37:38 +000054option(LIBCXXABI_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF)
Asiri Rathnayake71ba2872017-01-03 12:58:34 +000055option(LIBCXXABI_HAS_EXTERNAL_THREAD_API
56 "Build libc++abi with an externalized threading API.
57 This option may only be set to ON when LIBCXXABI_ENABLE_THREADS=ON." OFF)
Asiri Rathnayake1f4def22017-01-09 11:57:21 +000058option(LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY
59 "Build libc++abi with an externalized threading library.
60 This option may only be set to ON when LIBCXXABI_ENABLE_THREADS=ON" OFF)
Eric Fiseliered5abb12017-03-02 21:55:17 +000061
62# FIXME: This option should default to off. Unfortunatly GCC 4.9 fails to link
63# programs to due undefined references to new/delete in libc++abi. Once this
64# has been fixed or worked around the default value should be changed.
Eric Fiselier48410622017-03-02 19:34:35 +000065option(LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS
66 "Build libc++abi with definitions for operator new/delete. Normally libc++
Eric Fiseliered5abb12017-03-02 21:55:17 +000067 provides these definitions" ON)
Eric Fiselier046d2fc2016-06-02 02:18:31 +000068option(LIBCXXABI_BUILD_32_BITS "Build 32 bit libc++abi." ${LLVM_BUILD_32_BITS})
Bryant Wongebc9aca2017-01-07 22:14:04 +000069option(LIBCXXABI_INCLUDE_TESTS "Generate build targets for the libc++abi unit tests." ${LLVM_INCLUDE_TESTS})
Ismail Donmez878d4bb2017-06-13 08:16:44 +000070set(LIBCXXABI_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
71 "Define suffix of library directory name (32/64)")
Petr Hosek43600b42017-11-17 23:25:09 +000072option(LIBCXXABI_INSTALL_LIBRARY "Install the libc++abi library." ON)
Eric Fiselier046d2fc2016-06-02 02:18:31 +000073set(LIBCXXABI_TARGET_TRIPLE "" CACHE STRING "Target triple for cross compiling.")
Ben Craig4ed725d2016-06-01 12:50:30 +000074set(LIBCXXABI_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
75set(LIBCXXABI_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")
76set(LIBCXXABI_LIBCXX_LIBRARY_PATH "" CACHE PATH "The path to libc++ library.")
Dan Albertfd961bd2014-07-10 02:20:11 +000077
78# Default to building a shared library so that the default options still test
79# the libc++abi that is being built. There are two problems with testing a
80# static libc++abi. In the case of a standalone build, the tests will link the
81# system's libc++, which might not have been built against our libc++abi. In the
82# case of an in tree build, libc++ will prefer a dynamic libc++abi from the
83# system over a static libc++abi from the output directory.
84option(LIBCXXABI_ENABLE_SHARED "Build libc++abi as a shared library." ON)
Eric Fiselierd95080e2015-03-03 15:59:09 +000085option(LIBCXXABI_ENABLE_STATIC "Build libc++abi as a static library." ON)
86
Ranjeet Singh2ecb4ee2017-03-01 11:42:01 +000087option(LIBCXXABI_BAREMETAL "Build libc++abi for baremetal targets." OFF)
88# The default terminate handler attempts to demangle uncaught exceptions, which
89# causes extra I/O and demangling code to be pulled in.
90option(LIBCXXABI_SILENT_TERMINATE "Set this to make the terminate handler default to a silent alternative" OFF)
91
Eric Fiselierd95080e2015-03-03 15:59:09 +000092if (NOT LIBCXXABI_ENABLE_SHARED AND NOT LIBCXXABI_ENABLE_STATIC)
93 message(FATAL_ERROR "libc++abi must be built as either a shared or static library.")
94endif()
Dan Albertfd961bd2014-07-10 02:20:11 +000095
Mehdi Amini6dc75812016-11-07 22:07:43 +000096if (LLVM_EXTERNAL_LIBCXX_SOURCE_DIR)
Petr Hosek4d14bc02016-11-11 19:12:58 +000097 set(LIBCXXABI_LIBCXX_SRC_DIRS ${LLVM_EXTERNAL_LIBCXX_SOURCE_DIR})
Mehdi Amini6dc75812016-11-07 22:07:43 +000098else()
Petr Hosek4d14bc02016-11-11 19:12:58 +000099 set(LIBCXXABI_LIBCXX_SRC_DIRS
100 "${LLVM_MAIN_SRC_DIR}/projects/libcxx"
101 "${LLVM_MAIN_SRC_DIR}/runtimes/libcxx"
102 )
Mehdi Amini6dc75812016-11-07 22:07:43 +0000103endif()
104
Petr Hosek4d14bc02016-11-11 19:12:58 +0000105set(LIBCXXABI_LIBCXX_INCLUDE_DIRS "")
106foreach(dir ${LIBCXXABI_LIBCXX_SRC_DIRS})
107 list(APPEND LIBCXXABI_LIBCXX_INCLUDE_DIRS "${dir}/include")
108endforeach()
109
Dan Albertfd961bd2014-07-10 02:20:11 +0000110find_path(
111 LIBCXXABI_LIBCXX_INCLUDES
112 vector
113 PATHS ${LIBCXXABI_LIBCXX_INCLUDES}
Eric Fiselier9a9e9392015-01-22 20:00:06 +0000114 ${LIBCXXABI_LIBCXX_PATH}/include
Dan Albertfd961bd2014-07-10 02:20:11 +0000115 ${CMAKE_BINARY_DIR}/${LIBCXXABI_LIBCXX_INCLUDES}
Petr Hosek4d14bc02016-11-11 19:12:58 +0000116 ${LIBCXXABI_LIBCXX_INCLUDE_DIRS}
Dan Albertfd961bd2014-07-10 02:20:11 +0000117 ${LLVM_INCLUDE_DIR}/c++/v1
Don Hinton16e9d9f2018-01-22 19:41:05 +0000118 NO_CMAKE_FIND_ROOT_PATH
Dan Albertfd961bd2014-07-10 02:20:11 +0000119 )
120
Eric Fiselier9a9e9392015-01-22 20:00:06 +0000121set(LIBCXXABI_LIBCXX_INCLUDES "${LIBCXXABI_LIBCXX_INCLUDES}" CACHE PATH
Dan Albertfd961bd2014-07-10 02:20:11 +0000122 "Specify path to libc++ includes." FORCE)
Dan Alberte11c1a72014-07-03 19:35:48 +0000123
Eric Fiselier9a9e9392015-01-22 20:00:06 +0000124find_path(
125 LIBCXXABI_LIBCXX_PATH
Petr Hosekf0f02572017-02-18 04:37:59 +0000126 utils/libcxx/test/__init__.py
Eric Fiselier9a9e9392015-01-22 20:00:06 +0000127 PATHS ${LIBCXXABI_LIBCXX_PATH}
128 ${LIBCXXABI_LIBCXX_INCLUDES}/../
Petr Hosek4d14bc02016-11-11 19:12:58 +0000129 ${LIBCXXABI_LIBCXX_SRC_DIRS}
Eric Fiselier9a9e9392015-01-22 20:00:06 +0000130 NO_DEFAULT_PATH
Don Hinton16e9d9f2018-01-22 19:41:05 +0000131 NO_CMAKE_FIND_ROOT_PATH
Eric Fiselier9a9e9392015-01-22 20:00:06 +0000132 )
133
134if (LIBCXXABI_LIBCXX_PATH STREQUAL "LIBCXXABI_LIBCXX_PATH-NOTFOUND")
135 message(WARNING "LIBCXXABI_LIBCXX_PATH was not specified and couldn't be infered.")
136 set(LIBCXXABI_LIBCXX_PATH "")
137endif()
138
139set(LIBCXXABI_LIBCXX_PATH "${LIBCXXABI_LIBCXX_PATH}" CACHE PATH
140 "Specify path to libc++ source." FORCE)
141
Dan Alberte11c1a72014-07-03 19:35:48 +0000142#===============================================================================
143# Configure System
144#===============================================================================
145
146# Add path for custom modules
147set(CMAKE_MODULE_PATH
148 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
149 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
150 ${CMAKE_MODULE_PATH}
151 )
152
Chandler Carruth343559e2014-12-29 12:22:04 +0000153set(LIBCXXABI_COMPILER ${CMAKE_CXX_COMPILER})
154set(LIBCXXABI_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
155set(LIBCXXABI_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
Jonas Hahnfelda4c45452017-05-04 06:04:49 +0000156if (LLVM_LIBRARY_OUTPUT_INTDIR)
157 set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
158else()
159 set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX})
160endif()
Chandler Carruth343559e2014-12-29 12:22:04 +0000161
Petr Hosek1f8318f2017-07-11 01:42:26 +0000162set(LIBCXXABI_INSTALL_PREFIX "" CACHE STRING
163 "Define libc++abi destination prefix.")
164
165if (NOT LIBCXXABI_INSTALL_PREFIX MATCHES "^$|.*/")
166 message(FATAL_ERROR "LIBCXXABI_INSTALL_PREFIX has to end with \"/\".")
167endif()
168
Ben Craig80b6b682016-04-18 13:30:38 +0000169set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR})
170set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR})
Martell Malone380a70a2017-06-01 00:09:20 +0000171set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR})
Ben Craig80b6b682016-04-18 13:30:38 +0000172
Ben Craig4ed725d2016-06-01 12:50:30 +0000173# By default, for non-standalone builds, libcxx and libcxxabi share a library
174# directory.
175if (NOT LIBCXXABI_LIBCXX_LIBRARY_PATH)
176 set(LIBCXXABI_LIBCXX_LIBRARY_PATH "${LIBCXXABI_LIBRARY_DIR}" CACHE PATH
177 "The path to libc++ library.")
Eugene Zelenko99874102016-08-08 17:59:02 +0000178endif()
Eric Fiselier046d2fc2016-06-02 02:18:31 +0000179
180# Check that we can build with 32 bits if requested.
181if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32)
182 if (LIBCXXABI_BUILD_32_BITS AND NOT LLVM_BUILD_32_BITS) # Don't duplicate the output from LLVM
183 message(STATUS "Building 32 bits executables and libraries.")
184 endif()
185elseif(LIBCXXABI_BUILD_32_BITS)
186 message(FATAL_ERROR "LIBCXXABI_BUILD_32_BITS=ON is not supported on this platform.")
187endif()
188
Martell Malone380a70a2017-06-01 00:09:20 +0000189# Declare libc++abi configuration variables.
190# They are intended for use as follows:
191# LIBCXXABI_C_FLAGS: General flags for both the c++ compiler and linker.
192# LIBCXXABI_CXX_FLAGS: General flags for both the c++ compiler and linker.
193# LIBCXXABI_COMPILE_FLAGS: Compile only flags.
194# LIBCXXABI_LINK_FLAGS: Linker only flags.
195# LIBCXXABI_LIBRARIES: libraries libc++abi is linked to.
Eric Fiselier046d2fc2016-06-02 02:18:31 +0000196
Logan Chien1c5ae132015-01-22 13:39:08 +0000197set(LIBCXXABI_C_FLAGS "")
Eric Fiselierc365bb52014-11-18 20:37:53 +0000198set(LIBCXXABI_CXX_FLAGS "")
199set(LIBCXXABI_COMPILE_FLAGS "")
200set(LIBCXXABI_LINK_FLAGS "")
Martell Malone380a70a2017-06-01 00:09:20 +0000201set(LIBCXXABI_LIBRARIES "")
202
203# Include macros for adding and removing libc++abi flags.
204include(HandleLibcxxabiFlags)
205
206#===============================================================================
207# Setup Compiler Flags
208#===============================================================================
Eric Fiselierc365bb52014-11-18 20:37:53 +0000209
Eric Fiselier046d2fc2016-06-02 02:18:31 +0000210# Configure target flags
211add_target_flags_if(LIBCXXABI_BUILD_32_BITS "-m32")
212add_target_flags_if(LIBCXXABI_TARGET_TRIPLE
Petr Hosek2ef575d2017-04-16 06:08:34 +0000213 "--target=${LIBCXXABI_TARGET_TRIPLE}")
Eric Fiselier046d2fc2016-06-02 02:18:31 +0000214add_target_flags_if(LIBCXXABI_GCC_TOOLCHAIN
Petr Hosek2ef575d2017-04-16 06:08:34 +0000215 "--gcc-toolchain=${LIBCXXABI_GCC_TOOLCHAIN}")
Eric Fiselier046d2fc2016-06-02 02:18:31 +0000216add_target_flags_if(LIBCXXABI_SYSROOT
217 "--sysroot=${LIBCXXABI_SYSROOT}")
218
Eric Fiselier11052022016-11-13 22:27:00 +0000219if (LIBCXXABI_TARGET_TRIPLE)
220 set(TARGET_TRIPLE "${LIBCXXABI_TARGET_TRIPLE}")
221endif()
222
Eric Fiselier046d2fc2016-06-02 02:18:31 +0000223# Configure compiler. Must happen after setting the target flags.
224include(config-ix)
Eric Fiselierc365bb52014-11-18 20:37:53 +0000225
Dan Alberte11c1a72014-07-03 19:35:48 +0000226if (LIBCXXABI_HAS_NOSTDINCXX_FLAG)
Eric Fiselierc365bb52014-11-18 20:37:53 +0000227 list(APPEND LIBCXXABI_COMPILE_FLAGS -nostdinc++)
228 # Remove -stdlib flags to prevent them from causing an unused flag warning.
229 string(REPLACE "-stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
230 string(REPLACE "-stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
Dan Alberte11c1a72014-07-03 19:35:48 +0000231endif()
Dan Alberte11c1a72014-07-03 19:35:48 +0000232
Saleem Abdulrasoolf0a26202016-07-15 00:49:42 +0000233if (LIBCXXABI_USE_COMPILER_RT)
234 list(APPEND LIBCXXABI_LINK_FLAGS "-rtlib=compiler-rt")
Eugene Zelenko99874102016-08-08 17:59:02 +0000235endif()
Eric Fiselierc365bb52014-11-18 20:37:53 +0000236
Shoaib Meenaia0863312016-09-27 03:44:09 +0000237# Let the library headers know they are currently being used to build the
238# library.
239add_definitions(-D_LIBCXXABI_BUILDING_LIBRARY)
240
241# Disable DLL annotations on Windows for static builds.
242if (WIN32 AND LIBCXXABI_ENABLE_STATIC AND NOT LIBCXXABI_ENABLE_SHARED)
Martell Malone9111b9c2017-05-28 22:46:50 +0000243 add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS)
Shoaib Meenaia0863312016-09-27 03:44:09 +0000244endif()
245
Martell Malone380a70a2017-06-01 00:09:20 +0000246add_compile_flags_if_supported(-Werror=return-type)
Dan Alberte11c1a72014-07-03 19:35:48 +0000247
248# Get warning flags
Martell Malone380a70a2017-06-01 00:09:20 +0000249add_compile_flags_if_supported(-W)
250add_compile_flags_if_supported(-Wall)
251add_compile_flags_if_supported(-Wchar-subscripts)
252add_compile_flags_if_supported(-Wconversion)
253add_compile_flags_if_supported(-Wmismatched-tags)
254add_compile_flags_if_supported(-Wmissing-braces)
255add_compile_flags_if_supported(-Wnewline-eof)
256add_compile_flags_if_supported(-Wunused-function)
257add_compile_flags_if_supported(-Wshadow)
258add_compile_flags_if_supported(-Wshorten-64-to-32)
259add_compile_flags_if_supported(-Wsign-compare)
260add_compile_flags_if_supported(-Wsign-conversion)
261add_compile_flags_if_supported(-Wstrict-aliasing=2)
262add_compile_flags_if_supported(-Wstrict-overflow=4)
263add_compile_flags_if_supported(-Wunused-parameter)
264add_compile_flags_if_supported(-Wunused-variable)
265add_compile_flags_if_supported(-Wwrite-strings)
266add_compile_flags_if_supported(-Wundef)
Dan Albertf1982192014-07-10 22:23:03 +0000267
Dan Alberte11c1a72014-07-03 19:35:48 +0000268if (LIBCXXABI_ENABLE_WERROR)
Martell Malone380a70a2017-06-01 00:09:20 +0000269 add_compile_flags_if_supported(-Werror)
270 add_compile_flags_if_supported(-WX)
Dan Alberte11c1a72014-07-03 19:35:48 +0000271else()
Martell Malone380a70a2017-06-01 00:09:20 +0000272 add_compile_flags_if_supported(-Wno-error)
273 add_compile_flags_if_supported(-WX-)
Dan Alberte11c1a72014-07-03 19:35:48 +0000274endif()
275if (LIBCXXABI_ENABLE_PEDANTIC)
Martell Malone380a70a2017-06-01 00:09:20 +0000276 add_compile_flags_if_supported(-pedantic)
Dan Alberte11c1a72014-07-03 19:35:48 +0000277endif()
278
279# Get feature flags.
Martell Malone380a70a2017-06-01 00:09:20 +0000280add_compile_flags_if_supported(-fstrict-aliasing)
Dan Alberte11c1a72014-07-03 19:35:48 +0000281
Asiri Rathnayake4174e8b2016-05-31 12:01:32 +0000282# Exceptions
283if (LIBCXXABI_ENABLE_EXCEPTIONS)
284 # Catches C++ exceptions only and tells the compiler to assume that extern C
285 # functions never throw a C++ exception.
Martell Malone380a70a2017-06-01 00:09:20 +0000286 add_compile_flags_if_supported(-EHsc)
287 # Do we really need to be run through the C compiler ?
288 add_c_compile_flags_if_supported(-funwind-tables)
Asiri Rathnayake4174e8b2016-05-31 12:01:32 +0000289else()
290 add_definitions(-D_LIBCXXABI_NO_EXCEPTIONS)
Martell Malone380a70a2017-06-01 00:09:20 +0000291 add_compile_flags_if_supported(-fno-exceptions)
292 add_compile_flags_if_supported(-EHs-)
293 add_compile_flags_if_supported(-EHa-)
Asiri Rathnayake4174e8b2016-05-31 12:01:32 +0000294endif()
Logan Chien1c5ae132015-01-22 13:39:08 +0000295
Dan Alberte11c1a72014-07-03 19:35:48 +0000296# Assert
297string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
298if (LIBCXXABI_ENABLE_ASSERTIONS)
299 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
300 if (NOT MSVC)
Eric Fiselierc365bb52014-11-18 20:37:53 +0000301 list(APPEND LIBCXXABI_COMPILE_FLAGS -D_DEBUG)
Dan Alberte11c1a72014-07-03 19:35:48 +0000302 endif()
303 # On Release builds cmake automatically defines NDEBUG, so we
304 # explicitly undefine it:
305 if (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
Eric Fiselierc365bb52014-11-18 20:37:53 +0000306 list(APPEND LIBCXXABI_COMPILE_FLAGS -UNDEBUG)
Dan Alberte11c1a72014-07-03 19:35:48 +0000307 endif()
308else()
309 if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
Eric Fiselierc365bb52014-11-18 20:37:53 +0000310 list(APPEND LIBCXXABI_COMPILE_FLAGS -DNDEBUG)
Dan Alberte11c1a72014-07-03 19:35:48 +0000311 endif()
312endif()
313# Static library
314if (NOT LIBCXXABI_ENABLE_SHARED)
Eric Fiselierc365bb52014-11-18 20:37:53 +0000315 list(APPEND LIBCXXABI_COMPILE_FLAGS -D_LIBCPP_BUILD_STATIC)
Dan Alberte11c1a72014-07-03 19:35:48 +0000316endif()
317
Asiri Rathnayake71ba2872017-01-03 12:58:34 +0000318# Threading
Eric Fiselierd872a692014-11-24 22:42:03 +0000319if (NOT LIBCXXABI_ENABLE_THREADS)
Ben Craigb06c53c2016-05-25 17:37:38 +0000320 if (LIBCXXABI_HAS_PTHREAD_API)
321 message(FATAL_ERROR "LIBCXXABI_HAS_PTHREAD_API can only"
322 " be set to ON when LIBCXXABI_ENABLE_THREADS"
323 " is also set to ON.")
324 endif()
Asiri Rathnayake71ba2872017-01-03 12:58:34 +0000325 if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
326 message(FATAL_ERROR "LIBCXXABI_HAS_EXTERNAL_THREAD_API can only"
327 " be set to ON when LIBCXXABI_ENABLE_THREADS"
328 " is also set to ON.")
329 endif()
Asiri Rathnayake1f4def22017-01-09 11:57:21 +0000330 if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY)
331 message(FATAL_ERROR "LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY can only"
332 " be set to ON when LIBCXXABI_ENABLE_THREADS"
333 " is also set to ON.")
334 endif()
Asiri Rathnayakeb62a4dd2016-09-21 09:09:32 +0000335 add_definitions(-D_LIBCXXABI_HAS_NO_THREADS)
Eric Fiselierd872a692014-11-24 22:42:03 +0000336endif()
337
Asiri Rathnayake1f4def22017-01-09 11:57:21 +0000338if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
339 if (LIBCXXABI_HAS_PTHREAD_API)
340 message(FATAL_ERROR "The options LIBCXXABI_HAS_EXTERNAL_THREAD_API"
341 " and LIBCXXABI_HAS_PTHREAD_API cannot be both"
342 " set to ON at the same time.")
343 endif()
344 if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY)
345 message(FATAL_ERROR "The options LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY"
346 " and LIBCXXABI_HAS_EXTERNAL_THREAD_API cannot be both"
347 " set to ON at the same time.")
348 endif()
Asiri Rathnayake71ba2872017-01-03 12:58:34 +0000349endif()
350
NAKAMURA Takumif4afd552017-07-31 09:35:08 +0000351if (LLVM_ENABLE_MODULES)
352 # Ignore that the rest of the modules flags are now unused.
353 add_compile_flags_if_supported(-Wno-unused-command-line-argument)
354 add_compile_flags(-fno-modules)
355endif()
356
Eric Fiselier0368af02017-03-04 02:15:37 +0000357set(LIBCXXABI_HAS_UNDEFINED_SYMBOLS OFF)
358if ((NOT LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS)
Eric Fiselier2d383292017-05-11 03:49:48 +0000359 OR (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY AND LIBCXXABI_ENABLE_SHARED)
360 OR MINGW)
Eric Fiselier0368af02017-03-04 02:15:37 +0000361 set(LIBCXXABI_HAS_UNDEFINED_SYMBOLS ON)
362endif()
Eric Fiselier48410622017-03-02 19:34:35 +0000363
364if (LIBCXXABI_HAS_UNDEFINED_SYMBOLS)
Asiri Rathnayake71ba2872017-01-03 12:58:34 +0000365 # Need to allow unresolved symbols if this is to work with shared library builds
366 if (APPLE)
Eric Fiselier0368af02017-03-04 02:15:37 +0000367 list(APPEND LIBCXXABI_LINK_FLAGS "-undefined dynamic_lookup")
Asiri Rathnayake71ba2872017-01-03 12:58:34 +0000368 else()
369 # Relax this restriction from HandleLLVMOptions
370 string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
371 endif()
372endif()
373
Ben Craigb06c53c2016-05-25 17:37:38 +0000374if (LIBCXXABI_HAS_PTHREAD_API)
375 add_definitions(-D_LIBCPP_HAS_THREAD_API_PTHREAD)
376endif()
377
Asiri Rathnayake71ba2872017-01-03 12:58:34 +0000378if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
Asiri Rathnayake1f4def22017-01-09 11:57:21 +0000379 add_definitions(-D_LIBCPP_HAS_THREAD_API_EXTERNAL)
380endif()
381
382if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY)
383 add_definitions(-D_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL)
Asiri Rathnayake71ba2872017-01-03 12:58:34 +0000384endif()
385
Shoaib Meenai03d803f2017-05-10 21:52:39 +0000386# Prevent libc++abi from having library dependencies on libc++
387add_definitions(-D_LIBCPP_DISABLE_EXTERN_TEMPLATE)
388
Dan Alberte11c1a72014-07-03 19:35:48 +0000389if (MSVC)
390 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
391endif()
392
Logan Chien083506f2015-01-22 13:27:36 +0000393# Define LIBCXXABI_USE_LLVM_UNWINDER for conditional compilation.
Logan Chien6962eb32016-11-13 14:42:15 +0000394if (LIBCXXABI_USE_LLVM_UNWINDER)
Ranjeet Singh2ecb4ee2017-03-01 11:42:01 +0000395 add_definitions(-DLIBCXXABI_USE_LLVM_UNWINDER)
Logan Chien083506f2015-01-22 13:27:36 +0000396endif()
397
James Y Knight0ecfd762017-01-13 19:22:26 +0000398if (LIBCXXABI_SILENT_TERMINATE)
Ranjeet Singh2ecb4ee2017-03-01 11:42:01 +0000399 add_definitions(-DLIBCXXABI_SILENT_TERMINATE)
400endif()
401
402if (LIBCXXABI_BAREMETAL)
403 add_definitions(-DLIBCXXABI_BAREMETAL)
James Y Knight0ecfd762017-01-13 19:22:26 +0000404endif()
405
Eric Fiselierc365bb52014-11-18 20:37:53 +0000406string(REPLACE ";" " " LIBCXXABI_CXX_FLAGS "${LIBCXXABI_CXX_FLAGS}")
407set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXXABI_CXX_FLAGS}")
Logan Chien1c5ae132015-01-22 13:39:08 +0000408set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBCXXABI_C_FLAGS}")
Dan Alberte11c1a72014-07-03 19:35:48 +0000409
410#===============================================================================
411# Setup Source Code
412#===============================================================================
413
Anton Korobeynikovc5096602015-05-08 16:10:11 +0000414set(LIBCXXABI_LIBUNWIND_INCLUDES "${LIBCXXABI_LIBUNWIND_INCLUDES}" CACHE PATH
415 "Specify path to libunwind includes." FORCE)
416set(LIBCXXABI_LIBUNWIND_PATH "${LIBCXXABI_LIBUNWIND_PATH}" CACHE PATH
417 "Specify path to libunwind source." FORCE)
418
Dan Alberte11c1a72014-07-03 19:35:48 +0000419include_directories(include)
Eric Fiselier36414032015-04-29 15:53:03 +0000420if (LIBCXXABI_USE_LLVM_UNWINDER OR LLVM_NATIVE_ARCH MATCHES ARM)
Anton Korobeynikovc5096602015-05-08 16:10:11 +0000421 find_path(
Anton Korobeynikovf6626662015-05-09 21:03:01 +0000422 LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL
Anton Korobeynikovc5096602015-05-08 16:10:11 +0000423 libunwind.h
424 PATHS ${LIBCXXABI_LIBUNWIND_INCLUDES}
425 ${LIBCXXABI_LIBUNWIND_PATH}/include
426 ${CMAKE_BINARY_DIR}/${LIBCXXABI_LIBUNWIND_INCLUDES}
427 ${LLVM_MAIN_SRC_DIR}/projects/libunwind/include
Petr Hosek4d14bc02016-11-11 19:12:58 +0000428 ${LLVM_MAIN_SRC_DIR}/runtimes/libunwind/include
Anton Korobeynikovf6626662015-05-09 21:03:01 +0000429 NO_DEFAULT_PATH
Don Hinton16e9d9f2018-01-22 19:41:05 +0000430 NO_CMAKE_FIND_ROOT_PATH
Anton Korobeynikovc5096602015-05-08 16:10:11 +0000431 )
432
Asiri Rathnayake0a3a1a82017-04-04 14:03:54 +0000433 if (LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL "LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL-NOTFOUND")
434 set(LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL "")
435 endif()
436
437 if (NOT LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL "")
Michal Gornyed611022017-01-14 17:05:16 +0000438 include_directories("${LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL}")
439 endif()
Eugene Zelenko99874102016-08-08 17:59:02 +0000440endif()
Dan Alberte11c1a72014-07-03 19:35:48 +0000441
442# Add source code. This also contains all of the logic for deciding linker flags
443# soname, etc...
444add_subdirectory(src)
Dan Albertfd961bd2014-07-10 02:20:11 +0000445
Don Hinton0d2ebaa2018-01-18 18:29:36 +0000446if (LIBCXXABI_INCLUDE_TESTS)
447 if (LIBCXXABI_STANDALONE_BUILD AND NOT LIBCXXABI_ENABLE_SHARED)
448 # We can't reasonably test the system C++ library with a static
449 # libc++abi. We either need to be able to replace libc++abi at
450 # run time (with a shared libc++abi), or we need to be able to
451 # replace the C++ runtime (with a non- standalone build).
452 message(WARNING "The libc++abi tests aren't valid when libc++abi "
453 "is built standalone (i.e. outside of "
454 "llvm/projects/libcxxabi ) and is built without "
455 "a shared library. Either build a shared "
456 "library, build libc++abi at the same time as "
457 "you build libc++, or do without testing. No "
458 "check target will be available!")
459 else()
460 add_subdirectory(test)
461 add_subdirectory(fuzz)
462 endif()
Dan Albertfd961bd2014-07-10 02:20:11 +0000463endif()