-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
256 lines (216 loc) · 5.26 KB
/
CMakeLists.txt
File metadata and controls
256 lines (216 loc) · 5.26 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
cmake_minimum_required(VERSION 3.23)
project(mem_profile)
if(APPLE)
list(APPEND CMAKE_PREFIX_PATH /opt/homebrew/opt/llvm)
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
option(MEM_PROFILE_BUILD_TOOLS "Build tools" ON)
option(
MEM_PROFILE_SANITIZE_RUNTIME
"Turn on address sanitizer for the mem_profile runtime library"
OFF)
if(UNIX)
add_compile_options(-Wall -fdiagnostics-color=always -g)
endif()
include(cmake/get_cpm.cmake)
CPMAddPackage("gh:fmtlib/fmt#11.2.0")
CPMAddPackage(
URI "gh:jeremy-rifkin/cpptrace@1.0.4"
OPTIONS
"CPPTRACE_DISABLE_CXX_20_MODULES TRUE"
)
CPMAddPackage("gh:stephenberry/glaze@3.0.0")
add_library(ankerl_unordered_dense INTERFACE)
target_include_directories(
ankerl_unordered_dense
INTERFACE
mp/3rd/ankerl/include
)
add_library(
ankerl::unordered_dense
ALIAS ankerl_unordered_dense
)
find_package(Clang REQUIRED)
message(STATUS "Using Clang @ ${Clang_DIR}\n\tinclude: ${CLANG_INCLUDE_DIRS}\n\tconfig: ${Clang_CONFIG}\n\tCLANG_LINK_CLANG_DYLIB: ${CLANG_LINK_CLANG_DYLIB}")
message(STATUS "Using LLVM @ ${LLVM_DIR}\n\tconfig: ${LLVM_CONFIG}")
include(cmake/Utils.cmake)
# Check for existence of static library targets. If these exist, link them,
# otherwise fall back to dynamic library target clang-cpp
if(TARGET clangFrontend)
set(clang_libs
clangAST
clangBasic
clangFrontend
clangSerialization
clangTooling
)
set(llvm_tool_libs)
else()
set(clang_libs clang-cpp)
set(llvm_tool_libs LLVM)
endif()
if(LINUX)
find_package(PkgConfig)
pkg_check_modules(libunwind REQUIRED IMPORTED_TARGET libunwind libunwind-generic)
endif()
check_targets_exist(TARGETS ${clang_libs} ${llvm_tool_libs})
mp_add_library(
clang_core
INTERFACE
NO_GLOB_HEADERS
INCLUDE_DIRS
${CLANG_INCLUDE_DIRS}
DEPS
${clang_libs}
)
mp_add_library(
clang_tooling
INTERFACE
NO_GLOB_HEADERS
DEPS
clang_core
${llvm_tool_libs}
)
mp_add_library(
mp_types
INTERFACE
ROOT mp/types
)
mp_add_library(
mp_core
STATIC
ROOT mp/core
DEPS
mp_types
PRIVATE_DEPS
fmt::fmt
)
mp_add_library(
mp_error
STATIC
ROOT mp/error
DEPS
mp::mp_core
PRIVATE_DEPS
fmt::fmt
)
mp_add_library(
mp_fs
STATIC
ROOT mp/fs
DEPS
mp::mp_error
PRIVATE_DEPS
fmt::fmt
)
mp_add_library(
mp_ast
STATIC
ROOT mp/ast
DEPS
mp::mp_error
fmt::fmt
mp::clang_core
)
mp_add_library(
mp_plugin
SHARED
SRC_FILES src/plugin/plugin.cpp
PRIVATE_DEPS
mp::mp_ast
)
mp_add_library(
mp_hook_prelude
INTERFACE
INCLUDE_DIRS mp/hook_prelude/include
PRELUDE_HEADERS mp/hook_prelude/include/mp_hook_prelude.h
)
mp_add_library(
mp_unwind
STATIC
ROOT mp/unwind
DEPS
mp::mp_error
mp::mp_core
fmt::fmt
mp::mp_hook_prelude
)
mp_add_library(
mp_runtime
SHARED
ROOT mp/runtime
PRIVATE_COMPILE_FEATURES
cxx_std_23
PRIVATE_DEPS
mp::mp_unwind
cpptrace::cpptrace
glaze::glaze
ankerl::unordered_dense
)
target_compile_features(mp_runtime PRIVATE cxx_std_23)
# target_compile_options(mp_runtime PRIVATE -fsanitize=address,undefined)
# target_link_options(mp_runtime PRIVATE -fsanitize=address,undefined)
if(MEM_PROFILE_SANITIZE_RUNTIME)
target_compile_options(mp_runtime PRIVATE -fsanitize=address,undefined)
target_link_options(mp_runtime PRIVATE -fsanitize=address,undefined)
endif()
add_library(
mp_build_with_plugin
INTERFACE
)
target_compile_options(
mp_build_with_plugin
INTERFACE
$<$<COMPILE_LANGUAGE:CXX>:-fplugin=$<TARGET_FILE:mp::mp_plugin>>
$<$<COMPILE_LANGUAGE:CXX>:-Xclang=-add-plugin>
$<$<COMPILE_LANGUAGE:CXX>:-Xclang=mp_instrument_dtors>
$<$<COMPILE_LANGUAGE:CXX>:$<INSTALL_INTERFACE:--include=$<INSTALL_PREFIX>/include/mp_hook_prelude.h>>
)
mp_make_shared(
mp_unwind_shared
API_MODULES
mp::mp_unwind
)
if(LINUX)
target_link_libraries(mp_unwind PRIVATE PkgConfig::libunwind)
endif()
# Set the directory for mem_profileConfig based on the Config mode search procedure
# https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure
if(WIN32)
set(CONFIG_DIR ${PROJECT_NAME})
else()
set(CONFIG_DIR share/cmake/${PROJECT_NAME})
endif()
include(CMakePackageConfigHelpers)
configure_package_config_file(
cmake/${PROJECT_NAME}Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${CONFIG_DIR}
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
DESTINATION ${CONFIG_DIR}
)
install(
EXPORT ${PROJECT_NAME}Targets
DESTINATION ${CONFIG_DIR}
NAMESPACE mp::
)
install(
TARGETS
mp_types
mp_hook_prelude
mp_unwind_shared
mp_plugin
mp_build_with_plugin
mp_runtime
EXPORT ${PROJECT_NAME}Targets
FILE_SET HEADERS
)
if(MEM_PROFILE_BUILD_TOOLS)
add_executable(ast_printer tools/ast_printer.cpp)
target_link_libraries(ast_printer mp_ast mp_fs fmt::fmt mp::clang_tooling)
endif()