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