| 1 |
# Copyright (c), ETH Zurich and UNC Chapel Hill. |
| 2 |
# All rights reserved. |
| 3 |
# |
| 4 |
# Redistribution and use in source and binary forms, with or without |
| 5 |
# modification, are permitted provided that the following conditions are met: |
| 6 |
# |
| 7 |
# * Redistributions of source code must retain the above copyright |
| 8 |
# notice, this list of conditions and the following disclaimer. |
| 9 |
# |
| 10 |
# * Redistributions in binary form must reproduce the above copyright |
| 11 |
# notice, this list of conditions and the following disclaimer in the |
| 12 |
# documentation and/or other materials provided with the distribution. |
| 13 |
# |
| 14 |
# * Neither the name of ETH Zurich and UNC Chapel Hill nor the names of |
| 15 |
# its contributors may be used to endorse or promote products derived |
| 16 |
# from this software without specific prior written permission. |
| 17 |
# |
| 18 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 |
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 |
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE |
| 22 |
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 |
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 |
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 |
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 |
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 |
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 |
# POSSIBILITY OF SUCH DAMAGE. |
| 29 |
|
| 30 |
|
| 31 |
cmake_minimum_required(VERSION 3.12) |
| 32 |
|
| 33 |
################################################################################ |
| 34 |
# Options |
| 35 |
################################################################################ |
| 36 |
|
| 37 |
option(SIMD_ENABLED "Whether to enable SIMD optimizations" ON) |
| 38 |
option(OPENMP_ENABLED "Whether to enable OpenMP parallelization" ON) |
| 39 |
option(IPO_ENABLED "Whether to enable interprocedural optimization" ON) |
| 40 |
option(CUDA_ENABLED "Whether to enable CUDA, if available" ON) |
| 41 |
option(HIP_ENABLED "Whether to enable AMD GPU support via HIP/ROCm" OFF) |
| 42 |
|
| 43 |
if(CUDA_ENABLED AND HIP_ENABLED) |
| 44 |
message(FATAL_ERROR "CUDA and HIP cannot be enabled at the same time") |
| 45 |
endif() |
| 46 |
|
| 47 |
# enable_language(HIP) and set_source_files_properties(LANGUAGE HIP) require |
| 48 |
# CMake 3.21+. Bump the minimum only when HIP is requested so CUDA-only and |
| 49 |
# CPU-only builds continue to work on older CMake versions. |
| 50 |
if(HIP_ENABLED) |
| 51 |
cmake_minimum_required(VERSION 3.21) |
| 52 |
endif() |
| 53 |
option(ONNX_ENABLED "Whether to enable ONNX, if available" ON) |
| 54 |
option(GUI_ENABLED "Whether to enable the graphical UI" ON) |
| 55 |
option(MVS_ENABLED "Whether to enable the Multi-View Stereo module" ON) |
| 56 |
option(OPENGL_ENABLED "Whether to enable OpenGL, if available" ON) |
| 57 |
option(TESTS_ENABLED "Whether to build test binaries" OFF) |
| 58 |
option(COVERAGE_ENABLED "Whether to enable code coverage" OFF) |
| 59 |
option(ASAN_ENABLED "Whether to enable AddressSanitizer flags" OFF) |
| 60 |
option(TSAN_ENABLED "Whether to enable ThreadSanitizer flags" OFF) |
| 61 |
option(UBSAN_ENABLED "Whether to enable UndefinedBehaviorSanitizer flags" OFF) |
| 62 |
option(PROFILING_ENABLED "Whether to enable google-perftools linker flags" OFF) |
| 63 |
option(WERROR_ENABLED "Whether to treat compiler warnings as errors" OFF) |
| 64 |
option(CCACHE_ENABLED "Whether to enable compiler caching, if available" ON) |
| 65 |
option(CGAL_ENABLED "Whether to enable the CGAL library" ON) |
| 66 |
option(LSD_ENABLED "Whether to enable the LSD library" ON) |
| 67 |
option(DOWNLOAD_ENABLED "Whether to enable (automatic) download of resources (requires Curl/OpenSSL)" ON) |
| 68 |
option(UNINSTALL_ENABLED "Whether to create a target to 'uninstall' colmap" ON) |
| 69 |
option(BENCHMARK_ENABLED "Whether to enable runtime benchmarking support" OFF) |
| 70 |
option(FETCH_POSELIB "Whether to consume PoseLib using FetchContent or find_package" ON) |
| 71 |
option(FETCH_FAISS "Whether to consume faiss using FetchContent or find_package" ON) |
| 72 |
option(FETCH_ONNX "Whether to consume ONNX using FetchContent or find_package" ON) |
| 73 |
option(BUILD_SHARED_LIBS "Whether to build shared libraries (faster linktime, slower runtime)" OFF) |
| 74 |
option(ALL_SOURCE_TARGET "Whether to create a target for all source files (for Visual Studio / XCode development)" OFF) |
| 75 |
|
| 76 |
# Experimental |
| 77 |
option(CASPAR_ENABLED "Whether to enable CASPAR-accelerated bundle adjustment" OFF) |
| 78 |
option(CASPAR_USE_DOUBLE "Use double precision in Caspar solver" OFF) |
| 79 |
|
| 80 |
# Hash map backend used by the performance-critical scene/SfM containers (see |
| 81 |
# src/colmap/util/hash_containers.h). One of: STD, BOOST, or empty for auto. |
| 82 |
# Auto selects BOOST (faster boost::unordered_flat/node maps) when the available |
| 83 |
# Boost is new enough (>= 1.84, for boost::unordered_node_map) and STD otherwise. |
| 84 |
set(COLMAP_HASH_MAP_BACKEND "" CACHE STRING |
| 85 |
"Hash map backend for scene/SfM containers: STD, BOOST, or empty for auto") |
| 86 |
set_property(CACHE COLMAP_HASH_MAP_BACKEND PROPERTY STRINGS "" STD BOOST) |
| 87 |
|
| 88 |
if(CASPAR_ENABLED) |
| 89 |
add_compile_definitions(CASPAR_ENABLED) |
| 90 |
if(CASPAR_USE_DOUBLE) |
| 91 |
add_compile_definitions(CASPAR_USE_DOUBLE) |
| 92 |
endif() |
| 93 |
endif() |
| 94 |
|
| 95 |
# Disables default features, as we specify each required feature manually below. |
| 96 |
list(APPEND VCPKG_MANIFEST_FEATURES "core") |
| 97 |
|
| 98 |
# Propagate options to vcpkg manifest. |
| 99 |
if(TESTS_ENABLED) |
| 100 |
list(APPEND VCPKG_MANIFEST_FEATURES "tests") |
| 101 |
endif() |
| 102 |
if(CUDA_ENABLED) |
| 103 |
list(APPEND VCPKG_MANIFEST_FEATURES "cuda") |
| 104 |
endif() |
| 105 |
if(ONNX_ENABLED AND NOT FETCH_ONNX) |
| 106 |
list(APPEND VCPKG_MANIFEST_FEATURES "onnx") |
| 107 |
endif() |
| 108 |
if(GUI_ENABLED) |
| 109 |
list(APPEND VCPKG_MANIFEST_FEATURES "gui") |
| 110 |
endif() |
| 111 |
if(CGAL_ENABLED) |
| 112 |
list(APPEND VCPKG_MANIFEST_FEATURES "cgal") |
| 113 |
endif() |
| 114 |
|
| 115 |
if(DOWNLOAD_ENABLED) |
| 116 |
list(APPEND VCPKG_MANIFEST_FEATURES "download") |
| 117 |
endif() |
| 118 |
|
| 119 |
project(COLMAP LANGUAGES C CXX) |
| 120 |
|
| 121 |
set(COLMAP_VERSION "4.2.0") |
| 122 |
|
| 123 |
set(CMAKE_CXX_STANDARD 17) |
| 124 |
set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 125 |
set(CMAKE_CUDA_STANDARD 17) |
| 126 |
set(CMAKE_CUDA_STANDARD_REQUIRED ON) |
| 127 |
|
| 128 |
set_property(GLOBAL PROPERTY GLOBAL_DEPENDS_NO_CYCLES ON) |
| 129 |
|
| 130 |
################################################################################ |
| 131 |
# Include CMake dependencies |
| 132 |
################################################################################ |
| 133 |
|
| 134 |
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) |
| 135 |
|
| 136 |
include(CheckCXXCompilerFlag) |
| 137 |
include(GNUInstallDirs) |
| 138 |
|
| 139 |
# Include helper macros and commands, and allow the included file to override |
| 140 |
# the CMake policies in this file |
| 141 |
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/CMakeHelper.cmake NO_POLICY_SCOPE) |
| 142 |
|
| 143 |
# Build position-independent code, so that shared libraries can link against |
| 144 |
# COLMAP's static libraries. |
| 145 |
set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
| 146 |
|
| 147 |
################################################################################ |
| 148 |
# Dependency configuration |
| 149 |
################################################################################ |
| 150 |
|
| 151 |
set(COLMAP_FIND_QUIETLY FALSE) |
| 152 |
include(cmake/FindDependencies.cmake) |
| 153 |
|
| 154 |
################################################################################ |
| 155 |
# Compiler specific configuration |
| 156 |
################################################################################ |
| 157 |
|
| 158 |
if(CMAKE_BUILD_TYPE) |
| 159 |
message(STATUS "Build type specified as ${CMAKE_BUILD_TYPE}") |
| 160 |
else() |
| 161 |
message(STATUS "Build type not specified, using Release") |
| 162 |
set(CMAKE_BUILD_TYPE Release) |
| 163 |
set(IS_DEBUG OFF) |
| 164 |
endif() |
| 165 |
|
| 166 |
if("${CMAKE_BUILD_TYPE}" STREQUAL "ClangTidy") |
| 167 |
find_program(CLANG_TIDY_EXE NAMES clang-tidy) |
| 168 |
if(NOT CLANG_TIDY_EXE) |
| 169 |
message(FATAL_ERROR "Could not find the clang-tidy executable, please set CLANG_TIDY_EXE") |
| 170 |
endif() |
| 171 |
else() |
| 172 |
unset(CLANG_TIDY_EXE) |
| 173 |
endif() |
| 174 |
|
| 175 |
if(IS_MSVC) |
| 176 |
# Some fixes for the Glog library. |
| 177 |
add_compile_definitions(GLOG_USE_GLOG_EXPORT) |
| 178 |
add_compile_definitions(GLOG_NO_ABBREVIATED_SEVERITIES) |
| 179 |
add_compile_definitions(GL_GLEXT_PROTOTYPES) |
| 180 |
add_compile_definitions(NOMINMAX) |
| 181 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") |
| 182 |
# Disable warning: 'initializing': conversion from 'X' to 'Y', possible loss of data |
| 183 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244 /wd4267 /wd4305") |
| 184 |
# Enable object level parallel builds in Visual Studio. |
| 185 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP") |
| 186 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") |
| 187 |
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug" OR "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") |
| 188 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /bigobj") |
| 189 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") |
| 190 |
endif() |
| 191 |
endif() |
| 192 |
|
| 193 |
if(IS_GNU) |
| 194 |
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) |
| 195 |
message(FATAL_ERROR "GCC version 4.8 or older not supported") |
| 196 |
endif() |
| 197 |
endif() |
| 198 |
|
| 199 |
if(IS_MACOS) |
| 200 |
# Mitigate CMake limitation, see: https://discourse.cmake.org/t/avoid-duplicate-linking-to-avoid-xcode-15-warnings/9084/10 |
| 201 |
add_link_options(LINKER:-no_warn_duplicate_libraries) |
| 202 |
endif() |
| 203 |
|
| 204 |
# Correctly set RPATH to look up dependencies. |
| 205 |
if(NOT IS_MSVC) |
| 206 |
if(IS_MACOS) |
| 207 |
set(RPATH_BASE "@executable_path") |
| 208 |
else() |
| 209 |
set(RPATH_BASE "$ORIGIN") |
| 210 |
endif() |
| 211 |
file(RELATIVE_PATH INSTALL_LIB_DIR "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}" "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}") |
| 212 |
list(APPEND CMAKE_INSTALL_RPATH "${RPATH_BASE}/${INSTALL_LIB_DIR}") |
| 213 |
endif() |
| 214 |
|
| 215 |
if(IS_DEBUG) |
| 216 |
add_compile_definitions(EIGEN_INITIALIZE_MATRICES_BY_NAN) |
| 217 |
endif() |
| 218 |
|
| 219 |
if(SIMD_ENABLED) |
| 220 |
message(STATUS "Enabling SIMD support") |
| 221 |
else() |
| 222 |
message(STATUS "Disabling SIMD support") |
| 223 |
endif() |
| 224 |
|
| 225 |
if(IPO_ENABLED AND NOT IS_DEBUG AND NOT IS_GNU) |
| 226 |
message(STATUS "Enabling interprocedural optimization") |
| 227 |
set_property(DIRECTORY PROPERTY INTERPROCEDURAL_OPTIMIZATION 1) |
| 228 |
else() |
| 229 |
message(STATUS "Disabling interprocedural optimization") |
| 230 |
endif() |
| 231 |
|
| 232 |
if(ASAN_ENABLED) |
| 233 |
message(STATUS "Enabling ASan support") |
| 234 |
if(IS_CLANG OR IS_GNU) |
| 235 |
add_compile_options(-fsanitize=address -fno-omit-frame-pointer -fsanitize-address-use-after-scope) |
| 236 |
add_link_options(-fsanitize=address) |
| 237 |
else() |
| 238 |
message(FATAL_ERROR "Unsupported compiler for ASan mode") |
| 239 |
endif() |
| 240 |
endif() |
| 241 |
|
| 242 |
if(TSAN_ENABLED) |
| 243 |
message(STATUS "Enabling TSan support") |
| 244 |
if(IS_CLANG OR IS_GNU) |
| 245 |
add_compile_options(-fsanitize=thread) |
| 246 |
add_link_options(-fsanitize=thread) |
| 247 |
else() |
| 248 |
message(FATAL_ERROR "Unsupported compiler for TSan mode") |
| 249 |
endif() |
| 250 |
endif() |
| 251 |
|
| 252 |
if(UBSAN_ENABLED) |
| 253 |
message(STATUS "Enabling UBsan support") |
| 254 |
if(IS_CLANG OR IS_GNU) |
| 255 |
add_compile_options(-fsanitize=undefined) |
| 256 |
add_link_options(-fsanitize=undefined) |
| 257 |
else() |
| 258 |
message(FATAL_ERROR "Unsupported compiler for UBsan mode") |
| 259 |
endif() |
| 260 |
endif() |
| 261 |
|
| 262 |
if(CCACHE_ENABLED) |
| 263 |
find_program(CCACHE ccache) |
| 264 |
if(CCACHE) |
| 265 |
message(STATUS "Enabling ccache support") |
| 266 |
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE}) |
| 267 |
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE}) |
| 268 |
if(CUDA_ENABLED) |
| 269 |
set(CMAKE_CUDA_COMPILER_LAUNCHER ${CCACHE}) |
| 270 |
endif() |
| 271 |
else() |
| 272 |
message(STATUS "Disabling ccache support") |
| 273 |
endif() |
| 274 |
else() |
| 275 |
message(STATUS "Disabling ccache support") |
| 276 |
endif() |
| 277 |
|
| 278 |
if(PROFILING_ENABLED) |
| 279 |
message(STATUS "Enabling profiling support") |
| 280 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lprofiler -ltcmalloc") |
| 281 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lprofiler -ltcmalloc") |
| 282 |
else() |
| 283 |
message(STATUS "Disabling profiling support") |
| 284 |
endif() |
| 285 |
|
| 286 |
if(TESTS_ENABLED) |
| 287 |
message(STATUS "Enabling tests") |
| 288 |
enable_testing() |
| 289 |
include(CTest) |
| 290 |
else() |
| 291 |
message(STATUS "Disabling tests") |
| 292 |
endif() |
| 293 |
|
| 294 |
if(COVERAGE_ENABLED) |
| 295 |
message(STATUS "Enabling coverage support") |
| 296 |
else() |
| 297 |
message(STATUS "Disabling coverage support") |
| 298 |
endif() |
| 299 |
|
| 300 |
################################################################################ |
| 301 |
# Add sources |
| 302 |
################################################################################ |
| 303 |
|
| 304 |
# Generate source file with version definitions. |
| 305 |
include(GenerateVersionDefinitions) |
| 306 |
|
| 307 |
include_directories(src) |
| 308 |
link_directories(${COLMAP_LINK_DIRS}) |
| 309 |
|
| 310 |
add_subdirectory(src/thirdparty) |
| 311 |
add_subdirectory(src/colmap) |
| 312 |
|
| 313 |
if(BENCHMARK_ENABLED) |
| 314 |
add_subdirectory(benchmark/runtime) |
| 315 |
endif() |
| 316 |
|
| 317 |
################################################################################ |
| 318 |
# Generate source groups for Visual Studio, XCode, etc. |
| 319 |
################################################################################ |
| 320 |
|
| 321 |
COLMAP_ADD_SOURCE_DIR(src/colmap/controllers CONTROLLERS_SRCS *.h *.cc) |
| 322 |
COLMAP_ADD_SOURCE_DIR(src/colmap/estimators ESTIMATORS_SRCS *.h *.cc) |
| 323 |
COLMAP_ADD_SOURCE_DIR(src/colmap/estimators/cost_functions ESTIMATORS_COST_FUNCTIONS_SRCS *.h *.cc) |
| 324 |
COLMAP_ADD_SOURCE_DIR(src/colmap/estimators/solvers ESTIMATORS_SOLVERS_SRCS *.h *.cc) |
| 325 |
COLMAP_ADD_SOURCE_DIR(src/colmap/exe EXE_SRCS *.h *.cc) |
| 326 |
COLMAP_ADD_SOURCE_DIR(src/colmap/feature FEATURE_SRCS *.h *.cc) |
| 327 |
COLMAP_ADD_SOURCE_DIR(src/colmap/geometry GEOMETRY_SRCS *.h *.cc) |
| 328 |
COLMAP_ADD_SOURCE_DIR(src/colmap/image IMAGE_SRCS *.h *.cc) |
| 329 |
COLMAP_ADD_SOURCE_DIR(src/colmap/math MATH_SRCS *.h *.cc) |
| 330 |
if(MVS_ENABLED) |
| 331 |
COLMAP_ADD_SOURCE_DIR(src/colmap/mvs MVS_SRCS *.h *.cc *.cu) |
| 332 |
endif() |
| 333 |
COLMAP_ADD_SOURCE_DIR(src/colmap/optim OPTIM_SRCS *.h *.cc) |
| 334 |
COLMAP_ADD_SOURCE_DIR(src/colmap/retrieval RETRIEVAL_SRCS *.h *.cc) |
| 335 |
COLMAP_ADD_SOURCE_DIR(src/colmap/scene SCENE_SRCS *.h *.cc) |
| 336 |
COLMAP_ADD_SOURCE_DIR(src/colmap/sensor SENSOR_SRCS *.h *.cc) |
| 337 |
COLMAP_ADD_SOURCE_DIR(src/colmap/sfm SFM_SRCS *.h *.cc) |
| 338 |
COLMAP_ADD_SOURCE_DIR(src/colmap/tools TOOLS_SRCS *.h *.cc) |
| 339 |
COLMAP_ADD_SOURCE_DIR(src/colmap/ui UI_SRCS *.h *.cc) |
| 340 |
COLMAP_ADD_SOURCE_DIR(src/colmap/util UTIL_SRCS *.h *.cc) |
| 341 |
|
| 342 |
if(LSD_ENABLED) |
| 343 |
COLMAP_ADD_SOURCE_DIR(src/thirdparty/LSD THIRDPARTY_LSD_SRCS *.h *.c) |
| 344 |
endif() |
| 345 |
COLMAP_ADD_SOURCE_DIR(src/thirdparty/PoissonRecon THIRDPARTY_POISSON_RECON_SRCS *.h *.cpp *.inl) |
| 346 |
COLMAP_ADD_SOURCE_DIR(src/thirdparty/SiftGPU THIRDPARTY_SIFT_GPU_SRCS *.h *.cpp *.cu) |
| 347 |
COLMAP_ADD_SOURCE_DIR(src/thirdparty/VLFeat THIRDPARTY_VLFEAT_SRCS *.h *.c *.tc) |
| 348 |
|
| 349 |
# Add all of the source files to a regular library target, as using a custom |
| 350 |
# target does not allow us to set its C++ include directories (and thus |
| 351 |
# intellisense can't find any of the included files). |
| 352 |
if(ALL_SOURCE_TARGET) |
| 353 |
set(ALL_SRCS |
| 354 |
${CONTROLLERS_SRCS} |
| 355 |
${ESTIMATORS_SRCS} |
| 356 |
${ESTIMATORS_COST_FUNCTIONS_SRCS} |
| 357 |
${ESTIMATORS_SOLVERS_SRCS} |
| 358 |
${EXE_SRCS} |
| 359 |
${FEATURE_SRCS} |
| 360 |
${GEOMETRY_SRCS} |
| 361 |
${IMAGE_SRCS} |
| 362 |
${MATH_SRCS} |
| 363 |
${OPTIM_SRCS} |
| 364 |
${RETRIEVAL_SRCS} |
| 365 |
${SCENE_SRCS} |
| 366 |
${SENSOR_SRCS} |
| 367 |
${SFM_SRCS} |
| 368 |
${TOOLS_SRCS} |
| 369 |
${UI_SRCS} |
| 370 |
${UTIL_SRCS} |
| 371 |
${THIRDPARTY_POISSON_RECON_SRCS} |
| 372 |
${THIRDPARTY_SIFT_GPU_SRCS} |
| 373 |
${THIRDPARTY_VLFEAT_SRCS} |
| 374 |
) |
| 375 |
|
| 376 |
if(MVS_ENABLED) |
| 377 |
list(APPEND ALL_SRCS |
| 378 |
${MVS_SRCS} |
| 379 |
) |
| 380 |
endif() |
| 381 |
|
| 382 |
if(LSD_ENABLED) |
| 383 |
list(APPEND ALL_SRCS |
| 384 |
${THIRDPARTY_LSD_SRCS} |
| 385 |
) |
| 386 |
endif() |
| 387 |
|
| 388 |
add_library( |
| 389 |
${COLMAP_SRC_ROOT_FOLDER} |
| 390 |
${ALL_SRCS} |
| 391 |
) |
| 392 |
|
| 393 |
# Prevent the library from being compiled automatically. |
| 394 |
set_target_properties( |
| 395 |
${COLMAP_SRC_ROOT_FOLDER} PROPERTIES |
| 396 |
EXCLUDE_FROM_ALL 1 |
| 397 |
EXCLUDE_FROM_DEFAULT_BUILD 1) |
| 398 |
endif() |
| 399 |
|
| 400 |
################################################################################ |
| 401 |
# Install and uninstall scripts |
| 402 |
################################################################################ |
| 403 |
|
| 404 |
# Install batch scripts under Windows. |
| 405 |
if(IS_MSVC) |
| 406 |
install(FILES "scripts/shell/COLMAP.bat" "scripts/shell/RUN_TESTS.bat" |
| 407 |
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE |
| 408 |
GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE |
| 409 |
DESTINATION "/") |
| 410 |
endif() |
| 411 |
|
| 412 |
# Install application meny entry and icon under Linux/Unix. |
| 413 |
if(UNIX AND NOT APPLE) |
| 414 |
install(FILES "doc/COLMAP.desktop" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications") |
| 415 |
# Install the app icon so the desktop entry's "Icon=colmap" resolves. |
| 416 |
install(FILES "src/colmap/ui/media/colmap-logo.svg" |
| 417 |
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps" |
| 418 |
RENAME "colmap.svg") |
| 419 |
endif() |
| 420 |
|
| 421 |
# Configure the uninstallation script. |
| 422 |
if(UNINSTALL_ENABLED) |
| 423 |
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/CMakeUninstall.cmake.in" |
| 424 |
"${CMAKE_CURRENT_BINARY_DIR}/CMakeUninstall.cmake" |
| 425 |
IMMEDIATE @ONLY) |
| 426 |
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/CMakeUninstall.cmake) |
| 427 |
set_target_properties(uninstall PROPERTIES FOLDER ${CMAKE_TARGETS_ROOT_FOLDER}) |
| 428 |
endif() |
| 429 |
|
| 430 |
set(COLMAP_EXPORT_LIBS |
| 431 |
# Internal. |
| 432 |
colmap_controllers |
| 433 |
colmap_estimators |
| 434 |
colmap_estimators_cost_functions |
| 435 |
colmap_estimators_solvers |
| 436 |
colmap_exe |
| 437 |
colmap_feature_types |
| 438 |
colmap_feature |
| 439 |
colmap_geometry |
| 440 |
colmap_image |
| 441 |
colmap_math |
| 442 |
colmap_optim |
| 443 |
colmap_retrieval |
| 444 |
colmap_scene |
| 445 |
colmap_scene_types |
| 446 |
colmap_sensor |
| 447 |
colmap_sfm |
| 448 |
colmap_util |
| 449 |
# Third-party. |
| 450 |
colmap_poisson_recon |
| 451 |
colmap_vlfeat |
| 452 |
) |
| 453 |
if(MVS_ENABLED) |
| 454 |
list(APPEND COLMAP_EXPORT_LIBS colmap_mvs) |
| 455 |
endif() |
| 456 |
if(LSD_ENABLED) |
| 457 |
list(APPEND COLMAP_EXPORT_LIBS |
| 458 |
# Third-party. |
| 459 |
colmap_lsd |
| 460 |
) |
| 461 |
endif() |
| 462 |
if(GUI_ENABLED) |
| 463 |
list(APPEND COLMAP_EXPORT_LIBS |
| 464 |
colmap_ui |
| 465 |
) |
| 466 |
endif() |
| 467 |
if(CUDA_ENABLED OR HIP_ENABLED) |
| 468 |
list(APPEND COLMAP_EXPORT_LIBS |
| 469 |
colmap_util_cuda |
| 470 |
) |
| 471 |
if(MVS_ENABLED) |
| 472 |
list(APPEND COLMAP_EXPORT_LIBS colmap_mvs_cuda) |
| 473 |
endif() |
| 474 |
endif() |
| 475 |
if(GPU_ENABLED) |
| 476 |
list(APPEND COLMAP_EXPORT_LIBS |
| 477 |
colmap_sift_gpu |
| 478 |
) |
| 479 |
endif() |
| 480 |
if(FETCH_POSELIB) |
| 481 |
list(APPEND COLMAP_EXPORT_LIBS PoseLib) |
| 482 |
endif() |
| 483 |
if(FETCH_FAISS) |
| 484 |
list(APPEND COLMAP_EXPORT_LIBS faiss) |
| 485 |
endif() |
| 486 |
if(CASPAR_ENABLED) |
| 487 |
list(APPEND COLMAP_EXPORT_LIBS caspar_lib_core) |
| 488 |
endif() |
| 489 |
|
| 490 |
# Add unified interface library target to export. |
| 491 |
add_library(colmap INTERFACE) |
| 492 |
target_link_libraries(colmap INTERFACE ${COLMAP_EXPORT_LIBS}) |
| 493 |
target_include_directories( |
| 494 |
colmap |
| 495 |
INTERFACE |
| 496 |
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> |
| 497 |
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>) |
| 498 |
|
| 499 |
install( |
| 500 |
TARGETS colmap ${COLMAP_EXPORT_LIBS} |
| 501 |
EXPORT colmap-targets |
| 502 |
LIBRARY DESTINATION thirdparty/) |
| 503 |
|
| 504 |
# Generate config and version. |
| 505 |
include(CMakePackageConfigHelpers) |
| 506 |
set(PACKAGE_CONFIG_FILE "${CMAKE_CURRENT_BINARY_DIR}/colmap-config.cmake") |
| 507 |
set(INSTALL_CONFIG_DIR "${CMAKE_INSTALL_DATAROOTDIR}/colmap") |
| 508 |
configure_package_config_file( |
| 509 |
${CMAKE_CURRENT_SOURCE_DIR}/cmake/colmap-config.cmake.in ${PACKAGE_CONFIG_FILE} |
| 510 |
INSTALL_DESTINATION ${INSTALL_CONFIG_DIR}) |
| 511 |
install(FILES ${PACKAGE_CONFIG_FILE} DESTINATION ${INSTALL_CONFIG_DIR}) |
| 512 |
|
| 513 |
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/colmap-config-version.cmake.in" |
| 514 |
"${CMAKE_CURRENT_BINARY_DIR}/colmap-config-version.cmake" @ONLY) |
| 515 |
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/colmap-config-version.cmake" |
| 516 |
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/colmap") |
| 517 |
|
| 518 |
# Install targets. |
| 519 |
install( |
| 520 |
EXPORT colmap-targets |
| 521 |
FILE colmap-targets.cmake |
| 522 |
NAMESPACE colmap:: |
| 523 |
DESTINATION ${INSTALL_CONFIG_DIR}) |
| 524 |
|
| 525 |
# Install header files. |
| 526 |
install( |
| 527 |
DIRECTORY src/colmap |
| 528 |
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
| 529 |
FILES_MATCHING PATTERN "*.h") |
| 530 |
install( |
| 531 |
DIRECTORY src/thirdparty |
| 532 |
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/colmap |
| 533 |
FILES_MATCHING |
| 534 |
REGEX ".*[.]h|.*[.]hpp|.*[.]inl" |
| 535 |
PATTERN "Symforce-Caspar" EXCLUDE) |
| 536 |
|
| 537 |
# Only ship the active Caspar precision tree (avoids bundling unused kernel |
| 538 |
# headers and the inactive precision when CASPAR_ENABLED is off). |
| 539 |
if(CASPAR_ENABLED) |
| 540 |
if(CASPAR_USE_DOUBLE) |
| 541 |
set(_caspar_install_precision "f64") |
| 542 |
else() |
| 543 |
set(_caspar_install_precision "f32") |
| 544 |
endif() |
| 545 |
install( |
| 546 |
DIRECTORY |
| 547 |
src/thirdparty/Symforce-Caspar/generated/${_caspar_install_precision} |
| 548 |
DESTINATION |
| 549 |
${CMAKE_INSTALL_INCLUDEDIR}/colmap/thirdparty/Symforce-Caspar/generated |
| 550 |
FILES_MATCHING REGEX ".*[.]h|.*[.]hpp|.*[.]inl") |
| 551 |
endif() |
| 552 |
|
| 553 |
# Install find_package scripts for dependencies. |
| 554 |
install( |
| 555 |
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cmake |
| 556 |
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/colmap |
| 557 |
FILES_MATCHING PATTERN "Find*.cmake") |