feat(slam): add cartographer_ros

This commit is contained in:
X-lanni
2025-07-04 14:39:48 +08:00
parent df9cee5779
commit 5cf886315d
825 changed files with 92220 additions and 0 deletions
+147
View File
@@ -0,0 +1,147 @@
# Copyright 2016 The Cartographer Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
include(CMakeParseArguments)
macro(_parse_arguments ARGS)
set(OPTIONS)
set(ONE_VALUE_ARG)
set(MULTI_VALUE_ARGS SRCS)
cmake_parse_arguments(ARG
"${OPTIONS}" "${ONE_VALUE_ARG}" "${MULTI_VALUE_ARGS}" ${ARGS})
endmacro(_parse_arguments)
macro(_common_compile_stuff VISIBILITY)
set(TARGET_COMPILE_FLAGS "${TARGET_COMPILE_FLAGS} ${GOOG_CXX_FLAGS}")
set_target_properties(${NAME} PROPERTIES
COMPILE_FLAGS ${TARGET_COMPILE_FLAGS})
target_include_directories(${NAME} PUBLIC ${PROJECT_NAME})
target_link_libraries(${NAME} PUBLIC ${PROJECT_NAME})
endmacro(_common_compile_stuff)
function(google_test NAME ARG_SRC)
add_executable(${NAME} ${ARG_SRC})
_common_compile_stuff("PRIVATE")
# Make sure that gmock always includes the correct gtest/gtest.h.
target_include_directories("${NAME}" SYSTEM PRIVATE
"${GMOCK_INCLUDE_DIRS}")
target_link_libraries("${NAME}" PUBLIC ${GMOCK_LIBRARIES})
add_test(${NAME} ${NAME})
endfunction()
function(google_binary NAME)
_parse_arguments("${ARGN}")
add_executable(${NAME} ${ARG_SRCS})
_common_compile_stuff("PRIVATE")
install(TARGETS "${NAME}" RUNTIME DESTINATION bin)
endfunction()
# Create a variable 'VAR_NAME'='FLAG'. If VAR_NAME is already set, FLAG is
# appended.
function(google_add_flag VAR_NAME FLAG)
if (${VAR_NAME})
set(${VAR_NAME} "${${VAR_NAME}} ${FLAG}" PARENT_SCOPE)
else()
set(${VAR_NAME} "${FLAG}" PARENT_SCOPE)
endif()
endfunction()
macro(google_initialize_cartographer_project)
if(CARTOGRAPHER_CMAKE_DIR)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
${CARTOGRAPHER_CMAKE_DIR}/modules)
else()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
endif()
if(WIN32)
# TODO turn on equivalent warnings on Windows
else()
set(GOOG_CXX_FLAGS "-pthread -fPIC ${GOOG_CXX_FLAGS}")
google_add_flag(GOOG_CXX_FLAGS "-Wall")
google_add_flag(GOOG_CXX_FLAGS "-Wpedantic")
# clalancette: disable deprecated declarations; there is currently no way to
# compile cartographer warning-free with this on
google_add_flag(GOOG_CXX_FLAGS "-Wno-deprecated-declarations")
# Turn some warnings into errors.
google_add_flag(GOOG_CXX_FLAGS "-Werror=format-security")
google_add_flag(GOOG_CXX_FLAGS "-Werror=missing-braces")
google_add_flag(GOOG_CXX_FLAGS "-Werror=reorder")
google_add_flag(GOOG_CXX_FLAGS "-Werror=return-type")
google_add_flag(GOOG_CXX_FLAGS "-Werror=switch")
google_add_flag(GOOG_CXX_FLAGS "-Werror=uninitialized")
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
google_add_flag(GOOG_CXX_FLAGS "-Wthread-safety")
endif()
if(NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE Release)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Release")
google_add_flag(GOOG_CXX_FLAGS "-O3 -DNDEBUG")
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
google_add_flag(GOOG_CXX_FLAGS "-O3 -g -DNDEBUG")
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
if(FORCE_DEBUG_BUILD)
message(WARNING "Building in Debug mode, expect very slow performance.")
google_add_flag(GOOG_CXX_FLAGS "-g")
else()
message(FATAL_ERROR
"Compiling in Debug mode is not supported and can cause severely degraded performance. "
"You should change the build type to Release. If you want to build in Debug mode anyway, "
"call CMake with -DFORCE_DEBUG_BUILD=True"
)
endif()
# Support for Debian packaging CMAKE_BUILD_TYPE
elseif(CMAKE_BUILD_TYPE STREQUAL "None")
message(WARNING "Building with CMAKE_BUILD_TYPE None, "
"please make sure you have set CFLAGS and CXXFLAGS according to your needs.")
else()
message(FATAL_ERROR "Unknown CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
# Add a hook that reruns CMake when source files are added or removed.
set(LIST_FILES_CMD "find ${PROJECT_SOURCE_DIR}/ -not -iwholename '*.git*' | sort | sed 's/^/#/'")
set(FILES_LIST_PATH "${PROJECT_BINARY_DIR}/AllFiles.cmake")
set(DETECT_CHANGES_CMD "bash" "-c" "${LIST_FILES_CMD} | diff -N -q ${FILES_LIST_PATH} - || ${LIST_FILES_CMD} > ${FILES_LIST_PATH}")
add_custom_target(${PROJECT_NAME}_detect_changes ALL
COMMAND ${DETECT_CHANGES_CMD}
VERBATIM
)
if(NOT EXISTS ${FILES_LIST_PATH})
execute_process(COMMAND ${DETECT_CHANGES_CMD})
endif()
include(${FILES_LIST_PATH})
endif()
endmacro()
macro(google_enable_testing)
enable_testing()
find_package(GMock REQUIRED)
endmacro()
@@ -0,0 +1,30 @@
# Copyright 2018 The Cartographer Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
find_package(Eigen3 QUIET NO_MODULE)
if (NOT EIGEN3_FOUND)
list(APPEND EIGEN3_POSSIBLE_DIRS
/usr/local/include/eigen3
/usr/include/eigen3
)
find_path(EIGEN3_INCLUDE_DIR
NAMES Eigen/Core
PATHS ${EIGEN3_POSSIBLE_DIRS}
)
if (EIGEN3_INCLUDE_DIR AND EXISTS ${EIGEN3_INCLUDE_DIR})
set(EIGEN3_FOUND TRUE)
else()
message(WARNING "Failed to find Eigen3. Please, define the path manually.")
endif()
endif()
@@ -0,0 +1,94 @@
# Copyright 2016 The Cartographer Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
if(NOT GMock_FOUND)
find_path(GMOCK_INCLUDE_DIRS gmock/gmock.h
HINTS
ENV GMOCK_DIR
PATH_SUFFIXES include
PATHS
/usr
)
# Find system-wide installed gmock.
find_library(GMOCK_LIBRARIES
NAMES gmock_main
HINTS
ENV GMOCK_DIR
PATH_SUFFIXES lib
PATHS
/usr
)
if(GMOCK_LIBRARIES)
find_library(GMOCK_LIBRARY
NAMES gmock
HINTS
ENV GMOCK_DIR
PATH_SUFFIXES lib
PATHS
/usr
)
find_library(GTEST_LIBRARY
NAMES gtest
HINTS
ENV GMOCK_DIR
PATH_SUFFIXES lib
PATHS
/usr
)
list(APPEND GMOCK_LIBRARIES ${GMOCK_LIBRARY} ${GTEST_LIBRARY})
endif()
# Find system-wide gtest header.
find_path(GTEST_INCLUDE_DIRS gtest/gtest.h
HINTS
ENV GTEST_DIR
PATH_SUFFIXES include
PATHS
/usr
)
list(APPEND GMOCK_INCLUDE_DIRS ${GTEST_INCLUDE_DIRS})
if(NOT GMOCK_LIBRARIES)
# If no system-wide gmock found, then find src version.
# Ubuntu might have this.
find_path(GMOCK_SRC_DIR src/gmock.cc
HINTS
ENV GMOCK_DIR
PATHS
/usr/src/googletest/googlemock
/usr/src/gmock
)
if(GMOCK_SRC_DIR)
# If src version found, build it.
if(NOT TARGET gmock)
add_subdirectory(${GMOCK_SRC_DIR} "${CMAKE_CURRENT_BINARY_DIR}/gmock"
EXCLUDE_FROM_ALL)
endif()
set(GMOCK_LIBRARIES gmock_main)
set(GMOCK_INCLUDE_DIRS ${GMOCK_SRC_DIR}/include)
endif()
endif()
# System-wide installed gmock library might require pthreads.
find_package(Threads REQUIRED)
list(APPEND GMOCK_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GMock DEFAULT_MSG GMOCK_LIBRARIES
GMOCK_INCLUDE_DIRS)
# Mitigate build issue with Catkin
set(GMOCK_FOUND FALSE)
@@ -0,0 +1,220 @@
# Copyright 2016 The Cartographer Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# TODO(hrapp): Take from the cmake master branch and simplified. As soon as we
# require a CMakeVersion that ships with this, remove again.
#.rst:
# FindLua
# -------
#
#
#
# Locate Lua library This module defines
#
# ::
#
# LUA_FOUND - if false, do not try to link to Lua
# LUA_LIBRARIES - both lua and lualib
# LUA_INCLUDE_DIR - where to find lua.h
# LUA_VERSION_STRING - the version of Lua found
# LUA_VERSION_MAJOR - the major version of Lua
# LUA_VERSION_MINOR - the minor version of Lua
# LUA_VERSION_PATCH - the patch version of Lua
#
#
#
# Note that the expected include convention is
#
# ::
#
# #include "lua.h"
#
# and not
#
# ::
#
# #include <lua/lua.h>
#
# This is because, the lua location is not standardized and may exist in
# locations other than lua/
#=============================================================================
# Copyright 2007-2009 Kitware, Inc.
# Copyright 2013 Rolf Eike Beer <eike@sf-mail.de>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
unset(_lua_include_subdirs)
unset(_lua_library_names)
unset(_lua_append_versions)
# this is a function only to have all the variables inside go away automatically
function(_lua_set_version_vars)
set(LUA_VERSIONS5 5.3 5.2)
if (Lua_FIND_VERSION_EXACT)
if (Lua_FIND_VERSION_COUNT GREATER 1)
set(_lua_append_versions ${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR})
endif ()
elseif (Lua_FIND_VERSION)
# once there is a different major version supported this should become a loop
if (NOT Lua_FIND_VERSION_MAJOR GREATER 5)
if (Lua_FIND_VERSION_COUNT EQUAL 1)
set(_lua_append_versions ${LUA_VERSIONS5})
else ()
foreach (subver IN LISTS LUA_VERSIONS5)
if (NOT subver VERSION_LESS ${Lua_FIND_VERSION})
list(APPEND _lua_append_versions ${subver})
endif ()
endforeach ()
endif ()
endif ()
else ()
# once there is a different major version supported this should become a loop
set(_lua_append_versions ${LUA_VERSIONS5})
endif ()
list(APPEND _lua_include_subdirs "include/lua" "include")
foreach (ver IN LISTS _lua_append_versions)
string(REGEX MATCH "^([0-9]+)\\.([0-9]+)$" _ver "${ver}")
list(APPEND _lua_include_subdirs
include/lua${CMAKE_MATCH_1}${CMAKE_MATCH_2}
include/lua${CMAKE_MATCH_1}.${CMAKE_MATCH_2}
include/lua-${CMAKE_MATCH_1}.${CMAKE_MATCH_2}
)
list(APPEND _lua_library_names
lua${CMAKE_MATCH_1}${CMAKE_MATCH_2}
lua${CMAKE_MATCH_1}.${CMAKE_MATCH_2}
lua-${CMAKE_MATCH_1}.${CMAKE_MATCH_2}
lua.${CMAKE_MATCH_1}.${CMAKE_MATCH_2}
)
endforeach ()
set(_lua_include_subdirs "${_lua_include_subdirs}" PARENT_SCOPE)
set(_lua_library_names "${_lua_library_names}" PARENT_SCOPE)
set(_lua_append_versions "${_lua_append_versions}" PARENT_SCOPE)
endfunction(_lua_set_version_vars)
function(_lua_check_header_version _hdr_file)
# At least 5.[012] have different ways to express the version
# so all of them need to be tested. Lua 5.2 defines LUA_VERSION
# and LUA_RELEASE as joined by the C preprocessor, so avoid those.
file(STRINGS "${_hdr_file}" lua_version_strings
REGEX "^#define[ \t]+LUA_(RELEASE[ \t]+\"Lua [0-9]|VERSION([ \t]+\"Lua [0-9]|_[MR])).*")
string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MAJOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_MAJOR ";${lua_version_strings};")
if (LUA_VERSION_MAJOR MATCHES "^[0-9]+$")
string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MINOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_MINOR ";${lua_version_strings};")
string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_RELEASE[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_PATCH ";${lua_version_strings};")
set(LUA_VERSION_STRING "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}.${LUA_VERSION_PATCH}")
else ()
string(REGEX REPLACE ".*;#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" LUA_VERSION_STRING ";${lua_version_strings};")
if (NOT LUA_VERSION_STRING MATCHES "^[0-9.]+$")
string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" LUA_VERSION_STRING ";${lua_version_strings};")
endif ()
string(REGEX REPLACE "^([0-9]+)\\.[0-9.]*$" "\\1" LUA_VERSION_MAJOR "${LUA_VERSION_STRING}")
string(REGEX REPLACE "^[0-9]+\\.([0-9]+)[0-9.]*$" "\\1" LUA_VERSION_MINOR "${LUA_VERSION_STRING}")
string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]).*" "\\1" LUA_VERSION_PATCH "${LUA_VERSION_STRING}")
endif ()
foreach (ver IN LISTS _lua_append_versions)
if (ver STREQUAL "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}")
set(LUA_VERSION_MAJOR ${LUA_VERSION_MAJOR} PARENT_SCOPE)
set(LUA_VERSION_MINOR ${LUA_VERSION_MINOR} PARENT_SCOPE)
set(LUA_VERSION_PATCH ${LUA_VERSION_PATCH} PARENT_SCOPE)
set(LUA_VERSION_STRING ${LUA_VERSION_STRING} PARENT_SCOPE)
return()
endif ()
endforeach ()
endfunction(_lua_check_header_version)
_lua_set_version_vars()
if (LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h")
_lua_check_header_version("${LUA_INCLUDE_DIR}/lua.h")
endif ()
if (NOT LUA_VERSION_STRING)
foreach (subdir IN LISTS _lua_include_subdirs)
unset(LUA_INCLUDE_PREFIX CACHE)
find_path(LUA_INCLUDE_PREFIX ${subdir}/lua.h
HINTS
ENV LUA_DIR
PATHS
~/Library/Frameworks
/Library/Frameworks
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
)
if (LUA_INCLUDE_PREFIX)
_lua_check_header_version("${LUA_INCLUDE_PREFIX}/${subdir}/lua.h")
if (LUA_VERSION_STRING)
set(LUA_INCLUDE_DIR "${LUA_INCLUDE_PREFIX}/${subdir}")
break()
endif ()
endif ()
endforeach ()
endif ()
unset(_lua_include_subdirs)
unset(_lua_append_versions)
find_library(LUA_LIBRARY
NAMES ${_lua_library_names} lua
HINTS
ENV LUA_DIR
PATH_SUFFIXES lib
PATHS
~/Library/Frameworks
/Library/Frameworks
/sw
/opt/local
/opt/csw
/opt
)
unset(_lua_library_names)
if (LUA_LIBRARY)
# include the math library for Unix
if (UNIX AND NOT APPLE AND NOT BEOS)
find_library(LUA_MATH_LIBRARY m)
set(LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}")
# For Windows and Mac, don't need to explicitly include the math library
else ()
set(LUA_LIBRARIES "${LUA_LIBRARY}")
endif ()
endif ()
# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if
# all listed variables are TRUE
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua
REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR
VERSION_VAR LUA_VERSION_STRING)
mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARY LUA_MATH_LIBRARY)
if (NOT LUA_FOUND)
MESSAGE(FATAL_ERROR "Did not find Lua >= 5.2.")
endif ()
@@ -0,0 +1,24 @@
# Copyright 2016 The Cartographer Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# TODO(hrapp): Replace through the one of ceres
find_program(SPHINX_EXECUTABLE
NAMES sphinx-build
PATHS
/usr/bin
DOC "Sphinx")
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Sphinx DEFAULT_MSG SPHINX_EXECUTABLE)