Saleem Abdulrasool | c5d132b | 2015-04-25 01:46:35 | [diff] [blame] | 1 | #=============================================================================== |
Tanya Lattner | d93178d | 2015-08-06 23:31:37 | [diff] [blame] | 2 | # Setup Project |
Saleem Abdulrasool | c5d132b | 2015-04-25 01:46:35 | [diff] [blame] | 3 | #=============================================================================== |
| 4 | |
Mark de Wever | cbaa359 | 2023-05-24 16:12:32 | [diff] [blame] | 5 | cmake_minimum_required(VERSION 3.20.0) |
Michael Kruse | e14f5f2 | 2024-05-25 15:41:21 | [diff] [blame] | 6 | set(LLVM_SUBPROJECT_TITLE "libunwind") |
Saleem Abdulrasool | c5d132b | 2015-04-25 01:46:35 | [diff] [blame] | 7 | |
John Ericson | 949bbd0 | 2022-01-01 07:03:31 | [diff] [blame] | 8 | set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake") |
| 9 | |
Petr Hosek | 57d4923 | 2017-04-12 02:28:07 | [diff] [blame] | 10 | # Add path for custom modules |
John Ericson | 949bbd0 | 2022-01-01 07:03:31 | [diff] [blame] | 11 | list(INSERT CMAKE_MODULE_PATH 0 |
Petr Hosek | 57d4923 | 2017-04-12 02:28:07 | [diff] [blame] | 12 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake" |
| 13 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" |
Nikolas Klauser | 0af67d1 | 2023-02-20 15:26:19 | [diff] [blame] | 14 | "${CMAKE_CURRENT_SOURCE_DIR}/../runtimes/cmake/Modules" |
John Ericson | 949bbd0 | 2022-01-01 07:03:31 | [diff] [blame] | 15 | "${LLVM_COMMON_CMAKE_UTILS}" |
| 16 | "${LLVM_COMMON_CMAKE_UTILS}/Modules" |
Petr Hosek | 57d4923 | 2017-04-12 02:28:07 | [diff] [blame] | 17 | ) |
| 18 | |
Dominik Montada | 8c03fdf | 2020-08-24 09:01:05 | [diff] [blame] | 19 | set(LIBUNWIND_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 20 | set(LIBUNWIND_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
| 21 | set(LIBUNWIND_LIBCXX_PATH "${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH |
| 22 | "Specify path to libc++ source.") |
| 23 | |
John Ericson | df31ff1 | 2022-01-19 06:45:07 | [diff] [blame] | 24 | include(GNUInstallDirs) |
YunQiang Su | 4520b47 | 2024-02-08 01:15:53 | [diff] [blame] | 25 | include(CheckSymbolExists) |
John Ericson | df31ff1 | 2022-01-19 06:45:07 | [diff] [blame] | 26 | |
Louis Dionne | b0b546d | 2024-12-11 17:49:06 | [diff] [blame] | 27 | if (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.") |
| 30 | endif() |
| 31 | |
Saleem Abdulrasool | c5d132b | 2015-04-25 01:46:35 | [diff] [blame] | 32 | #=============================================================================== |
| 33 | # Setup CMake Options |
| 34 | #=============================================================================== |
Petr Hosek | 641a29d | 2018-07-24 23:42:51 | [diff] [blame] | 35 | include(CMakeDependentOption) |
Petr Hosek | 57d4923 | 2017-04-12 02:28:07 | [diff] [blame] | 36 | include(HandleCompilerRT) |
Saleem Abdulrasool | c5d132b | 2015-04-25 01:46:35 | [diff] [blame] | 37 | |
| 38 | # Define options. |
gejin | 21b25a1 | 2021-08-26 08:20:38 | [diff] [blame] | 39 | option(LIBUNWIND_ENABLE_CET "Build libunwind with CET enabled." OFF) |
John Brawn | b32aac4 | 2024-08-04 12:27:12 | [diff] [blame] | 40 | option(LIBUNWIND_ENABLE_GCS "Build libunwind with GCS enabled." OFF) |
Saleem Abdulrasool | c5d132b | 2015-04-25 01:46:35 | [diff] [blame] | 41 | option(LIBUNWIND_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON) |
| 42 | option(LIBUNWIND_ENABLE_PEDANTIC "Compile with pedantic enabled." ON) |
| 43 | option(LIBUNWIND_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) |
Saleem Abdulrasool | c5d132b | 2015-04-25 01:46:35 | [diff] [blame] | 44 | option(LIBUNWIND_ENABLE_SHARED "Build libunwind as a shared library." ON) |
Petr Hosek | f3f5f12 | 2016-08-08 22:55:48 | [diff] [blame] | 45 | option(LIBUNWIND_ENABLE_STATIC "Build libunwind as a static library." ON) |
Asiri Rathnayake | 85624c5 | 2016-05-27 08:29:27 | [diff] [blame] | 46 | option(LIBUNWIND_ENABLE_CROSS_UNWINDING "Enable cross-platform unwinding support." OFF) |
Asiri Rathnayake | f33c342 | 2016-07-07 10:55:39 | [diff] [blame] | 47 | option(LIBUNWIND_ENABLE_ARM_WMMX "Enable unwinding support for ARM WMMX registers." OFF) |
Asiri Rathnayake | 6264758 | 2016-09-28 10:57:15 | [diff] [blame] | 48 | option(LIBUNWIND_ENABLE_THREADS "Build libunwind with threading support." ON) |
Sterling Augustine | 7981a28 | 2019-05-13 18:45:03 | [diff] [blame] | 49 | option(LIBUNWIND_WEAK_PTHREAD_LIB "Use weak references to refer to pthread functions." OFF) |
Petr Hosek | 57d4923 | 2017-04-12 02:28:07 | [diff] [blame] | 50 | option(LIBUNWIND_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF) |
Jonathan Roelofs | af9d03a | 2017-03-28 15:21:43 | [diff] [blame] | 51 | option(LIBUNWIND_INCLUDE_DOCS "Build the libunwind documentation." ${LLVM_INCLUDE_DOCS}) |
Kristina Bessonova | f042fd4 | 2021-02-13 10:49:47 | [diff] [blame] | 52 | option(LIBUNWIND_INCLUDE_TESTS "Build the libunwind tests." ${LLVM_INCLUDE_TESTS}) |
Hafiz Abid Qadeer | 380fee3 | 2020-07-29 10:39:41 | [diff] [blame] | 53 | option(LIBUNWIND_IS_BAREMETAL "Build libunwind for baremetal targets." OFF) |
Sterling Augustine | a20f5fe | 2020-08-18 19:05:07 | [diff] [blame] | 54 | option(LIBUNWIND_USE_FRAME_HEADER_CACHE "Cache frame headers for unwinding. Requires locking dl_iterate_phdr." OFF) |
Daniel Kiss | e7b8d37 | 2020-11-11 09:58:41 | [diff] [blame] | 55 | option(LIBUNWIND_REMEMBER_HEAP_ALLOC "Use heap instead of the stack for .cfi_remember_state." OFF) |
Louis Dionne | f8409af | 2022-10-11 13:19:55 | [diff] [blame] | 56 | option(LIBUNWIND_INSTALL_HEADERS "Install the libunwind headers." ON) |
Sterling Augustine | 5eb44df | 2023-08-15 18:36:30 | [diff] [blame] | 57 | option(LIBUNWIND_ENABLE_FRAME_APIS "Include libgcc-compatible frame apis." OFF) |
Saleem Abdulrasool | c5d132b | 2015-04-25 01:46:35 | [diff] [blame] | 58 | |
John Ericson | e941b03 | 2022-08-19 02:44:46 | [diff] [blame] | 59 | set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING |
| 60 | "Define suffix of library directory name (32/64)") |
Petr Hosek | b74f98c | 2017-11-17 23:29:46 | [diff] [blame] | 61 | option(LIBUNWIND_INSTALL_LIBRARY "Install the libunwind library." ON) |
Petr Hosek | 4a1e14e | 2018-07-24 23:27:51 | [diff] [blame] | 62 | cmake_dependent_option(LIBUNWIND_INSTALL_STATIC_LIBRARY |
| 63 | "Install the static libunwind library." ON |
| 64 | "LIBUNWIND_ENABLE_STATIC;LIBUNWIND_INSTALL_LIBRARY" OFF) |
| 65 | cmake_dependent_option(LIBUNWIND_INSTALL_SHARED_LIBRARY |
| 66 | "Install the shared libunwind library." ON |
| 67 | "LIBUNWIND_ENABLE_SHARED;LIBUNWIND_INSTALL_LIBRARY" OFF) |
Louis Dionne | 56b7461 | 2021-10-12 18:10:02 | [diff] [blame] | 68 | |
Louis Dionne | 3527e83 | 2024-09-27 13:17:15 | [diff] [blame] | 69 | set(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ö | b25e989 | 2023-03-29 21:36:51 | [diff] [blame] | 75 | if(MINGW) |
Louis Dionne | 2121b96 | 2024-09-30 15:57:35 | [diff] [blame] | 76 | 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ö | b25e989 | 2023-03-29 21:36:51 | [diff] [blame] | 81 | elseif (LIBUNWIND_ENABLE_SHARED) |
Louis Dionne | 56b7461 | 2021-10-12 18:10:02 | [diff] [blame] | 82 | set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-shared.cfg.in") |
| 83 | else() |
| 84 | set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-static.cfg.in") |
| 85 | endif() |
| 86 | set(LIBUNWIND_TEST_CONFIG "${LIBUNWIND_DEFAULT_TEST_CONFIG}" CACHE STRING |
Louis Dionne | 54a8a0d | 2021-09-29 19:26:05 | [diff] [blame] | 87 | "The path to the Lit testing configuration to use when running the tests. |
Louis Dionne | 6fd55bb | 2021-10-12 16:46:21 | [diff] [blame] | 88 | If a relative path is provided, it is assumed to be relative to '<monorepo>/libunwind/test/configs'.") |
Louis Dionne | 54a8a0d | 2021-09-29 19:26:05 | [diff] [blame] | 89 | if (NOT IS_ABSOLUTE "${LIBUNWIND_TEST_CONFIG}") |
Louis Dionne | 6fd55bb | 2021-10-12 16:46:21 | [diff] [blame] | 90 | set(LIBUNWIND_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/configs/${LIBUNWIND_TEST_CONFIG}") |
Louis Dionne | 54a8a0d | 2021-09-29 19:26:05 | [diff] [blame] | 91 | endif() |
Louis Dionne | c631e33 | 2022-05-11 14:16:29 | [diff] [blame] | 92 | message(STATUS "Using libunwind testing configuration: ${LIBUNWIND_TEST_CONFIG}") |
Dominik Montada | 8c03fdf | 2020-08-24 09:01:05 | [diff] [blame] | 93 | set(LIBUNWIND_TEST_PARAMS "" CACHE STRING |
| 94 | "A list of parameters to run the Lit test suite with.") |
Saleem Abdulrasool | c5d132b | 2015-04-25 01:46:35 | [diff] [blame] | 95 | |
Petr Hosek | f3f5f12 | 2016-08-08 22:55:48 | [diff] [blame] | 96 | if (NOT LIBUNWIND_ENABLE_SHARED AND NOT LIBUNWIND_ENABLE_STATIC) |
| 97 | message(FATAL_ERROR "libunwind must be built as either a shared or static library.") |
| 98 | endif() |
| 99 | |
gejin | 21b25a1 | 2021-08-26 08:20:38 | [diff] [blame] | 100 | if (LIBUNWIND_ENABLE_CET AND MSVC) |
| 101 | message(FATAL_ERROR "libunwind CET support is not available for MSVC!") |
| 102 | endif() |
| 103 | |
Martin Storsjö | bedf657 | 2022-04-09 20:40:07 | [diff] [blame] | 104 | if (WIN32) |
| 105 | set(LIBUNWIND_DEFAULT_HIDE_SYMBOLS TRUE) |
| 106 | else() |
| 107 | set(LIBUNWIND_DEFAULT_HIDE_SYMBOLS FALSE) |
| 108 | endif() |
Ryan Prichard | 729899f | 2021-02-23 00:35:38 | [diff] [blame] | 109 | option(LIBUNWIND_HIDE_SYMBOLS |
Martin Storsjö | bedf657 | 2022-04-09 20:40:07 | [diff] [blame] | 110 | "Do not export any symbols from the static library." ${LIBUNWIND_DEFAULT_HIDE_SYMBOLS}) |
Petr Hosek | 3cfc55cf | 2019-01-29 23:01:08 | [diff] [blame] | 111 | |
YunQiang Su | 4520b47 | 2024-02-08 01:15:53 | [diff] [blame] | 112 | # 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 |
| 114 | check_symbol_exists(__mips_hard_float "" __MIPSHF) |
| 115 | check_symbol_exists(_ABIO32 "" __MIPS_O32) |
| 116 | if (__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') |
| 124 | endif() |
| 125 | |
Saleem Abdulrasool | c5d132b | 2015-04-25 01:46:35 | [diff] [blame] | 126 | #=============================================================================== |
| 127 | # Configure System |
| 128 | #=============================================================================== |
| 129 | |
| 130 | # Add path for custom modules |
| 131 | set(CMAKE_MODULE_PATH |
| 132 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake" |
| 133 | ${CMAKE_MODULE_PATH}) |
| 134 | |
Martin Storsjö | be320fd | 2024-01-10 09:25:17 | [diff] [blame] | 135 | set(LIBUNWIND_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}" CACHE STRING |
John Ericson | 0a8d15a | 2022-01-11 03:03:21 | [diff] [blame] | 136 | "Path where built libunwind headers should be installed.") |
Martin Storsjö | be320fd | 2024-01-10 09:25:17 | [diff] [blame] | 137 | set(LIBUNWIND_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING |
John Ericson | 0a8d15a | 2022-01-11 03:03:21 | [diff] [blame] | 138 | "Path where built libunwind runtime libraries should be installed.") |
| 139 | |
Louis Dionne | 10378b3 | 2022-10-11 14:05:56 | [diff] [blame] | 140 | set(LIBUNWIND_SHARED_OUTPUT_NAME "unwind" CACHE STRING "Output name for the shared libunwind runtime library.") |
| 141 | set(LIBUNWIND_STATIC_OUTPUT_NAME "unwind" CACHE STRING "Output name for the static libunwind runtime library.") |
| 142 | |
Eric Christopher | 45a05a5 | 2018-06-29 20:27:40 | [diff] [blame] | 143 | if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) |
Petr Hosek | ed155f3 | 2024-05-31 18:48:45 | [diff] [blame] | 144 | set(LIBUNWIND_TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE}) |
| 145 | if(LIBUNWIND_LIBDIR_SUBDIR) |
| 146 | string(APPEND LIBUNWIND_TARGET_SUBDIR /${LIBUNWIND_LIBDIR_SUBDIR}) |
Petr Hosek | 81f433b | 2019-05-22 21:08:33 | [diff] [blame] | 147 | endif() |
Petr Hosek | ed155f3 | 2024-05-31 18:48:45 | [diff] [blame] | 148 | 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 Hosek | 4158131 | 2017-07-18 21:30:18 | [diff] [blame] | 152 | else() |
John Ericson | 914fffc | 2022-01-09 00:08:15 | [diff] [blame] | 153 | if(LLVM_LIBRARY_OUTPUT_INTDIR) |
| 154 | set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) |
| 155 | else() |
John Ericson | e941b03 | 2022-08-19 02:44:46 | [diff] [blame] | 156 | set(LIBUNWIND_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBUNWIND_LIBDIR_SUFFIX}) |
John Ericson | 914fffc | 2022-01-09 00:08:15 | [diff] [blame] | 157 | endif() |
Martin Storsjö | be320fd | 2024-01-10 09:25:17 | [diff] [blame] | 158 | set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX} CACHE STRING |
John Ericson | 1e03c37 | 2021-04-28 22:36:47 | [diff] [blame] | 159 | "Path where built libunwind libraries should be installed.") |
Petr Hosek | 4158131 | 2017-07-18 21:30:18 | [diff] [blame] | 160 | endif() |
| 161 | |
| 162 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR}) |
| 163 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR}) |
| 164 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR}) |
Saleem Abdulrasool | c5d132b | 2015-04-25 01:46:35 | [diff] [blame] | 165 | |
Eric Fiselier | 0447bde | 2016-06-02 01:02:10 | [diff] [blame] | 166 | set(LIBUNWIND_C_FLAGS "") |
| 167 | set(LIBUNWIND_CXX_FLAGS "") |
| 168 | set(LIBUNWIND_COMPILE_FLAGS "") |
| 169 | set(LIBUNWIND_LINK_FLAGS "") |
Louis Dionne | e674424 | 2024-10-17 20:17:40 | [diff] [blame] | 170 | set(LIBUNWIND_ADDITIONAL_COMPILE_FLAGS "" CACHE STRING "See documentation for LIBCXX_ADDITIONAL_COMPILE_FLAGS") |
mgrzywac | 9e37142 | 2023-06-29 07:41:08 | [diff] [blame] | 171 | set(LIBUNWIND_ADDITIONAL_LIBRARIES "" CACHE STRING |
| 172 | "Additional libraries libunwind is linked to which can be provided in cache") |
Saleem Abdulrasool | c5d132b | 2015-04-25 01:46:35 | [diff] [blame] | 173 | |
Petr Hosek | 20da3bd | 2019-10-11 22:22:29 | [diff] [blame] | 174 | # Include macros for adding and removing libunwind flags. |
| 175 | include(HandleLibunwindFlags) |
| 176 | |
| 177 | #=============================================================================== |
| 178 | # Setup Compiler Flags |
| 179 | #=============================================================================== |
| 180 | |
Eric Fiselier | 0447bde | 2016-06-02 01:02:10 | [diff] [blame] | 181 | # Configure compiler. |
| 182 | include(config-ix) |
| 183 | |
Charles Davis | 4c08654 | 2018-09-04 20:57:50 | [diff] [blame] | 184 | if (LIBUNWIND_USE_COMPILER_RT AND NOT LIBUNWIND_HAS_NODEFAULTLIBS_FLAG) |
Petr Hosek | 57d4923 | 2017-04-12 02:28:07 | [diff] [blame] | 185 | list(APPEND LIBUNWIND_LINK_FLAGS "-rtlib=compiler-rt") |
| 186 | endif() |
| 187 | |
Petr Hosek | 20da3bd | 2019-10-11 22:22:29 | [diff] [blame] | 188 | add_compile_flags_if_supported(-Werror=return-type) |
Saleem Abdulrasool | c5d132b | 2015-04-25 01:46:35 | [diff] [blame] | 189 | |
gejin | 21b25a1 | 2021-08-26 08:20:38 | [diff] [blame] | 190 | if (LIBUNWIND_ENABLE_CET) |
| 191 | add_compile_flags_if_supported(-fcf-protection=full) |
| 192 | add_compile_flags_if_supported(-mshstk) |
jinge90 | 09dcb93 | 2022-10-18 22:00:09 | [diff] [blame] | 193 | if (NOT CXX_SUPPORTS_FCF_PROTECTION_EQ_FULL_FLAG) |
gejin | 21b25a1 | 2021-08-26 08:20:38 | [diff] [blame] | 194 | message(SEND_ERROR "Compiler doesn't support CET -fcf-protection option!") |
| 195 | endif() |
jinge90 | 09dcb93 | 2022-10-18 22:00:09 | [diff] [blame] | 196 | if (NOT CXX_SUPPORTS_MSHSTK_FLAG) |
gejin | 21b25a1 | 2021-08-26 08:20:38 | [diff] [blame] | 197 | message(SEND_ERROR "Compiler doesn't support CET -mshstk option!") |
| 198 | endif() |
| 199 | endif() |
| 200 | |
John Brawn | b32aac4 | 2024-08-04 12:27:12 | [diff] [blame] | 201 | if (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() |
| 206 | endif() |
| 207 | |
Martin Storsjö | df6d2e8 | 2020-10-23 19:51:21 | [diff] [blame] | 208 | if (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) |
| 214 | endif() |
| 215 | |
YunQiang Su | 4520b47 | 2024-02-08 01:15:53 | [diff] [blame] | 216 | if (MIPS_FPABI_FPXX) |
| 217 | add_compile_flags(-mfp64) |
| 218 | endif() |
| 219 | |
Saleem Abdulrasool | c5d132b | 2015-04-25 01:46:35 | [diff] [blame] | 220 | # 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 Hosek | 20da3bd | 2019-10-11 22:22:29 | [diff] [blame] | 224 | add_cxx_compile_flags_if_supported(-fstrict-aliasing) |
| 225 | add_cxx_compile_flags_if_supported(-EHsc) |
Saleem Abdulrasool | c5d132b | 2015-04-25 01:46:35 | [diff] [blame] | 226 | |
Sergej Jaskiewicz | 57fc8ec | 2019-12-06 14:26:35 | [diff] [blame] | 227 | # 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. |
| 240 | set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE}) |
| 241 | set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) |
Petr Hosek | e3250b0 | 2019-10-12 01:50:57 | [diff] [blame] | 242 | add_compile_flags_if_supported(-funwind-tables) |
Sergej Jaskiewicz | 57fc8ec | 2019-12-06 14:26:35 | [diff] [blame] | 243 | set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE}) |
| 244 | |
Petr Hosek | b3df14b | 2022-03-10 09:47:09 | [diff] [blame] | 245 | if (LIBUNWIND_USES_ARM_EHABI AND NOT CXX_SUPPORTS_FUNWIND_TABLES_FLAG) |
Sergej Jaskiewicz | 57fc8ec | 2019-12-06 14:26:35 | [diff] [blame] | 246 | message(SEND_ERROR "The -funwind-tables flag must be supported " |
| 247 | "because this target uses ARM Exception Handling ABI") |
| 248 | endif() |
| 249 | |
Petr Hosek | 20da3bd | 2019-10-11 22:22:29 | [diff] [blame] | 250 | add_cxx_compile_flags_if_supported(-fno-exceptions) |
| 251 | add_cxx_compile_flags_if_supported(-fno-rtti) |
Saleem Abdulrasool | c5d132b | 2015-04-25 01:46:35 | [diff] [blame] | 252 | |
Petr Hosek | 7fac5172 | 2019-01-29 22:26:18 | [diff] [blame] | 253 | # Ensure that we don't depend on C++ standard library. |
Petr Hosek | b3df14b | 2022-03-10 09:47:09 | [diff] [blame] | 254 | if (CXX_SUPPORTS_NOSTDINCXX_FLAG) |
Petr Hosek | 20da3bd | 2019-10-11 22:22:29 | [diff] [blame] | 255 | list(APPEND LIBUNWIND_COMPILE_FLAGS -nostdinc++) |
| 256 | # Remove -stdlib flags to prevent them from causing an unused flag warning. |
Raphael Isemann | 6b7a49b | 2020-10-13 14:05:00 | [diff] [blame] | 257 | string(REPLACE "--stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 258 | string(REPLACE "--stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
Petr Hosek | 20da3bd | 2019-10-11 22:22:29 | [diff] [blame] | 259 | string(REPLACE "-stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 260 | string(REPLACE "-stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 261 | endif() |
Petr Hosek | 7fac5172 | 2019-01-29 22:26:18 | [diff] [blame] | 262 | |
Saleem Abdulrasool | c5d132b | 2015-04-25 01:46:35 | [diff] [blame] | 263 | # Assert |
| 264 | string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) |
| 265 | if (LIBUNWIND_ENABLE_ASSERTIONS) |
| 266 | # MSVC doesn't like _DEBUG on release builds. See PR 4379. |
| 267 | if (NOT MSVC) |
Petr Hosek | 20da3bd | 2019-10-11 22:22:29 | [diff] [blame] | 268 | add_compile_flags(-D_DEBUG) |
Eugene Zelenko | 5608df9 | 2016-08-08 17:56:28 | [diff] [blame] | 269 | endif() |
Saleem Abdulrasool | c5d132b | 2015-04-25 01:46:35 | [diff] [blame] | 270 | |
| 271 | # On Release builds cmake automatically defines NDEBUG, so we |
| 272 | # explicitly undefine it: |
Martin Storsjö | f1f8899 | 2022-05-04 09:52:20 | [diff] [blame] | 273 | if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") |
Petr Hosek | 20da3bd | 2019-10-11 22:22:29 | [diff] [blame] | 274 | add_compile_flags(-UNDEBUG) |
Eugene Zelenko | 5608df9 | 2016-08-08 17:56:28 | [diff] [blame] | 275 | endif() |
Saleem Abdulrasool | c5d132b | 2015-04-25 01:46:35 | [diff] [blame] | 276 | else() |
Martin Storsjö | f1f8899 | 2022-05-04 09:52:20 | [diff] [blame] | 277 | if (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") |
Petr Hosek | 20da3bd | 2019-10-11 22:22:29 | [diff] [blame] | 278 | add_compile_flags(-DNDEBUG) |
Eugene Zelenko | 5608df9 | 2016-08-08 17:56:28 | [diff] [blame] | 279 | endif() |
| 280 | endif() |
Saleem Abdulrasool | c5d132b | 2015-04-25 01:46:35 | [diff] [blame] | 281 | |
Asiri Rathnayake | 54387ee | 2016-05-25 12:36:34 | [diff] [blame] | 282 | # Cross-unwinding |
| 283 | if (NOT LIBUNWIND_ENABLE_CROSS_UNWINDING) |
Petr Hosek | 20da3bd | 2019-10-11 22:22:29 | [diff] [blame] | 284 | add_compile_flags(-D_LIBUNWIND_IS_NATIVE_ONLY) |
Eugene Zelenko | 5608df9 | 2016-08-08 17:56:28 | [diff] [blame] | 285 | endif() |
Asiri Rathnayake | 54387ee | 2016-05-25 12:36:34 | [diff] [blame] | 286 | |
Sterling Augustine | 5eb44df | 2023-08-15 18:36:30 | [diff] [blame] | 287 | # Include stubs for __register_frame_info_bases and related |
| 288 | if (LIBUNWIND_ENABLE_FRAME_APIS) |
| 289 | add_compile_flags(-D_LIBUNWIND_SUPPORT_FRAME_APIS) |
| 290 | endif() |
| 291 | |
Asiri Rathnayake | 6264758 | 2016-09-28 10:57:15 | [diff] [blame] | 292 | # Threading-support |
| 293 | if (NOT LIBUNWIND_ENABLE_THREADS) |
Petr Hosek | 20da3bd | 2019-10-11 22:22:29 | [diff] [blame] | 294 | add_compile_flags(-D_LIBUNWIND_HAS_NO_THREADS) |
Asiri Rathnayake | 6264758 | 2016-09-28 10:57:15 | [diff] [blame] | 295 | endif() |
| 296 | |
Asiri Rathnayake | f33c342 | 2016-07-07 10:55:39 | [diff] [blame] | 297 | # ARM WMMX register support |
| 298 | if (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 Hosek | 20da3bd | 2019-10-11 22:22:29 | [diff] [blame] | 303 | add_compile_flags(-D__ARM_WMMX) |
Eugene Zelenko | 5608df9 | 2016-08-08 17:56:28 | [diff] [blame] | 304 | endif() |
Asiri Rathnayake | f33c342 | 2016-07-07 10:55:39 | [diff] [blame] | 305 | |
Hafiz Abid Qadeer | 380fee3 | 2020-07-29 10:39:41 | [diff] [blame] | 306 | if(LIBUNWIND_IS_BAREMETAL) |
| 307 | add_compile_definitions(_LIBUNWIND_IS_BAREMETAL) |
| 308 | endif() |
| 309 | |
Sterling Augustine | a20f5fe | 2020-08-18 19:05:07 | [diff] [blame] | 310 | if(LIBUNWIND_USE_FRAME_HEADER_CACHE) |
| 311 | add_compile_definitions(_LIBUNWIND_USE_FRAME_HEADER_CACHE) |
| 312 | endif() |
| 313 | |
Daniel Kiss | e7b8d37 | 2020-11-11 09:58:41 | [diff] [blame] | 314 | if(LIBUNWIND_REMEMBER_HEAP_ALLOC) |
| 315 | add_compile_definitions(_LIBUNWIND_REMEMBER_HEAP_ALLOC) |
| 316 | endif() |
| 317 | |
Saleem Abdulrasool | c5d132b | 2015-04-25 01:46:35 | [diff] [blame] | 318 | # This is the _ONLY_ place where add_definitions is called. |
| 319 | if (MSVC) |
| 320 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) |
Eugene Zelenko | 5608df9 | 2016-08-08 17:56:28 | [diff] [blame] | 321 | endif() |
Saleem Abdulrasool | c5d132b | 2015-04-25 01:46:35 | [diff] [blame] | 322 | |
Petr Hosek | b3df14b | 2022-03-10 09:47:09 | [diff] [blame] | 323 | if (C_SUPPORTS_COMMENT_LIB_PRAGMA) |
Michał Górny | 35bc527 | 2019-11-30 14:13:56 | [diff] [blame] | 324 | 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 Hosek | 789b7f0 | 2019-05-30 04:40:21 | [diff] [blame] | 330 | endif() |
| 331 | |
Saleem Abdulrasool | c5d132b | 2015-04-25 01:46:35 | [diff] [blame] | 332 | #=============================================================================== |
| 333 | # Setup Source Code |
| 334 | #=============================================================================== |
| 335 | |
PoYao Chang | 1c4867e | 2021-12-16 18:32:12 | [diff] [blame] | 336 | add_subdirectory(include) |
Saleem Abdulrasool | c5d132b | 2015-04-25 01:46:35 | [diff] [blame] | 337 | |
| 338 | add_subdirectory(src) |
Jonathan Roelofs | af9d03a | 2017-03-28 15:21:43 | [diff] [blame] | 339 | |
| 340 | if (LIBUNWIND_INCLUDE_DOCS) |
| 341 | add_subdirectory(docs) |
| 342 | endif() |
Jonathan Roelofs | 6e50d93 | 2017-07-06 15:20:12 | [diff] [blame] | 343 | |
Alfonso Gregory | a2c319f | 2021-09-16 16:27:53 | [diff] [blame] | 344 | if (LIBUNWIND_INCLUDE_TESTS AND EXISTS ${LLVM_CMAKE_DIR}) |
Martin Storsjo | 5d108d2 | 2018-08-03 05:51:31 | [diff] [blame] | 345 | add_subdirectory(test) |
| 346 | endif() |