blob: 3c8499fd33464974df5a1f0087643d699f487f04 [file] [log] [blame]
Saleem Abdulrasoolc5d132b2015-04-25 01:46:351#===============================================================================
Tanya Lattnerd93178d2015-08-06 23:31:372# Setup Project
Saleem Abdulrasoolc5d132b2015-04-25 01:46:353#===============================================================================
4
Mark de Wevercbaa3592023-05-24 16:12:325cmake_minimum_required(VERSION 3.20.0)
Michael Krusee14f5f22024-05-25 15:41:216set(LLVM_SUBPROJECT_TITLE "libunwind")
Saleem Abdulrasoolc5d132b2015-04-25 01:46:357
John Ericson949bbd02022-01-01 07:03:318set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
9
Petr Hosek57d49232017-04-12 02:28:0710# Add path for custom modules
John Ericson949bbd02022-01-01 07:03:3111list(INSERT CMAKE_MODULE_PATH 0
Petr Hosek57d49232017-04-12 02:28:0712 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
13 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
Nikolas Klauser0af67d12023-02-20 15:26:1914 "${CMAKE_CURRENT_SOURCE_DIR}/../runtimes/cmake/Modules"
John Ericson949bbd02022-01-01 07:03:3115 "${LLVM_COMMON_CMAKE_UTILS}"
16 "${LLVM_COMMON_CMAKE_UTILS}/Modules"
Petr Hosek57d49232017-04-12 02:28:0717 )
18
Dominik Montada8c03fdf2020-08-24 09:01:0519set(LIBUNWIND_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
20set(LIBUNWIND_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
21set(LIBUNWIND_LIBCXX_PATH "${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH
22 "Specify path to libc++ source.")
23
John Ericsondf31ff12022-01-19 06:45:0724include(GNUInstallDirs)
YunQiang Su4520b472024-02-08 01:15:5325include(CheckSymbolExists)
John Ericsondf31ff12022-01-19 06:45:0726
Louis Dionneb0b546d2024-12-11 17:49:0627if (MSVC)
28 message(FATAL_ERROR "Libunwind doesn't build for MSVC targets, and that is almost certainly not what you want to do "
29 "anyway since libunwind is tied to the Itanium C++ ABI, and MSVC targets must use the MS C++ ABI.")
30endif()
31
Saleem Abdulrasoolc5d132b2015-04-25 01:46:3532#===============================================================================
33# Setup CMake Options
34#===============================================================================
Petr Hosek641a29d2018-07-24 23:42:5135include(CMakeDependentOption)
Petr Hosek57d49232017-04-12 02:28:0736include(HandleCompilerRT)
Saleem Abdulrasoolc5d132b2015-04-25 01:46:3537
38# Define options.
gejin21b25a12021-08-26 08:20:3839option(LIBUNWIND_ENABLE_CET "Build libunwind with CET enabled." OFF)
John Brawnb32aac42024-08-04 12:27:1240option(LIBUNWIND_ENABLE_GCS "Build libunwind with GCS enabled." OFF)
Saleem Abdulrasoolc5d132b2015-04-25 01:46:3541option(LIBUNWIND_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
42option(LIBUNWIND_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
43option(LIBUNWIND_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
Saleem Abdulrasoolc5d132b2015-04-25 01:46:3544option(LIBUNWIND_ENABLE_SHARED "Build libunwind as a shared library." ON)
Petr Hosekf3f5f122016-08-08 22:55:4845option(LIBUNWIND_ENABLE_STATIC "Build libunwind as a static library." ON)
Asiri Rathnayake85624c52016-05-27 08:29:2746option(LIBUNWIND_ENABLE_CROSS_UNWINDING "Enable cross-platform unwinding support." OFF)
Asiri Rathnayakef33c3422016-07-07 10:55:3947option(LIBUNWIND_ENABLE_ARM_WMMX "Enable unwinding support for ARM WMMX registers." OFF)
Asiri Rathnayake62647582016-09-28 10:57:1548option(LIBUNWIND_ENABLE_THREADS "Build libunwind with threading support." ON)
Sterling Augustine7981a282019-05-13 18:45:0349option(LIBUNWIND_WEAK_PTHREAD_LIB "Use weak references to refer to pthread functions." OFF)
Petr Hosek57d49232017-04-12 02:28:0750option(LIBUNWIND_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
Jonathan Roelofsaf9d03a2017-03-28 15:21:4351option(LIBUNWIND_INCLUDE_DOCS "Build the libunwind documentation." ${LLVM_INCLUDE_DOCS})
Kristina Bessonovaf042fd42021-02-13 10:49:4752option(LIBUNWIND_INCLUDE_TESTS "Build the libunwind tests." ${LLVM_INCLUDE_TESTS})
Hafiz Abid Qadeer380fee32020-07-29 10:39:4153option(LIBUNWIND_IS_BAREMETAL "Build libunwind for baremetal targets." OFF)
Sterling Augustinea20f5fe2020-08-18 19:05:0754option(LIBUNWIND_USE_FRAME_HEADER_CACHE "Cache frame headers for unwinding. Requires locking dl_iterate_phdr." OFF)
Daniel Kisse7b8d372020-11-11 09:58:4155option(LIBUNWIND_REMEMBER_HEAP_ALLOC "Use heap instead of the stack for .cfi_remember_state." OFF)
Louis Dionnef8409af2022-10-11 13:19:5556option(LIBUNWIND_INSTALL_HEADERS "Install the libunwind headers." ON)
Sterling Augustine5eb44df2023-08-15 18:36:3057option(LIBUNWIND_ENABLE_FRAME_APIS "Include libgcc-compatible frame apis." OFF)
Saleem Abdulrasoolc5d132b2015-04-25 01:46:3558
John Ericsone941b032022-08-19 02:44:4659set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
60 "Define suffix of library directory name (32/64)")
Petr Hosekb74f98c2017-11-17 23:29:4661option(LIBUNWIND_INSTALL_LIBRARY "Install the libunwind library." ON)
Petr Hosek4a1e14e2018-07-24 23:27:5162cmake_dependent_option(LIBUNWIND_INSTALL_STATIC_LIBRARY
63 "Install the static libunwind library." ON
64 "LIBUNWIND_ENABLE_STATIC;LIBUNWIND_INSTALL_LIBRARY" OFF)
65cmake_dependent_option(LIBUNWIND_INSTALL_SHARED_LIBRARY
66 "Install the shared libunwind library." ON
67 "LIBUNWIND_ENABLE_SHARED;LIBUNWIND_INSTALL_LIBRARY" OFF)
Louis Dionne56b74612021-10-12 18:10:0268
Louis Dionne3527e832024-09-27 13:17:1569set(LIBUNWIND_LIBRARY_VERSION "1.0" CACHE STRING
70 "Version of libunwind. This will be reflected in the name of the shared library produced.
71 For example, -DLIBUNWIND_LIBRARY_VERSION=x.y will result in the library being named
72 libunwind.x.y.dylib, along with the usual symlinks pointing to that. On Apple platforms,
73 this also controls the linker's 'current_version' property.")
74
Martin Storsjöb25e9892023-03-29 21:36:5175if(MINGW)
Louis Dionne2121b962024-09-30 15:57:3576 if (LIBUNWIND_ENABLE_SHARED)
77 set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-shared-mingw.cfg.in")
78 else()
79 set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-static-mingw.cfg.in")
80 endif()
Martin Storsjöb25e9892023-03-29 21:36:5181elseif (LIBUNWIND_ENABLE_SHARED)
Louis Dionne56b74612021-10-12 18:10:0282 set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-shared.cfg.in")
83else()
84 set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-static.cfg.in")
85endif()
86set(LIBUNWIND_TEST_CONFIG "${LIBUNWIND_DEFAULT_TEST_CONFIG}" CACHE STRING
Louis Dionne54a8a0d2021-09-29 19:26:0587 "The path to the Lit testing configuration to use when running the tests.
Louis Dionne6fd55bb2021-10-12 16:46:2188 If a relative path is provided, it is assumed to be relative to '<monorepo>/libunwind/test/configs'.")
Louis Dionne54a8a0d2021-09-29 19:26:0589if (NOT IS_ABSOLUTE "${LIBUNWIND_TEST_CONFIG}")
Louis Dionne6fd55bb2021-10-12 16:46:2190 set(LIBUNWIND_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/configs/${LIBUNWIND_TEST_CONFIG}")
Louis Dionne54a8a0d2021-09-29 19:26:0591endif()
Louis Dionnec631e332022-05-11 14:16:2992message(STATUS "Using libunwind testing configuration: ${LIBUNWIND_TEST_CONFIG}")
Dominik Montada8c03fdf2020-08-24 09:01:0593set(LIBUNWIND_TEST_PARAMS "" CACHE STRING
94 "A list of parameters to run the Lit test suite with.")
Saleem Abdulrasoolc5d132b2015-04-25 01:46:3595
Petr Hosekf3f5f122016-08-08 22:55:4896if (NOT LIBUNWIND_ENABLE_SHARED AND NOT LIBUNWIND_ENABLE_STATIC)
97 message(FATAL_ERROR "libunwind must be built as either a shared or static library.")
98endif()
99
gejin21b25a12021-08-26 08:20:38100if (LIBUNWIND_ENABLE_CET AND MSVC)
101 message(FATAL_ERROR "libunwind CET support is not available for MSVC!")
102endif()
103
Martin Storsjöbedf6572022-04-09 20:40:07104if (WIN32)
105 set(LIBUNWIND_DEFAULT_HIDE_SYMBOLS TRUE)
106else()
107 set(LIBUNWIND_DEFAULT_HIDE_SYMBOLS FALSE)
108endif()
Ryan Prichard729899f2021-02-23 00:35:38109option(LIBUNWIND_HIDE_SYMBOLS
Martin Storsjöbedf6572022-04-09 20:40:07110 "Do not export any symbols from the static library." ${LIBUNWIND_DEFAULT_HIDE_SYMBOLS})
Petr Hosek3cfc55cf2019-01-29 23:01:08111
YunQiang Su4520b472024-02-08 01:15:53112# If toolchain is FPXX, we switch to FP64 to save the full FPRs. See:
113# https://web.archive.org/web/20180828210612/https://dmz-portal.mips.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking
114check_symbol_exists(__mips_hard_float "" __MIPSHF)
115check_symbol_exists(_ABIO32 "" __MIPS_O32)
116if (__MIPSHF AND __MIPS_O32)
117 file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/mips_is_fpxx.c
118 "#if __mips_fpr != 0\n"
119 "# error\n"
120 "#endif\n")
121 try_compile(MIPS_FPABI_FPXX ${CMAKE_BINARY_DIR}
122 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/mips_is_fpxx.c
123 CMAKE_FLAGS -DCMAKE_C_LINK_EXECUTABLE='echo')
124endif()
125
Saleem Abdulrasoolc5d132b2015-04-25 01:46:35126#===============================================================================
127# Configure System
128#===============================================================================
129
130# Add path for custom modules
131set(CMAKE_MODULE_PATH
132 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
133 ${CMAKE_MODULE_PATH})
134
Martin Storsjöbe320fd2024-01-10 09:25:17135set(LIBUNWIND_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}" CACHE STRING
John Ericson0a8d15a2022-01-11 03:03:21136 "Path where built libunwind headers should be installed.")
Martin Storsjöbe320fd2024-01-10 09:25:17137set(LIBUNWIND_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING
John Ericson0a8d15a2022-01-11 03:03:21138 "Path where built libunwind runtime libraries should be installed.")
139
Louis Dionne10378b32022-10-11 14:05:56140set(LIBUNWIND_SHARED_OUTPUT_NAME "unwind" CACHE STRING "Output name for the shared libunwind runtime library.")
141set(LIBUNWIND_STATIC_OUTPUT_NAME "unwind" CACHE STRING "Output name for the static libunwind runtime library.")
142
Eric Christopher45a05a52018-06-29 20:27:40143if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
Petr Hoseked155f32024-05-31 18:48:45144 set(LIBUNWIND_TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE})
145 if(LIBUNWIND_LIBDIR_SUBDIR)
146 string(APPEND LIBUNWIND_TARGET_SUBDIR /${LIBUNWIND_LIBDIR_SUBDIR})
Petr Hosek81f433b2019-05-22 21:08:33147 endif()
Petr Hoseked155f32024-05-31 18:48:45148 set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LIBUNWIND_TARGET_SUBDIR})
149 set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LIBUNWIND_TARGET_SUBDIR} CACHE STRING
150 "Path where built libunwind libraries should be installed.")
151 unset(LIBUNWIND_TARGET_SUBDIR)
Petr Hosek41581312017-07-18 21:30:18152else()
John Ericson914fffc2022-01-09 00:08:15153 if(LLVM_LIBRARY_OUTPUT_INTDIR)
154 set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
155 else()
John Ericsone941b032022-08-19 02:44:46156 set(LIBUNWIND_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBUNWIND_LIBDIR_SUFFIX})
John Ericson914fffc2022-01-09 00:08:15157 endif()
Martin Storsjöbe320fd2024-01-10 09:25:17158 set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX} CACHE STRING
John Ericson1e03c372021-04-28 22:36:47159 "Path where built libunwind libraries should be installed.")
Petr Hosek41581312017-07-18 21:30:18160endif()
161
162set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR})
163set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR})
164set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR})
Saleem Abdulrasoolc5d132b2015-04-25 01:46:35165
Eric Fiselier0447bde2016-06-02 01:02:10166set(LIBUNWIND_C_FLAGS "")
167set(LIBUNWIND_CXX_FLAGS "")
168set(LIBUNWIND_COMPILE_FLAGS "")
169set(LIBUNWIND_LINK_FLAGS "")
Louis Dionnee6744242024-10-17 20:17:40170set(LIBUNWIND_ADDITIONAL_COMPILE_FLAGS "" CACHE STRING "See documentation for LIBCXX_ADDITIONAL_COMPILE_FLAGS")
mgrzywac9e371422023-06-29 07:41:08171set(LIBUNWIND_ADDITIONAL_LIBRARIES "" CACHE STRING
172 "Additional libraries libunwind is linked to which can be provided in cache")
Saleem Abdulrasoolc5d132b2015-04-25 01:46:35173
Petr Hosek20da3bd2019-10-11 22:22:29174# Include macros for adding and removing libunwind flags.
175include(HandleLibunwindFlags)
176
177#===============================================================================
178# Setup Compiler Flags
179#===============================================================================
180
Eric Fiselier0447bde2016-06-02 01:02:10181# Configure compiler.
182include(config-ix)
183
Charles Davis4c086542018-09-04 20:57:50184if (LIBUNWIND_USE_COMPILER_RT AND NOT LIBUNWIND_HAS_NODEFAULTLIBS_FLAG)
Petr Hosek57d49232017-04-12 02:28:07185 list(APPEND LIBUNWIND_LINK_FLAGS "-rtlib=compiler-rt")
186endif()
187
Petr Hosek20da3bd2019-10-11 22:22:29188add_compile_flags_if_supported(-Werror=return-type)
Saleem Abdulrasoolc5d132b2015-04-25 01:46:35189
gejin21b25a12021-08-26 08:20:38190if (LIBUNWIND_ENABLE_CET)
191 add_compile_flags_if_supported(-fcf-protection=full)
192 add_compile_flags_if_supported(-mshstk)
jinge9009dcb932022-10-18 22:00:09193 if (NOT CXX_SUPPORTS_FCF_PROTECTION_EQ_FULL_FLAG)
gejin21b25a12021-08-26 08:20:38194 message(SEND_ERROR "Compiler doesn't support CET -fcf-protection option!")
195 endif()
jinge9009dcb932022-10-18 22:00:09196 if (NOT CXX_SUPPORTS_MSHSTK_FLAG)
gejin21b25a12021-08-26 08:20:38197 message(SEND_ERROR "Compiler doesn't support CET -mshstk option!")
198 endif()
199endif()
200
John Brawnb32aac42024-08-04 12:27:12201if (LIBUNWIND_ENABLE_GCS)
202 add_compile_flags_if_supported(-mbranch-protection=standard)
203 if (NOT CXX_SUPPORTS_MBRANCH_PROTECTION_EQ_STANDARD_FLAG)
204 message(SEND_ERROR "Compiler doesn't support GCS -mbranch-protection option!")
205 endif()
206endif()
207
Martin Storsjödf6d2e82020-10-23 19:51:21208if (WIN32)
209 # The headers lack matching dllexport attributes (_LIBUNWIND_EXPORT);
210 # silence the warning instead of cluttering the headers (which aren't
211 # necessarily the ones that the callers will use anyway) with the
212 # attributes.
213 add_compile_flags_if_supported(-Wno-dll-attribute-on-redeclaration)
214endif()
215
YunQiang Su4520b472024-02-08 01:15:53216if (MIPS_FPABI_FPXX)
217 add_compile_flags(-mfp64)
218endif()
219
Saleem Abdulrasoolc5d132b2015-04-25 01:46:35220# Get feature flags.
221# Exceptions
222# Catches C++ exceptions only and tells the compiler to assume that extern C
223# functions never throw a C++ exception.
Petr Hosek20da3bd2019-10-11 22:22:29224add_cxx_compile_flags_if_supported(-fstrict-aliasing)
225add_cxx_compile_flags_if_supported(-EHsc)
Saleem Abdulrasoolc5d132b2015-04-25 01:46:35226
Sergej Jaskiewicz57fc8ec2019-12-06 14:26:35227# Don't run the linker in this CMake check.
228#
229# The reason why this was added is that when building libunwind for
230# ARM Linux, we need to pass the -funwind-tables flag in order for it to
231# work properly with ARM EHABI.
232#
233# However, when performing CMake checks, adding this flag causes the check
234# to produce a false negative, because the compiler generates calls
235# to __aeabi_unwind_cpp_pr0, which is defined in libunwind itself,
236# which isn't built yet, so the linker complains about undefined symbols.
237#
238# This leads to libunwind not being built with this flag, which makes
239# libunwind quite useless in this setup.
240set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
241set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
Petr Hoseke3250b02019-10-12 01:50:57242add_compile_flags_if_supported(-funwind-tables)
Sergej Jaskiewicz57fc8ec2019-12-06 14:26:35243set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
244
Petr Hosekb3df14b2022-03-10 09:47:09245if (LIBUNWIND_USES_ARM_EHABI AND NOT CXX_SUPPORTS_FUNWIND_TABLES_FLAG)
Sergej Jaskiewicz57fc8ec2019-12-06 14:26:35246 message(SEND_ERROR "The -funwind-tables flag must be supported "
247 "because this target uses ARM Exception Handling ABI")
248endif()
249
Petr Hosek20da3bd2019-10-11 22:22:29250add_cxx_compile_flags_if_supported(-fno-exceptions)
251add_cxx_compile_flags_if_supported(-fno-rtti)
Saleem Abdulrasoolc5d132b2015-04-25 01:46:35252
Petr Hosek7fac51722019-01-29 22:26:18253# Ensure that we don't depend on C++ standard library.
Petr Hosekb3df14b2022-03-10 09:47:09254if (CXX_SUPPORTS_NOSTDINCXX_FLAG)
Petr Hosek20da3bd2019-10-11 22:22:29255 list(APPEND LIBUNWIND_COMPILE_FLAGS -nostdinc++)
256 # Remove -stdlib flags to prevent them from causing an unused flag warning.
Raphael Isemann6b7a49b2020-10-13 14:05:00257 string(REPLACE "--stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
258 string(REPLACE "--stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
Petr Hosek20da3bd2019-10-11 22:22:29259 string(REPLACE "-stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
260 string(REPLACE "-stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
261endif()
Petr Hosek7fac51722019-01-29 22:26:18262
Saleem Abdulrasoolc5d132b2015-04-25 01:46:35263# Assert
264string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
265if (LIBUNWIND_ENABLE_ASSERTIONS)
266 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
267 if (NOT MSVC)
Petr Hosek20da3bd2019-10-11 22:22:29268 add_compile_flags(-D_DEBUG)
Eugene Zelenko5608df92016-08-08 17:56:28269 endif()
Saleem Abdulrasoolc5d132b2015-04-25 01:46:35270
271 # On Release builds cmake automatically defines NDEBUG, so we
272 # explicitly undefine it:
Martin Storsjöf1f88992022-05-04 09:52:20273 if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
Petr Hosek20da3bd2019-10-11 22:22:29274 add_compile_flags(-UNDEBUG)
Eugene Zelenko5608df92016-08-08 17:56:28275 endif()
Saleem Abdulrasoolc5d132b2015-04-25 01:46:35276else()
Martin Storsjöf1f88992022-05-04 09:52:20277 if (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
Petr Hosek20da3bd2019-10-11 22:22:29278 add_compile_flags(-DNDEBUG)
Eugene Zelenko5608df92016-08-08 17:56:28279 endif()
280endif()
Saleem Abdulrasoolc5d132b2015-04-25 01:46:35281
Asiri Rathnayake54387ee2016-05-25 12:36:34282# Cross-unwinding
283if (NOT LIBUNWIND_ENABLE_CROSS_UNWINDING)
Petr Hosek20da3bd2019-10-11 22:22:29284 add_compile_flags(-D_LIBUNWIND_IS_NATIVE_ONLY)
Eugene Zelenko5608df92016-08-08 17:56:28285endif()
Asiri Rathnayake54387ee2016-05-25 12:36:34286
Sterling Augustine5eb44df2023-08-15 18:36:30287# Include stubs for __register_frame_info_bases and related
288if (LIBUNWIND_ENABLE_FRAME_APIS)
289 add_compile_flags(-D_LIBUNWIND_SUPPORT_FRAME_APIS)
290endif()
291
Asiri Rathnayake62647582016-09-28 10:57:15292# Threading-support
293if (NOT LIBUNWIND_ENABLE_THREADS)
Petr Hosek20da3bd2019-10-11 22:22:29294 add_compile_flags(-D_LIBUNWIND_HAS_NO_THREADS)
Asiri Rathnayake62647582016-09-28 10:57:15295endif()
296
Asiri Rathnayakef33c3422016-07-07 10:55:39297# 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 Hosek20da3bd2019-10-11 22:22:29303 add_compile_flags(-D__ARM_WMMX)
Eugene Zelenko5608df92016-08-08 17:56:28304endif()
Asiri Rathnayakef33c3422016-07-07 10:55:39305
Hafiz Abid Qadeer380fee32020-07-29 10:39:41306if(LIBUNWIND_IS_BAREMETAL)
307 add_compile_definitions(_LIBUNWIND_IS_BAREMETAL)
308endif()
309
Sterling Augustinea20f5fe2020-08-18 19:05:07310if(LIBUNWIND_USE_FRAME_HEADER_CACHE)
311 add_compile_definitions(_LIBUNWIND_USE_FRAME_HEADER_CACHE)
312endif()
313
Daniel Kisse7b8d372020-11-11 09:58:41314if(LIBUNWIND_REMEMBER_HEAP_ALLOC)
315 add_compile_definitions(_LIBUNWIND_REMEMBER_HEAP_ALLOC)
316endif()
317
Saleem Abdulrasoolc5d132b2015-04-25 01:46:35318# This is the _ONLY_ place where add_definitions is called.
319if (MSVC)
320 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
Eugene Zelenko5608df92016-08-08 17:56:28321endif()
Saleem Abdulrasoolc5d132b2015-04-25 01:46:35322
Petr Hosekb3df14b2022-03-10 09:47:09323if (C_SUPPORTS_COMMENT_LIB_PRAGMA)
Michał Górny35bc5272019-11-30 14:13:56324 if (LIBUNWIND_HAS_DL_LIB)
325 add_definitions(-D_LIBUNWIND_LINK_DL_LIB)
326 endif()
327 if (LIBUNWIND_HAS_PTHREAD_LIB)
328 add_definitions(-D_LIBUNWIND_LINK_PTHREAD_LIB)
329 endif()
Petr Hosek789b7f02019-05-30 04:40:21330endif()
331
Saleem Abdulrasoolc5d132b2015-04-25 01:46:35332#===============================================================================
333# Setup Source Code
334#===============================================================================
335
PoYao Chang1c4867e2021-12-16 18:32:12336add_subdirectory(include)
Saleem Abdulrasoolc5d132b2015-04-25 01:46:35337
338add_subdirectory(src)
Jonathan Roelofsaf9d03a2017-03-28 15:21:43339
340if (LIBUNWIND_INCLUDE_DOCS)
341 add_subdirectory(docs)
342endif()
Jonathan Roelofs6e50d932017-07-06 15:20:12343
Alfonso Gregorya2c319f2021-09-16 16:27:53344if (LIBUNWIND_INCLUDE_TESTS AND EXISTS ${LLVM_CMAKE_DIR})
Martin Storsjo5d108d22018-08-03 05:51:31345 add_subdirectory(test)
346endif()