Make lxqt globals a public header
[lxde/liblxqt.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
2
3 project(liblxqt)
4
5 set(QT_MINIMUM_VERSION "5.7.1")
6 set(QTXDG_MINIMUM_VERSION "3.1.0")
7 set(LXQTBT_MINIMUM_VERSION "0.4.1")
8
9 # Major LXQt Version, belong to all components
10 set(LXQT_MAJOR_VERSION 0)
11 # Minor LXQt Version, belong to all components
12 set(LXQT_MINOR_VERSION 12)
13 #
14 # Patch Version, belong *only* to the component
15 # LXQt is 0.11 - liblxqt is at patch version 1
16 # The official LXQt version will follow liblxqt.
17 #
18 # In a perfect world all components would have the same major- and minor- and
19 # patch-version as liblxqt - in real life it will be fine if every component
20 # has it's own patch version within a major/minor life cyle.
21 #
22 set(LXQT_PATCH_VERSION 0)
23 set(LXQT_VERSION ${LXQT_MAJOR_VERSION}.${LXQT_MINOR_VERSION}.${LXQT_PATCH_VERSION})
24
25 include(CMakePackageConfigHelpers)
26 include(GNUInstallDirs) # Standard directories for installation
27
28 #-----------------------------------------------------------------------------
29 # Release is the default build type
30 #-----------------------------------------------------------------------------
31 if (NOT CMAKE_BUILD_TYPE)
32     set(CMAKE_BUILD_TYPE Release)
33 endif()
34
35 set(LXQT_PKG_CONFIG_DESCRIPTION "Shared library for LXQt applications")
36
37 set(PUB_HDRS
38     lxqthtmldelegate.h
39     lxqtsettings.h
40     lxqtplugininfo.h
41     lxqtpowermanager.h
42     lxqtscreensaver.h
43     lxqtapplication.h
44     lxqtsingleapplication.h
45     lxqttranslator.h
46     lxqtprogramfinder.h
47
48     configdialog/lxqtconfigdialog.h
49     configdialog/lxqtpageselectwidget.h
50
51     lxqtpower/lxqtpower.h
52     lxqtnotification.h
53     lxqtautostartentry.h
54     lxqtgridlayout.h
55     lxqtrotatedwidget.h
56     lxqtglobals.h
57 )
58
59 set(PUBLIC_CLASSES
60     HtmlDelegate
61     Settings
62     PluginInfo
63     PowerManager
64     ScreenSaver
65     Application
66     SingleApplication
67     Translator
68     ProgramFinder
69
70     ConfigDialog
71     PageSelectWidget
72
73     Power
74     Notification
75     AutostartEntry
76     GridLayout
77     RotatedWidget
78     Globals
79 )
80
81 set(SRCS
82     lxqthtmldelegate.cpp
83     lxqtplugininfo.cpp
84     lxqtpowermanager.cpp
85     lxqtsettings.cpp
86     lxqtscreensaver.cpp
87     lxqtapplication.cpp
88     lxqtsingleapplication.cpp
89     lxqttranslator.cpp
90     lxqtprogramfinder.cpp
91
92     configdialog/lxqtconfigdialog.cpp
93     configdialog/lxqtpageselectwidget.cpp
94
95     lxqtpower/lxqtpower.cpp
96     lxqtpower/lxqtpowerproviders.cpp
97     lxqtautostartentry.cpp
98     lxqtnotification.cpp
99     lxqtgridlayout.cpp
100     lxqtrotatedwidget.cpp
101 )
102
103 set(MOCS
104     lxqthtmldelegate.h
105     lxqtpowermanager.h
106     lxqtsettings.h
107     lxqtscreensaver.h
108     lxqtapplication.h
109
110     configdialog/lxqtconfigdialog.h
111     configdialog/lxqtpageselectwidget.h
112
113     lxqtnotification.h
114     lxqtnotification_p.h
115     lxqtpower/lxqtpower.h
116     lxqtpower/lxqtpowerproviders.h
117     lxqtgridlayout.h
118     lxqtrotatedwidget.h
119 )
120
121 set(FORMS
122     configdialog/lxqtconfigdialog.ui
123 )
124
125 file(GLOB LXQT_CONFIG_FILES resources/*.conf)
126
127 option(UPDATE_TRANSLATIONS "Update source translation translations/*.ts files" OFF)
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(lxqt-build-tools ${LXQTBT_MINIMUM_VERSION} REQUIRED)
136 find_package(X11 REQUIRED QUIET)
137 find_package(Qt5 ${QT_MINIMUM_VERSION} CONFIG REQUIRED Widgets DBus X11Extras LinguistTools)
138 find_package(Qt5Xdg ${QTXDG_MINIMUM_VERSION} REQUIRED)
139 find_package(KF5WindowSystem REQUIRED QUIET)
140 message(STATUS "Building ${PROJECT_NAME} with Qt ${Qt5Core_VERSION}")
141
142 QT5_ADD_DBUS_INTERFACE(DBUS_INTERFACE_SRCS
143     dbus/org.freedesktop.Notifications.xml
144     notifications_interface
145 )
146
147 QT5_ADD_DBUS_ADAPTOR(DBUS_ADAPTOR_SRCS
148     dbus/org.lxqt.SingleApplication.xml
149     lxqtsingleapplication.h LXQt::SingleApplication
150 )
151
152 set_property(SOURCE ${DBUS_INTERFACE_SRCS} ${DBUS_ADAPTOR_SRCS} PROPERTY SKIP_AUTOGEN ON)
153 list(APPEND SRCS "${DBUS_INTERFACE_SRCS}" "${DBUS_ADAPTOR_SRCS}")
154
155 # KF5WindowSystem is missing here. KF5WindowSystem doesn't provide an .pc file.
156 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}")
157
158
159 # Standard directories for installation
160 include(LXQtCompilerSettings NO_POLICY_SCOPE)
161 include(LXQtCreatePkgConfigFile)
162 include(LXQtCreatePortableHeaders)
163 include(LXQtConfigVars)
164
165 set(LXQT_INTREE_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/include")
166
167 set(LXQT_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}/${LXQT_LIBRARY_NAME}")
168 set(LXQT_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_FULL_DATAROOTDIR}/cmake")
169
170
171 ## Translations
172 include(LXQtTranslateTs)
173
174 lxqt_translate_ts(QM_FILES
175     UPDATE_TRANSLATIONS
176         ${UPDATE_TRANSLATIONS}
177     SOURCES
178         ${SRCS}
179         ${FORMS}
180     INSTALL_DIR
181         "${LXQT_TRANSLATIONS_DIR}/${PROJECT_NAME}"
182     PULL_TRANSLATIONS
183         ${PULL_TRANSLATIONS}
184     CLEAN_TRANSLATIONS
185         ${CLEAN_TRANSLATIONS}
186     TRANSLATIONS_REPO
187         ${TRANSLATIONS_REPO}
188     TRANSLATIONS_REFSPEC
189         ${TRANSLATIONS_REFSPEC}
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 lxqt_create_portable_headers(INTREE_PORTABLE_HEADERS
205     NAME_PREFIX "lxqt"
206     OUTPUT_DIR "${LXQT_INTREE_INCLUDE_DIR}/LXQt"
207     HEADER_NAMES ${PUBLIC_CLASSES}
208 )
209
210 #check_portable_headers(H_FILES ${PUB_HDRS} LINKS "${INTREE_PORTABLE_HEADERS}")
211
212 #************************************************
213 # Create in-tree build infrastructure
214 #************************************************
215 set(CFG_LXQT_TARGETS_FILE   "${LXQT_INTREE_TARGETS_FILE}")
216
217 configure_package_config_file(
218     "${CMAKE_CURRENT_SOURCE_DIR}/cmake/lxqt-config.cmake.in"
219     "${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}-config.cmake"
220     INSTALL_DESTINATION "neverland"     # required, altough we don't install it
221 )
222
223 #************************************************
224 # Create installable build infrastructure
225 #************************************************
226 set(CFG_LXQT_TARGETS_FILE "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/${LXQT_LIBRARY_NAME}-targets.cmake")
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 add_library(${LXQT_LIBRARY_NAME}
254     SHARED ${PUB_HDRS}
255            ${SRCS}
256            ${dbus_generated}
257            ${UIS} ${MOCS}
258            ${QM_FILES}
259            ${QRC_CXX_SOURCES}
260
261 )
262
263 target_link_libraries(${LXQT_LIBRARY_NAME}
264     PUBLIC
265         KF5::WindowSystem
266         Qt5::Widgets
267         Qt5::DBus
268         Qt5::X11Extras
269         Qt5Xdg
270     PRIVATE
271         ${X11_Xscreensaver_LIB}
272         ${X11_X11_LIB}
273 )
274
275 set_target_properties(${LXQT_LIBRARY_NAME} PROPERTIES
276     VERSION   ${LXQT_VERSION}
277     SOVERSION ${LXQT_MAJOR_VERSION}
278 )
279
280 target_compile_definitions(${LXQT_LIBRARY_NAME}
281     PRIVATE
282         "LXQT_RELATIVE_SHARE_DIR=\"${LXQT_RELATIVE_SHARE_DIR}\""
283         "LXQT_SHARE_DIR=\"${LXQT_SHARE_DIR}\""
284         "LXQT_RELATIVE_SHARE_TRANSLATIONS_DIR=\"${LXQT_RELATIVE_TRANSLATIONS_DIR}\""
285         "LXQT_SHARE_TRANSLATIONS_DIR=\"${LXQT_TRANSLATIONS_DIR}\""
286         "LXQT_GRAPHICS_DIR=\"${LXQT_GRAPHICS_DIR}\""
287         "LXQT_ETC_XDG_DIR=\"${LXQT_ETC_XDG_DIR}\""
288         "LXQT_DATA_DIR=\"${LXQT_DATA_DIR}\""
289         "LXQT_INSTALL_PREFIX=\"${CMAKE_INSTALL_PREFIX}\""
290         "LXQT_VERSION=\"${LXQT_VERSION}\""
291         "COMPILE_LIBLXQT"
292         "QT_NO_FOREACH"
293         "$<$<CONFIG:Release>:QT_NO_DEBUG_OUTPUT>"
294         "$<$<CONFIG:Release>:QT_NO_WARNING_OUTPUT>"
295 )
296
297 if (Qt5Core_VERSION VERSION_LESS "5.9.0")
298     if (NOT DEFINED WITH_XDG_DIRS_FALLBACK)
299         set(WITH_XDG_DIRS_FALLBACK ON)
300     endif ()
301 elseif (WITH_XDG_DIRS_FALLBACK)
302     set(WITH_XDG_DIRS_FALLBACK OFF)
303     message(WARNING "Disabling requested WITH_XDG_DIRS_FALLBACK workaround, as proper implementation is in Qt from v5.9.0")
304 endif ()
305 if (WITH_XDG_DIRS_FALLBACK)
306     message(STATUS "Building with homemade QSettings XDG fallback workaround")
307     target_compile_definitions(${LXQT_LIBRARY_NAME}
308         PRIVATE "WITH_XDG_DIRS_FALLBACK"
309     )
310 endif ()
311
312 target_include_directories(${LXQT_LIBRARY_NAME}
313     INTERFACE
314         "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${LXQT_LIBRARY_NAME}>"
315         "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${LXQT_LIBRARY_NAME}/LXQt>"
316         "$<BUILD_INTERFACE:${LXQT_INTREE_INCLUDE_DIR}>"
317         "$<BUILD_INTERFACE:${LXQT_INTREE_INCLUDE_DIR}/LXQt>"
318 )
319
320 install(TARGETS
321     ${LXQT_LIBRARY_NAME}
322     DESTINATION "${CMAKE_INSTALL_LIBDIR}"
323     EXPORT ${LXQT_LIBRARY_NAME}-targets
324     LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
325     COMPONENT Runtime
326 )
327
328 install(FILES
329     ${PUB_HDRS}
330     DESTINATION "${LXQT_INSTALL_INCLUDE_DIR}/LXQt"
331     COMPONENT Devel
332 )
333
334 install(FILES
335     ${INTREE_PORTABLE_HEADERS}
336     DESTINATION "${LXQT_INSTALL_INCLUDE_DIR}/LXQt"
337     COMPONENT Devel
338 )
339
340 install(FILES ${LXQT_CONFIG_FILES}
341     DESTINATION "${CMAKE_INSTALL_FULL_DATADIR}/lxqt"
342     COMPONENT Runtime
343 )
344
345 #************************************************
346 # Create and install pkgconfig file
347 #************************************************
348 lxqt_create_pkgconfig_file(
349     PACKAGE_NAME ${LXQT_LIBRARY_NAME}
350     DESCRIPTIVE_NAME ${LXQT_LIBRARY_NAME}
351     DESCRIPTION ${LXQT_PKG_CONFIG_DESCRIPTION}
352     INCLUDEDIRS ${LXQT_LIBRARY_NAME}
353     LIBS ${LXQT_LIBRARY_NAME}
354     REQUIRES ${LXQT_PKG_CONFIG_REQUIRES}
355     VERSION ${LXQT_VERSION}
356     INSTALL
357 )
358 #************************************************