CMakeLists.txt 11.9 KB
Newer Older
1
cmake_minimum_required(VERSION 3.3)
2
find_package(ECM 5.40.0 REQUIRED NO_MODULE)
3
set(CMAKE_CXX_STANDARD 14)
Linus Jahn's avatar
Linus Jahn committed
4
set(QT_MIN_VERSION "5.10.0")
Linus Jahn's avatar
Linus Jahn committed
5

Jonah Brüchert's avatar
Jonah Brüchert committed
6 7 8 9
if(POLICY CMP0071)
	cmake_policy(SET CMP0071 NEW)
endif()

Linus Jahn's avatar
Linus Jahn committed
10 11
project(kaidan)

12
set(APPLICATION_ID "im.kaidan.kaidan")
13 14 15 16 17
set(APPLICATION_NAME "kaidan")
set(APPLICATION_DISPLAY_NAME "Kaidan")
if(UBUNTU_TOUCH)
	set(APPLICATION_NAME "${APPLICATION_ID}")
endif()
Linus Jahn's avatar
Linus Jahn committed
18 19
set(VERSION_STRING "0.5.0-dev")
set(DEVELOPMENT_BUILD TRUE)
20
set(APPLICATION_VERSION_CODE 6)
21

22 23
# CMake options
option(I18N "Enable i18n support" FALSE)
Ilya Bizyaev's avatar
Ilya Bizyaev committed
24
option(STATIC_BUILD "Build Kaidan statically")
25
option(APPIMAGE "Build Kaidan as AppImage (will only work in the appimage script)" FALSE)
Melvin Keskin's avatar
Melvin Keskin committed
26
option(UBUNTU_TOUCH "Building an Ubuntu Touch click (internal use only!)" FALSE)
27
option(CLICK_ARCH "Architecture that will be used in the click's manifest")
28
option(CLICK_DATE "Date used in the version number in the click's manifest")
29
option(QUICK_COMPILER "Use QtQuick compiler to improve performance" FALSE)
30
option(USE_KNOTIFICATIONS "Use KNotifications for displaying notifications" TRUE)
31
option(BUNDLE_ICONS "Bundle breeze icons" FALSE)
Linus Jahn's avatar
Linus Jahn committed
32 33 34 35 36 37 38 39

# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)

# Instruct CMake to run moc, uic and rcc automatically when needed.
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
40
set(AUTOMOC_MOC_OPTIONS -Muri=${APPLICATION_ID})
Linus Jahn's avatar
Linus Jahn committed
41

42 43 44 45
#
# Dependecies
#

Linus Jahn's avatar
Linus Jahn committed
46
# CMake module path
Ilya Bizyaev's avatar
Ilya Bizyaev committed
47
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
48 49 50 51 52 53 54 55

# CMake modules include
include(KDEInstallDirs)
include(KDECompilerSettings NO_POLICY_SCOPE)
include(KDECMakeSettings)
include(ECMInstallIcons)
include(FeatureSummary)
kde_enable_exceptions()
Linus Jahn's avatar
Linus Jahn committed
56 57

# Find packages
Filipe Azevedo's avatar
Filipe Azevedo committed
58
find_package(Qt5 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS Core Qml Quick Svg Sql QuickControls2 Xml Multimedia Positioning Location)
Linus Jahn's avatar
Linus Jahn committed
59
find_package(KF5Kirigami2 REQUIRED)
Linus Jahn's avatar
Linus Jahn committed
60
find_package(ZXing REQUIRED COMPONENTS Core)
61
find_package(QXmpp 1.0.0 REQUIRED)
Ilya Bizyaev's avatar
Ilya Bizyaev committed
62

Jonah Brüchert's avatar
Jonah Brüchert committed
63
# Optional QtQuickCompiler
64 65 66 67
if(QUICK_COMPILER)
	find_package(Qt5QuickCompiler)
	set_package_properties(Qt5QuickCompiler PROPERTIES
		DESCRIPTION "Compile QML at build time"
68
		TYPE OPTIONAL
69 70
	)
endif()
Jonah Brüchert's avatar
Jonah Brüchert committed
71

72 73 74 75 76 77
if(USE_KNOTIFICATIONS)
	find_package(KF5Notifications REQUIRED)
	set(__KF5Notifications_LIBRARIES KF5::Notifications)
	add_definitions(-DHAVE_KNOTIFICATIONS)
endif()

Ilya Bizyaev's avatar
Ilya Bizyaev committed
78
# Optional QWidget style integration (not on mobile)
79
if(NOT UBUNTU_TOUCH AND NOT ANDROID AND NOT IOS)
80 81 82 83 84
	find_package(Qt5Widgets)
	set_package_properties(Qt5Widgets PROPERTIES
		DESCRIPTION "Integration with QWidget based desktop styles"
		TYPE OPTIONAL
	)
85 86
endif()

Ilya Bizyaev's avatar
Ilya Bizyaev committed
87
# Platform-specific
88 89 90 91 92 93 94
if(Qt5Widgets_FOUND)
	add_definitions(-DHAVE_QWIDGETS -DQAPPLICATION_CLASS=QApplication)
	set(__Qt5Widgets_LIBRARIES Qt5::Widgets)
else()
	add_definitions(-DQAPPLICATION_CLASS=QGuiApplication)
endif()

95
if(ANDROID)
96
	find_package(Qt5 REQUIRED COMPONENTS AndroidExtras)
Ilya Bizyaev's avatar
Ilya Bizyaev committed
97 98
endif()

99
if(ANDROID OR WIN32)
100
	find_package(PkgConfig REQUIRED)
101
	pkg_search_module(OPENSSL REQUIRED openssl IMPORTED_TARGET)
Ilya Bizyaev's avatar
Ilya Bizyaev committed
102
	message(STATUS "Using OpenSSL ${OPENSSL_VERSION}")
103 104
endif()

105

106
#
107
# Load submodules
108 109
#

110 111 112 113
# Main kaidan sources
include("${CMAKE_SOURCE_DIR}/src/CMakeLists.txt")

# I18n support
114 115 116
if(I18N)
	include("${CMAKE_SOURCE_DIR}/i18n/CMakeLists.txt")
endif()
117

118

119 120 121
#
# Sources / Resources
#
Linus Jahn's avatar
Linus Jahn committed
122

Ilya Bizyaev's avatar
Ilya Bizyaev committed
123
# Include bundled icons on Ubuntu Touch, Android, Windows, macOS and iOS
124
if(BUNDLE_ICONS OR UBUNTU_TOUCH OR ANDROID OR WIN32 OR APPLE)
125 126 127
	set(KAIDAN_ICONS_QRC kirigami-icons.qrc)
endif()

Ilya Bizyaev's avatar
Ilya Bizyaev committed
128 129
# Bundle images on Android, Windows, macOS and iOS
if(ANDROID OR WIN32 OR APPLE)
130 131 132
	set(KAIDAN_IMAGES_QRC "data/images/images.qrc")
endif()

Ilya Bizyaev's avatar
Ilya Bizyaev committed
133 134 135
# Set app icon
if(APPLE)
	set(KAIDAN_ICNS "${CMAKE_SOURCE_DIR}/misc/macos/kaidan.icns")
136
	set_source_files_properties(${KAIDAN_ICNS} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
Ilya Bizyaev's avatar
Ilya Bizyaev committed
137 138 139 140 141 142 143 144
elseif(WIN32)
	include(ECMAddAppIcon)
	file(GLOB WIN_ICONS_SRCS "${CMAKE_SOURCE_DIR}/misc/windows/*kaidan.png")
	message(STATUS ${WIN_ICONS_SRCS})
	ecm_add_app_icon(KAIDAN_ICNS ICONS ${WIN_ICONS_SRCS})
	message(STATUS ${KAIDAN_ICNS})
endif()

145
if(QUICK_COMPILER)
146
	qtquick_compiler_add_resources(KAIDAN_QML_QRC src/qml/qml.qrc)
Jonah Brüchert's avatar
Jonah Brüchert committed
147
else()
148
	qt5_add_resources(KAIDAN_QML_QRC src/qml/qml.qrc)
Jonah Brüchert's avatar
Jonah Brüchert committed
149 150
endif()

Linus Jahn's avatar
Linus Jahn committed
151
add_executable(${PROJECT_NAME}
Ilya Bizyaev's avatar
Ilya Bizyaev committed
152 153 154
	MACOSX_BUNDLE
	WIN32
	${KAIDAN_ICNS}
155
	${KAIDAN_SOURCES}
Jonah Brüchert's avatar
Jonah Brüchert committed
156
	${KAIDAN_QML_QRC}
157 158 159
	${KAIDAN_ICONS_QRC}  # only set if enabled
	${KAIDAN_IMAGES_QRC} #
	${I18N_QRC_CPP}      #
Linus Jahn's avatar
Linus Jahn committed
160 161 162 163
)

target_link_libraries(${PROJECT_NAME}
	Qt5::Core
164
	Qt5::Sql
Linus Jahn's avatar
Linus Jahn committed
165 166
	Qt5::Qml
	Qt5::Quick
167
	Qt5::Svg
Ilya Bizyaev's avatar
Ilya Bizyaev committed
168
	Qt5::Network
Linus Jahn's avatar
Linus Jahn committed
169
	Qt5::Xml
Linus Jahn's avatar
Linus Jahn committed
170
	Qt5::Multimedia
Filipe Azevedo's avatar
Filipe Azevedo committed
171 172
	Qt5::Positioning
	Qt5::Location
Linus Jahn's avatar
Linus Jahn committed
173
	ZXing::Core
174
	QXmpp::QXmpp
175
	${__Qt5Widgets_LIBRARIES}
176
	${__KF5Notifications_LIBRARIES}
Linus Jahn's avatar
Linus Jahn committed
177
)
178

179 180
if(ANDROID OR WIN32 OR IOS)
	target_link_libraries(${PROJECT_NAME} Qt5::QuickControls2 KF5::Kirigami2)
Ilya Bizyaev's avatar
Ilya Bizyaev committed
181 182
endif()

183 184 185 186 187
if(ANDROID OR WIN32)
	target_link_libraries(${PROJECT_NAME} PkgConfig::OPENSSL)
endif()

if(ANDROID)
Ilya Bizyaev's avatar
Ilya Bizyaev committed
188
	target_link_libraries(${PROJECT_NAME} Qt5::AndroidExtras)
189
endif()
190

191
if(STATIC_BUILD)
192
	add_definitions(-DQXMPP_BUILD)
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

	find_package(Perl REQUIRED)

	set(STATIC_DEPENDENCIES_CMAKE_FILE "${CMAKE_BINARY_DIR}/QtStaticDependencies.cmake")
	if(EXISTS ${STATIC_DEPENDENCIES_CMAKE_FILE})
		file(REMOVE ${STATIC_DEPENDENCIES_CMAKE_FILE})
	endif()

	get_target_property(QT_LIBDIR Qt5::Core LOCATION)
	get_filename_component(QT_LIBDIR ${QT_LIBDIR} DIRECTORY)

	macro(CONVERT_PRL_LIBS_TO_CMAKE _qt_component)
		if(TARGET Qt5::${_qt_component})
			get_target_property(_lib_location Qt5::${_qt_component} LOCATION)
			execute_process(COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/utils/convert-prl-libs-to-cmake.pl
				--lib ${_lib_location}
				--libdir ${QT_LIBDIR}
				--out ${STATIC_DEPENDENCIES_CMAKE_FILE}
				--component ${_qt_component}
				--compiler ${CMAKE_CXX_COMPILER_ID}
			)
		endif()
	endmacro()

	link_directories(${_qt5_install_prefix}/../)

	foreach(qt_module Gui Quick QuickControls2 Network Qml Svg Sql QSQLiteDriverPlugin
             QJpegPlugin QGifPlugin QSvgPlugin QSvgIconPlugin QICOPlugin QGenericEnginePlugin
	         QLocalClientConnectionFactory QTcpServerConnectionFactory)
		CONVERT_PRL_LIBS_TO_CMAKE(${qt_module})
Ilya Bizyaev's avatar
Ilya Bizyaev committed
223
	endforeach()
224 225 226 227 228 229 230 231 232 233 234 235 236 237

	if(WIN32)
		CONVERT_PRL_LIBS_TO_CMAKE(QWindowsIntegrationPlugin)
	elseif(IOS)
		foreach(qt_module QIOSIntegrationPlugin QMacHeifPlugin QMacJp2Plugin
			QICNSPlugin QTgaPlugin QTiffPlugin QWbmpPlugin QWebpPlugin)
			CONVERT_PRL_LIBS_TO_CMAKE(${qt_module})
		endforeach()
	endif()

	if(NOT EXISTS ${STATIC_DEPENDENCIES_CMAKE_FILE})
		message(FATAL_ERROR "Unable to find ${STATIC_DEPENDENCIES_CMAKE_FILE}")
	endif()
	include(${STATIC_DEPENDENCIES_CMAKE_FILE})
Ilya Bizyaev's avatar
Ilya Bizyaev committed
238 239

	set(QT_QML_PATH ${_qt5Quick_install_prefix})
240

241
	find_library(KIRIGAMI_PLUGIN kirigamiplugin PATHS ${Kirigami2_INSTALL_PREFIX}/${KDE_INSTALL_QMLDIR}/org/kde/kirigami.2)
Ilya Bizyaev's avatar
Ilya Bizyaev committed
242 243 244 245 246 247 248 249 250 251
	find_library(QUICK_PLUGIN qtquick2plugin PATHS ${QT_QML_PATH}/qml/QtQuick.2)
	find_library(LABS_PLATFORM_PLUGIN qtlabsplatformplugin PATHS ${QT_QML_PATH}/qml/Qt/labs/platform)
	find_library(GRAPHEFFECTS_PLUGIN qtgraphicaleffectsplugin PATHS ${QT_QML_PATH}/qml/QtGraphicalEffects)
	find_library(GRAPHEFFECTS_PRIVATE_PLUGIN qtgraphicaleffectsprivate PATHS ${QT_QML_PATH}/qml/QtGraphicalEffects/private)
	find_library(QQC2_PLUGIN qtquickcontrols2plugin PATHS ${QT_QML_PATH}/qml/QtQuick/Controls.2)
	find_library(QQC2_MATERIAL_PLUGIN qtquickcontrols2materialstyleplugin PATHS ${QT_QML_PATH}/qml/QtQuick/Controls.2/Material)
	find_library(QQC2_UNIVERSAL_PLUGIN qtquickcontrols2universalstyleplugin PATHS ${QT_QML_PATH}/qml/QtQuick/Controls.2/Universal)
	find_library(QLAYOUTS_PLUGIN qquicklayoutsplugin PATHS ${QT_QML_PATH}/qml/QtQuick/Layouts)
	find_library(QWINDOW_PLUGIN windowplugin PATHS ${QT_QML_PATH}/qml/QtQuick/Window.2)
	find_library(QSHAPES_PLUGIN qmlshapesplugin PATHS ${QT_QML_PATH}/qml/QtQuick/Shapes)
252
	find_library(QUICKSHAPES Qt5QuickShapes PATHS ${QT_LIBDIR})
Ilya Bizyaev's avatar
Ilya Bizyaev committed
253 254 255 256
	find_library(QTEMPLATES_PLUGIN qtquicktemplates2plugin PATHS ${QT_QML_PATH}/qml/QtQuick/Templates.2)
	find_library(QMODELS_PLUGIN modelsplugin PATHS ${QT_QML_PATH}/qml/QtQml/Models.2)
	target_link_libraries(${PROJECT_NAME}
		${plugin_libs}
257 258 259 260 261 262 263 264 265
		Qt5::QSQLiteDriverPlugin
		Qt5::QJpegPlugin
		Qt5::QGifPlugin
		Qt5::QSvgPlugin
		Qt5::QSvgIconPlugin
		Qt5::QICOPlugin
		Qt5::QGenericEnginePlugin
		Qt5::QLocalClientConnectionFactory
		Qt5::QTcpServerConnectionFactory
Ilya Bizyaev's avatar
Ilya Bizyaev committed
266 267 268 269 270 271 272 273 274 275 276
		${KIRIGAMI_PLUGIN}
		${QUICK_PLUGIN}
		${LABS_PLATFORM_PLUGIN}
		${GRAPHEFFECTS_PLUGIN}
		${GRAPHEFFECTS_PRIVATE_PLUGIN}
		${QQC2_PLUGIN}
		${QQC2_MATERIAL_PLUGIN}
		${QQC2_UNIVERSAL_PLUGIN}
		${QLAYOUTS_PLUGIN}
		${QWINDOW_PLUGIN}
		${QSHAPES_PLUGIN}
277
		${QUICKSHAPES}
Ilya Bizyaev's avatar
Ilya Bizyaev committed
278 279
		${QTEMPLATES_PLUGIN}
		${QMODELS_PLUGIN}
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
		${__Qt5Widgets_LIBRARIES}
	)

	if(WIN32)
		target_link_libraries(${PROJECT_NAME}
			Qt5::QWindowsIntegrationPlugin
		)
	elseif(IOS)
		target_link_libraries(${PROJECT_NAME}
			Qt5::QIOSIntegrationPlugin
			Qt5::QMacHeifPlugin
			Qt5::QMacJp2Plugin
			Qt5::QICNSPlugin
			Qt5::QTgaPlugin
			Qt5::QTiffPlugin
			Qt5::QWbmpPlugin
			Qt5::QWebpPlugin
		)
	endif()
Ilya Bizyaev's avatar
Ilya Bizyaev committed
299 300 301
endif()

# Set a custom plist file for the app bundle
302 303 304 305 306 307 308
if(APPLE)
	if(IOS)
		set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/misc/ios/Info.plist)
	else()
		set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/misc/macos/Info.plist)
	endif()
endif()
Ilya Bizyaev's avatar
Ilya Bizyaev committed
309

310 311 312 313
#
# Global C++ variables
#

314 315 316 317 318
# iOS-specific linker flags
if(IOS)
	set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} "-Wl,-e,_qt_main_wrapper -u _qt_registerPlatformPlugin")
endif()

319
if(UBUNTU_TOUCH)
320
	set(KAIDAN_COMPILE_DEFINITIONS UBUNTU_TOUCH=True)
321
elseif(APPIMAGE)
322 323 324 325
	set(KAIDAN_COMPILE_DEFINITIONS
		APPIMAGE=True
		TARGET_GSTREAMER_PLUGINS="${TARGET_GSTREAMER_PLUGINS}"
	)
326 327
endif()

Ilya Bizyaev's avatar
Ilya Bizyaev committed
328 329 330 331 332 333 334
if(STATIC_BUILD)
	set(KAIDAN_COMPILE_DEFINITIONS
		STATIC_BUILD=True
		${KAIDAN_COMPILE_DEFINITIONS}
	)
endif()

335
target_compile_definitions(${PROJECT_NAME} PRIVATE
336
	DEBUG_SOURCE_PATH="${CMAKE_SOURCE_DIR}"
337 338 339 340
	VERSION_STRING="${VERSION_STRING}"
	APPLICATION_ID="${APPLICATION_ID}"
	APPLICATION_NAME="${APPLICATION_NAME}"
	APPLICATION_DISPLAY_NAME="${APPLICATION_DISPLAY_NAME}"
341
	${KAIDAN_COMPILE_DEFINITIONS}
342
)
343 344

#
345
# Install Kaidan
346 347
#

348 349 350 351 352
if(ANDROID)
	configure_file(${CMAKE_SOURCE_DIR}/misc/android/AndroidManifest.xml.in
	               ${CMAKE_SOURCE_DIR}/misc/android/AndroidManifest.xml)
endif()

353
if(UBUNTU_TOUCH AND CLICK_ARCH)
354 355 356 357 358
	set(CLICK_VERSION ${VERSION_STRING})
	if(DEVELOPMENT_BUILD)
		set(CLICK_VERSION "${CLICK_VERSION}.${CLICK_DATE}")
	endif()

359 360 361 362 363
	# will replace ${CLICK_ARCH} with its value
	configure_file(${CMAKE_SOURCE_DIR}/misc/ubuntu-touch/manifest.json.in
	               ${CMAKE_SOURCE_DIR}/misc/ubuntu-touch/manifest.json)

	# install kaidan binary
364
	install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/bin/${PROJECT_NAME}
365 366 367 368 369 370 371 372 373 374 375 376
	        DESTINATION ${CMAKE_INSTALL_PREFIX}
	)
	# install kaidan media
	install(DIRECTORY "data/images"
	        DESTINATION "${CMAKE_INSTALL_FULL_DATADIR}/${APPLICATION_ID}"
	)
	# install icon
	install(FILES "misc/kaidan.svg" "misc/ubuntu-touch/apparmor.json"
	              "misc/ubuntu-touch/kaidan.desktop" "misc/ubuntu-touch/manifest.json"
	        DESTINATION "${CMAKE_INSTALL_PREFIX}"
	)
elseif(UNIX AND NOT APPLE)
377
	# install kaidan binary
378
	install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/bin/${PROJECT_NAME}
379
	        DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}
380 381
	)

382
	# install kaidan media
383
	install(DIRECTORY "data/images"
384
	        DESTINATION "${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}"
385
	)
386

387 388
	# install icon (scalable + 128x)
	install(FILES "misc/kaidan.svg"
389
	        DESTINATION "${CMAKE_INSTALL_FULL_DATADIR}/icons/hicolor/scalable/apps"
390 391
	)
	install(FILES "misc/kaidan-128x128.png"
392 393
	        DESTINATION "${CMAKE_INSTALL_FULL_DATADIR}/icons/hicolor/128x128/apps"
	        RENAME "kaidan.png"
394
	)
395 396
	# install desktop file
	install(FILES "misc/kaidan.desktop"
Jonah Brüchert's avatar
Jonah Brüchert committed
397 398 399 400 401 402
	        DESTINATION "${KDE_INSTALL_APPDIR}"
	)
	# install metainfo
	install(FILES "misc/metadata.xml"
		DESTINATION "${KDE_INSTALL_METAINFODIR}"
		RENAME "im.kaidan.kaidan.appdata.xml"
403
	)
404
endif()
Linus Jahn's avatar
Linus Jahn committed
405

406 407 408 409
# KNotifications
if(USE_KNOTIFICATIONS)
	install(FILES misc/kaidan.notifyrc DESTINATION ${KNOTIFYRC_INSTALL_DIR})
endif()
Linus Jahn's avatar
Linus Jahn committed
410 411

feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)