-
-
Notifications
You must be signed in to change notification settings - Fork 305
/
CMakeLists.txt
570 lines (474 loc) · 16.5 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
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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
# SPDX-FileCopyrightText: 2024 Manuel Schneider
cmake_minimum_required(VERSION 3.22) # Ubuntu 22.04
# dont touch! set by metatool
set(PROJECT_VERSION 0.26.7)
project(albert
VERSION ${PROJECT_VERSION}
DESCRIPTION "Keyboard launcher"
HOMEPAGE_URL "https://albertlauncher.github.io"
)
set(PROJECT_DISPLAY_NAME "Albert")
# Local cmake modules (also CMake uses this in a pretty obscure way, e.g. for the plist)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
set(ALBERT_COMPILE_OPTIONS
#-Werror
-Wall
-Wextra
-Wpedantic
# warnings that should be errors
-Werror=return-type
# -Wconversion
# -Weffc++
-Winline
-Wmissing-field-initializers
-Wshadow
-Wstrict-aliasing
# Use this from time to time
# -Weverything
# -Wdocumentation
# -Wno-c++98-compat
# -Wno-c++20-compat
# -Wno-c++98-compat-pedantic
# ??
# -Wl,-undefined
)
# Put the binaries in dedicated toplevel directories
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
### Dependencies ##############################################################
# QNotification
add_subdirectory(lib/QNotification EXCLUDE_FROM_ALL)
# QHotkey
set(QT_DEFAULT_MAJOR_VERSION 6)
set(BUILD_SHARED_LIBS FALSE)
set(QHOTKEY_INSTALL OFF CACHE BOOL "" FORCE)
add_subdirectory(lib/QHotkey EXCLUDE_FROM_ALL)
target_compile_options(qhotkey PRIVATE -Wno-gnu-zero-variadic-macro-arguments -Wno-unused-parameter -Wno-shadow)
### Lib ######################################################################
set(TARGET_LIB lib${PROJECT_NAME})
set(LIB_PUBLIC_HEADER
${PROJECT_BINARY_DIR}/include/albert/config.h # generated
${PROJECT_BINARY_DIR}/include/albert/export.h # generated
include/albert/action.h
include/albert/backgroundexecutor.h
include/albert/extension.h
include/albert/extensionplugin.h
include/albert/extensionregistry.h
include/albert/extensionwatcher.h
include/albert/fallbackhandler.h
include/albert/frontend.h
include/albert/globalqueryhandler.h
include/albert/iconprovider.h
include/albert/indexitem.h
include/albert/indexqueryhandler.h
include/albert/inputhistory.h
include/albert/item.h
include/albert/logging.h
include/albert/matchconfig.h
include/albert/matcher.h
include/albert/notification.h
include/albert/plugindependency.h
include/albert/plugininstance.h
include/albert/pluginloader.h
include/albert/pluginmetadata.h
include/albert/pluginprovider.h
include/albert/property.h
include/albert/query.h
include/albert/rankitem.h
include/albert/standarditem.h
include/albert/telemetryprovider.h
include/albert/timeit.h
include/albert/triggerqueryhandler.h
include/albert/util.h
)
set(LIB_SRC
src/app/app.cpp
src/app/app.h
src/app/appqueryhandler.cpp
src/app/appqueryhandler.h
src/app/messagehandler.cpp
src/app/messagehandler.h
src/app/pluginqueryhandler.cpp
src/app/pluginqueryhandler.h
src/app/qtpluginloader.cpp
src/app/qtpluginloader.h
src/app/qtpluginprovider.cpp
src/app/qtpluginprovider.h
src/app/report.cpp
src/app/report.h
src/app/rpcserver.cpp
src/app/rpcserver.h
src/app/telemetry.cpp
src/app/telemetry.h
src/app/telemetryprovider.cpp
src/app/triggersqueryhandler.cpp
src/app/triggersqueryhandler.h
src/common/action.cpp
src/common/extension.cpp
src/common/item.cpp
src/common/rankitem.cpp
src/frontend/frontend.cpp
src/frontend/inputhistory.cpp
src/frontend/itemsmodel.cpp
src/frontend/itemsmodel.h
src/frontend/session.cpp
src/frontend/session.h
src/platform/platform.h
src/platform/signalhandler.h
src/plugin/extensionregistry.cpp
src/plugin/plugin.cpp
src/plugin/plugin.h
src/plugin/plugininstance.cpp
src/plugin/pluginloader.cpp
src/plugin/pluginprovider.cpp
src/plugin/pluginregistry.cpp
src/plugin/pluginregistry.h
src/plugin/topologicalsort.hpp
src/query/fallbackhandler.cpp
src/query/globalqueryhandler.cpp
src/query/query.cpp
src/query/queryengine.cpp
src/query/queryengine.h
src/query/queryexecution.cpp
src/query/queryexecution.h
src/query/triggerqueryhandler.cpp
src/query/usagedatabase.cpp
src/query/usagedatabase.h
src/settings/pluginswidget/pluginsmodel.cpp
src/settings/pluginswidget/pluginsmodel.h
src/settings/pluginswidget/pluginssortproxymodel.cpp
src/settings/pluginswidget/pluginssortproxymodel.h
src/settings/pluginswidget/pluginswidget.cpp
src/settings/pluginswidget/pluginswidget.h
src/settings/pluginswidget/pluginwidget.cpp
src/settings/pluginswidget/pluginwidget.h
src/settings/querywidget/fallbacksmodel.cpp
src/settings/querywidget/fallbacksmodel.h
src/settings/querywidget/queryhandlermodel.cpp
src/settings/querywidget/queryhandlermodel.h
src/settings/querywidget/querywidget.cpp
src/settings/querywidget/querywidget.h
src/settings/settingswindow.cpp
src/settings/settingswindow.h
src/util/extensionplugin.cpp
src/util/iconprovider.cpp
src/util/indexitem.cpp
src/util/indexqueryhandler.cpp
src/util/itemindex.cpp
src/util/itemindex.h
src/util/levenshtein.cpp
src/util/levenshtein.h
src/util/matcher.cpp
src/util/notification.cpp
src/util/standarditem.cpp
src/util/util.cpp
src/config.h.in
)
if (WIN32)
list(APPEND LIB_SRC
src/platform/win/signalhandler.cpp
)
elseif (APPLE)
list(APPEND LIB_SRC
src/platform/unix/signalhandler.cpp
src/platform/mac/platform.mm
)
elseif(UNIX) # assume xdg
list(APPEND LIB_SRC
src/platform/unix/signalhandler.cpp
src/platform/xdg/iconlookup.cpp
src/platform/xdg/iconlookup.h
src/platform/xdg/platform.cpp
src/platform/xdg/themefileparser.cpp
src/platform/xdg/themefileparser.h
)
endif()
set(LIB_UI
src/settings/querywidget/querywidget.ui
src/settings/settingswindow.ui
)
add_library(${TARGET_LIB} SHARED
${LIB_PUBLIC_HEADER}
${LIB_SRC}
${LIB_UI}
resources/resources.qrc
)
add_library("${PROJECT_NAME}::${TARGET_LIB}" ALIAS ${TARGET_LIB})
include(GNUInstallDirs)
include(GenerateExportHeader)
generate_export_header(${TARGET_LIB}
BASE_NAME ${PROJECT_NAME}
EXPORT_FILE_NAME "${PROJECT_BINARY_DIR}/include/albert/export.h"
)
target_compile_options(${TARGET_LIB} PRIVATE ${ALBERT_COMPILE_OPTIONS})
target_include_directories(${TARGET_LIB}
PUBLIC
"$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include/>"
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
PRIVATE
"${PROJECT_BINARY_DIR}/include/albert"
"${PROJECT_SOURCE_DIR}/include/albert"
src
src/app
src/common
src/frontend
src/handlers
src/platform
src/platform/mac
src/platform/unix
src/platform/xdg
src/plugin
src/query
src/settings
src/settings/pluginswidget
src/settings/querywidget
src/util
)
configure_file(
"${PROJECT_SOURCE_DIR}/src/config.h.in"
"${PROJECT_BINARY_DIR}/include/albert/config.h"
@ONLY
)
find_package(Qt6 6.2 REQUIRED COMPONENTS # Ubuntu 22.04
Core
Concurrent
Network
Sql
Svg
Widgets
LinguistTools
)
target_link_libraries(${TARGET_LIB}
PRIVATE
QHotkey::QHotkey
QNotifications::QNotifications
Qt6::Concurrent
Qt6::Core
Qt6::Network
Qt6::Sql
Qt6::Widgets
)
if(APPLE)
target_link_libraries(${TARGET_LIB}
PRIVATE objc "-framework Cocoa"
)
elseif(UNIX)
if (DEFINED CMAKE_LIBRARY_ARCHITECTURE)
target_compile_definitions(${TARGET_LIB}
PRIVATE -DMULTIARCH_TUPLE="${CMAKE_LIBRARY_ARCHITECTURE}"
)
endif()
endif()
set_target_properties(${TARGET_LIB} PROPERTIES
#INSTALL_RPATH "$ORIGIN"
CXX_STANDARD 20
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
CXX_VISIBILITY_PRESET hidden
FRAMEWORK TRUE
FRAMEWORK_VERSION A
MACOSX_FRAMEWORK_BUNDLE_VERSION "${PROJECT_VERSION}"
MACOSX_FRAMEWORK_IDENTIFIER "org.albertlauncher.albert.interface"
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${PROJECT_VERSION}
OUTPUT_NAME "${PROJECT_NAME}"
PUBLIC_HEADER "${LIB_PUBLIC_HEADER}"
SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}" # also mach-o compat version
# NO_SONAME true # do _not_ add. linkers other that ldd will make troubles using non relative paths
VERSION ${PROJECT_VERSION}
VISIBILITY_INLINES_HIDDEN 1
AUTOMOC ON
AUTOUIC ON
AUTORCC ON
)
### Internationalization
file(GLOB TS_FILES i18n/*.ts)
# Source files to be translated (separate because some files may be masked)
file(GLOB_RECURSE TRANSLATION_SOURCE_FILES
include/.h
src/*.h
src/*.ui
src/*.mm
src/*.cpp
)
qt_add_translations(
${TARGET_LIB}
TS_FILES ${TS_FILES}
SOURCES ${TRANSLATION_SOURCE_FILES}
LUPDATE_OPTIONS
# -no-obsolete
-locations none
)
# For convenience, QtCreator does not show the umbrella target
add_custom_target(global_lupdate DEPENDS update_translations)
### Export/Install
include(CMakePackageConfigHelpers)
set(LIB_EXPORT_NAME "${PROJECT_NAME}-targets")
set(LIB_TARGETS_FILE "${LIB_EXPORT_NAME}.cmake")
set(LIB_CONFIG_FILE "${PROJECT_NAME}-config.cmake")
set(LIB_VERSION_FILE "${PROJECT_NAME}-config-version.cmake")
set(LIB_MACROS_FILE "${PROJECT_NAME}-macros.cmake")
set(LIB_FIND_ALBERT_FILE "FindAlbert.cmake")
set(LIB_CMAKE_MODULE_DIR "${PROJECT_SOURCE_DIR}/cmake")
set(INSTALL_CONFIGDIR "${CMAKE_INSTALL_LIBDIR}/cmake/Albert")
# Install the target
# https://cmake.org/cmake/help/latest/command/install.html#targets
install(
TARGETS ${TARGET_LIB}
EXPORT ${LIB_EXPORT_NAME} # just an association
FRAMEWORK DESTINATION .
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/albert
)
# Create a targets file in install tree
# https://cmake.org/cmake/help/latest/command/install.html#export
# By default the generated file will be called <export-name>.cmake
install(
EXPORT ${LIB_EXPORT_NAME}
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${INSTALL_CONFIGDIR}
)
# Create a targets file in build tree (matching install(EXPORT))
# https://cmake.org/cmake/help/latest/command/export.html#exporting-targets-matching-install-export
# Seems like a shorthand for export(TARGETS)
export(
EXPORT ${LIB_EXPORT_NAME}
NAMESPACE ${PROJECT_NAME}::
FILE "${PROJECT_BINARY_DIR}/${LIB_TARGETS_FILE}"
)
include(CMakePackageConfigHelpers)
# Create version file in build tree
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/${LIB_VERSION_FILE}"
VERSION "${PROJECT_VERSION}"
COMPATIBILITY AnyNewerVersion
)
# Create config file in build tree
configure_package_config_file(
"${LIB_CMAKE_MODULE_DIR}/${LIB_CONFIG_FILE}.in"
"${PROJECT_BINARY_DIR}/${LIB_CONFIG_FILE}"
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)
# Copy the macros to the build directory
configure_file(
"${LIB_CMAKE_MODULE_DIR}/${LIB_MACROS_FILE}"
"${PROJECT_BINARY_DIR}/${LIB_MACROS_FILE}"
COPYONLY
)
# Copy the dummy FindAlbert to the build directory
configure_file(
"${LIB_CMAKE_MODULE_DIR}/${LIB_FIND_ALBERT_FILE}.in"
"${PROJECT_BINARY_DIR}/${LIB_FIND_ALBERT_FILE}"
@ONLY
)
install(FILES
"${PROJECT_BINARY_DIR}/${LIB_CONFIG_FILE}"
"${PROJECT_BINARY_DIR}/${LIB_VERSION_FILE}"
"${PROJECT_BINARY_DIR}/${LIB_MACROS_FILE}"
DESTINATION ${INSTALL_CONFIGDIR}
)
### App ######################################################################
set(TARGET_APP ${CMAKE_PROJECT_NAME})
add_executable(${TARGET_APP} MACOSX_BUNDLE "src/main.cpp")
if (APPLE)
set(ICON_NAME "albert")
set(ICON_PATH "dist/macos/${ICON_NAME}.icns")
target_sources(${TARGET_APP} PRIVATE ${ICON_PATH})
set_source_files_properties(${ICON_PATH} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
set_target_properties(${TARGET_APP} PROPERTIES
BUNDLE True
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_BUNDLE_NAME "${PROJECT_DISPLAY_NAME}" # "${PROJECT_NAME}"
MACOSX_BUNDLE_BUNDLE_VERSION "${CMAKE_PROJECT_VERSION}"
MACOSX_BUNDLE_COPYRIGHT "Copyright (c) 2024 Manuel Schneider"
MACOSX_BUNDLE_GUI_IDENTIFIER "org.albertlauncher.albert"
MACOSX_BUNDLE_ICON_FILE "${ICON_NAME}"
MACOSX_BUNDLE_INFO_STRING "Albert keyboard launcher"
MACOSX_BUNDLE_SHORT_VERSION_STRING "${CMAKE_PROJECT_VERSION}"
)
elseif (UNIX)
install(FILES dist/xdg/albert.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
install(FILES resources/albert.svg DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps)
endif()
target_link_libraries(${TARGET_APP} PRIVATE ${TARGET_LIB})
#INSTALL_RPATH_USE_LINK_PATH TRUE
#INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
#BUILD_WITH_INSTALL_RPATH FALSE
#INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}/albert/" # Set the RPATH for the library lookup
#INSTALL_RPATH "$ORIGIN/../Frameworks/albert/" # Set the RPATH for the library lookup
install(
TARGETS ${TARGET_APP}
BUNDLE DESTINATION .
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
### Plugins ###################################################################
# Since the cmake module path of this project contains a dummy FindAlbert.cmake
# CMake uses this one instead of searching systemwide.
list(APPEND CMAKE_MODULE_PATH "${PROJECT_BINARY_DIR}")
# # on macOS include the macports lookup path
# if (APPLE)
# list(APPEND CMAKE_PREFIX_PATH "/opt/local")
# message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
# endif()
#2024: Drop ports use brew only
# if (APPLE)
# list(APPEND CMAKE_PREFIX_PATH "/opt/homebrew")
# message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
# endif()
option(BUILD_PLUGINS "Build plugins" ON)
set(PLUGINS_DIR "${CMAKE_CURRENT_LIST_DIR}/plugins")
if (BUILD_PLUGINS)
file(GLOB ENTRIES RELATIVE "${PLUGINS_DIR}" plugins/*)
list(FILTER ENTRIES EXCLUDE REGEX "^\\..+")
foreach(ENTRY ${ENTRIES})
if(IS_DIRECTORY "${PLUGINS_DIR}/${ENTRY}")
string(TOUPPER ${ENTRY} UPPER)
option(BUILD_PLUGIN_${UPPER} "Build plugin ${ENTRY}" ON)
if (BUILD_PLUGIN_${UPPER})
add_subdirectory("${PLUGINS_DIR}/${ENTRY}")
endif()
endif()
endforeach()
endif()
### Test ######################################################################
option(BUILD_TESTS "Build tests (Requires QTest)" OFF)
if (BUILD_TESTS)
include(CTest)
find_package(Qt6 REQUIRED COMPONENTS Test)
get_target_property(SRC_TST ${TARGET_LIB} SOURCES)
get_target_property(INC_TST ${TARGET_LIB} INCLUDE_DIRECTORIES)
get_target_property(LIBS_TST ${TARGET_LIB} LINK_LIBRARIES)
get_target_property(CXX_STD_TST ${TARGET_LIB} CXX_STANDARD)
set(TARGET_TST ${CMAKE_PROJECT_NAME}_test)
add_executable(${TARGET_TST} ${SRC_TST} test/test.h test/test.cpp)
target_include_directories(${TARGET_TST} PRIVATE ${INC_TST} test)
target_link_libraries(${TARGET_TST} PRIVATE ${LIBS_TST} Qt6::Test)
set_target_properties(${TARGET_TST} PROPERTIES
CXX_STANDARD ${CXX_STD_TST}
AUTOMOC ON
AUTOUIC ON
AUTORCC ON
)
add_test(NAME ${TARGET_TST} COMMAND ${TARGET_TST})
endif()
### Packaging #################################################################
if (APPLE)
set(CPACK_GENERATOR "DragNDrop")
set(CPACK_PACKAGE_CHECKSUM "SHA256")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/README.md")
set(CPACK_PACKAGE_EXECUTABLES "${PROJECT_NAME}" "${PROJECT_DISPLAY_NAME} executable")
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_DISPLAY_NAME}-v${PROJECT_VERSION}")
set(CPACK_PACKAGE_NAME "${PROJECT_DISPLAY_NAME}")
#set(CPACK_PACKAGE_ICON "${PROJECT_SOURCE_DIR}/${ICON_PATH}")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CMAKE_PROJECT_NAME}")
set(CPACK_PACKAGE_VENDOR "manuelschneid3r")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE.md")
set(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_WELCOME "${PROJECT_SOURCE_DIR}/README.md")
set(CPACK_STRIP_FILES TRUE)
set(CPACK_MONOLITHIC_INSTALL TRUE)
configure_file("cmake/bundle-macos.cmake.in" "${PROJECT_BINARY_DIR}/bundle-macos.cmake" @ONLY)
install(SCRIPT "${PROJECT_BINARY_DIR}/bundle-macos.cmake")
include(CPack)
endif()