-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
295 lines (250 loc) · 12.7 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
############################################################################
# libmix4sam - Mixtures for Smoothing and Mapping Library
#
# Copyright (C) 2020 Chair of Automation Technology / TU Chemnitz
# For more information see https://mytuc.org/mix
#
# libmix4sam is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# libmix4sam is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this software. If not, see <http://www.gnu.org/licenses/>.
#
# Contact Information: Sven Lange (sven.lange@etit.tu-chemnitz.de)
############################################################################
# Main CMake file, based on gtsam's template file for creating new projects
# using gtsam's CMake tools, see <gtsam>/cmake/example_project/CMakeLists.txt.
cmake_minimum_required(VERSION 3.0)
cmake_policy(SET CMP0048 NEW)
project(libmix4sam VERSION 0.1.0 LANGUAGES CXX C)
set(CMAKE_VERBOSE_MAKEFILE ON)
# Enforce c++11 standards
add_compile_options(-std=c++11) # CMake 3.1 and earlier
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
###################################################################################
# OPTIONS
# See whether libmix4sam_unstable is available
if(EXISTS "${PROJECT_SOURCE_DIR}/${PROJECT_NAME}_unstable" AND IS_DIRECTORY "${PROJECT_SOURCE_DIR}/${PROJECT_NAME}_unstable")
set(LIBMIX4SAM_UNSTABLE_AVAILABLE 1)
else()
set(LIBMIX4SAM_UNSTABLE_AVAILABLE 0)
endif()
option(USE_LOCAL_GTSAM_BUILD "If enabled, the user can specify a build and source directory of gtsam which will be used instead of the gtsam-system installation" ON)
option(USE_LOCAL_GTSAM_INSTALL "If enabled, the user can specify a install directory of gtsam which will be used instead of the gtsam-system installation" OFF)
option(LIBMIX4SAM_BUILD_STATIC_LIBRARY "whether build static library" OFF)
option(LIBMIX4SAM_BUILD_MATLAB_WRAP "Enable/Disable building the Matlab interface (using wrap functionality of gtsam)" ON)
option(LIBMIX4SAM_BUILD_PYTHON_WRAP "Enable/Disable building the Python interface (using wrap functionality of gtsam)" ON)
option(LIBMIX4SAM_BUILD_EXAMPLES "Enable/Disable building of the example applications" ON)
if(LIBMIX4SAM_UNSTABLE_AVAILABLE)
option(LIBMIX4SAM_BUILD_UNSTABLE "Enable/Disable libmix4sam_unstable" ON)
endif()
# Choose the correct python environment, if executed within conda environment
if(LIBMIX4SAM_BUILD_PYTHON_WRAP OR LIBMIX4SAM_BUILD_MATLAB_WRAP)
if(DEFINED ENV{CONDA_PREFIX})
set(Python_FIND_STRATEGY LOCATION CACHE INTERNAL "")
set(Python3_FIND_STRATEGY LOCATION CACHE INTERNAL "")
set(PYTHON_ROOT_DIR "$ENV{CONDA_PREFIX}" CACHE PATH "")
set(Python_ROOT_DIR "$ENV{CONDA_PREFIX}" CACHE PATH "")
set(Python3_ROOT_DIR "$ENV{CONDA_PREFIX}" CACHE PATH "")
endif()
endif()
# Find GTSAM components eighter locally or system-wide install.
if(USE_LOCAL_GTSAM_INSTALL AND USE_LOCAL_GTSAM_BUILD)
message(FATAL_ERROR "Eigther use local build or local install!")
endif()
if(USE_LOCAL_GTSAM_INSTALL)
unset(GTSAM_BUILD_DIR CACHE)
unset(GTSAM_SRC_DIR CACHE)
set(GTSAM_INSTALL_DIR "$ENV{HOME}/workspace/gtsam/gtsam-42a9-install" CACHE PATH "Install Directory")
find_package(GTSAM REQUIRED NO_MODULE QUIET
PATHS "${GTSAM_INSTALL_DIR}"
NO_DEFAULT_PATH
)
endif()
if(USE_LOCAL_GTSAM_BUILD)
unset(GTSAM_INSTALL_DIR CACHE)
set(GTSAM_BUILD_DIR "$ENV{HOME}/workspace/gtsam/gtsam-42a9-build" CACHE PATH "Build Directory")
set(GTSAM_INSTALL_DIR "$ENV{HOME}/workspace/gtsam/gtsam-42a9-install" CACHE PATH "Install Directory")
# Even if we use the local build directory, some cmake files with their dependencies are only
# available within the install directory.
# These should be set automatically depending on Build dir by find_package!
unset(GTSAM_INCLUDE_DIR CACHE)
unset(GTSAM_DIR CACHE)
unset(GTSAM_SRC_DIR CACHE)
find_package(GTSAM REQUIRED NO_MODULE QUIET
PATHS "${GTSAM_BUILD_DIR}"
NO_DEFAULT_PATH
)
# For using the cmake-scripts
# (GTSAM_INCLUDE_DIR is a list, we need the first entry)
LIST(GET GTSAM_INCLUDE_DIR 0 GTSAM_SRC_DIR)
# We don't need to define include_directories for GTSAM. This is already handled internally.
endif()
if(NOT USE_LOCAL_GTSAM_INSTALL AND NOT USE_LOCAL_GTSAM_BUILD)
unset(GTSAM_BUILD_DIR CACHE)
unset(GTSAM_INCLUDE_DIR CACHE)
unset(GTSAM_SRC_DIR CACHE)
find_package(GTSAM REQUIRED NO_MODULE)
find_package(Eigen3 REQUIRED) # TODO: Don't know if it's needed.
endif()
###################################################################################
# Include GTSAM CMake tools
find_package(GTSAMCMakeTools NO_MODULE QUIET
PATHS "${GTSAM_INSTALL_DIR}/lib/cmake/GTSAMCMakeTools"
PATHS "${GTSAM_SRC_DIR}/cmake"
NO_DEFAULT_PATH
)
if (NOT GTSAMCMakeTools_FOUND)
find_package(GTSAMCMakeTools)
endif()
include(GtsamMakeConfigFile)
include(GtsamBuildTypes) # Load build type flags and default to Debug mode
include(GtsamTesting) # Easy functions for creating unit tests and scripts
include(GtsamPrinting) # Additional macros for printing configuration options
# Helper (copied from gtsam 4.1, because it is not present in previous versions)
function(print_config config msg)
string_pad(padded_config ${GTSAM_PRINT_SUMMARY_PADDING_LENGTH} " ${config}")
message(STATUS "${padded_config}: ${msg}")
endfunction()
###################################################################################
# BOOST
set(BOOST_FIND_MINIMUM_VERSION 1.65)
set(BOOST_FIND_MINIMUM_COMPONENTS filesystem system thread serialization)
# Following is only necessary if we need a special boost version:
#option(Boost_NO_SYSTEM_PATHS "Enable/Disable Boost system path" ON)
#set(BOOST_ROOT "$ENV{HOME}/workspace/boost/install_1_55_0" CACHE PATH "")
#set(Boost_ADDITIONAL_VERSIONS "1.55" "1.55.0")
#set(BOOST_INCLUDEDIR $ENV{HOME}/boost/install_1_55_0/include)
#set(BOOST_LIBRARYDIR $ENV{HOME}/boost/install_1_55_0/lib)
#set(BOOST_FIND_MINIMUM_VERSION 1.55)
# Boost - same requirement as gtsam
find_package(Boost ${BOOST_FIND_MINIMUM_VERSION} COMPONENTS ${BOOST_FIND_MINIMUM_COMPONENTS} REQUIRED)
include_directories(SYSTEM ${Boost_INCLUDE_DIR}) # Use SYSTEM to include it via -isystem to deactivate boost's concept_check
###################################################################################
# Ensure that the local folder is searched before the library folders.
include_directories(BEFORE "${PROJECT_SOURCE_DIR}")
if(GTSAM_MEX_BUILD_STATIC_MODULE AND LIBMIX4SAM_BUILD_MATLAB_WRAP)
message(FATAL_ERROR "matlab toolbox needs shared gtsam and libmix4sam lib and can not be build as static wrapper.")
endif()
###################################################################################
# Build static library from common sources
set(CONVENIENCE_LIB_NAME ${PROJECT_NAME})
#target_link_libraries(${CONVENIENCE_LIB_NAME} gtsam)
add_subdirectory(${CONVENIENCE_LIB_NAME})
###################################################################################
# Build tests (CMake tracks the dependency to link with GTSAM through our project's static library)
#gtsamAddTestsGlob("example" "tests/test*.cpp" "" "${CONVENIENCE_LIB_NAME}")
###################################################################################
# Build scripts (CMake tracks the dependency to link with GTSAM through our project's static library)
#gtsamAddExamplesGlob("*.cpp" "" "${CONVENIENCE_LIB_NAME}")
# Build examples
if (LIBMIX4SAM_BUILD_EXAMPLES)
add_subdirectory(examples)
endif(LIBMIX4SAM_BUILD_EXAMPLES)
###################################################################################
# Build libisf_unstable
if (LIBMIX4SAM_BUILD_UNSTABLE)
add_subdirectory("${CONVENIENCE_LIB_NAME}_unstable")
endif()
###################################################################################
# For gtsam debugging functionalities (debug.h)
OPTION(DEFINE_GTSAM_ENABLE_DEBUG "Activate Custom Debug Messages" ON) # Enabled by default
IF(DEFINE_GTSAM_ENABLE_DEBUG)
ADD_DEFINITIONS(-DGTSAM_ENABLE_DEBUG)
ENDIF(DEFINE_GTSAM_ENABLE_DEBUG)
###############################################################################
# Wrappers -> makes use of gtsam's wrap library
if (LIBMIX4SAM_BUILD_PYTHON_WRAP OR LIBMIX4SAM_BUILD_MATLAB_WRAP)
# Import the gtwrap package.
# Here we must use the install directory because gtwrapConfig.cmake uses variables
# at build time. Although we find the file in the build folder, there are still other
# dependent cmake files missing, which are only merged in the installation folder.
# Therefore, we have to fall back on the installation folder.
find_package(gtwrap NO_MODULE QUIET
PATHS "${GTSAM_INSTALL_DIR}/lib/cmake/gtwrap"
NO_DEFAULT_PATH
)
# Alternative kicks in if the global installation method was chosen for gtsam.
if (NOT gtwrap_FOUND)
find_package(gtwrap)
endif()
# Set the python version for the wrapper
set(WRAP_PYTHON_VERSION "Default" CACHE STRING "The Python version to use for wrapping")
gtwrap_get_python_version(${WRAP_PYTHON_VERSION})
# Build the Python wrapper, if chosen
if (LIBMIX4SAM_BUILD_PYTHON_WRAP)
add_subdirectory(python)
endif(LIBMIX4SAM_BUILD_PYTHON_WRAP)
# Build the Matlab wrapper, if chosen
if (LIBMIX4SAM_BUILD_MATLAB_WRAP)
add_subdirectory(matlab)
endif(LIBMIX4SAM_BUILD_MATLAB_WRAP)
endif()
###############################################################################
# Documentation
find_package(Doxygen)
if (DOXYGEN_FOUND)
add_subdirectory(doc)
endif()
###############################################################################
# Print configuration variables
message(STATUS "===============================================================")
message(STATUS "================ Configuration Options ======================")
print_config("CMAKE_CXX_COMPILER_ID type" "${CMAKE_CXX_COMPILER_ID}")
print_config("CMAKE_CXX_COMPILER_VERSION" "${CMAKE_CXX_COMPILER_VERSION}")
print_config("CMake version" "${CMAKE_VERSION}")
print_config("CMake generator" "${CMAKE_GENERATOR}")
print_config("CMake build tool" "${CMAKE_BUILD_TOOL}")
print_config("Build type" "${CMAKE_BUILD_TYPE}")
message(STATUS "================ Directories ================================")
print_config("Used CMakeTools Directory" "${GTSAMCMakeTools_DIR}")
if(USE_LOCAL_GTSAM_BUILD)
print_config("GTSAM-Build-Directory" "${GTSAM_BUILD_DIR}")
print_config("GTSAM-Include-Dir" "${GTSAM_INCLUDE_DIR}")
print_config("GTSAM-Install-Dir (needed for wrappers)" "${GTSAM_INSTALL_DIR}")
endif()
if(USE_LOCAL_GTSAM_INSTALL)
print_config("GTSAM-Include-Dir" "${GTSAM_INCLUDE_DIR}")
endif()
if(LIBMIX4SAM_UNSTABLE_AVAILABLE)
print_config("Build libmix4sam_unstable" "${LIBMIX4SAM_BUILD_UNSTABLE}")
endif()
if(LIBMIX4SAM_BUILD_PYTHON_WRAP OR LIBMIX4SAM_BUILD_MATLAB_WRAP)
print_config("Python executable path" "${PYTHON_EXECUTABLE}")
endif()
print_config("Build python wrapper" "${LIBMIX4SAM_BUILD_PYTHON_WRAP}")
if(LIBMIX4SAM_BUILD_PYTHON_WRAP)
print_config("Python version to use for wrapper" "${WRAP_PYTHON_VERSION}")
endif()
print_config("Build matlab wrapper" "${LIBMIX4SAM_BUILD_MATLAB_WRAP}")
message(STATUS "===============================================================")
# Add all targets to the build-tree export set
export(TARGETS libmix4sam FILE "${PROJECT_BINARY_DIR}/libmix4sam-exports.cmake")
# Export the package for use from the build-tree
# (this registers the build-tree with a global CMake-registry)
export(PACKAGE libmix4sam)
set(DEF_INSTALL_CMAKE_DIR lib/cmake/libmix4sam)
set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
file(RELATIVE_PATH CONF_REL_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/${INSTALL_CMAKE_DIR}" "${CMAKE_INSTALL_PREFIX}/include")
# ... for the build tree
set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}")
configure_file(libmix4samConfig.cmake.in
"${PROJECT_BINARY_DIR}/libmix4samConfig.cmake" @ONLY)
# ... for the install tree
set(CONF_INCLUDE_DIRS "\${${CMAKE_PROJECT_NAME}_CMAKE_DIR}/${CONF_REL_INCLUDE_DIR}")
configure_file(libmix4samConfig.cmake.in
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/libmix4samConfig.cmake" @ONLY)
install(FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/libmix4samConfig.cmake"
DESTINATION "${CMAKE_INSTALL_PREFIX}/${INSTALL_CMAKE_DIR}" COMPONENT dev)
install(EXPORT libmix4sam-exports DESTINATION ${DEF_INSTALL_CMAKE_DIR})
# remove GTSAMCMakeTools_DIR from cmake_gui since it is recomputed anyway
unset(GTSAMCMakeTools_DIR CACHE)