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