Debian Codegraph @

CMakeLists.txt

raw ◀ ▶
Source reconstructed at patch state 2 of 4 — not the installed (fully patched) source.
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 -fdiagnostics-color=always \
300 -Wunreachable-code \
301 -Wno-attributes"
302 )
303 if(NOT CMAKE_COMPILER_IS_GNUCXX)
304 # -Wshadow is buggy and broken in GCC, so do not enable it.
305 # see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79328
306 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
307 endif()
308 endif()
309
310 if(MSVC)
311 set(
312 CMAKE_CXX_FLAGS
313 "${CMAKE_CXX_FLAGS} /bigobj"
314 )
315 endif()
316
317 if(NOT (CMAKE_BUILD_TYPE OR CMAKE_CONFIGURATION_TYPES))
318 set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
319 "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
320 FORCE)
321 message("Setting build type to '${CMAKE_BUILD_TYPE}'")
322 else(NOT (CMAKE_BUILD_TYPE OR CMAKE_CONFIGURATION_TYPES))
323 message("Build type set to '${CMAKE_BUILD_TYPE}'")
324 endif(NOT (CMAKE_BUILD_TYPE OR CMAKE_CONFIGURATION_TYPES))
325
326 set(SPDLOG_DEBUG_ON false)
327
328 # Windows doesn't handle CMAKE_BUILD_TYPE.
329 if(NOT WIN32)
330 if(CMAKE_BUILD_TYPE STREQUAL "Debug")
331 set(SPDLOG_DEBUG_ON true)
332 else()
333 set(SPDLOG_DEBUG_ON false)
334 endif()
335 endif()
336
337 find_program(GIT git)
338 if(GIT)
339 execute_process(
340 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
341 COMMAND ${GIT} rev-parse --short HEAD
342 OUTPUT_VARIABLE GIT_OUT OUTPUT_STRIP_TRAILING_WHITESPACE
343 )
344 if(GIT_OUT)
345 set(CPACK_PACKAGE_VERSION_PATCH "${CPACK_PACKAGE_VERSION_PATCH}-${GIT_OUT}")
346 else()
347 set(CPACK_PACKAGE_VERSION_PATCH "${CPACK_PACKAGE_VERSION_PATCH}")
348 endif()
349 endif(GIT)
350
351 set(CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH})
352 set(PROJECT_VERSION ${CPACK_PACKAGE_VERSION})
353
354 message(STATUS "Version: ${PROJECT_VERSION}")
355
356 cmake_host_system_information(RESULT BUILD_HOST QUERY HOSTNAME)
357
358 include(CheckSymbolExists)
359 check_symbol_exists(backtrace_symbols_fd "execinfo.h" HAVE_BACKTRACE_SYMBOLS_FD)
360
361 configure_file(cmake/nheko.h config/nheko.h)
362
363 #
364 # Declare source and header files.
365 #
366 set(SRC_FILES
367 # Emoji
368 src/emoji/Provider.cpp
369 src/emoji/Provider.h
370 src/emoji/Emoji.cpp
371 src/emoji/Emoji.h
372
373 # Timeline
374 src/timeline/CommunitiesModel.cpp
375 src/timeline/CommunitiesModel.h
376 src/timeline/DelegateChooser.cpp
377 src/timeline/DelegateChooser.h
378 src/timeline/EventStore.cpp
379 src/timeline/EventStore.h
380 src/timeline/EventDelegateChooser.cpp
381 src/timeline/EventDelegateChooser.h
382 src/timeline/InputBar.cpp
383 src/timeline/InputBar.h
384 src/timeline/Permissions.cpp
385 src/timeline/Permissions.h
386 src/timeline/PresenceEmitter.cpp
387 src/timeline/PresenceEmitter.h
388 src/timeline/Reaction.cpp
389 src/timeline/Reaction.h
390 src/timeline/RoomlistModel.cpp
391 src/timeline/RoomlistModel.h
392 src/timeline/TimelineFilter.cpp
393 src/timeline/TimelineFilter.h
394 src/timeline/TimelineModel.cpp
395 src/timeline/TimelineModel.h
396 src/timeline/TimelineViewManager.cpp
397 src/timeline/TimelineViewManager.h
398
399 # UI components
400 src/ui/HiddenEvents.cpp
401 src/ui/HiddenEvents.h
402 src/ui/EventExpiry.cpp
403 src/ui/EventExpiry.h
404 src/ui/MxcAnimatedImage.cpp
405 src/ui/MxcAnimatedImage.h
406 src/ui/MxcMediaProxy.cpp
407 src/ui/MxcMediaProxy.h
408 src/ui/NhekoCursorShape.cpp
409 src/ui/NhekoCursorShape.h
410 src/ui/NhekoDropArea.cpp
411 src/ui/NhekoDropArea.h
412 src/ui/NhekoGlobalObject.cpp
413 src/ui/NhekoGlobalObject.h
414 src/ui/NhekoMenuVisibilityFilter.h
415 src/ui/NhekoMenuVisibilityFilter.cpp
416 src/ui/RoomSettings.cpp
417 src/ui/RoomSettings.h
418 src/ui/RoomSummary.cpp
419 src/ui/RoomSummary.h
420 src/ui/Theme.cpp
421 src/ui/Theme.h
422 src/ui/UIA.cpp
423 src/ui/UIA.h
424 src/ui/UserProfile.cpp
425 src/ui/UserProfile.h
426
427 src/voip/CallDevices.cpp
428 src/voip/CallDevices.h
429 src/voip/CallManager.cpp
430 src/voip/CallManager.h
431 src/voip/ScreenCastPortal.cpp
432 src/voip/ScreenCastPortal.h
433 src/voip/WebRTCSession.h
434 src/voip/WebRTCSession.cpp
435 src/voip/WebRTCSession.h
436
437 src/encryption/DeviceVerificationFlow.cpp
438 src/encryption/DeviceVerificationFlow.h
439 src/encryption/Olm.cpp
440 src/encryption/Olm.h
441 src/encryption/SelfVerificationStatus.cpp
442 src/encryption/SelfVerificationStatus.h
443 src/encryption/VerificationManager.cpp
444 src/encryption/VerificationManager.h
445
446 # Generic notification stuff
447 src/notifications/Manager.cpp
448 src/notifications/Manager.h
449
450 src/dock/Dock.cpp
451 src/dock/Dock.h
452
453 src/AliasEditModel.cpp
454 src/AliasEditModel.h
455 src/AvatarProvider.cpp
456 src/AvatarProvider.h
457 src/BlurhashProvider.cpp
458 src/BlurhashProvider.h
459 src/Cache.cpp
460 src/Cache.h
461 src/CacheCryptoStructs.cpp
462 src/CacheCryptoStructs.h
463 src/CacheStructs.h
464 src/Cache_p.h
465 src/ChatPage.cpp
466 src/ChatPage.h
467 src/Clipboard.cpp
468 src/Clipboard.h
469 src/ColorImageProvider.cpp
470 src/ColorImageProvider.h
471 src/CombinedImagePackModel.cpp
472 src/CombinedImagePackModel.h
473 src/GridImagePackModel.cpp
474 src/GridImagePackModel.h
475 src/CommandCompleter.cpp
476 src/CommandCompleter.h
477 src/CompletionModelRoles.h
478 src/CompletionProxyModel.cpp
479 src/CompletionProxyModel.h
480 src/Config.h
481 src/EventAccessors.cpp
482 src/EventAccessors.h
483 src/FallbackAuth.cpp
484 src/FallbackAuth.h
485 src/ImagePackListModel.cpp
486 src/ImagePackListModel.h
487 src/InviteesModel.cpp
488 src/InviteesModel.h
489 src/JdenticonProvider.cpp
490 src/JdenticonProvider.h
491 src/Logging.cpp
492 src/Logging.h
493 src/LoginPage.cpp
494 src/LoginPage.h
495 src/MainWindow.cpp
496 src/MainWindow.h
497 src/MatrixClient.cpp
498 src/MatrixClient.h
499 src/MemberList.cpp
500 src/MemberList.h
501 src/MxcImageProvider.cpp
502 src/MxcImageProvider.h
503 src/PowerlevelsEditModels.cpp
504 src/PowerlevelsEditModels.h
505 src/ReadReceiptsModel.cpp
506 src/ReadReceiptsModel.h
507 src/ReCaptcha.cpp
508 src/ReCaptcha.h
509 src/RegisterPage.cpp
510 src/RegisterPage.h
511 src/RoomDirectoryModel.cpp
512 src/RoomDirectoryModel.h
513 src/RoomsModel.cpp
514 src/RoomsModel.h
515 src/SSOHandler.cpp
516 src/SSOHandler.h
517 src/SingleImagePackModel.cpp
518 src/SingleImagePackModel.h
519 src/TrayIcon.cpp
520 src/TrayIcon.h
521 src/UserSettingsPage.cpp
522 src/UserSettingsPage.h
523 src/UsersModel.cpp
524 src/UsersModel.h
525 src/Utils.cpp
526 src/Utils.h
527
528 includes/jdenticoninterface.h
529
530 src/main.cpp
531 )
532
533 include(FeatureSummary)
534
535 if(USE_BUNDLED_OPENSSL)
536 hunter_add_package_safe(OpenSSL)
537 endif()
538 find_package(OpenSSL 1.1.0 REQUIRED)
539 if(USE_BUNDLED_OLM)
540 include(FetchContent)
541 FetchContent_Declare(
542 Olm
543 GIT_REPOSITORY https://gitlab.matrix.org/matrix-org/olm.git
544 GIT_TAG 3.2.16
545 PATCH_COMMAND git apply ${CMAKE_CURRENT_SOURCE_DIR}/third_party/olm-patches/0001-fix-list-const-ptr.patch
546 UPDATE_DISCONNECTED 1
547 )
548 set(OLM_TESTS OFF CACHE INTERNAL "")
549 FetchContent_MakeAvailable(Olm)
550 else()
551 find_package(Olm 3.2.7 REQUIRED)
552 set_package_properties(Olm PROPERTIES
553 DESCRIPTION "An implementation of the Double Ratchet cryptographic ratchet"
554 URL "https://git.matrix.org/git/olm/about/"
555 TYPE REQUIRED
556 )
557 endif()
558 if(USE_BUNDLED_SPDLOG)
559 hunter_add_package_safe(spdlog)
560 endif()
561 find_package(spdlog 1.0.0 CONFIG REQUIRED)
562
563 if(USE_BUNDLED_CMARK)
564 include(FetchContent)
565 FetchContent_Declare(
566 cmark
567 GIT_REPOSITORY https://github.com/commonmark/cmark.git
568 GIT_TAG 0.31.1
569 CMAKE_ARGS "BUILD_TESTING=OFF"
570 )
571 FetchContent_MakeAvailable(cmark)
572 if (NOT TARGET cmark::cmark)
573 add_library(cmark::cmark ALIAS cmark)
574 endif()
575 else()
576 find_package(cmark REQUIRED 0.29.0)
577 endif()
578
579 if(USE_BUNDLED_JSON)
580 hunter_add_package_safe(nlohmann_json)
581 endif()
582 find_package(nlohmann_json 3.2.0)
583 set_package_properties(nlohmann_json PROPERTIES
584 DESCRIPTION "JSON for Modern C++, a C++11 header-only JSON class"
585 URL "https://nlohmann.github.io/json/"
586 TYPE REQUIRED
587 )
588
589 if(USE_BUNDLED_LMDBXX)
590 include(FetchContent)
591 FetchContent_Declare(
592 lmdbxx
593 URL "https://raw.githubusercontent.com/hoytech/lmdbxx/1.0.0/lmdb++.h"
594 DOWNLOAD_NO_EXTRACT TRUE
595 CONFIGURE_COMMAND ""
596 BUILD_COMMAND ""
597 )
598 FetchContent_Populate(lmdbxx)
599 add_library(lmdbxx INTERFACE)
600 target_include_directories(lmdbxx INTERFACE ${lmdbxx_SOURCE_DIR})
601 add_library(lmdbxx::lmdbxx ALIAS lmdbxx)
602 else()
603 if(NOT LMDBXX_INCLUDE_DIR)
604 find_path(LMDBXX_INCLUDE_DIR
605 NAMES lmdb++.h
606 PATHS /usr/include
607 /usr/local/include
608 $ENV{LIB_DIR}/include
609 $ENV{LIB_DIR}/include/lmdbxx)
610 endif()
611 add_library(lmdbxx INTERFACE)
612 target_include_directories(lmdbxx INTERFACE ${LMDBXX_INCLUDE_DIR})
613 add_library(lmdbxx::lmdbxx ALIAS lmdbxx)
614 endif()
615
616 if(USE_BUNDLED_MTXCLIENT)
617 include(FetchContent)
618 FetchContent_Declare(
619 MatrixClient
620 GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git
621 GIT_TAG v0.10.1
622 )
623 set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "")
624 set(BUILD_LIB_TESTS OFF CACHE INTERNAL "")
625 FetchContent_MakeAvailable(MatrixClient)
626 else()
627 find_package(MatrixClient 0.10.0 REQUIRED)
628 endif()
629
630 if(VOIP)
631 include(FindPkgConfig)
632 pkg_check_modules(GSTREAMER REQUIRED IMPORTED_TARGET gstreamer-sdp-1.0>=1.18 gstreamer-webrtc-1.0>=1.18 gstreamer-gl-1.0)
633 if (WIN32)
634 pkg_check_modules(GSTREAMER REQUIRED IMPORTED_TARGET gstreamer-d3d11-1.0)
635 endif()
636 endif()
637
638 if(X11 AND NOT WIN32 AND NOT APPLE AND NOT HAIKU)
639 pkg_check_modules(XCB REQUIRED IMPORTED_TARGET xcb xcb-ewmh)
640 endif()
641
642 feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
643
644 # this must be defined here to make the moc work properly
645 if(NOT APPLE AND NOT WIN32)
646 add_compile_definitions(NHEKO_DBUS_SYS)
647 endif()
648
649 #
650 # Bundle resources
651 #
652 qt_add_resources(QRC resources/res.qrc)
653
654 if(APPLE)
655 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework Foundation -framework Cocoa -framework UserNotifications")
656 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)
657 if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0")
658 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)
659 endif()
660 elseif(WIN32)
661 file(DOWNLOAD
662 "https://raw.githubusercontent.com/mohabouje/WinToast/v1.3.0/src/wintoastlib.cpp"
663 ${PROJECT_SOURCE_DIR}/src/wintoastlib.cpp
664 EXPECTED_HASH SHA256=1ddf8ee2604e1757d383a2f60d4d597c4f5d9496369e6a22586cedf4af77ca8f)
665
666 file(DOWNLOAD
667 "https://raw.githubusercontent.com/mohabouje/WinToast/v1.3.0/include/wintoastlib.h"
668 ${PROJECT_SOURCE_DIR}/src/wintoastlib.h
669 EXPECTED_HASH SHA256=08cb30d28db9c851d3d4259ae6108ce7dafa966957df6735a06cd55e0716fded)
670
671 set(SRC_FILES ${SRC_FILES} src/notifications/ManagerWin.cpp src/wintoastlib.cpp src/wintoastlib.h)
672 else()
673 set(SRC_FILES ${SRC_FILES}
674 src/dbus/NhekoDBusApi.h
675 src/dbus/NhekoDBusBackend.h
676 src/dbus/NhekoDBusApi.cpp
677 src/dbus/NhekoDBusBackend.cpp
678 src/notifications/ManagerLinux.cpp
679 )
680 endif()
681
682 set(NHEKO_DEPS
683 ${SRC_FILES}
684 ${QRC}
685 ${META_FILES_TO_INCLUDE})
686
687 if(ASAN)
688 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address,undefined")
689 endif()
690
691 if(WIN32)
692 qt_add_executable(nheko WIN32 ${OS_BUNDLE} ${NHEKO_DEPS})
693 target_compile_definitions(nheko PRIVATE _WIN32_WINNT=0x0601 NOMINMAX WIN32_LEAN_AND_MEAN STRICT)
694 else()
695 qt_add_executable(nheko ${OS_BUNDLE} ${NHEKO_DEPS})
696
697 if(APPLE)
698 set_target_properties(nheko PROPERTIES MACOSX_BUNDLE_INFO_PLIST
699 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/MacOSXBundleInfo.plist.in")
700 endif()
701
702 if(HAVE_BACKTRACE_SYMBOLS_FD AND NOT CMAKE_BUILD_TYPE STREQUAL "Release")
703 set_target_properties(nheko PROPERTIES ENABLE_EXPORTS ON)
704 endif()
705 endif()
706
707 set_target_properties(nheko
708 PROPERTIES
709 CMAKE_SKIP_INSTALL_RPATH TRUE
710 AUTOMOC ON)
711
712 #
713 # Add qml files
714 #
715 if(QT_KNOWN_POLICY_QTP0004)
716 qt_policy(SET QTP0004 NEW)
717 endif()
718 set(QML_SOURCES
719 resources/qml/Root.qml
720 resources/qml/ChatPage.qml
721 resources/qml/CommunitiesList.qml
722 resources/qml/RoomList.qml
723 resources/qml/Avatar.qml
724 resources/qml/Completer.qml
725 resources/qml/EncryptionIndicator.qml
726 resources/qml/ImageButton.qml
727 resources/qml/ElidedLabel.qml
728 resources/qml/MatrixText.qml
729 resources/qml/MatrixTextField.qml
730 resources/qml/ToggleButton.qml
731 resources/qml/UploadBox.qml
732 resources/qml/MessageInput.qml
733 resources/qml/MessageView.qml
734 resources/qml/PrivacyScreen.qml
735 resources/qml/Reactions.qml
736 resources/qml/ReplyPopup.qml
737 resources/qml/StatusIndicator.qml
738 resources/qml/TimelineEvent.qml
739 resources/qml/TimelineSectionHeader.qml
740 resources/qml/TimelineDefaultMessageStyle.qml
741 resources/qml/TimelineBubbleMessageStyle.qml
742 resources/qml/TimelineMetadata.qml
743 resources/qml/TimelineView.qml
744 resources/qml/TopBar.qml
745 resources/qml/QuickSwitcher.qml
746 resources/qml/ForwardCompleter.qml
747 resources/qml/SelfVerificationCheck.qml
748 resources/qml/TypingIndicator.qml
749 resources/qml/MessageInputWarning.qml
750 resources/qml/components/AdaptiveLayout.qml
751 resources/qml/components/AdaptiveLayoutElement.qml
752 resources/qml/components/AvatarListTile.qml
753 resources/qml/components/FlatButton.qml
754 resources/qml/components/MainWindowDialog.qml
755 resources/qml/components/NhekoTabButton.qml
756 resources/qml/components/NotificationBubble.qml
757 resources/qml/components/PowerlevelIndicator.qml
758 resources/qml/components/ReorderableListview.qml
759 resources/qml/components/SpaceMenu.qml
760 resources/qml/components/SpaceMenuLevel.qml
761 resources/qml/components/TextButton.qml
762 resources/qml/components/UserListRow.qml
763 resources/qml/delegates/Encrypted.qml
764 resources/qml/delegates/FileMessage.qml
765 resources/qml/delegates/ImageMessage.qml
766 resources/qml/delegates/NoticeMessage.qml
767 resources/qml/delegates/Pill.qml
768 resources/qml/delegates/Placeholder.qml
769 resources/qml/delegates/PlayableMediaMessage.qml
770 resources/qml/delegates/Redacted.qml
771 resources/qml/delegates/Reply.qml
772 resources/qml/delegates/TextMessage.qml
773 resources/qml/device-verification/DeviceVerification.qml
774 resources/qml/device-verification/DigitVerification.qml
775 resources/qml/device-verification/EmojiVerification.qml
776 resources/qml/device-verification/Failed.qml
777 resources/qml/device-verification/NewVerificationRequest.qml
778 resources/qml/device-verification/Success.qml
779 resources/qml/device-verification/Waiting.qml
780 resources/qml/dialogs/AliasEditor.qml
781 resources/qml/dialogs/ConfirmJoinRoomDialog.qml
782 resources/qml/dialogs/CreateDirect.qml
783 resources/qml/dialogs/CreateRoom.qml
784 resources/qml/dialogs/FallbackAuthDialog.qml
785 resources/qml/dialogs/HiddenEventsDialog.qml
786 resources/qml/dialogs/EventExpirationDialog.qml
787 resources/qml/dialogs/ImageOverlay.qml
788 resources/qml/dialogs/ImagePackEditorDialog.qml
789 resources/qml/dialogs/ImagePackDeleteDialog.qml
790 resources/qml/dialogs/ImagePackSettingsDialog.qml
791 resources/qml/dialogs/InputDialog.qml
792 resources/qml/dialogs/InviteDialog.qml
793 resources/qml/dialogs/JoinRoomDialog.qml
794 resources/qml/dialogs/LeaveRoomDialog.qml
795 resources/qml/dialogs/LogoutDialog.qml
796 resources/qml/dialogs/PhoneNumberInputDialog.qml
797 resources/qml/dialogs/PowerLevelEditor.qml
798 resources/qml/dialogs/PowerLevelSpacesApplyDialog.qml
799 resources/qml/dialogs/RawMessageDialog.qml
800 resources/qml/dialogs/ReadReceipts.qml
801 resources/qml/dialogs/ReCaptchaDialog.qml
802 resources/qml/dialogs/ReportMessage.qml
803 resources/qml/dialogs/RoomDirectory.qml
804 resources/qml/dialogs/RoomMembers.qml
805 resources/qml/dialogs/AllowedRoomsSettingsDialog.qml
806 resources/qml/dialogs/RoomSettingsDialog.qml
807 resources/qml/dialogs/UserProfile.qml
808 resources/qml/dialogs/IgnoredUsers.qml
809 resources/qml/emoji/StickerPicker.qml
810 resources/qml/pages/LoginPage.qml
811 resources/qml/pages/RegisterPage.qml
812 resources/qml/pages/UserSettingsPage.qml
813 resources/qml/pages/WelcomePage.qml
814 resources/qml/ui/NhekoSlider.qml
815 resources/qml/ui/Ripple.qml
816 resources/qml/ui/Snackbar.qml
817 resources/qml/ui/Spinner.qml
818 resources/qml/ui/animations/BlinkAnimation.qml
819 resources/qml/ui/media/MediaControls.qml
820 resources/qml/voip/ActiveCallBar.qml
821 resources/qml/voip/CallDevices.qml
822 resources/qml/voip/CallInvite.qml
823 resources/qml/voip/CallInviteBar.qml
824 resources/qml/voip/DeviceError.qml
825 resources/qml/voip/PlaceCall.qml
826 resources/qml/voip/ScreenShare.qml
827 resources/qml/voip/VideoCall.qml
828 resources/qml/voip/VideoCallD3D11.qml
829 resources/qml/delegates/EncryptionEnabled.qml
830 resources/qml/ui/TimelineEffects.qml
831 )
832 qt_add_qml_module(nheko
833 URI im.nheko
834 NO_RESOURCE_TARGET_PATH
835 RESOURCE_PREFIX "/"
836 VERSION 1.1
837 DEPENDENCIES QtQuick QtQml.Models
838 QML_FILES
839 ${QML_SOURCES}
840 SOURCES
841 src/UserDirectoryModel.cpp
842 src/UserDirectoryModel.h
843 )
844 #qt_target_qml_sources(nheko
845 # #PREFIX "/"
846 #)
847
848 #set_target_properties(nheko PROPERTIES
849 # QT_QMLCACHEGEN_ARGUMENTS "--verbose"
850 #)
851
852 #
853 # Bundle translations
854 #
855 file(GLOB LANG_TS_SRC "${CMAKE_CURRENT_SOURCE_DIR}/resources/langs/*.ts")
856 qt_add_translations(nheko RESOURCE_PREFIX "/translations" TS_FILES
857 ${LANG_TS_SRC} SOURCES ${QML_SOURCES} ${SRC_FILES})
858
859 if(WIN32)
860 target_compile_definitions(nheko PRIVATE WIN32_LEAN_AND_MEAN)
861 target_link_libraries(nheko PRIVATE Qt6::DBus)
862 if(MSVC)
863 target_compile_options(nheko PUBLIC "/Zc:__cplusplus")
864 endif()
865 else()
866 target_link_libraries(nheko PRIVATE Qt6::DBus)
867 if(FLATPAK)
868 target_compile_definitions(nheko PRIVATE NHEKO_FLATPAK)
869 endif()
870 endif()
871
872 target_include_directories(nheko PRIVATE src includes src/timeline/ src/ui/ src/encryption/ src/voip/)
873
874 if(USE_BUNDLED_CPPHTTPLIB)
875 target_include_directories(nheko PRIVATE third_party/cpp-httplib-0.5.12)
876 target_sources(nheko PRIVATE third_party/cpp-httplib-0.5.12/httplib.h)
877 else()
878 find_package(httplib REQUIRED)
879 target_link_libraries(nheko PRIVATE httplib::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