-
Notifications
You must be signed in to change notification settings - Fork 28
/
CMakeLists.txt
235 lines (200 loc) · 7.23 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
# PROJECT CONFIGURATION
cmake_minimum_required(VERSION 3.5)
project(DPGO)
if(NOT CMAKE_BUILD_TYPE)
# Options: Debug, Release, MinSizeRel, RelWithDebInfo
message(STATUS "No build type selected, default to Release")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose build type." FORCE)
endif()
message(STATUS "CXX compiler version: " ${CMAKE_CXX_COMPILER_VERSION})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -march=native")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -pthread -O3")
include(GNUInstallDirs)
set(DPGO_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR}/DPGO)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# Directory for built libraries
set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/lib CACHE PATH "The directory in which to place libraries built by this project")
# Directory for built executables
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/bin CACHE PATH "The directory in which to place executables built by this project")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
message(STATUS "CMAKE_MODULE_PATH: " ${CMAKE_MODULE_PATH})
# ROPTLIB
configure_file(cmake/roptlib.cmake roptlib-download/CMakeLists.txt)
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/roptlib-download")
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/roptlib-download")
add_subdirectory("${CMAKE_BINARY_DIR}/roptlib-src"
"${CMAKE_BINARY_DIR}/roptlib-build")
# Dependencies
find_package(SPQR REQUIRED)
find_package(Cholmod REQUIRED)
find_package(BLAS REQUIRED)
find_package(Threads REQUIRED)
find_package(Boost)
find_package(Eigen3 REQUIRED)
message(STATUS "Found Eigen version: ${EIGEN3_VERSION}")
message(STATUS "EIGEN3_INCLUDE_DIR: ${EIGEN3_INCLUDE_DIR}")
find_package(Glog REQUIRED)
if (GLOG_FOUND)
message(STATUS "Found Google Logging: ${GLOG_INCLUDE_DIRS}")
else (GLOG_FOUND)
message(FATAL_ERROR "Can't find Google Logging. Please set GLOG_INCLUDE_DIR & "
"GLOG_LIBRARY")
endif (GLOG_FOUND)
# Enable OpenMP (if available)
set(ENABLE_OPENMP OFF CACHE BOOL "Enable OpenMP (if available)")
# PERFORMANCE IMPROVEMENTS
if(${ENABLE_OPENMP})
find_package(OpenMP)
if(OPENMP_FOUND)
message(STATUS "Found OpenMP! Turning on support for parallelization\n")
endif()
endif()
message(STATUS "Boost version: " ${Boost_VERSION_STRING})
set(EXTERNAL_INCLUDES
${CHOLMOD_INCLUDES}
${EIGEN3_INCLUDE_DIR}
${Boost_INCLUDE_DIRS}
${GLOG_INCLUDE_DIRS}
CACHE INTERNAL "")
add_library(DPGO SHARED
src/manifold/Poses.cpp
src/manifold/LiftedSEManifold.cpp
src/manifold/LiftedSEVariable.cpp
src/manifold/LiftedSEVector.cpp
src/PoseGraph.cpp
src/PGOAgent.cpp
src/QuadraticProblem.cpp
src/QuadraticOptimizer.cpp
src/DPGO_utils.cpp
src/DPGO_solver.cpp
src/DPGO_robust.cpp
src/PGOLogger.cpp)
target_include_directories(DPGO PUBLIC
${EXTERNAL_INCLUDES}
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
# INSTALL
$<INSTALL_INTERFACE:${DPGO_INSTALL_INCLUDEDIR}>
)
target_link_libraries(DPGO
${CMAKE_THREAD_LIBS_INIT}
roptlib
${GLOG_LIBRARIES}
${CHOLMOD_LIBRARIES}
${SPQR_LIBRARIES}
${Boost_LIBRARIES})
if(OPENMP_FOUND)
# Add additional compilation flags to enable OpenMP support
set_target_properties(DPGO PROPERTIES COMPILE_FLAGS ${OpenMP_CXX_FLAGS})
set_target_properties(DPGO PROPERTIES LINK_FLAGS "-fopenmp")
target_link_libraries(DPGO)
endif()
# Build Distributed PGO example
add_executable(multi-robot-example
examples/MultiRobotExample.cpp)
target_link_libraries(multi-robot-example DPGO)
add_executable(chordal-initialization-example
examples/ChordalInitializationExample.cpp)
target_link_libraries(chordal-initialization-example DPGO)
add_executable(single-robot-example
examples/SingleRobotExample.cpp)
target_link_libraries(single-robot-example DPGO)
add_executable(single-robot-gnc-example
examples/SingleRobotGNCExample.cpp)
target_link_libraries(single-robot-gnc-example DPGO)
############################### TESTS ##########################################
### Add testing
option(BUILD_DPGO_TESTS "Build tests" ON)
if(BUILD_DPGO_TESTS)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/gtest.cmake googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()
# Prevent overriding the parent project's compiler/linker
# settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory("${CMAKE_BINARY_DIR}/external/googletest-src"
"${CMAKE_BINARY_DIR}/external/googletest-build"
EXCLUDE_FROM_ALL)
# The gtest/gtest_main targets carry header search path
# dependencies automatically when using CMake 2.8.11 or
# later. Otherwise we have to add them here ourselves.
if (CMAKE_VERSION VERSION_LESS 2.8.11)
include_directories("${gtest_SOURCE_DIR}/include")
endif()
add_executable(
testDPGO
tests/testUtils.cpp
tests/testPGO.cpp
tests/testPoses.cpp
tests/testEigenMap.cpp
tests/testConstruction.cpp
tests/testLineGraph.cpp
tests/testTriangleGraph.cpp
tests/testOptimizationThread.cpp)
target_include_directories(testDPGO PUBLIC
${EXTERNAL_INCLUDES}
${CMAKE_CURRENT_SOURCE_DIR}/include>
${CMAKE_SOURCE_DIR}/eigen>
)
target_link_libraries(
testDPGO
gtest_main
DPGO
)
add_test(
NAME testDPGO
COMMAND ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/unit_tests
)
endif(BUILD_DPGO_TESTS)
############################### INSTALL ##########################################
include(CMakePackageConfigHelpers)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/DPGO)
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/DPGOConfigVersion.cmake
VERSION 1.0
COMPATIBILITY AnyNewerVersion
)
configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/DPGOConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/DPGOConfig.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)
# install the configuration file
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/DPGOConfig.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)
# Install header files
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/
DESTINATION ${DPGO_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.h"
)
install(TARGETS DPGO
EXPORT DPGOTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(EXPORT DPGOTargets
FILE DPGOTargets.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)
export(TARGETS DPGO FILE DPGOTargets.cmake)
############################### UNINSTALL ##########################################
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/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)
endif()