blob: 068074cef28e822e5693a948148adde8ad567330 [file] [log] [blame]
Dominik Montada9e379242020-08-24 11:01:05 +02001if (NOT IS_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/../libcxx")
2 message(FATAL_ERROR "libunwind requires being built in a monorepo layout with libcxx available")
3endif()
4
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +00005#===============================================================================
Tanya Lattnerfdfd2c12015-08-06 23:31:37 +00006# Setup Project
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +00007#===============================================================================
8
Louis Dionne7ee89bc2020-04-22 11:15:05 -04009cmake_minimum_required(VERSION 3.13.4)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000010
John Ericson6a10e3e2022-01-01 07:03:31 +000011set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
12
Petr Hosek9bbcefb2017-04-12 02:28:07 +000013# Add path for custom modules
John Ericson6a10e3e2022-01-01 07:03:31 +000014list(INSERT CMAKE_MODULE_PATH 0
Petr Hosek9bbcefb2017-04-12 02:28:07 +000015 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
16 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
John Ericson6a10e3e2022-01-01 07:03:31 +000017 "${LLVM_COMMON_CMAKE_UTILS}"
18 "${LLVM_COMMON_CMAKE_UTILS}/Modules"
Petr Hosek9bbcefb2017-04-12 02:28:07 +000019 )
20
Dominik Montada9e379242020-08-24 11:01:05 +020021set(LIBUNWIND_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
22set(LIBUNWIND_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
23set(LIBUNWIND_LIBCXX_PATH "${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH
24 "Specify path to libc++ source.")
25
Petr Hosek7aecb762019-05-30 07:34:39 +000026if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBUNWIND_STANDALONE_BUILD)
Louis Dionne107cd562022-02-08 11:38:29 -050027 message(FATAL_ERROR "The Standalone build has been deprecated since LLVM 14, and it is not supported anymore. "
28 "Please use one of the ways described at https://libcxx.llvm.org/BuildingLibcxx.html for "
29 "building libunwind.")
30
Martin Storsjö51ffc5e2021-09-10 22:14:48 +030031 # We may have an incomplete toolchain - do language support tests without
32 # linking.
33 include(EnableLanguageNolink)
34 project(libunwind LANGUAGES NONE)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000035
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000036 set(PACKAGE_NAME libunwind)
Tom Stellard659c7d92022-02-01 23:29:29 -080037 set(PACKAGE_VERSION 15.0.0git)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000038 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
Tanya Lattnera7abd9b2015-08-05 04:01:47 +000039 set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org")
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000040
John Ericson44f80b82022-01-19 06:45:07 +000041 set(LIBUNWIND_STANDALONE_BUILD TRUE)
42endif()
43
44# Must go below project(..)
45include(GNUInstallDirs)
46
47if(LIBUNWIND_STANDALONE_BUILD)
48 llvm_enable_language_nolink(C CXX ASM)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000049
Dominik Montada9e379242020-08-24 11:01:05 +020050 # Find the LLVM sources and simulate LLVM CMake options.
51 include(HandleOutOfTreeLLVM)
John Ericson44f80b82022-01-19 06:45:07 +000052
53 # In a standalone build, we don't have llvm to automatically generate the
54 # llvm-lit script for us. So we need to provide an explicit directory that
55 # the configurator should write the script into.
56 set(LLVM_LIT_OUTPUT_DIR "${LIBUNWIND_BINARY_DIR}/bin")
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000057else()
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000058 set(LLVM_LIT "${CMAKE_SOURCE_DIR}/utils/lit/lit.py")
59endif()
60
61#===============================================================================
62# Setup CMake Options
63#===============================================================================
Petr Hosek68b2a0f2018-07-24 23:42:51 +000064include(CMakeDependentOption)
Petr Hosek9bbcefb2017-04-12 02:28:07 +000065include(HandleCompilerRT)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000066
67# Define options.
Louis Dionnea281fd32021-11-23 16:34:09 -050068option(LIBUNWIND_BUILD_32_BITS "Build 32 bit multilib libunwind. This option is not supported anymore when building the runtimes. Please specify a full triple instead." ${LLVM_BUILD_32_BITS})
69if (LIBUNWIND_BUILD_32_BITS)
Louis Dionne0f447a32021-12-01 12:57:30 -050070 message(FATAL_ERROR "LIBUNWIND_BUILD_32_BITS is not supported anymore when building the runtimes, please specify a full triple instead.")
Louis Dionnea281fd32021-11-23 16:34:09 -050071endif()
72
gejin7f493162021-08-26 16:20:38 +080073option(LIBUNWIND_ENABLE_CET "Build libunwind with CET enabled." OFF)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000074option(LIBUNWIND_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
75option(LIBUNWIND_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
76option(LIBUNWIND_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000077option(LIBUNWIND_ENABLE_SHARED "Build libunwind as a shared library." ON)
Petr Hosek35f87502016-08-08 22:55:48 +000078option(LIBUNWIND_ENABLE_STATIC "Build libunwind as a static library." ON)
Asiri Rathnayake8c94db92016-05-27 08:29:27 +000079option(LIBUNWIND_ENABLE_CROSS_UNWINDING "Enable cross-platform unwinding support." OFF)
Asiri Rathnayaked90f6812016-07-07 10:55:39 +000080option(LIBUNWIND_ENABLE_ARM_WMMX "Enable unwinding support for ARM WMMX registers." OFF)
Asiri Rathnayake6d434c82016-09-28 10:57:15 +000081option(LIBUNWIND_ENABLE_THREADS "Build libunwind with threading support." ON)
Sterling Augustine7f90e762019-05-13 18:45:03 +000082option(LIBUNWIND_WEAK_PTHREAD_LIB "Use weak references to refer to pthread functions." OFF)
Petr Hosek9bbcefb2017-04-12 02:28:07 +000083option(LIBUNWIND_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
Jonathan Roelofsa9bd4562017-03-28 15:21:43 +000084option(LIBUNWIND_INCLUDE_DOCS "Build the libunwind documentation." ${LLVM_INCLUDE_DOCS})
Kristina Bessonovadc676eb2021-02-13 12:49:47 +020085option(LIBUNWIND_INCLUDE_TESTS "Build the libunwind tests." ${LLVM_INCLUDE_TESTS})
Hafiz Abid Qadeer1fd0b1b2020-07-29 11:39:41 +010086option(LIBUNWIND_IS_BAREMETAL "Build libunwind for baremetal targets." OFF)
Sterling Augustineb778c912020-08-18 12:05:07 -070087option(LIBUNWIND_USE_FRAME_HEADER_CACHE "Cache frame headers for unwinding. Requires locking dl_iterate_phdr." OFF)
Daniel Kisscc1fc4e2020-11-11 10:58:41 +010088option(LIBUNWIND_REMEMBER_HEAP_ALLOC "Use heap instead of the stack for .cfi_remember_state." OFF)
PoYao Chang4ead6102021-12-16 13:32:12 -050089option(LIBUNWIND_INSTALL_HEADERS "Install the libunwind headers." OFF)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000090
Petr Hosek285a8f32017-08-08 00:37:59 +000091set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
92 "Define suffix of library directory name (32/64)")
Petr Hosek94bbfa62017-11-17 23:29:46 +000093option(LIBUNWIND_INSTALL_LIBRARY "Install the libunwind library." ON)
Petr Hosek106866a2018-07-24 23:27:51 +000094cmake_dependent_option(LIBUNWIND_INSTALL_STATIC_LIBRARY
95 "Install the static libunwind library." ON
96 "LIBUNWIND_ENABLE_STATIC;LIBUNWIND_INSTALL_LIBRARY" OFF)
97cmake_dependent_option(LIBUNWIND_INSTALL_SHARED_LIBRARY
98 "Install the shared libunwind library." ON
99 "LIBUNWIND_ENABLE_SHARED;LIBUNWIND_INSTALL_LIBRARY" OFF)
John Baldwin22b1bfd2018-02-27 18:40:04 +0000100set(LIBUNWIND_TEST_LINKER_FLAGS "" CACHE STRING
101 "Additional linker flags for test programs.")
102set(LIBUNWIND_TEST_COMPILER_FLAGS "" CACHE STRING
103 "Additional compiler flags for test programs.")
Louis Dionnebbd954d2021-10-12 14:10:02 -0400104
Louis Dionned1c7f922021-10-12 15:59:08 -0400105# TODO: Remove this after branching for LLVM 15
106if(LIBUNWIND_SYSROOT OR LIBUNWIND_TARGET_TRIPLE OR LIBUNWIND_GCC_TOOLCHAIN)
107 message(WARNING "LIBUNWIND_SYSROOT, LIBUNWIND_TARGET_TRIPLE and LIBUNWIND_GCC_TOOLCHAIN are not supported anymore, please use the native CMake equivalents instead")
108endif()
109
Louis Dionnebbd954d2021-10-12 14:10:02 -0400110if (LIBUNWIND_ENABLE_SHARED)
111 set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-shared.cfg.in")
112else()
113 set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-static.cfg.in")
114endif()
115set(LIBUNWIND_TEST_CONFIG "${LIBUNWIND_DEFAULT_TEST_CONFIG}" CACHE STRING
Louis Dionne15999e72021-09-29 15:26:05 -0400116 "The path to the Lit testing configuration to use when running the tests.
Louis Dionne10f4e4a2021-10-12 12:46:21 -0400117 If a relative path is provided, it is assumed to be relative to '<monorepo>/libunwind/test/configs'.")
Louis Dionne15999e72021-09-29 15:26:05 -0400118if (NOT IS_ABSOLUTE "${LIBUNWIND_TEST_CONFIG}")
Louis Dionne10f4e4a2021-10-12 12:46:21 -0400119 set(LIBUNWIND_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/configs/${LIBUNWIND_TEST_CONFIG}")
Louis Dionne15999e72021-09-29 15:26:05 -0400120endif()
Dominik Montada9e379242020-08-24 11:01:05 +0200121set(LIBUNWIND_TEST_PARAMS "" CACHE STRING
122 "A list of parameters to run the Lit test suite with.")
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000123
Petr Hosek35f87502016-08-08 22:55:48 +0000124if (NOT LIBUNWIND_ENABLE_SHARED AND NOT LIBUNWIND_ENABLE_STATIC)
125 message(FATAL_ERROR "libunwind must be built as either a shared or static library.")
126endif()
127
gejin7f493162021-08-26 16:20:38 +0800128if (LIBUNWIND_ENABLE_CET AND MSVC)
129 message(FATAL_ERROR "libunwind CET support is not available for MSVC!")
130endif()
131
Ryan Prichard8d5fb6f2021-02-22 16:35:38 -0800132option(LIBUNWIND_HIDE_SYMBOLS
Petr Hosek809c2b52019-01-29 23:01:08 +0000133 "Do not export any symbols from the static library." OFF)
134
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000135#===============================================================================
136# Configure System
137#===============================================================================
138
139# Add path for custom modules
140set(CMAKE_MODULE_PATH
141 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
142 ${CMAKE_MODULE_PATH})
143
John Ericson57e4aff2022-01-16 06:00:29 +0000144set(LIBUNWIND_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}" CACHE PATH
John Ericson834e4a32022-01-11 03:03:21 +0000145 "Path where built libunwind headers should be installed.")
John Ericson57e4aff2022-01-16 06:00:29 +0000146set(LIBUNWIND_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH
John Ericson834e4a32022-01-11 03:03:21 +0000147 "Path where built libunwind runtime libraries should be installed.")
148
Eric Christopher92b75a22018-06-29 20:27:40 +0000149if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
Petr Hosek5844fc62021-04-16 21:33:18 -0700150 set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
John Ericsona5feaf62021-04-28 22:36:47 +0000151 set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH
152 "Path where built libunwind libraries should be installed.")
Petr Hosek1f9c24d2019-05-22 21:08:33 +0000153 if(LIBCXX_LIBDIR_SUBDIR)
154 string(APPEND LIBUNWIND_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR})
155 string(APPEND LIBUNWIND_INSTALL_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR})
156 endif()
Petr Hosekae8b8512017-07-18 21:30:18 +0000157else()
John Ericson14da6e72022-01-09 00:08:15 +0000158 if(LLVM_LIBRARY_OUTPUT_INTDIR)
159 set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
160 else()
161 set(LIBUNWIND_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBUNWIND_LIBDIR_SUFFIX})
162 endif()
John Ericsona5feaf62021-04-28 22:36:47 +0000163 set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX} CACHE PATH
164 "Path where built libunwind libraries should be installed.")
Petr Hosekae8b8512017-07-18 21:30:18 +0000165endif()
166
167set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR})
168set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR})
169set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR})
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000170
Eric Fiselier077b6822016-06-02 01:02:10 +0000171set(LIBUNWIND_C_FLAGS "")
172set(LIBUNWIND_CXX_FLAGS "")
173set(LIBUNWIND_COMPILE_FLAGS "")
174set(LIBUNWIND_LINK_FLAGS "")
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000175
Petr Hosekcfb6df82019-10-11 22:22:29 +0000176# Include macros for adding and removing libunwind flags.
177include(HandleLibunwindFlags)
178
179#===============================================================================
180# Setup Compiler Flags
181#===============================================================================
182
Martin Storsjö51ffc5e2021-09-10 22:14:48 +0300183# Compiler tests may be failing if the compiler implicitly links in libunwind,
184# which doesn't exist yet. This gets waived by --unwindlib=none
185# later in config-ix below, but the tests for --target etc before that may
186# be failing due to it. Only test compilation, not linking, for these
187# tests here now.
188set(CMAKE_TRY_COMPILE_TARGET_TYPE_ORIG ${CMAKE_TRY_COMPILE_TARGET_TYPE})
189set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
Martin Storsjö51ffc5e2021-09-10 22:14:48 +0300190set(CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE_ORIG})
Eric Fiselier077b6822016-06-02 01:02:10 +0000191
192# Configure compiler.
193include(config-ix)
194
Charles Davisddde2e12018-09-04 20:57:50 +0000195if (LIBUNWIND_USE_COMPILER_RT AND NOT LIBUNWIND_HAS_NODEFAULTLIBS_FLAG)
Petr Hosek9bbcefb2017-04-12 02:28:07 +0000196 list(APPEND LIBUNWIND_LINK_FLAGS "-rtlib=compiler-rt")
197endif()
198
Petr Hosekcfb6df82019-10-11 22:22:29 +0000199add_compile_flags_if_supported(-Werror=return-type)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000200
gejin7f493162021-08-26 16:20:38 +0800201if (LIBUNWIND_ENABLE_CET)
202 add_compile_flags_if_supported(-fcf-protection=full)
203 add_compile_flags_if_supported(-mshstk)
204 if (NOT LIBUNWIND_SUPPORTS_FCF_PROTECTION_EQ_FULL_FLAG)
205 message(SEND_ERROR "Compiler doesn't support CET -fcf-protection option!")
206 endif()
207 if (NOT LIBUNWIND_SUPPORTS_MSHSTK_FLAG)
208 message(SEND_ERROR "Compiler doesn't support CET -mshstk option!")
209 endif()
210endif()
211
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000212# Get warning flags
Petr Hosekcfb6df82019-10-11 22:22:29 +0000213add_compile_flags_if_supported(-W)
214add_compile_flags_if_supported(-Wall)
215add_compile_flags_if_supported(-Wchar-subscripts)
216add_compile_flags_if_supported(-Wconversion)
217add_compile_flags_if_supported(-Wmismatched-tags)
218add_compile_flags_if_supported(-Wmissing-braces)
219add_compile_flags_if_supported(-Wnewline-eof)
220add_compile_flags_if_supported(-Wno-unused-function)
221add_compile_flags_if_supported(-Wshadow)
222add_compile_flags_if_supported(-Wshorten-64-to-32)
223add_compile_flags_if_supported(-Wsign-compare)
224add_compile_flags_if_supported(-Wsign-conversion)
225add_compile_flags_if_supported(-Wstrict-aliasing=2)
226add_compile_flags_if_supported(-Wstrict-overflow=4)
227add_compile_flags_if_supported(-Wunused-parameter)
228add_compile_flags_if_supported(-Wunused-variable)
229add_compile_flags_if_supported(-Wwrite-strings)
230add_compile_flags_if_supported(-Wundef)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000231
kristinaa95e23b2020-07-31 18:44:02 +0100232add_compile_flags_if_supported(-Wno-suggest-override)
233
Martin Storsjö66b29762020-10-23 22:51:21 +0300234if (WIN32)
235 # The headers lack matching dllexport attributes (_LIBUNWIND_EXPORT);
236 # silence the warning instead of cluttering the headers (which aren't
237 # necessarily the ones that the callers will use anyway) with the
238 # attributes.
239 add_compile_flags_if_supported(-Wno-dll-attribute-on-redeclaration)
240endif()
241
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000242if (LIBUNWIND_ENABLE_WERROR)
Petr Hosekcfb6df82019-10-11 22:22:29 +0000243 add_compile_flags_if_supported(-Werror)
244 add_compile_flags_if_supported(-WX)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000245else()
Petr Hosekcfb6df82019-10-11 22:22:29 +0000246 add_compile_flags_if_supported(-Wno-error)
247 add_compile_flags_if_supported(-WX-)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000248endif()
249
250if (LIBUNWIND_ENABLE_PEDANTIC)
Petr Hosekcfb6df82019-10-11 22:22:29 +0000251 add_compile_flags_if_supported(-pedantic)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000252endif()
253
254# Get feature flags.
255# Exceptions
256# Catches C++ exceptions only and tells the compiler to assume that extern C
257# functions never throw a C++ exception.
Petr Hosekcfb6df82019-10-11 22:22:29 +0000258add_cxx_compile_flags_if_supported(-fstrict-aliasing)
259add_cxx_compile_flags_if_supported(-EHsc)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000260
Sergej Jaskiewiczbaf07ac2019-12-06 17:26:35 +0300261# Don't run the linker in this CMake check.
262#
263# The reason why this was added is that when building libunwind for
264# ARM Linux, we need to pass the -funwind-tables flag in order for it to
265# work properly with ARM EHABI.
266#
267# However, when performing CMake checks, adding this flag causes the check
268# to produce a false negative, because the compiler generates calls
269# to __aeabi_unwind_cpp_pr0, which is defined in libunwind itself,
270# which isn't built yet, so the linker complains about undefined symbols.
271#
272# This leads to libunwind not being built with this flag, which makes
273# libunwind quite useless in this setup.
274set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
275set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
Petr Hosek1073ad92019-10-12 01:50:57 +0000276add_compile_flags_if_supported(-funwind-tables)
Sergej Jaskiewiczbaf07ac2019-12-06 17:26:35 +0300277set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
278
279if (LIBUNWIND_USES_ARM_EHABI AND NOT LIBUNWIND_SUPPORTS_FUNWIND_TABLES_FLAG)
280 message(SEND_ERROR "The -funwind-tables flag must be supported "
281 "because this target uses ARM Exception Handling ABI")
282endif()
283
Petr Hosekcfb6df82019-10-11 22:22:29 +0000284add_cxx_compile_flags_if_supported(-fno-exceptions)
285add_cxx_compile_flags_if_supported(-fno-rtti)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000286
Petr Hosekac0d9e02019-01-29 22:26:18 +0000287# Ensure that we don't depend on C++ standard library.
Petr Hosek1073ad92019-10-12 01:50:57 +0000288if (LIBUNWIND_HAS_NOSTDINCXX_FLAG)
Petr Hosekcfb6df82019-10-11 22:22:29 +0000289 list(APPEND LIBUNWIND_COMPILE_FLAGS -nostdinc++)
290 # Remove -stdlib flags to prevent them from causing an unused flag warning.
Raphael Isemanneb5b92d2020-10-13 16:05:00 +0200291 string(REPLACE "--stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
292 string(REPLACE "--stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
Petr Hosekcfb6df82019-10-11 22:22:29 +0000293 string(REPLACE "-stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
294 string(REPLACE "-stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
295endif()
Petr Hosekac0d9e02019-01-29 22:26:18 +0000296
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000297# Assert
298string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
299if (LIBUNWIND_ENABLE_ASSERTIONS)
300 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
301 if (NOT MSVC)
Petr Hosekcfb6df82019-10-11 22:22:29 +0000302 add_compile_flags(-D_DEBUG)
Eugene Zelenko12b5d282016-08-08 17:56:28 +0000303 endif()
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000304
305 # On Release builds cmake automatically defines NDEBUG, so we
306 # explicitly undefine it:
307 if (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
Petr Hosekcfb6df82019-10-11 22:22:29 +0000308 add_compile_flags(-UNDEBUG)
Eugene Zelenko12b5d282016-08-08 17:56:28 +0000309 endif()
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000310else()
311 if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
Petr Hosekcfb6df82019-10-11 22:22:29 +0000312 add_compile_flags(-DNDEBUG)
Eugene Zelenko12b5d282016-08-08 17:56:28 +0000313 endif()
314endif()
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000315
Asiri Rathnayakec00dcef2016-05-25 12:36:34 +0000316# Cross-unwinding
317if (NOT LIBUNWIND_ENABLE_CROSS_UNWINDING)
Petr Hosekcfb6df82019-10-11 22:22:29 +0000318 add_compile_flags(-D_LIBUNWIND_IS_NATIVE_ONLY)
Eugene Zelenko12b5d282016-08-08 17:56:28 +0000319endif()
Asiri Rathnayakec00dcef2016-05-25 12:36:34 +0000320
Asiri Rathnayake6d434c82016-09-28 10:57:15 +0000321# Threading-support
322if (NOT LIBUNWIND_ENABLE_THREADS)
Petr Hosekcfb6df82019-10-11 22:22:29 +0000323 add_compile_flags(-D_LIBUNWIND_HAS_NO_THREADS)
Asiri Rathnayake6d434c82016-09-28 10:57:15 +0000324endif()
325
Asiri Rathnayaked90f6812016-07-07 10:55:39 +0000326# ARM WMMX register support
327if (LIBUNWIND_ENABLE_ARM_WMMX)
328 # __ARM_WMMX is a compiler pre-define (as per the ACLE 2.0). Clang does not
329 # define this macro for any supported target at present. Therefore, here we
330 # provide the option to explicitly enable support for WMMX registers in the
331 # unwinder.
Petr Hosekcfb6df82019-10-11 22:22:29 +0000332 add_compile_flags(-D__ARM_WMMX)
Eugene Zelenko12b5d282016-08-08 17:56:28 +0000333endif()
Asiri Rathnayaked90f6812016-07-07 10:55:39 +0000334
Hafiz Abid Qadeer1fd0b1b2020-07-29 11:39:41 +0100335if(LIBUNWIND_IS_BAREMETAL)
336 add_compile_definitions(_LIBUNWIND_IS_BAREMETAL)
337endif()
338
Sterling Augustineb778c912020-08-18 12:05:07 -0700339if(LIBUNWIND_USE_FRAME_HEADER_CACHE)
340 add_compile_definitions(_LIBUNWIND_USE_FRAME_HEADER_CACHE)
341endif()
342
Daniel Kisscc1fc4e2020-11-11 10:58:41 +0100343if(LIBUNWIND_REMEMBER_HEAP_ALLOC)
344 add_compile_definitions(_LIBUNWIND_REMEMBER_HEAP_ALLOC)
345endif()
346
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000347# This is the _ONLY_ place where add_definitions is called.
348if (MSVC)
349 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
Eugene Zelenko12b5d282016-08-08 17:56:28 +0000350endif()
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000351
Martin Storsjo74e3b4d2017-11-29 08:21:12 +0000352# Disable DLL annotations on Windows for static builds.
353if (WIN32 AND LIBUNWIND_ENABLE_STATIC AND NOT LIBUNWIND_ENABLE_SHARED)
Ryan Prichard8d5fb6f2021-02-22 16:35:38 -0800354 add_definitions(-D_LIBUNWIND_HIDE_SYMBOLS)
Martin Storsjo74e3b4d2017-11-29 08:21:12 +0000355endif()
356
Petr Hosek0e595162019-05-30 04:40:21 +0000357if (LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
Michał Górnyf939ab72019-11-30 15:13:56 +0100358 if (LIBUNWIND_HAS_DL_LIB)
359 add_definitions(-D_LIBUNWIND_LINK_DL_LIB)
360 endif()
361 if (LIBUNWIND_HAS_PTHREAD_LIB)
362 add_definitions(-D_LIBUNWIND_LINK_PTHREAD_LIB)
363 endif()
Petr Hosek0e595162019-05-30 04:40:21 +0000364endif()
365
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000366#===============================================================================
367# Setup Source Code
368#===============================================================================
369
PoYao Chang4ead6102021-12-16 13:32:12 -0500370add_subdirectory(include)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000371
372add_subdirectory(src)
Jonathan Roelofsa9bd4562017-03-28 15:21:43 +0000373
374if (LIBUNWIND_INCLUDE_DOCS)
375 add_subdirectory(docs)
376endif()
Jonathan Roelofs0fedff12017-07-06 15:20:12 +0000377
Alfonso Gregorya7e4ce02021-09-16 18:27:53 +0200378if (LIBUNWIND_INCLUDE_TESTS AND EXISTS ${LLVM_CMAKE_DIR})
Martin Storsjo41118c42018-08-03 05:51:31 +0000379 add_subdirectory(test)
380endif()