forked from roboception/cvkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
293 lines (236 loc) · 10.5 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
# This file is part of the Computer Vision Toolkit (cvkit).
#
# Author: Heiko Hirschmueller
#
# Copyright (c) 2014, Institute of Robotics and Mechatronics, German Aerospace Center
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
cmake_minimum_required (VERSION 2.8.9)
project(cvkit)
enable_testing()
include_directories(${CMAKE_SOURCE_DIR})
# settings for NSIS (Windows) install package
set(CPACK_PACKAGE_CONTACT "Heiko Hirschmueller <[email protected]>")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Computer Vision Toolkit")
set(CPACK_PACKAGE_VENDOR "Institute of Robotics and Mechatronics, German Aerospace Center")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.txt")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
set(CPACK_PACKAGE_VERSION_MAJOR "1")
set(CPACK_PACKAGE_VERSION_MINOR "8")
set(CPACK_PACKAGE_VERSION_PATCH "7")
set(CVKIT_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH})
find_program(GIT_CMD git)
if (GIT_CMD AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
execute_process(COMMAND ${GIT_CMD} rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_SHA1
OUTPUT_STRIP_TRAILING_WHITESPACE)
#message(STATUS "GIT_SHA1: " ${GIT_SHA1})
execute_process(COMMAND ${GIT_CMD} describe --match "*[0-9].[0-9]*" HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_DESCRIBE
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
#message(STATUS "GIT_DESCRIBE: " ${GIT_DESCRIBE})
if (GIT_DESCRIBE)
string(REGEX REPLACE "v?([0-9.]+).*" "\\1" GIT_VERSION ${GIT_DESCRIBE})
#message(STATUS "GIT_VERSION: " ${GIT_VERSION})
if (NOT GIT_DESCRIBE MATCHES ${CVKIT_VERSION})
message(WARNING "Version from git (${GIT_VERSION}) doesn't match cmake (${CVKIT_VERSION})")
endif()
if (GIT_DESCRIBE MATCHES ".*-g.*")
# convert a git describe string to usable debian version, e.g. v1.7.1-7-ge324c81 to 1.7.1+7+ge324c81
string(REGEX REPLACE "v?([0-9.]*)-([0-9]*)-([a-g0-9]*).*" "\\1+\\2+\\3" DEB_GIT_VERSION ${GIT_DESCRIBE})
set(CPACK_PACKAGE_VERSION ${DEB_GIT_VERSION})
else()
# current HEAD is git tag (i.e. releaase), directly use the version
set(CPACK_PACKAGE_VERSION ${GIT_VERSION})
endif()
else ()
set(CPACK_PACKAGE_VERSION ${CVKIT_VERSION}+g${GIT_SHA1})
endif ()
#message(STATUS "CPACK_PACKAGE_VERSION: " ${CPACK_PACKAGE_VERSION})
endif ()
if (WIN32)
set(CPACK_GENERATOR NSIS)
set(CPACK_NSIS_INSTALL_ROOT "C:")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "cvkit")
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "
\\\${registerExtension} '\\\$INSTDIR\\\\bin\\\\plyv.exe' '.ply' 'cvkit.plyv.ply'
\\\${registerExtension} '\\\$INSTDIR\\\\bin\\\\sv.exe' '.pfm' 'cvkit.sv.pfm'
\\\${registerExtension} '\\\$INSTDIR\\\\bin\\\\sv.exe' '.pgm' 'cvkit.sv.pgm'
\\\${registerExtension} '\\\$INSTDIR\\\\bin\\\\sv.exe' '.ppm' 'cvkit.sv.ppm'
\\\${registerExtension} '\\\$INSTDIR\\\\bin\\\\sv.exe' '.tif' 'cvkit.sv.tif'
\\\${registerExtension} '\\\$INSTDIR\\\\bin\\\\sv.exe' '.jpg' 'cvkit.sv.jpg'
\\\${registerExtension} '\\\$INSTDIR\\\\bin\\\\sv.exe' '.png' 'cvkit.sv.png'
\\\${registerExtension} '\\\$INSTDIR\\\\bin\\\\sv.exe' '.vrt' 'cvkit.sv.vrt'
System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) v (0x08000000, 0, 0, 0)'
")
set(CPACK_NSIS_CREATE_ICONS_EXTRA "
CreateShortCut '\\\$SMPROGRAMS\\\\\$STARTMENU_FOLDER\\\\Example.lnk' '\\\$INSTDIR\\\\example'
CreateShortCut '\\\$SMPROGRAMS\\\\\$STARTMENU_FOLDER\\\\Readme.lnk' '\\\$INSTDIR\\\\doc\\\\README.txt'
CreateShortCut '\\\$SMPROGRAMS\\\\\$STARTMENU_FOLDER\\\\Usage.lnk' '\\\$INSTDIR\\\\doc\\\\USAGE.txt'
")
set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "
\\\${unregisterExtension} '.ply' 'cvkit.plyv.ply'
\\\${unregisterExtension} '.pfm' 'cvkit.sv.pfm'
\\\${unregisterExtension} '.pgm' 'cvkit.sv.pgm'
\\\${unregisterExtension} '.ppm' 'cvkit.sv.ppm'
\\\${unregisterExtension} '.tif' 'cvkit.sv.tif'
\\\${unregisterExtension} '.jpg' 'cvkit.sv.jpg'
\\\${unregisterExtension} '.png' 'cvkit.sv.png'
\\\${unregisterExtension} '.vrt' 'cvkit.sv.vrt'
System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) v (0x08000000, 0, 0, 0)'
")
set(CPACK_NSIS_DELETE_ICONS_EXTRA "
Delete '\\\$SMPROGRAMS\\\\\$MUI_TEMP\\\\Readme.lnk'
Delete '\\\$SMPROGRAMS\\\\\$MUI_TEMP\\\\Usage.lnk'
Delete '\\\$SMPROGRAMS\\\\\$MUI_TEMP\\\\Example.lnk'
")
else (WIN32)
set(CPACK_GENERATOR "DEB")
find_program(DPKG_CMD dpkg)
if (NOT DPKG_CMD)
message(STATUS "Can not find dpkg in your path, default to i386.")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386)
else ()
execute_process(COMMAND "${DPKG_CMD}" --print-architecture
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif ()
# add ~distribution-codename (e.g. ~trusty or ~xenial) to end of package version
# if lsb_release is available, take it from there or fall back to DISTRO_CODENAME env variable
set(DISTRO_CODENAME $ENV{DISTRO_CODENAME})
find_program(LSB_RELEASE_CMD lsb_release)
mark_as_advanced(LSB_RELEASE_CMD)
if (LSB_RELEASE_CMD)
execute_process(COMMAND "${LSB_RELEASE_CMD}" --codename --short
OUTPUT_VARIABLE DISTRO_CODENAME
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif ()
if (DISTRO_CODENAME)
set(CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}-1~${DISTRO_CODENAME})
else ()
message(STATUS "Could not find lsb_release nor is DISTRO_CODENAME set.")
endif ()
string(TOLOWER "${PROJECT_NAME}" CPACK_PACKAGE_NAME)
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
# Generate postinst, postrm hooks which call ldconfig
set(POSTINST_SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/postinst")
set(POSTRM_SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/postrm")
file(WRITE "${POSTINST_SCRIPT}" "#!/bin/sh\n\nset -e\n")
file(WRITE "${POSTRM_SCRIPT}" "#!/bin/sh\n\nset -e\n")
file(APPEND "${POSTINST_SCRIPT}" "if [ \"$1\" = \"configure\" ]; then\n ldconfig\nfi\n")
file(APPEND "${POSTRM_SCRIPT}" "if [ \"$1\" = \"remove\" ]; then\n ldconfig\nfi\n")
execute_process(COMMAND chmod 755 "${POSTINST_SCRIPT}" "${POSTRM_SCRIPT}")
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${POSTINST_SCRIPT};${POSTRM_SCRIPT}")
endif ()
include(CPack)
# export all DLL symbols if Visual studio is used for compilation and disable
# some warnings
if (MSVC)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
add_definitions("/wd4996")
endif ()
# set default build type to release
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "Build type: DEBUG or RELEASE" FORCE)
endif ()
# choose to install header and libs
set(INSTALL_DEVELOPMENT 1 CACHE BOOL "Install header and libs for development with cvkit")
# check for optional external packages
find_package(JPEG)
find_package(PNG)
find_package(GDAL)
find_package(OpenGL)
find_package(GLUT)
find_package(GLEW)
if (NOT WIN32 AND NOT CYGWIN)
find_package(X11)
find_path(INOTIFY_DIR sys/inotify.h)
if (INOTIFY_DIR)
include_directories(INOTIFY_DIR)
add_definitions(-DINCLUDE_INOTIFY)
endif ()
endif ()
# make it possible to compile without GDAL, even if it is available
if (GDAL_FOUND)
set(USE_GDAL 1 CACHE BOOL "Install header and libs for development with cvkit")
else ()
set(USE_GDAL 0 CACHE BOOL "Install header and libs for development with cvkit" FORCE)
endif ()
# - Optionally compile as C++11 -
set(USE_CPP11 1 CACHE BOOL "Compile as C++11 (and use standard threads)")
if (USE_CPP11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif ()
# - Optional pthread support -
find_package(Threads)
if (CMAKE_USE_PTHREADS_INIT)
set(INCLUDE_PTHREADS 1 CACHE BOOL "Use pthreads")
if (INCLUDE_PTHREADS)
add_definitions(-DINCLUDE_PTHREADS)
endif ()
else ()
set(INCLUDE_PTHREADS 0 CACHE BOOL "Use pthreads" FORCE)
endif ()
# - Standard definitions -
if (CMAKE_COMPILER_IS_GNUCC)
add_definitions(-Wall)
endif ()
if (APPLE)
add_definitions(-Wno-deprecated-declarations)
endif ()
# build individual parts
add_subdirectory(doc)
add_subdirectory(gutil)
add_subdirectory(gmath)
add_subdirectory(gimage)
add_subdirectory(bgui)
add_subdirectory(gvr)
# build excecutables
add_subdirectory(tools)
# add examples
add_subdirectory(example)
# install cmake config files in lib install directory
if (INSTALL_DEVELOPMENT)
export(TARGETS gutil gmath gimage bgui gvr
FILE "${PROJECT_BINARY_DIR}/CVKITTargets.cmake")
set(CONF_INCLUDE_DIRS "\${CVKIT_CMAKE_DIR}/../../include")
configure_file(cmake/CVKITConfig.cmake.in
"${PROJECT_BINARY_DIR}/CVKITConfig.cmake" @ONLY)
configure_file(cmake/CVKITConfigVersion.cmake.in
"${PROJECT_BINARY_DIR}/CVKITConfigVersion.cmake" @ONLY)
install(FILES
"${PROJECT_BINARY_DIR}/CVKITConfig.cmake"
"${PROJECT_BINARY_DIR}/CVKITConfigVersion.cmake"
DESTINATION lib/cvkit)
install(EXPORT CVKITTargets DESTINATION lib/cvkit)
endif ()