forked from colmap/colmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
executable file
·437 lines (363 loc) · 14 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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
# Copyright (c) 2018, ETH Zurich and UNC Chapel Hill.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * 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.
#
# * Neither the name of ETH Zurich and UNC Chapel Hill 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 HOLDERS 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.
#
# Author: Johannes L. Schoenberger (jsch-at-demuc-dot-de)
cmake_minimum_required(VERSION 3.0)
project(COLMAP)
set(COLMAP_VERSION "3.6")
set(COLMAP_VERSION_NUMBER "3600")
################################################################################
# Include CMake dependencies
################################################################################
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(CheckCXXCompilerFlag)
# Include helper macros and commands, and allow the included file to override
# the CMake policies in this file
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/CMakeHelper.cmake NO_POLICY_SCOPE)
################################################################################
# Options
################################################################################
option(SIMD_ENABLED "Whether to enable SIMD optimizations" ON)
option(OPENMP_ENABLED "Whether to enable OpenMP parallelization" ON)
option(IPO_ENABLED "Whether to enable interprocedural optimization" ON)
option(CUDA_ENABLED "Whether to enable CUDA, if available" ON)
option(OPENGL_ENABLED "Whether to enable OpenGL, if available" ON)
option(TESTS_ENABLED "Whether to build test binaries" OFF)
option(PROFILING_ENABLED "Whether to enable google-perftools linker flags" OFF)
option(CGAL_ENABLED "Whether to enable the CGAL library" ON)
option(BOOST_STATIC "Whether to enable static boost library linker flags" ON)
set(CUDA_ARCHS "Auto" CACHE STRING "List of CUDA architectures for which to \
generate code, e.g., Auto, All, Maxwell, Pascal, ...")
if(TESTS_ENABLED)
enable_testing()
endif()
if(BOOST_STATIC)
set(Boost_USE_STATIC_LIBS ON)
else()
add_definitions("-DBOOST_TEST_DYN_LINK")
endif()
################################################################################
# Find packages
################################################################################
if(OPENMP_ENABLED)
find_package(OpenMP QUIET)
endif()
find_package(Ceres REQUIRED)
find_package(Boost REQUIRED COMPONENTS
program_options
filesystem
graph
regex
system
unit_test_framework)
find_package(Eigen3 REQUIRED)
find_package(FreeImage REQUIRED)
find_package(Glog REQUIRED)
find_package(OpenGL REQUIRED)
find_package(Glew REQUIRED)
find_package(Git)
find_package(CGAL QUIET)
set(CUDA_MIN_VERSION "7.0")
if(CUDA_ENABLED)
find_package(CUDA ${CUDA_MIN_VERSION} QUIET)
endif()
find_package(Qt5 5.4 REQUIRED COMPONENTS Core OpenGL Widgets)
if(Qt5_FOUND)
message(STATUS "Found Qt")
message(STATUS " Module : ${Qt5Core_DIR}")
message(STATUS " Module : ${Qt5OpenGL_DIR}")
message(STATUS " Module : ${Qt5Widgets_DIR}")
endif()
if(CGAL_FOUND)
message(STATUS "Found CGAL")
message(STATUS " Includes : ${CGAL_INCLUDE_DIRS}")
message(STATUS " Libraries : ${CGAL_LIBRARY}")
endif()
################################################################################
# Compiler specific configuration
################################################################################
if(CMAKE_BUILD_TYPE)
message(STATUS "Build type specified as ${CMAKE_BUILD_TYPE}")
else()
message(STATUS "Build type not specified, using Release")
set(CMAKE_BUILD_TYPE Release)
set(IS_DEBUG OFF)
endif()
if(IS_MSVC)
# Some fixes for the Glog library.
add_definitions("-DGLOG_NO_ABBREVIATED_SEVERITIES")
add_definitions("-DGL_GLEXT_PROTOTYPES")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
# Enable object level parallel builds in Visual Studio.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
endif()
if(IS_GNU)
# Hide incorrect warnings for uninitialized Eigen variables under GCC.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-maybe-uninitialized")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-maybe-uninitialized")
endif()
if(IS_DEBUG)
add_definitions("-DEIGEN_INITIALIZE_MATRICES_BY_NAN")
endif()
if(SIMD_ENABLED)
message(STATUS "Enabling SIMD support")
else()
message(STATUS "Disabling SIMD support")
endif()
if(OPENMP_ENABLED AND OPENMP_FOUND)
message(STATUS "Enabling OpenMP support")
add_definitions("-DOPENMP_ENABLED")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
else()
message(STATUS "Disabling OpenMP support")
endif()
if(IPO_ENABLED AND NOT IS_DEBUG AND NOT IS_GNU)
message(STATUS "Enabling interprocedural optimization")
set_property(DIRECTORY PROPERTY INTERPROCEDURAL_OPTIMIZATION 1)
else()
message(STATUS "Disabling interprocedural optimization")
endif()
if(CUDA_FOUND)
if(CUDA_ENABLED)
add_definitions("-DCUDA_ENABLED")
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SelectCudaComputeArch.cmake)
CUDA_SELECT_NVCC_ARCH_FLAGS(CUDA_ARCH_FLAGS ${CUDA_ARCHS})
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} ${CUDA_ARCH_FLAGS}")
# Fix for some combinations of CUDA and GCC (e.g. under Ubuntu 16.04).
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -D_FORCE_INLINES")
# Do not show warnings if the architectures are deprecated.
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Wno-deprecated-gpu-targets")
message(STATUS "Enabling CUDA support (version: ${CUDA_VERSION_STRING},"
" archs: ${CUDA_ARCH_FLAGS_readable})")
else()
set(CUDA_FOUND OFF)
message(STATUS "Disabling CUDA support")
endif()
else()
set(CUDA_ENABLED OFF)
if(CUDA_VERSION_STRING)
message(STATUS "Disabling CUDA support (found version "
"${CUDA_VERSION_STRING} but >= ${CUDA_MIN_VERSION} required)")
else()
message(STATUS "Disabling CUDA support")
endif()
endif()
if(OPENGL_ENABLED)
add_definitions("-DOPENGL_ENABLED")
message(STATUS "Enabling OpenGL support")
else()
message(STATUS "Disabling OpenGL support")
endif()
if(PROFILING_ENABLED)
message(STATUS "Enabling profiling support")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lprofiler -ltcmalloc")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lprofiler -ltcmalloc")
else()
message(STATUS "Disabling profiling support")
endif()
if(CGAL_FOUND AND CGAL_ENABLED)
message(STATUS "Enabling CGAL support")
add_definitions("-DCGAL_ENABLED")
else()
message(STATUS "Disabling CGAL support")
set(CGAL_ENABLED OFF)
endif()
# Qt5 was built with -reduce-relocations.
if(Qt5_POSITION_INDEPENDENT_CODE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if(CUDA_ENABLED AND NOT IS_MSVC)
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} --compiler-options -fPIC")
endif()
endif()
# Enable automatic compilation of Qt resource files.
set(CMAKE_AUTORCC ON)
################################################################################
# Add sources
################################################################################
# Generate source file with version definitions.
include(GenerateVersionDefinitions)
set(COLMAP_INCLUDE_DIRS
${Boost_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIRS}
${GLOG_INCLUDE_DIRS}
${FREEIMAGE_INCLUDE_DIRS}
${CERES_INCLUDE_DIRS}
${GLEW_INCLUDE_DIRS}
${Qt5Core_INCLUDE_DIRS}
${Qt5OpenGL_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS}
)
set(COLMAP_LINK_DIRS
${Boost_LIBRARY_DIRS}
)
set(COLMAP_EXTERNAL_LIBRARIES
${CMAKE_DL_LIBS}
${Boost_FILESYSTEM_LIBRARY}
${Boost_PROGRAM_OPTIONS_LIBRARY}
${Boost_REGEX_LIBRARY}
${Boost_SYSTEM_LIBRARY}
${GLOG_LIBRARIES}
${FREEIMAGE_LIBRARIES}
${CERES_LIBRARIES}
${OPENGL_gl_LIBRARY}
${OPENGL_glu_LIBRARY}
${Qt5Core_LIBRARIES}
${Qt5OpenGL_LIBRARIES}
${Qt5Widgets_LIBRARIES}
)
if(CGAL_ENABLED)
list(APPEND COLMAP_INCLUDE_DIRS ${CGAL_INCLUDE_DIRS} ${GMP_INCLUDE_DIR})
list(APPEND COLMAP_EXTERNAL_LIBRARIES ${CGAL_LIBRARY} ${GMP_LIBRARIES})
list(APPEND COLMAP_LINK_DIRS ${CGAL_LIBRARIES_DIR})
endif()
if(UNIX)
list(APPEND COLMAP_EXTERNAL_LIBRARIES pthread)
endif()
set(COLMAP_INTERNAL_LIBRARIES
colmap
flann
graclus
lsd
pba
poisson_recon
sqlite3
sift_gpu
vlfeat
)
if(CUDA_ENABLED)
list(APPEND COLMAP_INTERNAL_LIBRARIES colmap_cuda colmap)
endif()
set(COLMAP_LIBRARIES
${COLMAP_INTERNAL_LIBRARIES}
${COLMAP_EXTERNAL_LIBRARIES}
)
include_directories(
lib
src
${COLMAP_INCLUDE_DIRS}
)
link_directories(${COLMAP_LINK_DIRS})
add_subdirectory(lib)
add_subdirectory(src)
################################################################################
# Generate source groups for Visual Studio, XCode, etc.
################################################################################
COLMAP_ADD_SOURCE_DIR(lib/FLANN LIB_FLANN_SRCS *.h *.cpp *.hpp *.cu)
COLMAP_ADD_SOURCE_DIR(lib/Graclus LIB_GRACLUS_SRCS *.h *.c)
COLMAP_ADD_SOURCE_DIR(lib/LSD LIB_LSD_SRCS *.h *.c)
COLMAP_ADD_SOURCE_DIR(lib/PBA LIB_PBA_SRCS *.h *.cpp *.cu)
COLMAP_ADD_SOURCE_DIR(lib/PoissonRecon LIB_POISSON_RECON_SRCS *.h *.cpp *.inl)
COLMAP_ADD_SOURCE_DIR(lib/SiftGPU LIB_SIFT_GPU_SRCS *.h *.cpp *.cu)
COLMAP_ADD_SOURCE_DIR(lib/SQLite LIB_SQLITE_SRCS *.h *.c)
COLMAP_ADD_SOURCE_DIR(lib/VLFeat LIB_VLFEAT_SRCS *.h *.c *.tc)
COLMAP_ADD_SOURCE_DIR(src/base BASE_SRCS *.h *.cc)
COLMAP_ADD_SOURCE_DIR(src/controllers CONTROLLERS_SRCS *.h *.cc)
COLMAP_ADD_SOURCE_DIR(src/estimators ESTIMATORS_SRCS *.h *.cc)
COLMAP_ADD_SOURCE_DIR(src/exe EXE_SRCS *.h *.cc)
COLMAP_ADD_SOURCE_DIR(src/feature FEATURE_SRCS *.h *.cc)
COLMAP_ADD_SOURCE_DIR(src/mvs MVS_SRCS *.h *.cc *.cu)
COLMAP_ADD_SOURCE_DIR(src/optim OPTIM_SRCS *.h *.cc)
COLMAP_ADD_SOURCE_DIR(src/retrieval RETRIEVAL_SRCS *.h *.cc)
COLMAP_ADD_SOURCE_DIR(src/sfm SFM_SRCS *.h *.cc)
COLMAP_ADD_SOURCE_DIR(src/tools TOOLS_SRCS *.h *.cc)
COLMAP_ADD_SOURCE_DIR(src/ui UI_SRCS *.h *.cc)
COLMAP_ADD_SOURCE_DIR(src/util UTIL_SRCS *.h *.cc)
# Add all of the source files to a regular library target, as using a custom
# target does not allow us to set its C++ include directories (and thus
# intellisense can't find any of the included files).
add_library(
${COLMAP_SRC_ROOT_FOLDER}
${LIB_FLANN_SRCS}
${LIB_GRACLUS_SRCS}
${LIB_LSD_SRCS}
${LIB_PBA_SRCS}
${LIB_POISSON_RECON_SRCS}
${LIB_SIFT_GPU_SRCS}
${LIB_SQLITE_SRCS}
${LIB_VLFEAT_SRCS}
${BASE_SRCS}
${CONTROLLERS_SRCS}
${ESTIMATORS_SRCS}
${EXE_SRCS}
${FEATURE_SRCS}
${MVS_SRCS}
${OPTIM_SRCS}
${RETRIEVAL_SRCS}
${SFM_SRCS}
${TOOLS_SRCS}
${UI_SRCS}
${UTIL_SRCS}
)
# Prevent the library from being compiled automatically.
set_target_properties(
${COLMAP_SRC_ROOT_FOLDER} PROPERTIES
EXCLUDE_FROM_ALL 1
EXCLUDE_FROM_DEFAULT_BUILD 1)
################################################################################
# Install and uninstall scripts
################################################################################
# Install header files.
install(DIRECTORY src/
DESTINATION include/colmap
FILES_MATCHING PATTERN "*.h")
install(DIRECTORY lib/
DESTINATION include/colmap/lib
FILES_MATCHING REGEX ".*[.]h|.*[.]hpp|.*[.]inl")
# Generate and install CMake configuration.
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/CMakeConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/COLMAPConfig.cmake" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/COLMAPConfig.cmake"
DESTINATION "share/colmap")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/CMakeConfigVersion.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/COLMAPConfigVersion.cmake" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/COLMAPConfigVersion.cmake"
DESTINATION "share/colmap")
# Install find_package scripts for dependencies.
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cmake
DESTINATION share/colmap
FILES_MATCHING PATTERN "Find*.cmake")
# Install batch scripts under Windows.
if(IS_MSVC)
install(FILES "scripts/shell/COLMAP.bat" "scripts/shell/RUN_TESTS.bat"
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
DESTINATION "/")
endif()
# Install application meny entry under Linux/Unix.
if(UNIX AND NOT APPLE)
install(FILES "doc/COLMAP.desktop" DESTINATION "share/applications")
endif()
# Configure the uninstallation script.
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/CMakeUninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/CMakeUninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/CMakeUninstall.cmake)
set_target_properties(uninstall PROPERTIES FOLDER ${CMAKE_TARGETS_ROOT_FOLDER})