Settings: unify duplicated code
[lxde/liblxqt.git] / CMakeLists.txt
CommitLineData
a1aa2bec 1cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
0eff6363 2
af223b3d 3project(liblxqt)
0eff6363 4
af223b3d 5set(LXQT_MAJOR_VERSION 0)
3cf73843 6set(LXQT_MINOR_VERSION 10)
948bc69d 7set(LXQT_PATCH_VERSION 0)
0eff6363 8
4f07364e 9include(CMakePackageConfigHelpers)
06d4bbb6
LP
10include(GNUInstallDirs) # Standard directories for installation
11
06d4bbb6
LP
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#-----------------------------------------------------------------------------
17if (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 )
21endif()
22
ac768bbc
LP
23#-----------------------------------------------------------------------------
24# Release is the default build type
25#-----------------------------------------------------------------------------
26if (NOT CMAKE_BUILD_TYPE)
27 set(CMAKE_BUILD_TYPE Release)
28endif()
29
eedae82c 30set(LXQT_PKG_CONFIG_DESCRIPTION "Shared library for LXQt applications")
0eff6363 31
af223b3d 32set(PUB_HDRS
3e7b0203 33 lxqthtmldelegate.h
82830dc2 34 lxqtsettings.h
191d2d13 35 lxqtplugininfo.h
b6483430 36 lxqtpowermanager.h
b6483430 37 lxqtscreensaver.h
077c1e76 38 lxqtapplication.h
7e7ee62a 39 lxqtsingleapplication.h
949dba2f 40 lxqttranslator.h
b6483430 41 lxqtprogramfinder.h
ad7ee7e8 42
b6483430
AS
43 configdialog/lxqtconfigdialog.h
44 configdialog/lxqtpageselectwidget.h
ad7ee7e8 45
8e6db58a 46 lxqtpower/lxqtpower.h
0e4fbf35 47 lxqtnotification.h
739b8f7f 48 lxqtautostartentry.h
f9de00b4 49 lxqtgridlayout.h
b6483430 50 lxqtrotatedwidget.h
f9cba1ba 51 lxqtglobals.h
4ef6cee9 52)
53
b6483430 54set(PUBLIC_CLASSES
3e7b0203 55 HtmlDelegate
f324ccfb 56 Settings
f324ccfb
AS
57 PluginInfo
58 PowerManager
f324ccfb
AS
59 ScreenSaver
60 Application
7e7ee62a 61 SingleApplication
f324ccfb
AS
62 Translator
63 ProgramFinder
64
65 ConfigDialog
66 PageSelectWidget
67
68 Power
69 Notification
70 AutostartEntry
71 GridLayout
72 RotatedWidget
af223b3d
AS
73)
74
af223b3d 75set(SRCS
3e7b0203 76 lxqthtmldelegate.cpp
191d2d13 77 lxqtplugininfo.cpp
b6483430 78 lxqtpowermanager.cpp
82830dc2 79 lxqtsettings.cpp
b6483430 80 lxqtscreensaver.cpp
077c1e76 81 lxqtapplication.cpp
7e7ee62a 82 lxqtsingleapplication.cpp
949dba2f 83 lxqttranslator.cpp
b6483430 84 lxqtprogramfinder.cpp
ad7ee7e8 85
b6483430
AS
86 configdialog/lxqtconfigdialog.cpp
87 configdialog/lxqtpageselectwidget.cpp
ad7ee7e8 88
8e6db58a
AS
89 lxqtpower/lxqtpower.cpp
90 lxqtpower/lxqtpowerproviders.cpp
739b8f7f 91 lxqtautostartentry.cpp
b11ac14c 92 lxqtnotification.cpp
f9de00b4 93 lxqtgridlayout.cpp
b6483430 94 lxqtrotatedwidget.cpp
4ef6cee9 95)
96
af223b3d 97set(MOCS
3e7b0203 98 lxqthtmldelegate.h
b11ac14c 99 lxqtpowermanager.h
82830dc2 100 lxqtsettings.h
b6483430 101 lxqtscreensaver.h
077c1e76 102 lxqtapplication.h
ad7ee7e8 103
b6483430
AS
104 configdialog/lxqtconfigdialog.h
105 configdialog/lxqtpageselectwidget.h
ad7ee7e8 106
0e4fbf35
AS
107 lxqtnotification.h
108 lxqtnotification_p.h
8e6db58a
AS
109 lxqtpower/lxqtpower.h
110 lxqtpower/lxqtpowerproviders.h
f9de00b4 111 lxqtgridlayout.h
b6483430 112 lxqtrotatedwidget.h
4ef6cee9 113)
114
af223b3d 115set(FORMS
b6483430 116 configdialog/lxqtconfigdialog.ui
af223b3d
AS
117)
118
b6483430 119# additional cmake files
bffeaa1c 120list(APPEND CMAKE_MODULE_PATH
e2eb0f8e
LP
121 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
122 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
08f726f3 123 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/find-modules"
bffeaa1c 124)
af223b3d 125
fd3dee16 126option(UPDATE_TRANSLATIONS "Update source translation translations/*.ts files" OFF)
8c931cd4 127
afd3b116
JL
128set(CMAKE_INCLUDE_CURRENT_DIR ON)
129set(CMAKE_POSITION_INDEPENDENT_CODE ON)
4681206d 130
b11ac14c 131set(CMAKE_AUTOMOC ON)
92ab355b
LP
132set(CMAKE_AUTOUIC ON)
133
cd10d270 134find_package(X11 REQUIRED QUIET)
b11ac14c
JL
135find_package(Qt5Widgets REQUIRED QUIET)
136find_package(Qt5DBus REQUIRED QUIET)
137find_package(Qt5X11Extras REQUIRED QUIET)
138find_package(Qt5LinguistTools REQUIRED QUIET)
a8942b21 139find_package(Qt5Xdg REQUIRED QUIET)
7e7ee62a 140find_package(KF5WindowSystem REQUIRED QUIET)
b11ac14c
JL
141message(STATUS "Building with Qt ${Qt5Core_VERSION_STRING}")
142
b11ac14c
JL
143QT5_ADD_DBUS_INTERFACE(SRCS
144 dbus/org.freedesktop.Notifications.xml
145 notifications_interface
146)
147
7e7ee62a
LP
148QT5_ADD_DBUS_ADAPTOR(SRCS
149 dbus/org.lxqt.SingleApplication.xml
f05ba5af 150 lxqtsingleapplication.h LXQt::SingleApplication
7e7ee62a
LP
151)
152
b11ac14c 153set(LXQT_QT_VERSION "5")
7e7ee62a
LP
154
155# KF5WindowSystem is missing here. KF5WindowSystem doesn't provide an .pc file.
47934845 156set(LXQT_PKG_CONFIG_REQUIRES "Qt5Xdg >= 1.2.0, Qt5Widgets, Qt5Xml, Qt5DBus, Qt5X11Extras")
af223b3d 157
d7e822b0 158
7255c8df 159# Standard directories for installation
216edec1 160include(LXQtCompilerSettings NO_POLICY_SCOPE)
7255c8df 161include(LXQtCreatePkgConfigFile)
4f07364e
LP
162include(cmake/FindInstallConfigPath.cmake) # sets LXQT_ETC_XDG_DIR, if unset
163include(create_portable_headers)
371400de 164
af223b3d 165set(LXQT_VERSION ${LXQT_MAJOR_VERSION}.${LXQT_MINOR_VERSION}.${LXQT_PATCH_VERSION})
82ee80f9 166set(LXQT_LIBRARY_NAME "lxqt" CACHE STRING "lxqt")
51a92980 167set(LXQT_RELATIVE_SHARE_DIR "${LXQT_LIBRARY_NAME}")
e47d1cae 168set(LXQT_SHARE_DIR "${CMAKE_INSTALL_FULL_DATAROOTDIR}/${LXQT_RELATIVE_SHARE_DIR}")
51a92980
LP
169set(LXQT_RELATIVE_TRANSLATIONS_DIR "${LXQT_LIBRARY_NAME}/translations")
170set(LXQT_TRANSLATIONS_DIR "${LXQT_SHARE_DIR}/translations")
825771a5 171set(LXQT_GRAPHICS_DIR "${LXQT_SHARE_DIR}/graphics")
371400de 172
4f07364e 173set(LXQT_INTREE_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/include")
b11ac14c 174set(LXQT_INTREE_TARGETS_FILE "${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}-targets.cmake")
371400de 175
b11ac14c 176set(LXQT_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}/${LXQT_LIBRARY_NAME}")
e47d1cae 177set(LXQT_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_FULL_DATAROOTDIR}/cmake")
371400de 178
f88aabc1 179
4790513b
LP
180## Translations
181include(LXQtTranslateTs)
182
183lxqt_translate_ts(QM_FILES
184 UPDATE_TRANSLATIONS
185 ${UPDATE_TRANSLATIONS}
186 SOURCES
187 ${SRCS}
188 ${FORMS}
189 INSTALL_DIR
e2eb0f8e 190 "${LXQT_TRANSLATIONS_DIR}/${PROJECT_NAME}"
db5b3bb5
PK
191 PULL_TRANSLATIONS
192 ${PULL_TRANSLATIONS}
193 CLEAN_TRANSLATIONS
194 ${CLEAN_TRANSLATIONS}
195 TRANSLATIONS_REPO
196 ${TRANSLATIONS_REPO}
197 TRANSLATIONS_REFSPEC
198 ${TRANSLATIONS_REFSPEC}
4790513b
LP
199)
200
af223b3d
AS
201message(STATUS "")
202message(STATUS "liblxqt version: ${LXQT_VERSION}")
203message(STATUS "")
204
205
371400de
AS
206# Copy public headers
207foreach(h ${PUB_HDRS})
208 get_filename_component(bh ${h} NAME)
b11ac14c 209 configure_file(${h} "${LXQT_INTREE_INCLUDE_DIR}/LXQt/${bh}" COPYONLY)
371400de
AS
210endforeach()
211
212# Create the portable headers
e2eb0f8e
LP
213create_portable_headers(INTREE_PORTABLE_HEADERS "${LXQT_INTREE_INCLUDE_DIR}/LXQt" ${PUBLIC_CLASSES})
214check_portable_headers(H_FILES ${PUB_HDRS} LINKS "${INTREE_PORTABLE_HEADERS}")
371400de 215
af223b3d 216#************************************************
f324ccfb 217# Create in-tree build infrastructure
af223b3d 218#************************************************
e2eb0f8e 219set(CFG_LXQT_TARGETS_FILE "${LXQT_INTREE_TARGETS_FILE}")
c8a513bd 220set(CFG_LXQT_CMAKE_MODULES_DIR "${PROJECT_SOURCE_DIR}/cmake/modules")
08f726f3
LP
221set(CFG_LXQT_CMAKE_FIND_MODULES_DIR "${PROJECT_SOURCE_DIR}/cmake/find-modules")
222
af223b3d 223
4f07364e
LP
224configure_package_config_file(
225 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/lxqt-config.cmake.in"
226 "${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}-config.cmake"
227 INSTALL_DESTINATION "neverland" # required, altough we don't install it
371400de
AS
228)
229
af223b3d 230#************************************************
b11ac14c 231# Create installable build infrastructure
af223b3d 232#************************************************
b11ac14c 233set(CFG_LXQT_TARGETS_FILE "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/${LXQT_LIBRARY_NAME}-targets.cmake")
c8a513bd 234set(CFG_LXQT_CMAKE_MODULES_DIR "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/modules")
08f726f3 235set(CFG_LXQT_CMAKE_FIND_MODULES_DIR "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/find-modules")
949dba2f 236
4f07364e
LP
237configure_package_config_file(
238 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/lxqt-config.cmake.in"
b11ac14c 239 "${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}-config.cmake"
4f07364e 240 INSTALL_DESTINATION "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}"
4681206d 241)
f88aabc1 242
4f07364e
LP
243write_basic_package_version_file(
244 "${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}-config-version.cmake"
245 VERSION ${LXQT_VERSION}
246 COMPATIBILITY AnyNewerVersion
f324ccfb 247)
f88aabc1 248
96a82211 249install(FILES
4f07364e
LP
250 "${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}-config.cmake"
251 "${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}-config-version.cmake"
e2eb0f8e 252 DESTINATION "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}"
371400de
AS
253 COMPONENT Devel
254)
af223b3d 255
96a82211 256install(EXPORT
371400de 257 ${LXQT_LIBRARY_NAME}-targets
761d737e 258 DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${LXQT_LIBRARY_NAME}"
371400de
AS
259 COMPONENT Devel
260)
a28cd05a 261
08f726f3
LP
262file(GLOB toInstallFindModules
263 "${PROJECT_SOURCE_DIR}/cmake/find-modules/*.cmake"
264)
265
266install(
267 FILES ${toInstallFindModules}
268 DESTINATION "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/find-modules"
269 COMPONENT Devel
270)
271
d2ff6c6b
LP
272file(GLOB toInstallModules
273 "${PROJECT_SOURCE_DIR}/cmake/modules/*.cmake"
274 "${PROJECT_SOURCE_DIR}/cmake/modules/*.in"
275)
276
c8a513bd
LP
277install(
278 FILES ${toInstallModules}
e2eb0f8e 279 DESTINATION "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/modules"
c8a513bd
LP
280 COMPONENT Devel
281)
282
371400de 283add_library(${LXQT_LIBRARY_NAME}
af223b3d 284 SHARED ${PUB_HDRS}
af223b3d
AS
285 ${SRCS}
286 ${dbus_generated}
287 ${UIS} ${MOCS}
288 ${QM_FILES}
371400de 289 ${QRC_CXX_SOURCES}
96a82211 290
af223b3d 291)
4ef6cee9 292
b11ac14c 293target_link_libraries(${LXQT_LIBRARY_NAME}
9b02d1a8
LP
294 PUBLIC
295 KF5::WindowSystem
296 Qt5::Widgets
297 Qt5::DBus
298 Qt5::X11Extras
299 Qt5Xdg
cd10d270
LP
300 PRIVATE
301 ${X11_Xscreensaver_LIB}
302 ${X11_X11_LIB}
b11ac14c 303)
2d13fe11 304
371400de 305set_target_properties(${LXQT_LIBRARY_NAME} PROPERTIES
af223b3d
AS
306 VERSION ${LXQT_VERSION}
307 SOVERSION ${LXQT_MAJOR_VERSION}
4ef6cee9 308)
309
0a6fef0b
LP
310target_compile_definitions(${LXQT_LIBRARY_NAME}
311 PRIVATE "LXQT_RELATIVE_SHARE_DIR=\"${LXQT_RELATIVE_SHARE_DIR}\""
312 PRIVATE "LXQT_SHARE_DIR=\"${LXQT_SHARE_DIR}\""
313 PRIVATE "LXQT_RELATIVE_SHARE_TRANSLATIONS_DIR=\"${LXQT_RELATIVE_TRANSLATIONS_DIR}\""
314 PRIVATE "LXQT_SHARE_TRANSLATIONS_DIR=\"${LXQT_TRANSLATIONS_DIR}\""
825771a5 315 PRIVATE "LXQT_GRAPHICS_DIR=\"${LXQT_GRAPHICS_DIR}\""
0a6fef0b
LP
316 PRIVATE "LXQT_ETC_XDG_DIR=\"${LXQT_ETC_XDG_DIR}\""
317 PRIVATE "LXQT_DATA_DIR=\"${LXQT_DATA_DIR}\""
26f76c3e 318 PRIVATE "LXQT_INSTALL_PREFIX=\"${CMAKE_INSTALL_PREFIX}\""
0a6fef0b
LP
319 PRIVATE "LXQT_VERSION=\"${LXQT_VERSION}\""
320 PRIVATE "COMPILE_LIBLXQT"
321)
322
323target_compile_definitions(${LXQT_LIBRARY_NAME}
324 PRIVATE "$<$<CONFIG:Release>:QT_NO_DEBUG_OUTPUT>"
325 PRIVATE "$<$<CONFIG:Release>:QT_NO_WARNING_OUTPUT>"
326)
327
4f07364e
LP
328target_include_directories(${LXQT_LIBRARY_NAME}
329 INTERFACE "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${LXQT_LIBRARY_NAME}>"
330 INTERFACE "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${LXQT_LIBRARY_NAME}/LXQt>"
331)
332
333target_include_directories(${LXQT_LIBRARY_NAME}
334 INTERFACE "$<BUILD_INTERFACE:${LXQT_INTREE_INCLUDE_DIR}>"
335 INTERFACE "$<BUILD_INTERFACE:${LXQT_INTREE_INCLUDE_DIR}/LXQt>"
336)
337
96a82211
JL
338install(TARGETS
339 ${LXQT_LIBRARY_NAME}
e2eb0f8e 340 DESTINATION "${CMAKE_INSTALL_LIBDIR}"
371400de 341 EXPORT ${LXQT_LIBRARY_NAME}-targets
e2eb0f8e 342 LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
19b97322 343 COMPONENT Runtime
371400de
AS
344)
345
eef4da0c
LP
346export(TARGETS ${LXQT_LIBRARY_NAME}
347 APPEND FILE "${LXQT_INTREE_TARGETS_FILE}"
348 EXPORT_LINK_INTERFACE_LIBRARIES
349)
f324ccfb 350
19b97322
LP
351install(FILES
352 ${PUB_HDRS}
353 DESTINATION "${LXQT_INSTALL_INCLUDE_DIR}/LXQt"
354 COMPONENT Devel
355)
356
357install(FILES
358 ${INTREE_PORTABLE_HEADERS}
359 DESTINATION "${LXQT_INSTALL_INCLUDE_DIR}/LXQt"
360 COMPONENT Devel
361)
af223b3d 362
371400de 363#************************************************
7255c8df 364# Create and install pkgconfig file
371400de 365#************************************************
7255c8df
LP
366lxqt_create_pkgconfig_file(
367 PACKAGE_NAME ${LXQT_LIBRARY_NAME}
368 DESCRIPTIVE_NAME ${LXQT_LIBRARY_NAME}
369 DESCRIPTION ${LXQT_PKG_CONFIG_DESCRIPTION}
370 INCLUDEDIRS ${LXQT_LIBRARY_NAME}
371 LIBS ${LXQT_LIBRARY_NAME}
372 REQUIRES ${LXQT_PKG_CONFIG_REQUIRES}
373 VERSION ${LXQT_VERSION}
374 INSTALL
388b7976 375)
371400de 376#************************************************
4ef6cee9 377
7c6da487
HJYP
378
379# building tarball with CPack -------------------------------------------------
b11ac14c
JL
380include(InstallRequiredSystemLibraries)
381set(CPACK_PACKAGE_VERSION_MAJOR ${LXQT_MAJOR_VERSION})
382set(CPACK_PACKAGE_VERSION_MINOR ${LXQT_MINOR_VERSION})
383set(CPACK_PACKAGE_VERSION_PATCH ${LXQT_PATCH_VERSION})
384set(CPACK_GENERATOR TBZ2)
385set(CPACK_SOURCE_GENERATOR TBZ2)
386set(CPACK_SOURCE_IGNORE_FILES /build/;.gitignore;.*~;.git;.kdev4;temp)
387include(CPack)
63cf48aa 388