-
Notifications
You must be signed in to change notification settings - Fork 108
/
CMakeLists.txt
313 lines (281 loc) · 11.9 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
CMAKE_MINIMUM_REQUIRED(VERSION 3.16)
if (POLICY CMP0092)
cmake_policy(SET CMP0092 NEW)
endif()
set(IDENTIFIER "io.github.quotient_im.Quaternion")
set(COPYRIGHT "Copyright © 2015-2024 The Quaternion contributors")
project(quaternion VERSION 0.0.96.81 LANGUAGES CXX)
if(UNIX AND NOT APPLE)
set(LINUX 1)
endif(UNIX AND NOT APPLE)
include(CheckCXXCompilerFlag)
if (WIN32)
if (NOT CMAKE_INSTALL_BINDIR)
set(CMAKE_INSTALL_BINDIR ".")
endif()
else()
include(GNUInstallDirs)
include(cmake/ECMInstallIcons.cmake)
endif(WIN32)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Debug' as none was specified")
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build" FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()
# Setup command line parameters for the compiler and linker
if (MSVC)
add_compile_options(/EHsc /W4
/wd4100 /wd4127 /wd4242 /wd4244 /wd4245 /wd4267 /wd4365 /wd4456 /wd4459
/wd4464 /wd4505 /wd4514 /wd4571 /wd4619 /wd4623 /wd4625 /wd4626 /wd4706
/wd4710 /wd4774 /wd4820 /wd4946 /wd5026 /wd5027)
else()
foreach (FLAG all pedantic extra error=return-void) # Switch these on
CHECK_CXX_COMPILER_FLAG("-W${FLAG}" W${FLAG}_SUPPORTED)
mark_as_advanced(W${FLAG}_SUPPORTED)
if (W${FLAG}_SUPPORTED AND NOT CMAKE_CXX_FLAGS MATCHES "W(no-)?${FLAG}($| )")
add_compile_options(-W${FLAG})
endif ()
endforeach ()
foreach (FLAG unused-parameter subobject-linkage) # Switch these off
CHECK_CXX_COMPILER_FLAG("-Wno-${FLAG}" Wno-${FLAG}_SUPPORTED)
mark_as_advanced(Wno-${FLAG}_SUPPORTED)
if (Wno-${FLAG}_SUPPORTED AND NOT CMAKE_CXX_FLAGS MATCHES "W(no-)?${FLAG}($| )")
add_compile_options(-Wno-${FLAG})
endif ()
endforeach ()
endif()
set(QtMinVersion "6.4")
set(QUOTIENT "QuotientQt6")
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15")
string(REGEX REPLACE "^(.).*" "Qt\\1" Qt ${QtMinVersion}) # makes "Qt<MajorVersionDigit>"
# Find the libraries
find_package(${Qt} ${QtMinVersion} REQUIRED
Widgets Network Quick Gui Multimedia QuickControls2 QuickWidgets
LinguistTools)
# ${Qt}_Prefix is only used to show Qt path in message()
# ${Qt}_BinDir is where all the *deployqt tools reside
if (QT_QMAKE_EXECUTABLE)
get_filename_component(${Qt}_BinDir "${QT_QMAKE_EXECUTABLE}" DIRECTORY)
get_filename_component(${Qt}_Prefix "${${Qt}_BinDir}/.." ABSOLUTE)
else()
get_filename_component(${Qt}_BinDir "${${Qt}_DIR}/../../../bin" ABSOLUTE)
get_filename_component(${Qt}_Prefix "${${Qt}_DIR}/../../../.." ABSOLUTE)
endif()
if(WIN32)
enable_language(RC)
include(CMakeDetermineRCCompiler)
if(MINGW)
set(CMAKE_RC_COMPILER_INIT windres)
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -I${CMAKE_CURRENT_BINARY_DIR} -i <SOURCE> -o <OBJECT>")
endif()
endif()
set(QUOTIENT_FORCE_NAMESPACED_INCLUDES 1)
if ((NOT DEFINED USE_INTREE_LIBQMC OR USE_INTREE_LIBQMC)
AND EXISTS ${PROJECT_SOURCE_DIR}/lib/Quotient/util.h)
add_subdirectory(lib)
if (NOT DEFINED USE_INTREE_LIBQMC)
set (USE_INTREE_LIBQMC 1)
endif ()
endif ()
if (NOT USE_INTREE_LIBQMC)
find_package(${QUOTIENT} 0.9 REQUIRED)
if (NOT ${QUOTIENT}_FOUND)
message(WARNING "libQuotient not found; configuration will most likely fail.")
message(WARNING "Make sure you have installed libQuotient development files")
message(WARNING "as a package or checked out the library sources in lib/.")
message(WARNING "See also BUILDING.md")
endif ()
endif ()
message(STATUS)
message(STATUS "== Quaternion ${quaternion_VERSION} configuration summary ==")
message(STATUS)
if (CMAKE_BUILD_TYPE)
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
endif(CMAKE_BUILD_TYPE)
message(STATUS "Quaternion install prefix: ${CMAKE_INSTALL_PREFIX}")
# Get Git info if possible
find_package(Git)
if(GIT_FOUND)
execute_process(COMMAND
"${GIT_EXECUTABLE}" rev-parse -q HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_SHA1
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "Git SHA1: ${GIT_SHA1}")
endif()
message(STATUS "Using compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
message(STATUS "Using Qt ${${Qt}_VERSION} at ${${Qt}_Prefix}")
if (USE_INTREE_LIBQMC)
message(STATUS "Using in-tree libQuotient")
if (GIT_FOUND)
execute_process(COMMAND
"${GIT_EXECUTABLE}" rev-parse -q HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib
OUTPUT_VARIABLE LIB_GIT_SHA1
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS " Library git SHA1: ${LIB_GIT_SHA1}")
endif (GIT_FOUND)
else ()
message(STATUS "Using libQuotient ${${QUOTIENT}_VERSION} at ${${QUOTIENT}_DIR}")
endif ()
message(STATUS)
# Windows, this is a GUI executable; OSX, make a bundle
add_executable(${PROJECT_NAME} WIN32 MACOSX_BUNDLE)
# Set up source files
target_sources(${PROJECT_NAME} PRIVATE
client/quaternionroom.cpp client/quaternionroom.h
client/htmlfilter.cpp client/htmlfilter.h
client/thumbnailprovider.cpp client/thumbnailprovider.h
client/activitydetector.cpp client/activitydetector.h
client/dialog.cpp client/dialog.h
client/logindialog.cpp client/logindialog.h
client/networkconfigdialog.cpp client/networkconfigdialog.h
client/roomdialogs.cpp client/roomdialogs.h
client/dockmodemenu.cpp client/dockmodemenu.h
client/mainwindow.cpp client/mainwindow.h
client/roomlistdock.cpp client/roomlistdock.h
client/userlistdock.cpp client/userlistdock.h
client/accountselector.cpp client/accountselector.h
client/kchatedit.cpp client/kchatedit.h
client/chatedit.cpp client/chatedit.h
client/timelinewidget.cpp client/timelinewidget.h
client/chatroomwidget.cpp client/chatroomwidget.h
client/systemtrayicon.cpp client/systemtrayicon.h
client/profiledialog.cpp client/profiledialog.h
client/models/messageeventmodel.cpp client/models/messageeventmodel.h
client/models/userlistmodel.cpp client/models/userlistmodel.h
client/models/roomlistmodel.cpp client/models/roomlistmodel.h
client/models/abstractroomordering.cpp client/models/abstractroomordering.h
client/models/orderbytag.cpp client/models/orderbytag.h
client/desktop_integration.h client/logging_categories.h
client/main.cpp
client/resources.qrc
)
# quaternion_en.ts is updated explicitly by building trbase target,
# while all other translation files are created and updated externally at
# Lokalise.co
set(quaternion_en_TS client/translations/quaternion_en.ts)
QT_CREATE_TRANSLATION(quaternion_QM ${quaternion_en_TS}
client/ client/qml/ OPTIONS -no-obsolete)
add_custom_target(trbase DEPENDS ${quaternion_en_TS})
QT_ADD_TRANSLATION(quaternion_QM
client/translations/quaternion_en_GB.ts
client/translations/quaternion_de.ts
client/translations/quaternion_pl.ts
client/translations/quaternion_ru.ts
client/translations/quaternion_es.ts
)
target_sources(${PROJECT_NAME} PRIVATE ${quaternion_QM})
if(WIN32)
set(quaternion_WINRC quaternion_win32.rc)
set_property(SOURCE ${quaternion_WINRC} APPEND PROPERTY
OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/icons/quaternion.ico
)
target_sources(${PROJECT_NAME} PRIVATE ${quaternion_WINRC})
endif()
if(APPLE)
MESSAGE(STATUS "CMAKE_OSX_DEPLOYMENT_TARGET: " ${CMAKE_OSX_DEPLOYMENT_TARGET})
set(MACOSX_BUNDLE_GUI_IDENTIFIER ${IDENTIFIER})
set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
set(MACOSX_BUNDLE_COPYRIGHT ${COPYRIGHT})
set(MACOSX_BUNDLE_SHORT_VERSION_STRING ${quaternion_VERSION})
set(MACOSX_BUNDLE_BUNDLE_VERSION ${quaternion_VERSION})
set(ICON_NAME "quaternion.icns")
set(${PROJECT_NAME}_MAC_ICON "${PROJECT_SOURCE_DIR}/icons/${ICON_NAME}")
set(MACOSX_BUNDLE_ICON_FILE ${ICON_NAME})
set_property(SOURCE "${${PROJECT_NAME}_MAC_ICON}" PROPERTY
MACOSX_PACKAGE_LOCATION Resources)
target_sources(${PROJECT_NAME} PRIVATE ${${PROJECT_NAME}_MAC_ICON})
endif(APPLE)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_23)
target_compile_definitions(${PROJECT_NAME} PRIVATE
GIT_SHA1="${GIT_SHA1}" LIB_GIT_SHA1="${LIB_GIT_SHA1}")
target_compile_definitions(${PROJECT_NAME} PRIVATE QT_NO_JAVA_STYLE_ITERATORS)
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL GNU) # https://bugzilla.redhat.com/show_bug.cgi?id=1721553
target_precompile_headers(${PROJECT_NAME} PRIVATE <Quotient/room.h>)
endif ()
target_link_libraries(${PROJECT_NAME} ${QUOTIENT}
${Qt}::Widgets ${Qt}::Quick ${Qt}::Qml ${Qt}::Gui ${Qt}::Network ${Qt}::QuickControls2 ${Qt}::QuickWidgets)
set_target_properties(${PROJECT_NAME} PROPERTIES
CXX_STANDARD 23
CXX_EXTENSIONS OFF
VISIBILITY_INLINES_HIDDEN ON
CXX_VISIBILITY_PRESET hidden
)
# macOS specific config for bundling
if (APPLE)
set_property(TARGET ${PROJECT_NAME} PROPERTY MACOSX_BUNDLE_INFO_PLIST
"${PROJECT_SOURCE_DIR}/cmake/MacOSXBundleInfo.plist.in")
endif()
# Installation
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
BUNDLE DESTINATION .
)
if(LINUX)
install(FILES linux/${IDENTIFIER}.desktop
DESTINATION ${CMAKE_INSTALL_DATADIR}/applications
)
install(FILES linux/${IDENTIFIER}.appdata.xml
DESTINATION ${CMAKE_INSTALL_DATADIR}/metainfo
)
install(FILES ${quaternion_QM}
DESTINATION ${CMAKE_INSTALL_DATADIR}/Quotient/quaternion/translations
)
file(GLOB quaternion_icons icons/quaternion/*-apps-quaternion.png)
ecm_install_icons(ICONS ${quaternion_icons} icons/quaternion/sources/sc-apps-quaternion.svg
DESTINATION ${CMAKE_INSTALL_DATADIR}/icons
)
endif(LINUX)
set(QML_DIR ${PROJECT_SOURCE_DIR}/client/qml)
if (NOT DEPLOY_VERBOSITY)
set(DEPLOY_VERBOSITY 1) # The default for *deployqt tools, out of 0..3
endif()
if(WIN32)
install(CODE "
message(STATUS \"Running windeployqt at \${CMAKE_INSTALL_PREFIX}\${CMAKE_INSTALL_BINDIR}\")
execute_process(
COMMAND \"${${Qt}_BinDir}/windeployqt\" --verbose ${DEPLOY_VERBOSITY}
--no-multimediaquick --no-test --qmldir \"${QML_DIR}\"
\${CMAKE_INSTALL_PREFIX}\${CMAKE_INSTALL_BINDIR}
RESULT_VARIABLE WDQ_RETVAL
)
if (WDQ_RETVAL)
message(FATAL_ERROR \"windeployqt returned \${WDQ_RETVAL} - check messages above\")
else()
message(STATUS \"Quaternion and its dependencies have been deployed to \${CMAKE_INSTALL_PREFIX}.\")
endif()
")
install(FILES ${quaternion_QM}
DESTINATION ${CMAKE_INSTALL_BINDIR}/translations
)
endif(WIN32)
# Packaging
if(APPLE)
execute_process(
COMMAND "${${Qt}_BinDir}/qmake" -query QT_INSTALL_TRANSLATIONS
OUTPUT_VARIABLE _qt_translations_dir
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ERROR_IS_FATAL ANY
)
set(MACDEPLOYQT_ARGS ${PROJECT_NAME}.app -dmg -qmldir="${QML_DIR}" -verbose=${DEPLOY_VERBOSITY})
add_custom_target(image
COMMAND mkdir ${PROJECT_NAME}.app/Contents/Translations
COMMAND install "${_qt_translations_dir}/qtbase_*.qm"
"${_qt_translations_dir}/qtdeclarative_*.qm"
"${_qt_translations_dir}/qtmultimedia_*.qm"
${PROJECT_NAME}.app/Contents/Translations
COMMAND "${${Qt}_BinDir}/macdeployqt" ${MACDEPLOYQT_ARGS}
DEPENDS ${PROJECT_NAME}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMENT "Running ${MACDEPLOYQT} with args: ${MACDEPLOYQT_ARGS}"
)
endif(APPLE)