936a9dfdfe1b84d3d0c881cbe6e24b09413d876c
[lxde/liblxqt.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8.9)
2
3 project(liblxqt)
4
5 set(LXQT_MAJOR_VERSION 0)
6 set(LXQT_MINOR_VERSION 8)
7 set(LXQT_PATCH_VERSION 0)
8
9 # Set default installation paths
10 set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}" CACHE PATH "Installation path for libraries")
11 set(LXQT_PKG_CONFIG_DESCRIPTION "Shared library for LXQt applications")
12
13 set(PUB_HDRS
14     aboutdialog/lxqtaboutdialog.h
15     addplugindialog/lxqtaddplugindialog.h
16     lxqthtmldelegate.h
17     lxqtsettings.h
18     lxqtplugininfo.h
19     lxqtpowermanager.h
20     lxqtscreensaver.h
21     lxqtapplication.h
22     lxqttranslator.h
23     lxqtprogramfinder.h
24
25     configdialog/lxqtconfigdialog.h
26     configdialog/lxqtpageselectwidget.h
27
28     lxqtpower/lxqtpower.h
29     lxqtnotification.h
30     lxqtautostartentry.h
31     lxqtgridlayout.h
32     lxqtrotatedwidget.h
33     lxqtglobals.h
34 )
35
36 set(PUBLIC_CLASSES
37     AboutDialog
38     HtmlDelegate
39     Settings
40     PluginInfo
41     PowerManager
42     AddPluginDialog
43     ScreenSaver
44     Application
45     Translator
46     ProgramFinder
47
48     ConfigDialog
49     PageSelectWidget
50
51     Power
52     Notification
53     AutostartEntry
54     GridLayout
55     RotatedWidget
56 )
57
58 set(PRIV_HDRS
59     aboutdialog/lxqtaboutdialog_p.h
60     aboutdialog/technicalinfo.h
61     translatorsinfo/translatorsinfo.h
62 )
63
64 set(SRCS
65     aboutdialog/lxqtaboutdialog.cpp
66     aboutdialog/technicalinfo.cpp
67     lxqthtmldelegate.cpp
68     lxqtplugininfo.cpp
69     lxqtpowermanager.cpp
70     addplugindialog/lxqtaddplugindialog.cpp
71     lxqtsettings.cpp
72     lxqtscreensaver.cpp
73     lxqtapplication.cpp
74     lxqttranslator.cpp
75     lxqtprogramfinder.cpp
76
77     configdialog/lxqtconfigdialog.cpp
78     configdialog/lxqtpageselectwidget.cpp
79
80     lxqtpower/lxqtpower.cpp
81     lxqtpower/lxqtpowerproviders.cpp
82     lxqtautostartentry.cpp
83     lxqtnotification.cpp
84     lxqtgridlayout.cpp
85     lxqtrotatedwidget.cpp
86     translatorsinfo/translatorsinfo.cpp
87 )
88
89 set(MOCS
90     aboutdialog/lxqtaboutdialog.h
91     aboutdialog/lxqtaboutdialog_p.h
92     addplugindialog/lxqtaddplugindialog.h
93     lxqthtmldelegate.h
94     lxqtpowermanager.h
95     lxqtsettings.h
96     lxqtscreensaver.h
97     lxqtapplication.h
98
99     configdialog/lxqtconfigdialog.h
100     configdialog/lxqtpageselectwidget.h
101
102     lxqtnotification.h
103     lxqtnotification_p.h
104     lxqtpower/lxqtpower.h
105     lxqtpower/lxqtpowerproviders.h
106     lxqtgridlayout.h
107     lxqtrotatedwidget.h
108 )
109
110 set(FORMS
111     aboutdialog/lxqtaboutdialog.ui
112     configdialog/lxqtconfigdialog.ui
113     addplugindialog/lxqtaddplugindialog.ui
114 )
115
116 set(TRANSLATION_TEMPLATE "${CMAKE_CURRENT_SOURCE_DIR}/translations/source.ts")
117 file(GLOB TS_FILES
118     "${CMAKE_CURRENT_SOURCE_DIR}/translations/liblxqt_*.ts"
119 )
120
121 # additional cmake files
122 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
123
124 option(UPDATE_TRANSLATIONS "Update source translation translations/*.ts files" OFF)
125
126 set(CMAKE_INCLUDE_CURRENT_DIR ON)
127 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
128
129 set(CMAKE_AUTOMOC ON)
130 find_package(Qt5Widgets REQUIRED QUIET)
131 find_package(Qt5DBus REQUIRED QUIET)
132 find_package(Qt5X11Extras REQUIRED QUIET)
133 find_package(Qt5LinguistTools REQUIRED QUIET)
134 find_package(Qt5Xdg REQUIRED)
135 message(STATUS "Building with Qt ${Qt5Core_VERSION_STRING}")
136
137 QT5_WRAP_UI(UIS ${FORMS})
138 if (UPDATE_TRANSLATIONS)
139     qt5_create_translation(QM_FILES ${SRCS} ${FORMS} ${TS_FILES} OPTIONS -locations absolute)
140     qt5_create_translation(TS_SOURCE_FILE
141         ${SRCS} ${FORMS}
142         ${TRANSLATION_TEMPLATE}
143         OPTIONS -locations absolute
144     )
145 else()
146     QT5_ADD_TRANSLATION(QM_FILES ${TS_FILES})
147 endif()
148 QT5_ADD_DBUS_INTERFACE(SRCS
149     dbus/org.freedesktop.Notifications.xml
150     notifications_interface
151 )
152
153 set(LXQT_QT_VERSION "5")
154 set(LXQT_QT_VERSION_SUFFIX "-qt5")
155 set(LXQT_PKG_CONFIG_REQUIRES "Qt5Widgets Qt5Xml Qt5DBus Qt5X11Extras")
156
157 include(${QTXDG_USE_FILE})
158
159 include_directories(
160     "${QTXDG_INCLUDE_DIRS}"
161 )
162
163 # Standard directories for installation
164 include(GNUInstallDirs)
165
166 set(LXQT_VERSION ${LXQT_MAJOR_VERSION}.${LXQT_MINOR_VERSION}.${LXQT_PATCH_VERSION})
167 set(LXQT_LIBRARY_NAME "lxqt${LXQT_QT_VERSION_SUFFIX}")
168 set(LXQT_RELATIVE_SHARE_DIR "${LXQT_LIBRARY_NAME}")
169 set(LXQT_SHARE_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_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
173 set(LXQT_INTREE_INCLUDE_DIR "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/include")
174 set(LXQT_INTREE_TARGETS_FILE "${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}-targets.cmake")
175
176 set(LXQT_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}/${LXQT_LIBRARY_NAME}")
177 set(LXQT_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_PREFIX}/share/cmake")
178
179 include(cmake/FindInstallConfigPath.cmake)
180 include(create_portable_headers)
181
182 message(STATUS "")
183 message(STATUS "liblxqt version: ${LXQT_VERSION}")
184 message(STATUS "")
185
186
187 # Copy public headers
188 foreach(h ${PUB_HDRS})
189     get_filename_component(bh ${h} NAME)
190     configure_file(${h} "${LXQT_INTREE_INCLUDE_DIR}/LXQt/${bh}" COPYONLY)
191 endforeach()
192
193 # Create the portable headers
194 create_portable_headers(INTREE_PORTABLE_HEADERS ${LXQT_INTREE_INCLUDE_DIR}/LXQt ${PUBLIC_CLASSES})
195 check_portable_headers(H_FILES ${PUB_HDRS} LINKS ${INTREE_PORTABLE_HEADERS})
196
197 #************************************************
198 # Create in-tree build infrastructure
199 #************************************************
200 set(CFG_LXQT_INCLUDE_DIR    ${LXQT_INTREE_INCLUDE_DIR})
201 set(CFG_LXQT_LIBRARY        ${LXQT_LIBRARY_NAME})
202 set(CFG_LXQT_USE_FILE       ${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}_use.cmake)
203 set(CFG_LXQT_TARGETS_FILE   ${LXQT_INTREE_TARGETS_FILE})
204 set(CFG_LXQT_CMAKE_MODULES_DIR "${PROJECT_SOURCE_DIR}/cmake/modules")
205
206 configure_file(
207     ${CMAKE_CURRENT_SOURCE_DIR}/cmake/lxqtX-config.cmake.in
208     ${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}-config.cmake
209     @ONLY
210 )
211
212 configure_file(
213     ${CMAKE_CURRENT_SOURCE_DIR}/cmake/lxqt_use.cmake.in
214     ${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}_use.cmake
215     @ONLY
216 )
217
218 include(${CFG_LXQT_USE_FILE})
219
220
221 #************************************************
222 # Create installable build infrastructure
223 #************************************************
224 set(CFG_LXQT_INCLUDE_DIR "${LXQT_INSTALL_INCLUDE_DIR}")
225 set(CFG_LXQT_LIBRARY ${LXQT_LIBRARY_NAME})
226 set(CFG_LXQT_USE_FILE "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/${LXQT_LIBRARY_NAME}_use.cmake")
227 set(CFG_LXQT_TARGETS_FILE "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/${LXQT_LIBRARY_NAME}-targets.cmake")
228 set(CFG_LXQT_CMAKE_MODULES_DIR "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/modules")
229
230 configure_file(
231     "${CMAKE_CURRENT_SOURCE_DIR}/cmake/lxqtX-config.cmake.in"
232     "${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}-config.cmake"
233     @ONLY
234 )
235
236 # use gcc visibility feature to decrease unnecessary exported symbols
237 if (CMAKE_COMPILER_IS_GNUCXX)
238     # set visibility to hidden to hide symbols, unlesss they're exported
239     # manually in the code
240     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden -fno-exceptions -Wl,-no-undefined -Wall")
241 endif()
242 add_definitions(-DCOMPILE_LIBLXQT)
243
244
245 configure_file(
246     ${CMAKE_CURRENT_SOURCE_DIR}/cmake/lxqt_use.cmake.in
247     ${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}_use.cmake
248     @ONLY
249 )
250
251 install(FILES
252     ${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}-config.cmake
253     ${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}_use.cmake
254     DESTINATION ${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}
255     COMPONENT Devel
256 )
257
258 install(EXPORT
259     ${LXQT_LIBRARY_NAME}-targets
260     DESTINATION ${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}
261     COMPONENT Devel
262 )
263
264 file(GLOB toInstallModules
265     "${PROJECT_SOURCE_DIR}/cmake/modules/*.cmake"
266     "${PROJECT_SOURCE_DIR}/cmake/modules/*.in"
267 )
268
269 install(
270     FILES ${toInstallModules}
271     DESTINATION  "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/modules"
272     COMPONENT Devel
273 )
274
275
276 include(translatorsinfo/CMakeLists.txt)
277 get_translatorsinfo_qrc(translatorsinfo_qrc)
278 qt5_add_resources(QRC_CXX_SOURCES ${translatorsinfo_qrc})
279
280 add_library(${LXQT_LIBRARY_NAME}
281     SHARED ${PUB_HDRS}
282            ${PRIV_HDRS}
283            ${SRCS}
284            ${dbus_generated}
285            ${UIS} ${MOCS}
286            ${QM_FILES}
287            ${TS_SOURCE_FILE}
288            ${QRC_CXX_SOURCES}
289
290 )
291
292 qt5_use_modules(${LXQT_LIBRARY_NAME} Widgets DBus X11Extras)
293 target_link_libraries(${LXQT_LIBRARY_NAME}
294     ${QTXDG_LIBRARIES}
295 )
296
297 set_target_properties(${LXQT_LIBRARY_NAME} PROPERTIES
298     VERSION   ${LXQT_VERSION}
299     SOVERSION ${LXQT_MAJOR_VERSION}
300 )
301
302 install(TARGETS
303     ${LXQT_LIBRARY_NAME}
304     DESTINATION ${CMAKE_INSTALL_LIBDIR}
305     EXPORT ${LXQT_LIBRARY_NAME}-targets
306     LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
307 )
308
309
310 export(TARGETS ${LXQT_LIBRARY_NAME} ${QTXDG_TARGET} FILE ${LXQT_INTREE_TARGETS_FILE})
311
312 install(FILES ${PUB_HDRS} DESTINATION "${LXQT_INSTALL_INCLUDE_DIR}/LXQt")
313 install(FILES ${INTREE_PORTABLE_HEADERS} DESTINATION "${LXQT_INSTALL_INCLUDE_DIR}/LXQt")
314 install(FILES ${QM_FILES} DESTINATION "${LXQT_TRANSLATIONS_DIR}/liblxqt")
315
316 #************************************************
317 # Create pkgconfig file
318 #************************************************
319 lxqt_create_pkgconfig_file(${LXQT_LIBRARY_NAME}
320     ${LXQT_PKG_CONFIG_DESCRIPTION}
321     ${LXQT_PKG_CONFIG_REQUIRES}
322     ${LXQT_LIBRARY_NAME}
323     ${LXQT_VERSION}
324 )
325 #************************************************
326
327
328 # building tarball with CPack -------------------------------------------------
329 include(InstallRequiredSystemLibraries)
330 set(CPACK_PACKAGE_VERSION_MAJOR ${LXQT_MAJOR_VERSION})
331 set(CPACK_PACKAGE_VERSION_MINOR ${LXQT_MINOR_VERSION})
332 set(CPACK_PACKAGE_VERSION_PATCH ${LXQT_PATCH_VERSION})
333 set(CPACK_GENERATOR TBZ2)
334 set(CPACK_SOURCE_GENERATOR TBZ2)
335 set(CPACK_SOURCE_IGNORE_FILES /build/;.gitignore;.*~;.git;.kdev4;temp)
336 include(CPack)