blob: 9eada6895e009b0ead9d46b2713fe70955e044a3 [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
Petr Hosek9bbcefb2017-04-12 02:28:07 +000011# Add path for custom modules
12set(CMAKE_MODULE_PATH
13 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
14 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
15 ${CMAKE_MODULE_PATH}
16 )
17
Dominik Montada9e379242020-08-24 11:01:05 +020018set(LIBUNWIND_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
19set(LIBUNWIND_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
20set(LIBUNWIND_LIBCXX_PATH "${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH
21 "Specify path to libc++ source.")
22
Petr Hosek7aecb762019-05-30 07:34:39 +000023if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBUNWIND_STANDALONE_BUILD)
Martin Storsjö76f69162020-01-26 22:11:28 +020024 project(libunwind LANGUAGES C CXX ASM)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000025
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000026 set(PACKAGE_NAME libunwind)
Tom Stellarda3013542021-01-26 19:37:08 -080027 set(PACKAGE_VERSION 13.0.0git)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000028 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
Tanya Lattnera7abd9b2015-08-05 04:01:47 +000029 set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org")
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000030
Dominik Montada9e379242020-08-24 11:01:05 +020031 # Add the CMake module path of libcxx so we can reuse HandleOutOfTreeLLVM.cmake
32 set(LIBUNWIND_LIBCXX_CMAKE_PATH "${LIBUNWIND_LIBCXX_PATH}/cmake/Modules")
33 list(APPEND CMAKE_MODULE_PATH "${LIBUNWIND_LIBCXX_CMAKE_PATH}")
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000034
Dominik Montada9e379242020-08-24 11:01:05 +020035 # In a standalone build, we don't have llvm to automatically generate the
36 # llvm-lit script for us. So we need to provide an explicit directory that
37 # the configurator should write the script into.
38 set(LIBUNWIND_STANDALONE_BUILD 1)
39 set(LLVM_LIT_OUTPUT_DIR "${LIBUNWIND_BINARY_DIR}/bin")
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000040
Dominik Montada9e379242020-08-24 11:01:05 +020041 # Find the LLVM sources and simulate LLVM CMake options.
42 include(HandleOutOfTreeLLVM)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000043else()
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000044 set(LLVM_LIT "${CMAKE_SOURCE_DIR}/utils/lit/lit.py")
45endif()
46
47#===============================================================================
48# Setup CMake Options
49#===============================================================================
Petr Hosek68b2a0f2018-07-24 23:42:51 +000050include(CMakeDependentOption)
Petr Hosek9bbcefb2017-04-12 02:28:07 +000051include(HandleCompilerRT)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000052
53# Define options.
Eric Fiselier077b6822016-06-02 01:02:10 +000054option(LIBUNWIND_BUILD_32_BITS "Build 32 bit libunwind" ${LLVM_BUILD_32_BITS})
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000055option(LIBUNWIND_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
56option(LIBUNWIND_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
57option(LIBUNWIND_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000058option(LIBUNWIND_ENABLE_SHARED "Build libunwind as a shared library." ON)
Petr Hosek35f87502016-08-08 22:55:48 +000059option(LIBUNWIND_ENABLE_STATIC "Build libunwind as a static library." ON)
Asiri Rathnayake8c94db92016-05-27 08:29:27 +000060option(LIBUNWIND_ENABLE_CROSS_UNWINDING "Enable cross-platform unwinding support." OFF)
Asiri Rathnayaked90f6812016-07-07 10:55:39 +000061option(LIBUNWIND_ENABLE_ARM_WMMX "Enable unwinding support for ARM WMMX registers." OFF)
Asiri Rathnayake6d434c82016-09-28 10:57:15 +000062option(LIBUNWIND_ENABLE_THREADS "Build libunwind with threading support." ON)
Sterling Augustine7f90e762019-05-13 18:45:03 +000063option(LIBUNWIND_WEAK_PTHREAD_LIB "Use weak references to refer to pthread functions." OFF)
Petr Hosek9bbcefb2017-04-12 02:28:07 +000064option(LIBUNWIND_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
Jonathan Roelofsa9bd4562017-03-28 15:21:43 +000065option(LIBUNWIND_INCLUDE_DOCS "Build the libunwind documentation." ${LLVM_INCLUDE_DOCS})
Kristina Bessonovadc676eb2021-02-13 12:49:47 +020066option(LIBUNWIND_INCLUDE_TESTS "Build the libunwind tests." ${LLVM_INCLUDE_TESTS})
Hafiz Abid Qadeer1fd0b1b2020-07-29 11:39:41 +010067option(LIBUNWIND_IS_BAREMETAL "Build libunwind for baremetal targets." OFF)
Sterling Augustineb778c912020-08-18 12:05:07 -070068option(LIBUNWIND_USE_FRAME_HEADER_CACHE "Cache frame headers for unwinding. Requires locking dl_iterate_phdr." OFF)
Daniel Kisscc1fc4e2020-11-11 10:58:41 +010069option(LIBUNWIND_REMEMBER_HEAP_ALLOC "Use heap instead of the stack for .cfi_remember_state." OFF)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000070
Petr Hosek285a8f32017-08-08 00:37:59 +000071set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
72 "Define suffix of library directory name (32/64)")
Petr Hosek94bbfa62017-11-17 23:29:46 +000073option(LIBUNWIND_INSTALL_LIBRARY "Install the libunwind library." ON)
Petr Hosek106866a2018-07-24 23:27:51 +000074cmake_dependent_option(LIBUNWIND_INSTALL_STATIC_LIBRARY
75 "Install the static libunwind library." ON
76 "LIBUNWIND_ENABLE_STATIC;LIBUNWIND_INSTALL_LIBRARY" OFF)
77cmake_dependent_option(LIBUNWIND_INSTALL_SHARED_LIBRARY
78 "Install the shared libunwind library." ON
79 "LIBUNWIND_ENABLE_SHARED;LIBUNWIND_INSTALL_LIBRARY" OFF)
Eric Fiselier077b6822016-06-02 01:02:10 +000080set(LIBUNWIND_TARGET_TRIPLE "" CACHE STRING "Target triple for cross compiling.")
81set(LIBUNWIND_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
82set(LIBUNWIND_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")
John Baldwin22b1bfd2018-02-27 18:40:04 +000083set(LIBUNWIND_TEST_LINKER_FLAGS "" CACHE STRING
84 "Additional linker flags for test programs.")
85set(LIBUNWIND_TEST_COMPILER_FLAGS "" CACHE STRING
86 "Additional compiler flags for test programs.")
Louis Dionne69fa60b2020-06-25 12:02:43 -040087set(LIBUNWIND_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/lit.site.cfg.in" CACHE STRING
88 "The Lit testing configuration to use when running the tests.")
Dominik Montada9e379242020-08-24 11:01:05 +020089set(LIBUNWIND_TEST_PARAMS "" CACHE STRING
90 "A list of parameters to run the Lit test suite with.")
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000091
Petr Hosek35f87502016-08-08 22:55:48 +000092if (NOT LIBUNWIND_ENABLE_SHARED AND NOT LIBUNWIND_ENABLE_STATIC)
93 message(FATAL_ERROR "libunwind must be built as either a shared or static library.")
94endif()
95
Eric Fiselier5529ab12016-06-02 01:19:52 +000096# Check that we can build with 32 bits if requested.
97if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32)
98 if (LIBUNWIND_BUILD_32_BITS AND NOT LLVM_BUILD_32_BITS) # Don't duplicate the output from LLVM
99 message(STATUS "Building 32 bits executables and libraries.")
100 endif()
101elseif(LIBUNWIND_BUILD_32_BITS)
102 message(FATAL_ERROR "LIBUNWIND_BUILD_32_BITS=ON is not supported on this platform.")
103endif()
104
Ryan Prichard8d5fb6f2021-02-22 16:35:38 -0800105option(LIBUNWIND_HIDE_SYMBOLS
Petr Hosek809c2b52019-01-29 23:01:08 +0000106 "Do not export any symbols from the static library." OFF)
107
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000108#===============================================================================
109# Configure System
110#===============================================================================
111
112# Add path for custom modules
113set(CMAKE_MODULE_PATH
114 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
115 ${CMAKE_MODULE_PATH})
116
Eric Christopher92b75a22018-06-29 20:27:40 +0000117if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
Petr Hosek5844fc62021-04-16 21:33:18 -0700118 set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
John Ericsona5feaf62021-04-28 22:36:47 +0000119 set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH
120 "Path where built libunwind libraries should be installed.")
Petr Hosek1f9c24d2019-05-22 21:08:33 +0000121 if(LIBCXX_LIBDIR_SUBDIR)
122 string(APPEND LIBUNWIND_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR})
123 string(APPEND LIBUNWIND_INSTALL_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR})
124 endif()
Eric Christopher92b75a22018-06-29 20:27:40 +0000125elseif(LLVM_LIBRARY_OUTPUT_INTDIR)
Petr Hosekae8b8512017-07-18 21:30:18 +0000126 set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
John Ericsona5feaf62021-04-28 22:36:47 +0000127 set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX} CACHE PATH
128 "Path where built libunwind libraries should be installed.")
Petr Hosekae8b8512017-07-18 21:30:18 +0000129else()
Petr Hosek285a8f32017-08-08 00:37:59 +0000130 set(LIBUNWIND_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBUNWIND_LIBDIR_SUFFIX})
John Ericsona5feaf62021-04-28 22:36:47 +0000131 set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX} CACHE PATH
132 "Path where built libunwind libraries should be installed.")
Petr Hosekae8b8512017-07-18 21:30:18 +0000133endif()
134
135set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR})
136set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR})
137set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR})
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000138
Eric Fiselier077b6822016-06-02 01:02:10 +0000139set(LIBUNWIND_C_FLAGS "")
140set(LIBUNWIND_CXX_FLAGS "")
141set(LIBUNWIND_COMPILE_FLAGS "")
142set(LIBUNWIND_LINK_FLAGS "")
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000143
Petr Hosekcfb6df82019-10-11 22:22:29 +0000144# Include macros for adding and removing libunwind flags.
145include(HandleLibunwindFlags)
146
147#===============================================================================
148# Setup Compiler Flags
149#===============================================================================
150
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000151# Get required flags.
Eric Fiselier077b6822016-06-02 01:02:10 +0000152add_target_flags_if(LIBUNWIND_BUILD_32_BITS "-m32")
Petr Hoseka6a888a2019-02-04 20:02:26 +0000153
154if(LIBUNWIND_TARGET_TRIPLE)
155 add_target_flags("--target=${LIBUNWIND_TARGET_TRIPLE}")
156elseif(CMAKE_CXX_COMPILER_TARGET)
157 set(LIBUNWIND_TARGET_TRIPLE "${CMAKE_CXX_COMPILER_TARGET}")
158endif()
159if(LIBUNWIND_GCC_TOOLCHAIN)
160 add_target_flags("--gcc-toolchain=${LIBUNWIND_GCC_TOOLCHAIN}")
161elseif(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN)
162 set(LIBUNWIND_GCC_TOOLCHAIN "${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}")
163endif()
164if(LIBUNWIND_SYSROOT)
165 add_target_flags("--sysroot=${LIBUNWIND_SYSROOT}")
166elseif(CMAKE_SYSROOT)
167 set(LIBUNWIND_SYSROOT "${CMAKE_SYSROOT}")
168endif()
Eric Fiselier077b6822016-06-02 01:02:10 +0000169
Petr Hosek058362b2017-12-05 20:48:05 +0000170if (LIBUNWIND_TARGET_TRIPLE)
171 set(TARGET_TRIPLE "${LIBUNWIND_TARGET_TRIPLE}")
172endif()
173
Eric Fiselier077b6822016-06-02 01:02:10 +0000174# Configure compiler.
175include(config-ix)
176
Charles Davisddde2e12018-09-04 20:57:50 +0000177if (LIBUNWIND_USE_COMPILER_RT AND NOT LIBUNWIND_HAS_NODEFAULTLIBS_FLAG)
Petr Hosek9bbcefb2017-04-12 02:28:07 +0000178 list(APPEND LIBUNWIND_LINK_FLAGS "-rtlib=compiler-rt")
179endif()
180
Petr Hosekcfb6df82019-10-11 22:22:29 +0000181add_compile_flags_if_supported(-Werror=return-type)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000182
183# Get warning flags
Petr Hosekcfb6df82019-10-11 22:22:29 +0000184add_compile_flags_if_supported(-W)
185add_compile_flags_if_supported(-Wall)
186add_compile_flags_if_supported(-Wchar-subscripts)
187add_compile_flags_if_supported(-Wconversion)
188add_compile_flags_if_supported(-Wmismatched-tags)
189add_compile_flags_if_supported(-Wmissing-braces)
190add_compile_flags_if_supported(-Wnewline-eof)
191add_compile_flags_if_supported(-Wno-unused-function)
192add_compile_flags_if_supported(-Wshadow)
193add_compile_flags_if_supported(-Wshorten-64-to-32)
194add_compile_flags_if_supported(-Wsign-compare)
195add_compile_flags_if_supported(-Wsign-conversion)
196add_compile_flags_if_supported(-Wstrict-aliasing=2)
197add_compile_flags_if_supported(-Wstrict-overflow=4)
198add_compile_flags_if_supported(-Wunused-parameter)
199add_compile_flags_if_supported(-Wunused-variable)
200add_compile_flags_if_supported(-Wwrite-strings)
201add_compile_flags_if_supported(-Wundef)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000202
kristinaa95e23b2020-07-31 18:44:02 +0100203add_compile_flags_if_supported(-Wno-suggest-override)
204
Martin Storsjö66b29762020-10-23 22:51:21 +0300205if (WIN32)
206 # The headers lack matching dllexport attributes (_LIBUNWIND_EXPORT);
207 # silence the warning instead of cluttering the headers (which aren't
208 # necessarily the ones that the callers will use anyway) with the
209 # attributes.
210 add_compile_flags_if_supported(-Wno-dll-attribute-on-redeclaration)
211endif()
212
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000213if (LIBUNWIND_ENABLE_WERROR)
Petr Hosekcfb6df82019-10-11 22:22:29 +0000214 add_compile_flags_if_supported(-Werror)
215 add_compile_flags_if_supported(-WX)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000216else()
Petr Hosekcfb6df82019-10-11 22:22:29 +0000217 add_compile_flags_if_supported(-Wno-error)
218 add_compile_flags_if_supported(-WX-)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000219endif()
220
221if (LIBUNWIND_ENABLE_PEDANTIC)
Petr Hosekcfb6df82019-10-11 22:22:29 +0000222 add_compile_flags_if_supported(-pedantic)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000223endif()
224
225# Get feature flags.
226# Exceptions
227# Catches C++ exceptions only and tells the compiler to assume that extern C
228# functions never throw a C++ exception.
Petr Hosekcfb6df82019-10-11 22:22:29 +0000229add_cxx_compile_flags_if_supported(-fstrict-aliasing)
230add_cxx_compile_flags_if_supported(-EHsc)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000231
Sergej Jaskiewiczbaf07ac2019-12-06 17:26:35 +0300232# Don't run the linker in this CMake check.
233#
234# The reason why this was added is that when building libunwind for
235# ARM Linux, we need to pass the -funwind-tables flag in order for it to
236# work properly with ARM EHABI.
237#
238# However, when performing CMake checks, adding this flag causes the check
239# to produce a false negative, because the compiler generates calls
240# to __aeabi_unwind_cpp_pr0, which is defined in libunwind itself,
241# which isn't built yet, so the linker complains about undefined symbols.
242#
243# This leads to libunwind not being built with this flag, which makes
244# libunwind quite useless in this setup.
245set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
246set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
Petr Hosek1073ad92019-10-12 01:50:57 +0000247add_compile_flags_if_supported(-funwind-tables)
Sergej Jaskiewiczbaf07ac2019-12-06 17:26:35 +0300248set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
249
250if (LIBUNWIND_USES_ARM_EHABI AND NOT LIBUNWIND_SUPPORTS_FUNWIND_TABLES_FLAG)
251 message(SEND_ERROR "The -funwind-tables flag must be supported "
252 "because this target uses ARM Exception Handling ABI")
253endif()
254
Petr Hosekcfb6df82019-10-11 22:22:29 +0000255add_cxx_compile_flags_if_supported(-fno-exceptions)
256add_cxx_compile_flags_if_supported(-fno-rtti)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000257
Petr Hosekac0d9e02019-01-29 22:26:18 +0000258# Ensure that we don't depend on C++ standard library.
Petr Hosek1073ad92019-10-12 01:50:57 +0000259if (LIBUNWIND_HAS_NOSTDINCXX_FLAG)
Petr Hosekcfb6df82019-10-11 22:22:29 +0000260 list(APPEND LIBUNWIND_COMPILE_FLAGS -nostdinc++)
261 # Remove -stdlib flags to prevent them from causing an unused flag warning.
Raphael Isemanneb5b92d2020-10-13 16:05:00 +0200262 string(REPLACE "--stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
263 string(REPLACE "--stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
Petr Hosekcfb6df82019-10-11 22:22:29 +0000264 string(REPLACE "-stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
265 string(REPLACE "-stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
266endif()
Petr Hosekac0d9e02019-01-29 22:26:18 +0000267
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000268# Assert
269string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
270if (LIBUNWIND_ENABLE_ASSERTIONS)
271 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
272 if (NOT MSVC)
Petr Hosekcfb6df82019-10-11 22:22:29 +0000273 add_compile_flags(-D_DEBUG)
Eugene Zelenko12b5d282016-08-08 17:56:28 +0000274 endif()
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000275
276 # On Release builds cmake automatically defines NDEBUG, so we
277 # explicitly undefine it:
278 if (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
Petr Hosekcfb6df82019-10-11 22:22:29 +0000279 add_compile_flags(-UNDEBUG)
Eugene Zelenko12b5d282016-08-08 17:56:28 +0000280 endif()
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000281else()
282 if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
Petr Hosekcfb6df82019-10-11 22:22:29 +0000283 add_compile_flags(-DNDEBUG)
Eugene Zelenko12b5d282016-08-08 17:56:28 +0000284 endif()
285endif()
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000286
Asiri Rathnayakec00dcef2016-05-25 12:36:34 +0000287# Cross-unwinding
288if (NOT LIBUNWIND_ENABLE_CROSS_UNWINDING)
Petr Hosekcfb6df82019-10-11 22:22:29 +0000289 add_compile_flags(-D_LIBUNWIND_IS_NATIVE_ONLY)
Eugene Zelenko12b5d282016-08-08 17:56:28 +0000290endif()
Asiri Rathnayakec00dcef2016-05-25 12:36:34 +0000291
Asiri Rathnayake6d434c82016-09-28 10:57:15 +0000292# Threading-support
293if (NOT LIBUNWIND_ENABLE_THREADS)
Petr Hosekcfb6df82019-10-11 22:22:29 +0000294 add_compile_flags(-D_LIBUNWIND_HAS_NO_THREADS)
Asiri Rathnayake6d434c82016-09-28 10:57:15 +0000295endif()
296
Asiri Rathnayaked90f6812016-07-07 10:55:39 +0000297# ARM WMMX register support
298if (LIBUNWIND_ENABLE_ARM_WMMX)
299 # __ARM_WMMX is a compiler pre-define (as per the ACLE 2.0). Clang does not
300 # define this macro for any supported target at present. Therefore, here we
301 # provide the option to explicitly enable support for WMMX registers in the
302 # unwinder.
Petr Hosekcfb6df82019-10-11 22:22:29 +0000303 add_compile_flags(-D__ARM_WMMX)
Eugene Zelenko12b5d282016-08-08 17:56:28 +0000304endif()
Asiri Rathnayaked90f6812016-07-07 10:55:39 +0000305
Hafiz Abid Qadeer1fd0b1b2020-07-29 11:39:41 +0100306if(LIBUNWIND_IS_BAREMETAL)
307 add_compile_definitions(_LIBUNWIND_IS_BAREMETAL)
308endif()
309
Sterling Augustineb778c912020-08-18 12:05:07 -0700310if(LIBUNWIND_USE_FRAME_HEADER_CACHE)
311 add_compile_definitions(_LIBUNWIND_USE_FRAME_HEADER_CACHE)
312endif()
313
Daniel Kisscc1fc4e2020-11-11 10:58:41 +0100314if(LIBUNWIND_REMEMBER_HEAP_ALLOC)
315 add_compile_definitions(_LIBUNWIND_REMEMBER_HEAP_ALLOC)
316endif()
317
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000318# This is the _ONLY_ place where add_definitions is called.
319if (MSVC)
320 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
Eugene Zelenko12b5d282016-08-08 17:56:28 +0000321endif()
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000322
Martin Storsjo74e3b4d2017-11-29 08:21:12 +0000323# Disable DLL annotations on Windows for static builds.
324if (WIN32 AND LIBUNWIND_ENABLE_STATIC AND NOT LIBUNWIND_ENABLE_SHARED)
Ryan Prichard8d5fb6f2021-02-22 16:35:38 -0800325 add_definitions(-D_LIBUNWIND_HIDE_SYMBOLS)
Martin Storsjo74e3b4d2017-11-29 08:21:12 +0000326endif()
327
Petr Hosek0e595162019-05-30 04:40:21 +0000328if (LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
Michał Górnyf939ab72019-11-30 15:13:56 +0100329 if (LIBUNWIND_HAS_DL_LIB)
330 add_definitions(-D_LIBUNWIND_LINK_DL_LIB)
331 endif()
332 if (LIBUNWIND_HAS_PTHREAD_LIB)
333 add_definitions(-D_LIBUNWIND_LINK_PTHREAD_LIB)
334 endif()
Petr Hosek0e595162019-05-30 04:40:21 +0000335endif()
336
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000337#===============================================================================
338# Setup Source Code
339#===============================================================================
340
341include_directories(include)
342
343add_subdirectory(src)
Jonathan Roelofsa9bd4562017-03-28 15:21:43 +0000344
345if (LIBUNWIND_INCLUDE_DOCS)
346 add_subdirectory(docs)
347endif()
Jonathan Roelofs0fedff12017-07-06 15:20:12 +0000348
Kristina Bessonovadc676eb2021-02-13 12:49:47 +0200349if (LIBUNWIND_INCLUDE_TESTS AND EXISTS ${LLVM_CMAKE_PATH})
Martin Storsjo41118c42018-08-03 05:51:31 +0000350 add_subdirectory(test)
351endif()