Fix broken build of qt4 version
[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 7)
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     lxqtsettings.h
16     lxqtxfitman.h
17     lxqtplugininfo.h
18     lxqtpowermanager.h
19     addplugindialog/lxqtaddplugindialog.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     lxqtnotification.cpp
83     lxqtautostartentry.cpp
84     translatorsinfo/translatorsinfo.cpp
85     lxqtgridlayout.cpp
86     lxqtrotatedwidget.cpp
87 )
88
89 set(MOCS
90     aboutdialog/lxqtaboutdialog.h
91     aboutdialog/lxqtaboutdialog_p.h
92     lxqtpowermanager.h
93     addplugindialog/lxqtaddplugindialog.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 file(GLOB TS_FILES
116     ${CMAKE_CURRENT_SOURCE_DIR}/translations/liblxqt_*.ts
117 )
118
119 # additional cmake files
120 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
121
122
123 option(USE_QT5 "Force use the Qt5." $ENV{USE_QT5})
124 option(USE_QT4 "Force use the Qt4." $ENV{USE_QT4})
125
126 if((USE_QT4 AND USE_QT5) OR
127    (NOT USE_QT4 AND NOT USE_QT5))
128
129     # Autodetect Qt version
130     find_package(Qt4 QUIET)
131     if (QT4_FOUND)
132         set(USE_QT4 ON)
133         set(USE_QT5 OFF)
134     else()
135         set(USE_QT4 OFF)
136         set(USE_QT5 ON)
137     endif()
138 endif()
139
140 set(CMAKE_INCLUDE_CURRENT_DIR ON)
141 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
142
143 if(USE_QT5)
144     set(CMAKE_AUTOMOC ON)
145     find_package(Qt5Widgets REQUIRED QUIET)
146     find_package(Qt5DBus REQUIRED QUIET)
147     find_package(Qt5X11Extras REQUIRED QUIET)
148     find_package(Qt5LinguistTools REQUIRED QUIET)
149     find_package(Qt5Xdg REQUIRED)
150     message(STATUS "Building with Qt ${Qt5Core_VERSION_STRING}")
151
152     QT5_WRAP_UI(UIS ${FORMS})
153     QT5_ADD_TRANSLATION(QM_FILES ${TS_FILES})
154     QT5_ADD_DBUS_INTERFACE(SRCS
155         dbus/org.freedesktop.Notifications.xml
156         notifications_interface
157     )
158
159     set(LXQT_QT_VERSION "5")
160     set(LXQT_PKG_CONFIG_REQUIRES "Qt5Widgets Qt5Xml Qt5DBus Qt5X11Extras")
161 else()
162     find_package(Qt4 REQUIRED QtCore QtGui QUIET)
163     find_package(qtxdg REQUIRED)
164     message(STATUS "Building with Qt ${QTVERSION}")
165
166     include(${QT_USE_FILE})
167
168     QT4_WRAP_CPP(MOCS ${MOCS})
169     QT4_WRAP_UI(UIS ${FORMS})
170     QT4_ADD_TRANSLATION(QM_FILES ${TS_FILES})
171     QT4_ADD_DBUS_INTERFACE(SRCS
172         dbus/org.freedesktop.Notifications.xml
173         notifications_interface
174     )
175
176     set(LXQT_QT_VERSION "4")
177     set(LXQT_PKG_CONFIG_REQUIRES "QtCore, QtXml")
178 endif()
179
180 include(${QTXDG_USE_FILE})
181
182 find_package(X11 REQUIRED QUIET)
183
184 include_directories (
185     ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
186     ${QT_QTCORE_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR} ${QT_QTDBUS_INCLUDE_DIR}
187     ${X11_INCLUDE_DIR}
188     ${QTXDG_INCLUDE_DIRS}
189 )
190
191 # Standard directories for installation
192 include(GNUInstallDirs)
193
194 set(LXQT_VERSION ${LXQT_MAJOR_VERSION}.${LXQT_MINOR_VERSION}.${LXQT_PATCH_VERSION})
195 set(LXQT_LIBRARY_NAME "lxqt${LXQT_QT_VERSION}")
196 set(LXQT_SHARE_DIR ${CMAKE_INSTALL_PREFIX}/share/lxqt${LXQT_QT_VERSION})
197 set(LXQT_TRANSLATIONS_DIR ${LXQT_SHARE_DIR}/translations)
198
199 set(LXQT_INTREE_INCLUDE_DIR     ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/include)
200 set(LXQT_INTREE_TRAGETS_FILE    ${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}-targets.cmake)
201
202 set(LXQT_INSTALL_INCLUDE_DIR   ${CMAKE_INSTALL_FULL_INCLUDEDIR}/lxqt${LXQT_QT_VERSION})
203 set(LXQT_INSTALL_CMAKE_DIR     ${CMAKE_INSTALL_PREFIX}/share/cmake/)
204
205 include(cmake/FindInstallConfigPath.cmake)
206 include(create_portable_headers)
207
208 message(STATUS "")
209 message(STATUS "liblxqt version: ${LXQT_VERSION}")
210 message(STATUS "")
211
212
213 # Copy public headers
214 foreach(h ${PUB_HDRS})
215     get_filename_component(bh ${h} NAME)
216     configure_file(${h} ${LXQT_INTREE_INCLUDE_DIR}/LxQt/${bh} COPYONLY)
217     configure_file(${h} ${LXQT_INTREE_INCLUDE_DIR}/lxqt/${bh} COPYONLY)
218 endforeach()
219
220 # Create the portable headers
221 create_portable_headers(INTREE_PORTABLE_HEADERS ${LXQT_INTREE_INCLUDE_DIR}/LxQt ${PUBLIC_CLASSES})
222 check_portable_headers(H_FILES ${PUB_HDRS} LINKS ${INTREE_PORTABLE_HEADERS})
223
224 #************************************************
225 # Create in-tree build infrastructure
226 #************************************************
227 set(CFG_LXQT_INCLUDE_DIR    ${LXQT_INTREE_INCLUDE_DIR})
228 set(CFG_LXQT_LIBRARY        ${LXQT_LIBRARY_NAME})
229 set(CFG_LXQT_USE_FILE       ${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}_use.cmake)
230 set(CFG_LXQT_TRAGETS_FILE   ${LXQT_INTREE_TRAGETS_FILE})
231
232 configure_file(
233     ${CMAKE_CURRENT_SOURCE_DIR}/cmake/lxqtX-config.cmake.in 
234     ${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}-config.cmake
235     @ONLY
236 )
237
238 configure_file(
239     ${CMAKE_CURRENT_SOURCE_DIR}/cmake/lxqt_use.cmake.in
240     ${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}_use.cmake
241     @ONLY
242 )
243
244 include(${CFG_LXQT_USE_FILE})
245
246
247 #************************************************
248 # Create instalable build infrastructure
249 #************************************************
250 set(CFG_LXQT_INCLUDE_DIR    ${LXQT_INSTALL_INCLUDE_DIR})
251 set(CFG_LXQT_LIBRARY        ${LXQT_LIBRARY_NAME})
252 set(CFG_LXQT_USE_FILE       ${LXQT_INSTALL_CMAKE_DIR}${LXQT_LIBRARY_NAME}/${LXQT_LIBRARY_NAME}_use.cmake)
253 set(CFG_LXQT_TRAGETS_FILE   ${LXQT_INSTALL_CMAKE_DIR}${LXQT_LIBRARY_NAME}/${LXQT_LIBRARY_NAME}-targets.cmake)
254
255 configure_file(
256     ${CMAKE_CURRENT_SOURCE_DIR}/cmake/lxqtX-config.cmake.in 
257     ${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}-config.cmake
258     @ONLY
259 )
260
261 # use gcc visibility feature to decrease unnecessary exported symbols
262 if (CMAKE_COMPILER_IS_GNUCXX)
263     # set visibility to hidden to hide symbols, unlesss they're exporeted
264     # manually in the code
265     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden -fno-exceptions -Wl,-no-undefined -Wall")
266 endif()
267 add_definitions(-DCOMPILE_LIBLXQT)
268
269 # create the portable headers *******************
270 #include(create_portable_headers)
271 #create_portable_headers(PORTABLE_HEADERS ${PUBLIC_CLASSES})
272 #check_portable_headers("${PUB_HDRS}")
273 #************************************************
274
275 configure_file(
276     ${CMAKE_CURRENT_SOURCE_DIR}/cmake/lxqt_use.cmake.in
277     ${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}_use.cmake
278     @ONLY
279 )
280
281 install(FILES 
282     ${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}-config.cmake
283     DESTINATION ${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}
284     COMPONENT Devel
285 )
286
287
288 install(FILES 
289     ${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}-config.cmake
290     ${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}_use.cmake
291     DESTINATION ${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}
292     COMPONENT Devel
293 )
294
295 install(EXPORT 
296     ${LXQT_LIBRARY_NAME}-targets
297     DESTINATION ${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}
298     COMPONENT Devel
299 )
300
301
302 include(translatorsinfo/CMakeLists.txt)
303 get_translatorsinfo_qrc(translatorsinfo_qrc)
304 if(USE_QT5)
305     qt5_add_resources(QRC_CXX_SOURCES ${translatorsinfo_qrc})
306 else()
307     qt4_add_resources(QRC_CXX_SOURCES ${translatorsinfo_qrc})
308 endif()
309
310 add_library(${LXQT_LIBRARY_NAME}
311     SHARED ${PUB_HDRS}
312            ${PRIV_HDRS}
313            ${SRCS}
314            ${dbus_generated}
315            ${UIS} ${MOCS}
316            ${QM_FILES}
317            ${QRC_CXX_SOURCES}
318            
319 )
320
321
322 target_link_libraries(${LXQT_LIBRARY_NAME}
323     ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY}
324     ${QT_QTDBUS_LIBRARY}
325     ${X11_X11_LIB}
326     ${QTXDG_LIBRARIES}
327 )
328
329 if(USE_QT5)
330         qt5_use_modules(${LXQT_LIBRARY_NAME} Widgets DBus X11Extras)
331 endif()
332
333 set_target_properties(${LXQT_LIBRARY_NAME} PROPERTIES
334     VERSION   ${LXQT_VERSION}
335     SOVERSION ${LXQT_MAJOR_VERSION}
336 )
337
338 install(TARGETS 
339     ${LXQT_LIBRARY_NAME} 
340     DESTINATION ${CMAKE_INSTALL_LIBDIR} 
341     EXPORT ${LXQT_LIBRARY_NAME}-targets
342     LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
343 )
344
345
346 export(TARGETS ${LXQT_LIBRARY_NAME} ${QTXDG_TARGET} FILE ${LXQT_INTREE_TRAGETS_FILE})
347
348 install(FILES ${PUB_HDRS}                DESTINATION ${LXQT_INSTALL_INCLUDE_DIR}/LXQt)
349 install(FILES ${INTREE_PORTABLE_HEADERS} DESTINATION ${LXQT_INSTALL_INCLUDE_DIR}/LXQt)
350
351 install(FILES ${QM_FILES} DESTINATION ${LXQT_TRANSLATIONS_DIR})
352
353 #************************************************
354 # Create pkgconfig file
355 #************************************************
356 lxqt_create_pkgconfig_file(${LXQT_LIBRARY_NAME}
357     ${LXQT_PKG_CONFIG_DESCRIPTION}
358     ${LXQT_PKG_CONFIG_REQUIRES}
359     ${LXQT_LIBRARY_NAME}
360     ${LXQT_VERSION}
361 )
362 #************************************************
363 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}_use.cmake
364         DESTINATION ${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME})
365
366 # building tarball with CPack -------------------------------------------------
367 include (InstallRequiredSystemLibraries)
368 set (CPACK_PACKAGE_VERSION_MAJOR ${LXQT_MAJOR_VERSION})
369 set (CPACK_PACKAGE_VERSION_MINOR ${LXQT_MINOR_VERSION})
370 set (CPACK_PACKAGE_VERSION_PATCH ${LXQT_PATCH_VERSION})
371 set (CPACK_GENERATOR TBZ2)
372 set (CPACK_SOURCE_GENERATOR TBZ2)
373 set (CPACK_SOURCE_IGNORE_FILES /build/;.gitignore;.*~;.git;.kdev4;temp)
374 include (CPack)