Debian Codegraph @

CMakeLists.txt

raw ◀ ▶
4 Debian patches touch this file
1 cmake_minimum_required(VERSION 3.13...3.21)
2
3 option(APPVEYOR_BUILD "Build on appveyor" OFF)
4 option(CI_BUILD "Set when building in CI. Enables -Werror where possible" OFF)
5 option(ASAN "Compile with address sanitizers" OFF)
6 option(QML_DEBUGGING "Enable qml debugging" OFF)
7 if(UNIX AND NOT APPLE)
8 option(MAN "Build man page" ON)
9 else()
10 option(MAN "Build man page" OFF)
11 endif()
12 option(FLATPAK "Set this only if Nheko is built as a flatpak" OFF)
13 option(JSON_ImplicitConversions "Disable implicit conversions in nlohmann/json" ON)
14
15 set(
16 CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_LIST_DIR}/toolchain.cmake"
17 CACHE
18 FILEPATH "Default toolchain"
19 )
20 set(CMAKE_CXX_STANDARD 20 CACHE STRING "C++ standard")
21 set(CMAKE_CXX_STANDARD_REQUIRED ON CACHE BOOL "Require C++ standard to be supported")
22 set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "compile as PIC by default")
23 set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "macos deployment target")
24
25 option(HUNTER_ENABLED "Enable Hunter package manager" OFF)
26 include("cmake/HunterGate.cmake")
27 HunterGate(
28 URL "https://github.com/cpp-pm/hunter/archive/v0.26.1.tar.gz"
29 SHA1 "e41ac7a18c49b35ebac99ff2b5244317b2638a65"
30 LOCAL
31 )
32
33 macro(hunter_add_package_safe)
34 set(pkg_temp_backup_libdir "$ENV{PKG_CONFIG_LIBDIR}")
35 set(pkg_temp_backup_path "$ENV{PKG_CONFIG_PATH}")
36 hunter_add_package(${ARGV})
37 if("${pkg_temp_backup_path}" STREQUAL "")
38 unset(ENV{PKG_CONFIG_PATH})
39 else()
40 set(ENV{PKG_CONFIG_PATH} "${pkg_temp_backup_path}")
41 endif()
42 if("${pkg_temp_backup_libdir}" STREQUAL "")
43 unset(ENV{PKG_CONFIG_LIBDIR})
44 else()
45 set(ENV{PKG_CONFIG_LIBDIR} "${pkg_temp_backup_libdir}")
46 endif()
47 message("pkg_conf_path: '$ENV{PKG_CONFIG_PATH}', pkg_conf_libdir: '$ENV{PKG_CONFIG_LIBDIR}'")
48 endmacro()
49
50 project(nheko LANGUAGES CXX C)
51
52 option(USE_BUNDLED_SPDLOG "Use the bundled version of spdlog." ${HUNTER_ENABLED})
53 option(USE_BUNDLED_FMT "Use the bundled version of {fmt}." ${HUNTER_ENABLED})
54 option(USE_BUNDLED_OLM "Use the bundled version of libolm." ${HUNTER_ENABLED})
55 option(USE_BUNDLED_GTEST "Use the bundled version of Google Test." ${HUNTER_ENABLED})
56 option(USE_BUNDLED_CMARK "Use the bundled version of cmark." ${HUNTER_ENABLED})
57 option(USE_BUNDLED_JSON "Use the bundled version of nlohmann json." ${HUNTER_ENABLED})
58 option(USE_BUNDLED_OPENSSL "Use the bundled version of OpenSSL." OFF)
59 option(USE_BUNDLED_MTXCLIENT "Use the bundled version of the Matrix Client library." ${HUNTER_ENABLED})
60 option(USE_BUNDLED_LMDB "Use the bundled version of lmdb." ${HUNTER_ENABLED})
61 option(USE_BUNDLED_LMDBXX "Use the bundled version of lmdb++." ${HUNTER_ENABLED})
62 option(USE_BUNDLED_QTKEYCHAIN "Use the bundled version of Qt6Keychain." ${HUNTER_ENABLED})
63 option(USE_BUNDLED_COEURL "Use a bundled version of the Curl wrapper"
64 ${HUNTER_ENABLED})
65 option(USE_BUNDLED_LIBEVENT "Use the bundled version of libevent." ${HUNTER_ENABLED})
66 option(USE_BUNDLED_LIBCURL "Use the bundled version of libcurl." ${HUNTER_ENABLED})
67 option(USE_BUNDLED_RE2 "Use the bundled version of re2." ${HUNTER_ENABLED})
68 option(USE_BUNDLED_KDSINGLEAPPLICATION "Use the bundled version of KDSingleApplication." ${HUNTER_ENABLED})
69 option(USE_BUNDLED_CPPHTTPLIB "Use the bundled version of cpp-httplib." ON)
70 option(USE_BUNDLED_BLURHASH "Use the bundled version of blurhash." ON)
71
72 include(CMakeDependentOption)
73 set(VOIP_DEFAULT ON)
74 if(APPLE OR WIN32 OR HAIKU)
75 set(VOIP_DEFAULT OFF)
76 endif()
77 option(VOIP "Whether to enable voip support. Disable this, if you don't have gstreamer." ${VOIP_DEFAULT})
78 set(X11_DEFAULT)
79 if(WIN32 OR APPLE OR HAIKU)
80 set(X11_DEFAULT OFF)
81 endif()
82 option(X11 "Whether to enable X11 specific features (screenshare, window roles)." ${X11_DEFAULT})
83 cmake_dependent_option(SCREENSHARE_XDP "Whether to enable screenshare support using xdg-desktop-portal." ON "VOIP" OFF)
84
85 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
86
87 if(${CMAKE_VERSION} VERSION_LESS "3.14.0")
88 message("Adding FetchContent_MakeAvailable")
89 # from cmakes sources
90 macro(FetchContent_MakeAvailable)
91 foreach(contentName IN ITEMS ${ARGV})
92 string(TOLOWER ${contentName} contentNameLower)
93 FetchContent_GetProperties(${contentName})
94 if(NOT ${contentNameLower}_POPULATED)
95 FetchContent_Populate(${contentName})
96
97 # Only try to call add_subdirectory() if the populated content
98 # can be treated that way. Protecting the call with the check
99 # allows this function to be used for projects that just want
100 # to ensure the content exists, such as to provide content at
101 # a known location.
102 if(EXISTS ${${contentNameLower}_SOURCE_DIR}/CMakeLists.txt)
103 add_subdirectory(${${contentNameLower}_SOURCE_DIR}
104 ${${contentNameLower}_BINARY_DIR})
105 endif()
106 endif()
107 endforeach()
108 endmacro()
109 endif()
110
111 # Include Qt basic functions
112 include(QtCommon)
113
114 include(GNUInstallDirs)
115
116 set(CPACK_PACKAGE_VERSION_MAJOR "0")
117 set(CPACK_PACKAGE_VERSION_MINOR "12")
118 set(CPACK_PACKAGE_VERSION_PATCH "1")
119 set(PROJECT_VERSION_MAJOR ${CPACK_PACKAGE_VERSION_MAJOR})
120 set(PROJECT_VERSION_MINOR ${CPACK_PACKAGE_VERSION_MINOR})
121 set(PROJECT_VERSION_PATCH ${CPACK_PACKAGE_VERSION_PATCH})
122
123 # Set PROJECT_VERSION_PATCH & PROJECT_VERSION_TWEAK to 0 if not present
124 # Needed by add_project_meta.
125 fix_project_version()
126
127 # Set additional project information
128 set(COMPANY "Nheko")
129 set(COPYRIGHT "Copyright (c) 2024 Nheko Contributors")
130 set(IDENTIFIER "im.nheko.Nheko")
131
132 add_project_meta(META_FILES_TO_INCLUDE)
133
134 if(NOT MSVC AND NOT APPLE)
135 set(THREADS_PREFER_PTHREAD_FLAG ON)
136 find_package(Threads REQUIRED)
137 endif()
138
139 if(BUILD_DOCS)
140 find_package(Doxygen)
141
142 if(DOXYGEN_FOUND)
143 set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Doxyfile.in)
144 set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
145
146 configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT})
147
148 add_custom_target(docs ALL
149 COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
150 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
151 COMMENT "Generating API documentation with Doxygen"
152 VERBATIM )
153 else(DOXYGEN_FOUND)
154 message("Doxygen need to be installed to generate the doxygen documentation")
155 endif(DOXYGEN_FOUND)
156 endif()
157
158 #
159 ## coeurl
160 #
161 ## Need to repeat all libevent deps?!?
162 if(USE_BUNDLED_LIBEVENT)
163 hunter_add_package_safe(Libevent)
164 find_package(Libevent CONFIG REQUIRED)
165 else()
166 find_package(PkgConfig REQUIRED)
167 pkg_check_modules(libevent_core REQUIRED IMPORTED_TARGET libevent_core)
168 if(WIN32)
169 pkg_check_modules(libevent_windows REQUIRED IMPORTED_TARGET libevent_windows)
170 else()
171 pkg_check_modules(libevent_pthreads REQUIRED IMPORTED_TARGET libevent_pthreads)
172 endif()
173 endif()
174
175 # curl
176 if(USE_BUNDLED_LIBCURL)
177 hunter_add_package_safe(CURL)
178 find_package(CURL CONFIG REQUIRED)
179 else()
180 find_package(PkgConfig REQUIRED)
181 pkg_check_modules(libcurl REQUIRED IMPORTED_TARGET libcurl)
182 endif()
183
184 # fmt
185 if(USE_BUNDLED_FMT)
186 hunter_add_package_safe(fmt)
187 endif()
188 find_package(fmt 8.0.0 CONFIG REQUIRED)
189
190 # spdlog
191 if(USE_BUNDLED_SPDLOG)
192 hunter_add_package_safe(spdlog)
193 endif()
194 find_package(spdlog 1.0.0 CONFIG REQUIRED)
195
196 if(USE_BUNDLED_COEURL)
197 include(FetchContent)
198 FetchContent_Declare(
199 coeurl
200 GIT_REPOSITORY https://nheko.im/Nheko-Reborn/coeurl.git
201 GIT_TAG 831e2ee8e9cf08ea1ee9736cde8370f9d0312abc
202 )
203 FetchContent_MakeAvailable(coeurl)
204 set(COEURL_TARGET_NAME coeurl::coeurl)
205 else()
206 find_package(PkgConfig)
207 pkg_check_modules(coeurl IMPORTED_TARGET coeurl>=0.3.0)
208 if(TARGET PkgConfig::coeurl)
209 set(COEURL_TARGET_NAME PkgConfig::coeurl)
210 endif()
211 endif()
212
213 if(NOT TARGET PkgConfig::coeurl)
214 find_package(coeurl 0.2.1 CONFIG)
215 if(TARGET coeurl::coeurl)
216 set(COEURL_TARGET_NAME coeurl::coeurl)
217 endif()
218 endif()
219
220 if(NOT COEURL_TARGET_NAME)
221 message(ERROR "Couldn't find coeurl")
222 endif()
223
224 if(USE_BUNDLED_RE2)
225 hunter_add_package(re2)
226 find_package(re2 CONFIG REQUIRED)
227 else()
228 find_package(PkgConfig REQUIRED)
229 pkg_check_modules(re2 REQUIRED IMPORTED_TARGET re2)
230 endif()
231
232 #
233 # LMDB
234 #
235 #include(LMDB)
236 if(USE_BUNDLED_LMDB)
237 hunter_add_package_safe(lmdb)
238 find_package(liblmdb CONFIG REQUIRED)
239
240 target_include_directories(liblmdb::lmdb INTERFACE
241 "${HUNTER_INSTALL_PREFIX}/include/lmdb")
242 else()
243 find_package(LMDB REQUIRED)
244 endif()
245
246 #
247 # Discover Qt dependencies.
248 #
249 find_package(Qt6 6.5 COMPONENTS Core Widgets Gui LinguistTools Svg Multimedia Qml QuickControls2 REQUIRED)
•250 if (Qt6Qml_VERSION VERSION_GREATER_EQUAL "6.10.0")
251 find_package(Qt6 REQUIRED COMPONENTS GuiPrivate QmlPrivate)
252 endif()
253 find_package(Qt6DBus)
254
255 if(USE_BUNDLED_QTKEYCHAIN)
256 include(FetchContent)
257 set(BUILD_WITH_QT6 ON)
258 FetchContent_Declare(
259 qt6keychain
260 GIT_REPOSITORY https://github.com/frankosterfeld/qtkeychain.git
261 GIT_TAG v0.14.0
262 )
263 set(BUILD_TEST_APPLICATION OFF CACHE INTERNAL "")
264 FetchContent_MakeAvailable(qt6keychain)
265 else()
266 find_package(Qt6Keychain REQUIRED)
267 endif()
268
269 if(USE_BUNDLED_KDSINGLEAPPLICATION)
270 include(FetchContent)
271 set(KDSingleApplication_QT6 ON CACHE BOOL INTERNAL)
272 set(KDSingleApplication_EXAMPLES OFF CACHE BOOL INTERNAL)
273 FetchContent_Declare(
274 kdsingleapplication
275 GIT_REPOSITORY https://github.com/KDAB/KDSingleApplication.git
276 GIT_TAG v1.0.0
277 )
278 FetchContent_MakeAvailable(kdsingleapplication)
279 else()
280 find_package(KDSingleApplication-qt6 REQUIRED)
281 endif()
282
283 if(Qt6Widgets_FOUND)
284 if(Qt6Widgets_VERSION VERSION_LESS 6.5.0)
285 message(STATUS "Qt version ${Qt6Widgets_VERSION}")
286 message(WARNING "Minimum supported Qt6 version is 6.5!")
287 endif()
288 endif(Qt6Widgets_FOUND)
289
290 set(CMAKE_INCLUDE_CURRENT_DIR ON)
291 if(NOT MSVC)
292 set(
293 CMAKE_CXX_FLAGS
294 "${CMAKE_CXX_FLAGS} \
295 -Wall \
296 -Wextra \
297 -pedantic \
298 -fsized-deallocation \
299 -Wunreachable-code \
300 -Wno-attributes"
301 )
302 if(NOT CMAKE_COMPILER_IS_GNUCXX)
303 # -Wshadow is buggy and broken in GCC, so do not enable it.
304 # see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79328
305 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
306 endif()
307 endif()
308
309 if(MSVC)
310 set(
311 CMAKE_CXX_FLAGS
312 "${CMAKE_CXX_FLAGS} /bigobj"
313 )
314 endif()
315
316 if(NOT (CMAKE_BUILD_TYPE OR CMAKE_CONFIGURATION_TYPES))
317 set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
318 "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
319 FORCE)
320 message("Setting build type to '${CMAKE_BUILD_TYPE}'")
321 else(NOT (CMAKE_BUILD_TYPE OR CMAKE_CONFIGURATION_TYPES))
322 message("Build type set to '${CMAKE_BUILD_TYPE}'")
323 endif(NOT (CMAKE_BUILD_TYPE OR CMAKE_CONFIGURATION_TYPES))
324
325 set(SPDLOG_DEBUG_ON false)
326
327 # Windows doesn't handle CMAKE_BUILD_TYPE.
328 if(NOT WIN32)
329 if(CMAKE_BUILD_TYPE STREQUAL "Debug")
330 set(SPDLOG_DEBUG_ON true)
331 else()
332 set(SPDLOG_DEBUG_ON false)
333 endif()
334 endif()
335
336 find_program(GIT git)
337 if(GIT)
338 execute_process(
339 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
340 COMMAND ${GIT} rev-parse --short HEAD
341 OUTPUT_VARIABLE GIT_OUT OUTPUT_STRIP_TRAILING_WHITESPACE
342 )
343 if(GIT_OUT)
344 set(CPACK_PACKAGE_VERSION_PATCH "${CPACK_PACKAGE_VERSION_PATCH}-${GIT_OUT}")
345 else()
346 set(CPACK_PACKAGE_VERSION_PATCH "${CPACK_PACKAGE_VERSION_PATCH}")
347 endif()
348 endif(GIT)
349
350 set(CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH})
351 set(PROJECT_VERSION ${CPACK_PACKAGE_VERSION})
352
353 message(STATUS "Version: ${PROJECT_VERSION}")
354
355 cmake_host_system_information(RESULT BUILD_HOST QUERY HOSTNAME)
356
357 include(CheckSymbolExists)
358 check_symbol_exists(backtrace_symbols_fd "execinfo.h" HAVE_BACKTRACE_SYMBOLS_FD)
359
360 configure_file(cmake/nheko.h config/nheko.h)
361
362 #
363 # Declare source and header files.
364 #
365 set(SRC_FILES
366 # Emoji
367 src/emoji/Provider.cpp
368 src/emoji/Provider.h
369 src/emoji/Emoji.cpp
370 src/emoji/Emoji.h
371
372 # Timeline
373 src/timeline/CommunitiesModel.cpp
374 src/timeline/CommunitiesModel.h
375 src/timeline/DelegateChooser.cpp
376 src/timeline/DelegateChooser.h
377 src/timeline/EventStore.cpp
378 src/timeline/EventStore.h
379 src/timeline/EventDelegateChooser.cpp
380 src/timeline/EventDelegateChooser.h
381 src/timeline/InputBar.cpp
382 src/timeline/InputBar.h
383 src/timeline/Permissions.cpp
384 src/timeline/Permissions.h
385 src/timeline/PresenceEmitter.cpp
386 src/timeline/PresenceEmitter.h
387 src/timeline/Reaction.cpp
388 src/timeline/Reaction.h
389 src/timeline/RoomlistModel.cpp
390 src/timeline/RoomlistModel.h
391 src/timeline/TimelineFilter.cpp
392 src/timeline/TimelineFilter.h
393 src/timeline/TimelineModel.cpp
394 src/timeline/TimelineModel.h
395 src/timeline/TimelineViewManager.cpp
396 src/timeline/TimelineViewManager.h
397
398 # UI components
399 src/ui/HiddenEvents.cpp
400 src/ui/HiddenEvents.h
401 src/ui/EventExpiry.cpp
402 src/ui/EventExpiry.h
403 src/ui/MxcAnimatedImage.cpp
404 src/ui/MxcAnimatedImage.h
405 src/ui/MxcMediaProxy.cpp
406 src/ui/MxcMediaProxy.h
407 src/ui/NhekoCursorShape.cpp
408 src/ui/NhekoCursorShape.h
409 src/ui/NhekoDropArea.cpp
410 src/ui/NhekoDropArea.h
411 src/ui/NhekoGlobalObject.cpp
412 src/ui/NhekoGlobalObject.h
413 src/ui/NhekoMenuVisibilityFilter.h
414 src/ui/NhekoMenuVisibilityFilter.cpp
415 src/ui/RoomSettings.cpp
416 src/ui/RoomSettings.h
417 src/ui/RoomSummary.cpp
418 src/ui/RoomSummary.h
419 src/ui/Theme.cpp
420 src/ui/Theme.h
421 src/ui/UIA.cpp
422 src/ui/UIA.h
423 src/ui/UserProfile.cpp
424 src/ui/UserProfile.h
425
426 src/voip/CallDevices.cpp
427 src/voip/CallDevices.h
428 src/voip/CallManager.cpp
429 src/voip/CallManager.h
430 src/voip/ScreenCastPortal.cpp
431 src/voip/ScreenCastPortal.h
432 src/voip/WebRTCSession.h
433 src/voip/WebRTCSession.cpp
434 src/voip/WebRTCSession.h
435
436 src/encryption/DeviceVerificationFlow.cpp
437 src/encryption/DeviceVerificationFlow.h
438 src/encryption/Olm.cpp
439 src/encryption/Olm.h
440 src/encryption/SelfVerificationStatus.cpp
441 src/encryption/SelfVerificationStatus.h
442 src/encryption/VerificationManager.cpp
443 src/encryption/VerificationManager.h
444
445 # Generic notification stuff
446 src/notifications/Manager.cpp
447 src/notifications/Manager.h
448
449 src/dock/Dock.cpp
450 src/dock/Dock.h
451
452 src/AliasEditModel.cpp
453 src/AliasEditModel.h
454 src/AvatarProvider.cpp
455 src/AvatarProvider.h
456 src/BlurhashProvider.cpp
457 src/BlurhashProvider.h
458 src/Cache.cpp
459 src/Cache.h
460 src/CacheCryptoStructs.cpp
461 src/CacheCryptoStructs.h
462 src/CacheStructs.h
463 src/Cache_p.h
464 src/ChatPage.cpp
465 src/ChatPage.h
466 src/Clipboard.cpp
467 src/Clipboard.h
468 src/ColorImageProvider.cpp
469 src/ColorImageProvider.h
470 src/CombinedImagePackModel.cpp
471 src/CombinedImagePackModel.h
472 src/GridImagePackModel.cpp
473 src/GridImagePackModel.h
474 src/CommandCompleter.cpp
475 src/CommandCompleter.h
476 src/CompletionModelRoles.h
477 src/CompletionProxyModel.cpp
478 src/CompletionProxyModel.h
479 src/Config.h
480 src/EventAccessors.cpp
481 src/EventAccessors.h
482 src/FallbackAuth.cpp
483 src/FallbackAuth.h
484 src/ImagePackListModel.cpp
485 src/ImagePackListModel.h
486 src/InviteesModel.cpp
487 src/InviteesModel.h
488 src/JdenticonProvider.cpp
489 src/JdenticonProvider.h
490 src/Logging.cpp
491 src/Logging.h
492 src/LoginPage.cpp
493 src/LoginPage.h
494 src/MainWindow.cpp
495 src/MainWindow.h
496 src/MatrixClient.cpp
497 src/MatrixClient.h
498 src/MemberList.cpp
499 src/MemberList.h
500 src/MxcImageProvider.cpp
501 src/MxcImageProvider.h
502 src/PowerlevelsEditModels.cpp
503 src/PowerlevelsEditModels.h
504 src/ReadReceiptsModel.cpp
505 src/ReadReceiptsModel.h
506 src/ReCaptcha.cpp
507 src/ReCaptcha.h
508 src/RegisterPage.cpp
509 src/RegisterPage.h
510 src/RoomDirectoryModel.cpp
511 src/RoomDirectoryModel.h
512 src/RoomsModel.cpp
513 src/RoomsModel.h
514 src/SSOHandler.cpp
515 src/SSOHandler.h
516 src/SingleImagePackModel.cpp
517 src/SingleImagePackModel.h
518 src/TrayIcon.cpp
519 src/TrayIcon.h
520 src/UserSettingsPage.cpp
521 src/UserSettingsPage.h
522 src/UsersModel.cpp
523 src/UsersModel.h
524 src/Utils.cpp
525 src/Utils.h
526
527 includes/jdenticoninterface.h
528
529 src/main.cpp
530 )
531
532 include(FeatureSummary)
533
534 if(USE_BUNDLED_OPENSSL)
535 hunter_add_package_safe(OpenSSL)
536 endif()
537 find_package(OpenSSL 1.1.0 REQUIRED)
538 if(USE_BUNDLED_OLM)
539 include(FetchContent)
540 FetchContent_Declare(
541 Olm
542 GIT_REPOSITORY https://gitlab.matrix.org/matrix-org/olm.git
543 GIT_TAG 3.2.16
544 PATCH_COMMAND git apply ${CMAKE_CURRENT_SOURCE_DIR}/third_party/olm-patches/0001-fix-list-const-ptr.patch
545 UPDATE_DISCONNECTED 1
546 )
547 set(OLM_TESTS OFF CACHE INTERNAL "")
548 FetchContent_MakeAvailable(Olm)
549 else()
550 find_package(Olm 3.2.7 REQUIRED)
551 set_package_properties(Olm PROPERTIES
552 DESCRIPTION "An implementation of the Double Ratchet cryptographic ratchet"
553 URL "https://git.matrix.org/git/olm/about/"
554 TYPE REQUIRED
555 )
556 endif()
557 if(USE_BUNDLED_SPDLOG)
558 hunter_add_package_safe(spdlog)
559 endif()
560 find_package(spdlog 1.0.0 CONFIG REQUIRED)
561
562 if(USE_BUNDLED_CMARK)
563 include(FetchContent)
564 FetchContent_Declare(
565 cmark
566 GIT_REPOSITORY https://github.com/commonmark/cmark.git
567 GIT_TAG 0.31.1
568 CMAKE_ARGS "BUILD_TESTING=OFF"
569 )
570 FetchContent_MakeAvailable(cmark)
571 if (NOT TARGET cmark::cmark)
572 add_library(cmark::cmark ALIAS cmark)
573 endif()
574 else()
575 find_package(cmark REQUIRED 0.29.0)
576 endif()
577
578 if(USE_BUNDLED_JSON)
579 hunter_add_package_safe(nlohmann_json)
580 endif()
581 find_package(nlohmann_json 3.2.0)
582 set_package_properties(nlohmann_json PROPERTIES
583 DESCRIPTION "JSON for Modern C++, a C++11 header-only JSON class"
584 URL "https://nlohmann.github.io/json/"
585 TYPE REQUIRED
586 )
587
588 if(USE_BUNDLED_LMDBXX)
589 include(FetchContent)
590 FetchContent_Declare(
591 lmdbxx
592 URL "https://raw.githubusercontent.com/hoytech/lmdbxx/1.0.0/lmdb++.h"
593 DOWNLOAD_NO_EXTRACT TRUE
594 CONFIGURE_COMMAND ""
595 BUILD_COMMAND ""
596 )
597 FetchContent_Populate(lmdbxx)
598 add_library(lmdbxx INTERFACE)
599 target_include_directories(lmdbxx INTERFACE ${lmdbxx_SOURCE_DIR})
600 add_library(lmdbxx::lmdbxx ALIAS lmdbxx)
601 else()
602 if(NOT LMDBXX_INCLUDE_DIR)
603 find_path(LMDBXX_INCLUDE_DIR
604 NAMES lmdb++.h
605 PATHS /usr/include
606 /usr/local/include
607 $ENV{LIB_DIR}/include
608 $ENV{LIB_DIR}/include/lmdbxx)
609 endif()
610 add_library(lmdbxx INTERFACE)
611 target_include_directories(lmdbxx INTERFACE ${LMDBXX_INCLUDE_DIR})
612 add_library(lmdbxx::lmdbxx ALIAS lmdbxx)
613 endif()
614
615 if(USE_BUNDLED_MTXCLIENT)
616 include(FetchContent)
617 FetchContent_Declare(
618 MatrixClient
619 GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git
620 GIT_TAG v0.10.1
621 )
622 set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "")
623 set(BUILD_LIB_TESTS OFF CACHE INTERNAL "")
624 FetchContent_MakeAvailable(MatrixClient)
625 else()
626 find_package(MatrixClient 0.10.0 REQUIRED)
627 endif()
628
629 if(VOIP)
630 include(FindPkgConfig)
631 pkg_check_modules(GSTREAMER REQUIRED IMPORTED_TARGET gstreamer-sdp-1.0>=1.18 gstreamer-webrtc-1.0>=1.18 gstreamer-gl-1.0)
632 if (WIN32)
633 pkg_check_modules(GSTREAMER REQUIRED IMPORTED_TARGET gstreamer-d3d11-1.0)
634 endif()
635 endif()
636
637 if(X11 AND NOT WIN32 AND NOT APPLE AND NOT HAIKU)
638 pkg_check_modules(XCB REQUIRED IMPORTED_TARGET xcb xcb-ewmh)
639 endif()
640
641 feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
642
643 # this must be defined here to make the moc work properly
644 if(NOT APPLE AND NOT WIN32)
645 add_compile_definitions(NHEKO_DBUS_SYS)
646 endif()
647
648 #
649 # Bundle resources
650 #
651 qt_add_resources(QRC resources/res.qrc)
652
653 if(APPLE)
654 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework Foundation -framework Cocoa -framework UserNotifications")
655 set(SRC_FILES ${SRC_FILES} src/notifications/NotificationManagerProxy.h src/notifications/MacNotificationDelegate.h src/notifications/MacNotificationDelegate.mm src/notifications/ManagerMac.mm src/notifications/ManagerMac.cpp)
656 if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0")
657 set_source_files_properties( src/notifications/NotificationManagerProxy.h src/notifications/MacNotificationDelegate.h src/notifications/MacNotificationDelegate.mm src/notifications/ManagerMac.mm PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
658 endif()
659 elseif(WIN32)
660 file(DOWNLOAD
661 "https://raw.githubusercontent.com/mohabouje/WinToast/v1.3.0/src/wintoastlib.cpp"
662 ${PROJECT_SOURCE_DIR}/src/wintoastlib.cpp
663 EXPECTED_HASH SHA256=1ddf8ee2604e1757d383a2f60d4d597c4f5d9496369e6a22586cedf4af77ca8f)
664
665 file(DOWNLOAD
666 "https://raw.githubusercontent.com/mohabouje/WinToast/v1.3.0/include/wintoastlib.h"
667 ${PROJECT_SOURCE_DIR}/src/wintoastlib.h
668 EXPECTED_HASH SHA256=08cb30d28db9c851d3d4259ae6108ce7dafa966957df6735a06cd55e0716fded)
669
670 set(SRC_FILES ${SRC_FILES} src/notifications/ManagerWin.cpp src/wintoastlib.cpp src/wintoastlib.h)
671 else()
672 set(SRC_FILES ${SRC_FILES}
673 src/dbus/NhekoDBusApi.h
674 src/dbus/NhekoDBusBackend.h
675 src/dbus/NhekoDBusApi.cpp
676 src/dbus/NhekoDBusBackend.cpp
677 src/notifications/ManagerLinux.cpp
678 )
679 endif()
680
681 set(NHEKO_DEPS
682 ${SRC_FILES}
683 ${QRC}
684 ${META_FILES_TO_INCLUDE})
685
686 if(ASAN)
687 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address,undefined")
688 endif()
689
690 if(WIN32)
691 qt_add_executable(nheko WIN32 ${OS_BUNDLE} ${NHEKO_DEPS})
692 target_compile_definitions(nheko PRIVATE _WIN32_WINNT=0x0601 NOMINMAX WIN32_LEAN_AND_MEAN STRICT)
693 else()
694 qt_add_executable(nheko ${OS_BUNDLE} ${NHEKO_DEPS})
695
696 if(APPLE)
697 set_target_properties(nheko PROPERTIES MACOSX_BUNDLE_INFO_PLIST
698 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/MacOSXBundleInfo.plist.in")
699 endif()
700
701 if(HAVE_BACKTRACE_SYMBOLS_FD AND NOT CMAKE_BUILD_TYPE STREQUAL "Release")
702 set_target_properties(nheko PROPERTIES ENABLE_EXPORTS ON)
703 endif()
704 endif()
705
706 set_target_properties(nheko
707 PROPERTIES
708 CMAKE_SKIP_INSTALL_RPATH TRUE
709 AUTOMOC ON)
710
711 #
712 # Add qml files
713 #
•714 if(QT_KNOWN_POLICY_QTP0004)
715 qt_policy(SET QTP0004 NEW)
716 endif()
717 set(QML_SOURCES
718 resources/qml/Root.qml
719 resources/qml/ChatPage.qml
720 resources/qml/CommunitiesList.qml
721 resources/qml/RoomList.qml
722 resources/qml/Avatar.qml
723 resources/qml/Completer.qml
724 resources/qml/EncryptionIndicator.qml
725 resources/qml/ImageButton.qml
726 resources/qml/ElidedLabel.qml
727 resources/qml/MatrixText.qml
728 resources/qml/MatrixTextField.qml
729 resources/qml/ToggleButton.qml
730 resources/qml/UploadBox.qml
731 resources/qml/MessageInput.qml
732 resources/qml/MessageView.qml
733 resources/qml/PrivacyScreen.qml
734 resources/qml/Reactions.qml
735 resources/qml/ReplyPopup.qml
736 resources/qml/StatusIndicator.qml
737 resources/qml/TimelineEvent.qml
738 resources/qml/TimelineSectionHeader.qml
739 resources/qml/TimelineDefaultMessageStyle.qml
740 resources/qml/TimelineBubbleMessageStyle.qml
741 resources/qml/TimelineMetadata.qml
742 resources/qml/TimelineView.qml
743 resources/qml/TopBar.qml
744 resources/qml/QuickSwitcher.qml
745 resources/qml/ForwardCompleter.qml
746 resources/qml/SelfVerificationCheck.qml
747 resources/qml/TypingIndicator.qml
748 resources/qml/MessageInputWarning.qml
749 resources/qml/components/AdaptiveLayout.qml
750 resources/qml/components/AdaptiveLayoutElement.qml
751 resources/qml/components/AvatarListTile.qml
752 resources/qml/components/FlatButton.qml
753 resources/qml/components/MainWindowDialog.qml
754 resources/qml/components/NhekoTabButton.qml
755 resources/qml/components/NotificationBubble.qml
756 resources/qml/components/PowerlevelIndicator.qml
757 resources/qml/components/ReorderableListview.qml
758 resources/qml/components/SpaceMenu.qml
759 resources/qml/components/SpaceMenuLevel.qml
760 resources/qml/components/TextButton.qml
761 resources/qml/components/UserListRow.qml
762 resources/qml/delegates/Encrypted.qml
763 resources/qml/delegates/FileMessage.qml
764 resources/qml/delegates/ImageMessage.qml
765 resources/qml/delegates/NoticeMessage.qml
766 resources/qml/delegates/Pill.qml
767 resources/qml/delegates/Placeholder.qml
768 resources/qml/delegates/PlayableMediaMessage.qml
769 resources/qml/delegates/Redacted.qml
770 resources/qml/delegates/Reply.qml
771 resources/qml/delegates/TextMessage.qml
772 resources/qml/device-verification/DeviceVerification.qml
773 resources/qml/device-verification/DigitVerification.qml
774 resources/qml/device-verification/EmojiVerification.qml
775 resources/qml/device-verification/Failed.qml
776 resources/qml/device-verification/NewVerificationRequest.qml
777 resources/qml/device-verification/Success.qml
778 resources/qml/device-verification/Waiting.qml
779 resources/qml/dialogs/AliasEditor.qml
780 resources/qml/dialogs/ConfirmJoinRoomDialog.qml
781 resources/qml/dialogs/CreateDirect.qml
782 resources/qml/dialogs/CreateRoom.qml
783 resources/qml/dialogs/FallbackAuthDialog.qml
784 resources/qml/dialogs/HiddenEventsDialog.qml
785 resources/qml/dialogs/EventExpirationDialog.qml
786 resources/qml/dialogs/ImageOverlay.qml
787 resources/qml/dialogs/ImagePackEditorDialog.qml
788 resources/qml/dialogs/ImagePackDeleteDialog.qml
789 resources/qml/dialogs/ImagePackSettingsDialog.qml
790 resources/qml/dialogs/InputDialog.qml
791 resources/qml/dialogs/InviteDialog.qml
792 resources/qml/dialogs/JoinRoomDialog.qml
793 resources/qml/dialogs/LeaveRoomDialog.qml
794 resources/qml/dialogs/LogoutDialog.qml
795 resources/qml/dialogs/PhoneNumberInputDialog.qml
796 resources/qml/dialogs/PowerLevelEditor.qml
797 resources/qml/dialogs/PowerLevelSpacesApplyDialog.qml
798 resources/qml/dialogs/RawMessageDialog.qml
799 resources/qml/dialogs/ReadReceipts.qml
800 resources/qml/dialogs/ReCaptchaDialog.qml
801 resources/qml/dialogs/ReportMessage.qml
802 resources/qml/dialogs/RoomDirectory.qml
803 resources/qml/dialogs/RoomMembers.qml
804 resources/qml/dialogs/AllowedRoomsSettingsDialog.qml
805 resources/qml/dialogs/RoomSettingsDialog.qml
806 resources/qml/dialogs/UserProfile.qml
807 resources/qml/dialogs/IgnoredUsers.qml
808 resources/qml/emoji/StickerPicker.qml
809 resources/qml/pages/LoginPage.qml
810 resources/qml/pages/RegisterPage.qml
811 resources/qml/pages/UserSettingsPage.qml
812 resources/qml/pages/WelcomePage.qml
813 resources/qml/ui/NhekoSlider.qml
814 resources/qml/ui/Ripple.qml
815 resources/qml/ui/Snackbar.qml
816 resources/qml/ui/Spinner.qml
817 resources/qml/ui/animations/BlinkAnimation.qml
818 resources/qml/ui/media/MediaControls.qml
819 resources/qml/voip/ActiveCallBar.qml
820 resources/qml/voip/CallDevices.qml
821 resources/qml/voip/CallInvite.qml
822 resources/qml/voip/CallInviteBar.qml
823 resources/qml/voip/DeviceError.qml
824 resources/qml/voip/PlaceCall.qml
825 resources/qml/voip/ScreenShare.qml
826 resources/qml/voip/VideoCall.qml
827 resources/qml/voip/VideoCallD3D11.qml
828 resources/qml/delegates/EncryptionEnabled.qml
829 resources/qml/ui/TimelineEffects.qml
830 )
831 qt_add_qml_module(nheko
832 URI im.nheko
833 NO_RESOURCE_TARGET_PATH
834 RESOURCE_PREFIX "/"
835 VERSION 1.1
836 DEPENDENCIES QtQuick QtQml.Models
837 QML_FILES
838 ${QML_SOURCES}
839 SOURCES
840 src/UserDirectoryModel.cpp
841 src/UserDirectoryModel.h
842 )
843 #qt_target_qml_sources(nheko
844 # #PREFIX "/"
845 #)
846
847 #set_target_properties(nheko PROPERTIES
848 # QT_QMLCACHEGEN_ARGUMENTS "--verbose"
849 #)
850
851 #
852 # Bundle translations
853 #
854 file(GLOB LANG_TS_SRC "${CMAKE_CURRENT_SOURCE_DIR}/resources/langs/*.ts")
855 qt_add_translations(nheko RESOURCE_PREFIX "/translations" TS_FILES
856 ${LANG_TS_SRC} SOURCES ${QML_SOURCES} ${SRC_FILES})
857
858 if(WIN32)
859 target_compile_definitions(nheko PRIVATE WIN32_LEAN_AND_MEAN)
860 target_link_libraries(nheko PRIVATE Qt6::DBus)
861 if(MSVC)
862 target_compile_options(nheko PUBLIC "/Zc:__cplusplus")
863 endif()
864 else()
865 target_link_libraries(nheko PRIVATE Qt6::DBus)
866 if(FLATPAK)
867 target_compile_definitions(nheko PRIVATE NHEKO_FLATPAK)
868 endif()
869 endif()
870
871 target_include_directories(nheko PRIVATE src includes src/timeline/ src/ui/ src/encryption/ src/voip/)
872
873 if(USE_BUNDLED_CPPHTTPLIB)
874 target_include_directories(nheko PRIVATE third_party/cpp-httplib-0.5.12)
875 target_sources(nheko PRIVATE third_party/cpp-httplib-0.5.12/httplib.h)
876 else()
•877 find_package(PkgConfig REQUIRED)
878 pkg_check_modules(httplib REQUIRED IMPORTED_TARGET cpp-httplib)
879 target_link_libraries(nheko PRIVATE PkgConfig::httplib)
880 endif()
881
882 if(USE_BUNDLED_BLURHASH)
883 target_include_directories(nheko PRIVATE third_party/blurhash)
884 set(BLURHASH_SRC_FILES
885 third_party/blurhash/blurhash.cpp
886 third_party/blurhash/blurhash.hpp
887 )
888 target_sources(nheko PRIVATE ${BLURHASH_SRC_FILES})
889 else()
890 find_package(PkgConfig REQUIRED)
891 pkg_check_modules(blurhash REQUIRED IMPORTED_TARGET blurhash)
892 target_link_libraries(nheko PRIVATE PkgConfig::blurhash)
893 endif()
894
895 # Fixup bundled keychain include dirs
896 if(USE_BUNDLED_QTKEYCHAIN)
897 target_include_directories(nheko PRIVATE ${qt6keychain_SOURCE_DIR} ${qt6keychain_BINARY_DIR})
898 endif()
899 if(USE_BUNDLED_KDSINGLEAPPLICATION)
900 target_include_directories(nheko PRIVATE ${kdsingleapplication_SOURCE_DIR} ${kdsingleapplication_BINARY_DIR})
901 endif()
902
903 if(NOT JSON_ImplicitConversions)
904 set_target_properties(nlohmann_json::nlohmann_json PROPERTIES
905 INTERFACE_COMPILE_DEFINITIONS "JSON_USE_IMPLICIT_CONVERSIONS=\$<BOOL:OFF>;JSON_DIAGNOSTICS=\$<BOOL:OFF>"
906 )
907 target_compile_definitions(nheko PUBLIC JSON_USE_IMPLICIT_CONVERSIONS=0)
908 endif()
909
910 target_link_libraries(nheko PRIVATE
911 ${COEURL_TARGET_NAME}
912 MatrixClient::MatrixClient
913 cmark::cmark
914 fmt::fmt
915 spdlog::spdlog
916 Qt::Widgets
917 Qt::Svg
918 Qt::Gui
919 Qt::Multimedia
920 Qt::Qml
921 Qt::QmlPrivate
922 Qt::QuickControls2
923 qt6keychain
924 KDAB::kdsingleapplication
925 nlohmann_json::nlohmann_json
926 lmdbxx::lmdbxx
927 liblmdb::lmdb)
928
929 if(UNIX)
930 # for wayland activation tokens
931 target_link_libraries(nheko PRIVATE Qt::GuiPrivate)
932 endif()
933
934 if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0")
935 target_precompile_headers(nheko
936 PRIVATE
937 <string>
938 <algorithm>
939 )
940 endif()
941
942 if(TARGET PkgConfig::GSTREAMER)
943 target_link_libraries(nheko PRIVATE PkgConfig::GSTREAMER)
944 target_compile_definitions(nheko PRIVATE GSTREAMER_AVAILABLE)
945 endif()
946 if(TARGET PkgConfig::XCB)
947 target_link_libraries(nheko PRIVATE PkgConfig::XCB)
948 target_compile_definitions(nheko PRIVATE XCB_AVAILABLE)
949 endif()
950
951 if(MSVC)
952 target_link_libraries(nheko PRIVATE ntdll)
953 endif()
954
955 if(HAIKU)
956 target_link_libraries(nheko PRIVATE network)
957 endif()
958
959 if(QML_DEBUGGING)
960 target_compile_definitions(nheko PRIVATE QML_DEBUGGING)
961 endif()
962
963 if(NOT MSVC AND NOT HAIKU)
964 if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug" OR CI_BUILD)
965 target_compile_options(nheko PRIVATE "-Werror")
966 endif()
967 endif()
968 #if(NOT MSVC)
969 # target_link_options(nheko PRIVATE "LINKER:,--gc-sections")
970 #endif()
971
972 if(MAN)
973 add_subdirectory(man)
974 endif()
975
976 # potential workaround for macdeployqt issues
977 if(APPLE)
978 install(TARGETS nheko
979 BUNDLE DESTINATION .
980 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
981 )
982 qt_generate_deploy_qml_app_script(
983 TARGET nheko
984 OUTPUT_SCRIPT deploy_script
985 NO_UNSUPPORTED_PLATFORM_ERROR
986 )
987 install(SCRIPT ${deploy_script})
988 endif()
989
990 if(UNIX AND NOT APPLE)
991 if(FLATPAK)
992 set(APPID "im.nheko.Nheko")
993 set_target_properties(nheko PROPERTIES OUTPUT_NAME "${APPID}")
994 else()
995 set(APPID "nheko")
996 endif()
997
998 install(TARGETS nheko RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
999 install(FILES "resources/nheko-16.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/16x16/apps" RENAME "${APPID}.png")
1000 install(FILES "resources/nheko-32.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/32x32/apps" RENAME "${APPID}.png")
1001 install(FILES "resources/nheko-48.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/48x48/apps" RENAME "${APPID}.png")
1002 install(FILES "resources/nheko-64.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/64x64/apps" RENAME "${APPID}.png")
1003 install(FILES "resources/nheko-128.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/128x128/apps" RENAME "${APPID}.png")
1004 install(FILES "resources/nheko-256.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/256x256/apps" RENAME "${APPID}.png")
1005 install(FILES "resources/nheko-512.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/512x512/apps" RENAME "${APPID}.png")
1006 install(FILES "resources/nheko.svg" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps" RENAME "${APPID}.svg")
1007 install(FILES "resources/_nheko" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/zsh/site-functions")
1008
1009 configure_file("resources/nheko.desktop.in" "resources/nheko.desktop" @ONLY)
1010 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/resources/nheko.desktop" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications" RENAME "${APPID}.desktop")
1011 configure_file("resources/nheko.appdata.xml.in" "resources/nheko.appdata.xml" @ONLY)
1012 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/resources/nheko.appdata.xml" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/metainfo" RENAME "${APPID}.appdata.xml")
1013
1014 if(NOT TARGET uninstall)
1015 configure_file(
1016 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
1017 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
1018 IMMEDIATE @ONLY)
1019 add_custom_target(uninstall
1020 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
1021 endif()
1022 endif()
1023 # vim: tabstop=4 shiftwidth=4 expandtab