forked from lxqt/libqtxdg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
315 lines (257 loc) · 9.06 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
cmake_minimum_required( VERSION 2.8.5 )
project(libqtxdg)
# Support different versions of Qt
option(USE_QT5 "Build with Qt5." $ENV{USE_QT5})
option(BUILD_TESTS "Builds tests" OFF)
# The Qt4 version can be compiled with libmagic or with QtMimeTypes
# QtMimeTypes is the preferred way and also the default. libmagic will be
# dropped in future releases.
if (NOT USE_QT5)
option(USE_QTMIMETYPES "Use QtMimeTypes library" ON)
endif()
# Standard directories for installation
include(GNUInstallDirs)
# additional cmake files
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set (MAJOR_VERSION 1)
set (MINOR_VERSION 0)
set (PATCH_VERSION 0)
set(QTXDG_VERSION_STRING ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION})
add_definitions(-Wall)
find_package(PkgConfig)
if (USE_QT5)
find_package(Qt5Widgets REQUIRED QUIET)
find_package(Qt5Xml REQUIRED QUIET)
find_package(Qt5LinguistTools REQUIRED QUIET)
if (BUILD_TESTS)
find_package(Qt5Test REQUIRED QUIET)
endif()
# if both Qt4 and Qt5 are installed we must check what version was found
if (NOT ${Qt5Core_VERSION_MAJOR} EQUAL 5)
message(FATAL_ERROR "Qt was found, but NOT Qt5.")
endif()
set(QTXDGX_LIBRARY_NAME "Qt5Xdg")
set(QTXDGX_FILE_NAME "qt5xdg")
set(QTXDGX_PKG_CONFIG_DESCRIPTION "Qt5Xdg, a Qt5 implementation of XDG standards")
set(QTXDGX_PKG_CONFIG_REQUIRES "Qt5Core, Qt5Xml, Qt5Widgets")
include_directories(${Qt5Widgets_INCLUDE_DIRS} ${Qt5Xml_INCLUDE_DIRS})
add_definitions(${Qt5Core_DEFINITIONS})
# set(CMAKE_CXX_FLAGS
# "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}"
# )
# QMimeDatabase and QMimeType are part of Qt5Core
# We just use that as an mimetype provider.
# An empty MIMETYPES_PROVIDER_LIBRARY means we are using Qt internal
# mimetypes support
set(MIMETYPES_PROVIDER_LIBRARY "")
add_definitions("-DHAVE_QTMIMETYPES")
set(QTX_LIBRARIES ${Qt5Widgets_LIBRARIES} ${Qt5Xml_LIBRARIES})
message(STATUS "Building with Qt ${Qt5Core_VERSION_STRING}")
else()
find_package(Qt4 REQUIRED QtCore QtGui QtXml QUIET)
if (BUILD_TESTS)
find_package(Qt4 REQUIRED QtTest QUIET)
endif()
# if both Qt4 and Qt5 are installed we must check what version was found
if (NOT ${QT_VERSION_MAJOR} EQUAL 4)
message(FATAL_ERROR "Qt was found, but NOT Qt4")
endif()
set(QTXDGX_LIBRARY_NAME "qtxdg")
set(QTXDGX_FILE_NAME "qtxdg")
set(QTXDGX_PKG_CONFIG_DESCRIPTION "QtXdg, a Qt4 implementation of XDG standards")
include(${QT_USE_FILE})
set(QTX_LIBRARIES
${QT_QTCORE_LIBRARY}
${QT_QTGUI_LIBRARY}
${QT_QTXML_LIBRARY}
)
message(STATUS "Building with Qt ${QTVERSION}")
endif()
set(libqtxdg_PUBLIC_H_FILES
xdgaction.h
xdgdesktopfile.h
xdgdirs.h
xdgicon.h
xdgmenu.h
xdgmenuwidget.h
xmlhelper.h
xdgautostart.h
xdgmacros.h
)
set(libqtxdg_PUBLIC_CLASSES
XdgAction
XdgDesktopFile
XdgDirs
XdgIcon
XdgMenu
XdgMenuWidget
XmlHelper
XdgAutoStart
)
set(libqtxdg_PRIVATE_H_FILES
xdgmenuapplinkprocessor.h
xdgmenulayoutprocessor.h
xdgmenu_p.h
xdgmenureader.h
xdgmenurules.h
)
set(libqtxdg_CPP_FILES
xdgaction.cpp
xdgdesktopfile.cpp
xdgdirs.cpp
xdgicon.cpp
xdgmenuapplinkprocessor.cpp
xdgmenu.cpp
xdgmenulayoutprocessor.cpp
xdgmenureader.cpp
xdgmenurules.cpp
xdgmenuwidget.cpp
xmlhelper.cpp
xdgautostart.cpp
)
set(libqtxdg_MOCS
xdgaction.h
xdgmenuapplinkprocessor.h
xdgmenu.h
xdgmenu_p.h
xdgmenureader.h
xdgmenurules.h
xdgmenuwidget.h
)
if (USE_QT5)
list(APPEND libqtxdg_PRIVATE_H_FILES qiconfix/qiconloader_p.h)
list(APPEND libqtxdg_CPP_FILES qiconfix/qiconloader.cpp)
else()
list(APPEND libqtxdg_PRIVATE_H_FILES qiconfix/qiconloader_p_qt4.h)
list(APPEND libqtxdg_CPP_FILES qiconfix/qiconloader_qt4.cpp)
endif()
if (NOT USE_QT5)
if (USE_QTMIMETYPES)
# Using QtMimeTypes to provide a better mimetype support on Qt4
# Project repo: https://qt.gitorious.org/qtplayground/mimetypes
pkg_check_modules(QTMIMETYPES REQUIRED
QtMimeTypes
)
include_directories(${QTMIMETYPES_INCLUDE_DIRS})
set(QTXDGX_PKG_CONFIG_REQUIRES "QtCore, QtXml, QtMimeTypes")
set(MIMETYPES_PROVIDER_LIBRARY ${QTMIMETYPES_LIBRARIES})
link_directories(${QTMIMETYPES_LIBRARY_DIRS})
add_definitions("-DHAVE_QTMIMETYPES")
else()
# Use libmagic
find_package(LibMagic REQUIRED QUIET)
set(MIMETYPES_PROVIDER_LIBRARY ${LIBMAGIC_LIBRARY})
set(QTXDGX_PKG_CONFIG_REQUIRES "QtCore, QtXml")
list(APPEND libqtxdg_PUBLIC_H_FILES xdgmime.h)
list(APPEND libqtxdg_PUBLIC_CLASSES XdgMime)
list(APPEND libqtxdg_CPP_FILES xdgmime.cpp)
endif()
endif()
if (USE_QTMIMETYPES OR USE_QT5)
list(APPEND libqtxdg_PUBLIC_H_FILES xdgmimetype.h)
list(APPEND libqtxdg_PUBLIC_CLASSES XdgMimeType)
list(APPEND libqtxdg_CPP_FILES xdgmimetype.cpp)
endif()
#************************************************
# Build 2 config.cmake files
# One for in-tree build and second for normal one.
#************************************************
set(QTXDG_MAJOR_VERSION ${MAJOR_VERSION})
set(QTXDG_MINOR_VERSION ${MINOR_VERSION})
set(QTXDG_PATCH_VERSION ${PATCH_VERSION})
# In tree compilation ......................
set(QTXDG_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_BINARY_DIR}")
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/qtxdg-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake/${QTXDGX_FILE_NAME}-config.cmake
@ONLY
)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/${QTXDGX_FILE_NAME}_use.cmake
${CMAKE_CURRENT_BINARY_DIR}/cmake/${QTXDGX_FILE_NAME}_use.cmake
@ONLY
)
# Instalable ...............................
set(QTXDG_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/${QTXDGX_FILE_NAME})
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/qtxdg-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${QTXDGX_FILE_NAME}-config.cmake
@ONLY
)
# Translations **********************************
# QtXdg is an independent library, so I do not use razor_translate_ts
include(qtxdgTranslate)
qtxdg_translate_ts(libqtxdg_QM_FILES
SOURCES
${libqtxdg_PUBLIC_H_FILES}
${libqtxdg_PRIVATE_H_FILES}
${libqtxdg_CPP_FILES}
${libqtxdg_UI_FILES}
)
#************************************************
#**********************************************************
include(FindLibSuffix)
if(USE_QT5)
QT5_WRAP_CPP(libqtxdg_CXX_FILES ${libqtxdg_MOCS})
else()
QT4_WRAP_CPP(libqtxdg_CXX_FILES ${libqtxdg_MOCS})
endif()
if (NOT CMAKE_BUILD_TYPE)
set ( CMAKE_BUILD_TYPE Release )
endif (NOT CMAKE_BUILD_TYPE)
set(APP_SHARE_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/lib${QTXDGX_FILE_NAME})
add_definitions(-DTRANSLATIONS_DIR=\"${APP_SHARE_DIR}\")
add_library(${QTXDGX_LIBRARY_NAME} SHARED
${libqtxdg_PUBLIC_H_FILES}
${libqtxdg_PRIVATE_H_FILES}
${libqtxdg_CPP_FILES}
${libqtxdg_CXX_FILES}
${libqtxdg_QM_FILES}
)
target_link_libraries(${QTXDGX_LIBRARY_NAME}
${QTX_LIBRARIES}
${MIMETYPES_PROVIDER_LIBRARY}
)
set_target_properties(${QTXDGX_LIBRARY_NAME} PROPERTIES
VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}
SOVERSION ${MAJOR_VERSION}
)
# create the portable headers
include(create_portable_headers)
create_portable_headers(libqtxdg_PORTABLE_HEADERS ${libqtxdg_PUBLIC_CLASSES})
install(TARGETS ${QTXDGX_LIBRARY_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${libqtxdg_PUBLIC_H_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${QTXDGX_FILE_NAME})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${QTXDGX_FILE_NAME}-config.cmake DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/${QTXDGX_FILE_NAME})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/${QTXDGX_FILE_NAME}_use.cmake DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/${QTXDGX_FILE_NAME})
install(FILES ${libqtxdg_PORTABLE_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${QTXDGX_FILE_NAME})
include(create_pkgconfig_file)
create_pkgconfig_file(${QTXDGX_LIBRARY_NAME}
${QTXDGX_PKG_CONFIG_DESCRIPTION}
${QTXDGX_PKG_CONFIG_REQUIRES}
${QTXDGX_FILE_NAME}
${QTXDG_VERSION_STRING}
)
if(BUILD_TESTS)
enable_testing()
add_subdirectory(test)
else()
message(STATUS "")
message(STATUS "For building tests use -DBUILD_TESTS=Yes option.")
message(STATUS "")
endif()
# uninstall target
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
# building tarball with CPack -------------------------------------------------
include (InstallRequiredSystemLibraries)
set (CPACK_PACKAGE_VERSION_MAJOR ${MAJOR_VERSION})
set (CPACK_PACKAGE_VERSION_MINOR ${MINOR_VERSION})
set (CPACK_PACKAGE_VERSION_PATCH ${PATCH_VERSION})
set (CPACK_GENERATOR TBZ2)
set (CPACK_SOURCE_GENERATOR TBZ2)
set (CPACK_SOURCE_IGNORE_FILES /build/;.gitignore;.*~;.git;.kdev4;temp)
include (CPack)