-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
299 lines (264 loc) · 11.9 KB
/
Copy pathCMakeLists.txt
File metadata and controls
299 lines (264 loc) · 11.9 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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
cmake_minimum_required(VERSION 3.30)
# Base version; the released version string comes from git describe (see
# cmake/generate_version.cmake) and this value is the tarball fallback.
project(CLICE_PROJECT VERSION 0.1.0 LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_SCAN_FOR_MODULES OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include(GNUInstallDirs)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
option(CLICE_ENABLE_LTO "Enable ThinLTO for all targets" OFF)
option(CLICE_USE_LIBCXX "Use libc++ instead of libstdc++" OFF)
option(CLICE_OFFLINE_BUILD "Disable network downloads during configuration" OFF)
option(CLICE_ENABLE_TEST "Build unit tests" OFF)
option(CLICE_CI_ENVIRONMENT "Enable CI-specific configuration" OFF)
option(CLICE_ENABLE_BENCHMARK "Build benchmarks" OFF)
# Global flags that apply to all targets (including CPM dependencies).
if(NOT MSVC)
add_compile_options(-ffunction-sections -fdata-sections)
endif()
# Keyed on the target OS, not the compiler frontend: CI links Windows with
# GNU-driver clang++ + lld-link, where the frontend variant is "GNU" but the
# linker still speaks MSVC-style /OPT flags (see the Debug /OPT:NOICF below).
if(WIN32)
string(APPEND CMAKE_EXE_LINKER_FLAGS " -Wl,/OPT:REF")
string(APPEND CMAKE_SHARED_LINKER_FLAGS " -Wl,/OPT:REF")
elseif(APPLE)
string(APPEND CMAKE_EXE_LINKER_FLAGS " -Wl,-dead_strip")
string(APPEND CMAKE_SHARED_LINKER_FLAGS " -Wl,-dead_strip")
else()
string(APPEND CMAKE_EXE_LINKER_FLAGS " -static-libstdc++ -static-libgcc -Wl,--gc-sections")
string(APPEND CMAKE_SHARED_LINKER_FLAGS " -Wl,--gc-sections")
endif()
if(CLICE_USE_LIBCXX)
string(APPEND CMAKE_CXX_FLAGS " -stdlib=libc++")
string(APPEND CMAKE_EXE_LINKER_FLAGS " -stdlib=libc++")
string(APPEND CMAKE_SHARED_LINKER_FLAGS " -stdlib=libc++")
endif()
# Releases deliberately do NOT enable LTO yet. LLVM 22 removed the old
# toolchain blocker, but enabling remains deferred until the cancellation
# regression suite has been validated under ThinLTO.
if(CLICE_ENABLE_LTO)
string(APPEND CMAKE_C_FLAGS " -flto=thin")
string(APPEND CMAKE_CXX_FLAGS " -flto=thin")
string(APPEND CMAKE_EXE_LINKER_FLAGS " -flto=thin")
string(APPEND CMAKE_SHARED_LINKER_FLAGS " -flto=thin")
string(APPEND CMAKE_MODULE_LINKER_FLAGS " -flto=thin")
endif()
# Link optimizations are the default for optimized builds: what the test
# suites run is byte-for-byte what releases ship. Debug keeps the ASan
# friendly flags below instead. icf=safe (not =all) so address-taken
# functions keep C++ pointer identity.
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
if(WIN32)
# SAFEICF, not ICF: plain /OPT:ICF folds address-taken functions.
set(CLICE_LINK_OPT_FLAGS "-Wl,/OPT:SAFEICF")
elseif(APPLE)
# --keep-icf-stabs: without it dsymutil cannot see ICF-folded symbols,
# so they would be missing from the dSYM (and thus from GSYM).
set(CLICE_LINK_OPT_FLAGS "-Wl,--icf=safe" "-Wl,--keep-icf-stabs")
else()
set(CLICE_LINK_OPT_FLAGS "-Wl,--icf=safe" "-Wl,-O2")
endif()
# Only lld understands these; manual builds on the system linker
# (ld.bfd, Apple ld64) build fine without them.
include(CheckLinkerFlag)
check_linker_flag(CXX "${CLICE_LINK_OPT_FLAGS}" CLICE_LINKER_OPT_SUPPORTED)
if(CLICE_LINKER_OPT_SUPPORTED)
string(JOIN " " CLICE_LINK_OPT_FLAGS ${CLICE_LINK_OPT_FLAGS})
string(APPEND CMAKE_EXE_LINKER_FLAGS " ${CLICE_LINK_OPT_FLAGS}")
else()
message(STATUS "Linker rejects ${CLICE_LINK_OPT_FLAGS}; skipping link optimizations")
endif()
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(-fsanitize=address)
if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
# clang-cl (MSVC frontend): manually link ASan runtime since clang-cl
# doesn't handle -fsanitize=address linking automatically.
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} --print-resource-dir
OUTPUT_VARIABLE CLANG_RESOURCE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(ASAN_LIB_PATH "${CLANG_RESOURCE_DIR}/lib/windows")
link_directories(${ASAN_LIB_PATH})
set(ASAN_LINK_FLAGS "")
list(APPEND ASAN_LINK_FLAGS "clang_rt.asan_dynamic-x86_64.lib")
list(APPEND ASAN_LINK_FLAGS "/wholearchive:clang_rt.asan_dynamic_runtime_thunk-x86_64.lib")
foreach(flag ${ASAN_LINK_FLAGS})
string(APPEND CMAKE_EXE_LINKER_FLAGS " ${flag}")
string(APPEND CMAKE_SHARED_LINKER_FLAGS " ${flag}")
string(APPEND CMAKE_MODULE_LINKER_FLAGS " ${flag}")
endforeach()
else()
string(APPEND CMAKE_EXE_LINKER_FLAGS " -fsanitize=address")
string(APPEND CMAKE_SHARED_LINKER_FLAGS " -fsanitize=address")
endif()
if(WIN32)
# Disable Identical COMDAT Folding in Debug to avoid ASan ODR false positives.
string(APPEND CMAKE_EXE_LINKER_FLAGS " -Wl,/OPT:NOICF")
string(APPEND CMAKE_SHARED_LINKER_FLAGS " -Wl,/OPT:NOICF")
endif()
endif()
include("${PROJECT_SOURCE_DIR}/cmake/package.cmake")
include("${PROJECT_SOURCE_DIR}/cmake/pch.cmake")
# Project-specific options (not applied to third-party deps).
add_library(clice_options INTERFACE)
if(MSVC OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND
CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC"))
target_compile_options(clice_options INTERFACE /GR- /EHs-c- /Zc:preprocessor)
else()
target_compile_options(clice_options INTERFACE
-fno-rtti
-fno-exceptions
-Wno-deprecated-declarations
$<$<COMPILE_LANG_AND_ID:CXX,Clang,AppleClang>:-Wno-undefined-inline>
)
endif()
if(WIN32)
target_link_libraries(clice_options INTERFACE version ntdll)
endif()
if(CLICE_ENABLE_TEST)
target_compile_definitions(clice_options INTERFACE CLICE_ENABLE_TEST=1)
endif()
if(CLICE_CI_ENVIRONMENT)
target_compile_definitions(clice_options INTERFACE CLICE_CI_ENVIRONMENT=1)
endif()
# Version header, regenerated on every build so the embedded git describe
# tracks the checked-out commit (content-unchanged writes are elided).
set(CLICE_VERSION_HEADER "${PROJECT_BINARY_DIR}/generated/version.h")
# Target identifier stamped next to the version: the same canonical
# triple the release asset names use, so a crash log names the exact
# downloadable artifact.
clice_target_triple(CLICE_TARGET_STRING)
add_custom_target(generate_version_header
COMMAND ${CMAKE_COMMAND}
-DSOURCE_DIR=${PROJECT_SOURCE_DIR}
-DFALLBACK_VERSION=${PROJECT_VERSION}
-DTARGET_STRING=${CLICE_TARGET_STRING}
-DTEMPLATE=${PROJECT_SOURCE_DIR}/cmake/version.h.in
-DOUTPUT_FILE=${CLICE_VERSION_HEADER}
-P "${PROJECT_SOURCE_DIR}/cmake/generate_version.cmake"
BYPRODUCTS "${CLICE_VERSION_HEADER}"
COMMENT "Generating version header"
)
# Layered targets: core <- config <- worker <- sched <- server. Each layer
# may include downward only; the link DAG plus the layering check in CI
# (`pixi run check-layers`) enforce the boundary — sched and below never
# see an LSP or server header.
file(GLOB_RECURSE CLICE_CORE_SOURCES CONFIGURE_DEPENDS
"${PROJECT_SOURCE_DIR}/src/support/*.cpp"
"${PROJECT_SOURCE_DIR}/src/vfs/*.cpp"
"${PROJECT_SOURCE_DIR}/src/syntax/*.cpp"
"${PROJECT_SOURCE_DIR}/src/command/*.cpp"
"${PROJECT_SOURCE_DIR}/src/compile/*.cpp"
"${PROJECT_SOURCE_DIR}/src/semantic/*.cpp"
"${PROJECT_SOURCE_DIR}/src/index/*.cpp"
"${PROJECT_SOURCE_DIR}/src/feature/*.cpp"
)
add_library(clice-core STATIC ${CLICE_CORE_SOURCES})
add_library(clice::core ALIAS clice-core)
add_dependencies(clice-core generate_version_header)
clice_precompile_headers(clice-core)
target_include_directories(clice-core PUBLIC
"${PROJECT_SOURCE_DIR}/src"
"${PROJECT_SOURCE_DIR}/cmake"
"${PROJECT_BINARY_DIR}/generated"
)
target_link_libraries(clice-core PUBLIC
clice_options
llvm-libs
spdlog::spdlog
roaring::roaring
kota::codec::flatbuffers
kota::ipc::lsp
kota::codec::toml
kota::option
kota::support
simdjson::simdjson
lmdb
)
file(GLOB_RECURSE CLICE_CONFIG_SOURCES CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/src/config/*.cpp")
add_library(clice-config STATIC ${CLICE_CONFIG_SOURCES})
add_library(clice::config ALIAS clice-config)
target_link_libraries(clice-config PUBLIC clice::core)
clice_precompile_headers(clice-config)
file(GLOB_RECURSE CLICE_WORKER_SOURCES CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/src/worker/*.cpp")
add_library(clice-worker STATIC ${CLICE_WORKER_SOURCES})
add_library(clice::worker ALIAS clice-worker)
target_link_libraries(clice-worker PUBLIC clice::config)
clice_precompile_headers(clice-worker)
file(GLOB_RECURSE CLICE_SCHED_SOURCES CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/src/sched/*.cpp")
add_library(clice-sched STATIC ${CLICE_SCHED_SOURCES})
add_library(clice::sched ALIAS clice-sched)
target_link_libraries(clice-sched PUBLIC clice::worker)
clice_precompile_headers(clice-sched)
file(GLOB_RECURSE CLICE_SERVER_SOURCES CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/src/server/*.cpp")
add_library(clice-server STATIC ${CLICE_SERVER_SOURCES})
add_library(clice::server ALIAS clice-server)
# Server sources include the generated version.h; a link dependency alone
# does not order another target's compilation after the custom command.
add_dependencies(clice-server generate_version_header)
target_link_libraries(clice-server PUBLIC clice::sched)
clice_precompile_headers(clice-server)
file(GLOB CLICE_DRIVER_SOURCES CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/src/driver/*.cc")
add_executable(clice "${PROJECT_SOURCE_DIR}/src/clice.cc" ${CLICE_DRIVER_SOURCES})
target_link_libraries(clice PRIVATE clice::server kota::deco)
clice_precompile_headers(clice)
add_dependencies(clice generate_version_header)
install(TARGETS clice RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
add_custom_target(copy_clang_resource ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${LLVM_INSTALL_PATH}/lib/clang"
"${PROJECT_BINARY_DIR}/lib/clang"
COMMENT "Copying clang resource directory"
)
install(
DIRECTORY "${LLVM_INSTALL_PATH}/lib/clang"
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
if(CLICE_ENABLE_TEST)
file(GLOB_RECURSE CLICE_TEST_SOURCES CONFIGURE_DEPENDS
"${PROJECT_SOURCE_DIR}/tests/unit/*/*_tests.cpp"
)
set(CLICE_TEST_SUPPORT_SOURCES
"${PROJECT_SOURCE_DIR}/tests/unit/test/tester.cpp"
)
add_executable(unit_tests
"${PROJECT_SOURCE_DIR}/tests/unit/unit_tests.cc"
${CLICE_TEST_SOURCES}
${CLICE_TEST_SUPPORT_SOURCES}
)
target_include_directories(unit_tests PRIVATE
"${PROJECT_SOURCE_DIR}/src"
"${PROJECT_SOURCE_DIR}/tests/unit"
)
target_link_libraries(unit_tests PRIVATE clice::server kota::zest kota::deco)
clice_precompile_headers(unit_tests)
target_compile_definitions(unit_tests PRIVATE
CLICE_TESTS_DATA_DIR="${PROJECT_SOURCE_DIR}/tests/data"
)
# The generated/ include dir propagates through clice::core, but the
# generation order does not — depend explicitly so a test including
# version.h cannot race the generator on a clean parallel build.
add_dependencies(unit_tests generate_version_header)
endif()
if(CLICE_ENABLE_BENCHMARK)
foreach(benchmark scan_benchmark pipeline_benchmark pch_chain_benchmark index_stats_benchmark)
add_executable(${benchmark}
"${PROJECT_SOURCE_DIR}/benchmarks/${benchmark}.cpp"
)
target_include_directories(${benchmark} PRIVATE
"${PROJECT_SOURCE_DIR}/src"
)
target_link_libraries(${benchmark} PRIVATE clice::server kota::deco)
# The benchmarks locate lib/clang next to their binary; an explicit
# `ninja <benchmark>` must not race or skip the resource copy.
add_dependencies(${benchmark} copy_clang_resource)
endforeach()
endif()
include("${PROJECT_SOURCE_DIR}/cmake/release.cmake")