forked from cdcseacave/openMVS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
219 lines (192 loc) · 7.38 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
# CMake powered build system for OpenMVS
########################################################################
#
# Project-wide settings
CMAKE_MINIMUM_REQUIRED(VERSION 3.8.0)
if(POLICY CMP0011)
cmake_policy(SET CMP0011 NEW)
endif()
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()
# Name of the project.
#
# CMake files in this project can refer to the root source directory
# as ${OpenMVS_SOURCE_DIR} and to the root binary directory as
# ${OpenMVS_BINARY_DIR}.
PROJECT(OpenMVS)
set(OpenMVS_MAJOR_VERSION 1)
set(OpenMVS_MINOR_VERSION 1)
set(OpenMVS_PATCH_VERSION 1)
set(OpenMVS_VERSION ${OpenMVS_MAJOR_VERSION}.${OpenMVS_MINOR_VERSION}.${OpenMVS_PATCH_VERSION})
# Find dependencies:
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/build/Modules)
# fix CMake IntDir variable
if(MSVC AND "${MSVC_VERSION}" STRGREATER "1500")
SET(CMAKE_CFG_INTDIR "$(Platform)/$(Configuration)")
endif()
SET(COTIRE_INTDIR "cotire")
# Define helper functions and macros.
INCLUDE(build/Utils.cmake)
if(ENABLE_PRECOMPILED_HEADERS)
INCLUDE(build/Cotire.cmake)
endif()
# Init session with macros defined in Utils.cmake
GetOperatingSystemArchitectureBitness(SYSTEM)
ComposePackageLibSuffix()
ConfigCompilerAndLinker()
ConfigLibrary()
# List configuration options
SET(OpenMVS_USE_NONFREE ON CACHE BOOL "Build non-free (patented) functionality")
SET(OpenMVS_USE_CERES OFF CACHE BOOL "Enable CERES optimization library")
SET(OpenMVS_USE_FAST_FLOAT2INT ON CACHE BOOL "Use an optimized code to convert real numbers to int")
SET(OpenMVS_USE_FAST_INVSQRT OFF CACHE BOOL "Use an optimized code to compute the inverse square root (slower in fact on modern compilers)")
SET(OpenMVS_USE_FAST_CBRT ON CACHE BOOL "Use an optimized code to compute the cubic root")
SET(OpenMVS_USE_SSE ON CACHE BOOL "Enable SSE optimizations")
SET(OpenMVS_USE_OPENMP ON CACHE BOOL "Enable OpenMP library")
SET(OpenMVS_USE_OPENGL ON CACHE BOOL "Enable OpenGL library")
SET(OpenMVS_USE_CUDA ON CACHE BOOL "Enable CUDA library")
SET(OpenMVS_USE_BREAKPAD ON CACHE BOOL "Enable BreakPad library")
SET(OpenMVS_CONFIG_INCLUDE_DIR "${CMAKE_BINARY_DIR}/" CACHE PATH "Where to create the build/platform specific header")
INCLUDE_DIRECTORIES("${OpenMVS_SOURCE_DIR}")
# Find required packages
SET(OpenMVS_EXTRA_LIBS "")
if(OpenMVS_USE_OPENMP)
SET(OpenMP_LIBS "")
FIND_PACKAGE(OpenMP)
if(OPENMP_FOUND)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
ADD_DEFINITIONS(-D_USE_OPENMP)
SET(_USE_OPENMP TRUE)
#cmake only check for separate OpenMP library on AppleClang 7+
#https://github.com/Kitware/CMake/blob/42212f7539040139ecec092547b7d58ef12a4d72/Modules/FindOpenMP.cmake#L252
if (CMAKE_CXX_COMPILER_ID MATCHES "AppleClang" AND (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "7.0"))
SET(OpenMP_LIBS ${OpenMP_libomp_LIBRARY})
LIST(APPEND OpenMVS_EXTRA_LIBS ${OpenMP_LIBS})
endif()
else()
message("-- Can't find OpenMP. Continuing without it.")
endif()
endif()
if(OpenMVS_USE_OPENGL)
if(POLICY CMP0072)
cmake_policy(SET CMP0072 NEW)
endif()
FIND_PACKAGE(OpenGL)
if(OPENGL_FOUND)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
ADD_DEFINITIONS(${OpenGL_DEFINITIONS} -D_USE_OPENGL)
SET(_USE_OPENGL TRUE)
else()
MESSAGE("-- Can't find OpenGL. Continuing without it.")
endif()
endif()
if(OpenMVS_USE_CUDA)
FIND_PACKAGE(CUDA)
if(CUDA_FOUND)
INCLUDE_DIRECTORIES(${CUDA_INCLUDE_DIRS})
ADD_DEFINITIONS(-D_USE_CUDA)
SET(_USE_CUDA TRUE)
else()
SET(CUDA_CUDA_LIBRARY "")
MESSAGE("-- Can't find CUDA. Continuing without it.")
endif()
else()
SET(CUDA_CUDA_LIBRARY "")
endif()
if(OpenMVS_USE_BREAKPAD)
FIND_PACKAGE(BREAKPAD)
if(BREAKPAD_FOUND)
INCLUDE_DIRECTORIES(${BREAKPAD_INCLUDE_DIRS})
ADD_DEFINITIONS(${BREAKPAD_DEFINITIONS} -D_USE_BREAKPAD)
SET(_USE_BREAKPAD TRUE)
LIST(APPEND OpenMVS_EXTRA_LIBS ${BREAKPAD_LIBS})
else()
MESSAGE("-- Can't find BreakPad. Continuing without it.")
endif()
endif()
FIND_PACKAGE(Boost ${SYSTEM_PACKAGE_REQUIRED} COMPONENTS iostreams program_options system serialization)
if(Boost_FOUND)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
ADD_DEFINITIONS(${Boost_DEFINITIONS} -D_USE_BOOST)
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
SET(_USE_BOOST TRUE)
endif()
FIND_PACKAGE(Eigen ${SYSTEM_PACKAGE_REQUIRED})
if(EIGEN_FOUND)
INCLUDE_DIRECTORIES(${EIGEN_INCLUDE_DIRS})
ADD_DEFINITIONS(${EIGEN_DEFINITIONS} -D_USE_EIGEN)
SET(_USE_EIGEN TRUE)
endif()
FIND_PACKAGE(OpenCV ${SYSTEM_PACKAGE_REQUIRED})
if(OpenCV_FOUND)
INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS})
ADD_DEFINITIONS(${OpenCV_DEFINITIONS})
SET(_USE_OPENCV TRUE)
MESSAGE(STATUS "OpenCV ${OpenCV_VERSION} found (include: ${OpenCV_INCLUDE_DIRS})")
else()
MESSAGE("-- Can't find OpenCV. Please specify OpenCV directory using OpenCV_DIR variable")
endif()
# Set defines
SET(OpenMVS_DEFINITIONS "")
if(OpenMVS_USE_NONFREE)
LIST(APPEND OpenMVS_DEFINITIONS -D_USE_NONFREE)
SET(_USE_NONFREE TRUE)
endif()
if(OpenMVS_USE_FAST_FLOAT2INT)
LIST(APPEND OpenMVS_DEFINITIONS -D_USE_FAST_FLOAT2INT)
SET(_USE_FAST_FLOAT2INT TRUE)
endif()
if(OpenMVS_USE_FAST_INVSQRT)
LIST(APPEND OpenMVS_DEFINITIONS -D_USE_FAST_INVSQRT)
SET(_USE_FAST_INVSQRT TRUE)
endif()
if(OpenMVS_USE_FAST_CBRT)
LIST(APPEND OpenMVS_DEFINITIONS -D_USE_FAST_CBRT)
SET(_USE_FAST_CBRT TRUE)
endif()
if(OpenMVS_USE_SSE)
LIST(APPEND OpenMVS_DEFINITIONS -D_USE_SSE)
SET(_USE_SSE TRUE)
endif()
ADD_DEFINITIONS(${OpenMVS_DEFINITIONS})
# Add modules
ADD_SUBDIRECTORY(libs)
ADD_SUBDIRECTORY(apps)
ADD_SUBDIRECTORY(docs)
if(OpenMVS_USE_CERES)
SET(_USE_CERES TRUE)
endif()
# Set configuration file
CONFIGURE_FILE("${OpenMVS_SOURCE_DIR}/build/Templates/ConfigLocal.h.in" "${OpenMVS_CONFIG_INCLUDE_DIR}/ConfigLocal.h")
INSTALL(FILES "${OpenMVS_CONFIG_INCLUDE_DIR}/ConfigLocal.h" DESTINATION "${INSTALL_INCLUDE_DIR}")
INCLUDE_DIRECTORIES(${OpenMVS_CONFIG_INCLUDE_DIR})
# Add all targets to the build-tree export set
export(TARGETS Common IO Math MVS FILE "${PROJECT_BINARY_DIR}/OpenMVSTargets.cmake")
# Export the package for use from the build-tree
# (this registers the build-tree with a global CMake-registry)
export(PACKAGE OpenMVS)
# Create the OpenMVSConfig.cmake and OpenMVSConfigVersion files
file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" "${INSTALL_INCLUDE_DIR}")
# ... for the build tree
set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/build/OpenMVSConfig.cmake.in" "${PROJECT_BINARY_DIR}/OpenMVSConfig.cmake" @ONLY)
# ... for the install tree
set(CONF_INCLUDE_DIRS "${INSTALL_CMAKE_DIR}/${REL_INCLUDE_DIR}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/build/OpenMVSConfig.cmake.in" "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenMVSConfig.cmake" @ONLY)
# ... for both
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/build/OpenMVSConfigVersion.cmake.in" "${PROJECT_BINARY_DIR}/OpenMVSConfigVersion.cmake" @ONLY)
# Install the OpenMVSConfig.cmake and OpenMVSConfigVersion.cmake
install(FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenMVSConfig.cmake"
"${PROJECT_BINARY_DIR}/OpenMVSConfigVersion.cmake"
DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)
# Install the export set for use with the install-tree
install(EXPORT OpenMVSTargets DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)
# uninstall target
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/build/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)