3fcad2901e6bd59c3da99cfa535a8cbdf08e0a0f
[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 option(WITH_XDG_DIRS_FALLBACK "Use our XDG_CONFIG_DIRS fallback" ON)
128
129 set(CMAKE_INCLUDE_CURRENT_DIR ON)
130 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
131
132 set(CMAKE_AUTOMOC ON)
133 set(CMAKE_AUTOUIC ON)
134
135 find_package(X11 REQUIRED QUIET)
136 find_package(Qt5Widgets REQUIRED QUIET)
137 find_package(Qt5DBus REQUIRED QUIET)
138 find_package(Qt5X11Extras REQUIRED QUIET)
139 find_package(Qt5LinguistTools REQUIRED QUIET)
140 find_package(Qt5Xdg REQUIRED QUIET)
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 >= 1.2.0, Qt5Widgets, Qt5Xml, Qt5DBus, Qt5X11Extras")
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(create_portable_headers)
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 create_portable_headers(INTREE_PORTABLE_HEADERS "${LXQT_INTREE_INCLUDE_DIR}/LXQt" ${PUBLIC_CLASSES})
215 check_portable_headers(H_FILES ${PUB_HDRS} LINKS "${INTREE_PORTABLE_HEADERS}")
216
217 #************************************************
218 # Create in-tree build infrastructure
219 #************************************************
220 set(CFG_LXQT_TARGETS_FILE   "${LXQT_INTREE_TARGETS_FILE}")
221 set(CFG_LXQT_CMAKE_MODULES_DIR "${PROJECT_SOURCE_DIR}/cmake/modules")
222 set(CFG_LXQT_CMAKE_FIND_MODULES_DIR "${PROJECT_SOURCE_DIR}/cmake/find-modules")
223
224
225 configure_package_config_file(
226     "${CMAKE_CURRENT_SOURCE_DIR}/cmake/lxqt-config.cmake.in"
227     "${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}-config.cmake"
228     INSTALL_DESTINATION "neverland"     # required, altough we don't install it
229 )
230
231 #************************************************
232 # Create installable build infrastructure
233 #************************************************
234 set(CFG_LXQT_TARGETS_FILE "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/${LXQT_LIBRARY_NAME}-targets.cmake")
235 set(CFG_LXQT_CMAKE_MODULES_DIR "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/modules")
236 set(CFG_LXQT_CMAKE_FIND_MODULES_DIR "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/find-modules")
237
238 configure_package_config_file(
239     "${CMAKE_CURRENT_SOURCE_DIR}/cmake/lxqt-config.cmake.in"
240     "${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}-config.cmake"
241     INSTALL_DESTINATION "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}"
242 )
243
244 write_basic_package_version_file(
245     "${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}-config-version.cmake"
246     VERSION ${LXQT_VERSION}
247     COMPATIBILITY AnyNewerVersion
248 )
249
250 install(FILES
251     "${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}-config.cmake"
252     "${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}-config-version.cmake"
253     DESTINATION "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}"
254     COMPONENT Devel
255 )
256
257 install(EXPORT
258     ${LXQT_LIBRARY_NAME}-targets
259     DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${LXQT_LIBRARY_NAME}"
260     COMPONENT Devel
261 )
262
263 file(GLOB toInstallFindModules
264     "${PROJECT_SOURCE_DIR}/cmake/find-modules/*.cmake"
265 )
266
267 install(
268     FILES ${toInstallFindModules}
269     DESTINATION "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/find-modules"
270     COMPONENT Devel
271 )
272
273 file(GLOB toInstallModules
274     "${PROJECT_SOURCE_DIR}/cmake/modules/*.cmake"
275     "${PROJECT_SOURCE_DIR}/cmake/modules/*.in"
276 )
277
278 install(
279     FILES ${toInstallModules}
280     DESTINATION "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/modules"
281     COMPONENT Devel
282 )
283
284 add_library(${LXQT_LIBRARY_NAME}
285     SHARED ${PUB_HDRS}
286            ${SRCS}
287            ${dbus_generated}
288            ${UIS} ${MOCS}
289            ${QM_FILES}
290            ${QRC_CXX_SOURCES}
291
292 )
293
294 target_link_libraries(${LXQT_LIBRARY_NAME}
295     PUBLIC
296         KF5::WindowSystem
297         Qt5::Widgets
298         Qt5::DBus
299         Qt5::X11Extras
300         Qt5Xdg
301     PRIVATE
302         ${X11_Xscreensaver_LIB}
303         ${X11_X11_LIB}
304 )
305
306 set_target_properties(${LXQT_LIBRARY_NAME} PROPERTIES
307     VERSION   ${LXQT_VERSION}
308     SOVERSION ${LXQT_MAJOR_VERSION}
309 )
310
311 target_compile_definitions(${LXQT_LIBRARY_NAME}
312     PRIVATE "LXQT_RELATIVE_SHARE_DIR=\"${LXQT_RELATIVE_SHARE_DIR}\""
313     PRIVATE "LXQT_SHARE_DIR=\"${LXQT_SHARE_DIR}\""
314     PRIVATE "LXQT_RELATIVE_SHARE_TRANSLATIONS_DIR=\"${LXQT_RELATIVE_TRANSLATIONS_DIR}\""
315     PRIVATE "LXQT_SHARE_TRANSLATIONS_DIR=\"${LXQT_TRANSLATIONS_DIR}\""
316     PRIVATE "LXQT_GRAPHICS_DIR=\"${LXQT_GRAPHICS_DIR}\""
317     PRIVATE "LXQT_ETC_XDG_DIR=\"${LXQT_ETC_XDG_DIR}\""
318     PRIVATE "LXQT_DATA_DIR=\"${LXQT_DATA_DIR}\""
319     PRIVATE "LXQT_INSTALL_PREFIX=\"${CMAKE_INSTALL_PREFIX}\""
320     PRIVATE "LXQT_VERSION=\"${LXQT_VERSION}\""
321     PRIVATE "COMPILE_LIBLXQT"
322 )
323
324 target_compile_definitions(${LXQT_LIBRARY_NAME}
325     PRIVATE "$<$<CONFIG:Release>:QT_NO_DEBUG_OUTPUT>"
326     PRIVATE "$<$<CONFIG:Release>:QT_NO_WARNING_OUTPUT>"
327 )
328
329 if (WITH_XDG_DIRS_FALLBACK)
330     target_compile_definitions(${LXQT_LIBRARY_NAME}
331         PRIVATE "WITH_XDG_DIRS_FALLBACK"
332     )
333 endif ()
334
335 target_include_directories(${LXQT_LIBRARY_NAME}
336     INTERFACE "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${LXQT_LIBRARY_NAME}>"
337     INTERFACE "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${LXQT_LIBRARY_NAME}/LXQt>"
338 )
339
340 target_include_directories(${LXQT_LIBRARY_NAME}
341     INTERFACE "$<BUILD_INTERFACE:${LXQT_INTREE_INCLUDE_DIR}>"
342     INTERFACE "$<BUILD_INTERFACE:${LXQT_INTREE_INCLUDE_DIR}/LXQt>"
343 )
344
345 install(TARGETS
346     ${LXQT_LIBRARY_NAME}
347     DESTINATION "${CMAKE_INSTALL_LIBDIR}"
348     EXPORT ${LXQT_LIBRARY_NAME}-targets
349     LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
350     COMPONENT Runtime
351 )
352
353 export(TARGETS ${LXQT_LIBRARY_NAME}
354     APPEND FILE "${LXQT_INTREE_TARGETS_FILE}"
355     EXPORT_LINK_INTERFACE_LIBRARIES
356 )
357
358 install(FILES
359     ${PUB_HDRS}
360     DESTINATION "${LXQT_INSTALL_INCLUDE_DIR}/LXQt"
361     COMPONENT Devel
362 )
363
364 install(FILES
365     ${INTREE_PORTABLE_HEADERS}
366     DESTINATION "${LXQT_INSTALL_INCLUDE_DIR}/LXQt"
367     COMPONENT Devel
368 )
369
370 #************************************************
371 # Create and install pkgconfig file
372 #************************************************
373 lxqt_create_pkgconfig_file(
374     PACKAGE_NAME ${LXQT_LIBRARY_NAME}
375     DESCRIPTIVE_NAME ${LXQT_LIBRARY_NAME}
376     DESCRIPTION ${LXQT_PKG_CONFIG_DESCRIPTION}
377     INCLUDEDIRS ${LXQT_LIBRARY_NAME}
378     LIBS ${LXQT_LIBRARY_NAME}
379     REQUIRES ${LXQT_PKG_CONFIG_REQUIRES}
380     VERSION ${LXQT_VERSION}
381     INSTALL
382 )
383 #************************************************
384
385
386 # building tarball with CPack -------------------------------------------------
387 include(InstallRequiredSystemLibraries)
388 set(CPACK_PACKAGE_VERSION_MAJOR ${LXQT_MAJOR_VERSION})
389 set(CPACK_PACKAGE_VERSION_MINOR ${LXQT_MINOR_VERSION})
390 set(CPACK_PACKAGE_VERSION_PATCH ${LXQT_PATCH_VERSION})
391 set(CPACK_GENERATOR TBZ2)
392 set(CPACK_SOURCE_GENERATOR TBZ2)
393 set(CPACK_SOURCE_IGNORE_FILES /build/;.gitignore;.*~;.git;.kdev4;temp)
394 include(CPack)
395