-
Notifications
You must be signed in to change notification settings - Fork 43
/
CMakeLists.txt
229 lines (202 loc) · 6.15 KB
/
CMakeLists.txt
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
cmake_minimum_required(VERSION 3.16)
#
# Project name
#
project(clang-uml C CXX)
cmake_policy(SET CMP0054 NEW)
#
# CMake standard defines
#
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_VERBOSE_MAKEFILE OFF)
set(CMAKE_FIND_DEBUG_MODE OFF)
if(UNIX AND NOT APPLE)
set(LINUX TRUE)
endif()
#
# C++ setup
#
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
#
# clang-uml custom defines
#
set(CLANG_UML_INSTALL_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
set(CLANG_UML_INSTALL_BIN_DIR ${PROJECT_SOURCE_DIR}/bin)
set(UML_HEADERS_DIR ${PROJECT_SOURCE_DIR}/src/uml)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
if(APPLE)
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm" OR "${CMAKE_SYSTEM_PROCESSOR}"
STREQUAL "arm64")
set(HOMEBREW_PREFIX "/opt/homebrew")
else()
set(HOMEBREW_PREFIX "/usr/local")
endif()
endif(APPLE)
#
# CMake build options
#
option(LINK_LLVM_SHARED "Should LLVM be linked using shared libraries" ON)
set(LLVM_VERSION CACHE STRING "Major LLVM version to use (e.g. 15)")
set(LLVM_CONFIG_PATH CACHE STRING "Path to llvm-config binary")
set(CMAKE_PREFIX CACHE STRING "Path to custom cmake modules")
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_PREFIX}")
#
# Setup version string
#
include(GitVersion)
setup_git_version()
message(STATUS "clang-uml version: "
"${GIT_VERSION_MAJOR}.${GIT_VERSION_MINOR}.${GIT_VERSION_PATCH}")
#
# Setup coverage
#
option(CODE_COVERAGE "" OFF)
if(CODE_COVERAGE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g --coverage -fno-inline")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g --coverage -fno-inline")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lgcov")
endif(CODE_COVERAGE)
#
# Setup Address Sanitizer
#
option(ADDRESS_SANITIZER "" OFF)
if(ADDRESS_SANITIZER)
message(STATUS "Enabling address sanitizer")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} \
-fno-omit-frame-pointer \
-fsanitize=address \
-fsanitize-blacklist=${CMAKE_CURRENT_SOURCE_DIR}/.sanitize-blacklist"
)
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} \
-fno-omit-frame-pointer \
-fsanitize=address \
-fsanitize-blacklist=${CMAKE_CURRENT_SOURCE_DIR}/.sanitize-blacklist"
)
endif(ADDRESS_SANITIZER)
#
# Setup LLVM
#
include(LLVMSetup)
#
# Setup custom compile options depending on various compiler and environment
# quirks
#
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "13.0")
# Workaround over Wdangling-reference false positives in libfmt
set(CUSTOM_COMPILE_OPTIONS ${CUSTOM_COMPILE_OPTIONS}
-Wno-dangling-reference)
endif()
endif()
if(LLVM_VERSION_MAJOR GREATER_EQUAL 17)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CUSTOM_COMPILE_OPTIONS ${CUSTOM_COMPILE_OPTIONS}
-Wno-class-memaccess)
endif()
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CUSTOM_COMPILE_OPTIONS ${CUSTOM_COMPILE_OPTIONS}
-Wno-unused-private-field)
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19)
set(CUSTOM_COMPILE_OPTIONS
${CUSTOM_COMPILE_OPTIONS}
-Wno-missing-template-arg-list-after-template-kw)
endif()
if(APPLE)
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm"
OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64")
# Use LLVM bundled unwind on Apple Silicon to fix segfaults on
# exception throw
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} -L${HOMEBREW_PREFIX}/opt/llvm/lib/unwind -lunwind"
)
endif()
endif(APPLE)
endif()
#
# Setup threads library
#
find_package(Threads REQUIRED)
#
# Setup yaml-cpp
#
message(STATUS "Checking for yaml-cpp...")
find_package(yaml-cpp)
if("${YAML_CPP_LIBRARIES}" STREQUAL "")
message(FATAL_ERROR "Failed to find yaml-cpp library!")
else()
message(STATUS "Found yaml-cpp libraries: ${YAML_CPP_LIBRARIES}")
endif()
if(MSVC)
set(YAML_CPP_LIBRARIES "yaml-cpp")
endif(MSVC)
link_directories(${LLVM_LIBRARY_DIR} ${YAML_CPP_LIBRARY_DIR})
#
# Setup backward-cpp, libdw and libunwind
#
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(CLANG_UML_ENABLE_BACKTRACE_DEFAULT ON)
else()
set(CLANG_UML_ENABLE_BACKTRACE_DEFAULT OFF)
endif()
option(CLANG_UML_ENABLE_BACKTRACE "Enable backtrace on segfault"
${CLANG_UML_ENABLE_BACKTRACE_DEFAULT})
if(LINUX AND CLANG_UML_ENABLE_BACKTRACE)
find_package(PkgConfig REQUIRED)
pkg_check_modules(DW REQUIRED IMPORTED_TARGET libdw)
pkg_check_modules(UNWIND REQUIRED IMPORTED_TARGET libunwind)
set(BACKWARD_CPP_LIBRARIES PkgConfig::DW PkgConfig::UNWIND)
set(ENABLE_BACKWARD_CPP -DENABLE_BACKWARD_CPP)
message(STATUS "Enabling backward-cpp")
else()
message(STATUS "Disabling backward-cpp")
endif()
#
# Setup thirdparty sources
#
set(THIRDPARTY_HEADERS_DIR ${PROJECT_SOURCE_DIR}/thirdparty/)
#
# Setup include directories
#
include_directories(${LLVM_INCLUDE_DIRS})
include_directories(${CLANG_UML_INSTALL_INCLUDE_DIR})
include_directories(${UML_HEADERS_DIR})
include_directories(${THIRDPARTY_HEADERS_DIR})
include_directories(${PROJECT_SOURCE_DIR}/src/)
include_directories(${PROJECT_BINARY_DIR}/src/version)
include_directories(${YAML_CPP_INCLUDE_DIR})
add_subdirectory(src)
#
# Enable testing via CTest
#
option(BUILD_TESTS "" ON)
option(ENABLE_CXX_MODULES_TEST_CASES "" OFF)
option(ENABLE_CUDA_TEST_CASES "" OFF)
option(ENABLE_OBJECTIVE_C_TEST_CASES "" OFF)
option(FETCH_LIBOBJC2 "" OFF)
#
# Setup CUDA if available
#
if(ENABLE_CUDA_TEST_CASES)
include(CheckLanguage)
check_language(CUDA)
set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CUDA_ARCHITECTURES 75)
enable_language(CUDA)
endif(ENABLE_CUDA_TEST_CASES)
if(ENABLE_OBJECTIVE_C_TEST_CASES)
enable_language(OBJC)
if(UNIX AND NOT APPLE)
find_package(GNUstep REQUIRED)
endif()
endif(ENABLE_OBJECTIVE_C_TEST_CASES)
if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif(BUILD_TESTS)