blob: e344263173b0426a0066c0efbc5d0ffa50177d26 [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
11if (POLICY CMP0042)
12 cmake_policy(SET CMP0042 NEW) # Set MACOSX_RPATH=YES by default
13endif()
14
Petr Hosek9bbcefb2017-04-12 02:28:07 +000015# Add path for custom modules
16set(CMAKE_MODULE_PATH
17 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
18 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
19 ${CMAKE_MODULE_PATH}
20 )
21
Dominik Montada9e379242020-08-24 11:01:05 +020022set(LIBUNWIND_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
23set(LIBUNWIND_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
24set(LIBUNWIND_LIBCXX_PATH "${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH
25 "Specify path to libc++ source.")
26
Petr Hosek7aecb762019-05-30 07:34:39 +000027if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBUNWIND_STANDALONE_BUILD)
Martin Storsjö76f69162020-01-26 22:11:28 +020028 project(libunwind LANGUAGES C CXX ASM)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000029
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000030 set(PACKAGE_NAME libunwind)
Hans Wennborgeb901872020-07-15 11:40:53 +020031 set(PACKAGE_VERSION 12.0.0git)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000032 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
Tanya Lattnera7abd9b2015-08-05 04:01:47 +000033 set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org")
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000034
Dominik Montada9e379242020-08-24 11:01:05 +020035 # Add the CMake module path of libcxx so we can reuse HandleOutOfTreeLLVM.cmake
36 set(LIBUNWIND_LIBCXX_CMAKE_PATH "${LIBUNWIND_LIBCXX_PATH}/cmake/Modules")
37 list(APPEND CMAKE_MODULE_PATH "${LIBUNWIND_LIBCXX_CMAKE_PATH}")
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000038
Dominik Montada9e379242020-08-24 11:01:05 +020039 # In a standalone build, we don't have llvm to automatically generate the
40 # llvm-lit script for us. So we need to provide an explicit directory that
41 # the configurator should write the script into.
42 set(LIBUNWIND_STANDALONE_BUILD 1)
43 set(LLVM_LIT_OUTPUT_DIR "${LIBUNWIND_BINARY_DIR}/bin")
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000044
Dominik Montada9e379242020-08-24 11:01:05 +020045 # Find the LLVM sources and simulate LLVM CMake options.
46 include(HandleOutOfTreeLLVM)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000047else()
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000048 set(LLVM_LIT "${CMAKE_SOURCE_DIR}/utils/lit/lit.py")
49endif()
50
51#===============================================================================
52# Setup CMake Options
53#===============================================================================
Petr Hosek68b2a0f2018-07-24 23:42:51 +000054include(CMakeDependentOption)
Petr Hosek9bbcefb2017-04-12 02:28:07 +000055include(HandleCompilerRT)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000056
57# Define options.
Eric Fiselier077b6822016-06-02 01:02:10 +000058option(LIBUNWIND_BUILD_32_BITS "Build 32 bit libunwind" ${LLVM_BUILD_32_BITS})
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000059option(LIBUNWIND_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
60option(LIBUNWIND_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
61option(LIBUNWIND_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000062option(LIBUNWIND_ENABLE_SHARED "Build libunwind as a shared library." ON)
Petr Hosek35f87502016-08-08 22:55:48 +000063option(LIBUNWIND_ENABLE_STATIC "Build libunwind as a static library." ON)
Asiri Rathnayake8c94db92016-05-27 08:29:27 +000064option(LIBUNWIND_ENABLE_CROSS_UNWINDING "Enable cross-platform unwinding support." OFF)
Asiri Rathnayaked90f6812016-07-07 10:55:39 +000065option(LIBUNWIND_ENABLE_ARM_WMMX "Enable unwinding support for ARM WMMX registers." OFF)
Asiri Rathnayake6d434c82016-09-28 10:57:15 +000066option(LIBUNWIND_ENABLE_THREADS "Build libunwind with threading support." ON)
Sterling Augustine7f90e762019-05-13 18:45:03 +000067option(LIBUNWIND_WEAK_PTHREAD_LIB "Use weak references to refer to pthread functions." OFF)
Petr Hosek9bbcefb2017-04-12 02:28:07 +000068option(LIBUNWIND_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
Jonathan Roelofsa9bd4562017-03-28 15:21:43 +000069option(LIBUNWIND_INCLUDE_DOCS "Build the libunwind documentation." ${LLVM_INCLUDE_DOCS})
Hafiz Abid Qadeer1fd0b1b2020-07-29 11:39:41 +010070option(LIBUNWIND_IS_BAREMETAL "Build libunwind for baremetal targets." OFF)
Sterling Augustineb778c912020-08-18 12:05:07 -070071option(LIBUNWIND_USE_FRAME_HEADER_CACHE "Cache frame headers for unwinding. Requires locking dl_iterate_phdr." OFF)
Daniel Kisscc1fc4e2020-11-11 10:58:41 +010072option(LIBUNWIND_REMEMBER_HEAP_ALLOC "Use heap instead of the stack for .cfi_remember_state." OFF)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000073
Petr Hosek285a8f32017-08-08 00:37:59 +000074set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
75 "Define suffix of library directory name (32/64)")
Petr Hosek94bbfa62017-11-17 23:29:46 +000076option(LIBUNWIND_INSTALL_LIBRARY "Install the libunwind library." ON)
Petr Hosek106866a2018-07-24 23:27:51 +000077cmake_dependent_option(LIBUNWIND_INSTALL_STATIC_LIBRARY
78 "Install the static libunwind library." ON
79 "LIBUNWIND_ENABLE_STATIC;LIBUNWIND_INSTALL_LIBRARY" OFF)
80cmake_dependent_option(LIBUNWIND_INSTALL_SHARED_LIBRARY
81 "Install the shared libunwind library." ON
82 "LIBUNWIND_ENABLE_SHARED;LIBUNWIND_INSTALL_LIBRARY" OFF)
Eric Fiselier077b6822016-06-02 01:02:10 +000083set(LIBUNWIND_TARGET_TRIPLE "" CACHE STRING "Target triple for cross compiling.")
84set(LIBUNWIND_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
85set(LIBUNWIND_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")
John Baldwin22b1bfd2018-02-27 18:40:04 +000086set(LIBUNWIND_TEST_LINKER_FLAGS "" CACHE STRING
87 "Additional linker flags for test programs.")
88set(LIBUNWIND_TEST_COMPILER_FLAGS "" CACHE STRING
89 "Additional compiler flags for test programs.")
Louis Dionne69fa60b2020-06-25 12:02:43 -040090set(LIBUNWIND_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/lit.site.cfg.in" CACHE STRING
91 "The Lit testing configuration to use when running the tests.")
Dominik Montada9e379242020-08-24 11:01:05 +020092set(LIBUNWIND_TEST_PARAMS "" CACHE STRING
93 "A list of parameters to run the Lit test suite with.")
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +000094
Petr Hosek35f87502016-08-08 22:55:48 +000095if (NOT LIBUNWIND_ENABLE_SHARED AND NOT LIBUNWIND_ENABLE_STATIC)
96 message(FATAL_ERROR "libunwind must be built as either a shared or static library.")
97endif()
98
Eric Fiselier5529ab12016-06-02 01:19:52 +000099# Check that we can build with 32 bits if requested.
100if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32)
101 if (LIBUNWIND_BUILD_32_BITS AND NOT LLVM_BUILD_32_BITS) # Don't duplicate the output from LLVM
102 message(STATUS "Building 32 bits executables and libraries.")
103 endif()
104elseif(LIBUNWIND_BUILD_32_BITS)
105 message(FATAL_ERROR "LIBUNWIND_BUILD_32_BITS=ON is not supported on this platform.")
106endif()
107
Petr Hosek809c2b52019-01-29 23:01:08 +0000108option(LIBUNWIND_HERMETIC_STATIC_LIBRARY
109 "Do not export any symbols from the static library." OFF)
110
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000111#===============================================================================
112# Configure System
113#===============================================================================
114
115# Add path for custom modules
116set(CMAKE_MODULE_PATH
117 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
118 ${CMAKE_MODULE_PATH})
119
Eric Christopher92b75a22018-06-29 20:27:40 +0000120if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
Petr Hosek1f9c24d2019-05-22 21:08:33 +0000121 set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++)
122 set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++)
123 if(LIBCXX_LIBDIR_SUBDIR)
124 string(APPEND LIBUNWIND_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR})
125 string(APPEND LIBUNWIND_INSTALL_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR})
126 endif()
Eric Christopher92b75a22018-06-29 20:27:40 +0000127elseif(LLVM_LIBRARY_OUTPUT_INTDIR)
Petr Hosekae8b8512017-07-18 21:30:18 +0000128 set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
Petr Hosek1f9c24d2019-05-22 21:08:33 +0000129 set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX})
Petr Hosekae8b8512017-07-18 21:30:18 +0000130else()
Petr Hosek285a8f32017-08-08 00:37:59 +0000131 set(LIBUNWIND_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBUNWIND_LIBDIR_SUFFIX})
Petr Hosek1f9c24d2019-05-22 21:08:33 +0000132 set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX})
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
Petr Hosek1f9c24d2019-05-22 21:08:33 +0000139set(LIBUNWIND_INSTALL_PREFIX "" CACHE STRING "Define libunwind destination prefix.")
Petr Hosek426a8d42017-07-11 01:12:09 +0000140
Eric Fiselier077b6822016-06-02 01:02:10 +0000141set(LIBUNWIND_C_FLAGS "")
142set(LIBUNWIND_CXX_FLAGS "")
143set(LIBUNWIND_COMPILE_FLAGS "")
144set(LIBUNWIND_LINK_FLAGS "")
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000145
Petr Hosekcfb6df82019-10-11 22:22:29 +0000146# Include macros for adding and removing libunwind flags.
147include(HandleLibunwindFlags)
148
149#===============================================================================
150# Setup Compiler Flags
151#===============================================================================
152
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000153# Get required flags.
Eric Fiselier077b6822016-06-02 01:02:10 +0000154add_target_flags_if(LIBUNWIND_BUILD_32_BITS "-m32")
Petr Hoseka6a888a2019-02-04 20:02:26 +0000155
156if(LIBUNWIND_TARGET_TRIPLE)
157 add_target_flags("--target=${LIBUNWIND_TARGET_TRIPLE}")
158elseif(CMAKE_CXX_COMPILER_TARGET)
159 set(LIBUNWIND_TARGET_TRIPLE "${CMAKE_CXX_COMPILER_TARGET}")
160endif()
161if(LIBUNWIND_GCC_TOOLCHAIN)
162 add_target_flags("--gcc-toolchain=${LIBUNWIND_GCC_TOOLCHAIN}")
163elseif(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN)
164 set(LIBUNWIND_GCC_TOOLCHAIN "${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}")
165endif()
166if(LIBUNWIND_SYSROOT)
167 add_target_flags("--sysroot=${LIBUNWIND_SYSROOT}")
168elseif(CMAKE_SYSROOT)
169 set(LIBUNWIND_SYSROOT "${CMAKE_SYSROOT}")
170endif()
Eric Fiselier077b6822016-06-02 01:02:10 +0000171
Petr Hosek058362b2017-12-05 20:48:05 +0000172if (LIBUNWIND_TARGET_TRIPLE)
173 set(TARGET_TRIPLE "${LIBUNWIND_TARGET_TRIPLE}")
174endif()
175
Eric Fiselier077b6822016-06-02 01:02:10 +0000176# Configure compiler.
177include(config-ix)
178
Charles Davisddde2e12018-09-04 20:57:50 +0000179if (LIBUNWIND_USE_COMPILER_RT AND NOT LIBUNWIND_HAS_NODEFAULTLIBS_FLAG)
Petr Hosek9bbcefb2017-04-12 02:28:07 +0000180 list(APPEND LIBUNWIND_LINK_FLAGS "-rtlib=compiler-rt")
181endif()
182
Petr Hosekcfb6df82019-10-11 22:22:29 +0000183add_compile_flags_if_supported(-Werror=return-type)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000184
185# Get warning flags
Petr Hosekcfb6df82019-10-11 22:22:29 +0000186add_compile_flags_if_supported(-W)
187add_compile_flags_if_supported(-Wall)
188add_compile_flags_if_supported(-Wchar-subscripts)
189add_compile_flags_if_supported(-Wconversion)
190add_compile_flags_if_supported(-Wmismatched-tags)
191add_compile_flags_if_supported(-Wmissing-braces)
192add_compile_flags_if_supported(-Wnewline-eof)
193add_compile_flags_if_supported(-Wno-unused-function)
194add_compile_flags_if_supported(-Wshadow)
195add_compile_flags_if_supported(-Wshorten-64-to-32)
196add_compile_flags_if_supported(-Wsign-compare)
197add_compile_flags_if_supported(-Wsign-conversion)
198add_compile_flags_if_supported(-Wstrict-aliasing=2)
199add_compile_flags_if_supported(-Wstrict-overflow=4)
200add_compile_flags_if_supported(-Wunused-parameter)
201add_compile_flags_if_supported(-Wunused-variable)
202add_compile_flags_if_supported(-Wwrite-strings)
203add_compile_flags_if_supported(-Wundef)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000204
kristinaa95e23b2020-07-31 18:44:02 +0100205add_compile_flags_if_supported(-Wno-suggest-override)
206
Martin Storsjö66b29762020-10-23 22:51:21 +0300207if (WIN32)
208 # The headers lack matching dllexport attributes (_LIBUNWIND_EXPORT);
209 # silence the warning instead of cluttering the headers (which aren't
210 # necessarily the ones that the callers will use anyway) with the
211 # attributes.
212 add_compile_flags_if_supported(-Wno-dll-attribute-on-redeclaration)
213endif()
214
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000215if (LIBUNWIND_ENABLE_WERROR)
Petr Hosekcfb6df82019-10-11 22:22:29 +0000216 add_compile_flags_if_supported(-Werror)
217 add_compile_flags_if_supported(-WX)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000218else()
Petr Hosekcfb6df82019-10-11 22:22:29 +0000219 add_compile_flags_if_supported(-Wno-error)
220 add_compile_flags_if_supported(-WX-)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000221endif()
222
223if (LIBUNWIND_ENABLE_PEDANTIC)
Petr Hosekcfb6df82019-10-11 22:22:29 +0000224 add_compile_flags_if_supported(-pedantic)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000225endif()
226
227# Get feature flags.
228# Exceptions
229# Catches C++ exceptions only and tells the compiler to assume that extern C
230# functions never throw a C++ exception.
Petr Hosekcfb6df82019-10-11 22:22:29 +0000231add_cxx_compile_flags_if_supported(-fstrict-aliasing)
232add_cxx_compile_flags_if_supported(-EHsc)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000233
Sergej Jaskiewiczbaf07ac2019-12-06 17:26:35 +0300234# Don't run the linker in this CMake check.
235#
236# The reason why this was added is that when building libunwind for
237# ARM Linux, we need to pass the -funwind-tables flag in order for it to
238# work properly with ARM EHABI.
239#
240# However, when performing CMake checks, adding this flag causes the check
241# to produce a false negative, because the compiler generates calls
242# to __aeabi_unwind_cpp_pr0, which is defined in libunwind itself,
243# which isn't built yet, so the linker complains about undefined symbols.
244#
245# This leads to libunwind not being built with this flag, which makes
246# libunwind quite useless in this setup.
247set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
248set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
Petr Hosek1073ad92019-10-12 01:50:57 +0000249add_compile_flags_if_supported(-funwind-tables)
Sergej Jaskiewiczbaf07ac2019-12-06 17:26:35 +0300250set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
251
252if (LIBUNWIND_USES_ARM_EHABI AND NOT LIBUNWIND_SUPPORTS_FUNWIND_TABLES_FLAG)
253 message(SEND_ERROR "The -funwind-tables flag must be supported "
254 "because this target uses ARM Exception Handling ABI")
255endif()
256
Petr Hosekcfb6df82019-10-11 22:22:29 +0000257add_cxx_compile_flags_if_supported(-fno-exceptions)
258add_cxx_compile_flags_if_supported(-fno-rtti)
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000259
Petr Hosekac0d9e02019-01-29 22:26:18 +0000260# Ensure that we don't depend on C++ standard library.
Petr Hosek1073ad92019-10-12 01:50:57 +0000261if (LIBUNWIND_HAS_NOSTDINCXX_FLAG)
Petr Hosekcfb6df82019-10-11 22:22:29 +0000262 list(APPEND LIBUNWIND_COMPILE_FLAGS -nostdinc++)
263 # Remove -stdlib flags to prevent them from causing an unused flag warning.
Raphael Isemanneb5b92d2020-10-13 16:05:00 +0200264 string(REPLACE "--stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
265 string(REPLACE "--stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
Petr Hosekcfb6df82019-10-11 22:22:29 +0000266 string(REPLACE "-stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
267 string(REPLACE "-stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
268endif()
Petr Hosekac0d9e02019-01-29 22:26:18 +0000269
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000270# Assert
271string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
272if (LIBUNWIND_ENABLE_ASSERTIONS)
273 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
274 if (NOT MSVC)
Petr Hosekcfb6df82019-10-11 22:22:29 +0000275 add_compile_flags(-D_DEBUG)
Eugene Zelenko12b5d282016-08-08 17:56:28 +0000276 endif()
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000277
278 # On Release builds cmake automatically defines NDEBUG, so we
279 # explicitly undefine it:
280 if (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
Petr Hosekcfb6df82019-10-11 22:22:29 +0000281 add_compile_flags(-UNDEBUG)
Eugene Zelenko12b5d282016-08-08 17:56:28 +0000282 endif()
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000283else()
284 if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
Petr Hosekcfb6df82019-10-11 22:22:29 +0000285 add_compile_flags(-DNDEBUG)
Eugene Zelenko12b5d282016-08-08 17:56:28 +0000286 endif()
287endif()
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000288
Asiri Rathnayakec00dcef2016-05-25 12:36:34 +0000289# Cross-unwinding
290if (NOT LIBUNWIND_ENABLE_CROSS_UNWINDING)
Petr Hosekcfb6df82019-10-11 22:22:29 +0000291 add_compile_flags(-D_LIBUNWIND_IS_NATIVE_ONLY)
Eugene Zelenko12b5d282016-08-08 17:56:28 +0000292endif()
Asiri Rathnayakec00dcef2016-05-25 12:36:34 +0000293
Asiri Rathnayake6d434c82016-09-28 10:57:15 +0000294# Threading-support
295if (NOT LIBUNWIND_ENABLE_THREADS)
Petr Hosekcfb6df82019-10-11 22:22:29 +0000296 add_compile_flags(-D_LIBUNWIND_HAS_NO_THREADS)
Asiri Rathnayake6d434c82016-09-28 10:57:15 +0000297endif()
298
Asiri Rathnayaked90f6812016-07-07 10:55:39 +0000299# ARM WMMX register support
300if (LIBUNWIND_ENABLE_ARM_WMMX)
301 # __ARM_WMMX is a compiler pre-define (as per the ACLE 2.0). Clang does not
302 # define this macro for any supported target at present. Therefore, here we
303 # provide the option to explicitly enable support for WMMX registers in the
304 # unwinder.
Petr Hosekcfb6df82019-10-11 22:22:29 +0000305 add_compile_flags(-D__ARM_WMMX)
Eugene Zelenko12b5d282016-08-08 17:56:28 +0000306endif()
Asiri Rathnayaked90f6812016-07-07 10:55:39 +0000307
Hafiz Abid Qadeer1fd0b1b2020-07-29 11:39:41 +0100308if(LIBUNWIND_IS_BAREMETAL)
309 add_compile_definitions(_LIBUNWIND_IS_BAREMETAL)
310endif()
311
Sterling Augustineb778c912020-08-18 12:05:07 -0700312if(LIBUNWIND_USE_FRAME_HEADER_CACHE)
313 add_compile_definitions(_LIBUNWIND_USE_FRAME_HEADER_CACHE)
314endif()
315
Daniel Kisscc1fc4e2020-11-11 10:58:41 +0100316if(LIBUNWIND_REMEMBER_HEAP_ALLOC)
317 add_compile_definitions(_LIBUNWIND_REMEMBER_HEAP_ALLOC)
318endif()
319
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000320# This is the _ONLY_ place where add_definitions is called.
321if (MSVC)
322 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
Eugene Zelenko12b5d282016-08-08 17:56:28 +0000323endif()
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000324
Martin Storsjo74e3b4d2017-11-29 08:21:12 +0000325# Disable DLL annotations on Windows for static builds.
326if (WIN32 AND LIBUNWIND_ENABLE_STATIC AND NOT LIBUNWIND_ENABLE_SHARED)
327 add_definitions(-D_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS)
328endif()
329
Petr Hosek0e595162019-05-30 04:40:21 +0000330if (LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
Michał Górnyf939ab72019-11-30 15:13:56 +0100331 if (LIBUNWIND_HAS_DL_LIB)
332 add_definitions(-D_LIBUNWIND_LINK_DL_LIB)
333 endif()
334 if (LIBUNWIND_HAS_PTHREAD_LIB)
335 add_definitions(-D_LIBUNWIND_LINK_PTHREAD_LIB)
336 endif()
Petr Hosek0e595162019-05-30 04:40:21 +0000337endif()
338
Saleem Abdulrasoolf058d5e2015-04-25 01:46:35 +0000339#===============================================================================
340# Setup Source Code
341#===============================================================================
342
343include_directories(include)
344
345add_subdirectory(src)
Jonathan Roelofsa9bd4562017-03-28 15:21:43 +0000346
347if (LIBUNWIND_INCLUDE_DOCS)
348 add_subdirectory(docs)
349endif()
Jonathan Roelofs0fedff12017-07-06 15:20:12 +0000350
Martin Storsjo41118c42018-08-03 05:51:31 +0000351if (EXISTS ${LLVM_CMAKE_PATH})
352 add_subdirectory(test)
353endif()