Settings: unify duplicated code
[lxde/liblxqt.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
2
3 project(liblxqt)
4
5 set(LXQT_MAJOR_VERSION 0)
6 set(LXQT_MINOR_VERSION 10)
7 set(LXQT_PATCH_VERSION 0)
8
9 include(CMakePackageConfigHelpers)
10 include(GNUInstallDirs) # Standard directories for installation
11
12 #-----------------------------------------------------------------------------
13 # LXQT_DATA_DIR defaults to CMAKE_INSTALL_FULL_DATADIR. It's added to
14 #   XDG_DATA_DIRS by the startlxqt script
15 # Warning: Setting LXQT_DATA_DIR must be done after including GNUInstallDirs
16 #-----------------------------------------------------------------------------
17 if (NOT DEFINED LXQT_DATA_DIR)
18     set(LXQT_DATA_DIR "${CMAKE_INSTALL_FULL_DATADIR}" CACHE PATH
19         "LXQt base directory relative to which data files should be searched"
20     )
21 endif()
22
23 #-----------------------------------------------------------------------------
24 # Release is the default build type
25 #-----------------------------------------------------------------------------
26 if (NOT CMAKE_BUILD_TYPE)
27     set(CMAKE_BUILD_TYPE Release)
28 endif()
29
30 set(LXQT_PKG_CONFIG_DESCRIPTION "Shared library for LXQt applications")
31
32 set(PUB_HDRS
33     lxqthtmldelegate.h
34     lxqtsettings.h
35     lxqtplugininfo.h
36     lxqtpowermanager.h
37     lxqtscreensaver.h
38     lxqtapplication.h
39     lxqtsingleapplication.h
40     lxqttranslator.h
41     lxqtprogramfinder.h
42
43     configdialog/lxqtconfigdialog.h
44     configdialog/lxqtpageselectwidget.h
45
46     lxqtpower/lxqtpower.h
47     lxqtnotification.h
48     lxqtautostartentry.h
49     lxqtgridlayout.h
50     lxqtrotatedwidget.h
51     lxqtglobals.h
52 )
53
54 set(PUBLIC_CLASSES
55     HtmlDelegate
56     Settings
57     PluginInfo
58     PowerManager
59     ScreenSaver
60     Application
61     SingleApplication
62     Translator
63     ProgramFinder
64
65     ConfigDialog
66     PageSelectWidget
67
68     Power
69     Notification
70     AutostartEntry
71     GridLayout
72     RotatedWidget
73 )
74
75 set(SRCS
76     lxqthtmldelegate.cpp
77     lxqtplugininfo.cpp
78     lxqtpowermanager.cpp
79     lxqtsettings.cpp
80     lxqtscreensaver.cpp
81     lxqtapplication.cpp
82     lxqtsingleapplication.cpp
83     lxqttranslator.cpp
84     lxqtprogramfinder.cpp
85
86     configdialog/lxqtconfigdialog.cpp
87     configdialog/lxqtpageselectwidget.cpp
88
89     lxqtpower/lxqtpower.cpp
90     lxqtpower/lxqtpowerproviders.cpp
91     lxqtautostartentry.cpp
92     lxqtnotification.cpp
93     lxqtgridlayout.cpp
94     lxqtrotatedwidget.cpp
95 )
96
97 set(MOCS
98     lxqthtmldelegate.h
99     lxqtpowermanager.h
100     lxqtsettings.h
101     lxqtscreensaver.h
102     lxqtapplication.h
103
104     configdialog/lxqtconfigdialog.h
105     configdialog/lxqtpageselectwidget.h
106
107     lxqtnotification.h
108     lxqtnotification_p.h
109     lxqtpower/lxqtpower.h
110     lxqtpower/lxqtpowerproviders.h
111     lxqtgridlayout.h
112     lxqtrotatedwidget.h
113 )
114
115 set(FORMS
116     configdialog/lxqtconfigdialog.ui
117 )
118
119 # additional cmake files
120 list(APPEND CMAKE_MODULE_PATH
121     "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
122     "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
123     "${CMAKE_CURRENT_SOURCE_DIR}/cmake/find-modules"
124 )
125
126 option(UPDATE_TRANSLATIONS "Update source translation translations/*.ts files" OFF)
127
128 set(CMAKE_INCLUDE_CURRENT_DIR ON)
129 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
130
131 set(CMAKE_AUTOMOC ON)
132 set(CMAKE_AUTOUIC ON)
133
134 find_package(X11 REQUIRED QUIET)
135 find_package(Qt5Widgets REQUIRED QUIET)
136 find_package(Qt5DBus REQUIRED QUIET)
137 find_package(Qt5X11Extras REQUIRED QUIET)
138 find_package(Qt5LinguistTools REQUIRED QUIET)
139 find_package(Qt5Xdg REQUIRED QUIET)
140 find_package(KF5WindowSystem REQUIRED QUIET)
141 message(STATUS "Building with Qt ${Qt5Core_VERSION_STRING}")
142
143 QT5_ADD_DBUS_INTERFACE(SRCS
144     dbus/org.freedesktop.Notifications.xml
145     notifications_interface
146 )
147
148 QT5_ADD_DBUS_ADAPTOR(SRCS
149     dbus/org.lxqt.SingleApplication.xml
150     lxqtsingleapplication.h LXQt::SingleApplication
151 )
152
153 set(LXQT_QT_VERSION "5")
154
155 # KF5WindowSystem is missing here. KF5WindowSystem doesn't provide an .pc file.
156 set(LXQT_PKG_CONFIG_REQUIRES "Qt5Xdg >= 1.2.0, Qt5Widgets, Qt5Xml, Qt5DBus, Qt5X11Extras")
157
158
159 # Standard directories for installation
160 include(LXQtCompilerSettings NO_POLICY_SCOPE)
161 include(LXQtCreatePkgConfigFile)
162 include(cmake/FindInstallConfigPath.cmake) # sets LXQT_ETC_XDG_DIR, if unset
163 include(create_portable_headers)
164
165 set(LXQT_VERSION ${LXQT_MAJOR_VERSION}.${LXQT_MINOR_VERSION}.${LXQT_PATCH_VERSION})
166 set(LXQT_LIBRARY_NAME "lxqt" CACHE STRING "lxqt")
167 set(LXQT_RELATIVE_SHARE_DIR "${LXQT_LIBRARY_NAME}")
168 set(LXQT_SHARE_DIR "${CMAKE_INSTALL_FULL_DATAROOTDIR}/${LXQT_RELATIVE_SHARE_DIR}")
169 set(LXQT_RELATIVE_TRANSLATIONS_DIR "${LXQT_LIBRARY_NAME}/translations")
170 set(LXQT_TRANSLATIONS_DIR "${LXQT_SHARE_DIR}/translations")
171 set(LXQT_GRAPHICS_DIR "${LXQT_SHARE_DIR}/graphics")
172
173 set(LXQT_INTREE_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/include")
174 set(LXQT_INTREE_TARGETS_FILE "${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}-targets.cmake")
175
176 set(LXQT_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}/${LXQT_LIBRARY_NAME}")
177 set(LXQT_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_FULL_DATAROOTDIR}/cmake")
178
179
180 ## Translations
181 include(LXQtTranslateTs)
182
183 lxqt_translate_ts(QM_FILES
184     UPDATE_TRANSLATIONS
185         ${UPDATE_TRANSLATIONS}
186     SOURCES
187         ${SRCS}
188         ${FORMS}
189     INSTALL_DIR
190         "${LXQT_TRANSLATIONS_DIR}/${PROJECT_NAME}"
191     PULL_TRANSLATIONS
192         ${PULL_TRANSLATIONS}
193     CLEAN_TRANSLATIONS
194         ${CLEAN_TRANSLATIONS}
195     TRANSLATIONS_REPO
196         ${TRANSLATIONS_REPO}
197     TRANSLATIONS_REFSPEC
198         ${TRANSLATIONS_REFSPEC}
199 )
200
201 message(STATUS "")
202 message(STATUS "liblxqt version: ${LXQT_VERSION}")
203 message(STATUS "")
204
205
206 # Copy public headers
207 foreach(h ${PUB_HDRS})
208     get_filename_component(bh ${h} NAME)
209     configure_file(${h} "${LXQT_INTREE_INCLUDE_DIR}/LXQt/${bh}" COPYONLY)
210 endforeach()
211
212 # Create the portable headers
213 create_portable_headers(INTREE_PORTABLE_HEADERS "${LXQT_INTREE_INCLUDE_DIR}/LXQt" ${PUBLIC_CLASSES})
214 check_portable_headers(H_FILES ${PUB_HDRS} LINKS "${INTREE_PORTABLE_HEADERS}")
215
216 #************************************************
217 # Create in-tree build infrastructure
218 #************************************************
219 set(CFG_LXQT_TARGETS_FILE   "${LXQT_INTREE_TARGETS_FILE}")
220 set(CFG_LXQT_CMAKE_MODULES_DIR "${PROJECT_SOURCE_DIR}/cmake/modules")
221 set(CFG_LXQT_CMAKE_FIND_MODULES_DIR "${PROJECT_SOURCE_DIR}/cmake/find-modules")
222
223
224 configure_package_config_file(
225     "${CMAKE_CURRENT_SOURCE_DIR}/cmake/lxqt-config.cmake.in"
226     "${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}-config.cmake"
227     INSTALL_DESTINATION "neverland"     # required, altough we don't install it
228 )
229
230 #************************************************
231 # Create installable build infrastructure
232 #************************************************
233 set(CFG_LXQT_TARGETS_FILE "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/${LXQT_LIBRARY_NAME}-targets.cmake")
234 set(CFG_LXQT_CMAKE_MODULES_DIR "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/modules")
235 set(CFG_LXQT_CMAKE_FIND_MODULES_DIR "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/find-modules")
236
237 configure_package_config_file(
238     "${CMAKE_CURRENT_SOURCE_DIR}/cmake/lxqt-config.cmake.in"
239     "${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}-config.cmake"
240     INSTALL_DESTINATION "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}"
241 )
242
243 write_basic_package_version_file(
244     "${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}-config-version.cmake"
245     VERSION ${LXQT_VERSION}
246     COMPATIBILITY AnyNewerVersion
247 )
248
249 install(FILES
250     "${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}-config.cmake"
251     "${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}-config-version.cmake"
252     DESTINATION "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}"
253     COMPONENT Devel
254 )
255
256 install(EXPORT
257     ${LXQT_LIBRARY_NAME}-targets
258     DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${LXQT_LIBRARY_NAME}"
259     COMPONENT Devel
260 )
261
262 file(GLOB toInstallFindModules
263     "${PROJECT_SOURCE_DIR}/cmake/find-modules/*.cmake"
264 )
265
266 install(
267     FILES ${toInstallFindModules}
268     DESTINATION "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/find-modules"
269     COMPONENT Devel
270 )
271
272 file(GLOB toInstallModules
273     "${PROJECT_SOURCE_DIR}/cmake/modules/*.cmake"
274     "${PROJECT_SOURCE_DIR}/cmake/modules/*.in"
275 )
276
277 install(
278     FILES ${toInstallModules}
279     DESTINATION "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/modules"
280     COMPONENT Devel
281 )
282
283 add_library(${LXQT_LIBRARY_NAME}
284     SHARED ${PUB_HDRS}
285            ${SRCS}
286            ${dbus_generated}
287            ${UIS} ${MOCS}
288            ${QM_FILES}
289            ${QRC_CXX_SOURCES}
290
291 )
292
293 target_link_libraries(${LXQT_LIBRARY_NAME}
294     PUBLIC
295         KF5::WindowSystem
296         Qt5::Widgets
297         Qt5::DBus
298         Qt5::X11Extras
299         Qt5Xdg
300     PRIVATE
301         ${X11_Xscreensaver_LIB}
302         ${X11_X11_LIB}
303 )
304
305 set_target_properties(${LXQT_LIBRARY_NAME} PROPERTIES
306     VERSION   ${LXQT_VERSION}
307     SOVERSION ${LXQT_MAJOR_VERSION}
308 )
309
310 target_compile_definitions(${LXQT_LIBRARY_NAME}
311     PRIVATE "LXQT_RELATIVE_SHARE_DIR=\"${LXQT_RELATIVE_SHARE_DIR}\""
312     PRIVATE "LXQT_SHARE_DIR=\"${LXQT_SHARE_DIR}\""
313     PRIVATE "LXQT_RELATIVE_SHARE_TRANSLATIONS_DIR=\"${LXQT_RELATIVE_TRANSLATIONS_DIR}\""
314     PRIVATE "LXQT_SHARE_TRANSLATIONS_DIR=\"${LXQT_TRANSLATIONS_DIR}\""
315     PRIVATE "LXQT_GRAPHICS_DIR=\"${LXQT_GRAPHICS_DIR}\""
316     PRIVATE "LXQT_ETC_XDG_DIR=\"${LXQT_ETC_XDG_DIR}\""
317     PRIVATE "LXQT_DATA_DIR=\"${LXQT_DATA_DIR}\""
318     PRIVATE "LXQT_INSTALL_PREFIX=\"${CMAKE_INSTALL_PREFIX}\""
319     PRIVATE "LXQT_VERSION=\"${LXQT_VERSION}\""
320     PRIVATE "COMPILE_LIBLXQT"
321 )
322
323 target_compile_definitions(${LXQT_LIBRARY_NAME}
324     PRIVATE "$<$<CONFIG:Release>:QT_NO_DEBUG_OUTPUT>"
325     PRIVATE "$<$<CONFIG:Release>:QT_NO_WARNING_OUTPUT>"
326 )
327
328 target_include_directories(${LXQT_LIBRARY_NAME}
329     INTERFACE "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${LXQT_LIBRARY_NAME}>"
330     INTERFACE "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${LXQT_LIBRARY_NAME}/LXQt>"
331 )
332
333 target_include_directories(${LXQT_LIBRARY_NAME}
334     INTERFACE "$<BUILD_INTERFACE:${LXQT_INTREE_INCLUDE_DIR}>"
335     INTERFACE "$<BUILD_INTERFACE:${LXQT_INTREE_INCLUDE_DIR}/LXQt>"
336 )
337
338 install(TARGETS
339     ${LXQT_LIBRARY_NAME}
340     DESTINATION "${CMAKE_INSTALL_LIBDIR}"
341     EXPORT ${LXQT_LIBRARY_NAME}-targets
342     LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
343     COMPONENT Runtime
344 )
345
346 export(TARGETS ${LXQT_LIBRARY_NAME}
347     APPEND FILE "${LXQT_INTREE_TARGETS_FILE}"
348     EXPORT_LINK_INTERFACE_LIBRARIES
349 )
350
351 install(FILES
352     ${PUB_HDRS}
353     DESTINATION "${LXQT_INSTALL_INCLUDE_DIR}/LXQt"
354     COMPONENT Devel
355 )
356
357 install(FILES
358     ${INTREE_PORTABLE_HEADERS}
359     DESTINATION "${LXQT_INSTALL_INCLUDE_DIR}/LXQt"
360     COMPONENT Devel
361 )
362
363 #************************************************
364 # Create and install pkgconfig file
365 #************************************************
366 lxqt_create_pkgconfig_file(
367     PACKAGE_NAME ${LXQT_LIBRARY_NAME}
368     DESCRIPTIVE_NAME ${LXQT_LIBRARY_NAME}
369     DESCRIPTION ${LXQT_PKG_CONFIG_DESCRIPTION}
370     INCLUDEDIRS ${LXQT_LIBRARY_NAME}
371     LIBS ${LXQT_LIBRARY_NAME}
372     REQUIRES ${LXQT_PKG_CONFIG_REQUIRES}
373     VERSION ${LXQT_VERSION}
374     INSTALL
375 )
376 #************************************************
377
378
379 # building tarball with CPack -------------------------------------------------
380 include(InstallRequiredSystemLibraries)
381 set(CPACK_PACKAGE_VERSION_MAJOR ${LXQT_MAJOR_VERSION})
382 set(CPACK_PACKAGE_VERSION_MINOR ${LXQT_MINOR_VERSION})
383 set(CPACK_PACKAGE_VERSION_PATCH ${LXQT_PATCH_VERSION})
384 set(CPACK_GENERATOR TBZ2)
385 set(CPACK_SOURCE_GENERATOR TBZ2)
386 set(CPACK_SOURCE_IGNORE_FILES /build/;.gitignore;.*~;.git;.kdev4;temp)
387 include(CPack)
388