Adds the LXQtranslateTs cmake module
[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     lxqtsettings.h
17     lxqtxfitman.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     Settings
39     XfitMan
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     lxqtxfitman.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     lxqtpowermanager.h
94     lxqtsettings.h
95     lxqtscreensaver.h
96     lxqtapplication.h
97
98     configdialog/lxqtconfigdialog.h
99     configdialog/lxqtpageselectwidget.h
100
101     lxqtnotification.h
102     lxqtnotification_p.h
103     lxqtpower/lxqtpower.h
104     lxqtpower/lxqtpowerproviders.h
105     lxqtgridlayout.h
106     lxqtrotatedwidget.h
107 )
108
109 set(FORMS
110     aboutdialog/lxqtaboutdialog.ui
111     configdialog/lxqtconfigdialog.ui
112     addplugindialog/lxqtaddplugindialog.ui
113 )
114
115 set(TRANSLATION_TEMPLATE "${CMAKE_CURRENT_SOURCE_DIR}/translations/source.ts")
116 file(GLOB TS_FILES
117     "${CMAKE_CURRENT_SOURCE_DIR}/translations/liblxqt_*.ts"
118 )
119
120 # additional cmake files
121 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
122
123 option(UPDATE_TRANSLATIONS "Update source translation translations/*.ts files")
124
125 set(CMAKE_INCLUDE_CURRENT_DIR ON)
126 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
127
128 set(CMAKE_AUTOMOC ON)
129 find_package(Qt5Widgets REQUIRED QUIET)
130 find_package(Qt5DBus REQUIRED QUIET)
131 find_package(Qt5X11Extras REQUIRED QUIET)
132 find_package(Qt5LinguistTools REQUIRED QUIET)
133 find_package(Qt5Xdg REQUIRED)
134 message(STATUS "Building with Qt ${Qt5Core_VERSION_STRING}")
135
136 QT5_WRAP_UI(UIS ${FORMS})
137 if (UPDATE_TRANSLATIONS)
138     qt5_create_translation(QM_FILES ${SRCS} ${FORMS} ${TS_FILES} OPTIONS -locations absolute)
139     qt5_create_translation(TS_SOURCE_FILE
140         ${SRCS} ${FORMS}
141         ${TRANSLATION_TEMPLATE}
142         OPTIONS -locations absolute
143     )
144 else()
145     QT5_ADD_TRANSLATION(QM_FILES ${TS_FILES})
146 endif()
147 QT5_ADD_DBUS_INTERFACE(SRCS
148     dbus/org.freedesktop.Notifications.xml
149     notifications_interface
150 )
151
152 set(LXQT_QT_VERSION "5")
153 set(LXQT_QT_VERSION_SUFFIX "-qt5")
154 set(LXQT_PKG_CONFIG_REQUIRES "Qt5Widgets Qt5Xml Qt5DBus Qt5X11Extras")
155
156 include(${QTXDG_USE_FILE})
157
158 find_package(X11 REQUIRED QUIET)
159
160 include_directories(
161     "${CMAKE_CURRENT_SOURCE_DIR}"
162     "${CMAKE_CURRENT_BINARY_DIR}"
163     "${X11_INCLUDE_DIR}"
164     "${QTXDG_INCLUDE_DIRS}"
165 )
166
167 # Standard directories for installation
168 include(GNUInstallDirs)
169
170 set(LXQT_VERSION ${LXQT_MAJOR_VERSION}.${LXQT_MINOR_VERSION}.${LXQT_PATCH_VERSION})
171 set(LXQT_LIBRARY_NAME "lxqt${LXQT_QT_VERSION_SUFFIX}")
172 set(LXQT_RELATIVE_SHARE_DIR "${LXQT_LIBRARY_NAME}")
173 set(LXQT_SHARE_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/${LXQT_RELATIVE_SHARE_DIR}")
174 set(LXQT_RELATIVE_TRANSLATIONS_DIR "${LXQT_LIBRARY_NAME}/translations")
175 set(LXQT_TRANSLATIONS_DIR "${LXQT_SHARE_DIR}/translations")
176
177 set(LXQT_INTREE_INCLUDE_DIR "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/include")
178 set(LXQT_INTREE_TARGETS_FILE "${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}-targets.cmake")
179
180 set(LXQT_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}/${LXQT_LIBRARY_NAME}")
181 set(LXQT_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_PREFIX}/share/cmake")
182
183 include(cmake/FindInstallConfigPath.cmake)
184 include(create_portable_headers)
185
186 message(STATUS "")
187 message(STATUS "liblxqt version: ${LXQT_VERSION}")
188 message(STATUS "")
189
190
191 # Copy public headers
192 foreach(h ${PUB_HDRS})
193     get_filename_component(bh ${h} NAME)
194     configure_file(${h} "${LXQT_INTREE_INCLUDE_DIR}/LXQt/${bh}" COPYONLY)
195 endforeach()
196
197 # Create the portable headers
198 create_portable_headers(INTREE_PORTABLE_HEADERS ${LXQT_INTREE_INCLUDE_DIR}/LXQt ${PUBLIC_CLASSES})
199 check_portable_headers(H_FILES ${PUB_HDRS} LINKS ${INTREE_PORTABLE_HEADERS})
200
201 #************************************************
202 # Create in-tree build infrastructure
203 #************************************************
204 set(CFG_LXQT_INCLUDE_DIR    ${LXQT_INTREE_INCLUDE_DIR})
205 set(CFG_LXQT_LIBRARY        ${LXQT_LIBRARY_NAME})
206 set(CFG_LXQT_USE_FILE       ${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}_use.cmake)
207 set(CFG_LXQT_TARGETS_FILE   ${LXQT_INTREE_TARGETS_FILE})
208 set(CFG_LXQT_CMAKE_MODULES_DIR "${PROJECT_SOURCE_DIR}/cmake/modules")
209
210 configure_file(
211     ${CMAKE_CURRENT_SOURCE_DIR}/cmake/lxqtX-config.cmake.in
212     ${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}-config.cmake
213     @ONLY
214 )
215
216 configure_file(
217     ${CMAKE_CURRENT_SOURCE_DIR}/cmake/lxqt_use.cmake.in
218     ${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}_use.cmake
219     @ONLY
220 )
221
222 include(${CFG_LXQT_USE_FILE})
223
224
225 #************************************************
226 # Create installable build infrastructure
227 #************************************************
228 set(CFG_LXQT_INCLUDE_DIR "${LXQT_INSTALL_INCLUDE_DIR}")
229 set(CFG_LXQT_LIBRARY ${LXQT_LIBRARY_NAME})
230 set(CFG_LXQT_USE_FILE "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/${LXQT_LIBRARY_NAME}_use.cmake")
231 set(CFG_LXQT_TARGETS_FILE "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/${LXQT_LIBRARY_NAME}-targets.cmake")
232 set(CFG_LXQT_CMAKE_MODULES_DIR "${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/modules")
233
234 configure_file(
235     "${CMAKE_CURRENT_SOURCE_DIR}/cmake/lxqtX-config.cmake.in"
236     "${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}-config.cmake"
237     @ONLY
238 )
239
240 # use gcc visibility feature to decrease unnecessary exported symbols
241 if (CMAKE_COMPILER_IS_GNUCXX)
242     # set visibility to hidden to hide symbols, unlesss they're exported
243     # manually in the code
244     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden -fno-exceptions -Wl,-no-undefined -Wall")
245 endif()
246 add_definitions(-DCOMPILE_LIBLXQT)
247
248
249 configure_file(
250     ${CMAKE_CURRENT_SOURCE_DIR}/cmake/lxqt_use.cmake.in
251     ${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}_use.cmake
252     @ONLY
253 )
254
255 install(FILES
256     ${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}-config.cmake
257     ${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}_use.cmake
258     DESTINATION ${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}
259     COMPONENT Devel
260 )
261
262 install(EXPORT
263     ${LXQT_LIBRARY_NAME}-targets
264     DESTINATION ${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}
265     COMPONENT Devel
266 )
267
268 file(GLOB toInstallModules "${PROJECT_SOURCE_DIR}/cmake/modules/*.cmake")
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     ${X11_X11_LIB}
295     ${QTXDG_LIBRARIES}
296 )
297
298 set_target_properties(${LXQT_LIBRARY_NAME} PROPERTIES
299     VERSION   ${LXQT_VERSION}
300     SOVERSION ${LXQT_MAJOR_VERSION}
301 )
302
303 install(TARGETS
304     ${LXQT_LIBRARY_NAME}
305     DESTINATION ${CMAKE_INSTALL_LIBDIR}
306     EXPORT ${LXQT_LIBRARY_NAME}-targets
307     LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
308 )
309
310
311 export(TARGETS ${LXQT_LIBRARY_NAME} ${QTXDG_TARGET} FILE ${LXQT_INTREE_TARGETS_FILE})
312
313 install(FILES ${PUB_HDRS} DESTINATION "${LXQT_INSTALL_INCLUDE_DIR}/LXQt")
314 install(FILES ${INTREE_PORTABLE_HEADERS} DESTINATION "${LXQT_INSTALL_INCLUDE_DIR}/LXQt")
315 install(FILES ${QM_FILES} DESTINATION "${LXQT_TRANSLATIONS_DIR}/liblxqt")
316
317 #************************************************
318 # Create pkgconfig file
319 #************************************************
320 lxqt_create_pkgconfig_file(${LXQT_LIBRARY_NAME}
321     ${LXQT_PKG_CONFIG_DESCRIPTION}
322     ${LXQT_PKG_CONFIG_REQUIRES}
323     ${LXQT_LIBRARY_NAME}
324     ${LXQT_VERSION}
325 )
326 #************************************************
327
328
329 # building tarball with CPack -------------------------------------------------
330 include(InstallRequiredSystemLibraries)
331 set(CPACK_PACKAGE_VERSION_MAJOR ${LXQT_MAJOR_VERSION})
332 set(CPACK_PACKAGE_VERSION_MINOR ${LXQT_MINOR_VERSION})
333 set(CPACK_PACKAGE_VERSION_PATCH ${LXQT_PATCH_VERSION})
334 set(CPACK_GENERATOR TBZ2)
335 set(CPACK_SOURCE_GENERATOR TBZ2)
336 set(CPACK_SOURCE_IGNORE_FILES /build/;.gitignore;.*~;.git;.kdev4;temp)
337 include(CPack)