Use the "new" CMake FIND_PACKAGE case policy
[lxde/liblxqt.git] / CMakeLists.txt
CommitLineData
eedae82c 1cmake_minimum_required(VERSION 2.8.9)
0eff6363 2
af223b3d 3project(liblxqt)
0eff6363 4
af223b3d 5set(LXQT_MAJOR_VERSION 0)
948bc69d
JL
6set(LXQT_MINOR_VERSION 7)
7set(LXQT_PATCH_VERSION 0)
0eff6363 8
083e9c37 9# Set default installation paths
656043dc 10set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}" CACHE PATH "Installation path for libraries")
eedae82c 11set(LXQT_PKG_CONFIG_DESCRIPTION "Shared library for LXQt applications")
0eff6363 12
af223b3d 13set(PUB_HDRS
7ffe2055 14 aboutdialog/lxqtaboutdialog.h
82830dc2 15 lxqtsettings.h
b6483430 16 lxqtxfitman.h
191d2d13 17 lxqtplugininfo.h
b6483430
AS
18 lxqtpowermanager.h
19 addplugindialog/lxqtaddplugindialog.h
20 lxqtscreensaver.h
077c1e76 21 lxqtapplication.h
949dba2f 22 lxqttranslator.h
b6483430 23 lxqtprogramfinder.h
ad7ee7e8 24
b6483430
AS
25 configdialog/lxqtconfigdialog.h
26 configdialog/lxqtpageselectwidget.h
ad7ee7e8 27
8e6db58a 28 lxqtpower/lxqtpower.h
0e4fbf35 29 lxqtnotification.h
739b8f7f 30 lxqtautostartentry.h
f9de00b4 31 lxqtgridlayout.h
b6483430 32 lxqtrotatedwidget.h
f9cba1ba 33 lxqtglobals.h
4ef6cee9 34)
35
b6483430 36set(PUBLIC_CLASSES
f324ccfb
AS
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
af223b3d
AS
56)
57
58set(PRIV_HDRS
7ffe2055 59 aboutdialog/lxqtaboutdialog_p.h
1641df6e 60 aboutdialog/technicalinfo.h
b6483430 61 translatorsinfo/translatorsinfo.h
1641df6e
AS
62)
63
af223b3d 64set(SRCS
7ffe2055 65 aboutdialog/lxqtaboutdialog.cpp
1641df6e 66 aboutdialog/technicalinfo.cpp
b6483430 67 lxqtxfitman.cpp
191d2d13 68 lxqtplugininfo.cpp
b6483430
AS
69 lxqtpowermanager.cpp
70 addplugindialog/lxqtaddplugindialog.cpp
82830dc2 71 lxqtsettings.cpp
b6483430 72 lxqtscreensaver.cpp
077c1e76 73 lxqtapplication.cpp
949dba2f 74 lxqttranslator.cpp
b6483430 75 lxqtprogramfinder.cpp
ad7ee7e8 76
b6483430
AS
77 configdialog/lxqtconfigdialog.cpp
78 configdialog/lxqtpageselectwidget.cpp
ad7ee7e8 79
8e6db58a
AS
80 lxqtpower/lxqtpower.cpp
81 lxqtpower/lxqtpowerproviders.cpp
0e4fbf35 82 lxqtnotification.cpp
739b8f7f 83 lxqtautostartentry.cpp
f6abd4cf 84 translatorsinfo/translatorsinfo.cpp
f9de00b4 85 lxqtgridlayout.cpp
b6483430 86 lxqtrotatedwidget.cpp
4ef6cee9 87)
88
af223b3d 89set(MOCS
7ffe2055
AS
90 aboutdialog/lxqtaboutdialog.h
91 aboutdialog/lxqtaboutdialog_p.h
b6483430
AS
92 lxqtpowermanager.h
93 addplugindialog/lxqtaddplugindialog.h
82830dc2 94 lxqtsettings.h
b6483430 95 lxqtscreensaver.h
077c1e76 96 lxqtapplication.h
ad7ee7e8 97
b6483430
AS
98 configdialog/lxqtconfigdialog.h
99 configdialog/lxqtpageselectwidget.h
ad7ee7e8 100
0e4fbf35
AS
101 lxqtnotification.h
102 lxqtnotification_p.h
8e6db58a
AS
103 lxqtpower/lxqtpower.h
104 lxqtpower/lxqtpowerproviders.h
f9de00b4 105 lxqtgridlayout.h
b6483430 106 lxqtrotatedwidget.h
4ef6cee9 107)
108
af223b3d 109set(FORMS
7ffe2055 110 aboutdialog/lxqtaboutdialog.ui
b6483430 111 configdialog/lxqtconfigdialog.ui
b6483430 112 addplugindialog/lxqtaddplugindialog.ui
af223b3d
AS
113)
114
a28cd05a
AS
115file(GLOB TS_FILES
116 ${CMAKE_CURRENT_SOURCE_DIR}/translations/liblxqt_*.ts
117)
118
b6483430
AS
119# additional cmake files
120set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
af223b3d 121
af223b3d 122
4681206d
AS
123option(USE_QT5 "Force use the Qt5." $ENV{USE_QT5})
124option(USE_QT4 "Force use the Qt4." $ENV{USE_QT4})
f2cde75a 125
4681206d
AS
126if((USE_QT4 AND USE_QT5) OR
127 (NOT USE_QT4 AND NOT USE_QT5))
128
129 # Autodetect Qt version
371400de
AS
130 find_package(Qt4 QUIET)
131 if (QT4_FOUND)
4681206d
AS
132 set(USE_QT4 ON)
133 set(USE_QT5 OFF)
371400de
AS
134 else()
135 set(USE_QT4 OFF)
136 set(USE_QT5 ON)
4681206d
AS
137 endif()
138endif()
f2cde75a 139
afd3b116
JL
140set(CMAKE_INCLUDE_CURRENT_DIR ON)
141set(CMAKE_POSITION_INDEPENDENT_CODE ON)
4681206d 142
afd3b116 143if(USE_QT5)
154a38ff 144 set(CMAKE_AUTOMOC ON)
4681206d 145 find_package(Qt5Widgets REQUIRED QUIET)
2d13fe11 146 find_package(Qt5DBus REQUIRED QUIET)
4681206d
AS
147 find_package(Qt5X11Extras REQUIRED QUIET)
148 find_package(Qt5LinguistTools REQUIRED QUIET)
afd3b116 149 find_package(Qt5Xdg REQUIRED)
2d13fe11 150 message(STATUS "Building with Qt ${Qt5Core_VERSION_STRING}")
4681206d
AS
151
152 QT5_WRAP_UI(UIS ${FORMS})
153 QT5_ADD_TRANSLATION(QM_FILES ${TS_FILES})
2d13fe11
HJYP
154 QT5_ADD_DBUS_INTERFACE(SRCS
155 dbus/org.freedesktop.Notifications.xml
156 notifications_interface
157 )
4681206d 158
2d13fe11 159 set(LXQT_QT_VERSION "5")
917d0237 160 set(LXQT_QT_VERSION_SUFFIX "-qt5")
afd3b116 161 set(LXQT_PKG_CONFIG_REQUIRES "Qt5Widgets Qt5Xml Qt5DBus Qt5X11Extras")
4681206d 162else()
afd3b116 163 find_package(Qt4 REQUIRED QtCore QtGui QUIET)
bcfa0976 164 find_package(QTXDG REQUIRED)
4681206d
AS
165 message(STATUS "Building with Qt ${QTVERSION}")
166
167 include(${QT_USE_FILE})
168
169 QT4_WRAP_CPP(MOCS ${MOCS})
170 QT4_WRAP_UI(UIS ${FORMS})
171 QT4_ADD_TRANSLATION(QM_FILES ${TS_FILES})
172 QT4_ADD_DBUS_INTERFACE(SRCS
173 dbus/org.freedesktop.Notifications.xml
174 notifications_interface
175 )
176
177 set(LXQT_QT_VERSION "4")
917d0237 178 set(LXQT_QT_VERSION_SUFFIX "")
371400de 179 set(LXQT_PKG_CONFIG_REQUIRES "QtCore, QtXml")
4681206d 180endif()
af223b3d 181
af223b3d
AS
182include(${QTXDG_USE_FILE})
183
afd3b116
JL
184find_package(X11 REQUIRED QUIET)
185
af223b3d
AS
186include_directories (
187 ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
af223b3d 188 ${X11_INCLUDE_DIR}
2ccbc79f 189 ${QTXDG_INCLUDE_DIRS}
d7e822b0
AS
190)
191
b5294d21
LP
192if (NOT USE_QT5)
193 include_directories (
194 ${QT_QTCORE_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR} ${QT_QTDBUS_INCLUDE_DIR}
195 )
196endif()
197
371400de
AS
198# Standard directories for installation
199include(GNUInstallDirs)
200
af223b3d 201set(LXQT_VERSION ${LXQT_MAJOR_VERSION}.${LXQT_MINOR_VERSION}.${LXQT_PATCH_VERSION})
917d0237
LP
202set(LXQT_LIBRARY_NAME "lxqt${LXQT_QT_VERSION_SUFFIX}")
203set(LXQT_SHARE_DIR ${CMAKE_INSTALL_PREFIX}/share/${LXQT_LIBRARY_NAME})
371400de
AS
204set(LXQT_TRANSLATIONS_DIR ${LXQT_SHARE_DIR}/translations)
205
206set(LXQT_INTREE_INCLUDE_DIR ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/include)
c34f3845 207set(LXQT_INTREE_TARGETS_FILE ${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}-targets.cmake)
371400de 208
917d0237 209set(LXQT_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_FULL_INCLUDEDIR}/${LXQT_LIBRARY_NAME})
7bc50c7f 210set(LXQT_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_PREFIX}/share/cmake)
371400de
AS
211
212include(cmake/FindInstallConfigPath.cmake)
213include(create_portable_headers)
f88aabc1 214
af223b3d
AS
215message(STATUS "")
216message(STATUS "liblxqt version: ${LXQT_VERSION}")
217message(STATUS "")
218
219
371400de
AS
220# Copy public headers
221foreach(h ${PUB_HDRS})
222 get_filename_component(bh ${h} NAME)
0810a013 223 configure_file(${h} ${LXQT_INTREE_INCLUDE_DIR}/LXQt/${bh} COPYONLY)
57b51de6
LP
224 if (USE_QT4)
225 configure_file(${h} ${LXQT_INTREE_INCLUDE_DIR}/lxqt/${bh} COPYONLY)
226 endif()
371400de
AS
227endforeach()
228
229# Create the portable headers
0810a013 230create_portable_headers(INTREE_PORTABLE_HEADERS ${LXQT_INTREE_INCLUDE_DIR}/LXQt ${PUBLIC_CLASSES})
371400de
AS
231check_portable_headers(H_FILES ${PUB_HDRS} LINKS ${INTREE_PORTABLE_HEADERS})
232
af223b3d 233#************************************************
f324ccfb 234# Create in-tree build infrastructure
af223b3d 235#************************************************
371400de
AS
236set(CFG_LXQT_INCLUDE_DIR ${LXQT_INTREE_INCLUDE_DIR})
237set(CFG_LXQT_LIBRARY ${LXQT_LIBRARY_NAME})
238set(CFG_LXQT_USE_FILE ${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}_use.cmake)
c34f3845 239set(CFG_LXQT_TARGETS_FILE ${LXQT_INTREE_TARGETS_FILE})
af223b3d 240
af223b3d 241configure_file(
371400de
AS
242 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/lxqtX-config.cmake.in
243 ${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}-config.cmake
af223b3d
AS
244 @ONLY
245)
371400de
AS
246
247configure_file(
248 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/lxqt_use.cmake.in
249 ${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}_use.cmake
250 @ONLY
251)
252
371400de 253include(${CFG_LXQT_USE_FILE})
4681206d 254
f324ccfb 255
af223b3d 256#************************************************
f324ccfb 257# Create instalable build infrastructure
af223b3d 258#************************************************
371400de
AS
259set(CFG_LXQT_INCLUDE_DIR ${LXQT_INSTALL_INCLUDE_DIR})
260set(CFG_LXQT_LIBRARY ${LXQT_LIBRARY_NAME})
7bc50c7f
LP
261set(CFG_LXQT_USE_FILE ${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/${LXQT_LIBRARY_NAME}_use.cmake)
262set(CFG_LXQT_TARGETS_FILE ${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}/${LXQT_LIBRARY_NAME}-targets.cmake)
949dba2f 263
f324ccfb 264configure_file(
371400de
AS
265 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/lxqtX-config.cmake.in
266 ${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}-config.cmake
4681206d
AS
267 @ONLY
268)
f88aabc1 269
f9cba1ba
HJYP
270# use gcc visibility feature to decrease unnecessary exported symbols
271if (CMAKE_COMPILER_IS_GNUCXX)
388b7976
LP
272 # set visibility to hidden to hide symbols, unlesss they're exporeted
273 # manually in the code
274 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden -fno-exceptions -Wl,-no-undefined -Wall")
f9cba1ba
HJYP
275endif()
276add_definitions(-DCOMPILE_LIBLXQT)
277
af223b3d 278
4681206d 279configure_file(
371400de
AS
280 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/lxqt_use.cmake.in
281 ${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}_use.cmake
f324ccfb
AS
282 @ONLY
283)
f88aabc1 284
371400de 285install(FILES
afd3b116 286 ${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}-config.cmake
371400de
AS
287 ${CMAKE_CURRENT_BINARY_DIR}/install/${LXQT_LIBRARY_NAME}_use.cmake
288 DESTINATION ${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}
289 COMPONENT Devel
290)
af223b3d 291
371400de
AS
292install(EXPORT
293 ${LXQT_LIBRARY_NAME}-targets
294 DESTINATION ${LXQT_INSTALL_CMAKE_DIR}/${LXQT_LIBRARY_NAME}
295 COMPONENT Devel
296)
a28cd05a 297
4ef6cee9 298
f6abd4cf
AS
299include(translatorsinfo/CMakeLists.txt)
300get_translatorsinfo_qrc(translatorsinfo_qrc)
afd3b116
JL
301if(USE_QT5)
302 qt5_add_resources(QRC_CXX_SOURCES ${translatorsinfo_qrc})
303else()
304 qt4_add_resources(QRC_CXX_SOURCES ${translatorsinfo_qrc})
305endif()
f6abd4cf 306
371400de 307add_library(${LXQT_LIBRARY_NAME}
af223b3d
AS
308 SHARED ${PUB_HDRS}
309 ${PRIV_HDRS}
310 ${SRCS}
311 ${dbus_generated}
312 ${UIS} ${MOCS}
313 ${QM_FILES}
371400de
AS
314 ${QRC_CXX_SOURCES}
315
af223b3d 316)
4ef6cee9 317
b5294d21 318if (USE_QT5)
2d13fe11 319 qt5_use_modules(${LXQT_LIBRARY_NAME} Widgets DBus X11Extras)
b5294d21
LP
320 target_link_libraries(${LXQT_LIBRARY_NAME}
321 ${X11_X11_LIB}
322 ${QTXDG_LIBRARIES}
323 )
324else()
325 target_link_libraries(${LXQT_LIBRARY_NAME}
326 ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY}
327 ${QT_QTDBUS_LIBRARY}
328 ${X11_X11_LIB}
329 ${QTXDG_LIBRARIES}
330 )
2d13fe11
HJYP
331endif()
332
371400de 333set_target_properties(${LXQT_LIBRARY_NAME} PROPERTIES
af223b3d
AS
334 VERSION ${LXQT_VERSION}
335 SOVERSION ${LXQT_MAJOR_VERSION}
4ef6cee9 336)
337
371400de
AS
338install(TARGETS
339 ${LXQT_LIBRARY_NAME}
340 DESTINATION ${CMAKE_INSTALL_LIBDIR}
341 EXPORT ${LXQT_LIBRARY_NAME}-targets
2d13fe11 342 LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
371400de
AS
343)
344
345
c34f3845 346export(TARGETS ${LXQT_LIBRARY_NAME} ${QTXDG_TARGET} FILE ${LXQT_INTREE_TARGETS_FILE})
f324ccfb 347
eedae82c 348install(FILES ${PUB_HDRS} DESTINATION ${LXQT_INSTALL_INCLUDE_DIR}/LXQt)
57b51de6
LP
349
350if (USE_QT4)
351 install(FILES ${PUB_HDRS} DESTINATION ${LXQT_INSTALL_INCLUDE_DIR})
352endif()
353
eedae82c 354install(FILES ${INTREE_PORTABLE_HEADERS} DESTINATION ${LXQT_INSTALL_INCLUDE_DIR}/LXQt)
f324ccfb 355
949dba2f 356install(FILES ${QM_FILES} DESTINATION ${LXQT_TRANSLATIONS_DIR})
af223b3d 357
371400de
AS
358#************************************************
359# Create pkgconfig file
360#************************************************
361lxqt_create_pkgconfig_file(${LXQT_LIBRARY_NAME}
eedae82c 362 ${LXQT_PKG_CONFIG_DESCRIPTION}
371400de
AS
363 ${LXQT_PKG_CONFIG_REQUIRES}
364 ${LXQT_LIBRARY_NAME}
365 ${LXQT_VERSION}
388b7976 366)
371400de 367#************************************************
4ef6cee9 368
7c6da487
HJYP
369
370# building tarball with CPack -------------------------------------------------
371include (InstallRequiredSystemLibraries)
372set (CPACK_PACKAGE_VERSION_MAJOR ${LXQT_MAJOR_VERSION})
373set (CPACK_PACKAGE_VERSION_MINOR ${LXQT_MINOR_VERSION})
374set (CPACK_PACKAGE_VERSION_PATCH ${LXQT_PATCH_VERSION})
375set (CPACK_GENERATOR TBZ2)
376set (CPACK_SOURCE_GENERATOR TBZ2)
377set (CPACK_SOURCE_IGNORE_FILES /build/;.gitignore;.*~;.git;.kdev4;temp)
378include (CPack)