-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
320 lines (260 loc) · 10.5 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
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
SET(CMAKE_LEGACY_CYGWIN_WIN32 0)
PROJECT(g2o)
# The library prefix
SET(LIB_PREFIX g2o_)
SET(g2o_C_FLAGS)
SET(g2o_CXX_FLAGS)
# postfix, based on type
SET(CMAKE_DEBUG_POSTFIX "_d" CACHE STRING "postfix applied to debug build of libraries")
SET(CMAKE_RELEASE_POSTFIX "" CACHE STRING "postfix applied to release build of libraries")
SET(CMAKE_RELWITHDEBINFO_POSTFIX "_rd" CACHE STRING "postfix applied to release-with-debug-information libraries")
SET(CMAKE_MINSIZEREL_POSTFIX "_s" CACHE STRING "postfix applied to minimium-size-build libraries")
# work out the postfix; required where we use OUTPUT_NAME
IF(CMAKE_BUILD_TYPE MATCHES Release)
SET(EXE_POSTFIX)
ELSEIF(CMAKE_BUILD_TYPE MATCHES Debug)
SET(EXE_POSTFIX ${CMAKE_DEBUG_POSTFIX})
ELSEIF(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
SET(EXE_POSTFIX ${CMAKE_RELWITHDEBINFO_POSTFIX})
ELSEIF(CMAKE_BUILD_TYPE MATCHES MinSizeRel)
SET(EXE_POSTFIX ${CMAKE_MINSIZEREL_POSTFIX})
ENDIF(CMAKE_BUILD_TYPE MATCHES Release)
# Allow the developer to select if Dynamic or Static libraries are built
OPTION (BUILD_SHARED_LIBS "Build Shared Libraries (preferred and required for the g2o plugin system)" ON)
SET (G2O_LIB_TYPE STATIC)
#IF (BUILD_SHARED_LIBS)
# SET (G2O_LIB_TYPE SHARED)
#ENDIF()
# There seems to be an issue with MSVC8
# see http://eigen.tuxfamily.org/bz/show_bug.cgi?id=83
if(MSVC90)
add_definitions(-DEIGEN_DONT_ALIGN_STATICALLY=1)
message(STATUS "Disabling memory alignment for MSVC8")
endif(MSVC90)
# On the Mac platform, configure the RPATH as per the install, to
# avoid the problem of loading both the built and installed versions
# of the shared targets
#IF(APPLE)
# SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
# SET(CMAKE_INSTALL_RPATH "")
#ENDIF(APPLE)
# Set the output directory for the build executables and libraries
SET(g2o_RUNTIME_OUTPUT_DIRECTORY ${g2o_SOURCE_DIR}/build CACHE PATH "Target for the binaries")
IF(WIN32)
SET(g2o_LIBRARY_OUTPUT_DIRECTORY ${g2o_SOURCE_DIR}/build CACHE PATH "Target for the libraries")
ELSE(WIN32)
SET(g2o_LIBRARY_OUTPUT_DIRECTORY ${g2o_SOURCE_DIR}/lib CACHE PATH "Target for the libraries")
ENDIF(WIN32)
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${g2o_LIBRARY_OUTPUT_DIRECTORY})
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${g2o_LIBRARY_OUTPUT_DIRECTORY})
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${g2o_RUNTIME_OUTPUT_DIRECTORY})
# Set search directory for looking for our custom CMake scripts to
# look for SuiteSparse, QGLViewer, and Eigen3.
LIST(APPEND CMAKE_MODULE_PATH ${g2o_SOURCE_DIR}/cmake_modules)
# Detect OS and define macros appropriately
IF(UNIX)
ADD_DEFINITIONS(-DUNIX)
MESSAGE(STATUS "Compiling on Unix")
ENDIF(UNIX)
# detect Android Cross Compiler
# based on android-cmake which sets the variable ANDROID for us
IF(ANDROID)
ADD_DEFINITIONS(-DANDROID)
MESSAGE(STATUS "Cross compiling for Android")
ENDIF()
# For building the CHOLMOD / CSPARSE solvers
FIND_PACKAGE(Cholmod)
FIND_PACKAGE(BLAS)
FIND_PACKAGE(LAPACK)
IF(CHOLMOD_FOUND AND BLAS_FOUND AND LAPACK_FOUND)
MESSAGE(STATUS "Found CHOLMOD and its dependencies")
SET(CHOLMOD_FOUND TRUE)
ELSE()
SET(CHOLMOD_FOUND FALSE)
ENDIF()
FIND_PACKAGE(CSparse)
IF(CSPARSE_FOUND)
SET(BUILD_CSPARSE OFF CACHE BOOL "Build local CSparse library")
ELSE(CSPARSE_FOUND)
SET(BUILD_CSPARSE ON CACHE BOOL "Build local CSparse library")
IF(BUILD_CSPARSE)
SET(CSPARSE_FOUND TRUE)
ENDIF()
ENDIF(CSPARSE_FOUND)
OPTION(BUILD_LGPL_SHARED_LIBS "Build LGPL Code as Shared Libraries (LGPL Code)" ON)
SET (G2O_LGPL_LIB_TYPE STATIC)
IF (BUILD_LGPL_SHARED_LIBS)
SET (G2O_LGPL_LIB_TYPE SHARED)
ELSE()
MESSAGE(STATUS "Building LGPL code as static library (affects license of the binary)")
ENDIF()
# Eigen library parallelise itself, though, presumably due to performance issues
# OPENMP is experimental. We experienced some slowdown with it
SET(G2O_USE_OPENMP OFF CACHE BOOL "Build g2o with OpenMP support (EXPERIMENTAL)")
IF(G2O_USE_OPENMP)
FIND_PACKAGE(OpenMP)
IF(OPENMP_FOUND)
SET (G2O_OPENMP 1)
SET(g2o_C_FLAGS "${g2o_C_FLAGS} ${OpenMP_C_FLAGS}")
SET(g2o_CXX_FLAGS "${g2o_CXX_FLAGS} -DEIGEN_DONT_PARALLELIZE ${OpenMP_CXX_FLAGS}")
MESSAGE(STATUS "Compiling with OpenMP support")
ENDIF(OPENMP_FOUND)
ENDIF(G2O_USE_OPENMP)
# OpenGL is used in the draw actions for the different types, as well
# as for creating the GUI itself
FIND_PACKAGE(OpenGL)
SET(G2O_USE_OPENGL ON CACHE BOOL "Build g2o with OpenGL support for visualization")
IF (OPENGL_FOUND AND G2O_USE_OPENGL)
SET (G2O_HAVE_OPENGL 1)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
MESSAGE(STATUS "Compiling with OpenGL support")
ENDIF()
# For building the GUI
FIND_PACKAGE(QGLViewer)
FIND_PACKAGE(GTSAM REQUIRED)
IF (GTSAM_FOUND)
SET (HAVE_GTSAM 1)
INCLUDE_DIRECTORIES(${GTSAM_INCLUDE_DIR})
MESSAGE(STATUS "Compiling with gtsam")
MESSAGE(STATUS $(GTSAM_LIBS))
ENDIF()
# shall we build the core apps using the library
SET(G2O_BUILD_APPS ON CACHE BOOL "Build g2o apps")
IF(G2O_BUILD_APPS)
MESSAGE(STATUS "Compiling g2o apps")
ENDIF(G2O_BUILD_APPS)
include(CMakeDependentOption)
CMAKE_DEPENDENT_OPTION(G2O_BUILD_LINKED_APPS "Build apps linked with the libraries (no plugin system)" OFF
"G2O_BUILD_APPS" OFF)
# shall we build the examples
#SET(G2O_BUILD_EXAMPLES ON CACHE BOOL "Build g2o examples")
#IF(G2O_BUILD_EXAMPLES)
# MESSAGE(STATUS "Compiling g2o examples")
#ENDIF(G2O_BUILD_EXAMPLES)
# Compiler specific options for gcc
IF(CMAKE_COMPILER_IS_GNUCXX)
OPTION (BUILD_WITH_MARCH_NATIVE "Build with \"-march native\"" ON)
MESSAGE(STATUS "Compiling with GCC")
IF(NOT ${ARCH} MATCHES arm)
# Generic settings for optimisation
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -msse4.2")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -msse4.2")
ENDIF()
# switch off optimization for debug builds
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
# OS X
#IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
#SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
#SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
#ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# Linux
IF(BUILD_WITH_MARCH_NATIVE AND NOT ${ARCH} MATCHES arm AND ${CMAKE_SYSTEM_NAME} MATCHES "Linux")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=native")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -march=native")
ENDIF()
# activate warnings !!!
SET(g2o_C_FLAGS "${g2o_C_FLAGS} -Wall -W")
SET(g2o_CXX_FLAGS "${g2o_CXX_FLAGS} -Wall -W")
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
MESSAGE(STATUS "Compiling with Clang")
# activate all warnings
#SET(g2o_C_FLAGS "${g2o_C_FLAGS} -Weverything")
#SET(g2o_CXX_FLAGS "${g2o_CXX_FLAGS} -Weverything")
SET(g2o_C_FLAGS "${g2o_C_FLAGS} -Wall")
SET(g2o_CXX_FLAGS "${g2o_CXX_FLAGS} -Wall")
#SET(g2o_CXX_FLAGS "${g2o_CXX_FLAGS} -Wall -stdlib=libc++")
ENDIF()
# C++11 support
IF(NOT MSVC)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
endif()
# specifying compiler flags
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${g2o_CXX_FLAGS}")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${g2o_C_FLAGS}")
# Find Eigen3
FIND_PACKAGE(Eigen3 REQUIRED)
# Set up the top-level include directories
INCLUDE_DIRECTORIES(${g2o_SOURCE_DIR} ${EIGEN3_INCLUDE_DIR})
# Generate config.h
SET(G2O_OPENGL_FOUND ${OPENGL_FOUND})
SET(G2O_HAVE_CHOLMOD ${CHOLMOD_FOUND})
SET(G2O_HAVE_CSPARSE ${CSPARSE_FOUND})
SET(G2O_SHARED_LIBS ${BUILD_SHARED_LIBS})
SET(G2O_LGPL_SHARED_LIBS ${BUILD_LGPL_SHARED_LIBS})
SET(G2O_CXX_COMPILER "${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER}")
configure_file(config.h.in ${PROJECT_BINARY_DIR}/g2o/config.h)
include_directories(${PROJECT_BINARY_DIR})
INSTALL(FILES ${PROJECT_BINARY_DIR}/g2o/config.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/g2o)
# Include the subdirectories
ADD_SUBDIRECTORY(EXTERNAL)
ADD_SUBDIRECTORY(g2o)
#Dloop
if(MSVC)
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic")
endif()
set(HDRS
includes/DLoopDetector.h includes/TemplatedLoopDetector.h)
set(DEPENDENCY_DIR ${CMAKE_CURRENT_BINARY_DIR}/dependencies)
set(DEPENDENCY_INSTALL_DIR ${DEPENDENCY_DIR}/install)
macro(GetDependency name other_dependency)
find_package(${name} QUIET
PATHS ${DEPENDENCY_INSTALL_DIR})
include_directories(${${name}_INCLUDE_DIRS})
add_custom_target(${name})
endmacro(GetDependency)
GetDependency(DLib "")
GetDependency(DBoW2 DLib)
add_custom_target(Dependencies ${CMAKE_COMMAND} ${CMAKE_SOURCE_DIR} DEPENDS DBoW2 DLib)
# directories
set (INCLUDE_DIR includes)
# use sse3 instruction set
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse3")
find_package( OpenCV REQUIRED )
# include directory
include_directories(${INCLUDE_DIR} ${OpenCV_INCLUDE_DIRS} ${CSPARSE_INCLUDE_DIR})
MESSAGE(STATUS "printing opencv dirs")
MESSAGE(STATUS ${OpenCV_INCLUDE_DIRS})
# Sources
FILE(GLOB SRC_FILES "src/*.cpp")
# make release version
# set(CMAKE_BUILD_TYPE Release)
# main executable
add_executable(main ${SRC_FILES} main.cpp)
find_package( OpenCV REQUIRED )
find_package( Threads REQUIRED )
SET_TARGET_PROPERTIES(main PROPERTIES OUTPUT_NAME main${EXE_POSTFIX})
find_library(OPENGL_LIBRARY GL)
find_library(GLU_LIBRARY GLU)
set(OPENGL_LIBRARY ${OPENGL_LIBRARY} ${GLU_LIBRARY})
find_library(GLUT_LIBRARY glut)
#include_directories(/usr/local/include/AprilTags/)
##which of the two?
find_library(GTSAM_LIBRARY gtsam HINTS /usr/local/lib)
MESSAGE(STATUS ${GTSAM_LIBRARY})
target_link_libraries(main ${GTSAM_LIBRARY} /usr/lib/libtbb.so)
find_library(BOOST_SYSTEM_LIBRARY boost_system HINTS /usr/lib/x86_64-linux-gnu)
MESSAGE(STATUS ${BOOST_SYSTEM_LIBRARY})
target_link_libraries(main ${BOOST_SYSTEM_LIBRARY})
TARGET_LINK_LIBRARIES(main core solver_csparse)
TARGET_LINK_LIBRARIES(main types_slam2d)
TARGET_LINK_LIBRARIES(main types_slam3d)
#TARGET_LINK_LIBRARIES(main /usr/local/lib/libapriltags.a)
target_link_libraries( main ${OpenCV_LIBS} ${GLUT_LIBRARY} ${OPENGL_LIBRARY} ${DLib_LIBS} ${DBoW2_LIBS} ${CMAKE_THREAD_LIBS_INIT} )