forked from DOOMer/screengrab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
301 lines (235 loc) · 9.91 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
cmake_minimum_required( VERSION 2.6 )
# set project's name
project( screengrab )
message(STATUS "System: " ${CMAKE_HOST_SYSTEM_NAME} " " ${CMAKE_HOST_SYSTEM_VERSION})
message(STATUS "Processor: " ${CMAKE_HOST_SYSTEM_PROCESSOR})
find_package( Qt4 REQUIRED COMPONENTS QtCore QtGui QtNetwork)
include( "${QT_USE_FILE}" )
# add version define
set(SCREENGRAB_VERSION "0.9.90")
set(SCREENGRAB_VERSION_DEV "1.0")
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(GIT_FOUND)
set(VERSION "${SCREENGRAB_VERSION} (${SCREENGRAB_VERSION_DEV}-git-${GIT_HASH})")
else (DEV_BUILD)
set(VERSION "${SCREENGRAB_VERSION} (${SCREENGRAB_VERSION_DEV})")
endif(DEV_BUILD)
elseif(NOT SCREENGRAB_VERSION_DEV)
set(VERSION ${SCREENGRAB_VERSION})
endif(SCREENGRAB_VERSION_DEV)
add_definitions( -DVERSION="${VERSION}")
message(STATUS "Version : " ${VERSION})
#${CMAKE_SYSTEM_NAME} [${CMAKE_HOST_SYSTEM_PROCESSOR}]" )
message(STATUS "Use qmake: " ${QT_QMAKE_EXECUTABLE})
# ------ build type ------------------------
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif(NOT CMAKE_BUILD_TYPE)
if(${CMAKE_BUILD_TYPE} MATCHES "Release")
add_definitions(-DNDEBUG)
add_definitions(-DQT_NO_DEBUG_OUTPUT)
if(WIN32)
if(NOT MSVC)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
endif(NOT MSVC)
endif(WIN32)
endif(${CMAKE_BUILD_TYPE} MATCHES "Release")
message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
set(CMAKE_CXX_FLAGS "-Wnon-virtual-dtor -Woverloaded-virtual -Wall -Wextra")
# ------ install prefix --------------------------
set(CMAKE_INSTALL_PREFIX "/usr")
add_definitions( -DPREFIX="${CMAKE_INSTALL_PREFIX}")
message(STATUS "Install prefix: " ${CMAKE_INSTALL_PREFIX})
# ------ options ---------------------------------
OPTION (SG_GLOBALSHORTCUTS "Enable global shortcuts" ON)
if(SG_GLOBALSHORTCUTS)
add_definitions( -DSG_GLOBAL_SHORTCUTS="1")
endif(SG_GLOBALSHORTCUTS)
# ------ doc dir name ---------------------------------
if(UNIX AND NOT APPLE)
if (NOT SG_DOCDIR)
set(SG_DOCDIR "share/doc/screengrab" CACHE STRING "Documantation directory name")
endif (NOT SG_DOCDIR)
set(DOCPATH "share/doc/${SG_DOCDIR}" CACHE STRING "Documantation directory name")
message(STATUS "Documentation directory: " ${CMAKE_INSTALL_PREFIX}/${DOCPATH})
add_definitions( -DSG_DOCDIR="${CMAKE_INSTALL_PREFIX}/${DOCPATH}")
endif(UNIX AND NOT APPLE)
message(STATUS "Global shortcuts support: " ${SG_GLOBALSHORTCUTS})
set(SG_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/src/")
message(STATUS "SG_INCLUDE: " ${SG_INCLUDE})
#------- qtsingleapplication --------
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/common/qkeysequencewidget/")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/common/singleapp/")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/modules/uploader/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/common/singleapp")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/common/qkeysequencewidget/src")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/modules/uploader/")
#openarenainclude_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/common/singleapp")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/common/qkeysequencewidget/src")
if(SG_GLOBALSHORTCUTS)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/3rdparty/qxt/include/")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/3rdparty/qxt/")
# build QxtGui
add_definitions(-DBUILD_QXT_GUI)
endif(SG_GLOBALSHORTCUTS)
#------- sources --------
# with SET() command you can change variables or define new ones
# here we define SAMPLE_SRCS variable that contains a list of all .cpp files
# note that we don't need \ at the end of line
set(SCREENGRAB_SRC
src/main.cpp
src/core/core.cpp
src/core/config.cpp
src/core/regionselect.cpp
src/core/cmdline.cpp
src/core/shortcutmanager.cpp
src/ui/configwidget.cpp
src/ui/about.cpp
src/ui/mainwindow.cpp
)
if(UNIX AND NOT APPLE)
set(SCREENGRAB_SRC ${SCREENGRAB_SRC} src/common/netwm/netwm.cpp)
endif(UNIX AND NOT APPLE)
if(WIN32)
set(WIN_RC screengrab.rc)
endif(WIN32)
# set headers to moc
set(SCREENGRAB_MOC
src/core/core.h
src/ui/configwidget.h
src/ui/about.h
src/ui/mainwindow.h
)
# set headers to moc
set(SCREENGRAB_UI
src/ui/configwidget.ui
src/ui/aboutwidget.ui
src/ui/mainwindow.ui
)
# documentation files
set(DOCS
${CMAKE_CURRENT_SOURCE_DIR}/docs/ChangeLog.txt
${CMAKE_CURRENT_SOURCE_DIR}/docs/LICENSE.txt
${CMAKE_CURRENT_SOURCE_DIR}/docs/README.txt
)
# include headers produced by uic in our code
# (CMAKE_BINARY_DIR holds a path to the build directory, while INCLUDE_DIRECTORIES() works just like INCLUDEPATH from qmake)
# Qt resource file
set( SCREENGRAB_QRC screengrab.qrc )
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
# this will run uic on .ui files:
qt4_wrap_ui(SCREENGRAB_UI_H ${SCREENGRAB_UI} )
# genereate moc headers
qt4_wrap_cpp(SCREENGRAB_MOC_CPP ${SCREENGRAB_MOC} )
# genereating resource cpp
qt4_add_resources( QRC_SOURCES ${SCREENGRAB_QRC} )
#------- find lrelease & create qms ------------
# find lrelease binary
if(NOT QT_LRELEASE_EXECUTABLE)
find_program(QT_LRELEASE_EXECUTABLE
NAMES lrelease
PATHS ${QT_BINARY_DIR}
NO_DEFAULT_PATH
)
endif(NOT QT_LRELEASE_EXECUTABLE)
# debian hack
if(EXISTS ${QT_BINARY_DIR}/lrelease-qt4)
set(QT_LRELEASE_EXECUTABLE ${QT_BINARY_DIR}/lrelease-qt4)
endif(EXISTS ${QT_BINARY_DIR}/lrelease-qt4)
if(QT_LRELEASE_EXECUTABLE)
message(STATUS "Found lrelease executable: " ${QT_LRELEASE_EXECUTABLE})
message(STATUS "Generating localize ...")
execute_process(COMMAND find ${CMAKE_CURRENT_SOURCE_DIR}/localize -name *.ts COMMAND xargs ${QT_LRELEASE_EXECUTABLE} -silent)
else(QT_LRELEASE_EXECUTABLE)
message(FATAL_ERROR "Could NOT find lrelease executable")
endif(QT_LRELEASE_EXECUTABLE)
# --exclude-backups --exclude-vcs --exclude=localize/*qm --exclude=*.kdev4 --exclude=build --exclude=create-src.sh --exclude=win32
#------- add icon & trmove console in win32 (mingw) ----------
if(WIN32)
if(NOT MSVC)
add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/screengrabrc.o
COMMAND ${CMAKE_RC_COMPILER} -I${CMAKE_CURRENT_SOURCE_DIR} -i${CMAKE_CURRENT_SOURCE_DIR}/screengrab.rc
-o ${CMAKE_CURRENT_BINARY_DIR}/screengrabrc.o )
set(SCREENGRAB_SRC ${SCREENGRAB_SRC} ${CMAKE_CURRENT_BINARY_DIR}/screengrabrc.o)
endif(NOT MSVC)
endif(WIN32)
#------- build executable from sources ----------
add_executable( screengrab ${SCREENGRAB_SRC} ${SCREENGRAB_MOC_CPP} ${SCREENGRAB_UI_H} ${QRC_SOURCES} )
if(SG_GLOBALSHORTCUTS)
target_link_libraries( screengrab qxt)
endif(SG_GLOBALSHORTCUTS)
if(WIN32)
target_link_libraries( screengrab qkeysequencewidget singleapp uploader ${QT_LIBRARIES} )
endif(WIN32)
if(UNIX)
target_link_libraries( screengrab qkeysequencewidget singleapp uploader X11
${QT_LIBRARIES} )
endif(UNIX)
if(WIN32)
if(NOT MSVC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -mwindows ")
endif(NOT MSVC)
endif(WIN32)
#------- make src packae and installing ----------
if(UNIX AND NOT APPLE)
# 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 txt docs
INSTALL(FILES ${DOCS} DESTINATION ${DOCPATH})
# install html docs
INSTALL(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/docs/html/" DESTINATION "${DOCPATH}/html")
# install desktop files
INSTALL(FILES "${CMAKE_CURRENT_SOURCE_DIR}/screengrab.desktop" DESTINATION share/applications)
# install pixmap
INSTALL(FILES "${CMAKE_CURRENT_SOURCE_DIR}/img/screengrab.png" DESTINATION share/pixmaps)
INSTALL(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/localize/" DESTINATION share/screengrab/localize FILES_MATCHING PATTERN "*.qm")
endif(UNIX AND NOT APPLE)
if(WIN32)
set(WIN32_BINARY_RUNTIME
# ${CMAKE_FIND_ROOT_PATH}/bin/libgcc_s_sjlj-1.dll
# ${CMAKE_FIND_ROOT_PATH}/bin/libstdc++-6.dll
${CMAKE_FIND_ROOT_PATH}/bin/zlib1.dll
)
set(WIN32_BINARY_QT_LIBS
${QT_BINARY_DIR}/QtCore4.dll
${QT_BINARY_DIR}/QtGui4.dll
${QT_BINARY_DIR}/QtNetwork4.dll
)
INSTALL(TARGETS screengrab RUNTIME DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/distro)
install(FILES ${WIN32_BINARY_RUNTIME} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/distro)
install(FILES ${WIN32_BINARY_QT_LIBS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/distro)
install(FILES ${QT_JPEG_LIBRARY} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/bin/imageformats)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/localize/" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/distro/localize FILES_MATCHING PATTERN "*.qm")
install(FILES ${DOCS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/distro/docs)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/docs/html/" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/distro/docs/html)
endif(WIN32)