annotate libunwind/CMakeLists.txt @ 190:b1364f705114

relax tail call error on goto from normal function. args.c worked.
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 06 Jun 2020 13:15:35 +0900
parents 1d019706d866
children 2e18cbf3894f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 #===============================================================================
anatofuz
parents:
diff changeset
2 # Setup Project
anatofuz
parents:
diff changeset
3 #===============================================================================
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5 cmake_minimum_required(VERSION 3.4.3)
anatofuz
parents:
diff changeset
6
anatofuz
parents:
diff changeset
7 if (POLICY CMP0042)
anatofuz
parents:
diff changeset
8 cmake_policy(SET CMP0042 NEW) # Set MACOSX_RPATH=YES by default
anatofuz
parents:
diff changeset
9 endif()
anatofuz
parents:
diff changeset
10
anatofuz
parents:
diff changeset
11 # Add path for custom modules
anatofuz
parents:
diff changeset
12 set(CMAKE_MODULE_PATH
anatofuz
parents:
diff changeset
13 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
anatofuz
parents:
diff changeset
14 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
anatofuz
parents:
diff changeset
15 ${CMAKE_MODULE_PATH}
anatofuz
parents:
diff changeset
16 )
anatofuz
parents:
diff changeset
17
anatofuz
parents:
diff changeset
18 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBUNWIND_STANDALONE_BUILD)
anatofuz
parents:
diff changeset
19 project(libunwind LANGUAGES C CXX ASM)
anatofuz
parents:
diff changeset
20
anatofuz
parents:
diff changeset
21 # Rely on llvm-config.
anatofuz
parents:
diff changeset
22 set(CONFIG_OUTPUT)
anatofuz
parents:
diff changeset
23 if(NOT LLVM_CONFIG_PATH)
anatofuz
parents:
diff changeset
24 find_program(LLVM_CONFIG_PATH "llvm-config")
anatofuz
parents:
diff changeset
25 endif()
anatofuz
parents:
diff changeset
26 if (DEFINED LLVM_PATH)
anatofuz
parents:
diff changeset
27 set(LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIR} CACHE PATH "Path to llvm/include")
anatofuz
parents:
diff changeset
28 set(LLVM_PATH ${LLVM_PATH} CACHE PATH "Path to LLVM source tree")
anatofuz
parents:
diff changeset
29 set(LLVM_MAIN_SRC_DIR ${LLVM_PATH})
anatofuz
parents:
diff changeset
30 set(LLVM_CMAKE_PATH "${LLVM_PATH}/cmake/modules")
anatofuz
parents:
diff changeset
31 elseif(LLVM_CONFIG_PATH)
anatofuz
parents:
diff changeset
32 message(STATUS "Found LLVM_CONFIG_PATH as ${LLVM_CONFIG_PATH}")
anatofuz
parents:
diff changeset
33 set(CONFIG_COMMAND ${LLVM_CONFIG_PATH} "--includedir" "--prefix" "--src-root")
anatofuz
parents:
diff changeset
34 execute_process(COMMAND ${CONFIG_COMMAND}
anatofuz
parents:
diff changeset
35 RESULT_VARIABLE HAD_ERROR
anatofuz
parents:
diff changeset
36 OUTPUT_VARIABLE CONFIG_OUTPUT)
anatofuz
parents:
diff changeset
37 if (NOT HAD_ERROR)
anatofuz
parents:
diff changeset
38 string(REGEX REPLACE "[ \t]*[\r\n]+[ \t]*" ";"
anatofuz
parents:
diff changeset
39 CONFIG_OUTPUT ${CONFIG_OUTPUT})
anatofuz
parents:
diff changeset
40 else()
anatofuz
parents:
diff changeset
41 string(REPLACE ";" " " CONFIG_COMMAND_STR "${CONFIG_COMMAND}")
anatofuz
parents:
diff changeset
42 message(STATUS "${CONFIG_COMMAND_STR}")
anatofuz
parents:
diff changeset
43 message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}")
anatofuz
parents:
diff changeset
44 endif()
anatofuz
parents:
diff changeset
45
anatofuz
parents:
diff changeset
46 list(GET CONFIG_OUTPUT 0 INCLUDE_DIR)
anatofuz
parents:
diff changeset
47 list(GET CONFIG_OUTPUT 1 LLVM_OBJ_ROOT)
anatofuz
parents:
diff changeset
48 list(GET CONFIG_OUTPUT 2 MAIN_SRC_DIR)
anatofuz
parents:
diff changeset
49
anatofuz
parents:
diff changeset
50 set(LLVM_INCLUDE_DIR ${INCLUDE_DIR} CACHE PATH "Path to llvm/include")
anatofuz
parents:
diff changeset
51 set(LLVM_BINARY_DIR ${LLVM_OBJ_ROOT} CACHE PATH "Path to LLVM build tree")
anatofuz
parents:
diff changeset
52 set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
anatofuz
parents:
diff changeset
53 set(LLVM_LIT_PATH "${LLVM_PATH}/utils/lit/lit.py")
anatofuz
parents:
diff changeset
54
anatofuz
parents:
diff changeset
55 # --cmakedir is supported since llvm r291218 (4.0 release)
anatofuz
parents:
diff changeset
56 execute_process(
anatofuz
parents:
diff changeset
57 COMMAND ${LLVM_CONFIG_PATH} --cmakedir
anatofuz
parents:
diff changeset
58 RESULT_VARIABLE HAD_ERROR
anatofuz
parents:
diff changeset
59 OUTPUT_VARIABLE CONFIG_OUTPUT
anatofuz
parents:
diff changeset
60 ERROR_QUIET)
anatofuz
parents:
diff changeset
61 if(NOT HAD_ERROR)
anatofuz
parents:
diff changeset
62 string(STRIP "${CONFIG_OUTPUT}" LLVM_CMAKE_PATH_FROM_LLVM_CONFIG)
anatofuz
parents:
diff changeset
63 file(TO_CMAKE_PATH "${LLVM_CMAKE_PATH_FROM_LLVM_CONFIG}" LLVM_CMAKE_PATH)
anatofuz
parents:
diff changeset
64 else()
anatofuz
parents:
diff changeset
65 file(TO_CMAKE_PATH "${LLVM_BINARY_DIR}" LLVM_BINARY_DIR_CMAKE_STYLE)
anatofuz
parents:
diff changeset
66 set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR_CMAKE_STYLE}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
anatofuz
parents:
diff changeset
67 endif()
anatofuz
parents:
diff changeset
68 else()
anatofuz
parents:
diff changeset
69 message(WARNING "UNSUPPORTED LIBUNWIND CONFIGURATION DETECTED: "
anatofuz
parents:
diff changeset
70 "llvm-config not found and LLVM_MAIN_SRC_DIR not defined. "
anatofuz
parents:
diff changeset
71 "Reconfigure with -DLLVM_CONFIG=path/to/llvm-config "
anatofuz
parents:
diff changeset
72 "or -DLLVM_PATH=path/to/llvm-source-root.")
anatofuz
parents:
diff changeset
73 endif()
anatofuz
parents:
diff changeset
74
anatofuz
parents:
diff changeset
75 if (EXISTS ${LLVM_CMAKE_PATH})
anatofuz
parents:
diff changeset
76 # Enable warnings, otherwise -w gets added to the cflags by HandleLLVMOptions.
anatofuz
parents:
diff changeset
77 set(LLVM_ENABLE_WARNINGS ON)
anatofuz
parents:
diff changeset
78 list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}")
anatofuz
parents:
diff changeset
79 include("${LLVM_CMAKE_PATH}/AddLLVM.cmake")
anatofuz
parents:
diff changeset
80 include("${LLVM_CMAKE_PATH}/HandleLLVMOptions.cmake")
anatofuz
parents:
diff changeset
81 else()
anatofuz
parents:
diff changeset
82 message(WARNING "Not found: ${LLVM_CMAKE_PATH}")
anatofuz
parents:
diff changeset
83 endif()
anatofuz
parents:
diff changeset
84
anatofuz
parents:
diff changeset
85 set(PACKAGE_NAME libunwind)
anatofuz
parents:
diff changeset
86 set(PACKAGE_VERSION 11.0.0git)
anatofuz
parents:
diff changeset
87 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
anatofuz
parents:
diff changeset
88 set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org")
anatofuz
parents:
diff changeset
89
anatofuz
parents:
diff changeset
90 if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
anatofuz
parents:
diff changeset
91 set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
anatofuz
parents:
diff changeset
92 else()
anatofuz
parents:
diff changeset
93 # Seek installed Lit.
anatofuz
parents:
diff changeset
94 find_program(LLVM_LIT "lit.py" ${LLVM_MAIN_SRC_DIR}/utils/lit
anatofuz
parents:
diff changeset
95 DOC "Path to lit.py")
anatofuz
parents:
diff changeset
96 endif()
anatofuz
parents:
diff changeset
97
anatofuz
parents:
diff changeset
98 if (LLVM_LIT)
anatofuz
parents:
diff changeset
99 # Define the default arguments to use with 'lit', and an option for the user
anatofuz
parents:
diff changeset
100 # to override.
anatofuz
parents:
diff changeset
101 set(LIT_ARGS_DEFAULT "-sv")
anatofuz
parents:
diff changeset
102 if (MSVC OR XCODE)
anatofuz
parents:
diff changeset
103 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
anatofuz
parents:
diff changeset
104 endif()
anatofuz
parents:
diff changeset
105 set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
anatofuz
parents:
diff changeset
106
anatofuz
parents:
diff changeset
107 # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
anatofuz
parents:
diff changeset
108 if (WIN32 AND NOT CYGWIN)
anatofuz
parents:
diff changeset
109 set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
anatofuz
parents:
diff changeset
110 endif()
anatofuz
parents:
diff changeset
111 else()
anatofuz
parents:
diff changeset
112 set(LLVM_INCLUDE_TESTS OFF)
anatofuz
parents:
diff changeset
113 endif()
anatofuz
parents:
diff changeset
114
anatofuz
parents:
diff changeset
115 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX})
anatofuz
parents:
diff changeset
116 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX})
anatofuz
parents:
diff changeset
117 else()
anatofuz
parents:
diff changeset
118 set(LLVM_LIT "${CMAKE_SOURCE_DIR}/utils/lit/lit.py")
anatofuz
parents:
diff changeset
119 endif()
anatofuz
parents:
diff changeset
120
anatofuz
parents:
diff changeset
121 #===============================================================================
anatofuz
parents:
diff changeset
122 # Setup CMake Options
anatofuz
parents:
diff changeset
123 #===============================================================================
anatofuz
parents:
diff changeset
124 include(CMakeDependentOption)
anatofuz
parents:
diff changeset
125 include(HandleCompilerRT)
anatofuz
parents:
diff changeset
126
anatofuz
parents:
diff changeset
127 # Define options.
anatofuz
parents:
diff changeset
128 option(LIBUNWIND_BUILD_32_BITS "Build 32 bit libunwind" ${LLVM_BUILD_32_BITS})
anatofuz
parents:
diff changeset
129 option(LIBUNWIND_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
anatofuz
parents:
diff changeset
130 option(LIBUNWIND_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
anatofuz
parents:
diff changeset
131 option(LIBUNWIND_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
anatofuz
parents:
diff changeset
132 option(LIBUNWIND_ENABLE_SHARED "Build libunwind as a shared library." ON)
anatofuz
parents:
diff changeset
133 option(LIBUNWIND_ENABLE_STATIC "Build libunwind as a static library." ON)
anatofuz
parents:
diff changeset
134 option(LIBUNWIND_ENABLE_CROSS_UNWINDING "Enable cross-platform unwinding support." OFF)
anatofuz
parents:
diff changeset
135 option(LIBUNWIND_ENABLE_ARM_WMMX "Enable unwinding support for ARM WMMX registers." OFF)
anatofuz
parents:
diff changeset
136 option(LIBUNWIND_ENABLE_THREADS "Build libunwind with threading support." ON)
anatofuz
parents:
diff changeset
137 option(LIBUNWIND_WEAK_PTHREAD_LIB "Use weak references to refer to pthread functions." OFF)
anatofuz
parents:
diff changeset
138 option(LIBUNWIND_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
anatofuz
parents:
diff changeset
139 option(LIBUNWIND_INCLUDE_DOCS "Build the libunwind documentation." ${LLVM_INCLUDE_DOCS})
anatofuz
parents:
diff changeset
140
anatofuz
parents:
diff changeset
141 set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
anatofuz
parents:
diff changeset
142 "Define suffix of library directory name (32/64)")
anatofuz
parents:
diff changeset
143 option(LIBUNWIND_INSTALL_LIBRARY "Install the libunwind library." ON)
anatofuz
parents:
diff changeset
144 cmake_dependent_option(LIBUNWIND_INSTALL_STATIC_LIBRARY
anatofuz
parents:
diff changeset
145 "Install the static libunwind library." ON
anatofuz
parents:
diff changeset
146 "LIBUNWIND_ENABLE_STATIC;LIBUNWIND_INSTALL_LIBRARY" OFF)
anatofuz
parents:
diff changeset
147 cmake_dependent_option(LIBUNWIND_INSTALL_SHARED_LIBRARY
anatofuz
parents:
diff changeset
148 "Install the shared libunwind library." ON
anatofuz
parents:
diff changeset
149 "LIBUNWIND_ENABLE_SHARED;LIBUNWIND_INSTALL_LIBRARY" OFF)
anatofuz
parents:
diff changeset
150 set(LIBUNWIND_TARGET_TRIPLE "" CACHE STRING "Target triple for cross compiling.")
anatofuz
parents:
diff changeset
151 set(LIBUNWIND_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
anatofuz
parents:
diff changeset
152 set(LIBUNWIND_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")
anatofuz
parents:
diff changeset
153 set(LIBUNWIND_TEST_LINKER_FLAGS "" CACHE STRING
anatofuz
parents:
diff changeset
154 "Additional linker flags for test programs.")
anatofuz
parents:
diff changeset
155 set(LIBUNWIND_TEST_COMPILER_FLAGS "" CACHE STRING
anatofuz
parents:
diff changeset
156 "Additional compiler flags for test programs.")
anatofuz
parents:
diff changeset
157
anatofuz
parents:
diff changeset
158 if (NOT LIBUNWIND_ENABLE_SHARED AND NOT LIBUNWIND_ENABLE_STATIC)
anatofuz
parents:
diff changeset
159 message(FATAL_ERROR "libunwind must be built as either a shared or static library.")
anatofuz
parents:
diff changeset
160 endif()
anatofuz
parents:
diff changeset
161
anatofuz
parents:
diff changeset
162 # Check that we can build with 32 bits if requested.
anatofuz
parents:
diff changeset
163 if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32)
anatofuz
parents:
diff changeset
164 if (LIBUNWIND_BUILD_32_BITS AND NOT LLVM_BUILD_32_BITS) # Don't duplicate the output from LLVM
anatofuz
parents:
diff changeset
165 message(STATUS "Building 32 bits executables and libraries.")
anatofuz
parents:
diff changeset
166 endif()
anatofuz
parents:
diff changeset
167 elseif(LIBUNWIND_BUILD_32_BITS)
anatofuz
parents:
diff changeset
168 message(FATAL_ERROR "LIBUNWIND_BUILD_32_BITS=ON is not supported on this platform.")
anatofuz
parents:
diff changeset
169 endif()
anatofuz
parents:
diff changeset
170
anatofuz
parents:
diff changeset
171 option(LIBUNWIND_HERMETIC_STATIC_LIBRARY
anatofuz
parents:
diff changeset
172 "Do not export any symbols from the static library." OFF)
anatofuz
parents:
diff changeset
173
anatofuz
parents:
diff changeset
174 #===============================================================================
anatofuz
parents:
diff changeset
175 # Configure System
anatofuz
parents:
diff changeset
176 #===============================================================================
anatofuz
parents:
diff changeset
177
anatofuz
parents:
diff changeset
178 # Add path for custom modules
anatofuz
parents:
diff changeset
179 set(CMAKE_MODULE_PATH
anatofuz
parents:
diff changeset
180 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
anatofuz
parents:
diff changeset
181 ${CMAKE_MODULE_PATH})
anatofuz
parents:
diff changeset
182
anatofuz
parents:
diff changeset
183 set(LIBUNWIND_COMPILER ${CMAKE_CXX_COMPILER})
anatofuz
parents:
diff changeset
184 set(LIBUNWIND_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
anatofuz
parents:
diff changeset
185 set(LIBUNWIND_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
anatofuz
parents:
diff changeset
186
anatofuz
parents:
diff changeset
187 string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION
anatofuz
parents:
diff changeset
188 ${PACKAGE_VERSION})
anatofuz
parents:
diff changeset
189
anatofuz
parents:
diff changeset
190 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
anatofuz
parents:
diff changeset
191 set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++)
anatofuz
parents:
diff changeset
192 set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++)
anatofuz
parents:
diff changeset
193 if(LIBCXX_LIBDIR_SUBDIR)
anatofuz
parents:
diff changeset
194 string(APPEND LIBUNWIND_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR})
anatofuz
parents:
diff changeset
195 string(APPEND LIBUNWIND_INSTALL_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR})
anatofuz
parents:
diff changeset
196 endif()
anatofuz
parents:
diff changeset
197 elseif(LLVM_LIBRARY_OUTPUT_INTDIR)
anatofuz
parents:
diff changeset
198 set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
anatofuz
parents:
diff changeset
199 set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX})
anatofuz
parents:
diff changeset
200 else()
anatofuz
parents:
diff changeset
201 set(LIBUNWIND_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBUNWIND_LIBDIR_SUFFIX})
anatofuz
parents:
diff changeset
202 set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX})
anatofuz
parents:
diff changeset
203 endif()
anatofuz
parents:
diff changeset
204
anatofuz
parents:
diff changeset
205 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR})
anatofuz
parents:
diff changeset
206 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR})
anatofuz
parents:
diff changeset
207 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR})
anatofuz
parents:
diff changeset
208
anatofuz
parents:
diff changeset
209 set(LIBUNWIND_INSTALL_PREFIX "" CACHE STRING "Define libunwind destination prefix.")
anatofuz
parents:
diff changeset
210
anatofuz
parents:
diff changeset
211 set(LIBUNWIND_C_FLAGS "")
anatofuz
parents:
diff changeset
212 set(LIBUNWIND_CXX_FLAGS "")
anatofuz
parents:
diff changeset
213 set(LIBUNWIND_COMPILE_FLAGS "")
anatofuz
parents:
diff changeset
214 set(LIBUNWIND_LINK_FLAGS "")
anatofuz
parents:
diff changeset
215
anatofuz
parents:
diff changeset
216 # Include macros for adding and removing libunwind flags.
anatofuz
parents:
diff changeset
217 include(HandleLibunwindFlags)
anatofuz
parents:
diff changeset
218
anatofuz
parents:
diff changeset
219 #===============================================================================
anatofuz
parents:
diff changeset
220 # Setup Compiler Flags
anatofuz
parents:
diff changeset
221 #===============================================================================
anatofuz
parents:
diff changeset
222
anatofuz
parents:
diff changeset
223 # Get required flags.
anatofuz
parents:
diff changeset
224 add_target_flags_if(LIBUNWIND_BUILD_32_BITS "-m32")
anatofuz
parents:
diff changeset
225
anatofuz
parents:
diff changeset
226 if(LIBUNWIND_TARGET_TRIPLE)
anatofuz
parents:
diff changeset
227 add_target_flags("--target=${LIBUNWIND_TARGET_TRIPLE}")
anatofuz
parents:
diff changeset
228 elseif(CMAKE_CXX_COMPILER_TARGET)
anatofuz
parents:
diff changeset
229 set(LIBUNWIND_TARGET_TRIPLE "${CMAKE_CXX_COMPILER_TARGET}")
anatofuz
parents:
diff changeset
230 endif()
anatofuz
parents:
diff changeset
231 if(LIBUNWIND_GCC_TOOLCHAIN)
anatofuz
parents:
diff changeset
232 add_target_flags("--gcc-toolchain=${LIBUNWIND_GCC_TOOLCHAIN}")
anatofuz
parents:
diff changeset
233 elseif(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN)
anatofuz
parents:
diff changeset
234 set(LIBUNWIND_GCC_TOOLCHAIN "${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}")
anatofuz
parents:
diff changeset
235 endif()
anatofuz
parents:
diff changeset
236 if(LIBUNWIND_SYSROOT)
anatofuz
parents:
diff changeset
237 add_target_flags("--sysroot=${LIBUNWIND_SYSROOT}")
anatofuz
parents:
diff changeset
238 elseif(CMAKE_SYSROOT)
anatofuz
parents:
diff changeset
239 set(LIBUNWIND_SYSROOT "${CMAKE_SYSROOT}")
anatofuz
parents:
diff changeset
240 endif()
anatofuz
parents:
diff changeset
241
anatofuz
parents:
diff changeset
242 if (LIBUNWIND_TARGET_TRIPLE)
anatofuz
parents:
diff changeset
243 set(TARGET_TRIPLE "${LIBUNWIND_TARGET_TRIPLE}")
anatofuz
parents:
diff changeset
244 endif()
anatofuz
parents:
diff changeset
245
anatofuz
parents:
diff changeset
246 # Configure compiler.
anatofuz
parents:
diff changeset
247 include(config-ix)
anatofuz
parents:
diff changeset
248
anatofuz
parents:
diff changeset
249 if (LIBUNWIND_USE_COMPILER_RT AND NOT LIBUNWIND_HAS_NODEFAULTLIBS_FLAG)
anatofuz
parents:
diff changeset
250 list(APPEND LIBUNWIND_LINK_FLAGS "-rtlib=compiler-rt")
anatofuz
parents:
diff changeset
251 endif()
anatofuz
parents:
diff changeset
252
anatofuz
parents:
diff changeset
253 add_compile_flags_if_supported(-Werror=return-type)
anatofuz
parents:
diff changeset
254
anatofuz
parents:
diff changeset
255 # Get warning flags
anatofuz
parents:
diff changeset
256 add_compile_flags_if_supported(-W)
anatofuz
parents:
diff changeset
257 add_compile_flags_if_supported(-Wall)
anatofuz
parents:
diff changeset
258 add_compile_flags_if_supported(-Wchar-subscripts)
anatofuz
parents:
diff changeset
259 add_compile_flags_if_supported(-Wconversion)
anatofuz
parents:
diff changeset
260 add_compile_flags_if_supported(-Wmismatched-tags)
anatofuz
parents:
diff changeset
261 add_compile_flags_if_supported(-Wmissing-braces)
anatofuz
parents:
diff changeset
262 add_compile_flags_if_supported(-Wnewline-eof)
anatofuz
parents:
diff changeset
263 add_compile_flags_if_supported(-Wno-unused-function)
anatofuz
parents:
diff changeset
264 add_compile_flags_if_supported(-Wshadow)
anatofuz
parents:
diff changeset
265 add_compile_flags_if_supported(-Wshorten-64-to-32)
anatofuz
parents:
diff changeset
266 add_compile_flags_if_supported(-Wsign-compare)
anatofuz
parents:
diff changeset
267 add_compile_flags_if_supported(-Wsign-conversion)
anatofuz
parents:
diff changeset
268 add_compile_flags_if_supported(-Wstrict-aliasing=2)
anatofuz
parents:
diff changeset
269 add_compile_flags_if_supported(-Wstrict-overflow=4)
anatofuz
parents:
diff changeset
270 add_compile_flags_if_supported(-Wunused-parameter)
anatofuz
parents:
diff changeset
271 add_compile_flags_if_supported(-Wunused-variable)
anatofuz
parents:
diff changeset
272 add_compile_flags_if_supported(-Wwrite-strings)
anatofuz
parents:
diff changeset
273 add_compile_flags_if_supported(-Wundef)
anatofuz
parents:
diff changeset
274
anatofuz
parents:
diff changeset
275 if (LIBUNWIND_ENABLE_WERROR)
anatofuz
parents:
diff changeset
276 add_compile_flags_if_supported(-Werror)
anatofuz
parents:
diff changeset
277 add_compile_flags_if_supported(-WX)
anatofuz
parents:
diff changeset
278 else()
anatofuz
parents:
diff changeset
279 add_compile_flags_if_supported(-Wno-error)
anatofuz
parents:
diff changeset
280 add_compile_flags_if_supported(-WX-)
anatofuz
parents:
diff changeset
281 endif()
anatofuz
parents:
diff changeset
282
anatofuz
parents:
diff changeset
283 if (LIBUNWIND_ENABLE_PEDANTIC)
anatofuz
parents:
diff changeset
284 add_compile_flags_if_supported(-pedantic)
anatofuz
parents:
diff changeset
285 endif()
anatofuz
parents:
diff changeset
286
anatofuz
parents:
diff changeset
287 # Get feature flags.
anatofuz
parents:
diff changeset
288 # Exceptions
anatofuz
parents:
diff changeset
289 # Catches C++ exceptions only and tells the compiler to assume that extern C
anatofuz
parents:
diff changeset
290 # functions never throw a C++ exception.
anatofuz
parents:
diff changeset
291 add_cxx_compile_flags_if_supported(-fstrict-aliasing)
anatofuz
parents:
diff changeset
292 add_cxx_compile_flags_if_supported(-EHsc)
anatofuz
parents:
diff changeset
293
anatofuz
parents:
diff changeset
294 # Don't run the linker in this CMake check.
anatofuz
parents:
diff changeset
295 #
anatofuz
parents:
diff changeset
296 # The reason why this was added is that when building libunwind for
anatofuz
parents:
diff changeset
297 # ARM Linux, we need to pass the -funwind-tables flag in order for it to
anatofuz
parents:
diff changeset
298 # work properly with ARM EHABI.
anatofuz
parents:
diff changeset
299 #
anatofuz
parents:
diff changeset
300 # However, when performing CMake checks, adding this flag causes the check
anatofuz
parents:
diff changeset
301 # to produce a false negative, because the compiler generates calls
anatofuz
parents:
diff changeset
302 # to __aeabi_unwind_cpp_pr0, which is defined in libunwind itself,
anatofuz
parents:
diff changeset
303 # which isn't built yet, so the linker complains about undefined symbols.
anatofuz
parents:
diff changeset
304 #
anatofuz
parents:
diff changeset
305 # This leads to libunwind not being built with this flag, which makes
anatofuz
parents:
diff changeset
306 # libunwind quite useless in this setup.
anatofuz
parents:
diff changeset
307 set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
anatofuz
parents:
diff changeset
308 set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
anatofuz
parents:
diff changeset
309 add_compile_flags_if_supported(-funwind-tables)
anatofuz
parents:
diff changeset
310 set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
anatofuz
parents:
diff changeset
311
anatofuz
parents:
diff changeset
312 if (LIBUNWIND_USES_ARM_EHABI AND NOT LIBUNWIND_SUPPORTS_FUNWIND_TABLES_FLAG)
anatofuz
parents:
diff changeset
313 message(SEND_ERROR "The -funwind-tables flag must be supported "
anatofuz
parents:
diff changeset
314 "because this target uses ARM Exception Handling ABI")
anatofuz
parents:
diff changeset
315 endif()
anatofuz
parents:
diff changeset
316
anatofuz
parents:
diff changeset
317 add_cxx_compile_flags_if_supported(-fno-exceptions)
anatofuz
parents:
diff changeset
318 add_cxx_compile_flags_if_supported(-fno-rtti)
anatofuz
parents:
diff changeset
319
anatofuz
parents:
diff changeset
320 # Ensure that we don't depend on C++ standard library.
anatofuz
parents:
diff changeset
321 if (LIBUNWIND_HAS_NOSTDINCXX_FLAG)
anatofuz
parents:
diff changeset
322 list(APPEND LIBUNWIND_COMPILE_FLAGS -nostdinc++)
anatofuz
parents:
diff changeset
323 # Remove -stdlib flags to prevent them from causing an unused flag warning.
anatofuz
parents:
diff changeset
324 string(REPLACE "-stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
anatofuz
parents:
diff changeset
325 string(REPLACE "-stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
anatofuz
parents:
diff changeset
326 endif()
anatofuz
parents:
diff changeset
327
anatofuz
parents:
diff changeset
328 # Assert
anatofuz
parents:
diff changeset
329 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
anatofuz
parents:
diff changeset
330 if (LIBUNWIND_ENABLE_ASSERTIONS)
anatofuz
parents:
diff changeset
331 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
anatofuz
parents:
diff changeset
332 if (NOT MSVC)
anatofuz
parents:
diff changeset
333 add_compile_flags(-D_DEBUG)
anatofuz
parents:
diff changeset
334 endif()
anatofuz
parents:
diff changeset
335
anatofuz
parents:
diff changeset
336 # On Release builds cmake automatically defines NDEBUG, so we
anatofuz
parents:
diff changeset
337 # explicitly undefine it:
anatofuz
parents:
diff changeset
338 if (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
anatofuz
parents:
diff changeset
339 add_compile_flags(-UNDEBUG)
anatofuz
parents:
diff changeset
340 endif()
anatofuz
parents:
diff changeset
341 else()
anatofuz
parents:
diff changeset
342 if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
anatofuz
parents:
diff changeset
343 add_compile_flags(-DNDEBUG)
anatofuz
parents:
diff changeset
344 endif()
anatofuz
parents:
diff changeset
345 endif()
anatofuz
parents:
diff changeset
346
anatofuz
parents:
diff changeset
347 # Cross-unwinding
anatofuz
parents:
diff changeset
348 if (NOT LIBUNWIND_ENABLE_CROSS_UNWINDING)
anatofuz
parents:
diff changeset
349 add_compile_flags(-D_LIBUNWIND_IS_NATIVE_ONLY)
anatofuz
parents:
diff changeset
350 endif()
anatofuz
parents:
diff changeset
351
anatofuz
parents:
diff changeset
352 # Threading-support
anatofuz
parents:
diff changeset
353 if (NOT LIBUNWIND_ENABLE_THREADS)
anatofuz
parents:
diff changeset
354 add_compile_flags(-D_LIBUNWIND_HAS_NO_THREADS)
anatofuz
parents:
diff changeset
355 endif()
anatofuz
parents:
diff changeset
356
anatofuz
parents:
diff changeset
357 # ARM WMMX register support
anatofuz
parents:
diff changeset
358 if (LIBUNWIND_ENABLE_ARM_WMMX)
anatofuz
parents:
diff changeset
359 # __ARM_WMMX is a compiler pre-define (as per the ACLE 2.0). Clang does not
anatofuz
parents:
diff changeset
360 # define this macro for any supported target at present. Therefore, here we
anatofuz
parents:
diff changeset
361 # provide the option to explicitly enable support for WMMX registers in the
anatofuz
parents:
diff changeset
362 # unwinder.
anatofuz
parents:
diff changeset
363 add_compile_flags(-D__ARM_WMMX)
anatofuz
parents:
diff changeset
364 endif()
anatofuz
parents:
diff changeset
365
anatofuz
parents:
diff changeset
366 # This is the _ONLY_ place where add_definitions is called.
anatofuz
parents:
diff changeset
367 if (MSVC)
anatofuz
parents:
diff changeset
368 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
anatofuz
parents:
diff changeset
369 endif()
anatofuz
parents:
diff changeset
370
anatofuz
parents:
diff changeset
371 # Disable DLL annotations on Windows for static builds.
anatofuz
parents:
diff changeset
372 if (WIN32 AND LIBUNWIND_ENABLE_STATIC AND NOT LIBUNWIND_ENABLE_SHARED)
anatofuz
parents:
diff changeset
373 add_definitions(-D_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS)
anatofuz
parents:
diff changeset
374 endif()
anatofuz
parents:
diff changeset
375
anatofuz
parents:
diff changeset
376 if (LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
anatofuz
parents:
diff changeset
377 if (LIBUNWIND_HAS_DL_LIB)
anatofuz
parents:
diff changeset
378 add_definitions(-D_LIBUNWIND_LINK_DL_LIB)
anatofuz
parents:
diff changeset
379 endif()
anatofuz
parents:
diff changeset
380 if (LIBUNWIND_HAS_PTHREAD_LIB)
anatofuz
parents:
diff changeset
381 add_definitions(-D_LIBUNWIND_LINK_PTHREAD_LIB)
anatofuz
parents:
diff changeset
382 endif()
anatofuz
parents:
diff changeset
383 endif()
anatofuz
parents:
diff changeset
384
anatofuz
parents:
diff changeset
385 #===============================================================================
anatofuz
parents:
diff changeset
386 # Setup Source Code
anatofuz
parents:
diff changeset
387 #===============================================================================
anatofuz
parents:
diff changeset
388
anatofuz
parents:
diff changeset
389 include_directories(include)
anatofuz
parents:
diff changeset
390
anatofuz
parents:
diff changeset
391 add_subdirectory(src)
anatofuz
parents:
diff changeset
392
anatofuz
parents:
diff changeset
393 if (LIBUNWIND_INCLUDE_DOCS)
anatofuz
parents:
diff changeset
394 add_subdirectory(docs)
anatofuz
parents:
diff changeset
395 endif()
anatofuz
parents:
diff changeset
396
anatofuz
parents:
diff changeset
397 if (EXISTS ${LLVM_CMAKE_PATH})
anatofuz
parents:
diff changeset
398 add_subdirectory(test)
anatofuz
parents:
diff changeset
399 endif()