CMakeLists.txt 8.3 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(PkgConfig REQUIRED)
Linus Jahn's avatar
Linus Jahn committed
44
find_package(Qt5 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS Core Qml Quick Svg Sql QuickControls2 Xml)
Linus Jahn's avatar
Linus Jahn committed
45
find_package(KF5Kirigami2 REQUIRED)
46
pkg_check_modules(QXmpp REQUIRED qxmpp>=0.9)
Ilya Bizyaev's avatar
Ilya Bizyaev committed
47 48

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

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

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

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

	include_directories(${OPENSSL_INCLUDE_DIRS})
	message(STATUS "Using OpenSSL ${OPENSSL_VERSION}")
74 75
endif()

76

77
#
78
# Load submodules
79 80
#

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

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

89

90 91 92
#
# Sources / Resources
#
93

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

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

Ilya Bizyaev's avatar
Ilya Bizyaev committed
104 105 106 107 108 109 110 111 112 113 114
# 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()

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

target_link_libraries(${PROJECT_NAME}
	Qt5::Core
128
	Qt5::Sql
129 130
	Qt5::Qml
	Qt5::Quick
131
	Qt5::Svg
Ilya Bizyaev's avatar
Ilya Bizyaev committed
132
	Qt5::Network
Linus Jahn's avatar
Linus Jahn committed
133
	Qt5::Xml
134
	${__Qt5Widgets_LIBRARIES}
135 136 137 138 139 140 141 142 143
	${QXmpp_LIBRARIES}
)

target_include_directories(${PROJECT_NAME} PUBLIC
	${QXmpp_INCLUDE_DIRS}
)

target_compile_options(${PROJECT_NAME} PUBLIC
	${QXmpp_CFLAGS_OTHER}
144
)
145

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

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

Ilya Bizyaev's avatar
Ilya Bizyaev committed
154 155 156
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})
157 158 159
		get_target_property(_loc ${plugin} LOCATION)
		message("Plugin ${plugin} is at location ${_loc}")
		set(plugin_libs ${plugin_libs} ${_loc})
Ilya Bizyaev's avatar
Ilya Bizyaev committed
160 161 162 163
	endforeach()
	pkg_search_module(SQLITE REQUIRED sqlite3)

	set(QT_QML_PATH ${_qt5Quick_install_prefix})
164

Ilya Bizyaev's avatar
Ilya Bizyaev committed
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
	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)

213 214 215 216
#
# Global C++ variables
#

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

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

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

#
240
# Install Kaidan
241 242
#

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

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

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


feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)