-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
207 lines (175 loc) · 7.15 KB
/
CMakeLists.txt
File metadata and controls
207 lines (175 loc) · 7.15 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
cmake_minimum_required(VERSION 3.30)
project(CLICE_PROJECT 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)
option(CLICE_RELEASE "Enable release packaging (LTO + strip + pack)" OFF)
# Global flags that apply to all targets (including FetchContent dependencies).
if(NOT MSVC)
add_compile_options(-ffunction-sections -fdata-sections)
endif()
if(APPLE)
# https://conda-forge.org/docs/maintainer/knowledge_base/#newer-c-features-with-old-sdk
add_compile_definitions(_LIBCPP_DISABLE_AVAILABILITY=1)
endif()
if(MSVC OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND
CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC"))
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()
if(CLICE_RELEASE)
set(CLICE_ENABLE_LTO ON)
endif()
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()
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")
# 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()
set(FBS_SCHEMA_FILE "${PROJECT_SOURCE_DIR}/src/index/schema.fbs")
set(GENERATED_HEADER "${PROJECT_BINARY_DIR}/generated/schema_generated.h")
add_custom_command(
OUTPUT "${GENERATED_HEADER}"
COMMAND $<TARGET_FILE:flatc> --cpp -o "${PROJECT_BINARY_DIR}/generated" "${FBS_SCHEMA_FILE}"
DEPENDS "${FBS_SCHEMA_FILE}"
COMMENT "Generating C++ header from ${FBS_SCHEMA_FILE}"
)
add_custom_target(generate_flatbuffers_schema DEPENDS "${GENERATED_HEADER}")
file(GLOB_RECURSE CLICE_CORE_SOURCES CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/src/*.cpp")
add_library(clice-core STATIC ${CLICE_CORE_SOURCES})
add_library(clice::core ALIAS clice-core)
add_dependencies(clice-core generate_flatbuffers_schema)
target_include_directories(clice-core PUBLIC
"${PROJECT_SOURCE_DIR}/src"
"${PROJECT_BINARY_DIR}/generated"
)
target_link_libraries(clice-core PUBLIC
clice_options
llvm-libs
spdlog::spdlog
roaring::roaring
flatbuffers
eventide::ipc::lsp
eventide::serde::toml
simdjson::simdjson
)
add_executable(clice "${PROJECT_SOURCE_DIR}/src/clice.cc")
target_link_libraries(clice PRIVATE clice::core eventide::deco)
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/annotation.cpp"
"${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::core eventide::zest eventide::deco)
endif()
if(CLICE_ENABLE_BENCHMARK)
add_executable(scan_benchmark
"${PROJECT_SOURCE_DIR}/benchmarks/scan_benchmark.cpp"
)
target_include_directories(scan_benchmark PRIVATE
"${PROJECT_SOURCE_DIR}/src"
)
target_link_libraries(scan_benchmark PRIVATE clice::core eventide::deco)
endif()
if(CLICE_RELEASE)
include("${PROJECT_SOURCE_DIR}/cmake/release.cmake")
endif()