207
|
1 if (NOT IS_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/../libcxx")
|
|
2 message(FATAL_ERROR "libunwind requires being built in a monorepo layout with libcxx available")
|
|
3 endif()
|
|
4
|
150
|
5 #===============================================================================
|
|
6 # Setup Project
|
|
7 #===============================================================================
|
|
8
|
207
|
9 cmake_minimum_required(VERSION 3.13.4)
|
150
|
10
|
|
11 # Add path for custom modules
|
|
12 set(CMAKE_MODULE_PATH
|
|
13 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
|
|
14 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
|
|
15 ${CMAKE_MODULE_PATH}
|
|
16 )
|
|
17
|
207
|
18 set(LIBUNWIND_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
|
19 set(LIBUNWIND_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
20 set(LIBUNWIND_LIBCXX_PATH "${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH
|
|
21 "Specify path to libc++ source.")
|
|
22
|
150
|
23 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBUNWIND_STANDALONE_BUILD)
|
|
24 project(libunwind LANGUAGES C CXX ASM)
|
|
25
|
|
26 set(PACKAGE_NAME libunwind)
|
207
|
27 set(PACKAGE_VERSION 13.0.0git)
|
150
|
28 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
|
|
29 set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org")
|
|
30
|
207
|
31 # 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}")
|
150
|
34
|
207
|
35 # 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")
|
150
|
40
|
207
|
41 # Find the LLVM sources and simulate LLVM CMake options.
|
|
42 include(HandleOutOfTreeLLVM)
|
150
|
43 else()
|
|
44 set(LLVM_LIT "${CMAKE_SOURCE_DIR}/utils/lit/lit.py")
|
|
45 endif()
|
|
46
|
|
47 #===============================================================================
|
|
48 # Setup CMake Options
|
|
49 #===============================================================================
|
|
50 include(CMakeDependentOption)
|
|
51 include(HandleCompilerRT)
|
|
52
|
|
53 # Define options.
|
|
54 option(LIBUNWIND_BUILD_32_BITS "Build 32 bit libunwind" ${LLVM_BUILD_32_BITS})
|
|
55 option(LIBUNWIND_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
|
|
56 option(LIBUNWIND_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
|
|
57 option(LIBUNWIND_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
|
|
58 option(LIBUNWIND_ENABLE_SHARED "Build libunwind as a shared library." ON)
|
|
59 option(LIBUNWIND_ENABLE_STATIC "Build libunwind as a static library." ON)
|
|
60 option(LIBUNWIND_ENABLE_CROSS_UNWINDING "Enable cross-platform unwinding support." OFF)
|
|
61 option(LIBUNWIND_ENABLE_ARM_WMMX "Enable unwinding support for ARM WMMX registers." OFF)
|
|
62 option(LIBUNWIND_ENABLE_THREADS "Build libunwind with threading support." ON)
|
|
63 option(LIBUNWIND_WEAK_PTHREAD_LIB "Use weak references to refer to pthread functions." OFF)
|
|
64 option(LIBUNWIND_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
|
|
65 option(LIBUNWIND_INCLUDE_DOCS "Build the libunwind documentation." ${LLVM_INCLUDE_DOCS})
|
207
|
66 option(LIBUNWIND_INCLUDE_TESTS "Build the libunwind tests." ${LLVM_INCLUDE_TESTS})
|
|
67 option(LIBUNWIND_IS_BAREMETAL "Build libunwind for baremetal targets." OFF)
|
|
68 option(LIBUNWIND_USE_FRAME_HEADER_CACHE "Cache frame headers for unwinding. Requires locking dl_iterate_phdr." OFF)
|
|
69 option(LIBUNWIND_REMEMBER_HEAP_ALLOC "Use heap instead of the stack for .cfi_remember_state." OFF)
|
150
|
70
|
|
71 set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
|
|
72 "Define suffix of library directory name (32/64)")
|
|
73 option(LIBUNWIND_INSTALL_LIBRARY "Install the libunwind library." ON)
|
|
74 cmake_dependent_option(LIBUNWIND_INSTALL_STATIC_LIBRARY
|
|
75 "Install the static libunwind library." ON
|
|
76 "LIBUNWIND_ENABLE_STATIC;LIBUNWIND_INSTALL_LIBRARY" OFF)
|
|
77 cmake_dependent_option(LIBUNWIND_INSTALL_SHARED_LIBRARY
|
|
78 "Install the shared libunwind library." ON
|
|
79 "LIBUNWIND_ENABLE_SHARED;LIBUNWIND_INSTALL_LIBRARY" OFF)
|
|
80 set(LIBUNWIND_TARGET_TRIPLE "" CACHE STRING "Target triple for cross compiling.")
|
|
81 set(LIBUNWIND_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
|
|
82 set(LIBUNWIND_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")
|
|
83 set(LIBUNWIND_TEST_LINKER_FLAGS "" CACHE STRING
|
|
84 "Additional linker flags for test programs.")
|
|
85 set(LIBUNWIND_TEST_COMPILER_FLAGS "" CACHE STRING
|
|
86 "Additional compiler flags for test programs.")
|
207
|
87 set(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.")
|
|
89 set(LIBUNWIND_TEST_PARAMS "" CACHE STRING
|
|
90 "A list of parameters to run the Lit test suite with.")
|
150
|
91
|
|
92 if (NOT LIBUNWIND_ENABLE_SHARED AND NOT LIBUNWIND_ENABLE_STATIC)
|
|
93 message(FATAL_ERROR "libunwind must be built as either a shared or static library.")
|
|
94 endif()
|
|
95
|
|
96 # Check that we can build with 32 bits if requested.
|
|
97 if (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()
|
|
101 elseif(LIBUNWIND_BUILD_32_BITS)
|
|
102 message(FATAL_ERROR "LIBUNWIND_BUILD_32_BITS=ON is not supported on this platform.")
|
|
103 endif()
|
|
104
|
207
|
105 option(LIBUNWIND_HIDE_SYMBOLS
|
150
|
106 "Do not export any symbols from the static library." OFF)
|
|
107
|
|
108 #===============================================================================
|
|
109 # Configure System
|
|
110 #===============================================================================
|
|
111
|
|
112 # Add path for custom modules
|
|
113 set(CMAKE_MODULE_PATH
|
|
114 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
|
|
115 ${CMAKE_MODULE_PATH})
|
|
116
|
|
117 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
|
207
|
118 set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
|
|
119 set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE})
|
150
|
120 if(LIBCXX_LIBDIR_SUBDIR)
|
|
121 string(APPEND LIBUNWIND_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR})
|
|
122 string(APPEND LIBUNWIND_INSTALL_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR})
|
|
123 endif()
|
|
124 elseif(LLVM_LIBRARY_OUTPUT_INTDIR)
|
|
125 set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
|
|
126 set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX})
|
|
127 else()
|
|
128 set(LIBUNWIND_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBUNWIND_LIBDIR_SUFFIX})
|
|
129 set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX})
|
|
130 endif()
|
|
131
|
|
132 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR})
|
|
133 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR})
|
|
134 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR})
|
|
135
|
|
136 set(LIBUNWIND_C_FLAGS "")
|
|
137 set(LIBUNWIND_CXX_FLAGS "")
|
|
138 set(LIBUNWIND_COMPILE_FLAGS "")
|
|
139 set(LIBUNWIND_LINK_FLAGS "")
|
|
140
|
|
141 # Include macros for adding and removing libunwind flags.
|
|
142 include(HandleLibunwindFlags)
|
|
143
|
|
144 #===============================================================================
|
|
145 # Setup Compiler Flags
|
|
146 #===============================================================================
|
|
147
|
|
148 # Get required flags.
|
|
149 add_target_flags_if(LIBUNWIND_BUILD_32_BITS "-m32")
|
|
150
|
|
151 if(LIBUNWIND_TARGET_TRIPLE)
|
|
152 add_target_flags("--target=${LIBUNWIND_TARGET_TRIPLE}")
|
|
153 elseif(CMAKE_CXX_COMPILER_TARGET)
|
|
154 set(LIBUNWIND_TARGET_TRIPLE "${CMAKE_CXX_COMPILER_TARGET}")
|
|
155 endif()
|
|
156 if(LIBUNWIND_GCC_TOOLCHAIN)
|
|
157 add_target_flags("--gcc-toolchain=${LIBUNWIND_GCC_TOOLCHAIN}")
|
|
158 elseif(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN)
|
|
159 set(LIBUNWIND_GCC_TOOLCHAIN "${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}")
|
|
160 endif()
|
|
161 if(LIBUNWIND_SYSROOT)
|
|
162 add_target_flags("--sysroot=${LIBUNWIND_SYSROOT}")
|
|
163 elseif(CMAKE_SYSROOT)
|
|
164 set(LIBUNWIND_SYSROOT "${CMAKE_SYSROOT}")
|
|
165 endif()
|
|
166
|
|
167 if (LIBUNWIND_TARGET_TRIPLE)
|
|
168 set(TARGET_TRIPLE "${LIBUNWIND_TARGET_TRIPLE}")
|
|
169 endif()
|
|
170
|
|
171 # Configure compiler.
|
|
172 include(config-ix)
|
|
173
|
|
174 if (LIBUNWIND_USE_COMPILER_RT AND NOT LIBUNWIND_HAS_NODEFAULTLIBS_FLAG)
|
|
175 list(APPEND LIBUNWIND_LINK_FLAGS "-rtlib=compiler-rt")
|
|
176 endif()
|
|
177
|
|
178 add_compile_flags_if_supported(-Werror=return-type)
|
|
179
|
|
180 # Get warning flags
|
|
181 add_compile_flags_if_supported(-W)
|
|
182 add_compile_flags_if_supported(-Wall)
|
|
183 add_compile_flags_if_supported(-Wchar-subscripts)
|
|
184 add_compile_flags_if_supported(-Wconversion)
|
|
185 add_compile_flags_if_supported(-Wmismatched-tags)
|
|
186 add_compile_flags_if_supported(-Wmissing-braces)
|
|
187 add_compile_flags_if_supported(-Wnewline-eof)
|
|
188 add_compile_flags_if_supported(-Wno-unused-function)
|
|
189 add_compile_flags_if_supported(-Wshadow)
|
|
190 add_compile_flags_if_supported(-Wshorten-64-to-32)
|
|
191 add_compile_flags_if_supported(-Wsign-compare)
|
|
192 add_compile_flags_if_supported(-Wsign-conversion)
|
|
193 add_compile_flags_if_supported(-Wstrict-aliasing=2)
|
|
194 add_compile_flags_if_supported(-Wstrict-overflow=4)
|
|
195 add_compile_flags_if_supported(-Wunused-parameter)
|
|
196 add_compile_flags_if_supported(-Wunused-variable)
|
|
197 add_compile_flags_if_supported(-Wwrite-strings)
|
|
198 add_compile_flags_if_supported(-Wundef)
|
|
199
|
207
|
200 add_compile_flags_if_supported(-Wno-suggest-override)
|
|
201
|
|
202 if (WIN32)
|
|
203 # The headers lack matching dllexport attributes (_LIBUNWIND_EXPORT);
|
|
204 # silence the warning instead of cluttering the headers (which aren't
|
|
205 # necessarily the ones that the callers will use anyway) with the
|
|
206 # attributes.
|
|
207 add_compile_flags_if_supported(-Wno-dll-attribute-on-redeclaration)
|
|
208 endif()
|
|
209
|
150
|
210 if (LIBUNWIND_ENABLE_WERROR)
|
|
211 add_compile_flags_if_supported(-Werror)
|
|
212 add_compile_flags_if_supported(-WX)
|
|
213 else()
|
|
214 add_compile_flags_if_supported(-Wno-error)
|
|
215 add_compile_flags_if_supported(-WX-)
|
|
216 endif()
|
|
217
|
|
218 if (LIBUNWIND_ENABLE_PEDANTIC)
|
|
219 add_compile_flags_if_supported(-pedantic)
|
|
220 endif()
|
|
221
|
|
222 # Get feature flags.
|
|
223 # Exceptions
|
|
224 # Catches C++ exceptions only and tells the compiler to assume that extern C
|
|
225 # functions never throw a C++ exception.
|
|
226 add_cxx_compile_flags_if_supported(-fstrict-aliasing)
|
|
227 add_cxx_compile_flags_if_supported(-EHsc)
|
|
228
|
|
229 # Don't run the linker in this CMake check.
|
|
230 #
|
|
231 # The reason why this was added is that when building libunwind for
|
|
232 # ARM Linux, we need to pass the -funwind-tables flag in order for it to
|
|
233 # work properly with ARM EHABI.
|
|
234 #
|
|
235 # However, when performing CMake checks, adding this flag causes the check
|
|
236 # to produce a false negative, because the compiler generates calls
|
|
237 # to __aeabi_unwind_cpp_pr0, which is defined in libunwind itself,
|
|
238 # which isn't built yet, so the linker complains about undefined symbols.
|
|
239 #
|
|
240 # This leads to libunwind not being built with this flag, which makes
|
|
241 # libunwind quite useless in this setup.
|
|
242 set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
|
|
243 set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
|
244 add_compile_flags_if_supported(-funwind-tables)
|
|
245 set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
|
|
246
|
|
247 if (LIBUNWIND_USES_ARM_EHABI AND NOT LIBUNWIND_SUPPORTS_FUNWIND_TABLES_FLAG)
|
|
248 message(SEND_ERROR "The -funwind-tables flag must be supported "
|
|
249 "because this target uses ARM Exception Handling ABI")
|
|
250 endif()
|
|
251
|
|
252 add_cxx_compile_flags_if_supported(-fno-exceptions)
|
|
253 add_cxx_compile_flags_if_supported(-fno-rtti)
|
|
254
|
|
255 # Ensure that we don't depend on C++ standard library.
|
|
256 if (LIBUNWIND_HAS_NOSTDINCXX_FLAG)
|
|
257 list(APPEND LIBUNWIND_COMPILE_FLAGS -nostdinc++)
|
|
258 # Remove -stdlib flags to prevent them from causing an unused flag warning.
|
207
|
259 string(REPLACE "--stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
|
260 string(REPLACE "--stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
150
|
261 string(REPLACE "-stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
|
262 string(REPLACE "-stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
|
263 endif()
|
|
264
|
|
265 # Assert
|
|
266 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
|
|
267 if (LIBUNWIND_ENABLE_ASSERTIONS)
|
|
268 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
|
|
269 if (NOT MSVC)
|
|
270 add_compile_flags(-D_DEBUG)
|
|
271 endif()
|
|
272
|
|
273 # On Release builds cmake automatically defines NDEBUG, so we
|
|
274 # explicitly undefine it:
|
|
275 if (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
|
|
276 add_compile_flags(-UNDEBUG)
|
|
277 endif()
|
|
278 else()
|
|
279 if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
|
|
280 add_compile_flags(-DNDEBUG)
|
|
281 endif()
|
|
282 endif()
|
|
283
|
|
284 # Cross-unwinding
|
|
285 if (NOT LIBUNWIND_ENABLE_CROSS_UNWINDING)
|
|
286 add_compile_flags(-D_LIBUNWIND_IS_NATIVE_ONLY)
|
|
287 endif()
|
|
288
|
|
289 # Threading-support
|
|
290 if (NOT LIBUNWIND_ENABLE_THREADS)
|
|
291 add_compile_flags(-D_LIBUNWIND_HAS_NO_THREADS)
|
|
292 endif()
|
|
293
|
|
294 # ARM WMMX register support
|
|
295 if (LIBUNWIND_ENABLE_ARM_WMMX)
|
|
296 # __ARM_WMMX is a compiler pre-define (as per the ACLE 2.0). Clang does not
|
|
297 # define this macro for any supported target at present. Therefore, here we
|
|
298 # provide the option to explicitly enable support for WMMX registers in the
|
|
299 # unwinder.
|
|
300 add_compile_flags(-D__ARM_WMMX)
|
|
301 endif()
|
|
302
|
207
|
303 if(LIBUNWIND_IS_BAREMETAL)
|
|
304 add_compile_definitions(_LIBUNWIND_IS_BAREMETAL)
|
|
305 endif()
|
|
306
|
|
307 if(LIBUNWIND_USE_FRAME_HEADER_CACHE)
|
|
308 add_compile_definitions(_LIBUNWIND_USE_FRAME_HEADER_CACHE)
|
|
309 endif()
|
|
310
|
|
311 if(LIBUNWIND_REMEMBER_HEAP_ALLOC)
|
|
312 add_compile_definitions(_LIBUNWIND_REMEMBER_HEAP_ALLOC)
|
|
313 endif()
|
|
314
|
150
|
315 # This is the _ONLY_ place where add_definitions is called.
|
|
316 if (MSVC)
|
|
317 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
|
318 endif()
|
|
319
|
|
320 # Disable DLL annotations on Windows for static builds.
|
|
321 if (WIN32 AND LIBUNWIND_ENABLE_STATIC AND NOT LIBUNWIND_ENABLE_SHARED)
|
207
|
322 add_definitions(-D_LIBUNWIND_HIDE_SYMBOLS)
|
150
|
323 endif()
|
|
324
|
|
325 if (LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
|
|
326 if (LIBUNWIND_HAS_DL_LIB)
|
|
327 add_definitions(-D_LIBUNWIND_LINK_DL_LIB)
|
|
328 endif()
|
|
329 if (LIBUNWIND_HAS_PTHREAD_LIB)
|
|
330 add_definitions(-D_LIBUNWIND_LINK_PTHREAD_LIB)
|
|
331 endif()
|
|
332 endif()
|
|
333
|
|
334 #===============================================================================
|
|
335 # Setup Source Code
|
|
336 #===============================================================================
|
|
337
|
|
338 include_directories(include)
|
|
339
|
|
340 add_subdirectory(src)
|
|
341
|
|
342 if (LIBUNWIND_INCLUDE_DOCS)
|
|
343 add_subdirectory(docs)
|
|
344 endif()
|
|
345
|
207
|
346 if (LIBUNWIND_INCLUDE_TESTS AND EXISTS ${LLVM_CMAKE_PATH})
|
150
|
347 add_subdirectory(test)
|
|
348 endif()
|