-
Notifications
You must be signed in to change notification settings - Fork 139
/
CMakeLists.txt
195 lines (161 loc) · 6.45 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
# cmake version to be used
cmake_minimum_required( VERSION 3.0 )
# project name
project(PIXSFM)
################################################################################
# Include CMake dependencies
################################################################################
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fPIC")
# 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(TESTS_ENABLED "Whether to build test binaries" ON)
option(AVX2_ENABLED "Whether to compile with AVX2 support" ON)
if(TESTS_ENABLED)
enable_testing()
endif()
################################################################################
# Find packages
################################################################################
# find_package(CUDA ${CUDA_MIN_VERSION} REQUIRED) #not-required
find_package(Eigen3 3.3 REQUIRED)
find_package(COLMAP REQUIRED)
################################################################################
# Select correct C/C++ standard
################################################################################
if (${CERES_VERSION} VERSION_LESS "2.2.0")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
else()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
endif()
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
################################################################################
# Compiler specific configuration
################################################################################
if (AVX2_ENABLED)
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindAVX2.cmake")
CHECK_FOR_AVX2()
if(HAVE_AVX2)
add_definitions("-DAVX2_ENABLED")
message("Compiling with AVX2 support.")
# @TODO investigate linking with non-avx code, it works on some machines without
# -DEIGEN_DONT_VECTORIZE
# We assume here colmap was compiled with default flags, thus we need to set
# -DEIGEN_MAX_ALIGN_BYTES=16 to avoid segfaults (otherwise eigen aligns
# on 32 bytes if avx2 enabled)
set(EIGEN_DISABLE_ALIGN_FLAGS
"-DEIGEN_MAX_ALIGN_BYTES=16 -DEIGEN_MAX_STATIC_ALIGN_BYTES=16 -DEIGEN_DONT_VECTORIZE")
set (AVX2_CXX_FLAGS "-mavx2 -mf16c -mfma")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${AVX2_CXX_FLAGS} ${EIGEN_DISABLE_ALIGN_FLAGS}")
else()
message("Compiling without AVX2 support.")
set(AVX2_ENABLED OFF)
endif()
endif()
if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
if (NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif()
endif()
add_definitions("-DBOOST_TEST_DYN_LINK")
################################################################################
# Add sources
################################################################################
# set(TEMP_INCLUDE_DIR ${CMAKE_BINARY_DIR}/include)
# file(MAKE_DIRECTORY ${TEMP_INCLUDE_DIR})
set(PIXSFM_INCLUDE_DIRS
${HDF5_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIR}
${PROJECT_SOURCE_DIR}
${FREEIMAGE_INCLUDE_DIRS}
${CERES_INCLUDE_DIRS}
${COLMAP_INCLUDE_DIRS}
)
set(PIXSFM_LINK_DIRS
${COLMAP_LINK_DIRS}
)
set(PIXSFM_EXTERNAL_LIBRARIES
${CERES_LIBRARIES}
${FREEIMAGE_LIBRARIES}
${COLMAP_LIBRARIES}
${HDF5_C_LIBRARIES}
)
set(PIXSFM_INTERNAL_LIBRARIES
HighFive
pybind11::module
pybind11::embed
)
include_directories(
third-party
pixsfm
${PIXSFM_INCLUDE_DIRS}
)
link_directories(${PIXSFM_LINK_DIRS})
set(PYBIND11_INSTALL ON)
add_subdirectory(third-party)
add_subdirectory(pixsfm)
################################################################################
# Generate source groups for Visual Studio, XCode, etc.
################################################################################
PIXSFM_ADD_SOURCE_DIR(pixsfm/base/src BASE_SRCS *.h *.cc)
# PIXSFM_ADD_SOURCE_DIR(pixsfm/exe EXE_SRCS *.h *.cc)
PIXSFM_ADD_SOURCE_DIR(pixsfm/util UTIL_SRCS *.h *.cc)
PIXSFM_ADD_SOURCE_DIR(pixsfm/bundle_adjustment BA_SRCS *.h *.cc)
PIXSFM_ADD_SOURCE_DIR(pixsfm/keypoint_adjustment KA_SRCS *.h *.cc)
PIXSFM_ADD_SOURCE_DIR(pixsfm/localization LOC_SRCS *.h *.cc)
PIXSFM_ADD_SOURCE_DIR(pixsfm/features FEAT_SRCS *.h *.cc)
PIXSFM_ADD_SOURCE_DIR(pixsfm/residuals RESID_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(
${PIXSFM_SRC_ROOT_FOLDER}
${BASE_SRCS}
# ${EXE_SRCS}
${UTIL_SRCS}
${BA_SRCS}
${KA_SRCS}
${LOC_SRCS}
${FEAT_SRCS}
${RESID_SRCS}
)
# Prevent the library from being compiled automatically.
set_target_properties(
${PIXSFM_SRC_ROOT_FOLDER} PROPERTIES
EXCLUDE_FROM_ALL 1
EXCLUDE_FROM_DEFAULT_BUILD 1)
################################################################################
# Install and uninstall scripts
################################################################################
# Install header files.
install(DIRECTORY pixsfm/
DESTINATION include/pixsfm
FILES_MATCHING PATTERN "*.h")
install(DIRECTORY third-party/
DESTINATION include/pixsfm/third-party
FILES_MATCHING
PATTERN "*.h"
PATTERN "HighFive" EXCLUDE
PATTERN "pybind11" EXCLUDE)
# Generate and install CMake configuration.
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/CMakeConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/PIXSFMConfig.cmake" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/PIXSFMConfig.cmake"
DESTINATION "share/pixsfm")
# Install find_package scripts for dependencies.
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cmake
DESTINATION share/pixsfm
FILES_MATCHING PATTERN "Find*.cmake")
# 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})