This repository has been archived by the owner on Oct 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
CMakeLists.txt
290 lines (234 loc) · 8.1 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
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
# set project's name
project(screengrab)
find_package(Qt5Widgets 5.7.1 REQUIRED)
find_package(Qt5X11Extras 5.7.1 REQUIRED)
find_package(Qt5Network 5.7.1 REQUIRED)
find_package(KF5WindowSystem REQUIRED)
# for translations
find_package(Qt5LinguistTools REQUIRED)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# long live cmake + qt :)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
include(GNUInstallDirs)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(X11)
if (X11_FOUND)
set(HAVE_X11 1)
endif(X11_FOUND)
# set up xcb and x11_xcb
find_package(
XCB MODULE COMPONENTS
XCB
SHAPE
XFIXES
)
find_package(
X11_XCB MODULE
)
# add version define
set(SCREENGRAB_VERSION "1.97")
set(SCREENGRAB_VERSION_DEV "2.0-beta1")
# set(DEV_BUILD True)
if(SCREENGRAB_VERSION_DEV)
if(DEV_BUILD)
# search git executable
find_package(Git)
if(GIT_FOUND)
# executable git for check HEAD rev hash
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
OUTPUT_VARIABLE GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
set(VERSION "${SCREENGRAB_VERSION} (${SCREENGRAB_VERSION_DEV}-git-${GIT_HASH})")
else()
set(VERSION "${SCREENGRAB_VERSION} (${SCREENGRAB_VERSION_DEV})")
endif()
elseif(NOT SCREENGRAB_VERSION_DEV)
set(VERSION "${SCREENGRAB_VERSION}")
endif(SCREENGRAB_VERSION_DEV)
add_definitions(
-DVERSION="${VERSION}"
-DQT_NO_FOREACH
)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
message(STATUS "Install prefix: " ${CMAKE_INSTALL_PREFIX})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor -Woverloaded-virtual -Wall -Wextra")
set(SG_LIBDIR "${CMAKE_INSTALL_LIBDIR}/screengrab")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${SG_LIBDIR}")
message(STATUS "Library path: ${CMAKE_INSTALL_RPATH}")
# options
option(SG_GLOBALSHORTCUTS "Enable global shortcuts" OFF)
option(SG_EXT_UPLOADS "Enable upload screenshots to Imgur" ON)
option(SG_EXT_EDIT "Enable ability to edit screenshots in external editor" ON)
option(SG_DBUS_NOTIFY "Enable D-Bus notifications" ON)
option(UPDATE_TRANSLATIONS "Update source translation translations/*.ts files" OFF)
# Although the names, LXQtTranslateTs and LXQtTranslateDesktop, they don't
# bring any dependency on lxqt.
include(LXQtTranslateTs)
include(LXQtTranslateDesktop)
include(Qt5TranslationLoader)
if(SG_GLOBALSHORTCUTS)
add_definitions( -DSG_GLOBAL_SHORTCUTS="1")
if(SG_USE_SYSTEM_QXT)
# find qxt
find_package(Qxt REQUIRED COMPONENTS QxtCore, QxtGui)
include_directories(${QXT_QXTCORE_INCLUDE_DIR} ${QXT_QXTGUI_INCLUDE_DIR})
endif()
endif(SG_GLOBALSHORTCUTS)
if(SG_EXT_UPLOADS)
add_definitions( -DSG_EXT_UPLOADS="1")
endif()
if(SG_EXT_EDIT)
add_definitions( -DSG_EXT_EDIT="1")
find_package(Qt5Xdg REQUIRED)
endif()
if(SG_DBUS_NOTIFY)
find_package(Qt5DBus 5.2 REQUIRED)
add_definitions( -DSG_DBUS_NOTIFY="1")
endif()
message(STATUS "Global shortcuts support: " ${SG_GLOBALSHORTCUTS})
message(STATUS "Imgur upload support: " ${SG_EXT_UPLOADS})
message(STATUS "Editing screenshots in external editor support: " ${SG_EXT_EDIT})
message(STATUS "Enable D-Bus notifications: " ${SG_DBUS_NOTIFY})
message(STATUS "Use system Qxt Library: " ${SG_USE_SYSTEM_QXT})
message(STATUS "Update source translation translations/*.ts files: " ${UPDATE_TRANSLATIONS})
# docs
# CMAKE_INSTALL_FULL_DOCDIR = CMAKE_INSTALL_PREFIX/CMAKE_INSTALL_DATADIR/doc/PROJECT_NAME
message(STATUS "Documentation directory: " ${CMAKE_INSTALL_FULL_DOCDIR})
add_definitions(-DSG_DOCDIR="${CMAKE_INSTALL_FULL_DOCDIR}")
# app icon path
add_definitions(-DSG_ICONPATH="${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/pixmaps/screengrab.png")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/common/qkeysequencewidget")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/common/qkeysequencewidget/src")
if(SG_EXT_UPLOADS)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/modules/uploader")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/modules/uploader")
endif()
if (SG_EXT_EDIT)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/modules/extedit")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/modules/extedit")
endif()
set(SCREENGRAB_SRC
src/core/main.cpp
src/core/singleapp.cpp
src/core/core.cpp
src/core/config.cpp
src/core/regionselect.cpp
src/core/shortcutmanager.cpp
src/core/modulemanager.cpp
src/core/ui/configwidget.cpp
src/core/ui/about.cpp
src/core/ui/mainwindow.cpp
)
if(SG_DBUS_NOTIFY)
set(SCREENGRAB_SRC ${SCREENGRAB_SRC} src/core/dbusnotifier.cpp)
endif()
if(X11_FOUND)
set(SCREENGRAB_SRC ${SCREENGRAB_SRC} src/core/x11utils.cpp)
endif()
set(SCREENGRAB_HDR
src/core/singleapp.h
)
set(SCREENGRAB_UI
src/core/ui/configwidget.ui
src/core/ui/aboutwidget.ui
src/core/ui/mainwindow.ui
)
# Qt resource file
set(SCREENGRAB_QRC screengrab.qrc)
qt5_add_resources(QRC_SOURCES ${SCREENGRAB_QRC})
message(STATUS "Generating localize ...")
set(SCREENGRAB_DESKTOP_FILES_IN
screengrab.desktop.in
)
lxqt_translate_ts(SCREENGRAB_QMS
USE_QT5 TRUE
UPDATE_TRANSLATIONS ${UPDATE_TRANSLATIONS}
SOURCES
${SCREENGRAB_SRC}
${SCREENGRAB_UI}
INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/translations"
)
lxqt_translate_desktop(SCREENGRAB_DESKTOP_FILES
SOURCES ${SCREENGRAB_DESKTOP_FILES_IN}
)
qt5_translation_loader(SCREENGRAB_QM_LOADER
"${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/translations"
${PROJECT_NAME}
)
# generating executable
add_executable(screengrab
${SCREENGRAB_SRC}
${SCREENGRAB_UI_H}
${QRC_SOURCES}
${SCREENGRAB_QMS}
${SCREENGRAB_DESKTOP_FILES}
${SCREENGRAB_QM_LOADER}
)
if(SG_GLOBALSHORTCUTS)
if(SG_USE_SYSTEM_QXT)
target_link_libraries(screengrab ${QXT_QXTCORE_LIB_RELEASE} ${QXT_QXTGUI_LIB_RELEASE})
else(SG_USE_SYSTEM_QXT)
target_link_libraries(screengrab qxt)
endif(SG_USE_SYSTEM_QXT)
endif()
if(SG_EXT_UPLOADS)
target_link_libraries(screengrab uploader)
endif()
if(SG_EXT_EDIT)
target_link_libraries(screengrab extedit)
endif()
if(SG_DBUS_NOTIFY)
target_link_libraries(screengrab Qt5::DBus)
endif()
if (X11_XCB_FOUND)
add_definitions( -DX11_XCB_FOUND="1")
target_link_libraries(screengrab ${X11_XCB_LIBRARIES})
endif()
if (XCB_XCB_FOUND)
add_definitions( -DXCB_XCB_FOUND="1")
target_link_libraries(screengrab ${XCB_XCB_LIBRARY})
endif()
if (XCB_SHAPE_FOUND)
add_definitions( -DXCB_SHAPE_FOUND="1")
target_link_libraries(screengrab ${XCB_SHAPE_LIBRARY})
endif()
if (XCB_XFIXES_FOUND)
add_definitions( -DXCB_XFOXES_FOUND="1")
target_link_libraries(screengrab ${XCB_XFIXES_LIBRARY})
endif()
target_link_libraries(screengrab qkeysequencewidget Qt5::Widgets KF5::WindowSystem ${X11_LIBRARIES})
# make src.tar.gz
add_custom_target(dist @echo create source package)
set(SCREENGRAB_DIST "screengrab-${SCREENGRAB_VERSION}")
add_custom_command(COMMAND cp
ARGS -R ${CMAKE_CURRENT_SOURCE_DIR} "/tmp/${SCREENGRAB_DIST}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
TARGET dist
)
add_custom_command(COMMAND tar
ARGS cvfz "${CMAKE_CURRENT_BINARY_DIR}/${SCREENGRAB_DIST}.tar.gz" --exclude=*~ --exclude-vcs --exclude=localize/*qm --exclude=*.kdev4 --exclude=build --exclude=create-src.sh --exclude=win32 -C "/tmp" "${SCREENGRAB_DIST}"
WORKING_DIRECTORY "/tmp"
TARGET dist
)
add_custom_command(COMMAND rm
ARGS -rf "/tmp/${SCREENGRAB_DIST}"
WORKING_DIRECTORY "/tmp"
TARGET dist
)
# installing
install(TARGETS screengrab RUNTIME DESTINATION bin)
# install html docs
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/docs/html" DESTINATION "${CMAKE_INSTALL_FULL_DOCDIR}")
# install desktop files
install(FILES ${SCREENGRAB_DESKTOP_FILES} DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
# install pixmap
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/img/screengrab.png" DESTINATION "${CMAKE_INSTALL_DATADIR}/icons/hicolor/32x32/apps")