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