e93abef7d5c18ebb98cdf5032f6e82624f97affe
[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(Qt5Widgets REQUIRED QUIET)
135 find_package(Qt5DBus REQUIRED QUIET)
136 find_package(Qt5X11Extras REQUIRED QUIET)
137 find_package(Qt5LinguistTools REQUIRED QUIET)
138 find_package(Qt5Xdg REQUIRED QUIET)
139 find_package(KF5WindowSystem REQUIRED QUIET)
140 message(STATUS "Building with Qt ${Qt5Core_VERSION_STRING}")
141
142 QT5_ADD_DBUS_INTERFACE(SRCS
143     dbus/org.freedesktop.Notifications.xml
144     notifications_interface
145 )
146
147 QT5_ADD_DBUS_ADAPTOR(SRCS
148     dbus/org.lxqt.SingleApplication.xml
149     lxqtsingleapplication.h LXQt::SingleApplication
150 )
151
152 set(LXQT_QT_VERSION "5")
153
154 # KF5WindowSystem is missing here. KF5WindowSystem doesn't provide an .pc file.
155 set(LXQT_PKG_CONFIG_REQUIRES "Qt5Xdg >= 1.2.0, Qt5Widgets, Qt5Xml, Qt5DBus, Qt5X11Extras")
156
157
158 # Standard directories for installation
159 include(LXQtCompilerSettings NO_POLICY_SCOPE)
160 include(LXQtCreatePkgConfigFile)
161 include(cmake/FindInstallConfigPath.cmake) # sets LXQT_ETC_XDG_DIR, if unset
162 include(create_portable_headers)
163
164 set(LXQT_VERSION ${LXQT_MAJOR_VERSION}.${LXQT_MINOR_VERSION}.${LXQT_PATCH_VERSION})
165 set(LXQT_LIBRARY_NAME "lxqt" CACHE STRING "lxqt")
166 set(LXQT_RELATIVE_SHARE_DIR "${LXQT_LIBRARY_NAME}")
167 set(LXQT_SHARE_DIR "${CMAKE_INSTALL_FULL_DATAROOTDIR}/${LXQT_RELATIVE_SHARE_DIR}")
168 set(LXQT_RELATIVE_TRANSLATIONS_DIR "${LXQT_LIBRARY_NAME}/translations")
169 set(LXQT_TRANSLATIONS_DIR "${LXQT_SHARE_DIR}/translations")
170 set(LXQT_GRAPHICS_DIR "${LXQT_SHARE_DIR}/graphics")
171
172 set(LXQT_INTREE_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/include")
173 set(LXQT_INTREE_TARGETS_FILE "${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}-targets.cmake")
174
175 set(LXQT_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}/${LXQT_LIBRARY_NAME}")
176 set(LXQT_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_FULL_DATAROOTDIR}/cmake")
177
178
179 ## Translations
180 include(LXQtTranslateTs)
181
182 lxqt_translate_ts(QM_FILES
183     UPDATE_TRANSLATIONS
184         ${UPDATE_TRANSLATIONS}
185     SOURCES
186         ${SRCS}
187         ${FORMS}
188     INSTALL_DIR
189         "${LXQT_TRANSLATIONS_DIR}/${PROJECT_NAME}"
190 )
191
192 message(STATUS "")
193 message(STATUS "liblxqt version: ${LXQT_VERSION}")
194 message(STATUS "")
195
196
197 # Copy public headers
198 foreach(h ${PUB_HDRS})
199     get_filename_component(bh ${h} NAME)
200     configure_file(${h} "${LXQT_INTREE_INCLUDE_DIR}/LXQt/${bh}" COPYONLY)
201 endforeach()
202
203 # Create the portable headers
204 create_portable_headers(INTREE_PORTABLE_HEADERS "${LXQT_INTREE_INCLUDE_DIR}/LXQt" ${PUBLIC_CLASSES})
205 check_portable_headers(H_FILES ${PUB_HDRS} LINKS "${INTREE_PORTABLE_HEADERS}")
206
207 #************************************************
208 # Create in-tree build infrastructure
209 #************************************************
210 set(CFG_LXQT_TARGETS_FILE   "${LXQT_INTREE_TARGETS_FILE}")
211 set(CFG_LXQT_CMAKE_MODULES_DIR "${PROJECT_SOURCE_DIR}/cmake/modules")
212 set(CFG_LXQT_CMAKE_FIND_MODULES_DIR "${PROJECT_SOURCE_DIR}/cmake/find-modules")
213
214
215 configure_package_config_file(
216     "${CMAKE_CURRENT_SOURCE_DIR}/cmake/lxqt-config.cmake.in"
217     "${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}-config.cmake"
218     INSTALL_DESTINATION "neverland"     # required, altough we don't install it
219 )
220
221 #************************************************
222 # Create installable build infrastructure
223 #************************************************
224 set(CFG_LXQT_TARGETS_FILE "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/${LXQT_LIBRARY_NAME}-targets.cmake")
225 set(CFG_LXQT_CMAKE_MODULES_DIR "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/modules")
226 set(CFG_LXQT_CMAKE_FIND_MODULES_DIR "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/find-modules")
227
228 configure_package_config_file(
229     "${CMAKE_CURRENT_SOURCE_DIR}/cmake/lxqt-config.cmake.in"
230     "${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}-config.cmake"
231     INSTALL_DESTINATION "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}"
232 )
233
234 write_basic_package_version_file(
235     "${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}-config-version.cmake"
236     VERSION ${LXQT_VERSION}
237     COMPATIBILITY AnyNewerVersion
238 )
239
240 install(FILES
241     "${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}-config.cmake"
242     "${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}-config-version.cmake"
243     DESTINATION "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}"
244     COMPONENT Devel
245 )
246
247 install(EXPORT
248     ${LXQT_LIBRARY_NAME}-targets
249     DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${LXQT_LIBRARY_NAME}"
250     COMPONENT Devel
251 )
252
253 file(GLOB toInstallFindModules
254     "${PROJECT_SOURCE_DIR}/cmake/find-modules/*.cmake"
255 )
256
257 install(
258     FILES ${toInstallFindModules}
259     DESTINATION "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/find-modules"
260     COMPONENT Devel
261 )
262
263 file(GLOB toInstallModules
264     "${PROJECT_SOURCE_DIR}/cmake/modules/*.cmake"
265     "${PROJECT_SOURCE_DIR}/cmake/modules/*.in"
266 )
267
268 install(
269     FILES ${toInstallModules}
270     DESTINATION "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/modules"
271     COMPONENT Devel
272 )
273
274 add_library(${LXQT_LIBRARY_NAME}
275     SHARED ${PUB_HDRS}
276            ${SRCS}
277            ${dbus_generated}
278            ${UIS} ${MOCS}
279            ${QM_FILES}
280            ${QRC_CXX_SOURCES}
281
282 )
283
284 target_link_libraries(${LXQT_LIBRARY_NAME}
285     PUBLIC
286         KF5::WindowSystem
287         Qt5::Widgets
288         Qt5::DBus
289         Qt5::X11Extras
290         Qt5Xdg
291 )
292
293 set_target_properties(${LXQT_LIBRARY_NAME} PROPERTIES
294     VERSION   ${LXQT_VERSION}
295     SOVERSION ${LXQT_MAJOR_VERSION}
296 )
297
298 target_compile_definitions(${LXQT_LIBRARY_NAME}
299     PRIVATE "LXQT_RELATIVE_SHARE_DIR=\"${LXQT_RELATIVE_SHARE_DIR}\""
300     PRIVATE "LXQT_SHARE_DIR=\"${LXQT_SHARE_DIR}\""
301     PRIVATE "LXQT_RELATIVE_SHARE_TRANSLATIONS_DIR=\"${LXQT_RELATIVE_TRANSLATIONS_DIR}\""
302     PRIVATE "LXQT_SHARE_TRANSLATIONS_DIR=\"${LXQT_TRANSLATIONS_DIR}\""
303     PRIVATE "LXQT_GRAPHICS_DIR=\"${LXQT_GRAPHICS_DIR}\""
304     PRIVATE "LXQT_ETC_XDG_DIR=\"${LXQT_ETC_XDG_DIR}\""
305     PRIVATE "LXQT_DATA_DIR=\"${LXQT_DATA_DIR}\""
306     PRIVATE "LXQT_VERSION=\"${LXQT_VERSION}\""
307     PRIVATE "COMPILE_LIBLXQT"
308 )
309
310 target_compile_definitions(${LXQT_LIBRARY_NAME}
311     PRIVATE "$<$<CONFIG:Release>:QT_NO_DEBUG_OUTPUT>"
312     PRIVATE "$<$<CONFIG:Release>:QT_NO_WARNING_OUTPUT>"
313 )
314
315 target_include_directories(${LXQT_LIBRARY_NAME}
316     INTERFACE "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${LXQT_LIBRARY_NAME}>"
317     INTERFACE "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${LXQT_LIBRARY_NAME}/LXQt>"
318 )
319
320 target_include_directories(${LXQT_LIBRARY_NAME}
321     INTERFACE "$<BUILD_INTERFACE:${LXQT_INTREE_INCLUDE_DIR}>"
322     INTERFACE "$<BUILD_INTERFACE:${LXQT_INTREE_INCLUDE_DIR}/LXQt>"
323 )
324
325 install(TARGETS
326     ${LXQT_LIBRARY_NAME}
327     DESTINATION "${CMAKE_INSTALL_LIBDIR}"
328     EXPORT ${LXQT_LIBRARY_NAME}-targets
329     LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
330     COMPONENT Runtime
331 )
332
333 export(TARGETS ${LXQT_LIBRARY_NAME}
334     APPEND FILE "${LXQT_INTREE_TARGETS_FILE}"
335     EXPORT_LINK_INTERFACE_LIBRARIES
336 )
337
338 install(FILES
339     ${PUB_HDRS}
340     DESTINATION "${LXQT_INSTALL_INCLUDE_DIR}/LXQt"
341     COMPONENT Devel
342 )
343
344 install(FILES
345     ${INTREE_PORTABLE_HEADERS}
346     DESTINATION "${LXQT_INSTALL_INCLUDE_DIR}/LXQt"
347     COMPONENT Devel
348 )
349
350 #************************************************
351 # Create and install pkgconfig file
352 #************************************************
353 lxqt_create_pkgconfig_file(
354     PACKAGE_NAME ${LXQT_LIBRARY_NAME}
355     DESCRIPTIVE_NAME ${LXQT_LIBRARY_NAME}
356     DESCRIPTION ${LXQT_PKG_CONFIG_DESCRIPTION}
357     INCLUDEDIRS ${LXQT_LIBRARY_NAME}
358     LIBS ${LXQT_LIBRARY_NAME}
359     REQUIRES ${LXQT_PKG_CONFIG_REQUIRES}
360     VERSION ${LXQT_VERSION}
361     INSTALL
362 )
363 #************************************************
364
365
366 # building tarball with CPack -------------------------------------------------
367 include(InstallRequiredSystemLibraries)
368 set(CPACK_PACKAGE_VERSION_MAJOR ${LXQT_MAJOR_VERSION})
369 set(CPACK_PACKAGE_VERSION_MINOR ${LXQT_MINOR_VERSION})
370 set(CPACK_PACKAGE_VERSION_PATCH ${LXQT_PATCH_VERSION})
371 set(CPACK_GENERATOR TBZ2)
372 set(CPACK_SOURCE_GENERATOR TBZ2)
373 set(CPACK_SOURCE_IGNORE_FILES /build/;.gitignore;.*~;.git;.kdev4;temp)
374 include(CPack)
375