CMakeLists.txt 8.22 KB
Newer Older
1
cmake_minimum_required(VERSION 2.8.11)
2
find_package(ECM 5.40.0 REQUIRED NO_MODULE)
3
set(CMAKE_CXX_STANDARD 14)
4
set(QT_MIN_VERSION "5.8.0")
5 6 7

project(kaidan)

8 9
set(APPLICATION_ID "im.kaidan.kaidan")

10 11
# CMake options
option(I18N "Enable i18n support" FALSE)
Ilya Bizyaev's avatar
Ilya Bizyaev committed
12
option(STATIC_BUILD "Build Kaidan statically")
13 14
option(UBUNTU_TOUCH "Building a Ubuntu Touch click (internal use only!)" FALSE)
option(CLICK_ARCH "Architecture that will be used in the click's manifest")
15
option(CLICK_DATE "Date used in the version number in the click's manifest")
16 17 18 19 20 21 22 23

# 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)
24
set(AUTOMOC_MOC_OPTIONS -Muri=im.kaidan.kaidan)
25

26 27 28 29
#
# Dependecies
#

30
# CMake module path
Ilya Bizyaev's avatar
Ilya Bizyaev committed
31
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
32 33 34 35 36 37 38 39 40

# CMake modules include
include(GNUInstallDirs)
include(KDEInstallDirs)
include(KDECompilerSettings NO_POLICY_SCOPE)
include(KDECMakeSettings)
include(ECMInstallIcons)
include(FeatureSummary)
kde_enable_exceptions()
41 42

# Find packages
43
find_package(Qt5 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS Core Qml Quick Svg Sql QuickControls2)
Linus Jahn's avatar
Linus Jahn committed
44
find_package(KF5Kirigami2 REQUIRED)
Ilya Bizyaev's avatar
Ilya Bizyaev committed
45
find_package(PkgConfig REQUIRED)
Linus Jahn's avatar
Linus Jahn committed
46

Ilya Bizyaev's avatar
Ilya Bizyaev committed
47 48 49 50
pkg_search_module(GLOOX REQUIRED gloox)
include_directories(${GLOOX_INCLUDE_DIRS})

# Optional QWidget style integration (not on mobile)
51
if(NOT UBUNTU_TOUCH AND NOT ANDROID)
52 53 54 55 56
	find_package(Qt5Widgets)
	set_package_properties(Qt5Widgets PROPERTIES
		DESCRIPTION "Integration with QWidget based desktop styles"
		TYPE OPTIONAL
	)
57 58
endif()

Ilya Bizyaev's avatar
Ilya Bizyaev committed
59
# Platform-specific
60 61 62 63 64 65 66
if(Qt5Widgets_FOUND)
	add_definitions(-DHAVE_QWIDGETS -DQAPPLICATION_CLASS=QApplication)
	set(__Qt5Widgets_LIBRARIES Qt5::Widgets)
else()
	add_definitions(-DQAPPLICATION_CLASS=QGuiApplication)
endif()

67 68
if (ANDROID)
	find_package(Qt5 REQUIRED COMPONENTS AndroidExtras)
Ilya Bizyaev's avatar
Ilya Bizyaev committed
69 70 71 72 73 74 75
endif()

if (ANDROID OR WIN32)
	pkg_search_module(OPENSSL REQUIRED openssl)

	include_directories(${OPENSSL_INCLUDE_DIRS})
	message(STATUS "Using OpenSSL ${OPENSSL_VERSION}")
76 77
endif()

78

79
#
80
# Load submodules
81 82
#

83 84 85 86
# Main kaidan sources
include("${CMAKE_SOURCE_DIR}/src/CMakeLists.txt")

# I18n support
87 88 89
if(I18N)
	include("${CMAKE_SOURCE_DIR}/i18n/CMakeLists.txt")
endif()
90

91

92 93 94
#
# Sources / Resources
#
95

Ilya Bizyaev's avatar
Ilya Bizyaev committed
96 97
# Include bundled icons on Ubuntu Touch, Android, Windows, macOS and iOS
if(UBUNTU_TOUCH OR ANDROID OR WIN32 OR APPLE)
98 99 100
	set(KAIDAN_ICONS_QRC kirigami-icons.qrc)
endif()

Ilya Bizyaev's avatar
Ilya Bizyaev committed
101 102
# Bundle images on Android, Windows, macOS and iOS
if(ANDROID OR WIN32 OR APPLE)
103 104 105
	set(KAIDAN_IMAGES_QRC "data/images/images.qrc")
endif()

Ilya Bizyaev's avatar
Ilya Bizyaev committed
106 107 108 109 110 111 112 113 114 115 116
# Set app icon
if(APPLE)
	set(KAIDAN_ICNS "${CMAKE_SOURCE_DIR}/misc/macos/kaidan.icns")
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()

117
add_executable(${PROJECT_NAME}
Ilya Bizyaev's avatar
Ilya Bizyaev committed
118 119 120
	MACOSX_BUNDLE
	WIN32
	${KAIDAN_ICNS}
121
	${KAIDAN_SOURCES}
122 123 124
	${KAIDAN_ICONS_QRC}  # only set if enabled
	${KAIDAN_IMAGES_QRC} #
	${I18N_QRC_CPP}      #
125
	"kaidan_qml.qrc"
126 127
)

128

129 130 131 132
#
# Linker Flags
#

133 134
target_link_libraries(${PROJECT_NAME}
	Qt5::Core
135
	Qt5::Sql
136 137
	Qt5::Qml
	Qt5::Quick
138
	Qt5::Svg
Ilya Bizyaev's avatar
Ilya Bizyaev committed
139
	Qt5::Network
140
	${__Qt5Widgets_LIBRARIES}
Ilya Bizyaev's avatar
Ilya Bizyaev committed
141
	${GLOOX_LIBRARIES} ${GLOOX_LDFLAGS}
142
)
143

Ilya Bizyaev's avatar
Ilya Bizyaev committed
144 145 146 147
if (ANDROID OR WIN32)
	target_link_libraries(${PROJECT_NAME} Qt5::QuickControls2 KF5::Kirigami2 ${OPENSSL_LIBRARIES})
endif()

148
if (ANDROID)
Ilya Bizyaev's avatar
Ilya Bizyaev committed
149
	target_link_libraries(${PROJECT_NAME} Qt5::AndroidExtras)
150
endif()
151

Ilya Bizyaev's avatar
Ilya Bizyaev committed
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
if (WIN32 AND STATIC_BUILD)
	pkg_check_modules(QT5ALL Qt5Gui Qt5Quick Qt5QuickControls2 Qt5Network Qt5Qml Qt5Svg Qt5Sql)
	foreach(plugin ${Qt5Gui_PLUGINS} ${Qt5Network_PLUGINS} ${Qt5Qml_PLUGINS} ${Qt5Svg_PLUGINS} ${Qt5Sql_PLUGINS})
	  get_target_property(_loc ${plugin} LOCATION)
	  message("Plugin ${plugin} is at location ${_loc}")
	  set(plugin_libs ${plugin_libs} ${_loc})
	endforeach()
	pkg_search_module(SQLITE REQUIRED sqlite3)

	set(QT_QML_PATH ${_qt5Quick_install_prefix})
	
	find_library(KIRIGAMI_PLUGIN kirigamiplugin PATHS ${CMAKE_PREFIX_PATH}/${KDE_INSTALL_QMLDIR}/org/kde/kirigami.2)
	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)
	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)
	find_library(WIN_SECUR32 secur32)
	find_library(QT_FONT_SUPPORT Qt5FontDatabaseSupport)
	find_library(QT_THEME_SUPPORT Qt5ThemeSupport)
	find_library(QT_EVENT_SUPPORT Qt5EventDispatcherSupport)
	find_library(QT_ACCESSIBILITY_SUPPORT Qt5AccessibilitySupport)
	find_library(QT_UIAUTO_SUPPORT Qt5WindowsUIAutomationSupport)
	target_link_libraries(${PROJECT_NAME}
		${plugin_libs}
		${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}
		${QTEMPLATES_PLUGIN}
		${QMODELS_PLUGIN}
		${SQLITE_LIBRARIES}
		${QT_EVENT_SUPPORT}
		${QT_FONT_SUPPORT}
		${QT_THEME_SUPPORT}
		${QT_ACCESSIBILITY_SUPPORT}
		${QT_UIAUTO_SUPPORT}
		jpeg
		${__Qt5Widgets_LIBRARIES} ${WIN_SECUR32}
		${QT5ALL_LDFLAGS})
endif()

# Set a custom plist file for the app bundle
set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/misc/macos/Info.plist)

211 212 213 214
#
# Global C++ variables
#

215
if(UBUNTU_TOUCH)
216 217 218
	set(KAIDAN_COMPILE_DEFINITIONS
		UBUNTU_TOUCH=True
	)
219
elseif(NOT ANDROID)
220 221 222
	set(KAIDAN_COMPILE_DEFINITIONS
		NOTIFICATIONS_LIBNOTIFY=True
	)
223 224
endif()

Ilya Bizyaev's avatar
Ilya Bizyaev committed
225 226 227 228 229 230 231
if(STATIC_BUILD)
	set(KAIDAN_COMPILE_DEFINITIONS
		STATIC_BUILD=True
		${KAIDAN_COMPILE_DEFINITIONS}
	)
endif()

232
target_compile_definitions(${PROJECT_NAME} PRIVATE
233
	DEBUG_SOURCE_PATH="${CMAKE_SOURCE_DIR}"
234
	${KAIDAN_COMPILE_DEFINITIONS}
235
)
236 237

#
238
# Install Kaidan
239 240
#

241 242 243 244 245 246
if(UBUNTU_TOUCH AND CLICK_ARCH)
	# 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
247
	install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/bin/${PROJECT_NAME}
248 249 250 251 252 253 254 255 256 257 258 259
	        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)
260
	# install kaidan binary
261
	install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/bin/${PROJECT_NAME}
262
	        DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}
263 264
	)

265
	# install kaidan media
266
	install(DIRECTORY "data/images"
267
	        DESTINATION "${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}"
268
	)
269

270 271
	# install icon (scalable + 128x)
	install(FILES "misc/kaidan.svg"
272
	        DESTINATION "${CMAKE_INSTALL_FULL_DATADIR}/icons/hicolor/scalable/apps"
273 274
	)
	install(FILES "misc/kaidan-128x128.png"
275 276
	        DESTINATION "${CMAKE_INSTALL_FULL_DATADIR}/icons/hicolor/128x128/apps"
	        RENAME "kaidan.png"
277
	)
278 279
	# install desktop file
	install(FILES "misc/kaidan.desktop"
280
	        DESTINATION "${CMAKE_INSTALL_FULL_DATADIR}/applications"
281
	)
282
endif()
283 284 285


feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)