forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
229 lines (200 loc) · 7.39 KB
/
CMakeLists.txt
File metadata and controls
229 lines (200 loc) · 7.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# Get sources
enable_language(C CXX ASM)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(LIBUNWIND_CXX_SOURCES
libunwind.cpp
Unwind-EHABI.cpp
Unwind-seh.cpp
)
if(APPLE)
list(APPEND LIBUNWIND_CXX_SOURCES
Unwind_AppleExtras.cpp
)
endif()
set(LIBUNWIND_C_SOURCES
UnwindLevel1.c
UnwindLevel1-gcc-ext.c
Unwind-sjlj.c
)
set(LIBUNWIND_ASM_SOURCES
UnwindRegistersRestore.S
UnwindRegistersSave.S
)
set(LIBUNWIND_HEADERS
AddressSpace.hpp
assembly.h
CompactUnwinder.hpp
config.h
dwarf2.h
DwarfInstructions.hpp
DwarfParser.hpp
libunwind_ext.h
Registers.hpp
RWMutex.hpp
UnwindCursor.hpp
../include/libunwind.h
../include/unwind.h
)
if(APPLE)
list(APPEND LIBUNWIND_HEADERS
../include/mach-o/compact_unwind_encoding.h
)
endif()
if (MSVC_IDE)
# Force them all into the headers dir on MSVC, otherwise they end up at
# project scope because they don't have extensions.
source_group("Header Files" FILES ${LIBUNWIND_HEADERS})
endif()
if (RUST_SGX)
# Compile Flags
add_definitions(-DRUST_SGX)
add_definitions(-D__NO_STRING_INLINES)
add_definitions(-D__NO_MATH_INLINES)
add_definitions(-D_LIBUNWIND_IS_BAREMETAL)
# Can't use add_definitions because CMake will reorder these arguments
list(APPEND LIBUNWIND_COMPILE_FLAGS -U_FORTIFY_SOURCE)
list(APPEND LIBUNWIND_COMPILE_FLAGS -D_FORTIFY_SOURCE=0)
list(APPEND LIBUNWIND_COMPILE_FLAGS -fno-stack-protector)
list(APPEND LIBUNWIND_COMPILE_FLAGS -ffreestanding)
list(APPEND LIBUNWIND_COMPILE_FLAGS -fexceptions)
# Avoid too new relocation types being emitted, which might prevent linking
# on older platforms.
#
# See https://github.com/rust-lang/rust/issues/34978
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
list(APPEND LIBUNWIND_COMPILE_FLAGS -Wa,-mrelax-relocations=no)
else()
list(APPEND LIBUNWIND_COMPILE_FLAGS)
endif()
# Sources
list(APPEND LIBUNWIND_HEADERS UnwindRustSgx.h)
list(APPEND LIBUNWIND_C_SOURCES UnwindRustSgx.c)
endif()
set_source_files_properties(${LIBUNWIND_C_SOURCES}
PROPERTIES
COMPILE_FLAGS "-std=c99")
set_source_files_properties(${LIBUNWIND_ASM_SOURCES}
PROPERTIES
LANGUAGE ASM)
set(LIBUNWIND_SOURCES
${LIBUNWIND_CXX_SOURCES}
${LIBUNWIND_C_SOURCES}
${LIBUNWIND_ASM_SOURCES})
# Generate library list.
add_library_flags_if(LIBUNWIND_HAS_C_LIB c)
if (LIBUNWIND_USE_COMPILER_RT)
add_library_flags("${LIBUNWIND_BUILTINS_LIBRARY}")
else()
add_library_flags_if(LIBUNWIND_HAS_GCC_S_LIB gcc_s)
add_library_flags_if(LIBUNWIND_HAS_GCC_LIB gcc)
endif()
add_library_flags_if(LIBUNWIND_HAS_DL_LIB dl)
if (LIBUNWIND_ENABLE_THREADS AND (NOT RUST_SGX))
add_library_flags_if(LIBUNWIND_HAS_PTHREAD_LIB pthread)
add_compile_flags_if(LIBUNWIND_WEAK_PTHREAD_LIB -DLIBUNWIND_USE_WEAK_PTHREAD=1)
endif()
# Setup flags.
add_link_flags_if_supported(-nodefaultlibs)
# MINGW_LIBRARIES is defined in config-ix.cmake
add_library_flags_if(MINGW "${MINGW_LIBRARIES}")
if (LIBUNWIND_ENABLE_SHARED AND
NOT (LIBUNWIND_SUPPORTS_FNO_EXCEPTIONS_FLAG AND
LIBUNWIND_SUPPORTS_FUNWIND_TABLES_FLAG))
message(FATAL_ERROR
"Compiler doesn't support generation of unwind tables if exception "
"support is disabled. Building libunwind DSO with runtime dependency "
"on C++ ABI library is not supported.")
endif()
if (APPLE)
add_compile_flags("-U__STRICT_ANSI__")
add_link_flags("-compatibility_version 1" "-install_name /usr/lib/libunwind.1.dylib")
if (CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6")
add_link_flags("-current_version ${LIBUNWIND_VERSION}" "/usr/lib/libSystem.B.dylib")
endif ()
endif ()
string(REPLACE ";" " " LIBUNWIND_COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}")
string(REPLACE ";" " " LIBUNWIND_CXX_FLAGS "${LIBUNWIND_CXX_FLAGS}")
string(REPLACE ";" " " LIBUNWIND_C_FLAGS "${LIBUNWIND_C_FLAGS}")
string(REPLACE ";" " " LIBUNWIND_LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}")
set_property(SOURCE ${LIBUNWIND_CXX_SOURCES}
APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_CXX_FLAGS}")
set_property(SOURCE ${LIBUNWIND_C_SOURCES}
APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_C_FLAGS}")
# NOTE: avoid implicit dependencies on C++ runtimes. libunwind uses C++ for
# ease, but does not rely on C++ at runtime.
set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
# Build the shared library.
if (LIBUNWIND_ENABLE_SHARED)
add_library(unwind_shared SHARED ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
target_compile_options(unwind_shared PRIVATE /GR-)
else()
target_compile_options(unwind_shared PRIVATE -fno-rtti)
endif()
if(COMMAND llvm_setup_rpath)
llvm_setup_rpath(unwind_shared)
endif()
target_link_libraries(unwind_shared PRIVATE ${LIBUNWIND_LIBRARIES})
set_target_properties(unwind_shared PROPERTIES
CXX_EXTENSIONS OFF
CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON
COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
LINKER_LANGUAGE C
OUTPUT_NAME "unwind"
VERSION "1.0"
SOVERSION "1")
list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_shared")
if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared")
endif()
endif()
# Build the static library.
if (LIBUNWIND_ENABLE_STATIC)
add_library(unwind_static STATIC ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
target_compile_options(unwind_static PRIVATE /GR-)
else()
target_compile_options(unwind_static PRIVATE -fno-rtti)
endif()
target_link_libraries(unwind_static PRIVATE ${LIBUNWIND_LIBRARIES})
set_target_properties(unwind_static PROPERTIES
CXX_EXTENSIONS OFF
CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON
COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
LINKER_LANGUAGE C
OUTPUT_NAME "unwind")
if(LIBUNWIND_HERMETIC_STATIC_LIBRARY)
append_flags_if_supported(UNWIND_STATIC_LIBRARY_FLAGS -fvisibility=hidden)
append_flags_if_supported(UNWIND_STATIC_LIBRARY_FLAGS -fvisibility-global-new-delete-hidden)
target_compile_options(unwind_static PRIVATE ${UNWIND_STATIC_LIBRARY_FLAGS})
target_compile_definitions(unwind_static PRIVATE _LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS)
endif()
list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_static")
if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static")
endif()
endif()
# Add a meta-target for both libraries.
add_custom_target(unwind DEPENDS ${LIBUNWIND_BUILD_TARGETS})
if (LIBUNWIND_INSTALL_LIBRARY)
install(TARGETS ${LIBUNWIND_INSTALL_TARGETS}
LIBRARY DESTINATION ${LIBUNWIND_INSTALL_PREFIX}${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind
ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_PREFIX}${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind)
endif()
if (NOT CMAKE_CONFIGURATION_TYPES AND LIBUNWIND_INSTALL_LIBRARY)
add_custom_target(install-unwind
DEPENDS unwind
COMMAND "${CMAKE_COMMAND}"
-DCMAKE_INSTALL_COMPONENT=unwind
-P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")
add_custom_target(install-unwind-stripped
DEPENDS unwind
COMMAND "${CMAKE_COMMAND}"
-DCMAKE_INSTALL_COMPONENT=unwind
-DCMAKE_INSTALL_DO_STRIP=1
-P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")
endif()