-
-
Notifications
You must be signed in to change notification settings - Fork 240
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
349 lines (281 loc) · 12.1 KB
/
Copy pathCMakeLists.txt
File metadata and controls
349 lines (281 loc) · 12.1 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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
cmake_minimum_required(VERSION 3.16)
set(PROJECT_NAME vicinae)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_OSX_DEPLOYMENT_TARGET "14.4" CACHE STRING "Minimum macOS version to target")
project(${PROJECT_NAME} VERSION 1.0.0 LANGUAGES C CXX)
set(LIB_NAMESPACE "vicinae")
if (QT_DIR)
set(CMAKE_PREFIX_PATH ${QT_DIR} ${CMAKE_PREFIX_PATH})
message(STATUS "Using QT installation at ${QT_DIR}")
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
include(FetchContent)
include(GNUInstallDirs)
include(Git)
include(Utils)
# Viciane build configuration options
option(BUILD_TESTS "Build test suites for various vicinae components" OFF)
option(IGNORE_CCACHE "Always ignore ccache even if it is installed" OFF)
option(LTO "Enable Link Time Optimization (LTO). This will result in better performance, but greatly increased compile time. (Gentoo chads can't live without this)" OFF)
option(NOSTRIP "Never strip debug symbols from the binary, even in release mode. Note that symbols are never stripped for debug releases." OFF)
option(
INSTALL_NODE_MODULES
"Install required node_modules dependencies as part of the build process.
You can turn this off if you have another way to install the node_modules,
but they are still required build the project."
ON
)
option(WAYLAND_LAYER_SHELL "Enable support for the layer shell Wayland protocol" ON)
option(TYPESCRIPT_EXTENSIONS "Enable support for extensions built with React/Typescript (no browser involved)" ON)
option(PREFER_STATIC_LIBS "When available, link to a library statically instead of dynamically" OFF)
# Default for the USE_SYSTEM_* options below: Linux distros ship these as system
# packages, macOS does not, so it flips per platform.
set(USE_SYSTEM_DEFAULT ON)
if (APPLE)
set(USE_SYSTEM_DEFAULT OFF)
endif()
option(USE_SYSTEM_CMARK_GFM "Use system cmark-gfm (github's fork of cmark) instead of the vendored copy under vendor/cmark-gfm" ${USE_SYSTEM_DEFAULT})
option(USE_SYSTEM_LAYER_SHELL "Use system qt layer shell instead of building it from source" ON)
option(USE_SYSTEM_KF6 "Use system KDE syntax highlighting library for markdown code block highlight support" ${USE_SYSTEM_DEFAULT})
option(USE_SYSTEM_GLAZE "Use system glaze instead of fetching it. This is a header only library so only required at build time" OFF)
option(USE_SYSTEM_QT_KEYCHAIN "Use system qt-keychain instead of building it from source. Note: still depends on system libsecret." ${USE_SYSTEM_DEFAULT})
option(ENABLE_SANITIZERS "Enable ASan + UBSan for debug builds" OFF)
option(ENABLE_CLANG_TIDY "Run clang-tidy during compilation" OFF)
option(INSTALL_MODULES_LOAD_CONFIG "Install config files to auto load required kernel modules" ON)
option(AUTO_INSTALL_BROWSER_MANIFESTS "Install per-user browser native messaging host manifests at server startup" ON)
option(AUTO_ENABLE_AUTOSTART "Register the app to start at login on first launch (currently macOS only)" ON)
option(ENABLE_ONBOARDING "Show the onboarding window on first launch (macOS only)" ON)
set(BUNDLE_SOULVER_CORE_DEFAULT OFF)
if (APPLE)
set(BUNDLE_SOULVER_CORE_DEFAULT ON)
endif()
option(
BUNDLE_SOULVER_CORE
"Download the SoulverCore framework and bundle it with the app, making it the default calculator backend (macOS only)"
${BUNDLE_SOULVER_CORE_DEFAULT}
)
set(VICINAE_BUNDLE_ID "com.vicinaehq.Vicinae" CACHE STRING "macOS app bundle identifier")
set(NATIVE_MESSAGING_HOST "com.vicinae.vicinae")
set(CHROME_EXTENSION_ID "kcmipingpfbohfjckomimmahknoddnke") # https://chromewebstore.google.com/detail/vicinae-integration/kcmipingpfbohfjckomimmahknoddnke
set(FIREFOX_EXTENSION_ID "firefox@vicinae.com")
if (ENABLE_CLANG_TIDY)
set(CMAKE_CXX_CLANG_TIDY clang-tidy)
endif()
# disabled for now, as it seems to be incompatible with ccache, and as such slows us down more than anything
option(USE_PRECOMPILED_HEADERS "Use precompiled headers to speed up compilation" OFF)
set(LIB_DIR "${CMAKE_SOURCE_DIR}/src/lib")
set(EXTRA_DIR "${CMAKE_SOURCE_DIR}/extra")
set(THEME_DIR "${EXTRA_DIR}/themes")
set(VICINAE_LIBEXEC_PATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBEXECDIR}/vicinae)
set(VICINAE_LIBEXEC_DIR ${CMAKE_INSTALL_LIBEXECDIR}/vicinae)
if (APPLE)
if (NOT QT_DIR AND NOT CMAKE_PREFIX_PATH)
file(GLOB _qt_candidates "$ENV{HOME}/Qt/*/macos/lib/cmake/Qt6")
if (_qt_candidates)
list(SORT _qt_candidates COMPARE NATURAL ORDER DESCENDING)
list(GET _qt_candidates 0 _qt_cmake_dir)
get_filename_component(_qt_prefix "${_qt_cmake_dir}/../../.." ABSOLUTE)
list(PREPEND CMAKE_PREFIX_PATH "${_qt_prefix}")
message(STATUS "Using Qt from ${_qt_prefix}")
endif()
endif()
find_program(BREW_EXECUTABLE brew)
if (BREW_EXECUTABLE)
execute_process(
COMMAND ${BREW_EXECUTABLE} --prefix
OUTPUT_VARIABLE HOMEBREW_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE _brew_status
)
if (NOT _brew_status EQUAL 0)
set(HOMEBREW_PREFIX "")
endif()
endif()
if (HOMEBREW_PREFIX)
message(STATUS "Detected Homebrew prefix: ${HOMEBREW_PREFIX}")
if (NOT QT_DIR AND NOT CMAKE_PREFIX_PATH AND EXISTS "${HOMEBREW_PREFIX}/opt/qt/lib/cmake/Qt6")
list(PREPEND CMAKE_PREFIX_PATH "${HOMEBREW_PREFIX}/opt/qt")
endif()
include_directories(${HOMEBREW_PREFIX}/include)
link_directories(${HOMEBREW_PREFIX}/lib)
endif()
set(WAYLAND_LAYER_SHELL OFF)
set(WLR_DATA_CONTROL OFF)
endif()
if (NOT USE_SYSTEM_GLAZE)
include(Glaze)
import_glaze()
endif()
if (NOT USE_SYSTEM_KF6)
include(KF6)
import_kf6()
endif()
set(VENDOR_DIR ${CMAKE_SOURCE_DIR}/vendor)
include_directories(
${CMAKE_BINARY_DIR}
${CMAKE_SOURCE_DIR}/vendor
)
find_package(glaze)
add_subdirectory(src/browser-extension)
add_subdirectory(${LIB_DIR}/common)
add_subdirectory(${LIB_DIR}/script-command)
add_subdirectory(${LIB_DIR}/glyph)
add_subdirectory(${LIB_DIR}/xdgpp)
add_subdirectory(${LIB_DIR}/fuzzy)
add_subdirectory(${LIB_DIR}/crypto)
if (APPLE AND BUNDLE_SOULVER_CORE)
add_subdirectory(${LIB_DIR}/soulver)
endif()
# statically linked vendored libs.
# Most of the other vendored libs are header only so no need for a CMakeLists.txt
add_subdirectory(${VENDOR_DIR}/sqlcipher)
add_subdirectory(${VENDOR_DIR}/pugixml)
add_subdirectory(${VENDOR_DIR}/zip)
if (UNIX AND NOT APPLE)
add_subdirectory(${LIB_DIR}/linux-utils)
add_subdirectory(src/snippet)
add_subdirectory(src/file-indexer)
endif()
add_subdirectory(${LIB_DIR}/figura)
set(FIGURA_DIR ${CMAKE_SOURCE_DIR}/figura)
# End of Vicinae build configuration options
if (PREFER_STATIC_LIBS)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ".so" ".dylib")
set(BUILD_SHARED_LIBS OFF)
set(USE_SYSTEM_CMARK_GFM OFF)
set(USE_SYSTEM_LAYER_SHELL OFF)
set(USE_SYSTEM_QT_KEYCHAIN OFF)
endif()
if (NOT DEFINED VICINAE_GIT_TAG)
get_git_tag(VICINAE_GIT_TAG)
endif()
if (NOT DEFINED VICINAE_GIT_COMMIT_HASH)
get_git_commit(VICINAE_GIT_COMMIT_HASH)
endif()
if (DEFINED VICINAE_PROVENANCE)
message(STATUS "Provenance was explicitly set to ${VICINAE_PROVENANCE}")
else()
set(VICINAE_PROVENANCE "local")
endif()
message(STATUS "Vicinae version: ${VICINAE_GIT_TAG}")
message(STATUS "Vicinae commit hash: ${VICINAE_GIT_COMMIT_HASH}")
set(VICINAE_NODE_RUNTIME_VERSION "v22.23.1" CACHE STRING "Pinned node runtime used to run extensions")
if (APPLE)
# we only support apple silicon macs
set(_node_runtime_platform "darwin-arm64")
set(_node_runtime_sha256 "ef28d8fab2c0e4314522d4bb1b7173270aa3937e93b92cb7de79c112ac1fa953")
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64")
set(_node_runtime_platform "linux-arm64")
set(_node_runtime_sha256 "543fa39e57d4c07855939459a323f4deb9a79dd1bb45e6e99458b0f2de10db8d")
else()
set(_node_runtime_platform "linux-x64")
set(_node_runtime_sha256 "7a8cb04b4a1df4eaf432125324b81b29a088e73570a23259a8de1c65d07fc129")
endif()
set(VICINAE_NODE_RUNTIME_SHA256 "${_node_runtime_sha256}" CACHE STRING "sha256 of the node runtime archive")
set(VICINAE_NODE_RUNTIME_URL
"https://nodejs.org/dist/${VICINAE_NODE_RUNTIME_VERSION}/node-${VICINAE_NODE_RUNTIME_VERSION}-${_node_runtime_platform}.tar.gz"
CACHE STRING "URL of the node runtime archive")
set(VICINAE_NODE_RUNTIME_TAR_MEMBER
"node-${VICINAE_NODE_RUNTIME_VERSION}-${_node_runtime_platform}/bin/node")
# self-distributed builds (dmg, appimage) always download the pinned runtime so
# the node version never depends on what the host has installed; package manager
# builds use the system node unless this is explicitly turned on
if (APPLE OR VICINAE_PROVENANCE STREQUAL "appimage")
set(_node_runtime_download_default ON)
else()
set(_node_runtime_download_default OFF)
endif()
option(VICINAE_NODE_RUNTIME_DOWNLOAD "Run extensions with the pinned downloaded node runtime"
${_node_runtime_download_default})
get_cxx_compiler_name(CXX_COMPILER_NAME)
# Generate version header from template
configure_file(
"${CMAKE_SOURCE_DIR}/cmake/version.h.in"
"${CMAKE_BINARY_DIR}/generated/version.h"
@ONLY
)
set(CMARK_LIBRARY "cmark-gfm")
set(CMARK_EXT_LIBRARY "cmark-gfm-extensions")
if (NOT USE_SYSTEM_QT_KEYCHAIN)
include(QtKeychain)
checkout_qt_keychain()
endif()
if (NOT USE_SYSTEM_LAYER_SHELL)
include(QtLayerShell)
checkout_layer_shell_qt()
endif()
if (NOT USE_SYSTEM_CMARK_GFM)
include(CMark)
setup_vendored_cmark()
set(CMARK_LIBRARY "libcmark-gfm_static")
set(CMARK_EXT_LIBRARY "libcmark-gfm-extensions_static")
endif()
if (TYPESCRIPT_EXTENSIONS)
add_subdirectory(src/typescript)
add_compile_definitions(HAS_TYPESCRIPT_EXTENSIONS=1)
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif()
message(STATUS "Configured build type ${CMAKE_BUILD_TYPE}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3 -O0")
add_compile_options(-Wall -Wextra -Wpedantic -Wno-unused-parameter -Wno-missing-field-initializers)
if (ENABLE_SANITIZERS AND CMAKE_BUILD_TYPE MATCHES "Debug")
message(STATUS "Sanitizers enabled (ASan + UBSan)")
# glaze has issues with ubsan+variants
#add_compile_options(-fsanitize=address,undefined -fno-omit-frame-pointer)
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
add_link_options(-fsanitize=address)
add_compile_definitions(DEBUG=1)
endif()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release ReleaseHost)
if (${CMAKE_BUILD_TYPE} MATCHES "Debug")
add_compile_definitions(DEBUG=1)
else()
add_compile_definitions(DEBUG=0)
endif()
set(BUILD_INFO "${CXX_COMPILER_NAME} ${CMAKE_CXX_COMPILER_VERSION} - ${CMAKE_BUILD_TYPE}")
find_program(CCACHE ccache)
if (LTO)
set(BUILD_INFO "${BUILD_INFO} - LTO")
message(STATUS "Link Time Optimization (LTO) is enabled")
# gcc needs 'auto' to enable parallel compilation: https://stackoverflow.com/questions/72218980/gcc-v12-1-warning-about-serial-compilation
add_compile_options(-flto=auto)
add_link_options(-flto=auto)
endif()
if (CCACHE AND NOT IGNORE_CCACHE)
message(STATUS "ccache is installed, changing CMAKE_CXX_COMPILER_LAUNCHER")
set(CMAKE_CXX_COMPILER_LAUNCHER "ccache")
endif()
add_compile_definitions(BUILD_INFO="${BUILD_INFO}")
add_subdirectory(src/cli)
add_subdirectory(src/server)
if (UNIX AND NOT APPLE)
add_subdirectory(src/data-control-server)
endif()
set(INSTALL_SHARE ${CMAKE_INSTALL_PREFIX}/share)
set(INSTALL_MODULES ${CMAKE_INSTALL_PREFIX}/lib/modules-load.d)
set(VICINAE_INSTALL_SHARE ${INSTALL_SHARE}/vicinae)
set(VICINAE_THEME_DIR ${VICINAE_INSTALL_SHARE}/themes)
if(NOT APPLE)
make_directory(${VICINAE_INSTALL_SHARE})
file(REMOVE_RECURSE ${VICINAE_THEME_DIR})
install(DIRECTORY ./extra/themes DESTINATION ${VICINAE_INSTALL_SHARE})
endif()
if (UNIX AND NOT APPLE)
if (INSTALL_MODULES_LOAD_CONFIG)
install(DIRECTORY ${EXTRA_DIR}/modules-load.d/ DESTINATION ${INSTALL_MODULES})
endif()
set(APP_DIR ${INSTALL_SHARE}/applications)
make_directory(${APP_DIR})
install(FILES ./extra/vicinae.desktop DESTINATION ${APP_DIR})
install(FILES ./extra/vicinae-url-handler.desktop DESTINATION ${APP_DIR})
set(ICON_DIR ${INSTALL_SHARE}/icons/hicolor/512x512/apps)
make_directory(${ICON_DIR})
install(FILES ./extra/vicinae.png DESTINATION ${ICON_DIR})
set(SYSTEMD_USER_DIR ${CMAKE_INSTALL_PREFIX}/lib/systemd/user)
make_directory(${SYSTEMD_USER_DIR})
install(FILES ./extra/vicinae.service DESTINATION ${SYSTEMD_USER_DIR})
endif()