Extend CMake functions for reuse in other Cartographer subprojects. (#45)
- Change CARTOGRAPHER_LIBRARIES to be absolute path to adhere to the CMake documentation.master
parent
f6c9f9565f
commit
8e7996f015
|
@ -22,23 +22,7 @@ set(CARTOGRAPHER_VERSION ${CARTOGRAPHER_MAJOR_VERSION}.${CARTOGRAPHER_MINOR_VERS
|
||||||
set(CARTOGRAPHER_SOVERSION ${CARTOGRAPHER_MAJOR_VERSION}.${CARTOGRAPHER_MINOR_VERSION})
|
set(CARTOGRAPHER_SOVERSION ${CARTOGRAPHER_MAJOR_VERSION}.${CARTOGRAPHER_MINOR_VERSION})
|
||||||
|
|
||||||
include("${CMAKE_SOURCE_DIR}/cmake/functions.cmake")
|
include("${CMAKE_SOURCE_DIR}/cmake/functions.cmake")
|
||||||
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
|
google_initialize_cartographer_project()
|
||||||
|
|
||||||
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")
|
|
||||||
message(FATAL_ERROR "Cartographer is too slow to be useful in debug mode.")
|
|
||||||
else()
|
|
||||||
message(FATAL_ERROR "Unknown CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
|
|
||||||
|
|
||||||
find_package(Boost REQUIRED COMPONENTS system iostreams)
|
find_package(Boost REQUIRED COMPONENTS system iostreams)
|
||||||
find_package(Ceres REQUIRED)
|
find_package(Ceres REQUIRED)
|
||||||
|
@ -52,26 +36,6 @@ if(SPHINX_FOUND)
|
||||||
add_subdirectory("docs")
|
add_subdirectory("docs")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(GMOCK_SRC_DIR "/usr/src/gmock" CACHE STRING "Path to google-mock sources.")
|
|
||||||
|
|
||||||
add_subdirectory(${GMOCK_SRC_DIR} "${CMAKE_CURRENT_BINARY_DIR}/gmock")
|
|
||||||
|
|
||||||
google_add_flag(GOOG_CXX_FLAGS "-std=c++11")
|
|
||||||
|
|
||||||
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
|
||||||
google_add_flag(GOOG_CXX_FLAGS "-Weverything")
|
|
||||||
google_add_flag(GOOG_CXX_FLAGS "-Werror=deprecated")
|
|
||||||
google_add_flag(GOOG_CXX_FLAGS "-Werror=non-pod-varargs")
|
|
||||||
else()
|
|
||||||
google_add_flag(GOOG_CXX_FLAGS "-Wall")
|
|
||||||
google_add_flag(GOOG_CXX_FLAGS "-Wpedantic")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Turn some warnings into errors. These are defined for clang and gcc.
|
|
||||||
google_add_flag(GOOG_CXX_FLAGS "-Werror=format-security")
|
|
||||||
google_add_flag(GOOG_CXX_FLAGS "-Werror=return-type")
|
|
||||||
google_add_flag(GOOG_CXX_FLAGS "-Werror=uninitialized")
|
|
||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
||||||
SET(ALL_LIBRARIES "" CACHE INTERNAL "ALL_LIBRARIES")
|
SET(ALL_LIBRARIES "" CACHE INTERNAL "ALL_LIBRARIES")
|
||||||
|
@ -82,6 +46,8 @@ install(FILES package.xml DESTINATION share/cartographer)
|
||||||
set(CARTOGRAPHER_CONFIGURATION_FILES_DIRECTORY "${CMAKE_INSTALL_PREFIX}/share/cartographer/configuration_files")
|
set(CARTOGRAPHER_CONFIGURATION_FILES_DIRECTORY "${CMAKE_INSTALL_PREFIX}/share/cartographer/configuration_files")
|
||||||
install(DIRECTORY configuration_files DESTINATION share/cartographer/)
|
install(DIRECTORY configuration_files DESTINATION share/cartographer/)
|
||||||
|
|
||||||
|
install(DIRECTORY cmake DESTINATION share/cartographer/)
|
||||||
|
|
||||||
add_subdirectory("cartographer")
|
add_subdirectory("cartographer")
|
||||||
|
|
||||||
include(CMakePackageConfigHelpers)
|
include(CMakePackageConfigHelpers)
|
||||||
|
@ -96,11 +62,15 @@ list(APPEND CARTOGRAPHER_INCLUDE_DIRS "${LUA_INCLUDE_DIR}")
|
||||||
list(APPEND CARTOGRAPHER_INCLUDE_DIRS "${CERES_INCLUDE_DIRS}")
|
list(APPEND CARTOGRAPHER_INCLUDE_DIRS "${CERES_INCLUDE_DIRS}")
|
||||||
list(APPEND CARTOGRAPHER_INCLUDE_DIRS "${PROTOBUF_INCLUDE_DIR}")
|
list(APPEND CARTOGRAPHER_INCLUDE_DIRS "${PROTOBUF_INCLUDE_DIR}")
|
||||||
|
|
||||||
|
set(CARTOGRAPHER_CMAKE_DIR "${CMAKE_INSTALL_PREFIX}/share/cartographer/cmake")
|
||||||
|
|
||||||
google_combined_library(cartographer
|
google_combined_library(cartographer
|
||||||
SRCS "${ALL_LIBRARIES}"
|
SRCS "${ALL_LIBRARIES}"
|
||||||
)
|
)
|
||||||
|
|
||||||
get_property(CARTOGRAPHER_LIBRARY_FILE TARGET cartographer PROPERTY LOCATION)
|
get_property(CARTOGRAPHER_LIBRARY_FILE TARGET cartographer PROPERTY LOCATION)
|
||||||
|
get_filename_component(CARTOGRAPHER_LIBRARY_FILE_BASENAME
|
||||||
|
${CARTOGRAPHER_LIBRARY_FILE} NAME)
|
||||||
install(
|
install(
|
||||||
FILES
|
FILES
|
||||||
${CARTOGRAPHER_LIBRARY_FILE}
|
${CARTOGRAPHER_LIBRARY_FILE}
|
||||||
|
@ -109,7 +79,7 @@ install(
|
||||||
)
|
)
|
||||||
|
|
||||||
set(CARTOGRAPHER_LIBRARIES "")
|
set(CARTOGRAPHER_LIBRARIES "")
|
||||||
list(APPEND CARTOGRAPHER_LIBRARIES "cartographer")
|
list(APPEND CARTOGRAPHER_LIBRARIES "${CMAKE_INSTALL_PREFIX}/lib/${CARTOGRAPHER_LIBRARY_FILE_BASENAME}")
|
||||||
list(APPEND CARTOGRAPHER_LIBRARIES "${CERES_LIBRARIES}")
|
list(APPEND CARTOGRAPHER_LIBRARIES "${CERES_LIBRARIES}")
|
||||||
list(APPEND CARTOGRAPHER_LIBRARIES "${Boost_LIBRARIES}")
|
list(APPEND CARTOGRAPHER_LIBRARIES "${Boost_LIBRARIES}")
|
||||||
list(APPEND CARTOGRAPHER_LIBRARIES "${LUA_LIBRARIES}")
|
list(APPEND CARTOGRAPHER_LIBRARIES "${LUA_LIBRARIES}")
|
||||||
|
@ -119,7 +89,7 @@ list(APPEND CARTOGRAPHER_LIBRARIES "webp")
|
||||||
CONFIGURE_PACKAGE_CONFIG_FILE(
|
CONFIGURE_PACKAGE_CONFIG_FILE(
|
||||||
cartographer-config.cmake.in
|
cartographer-config.cmake.in
|
||||||
"${CMAKE_BINARY_DIR}/cmake/cartographer/cartographer-config.cmake"
|
"${CMAKE_BINARY_DIR}/cmake/cartographer/cartographer-config.cmake"
|
||||||
PATH_VARS CARTOGRAPHER_INCLUDE_DIRS CARTOGRAPHER_LIBRARY_DIRS
|
PATH_VARS CARTOGRAPHER_INCLUDE_DIRS CARTOGRAPHER_LIBRARY_DIRS CARTOGRAPHER_CMAKE_DIR
|
||||||
INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cartographer
|
INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cartographer
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
set(CARTOGRAPHER_INCLUDE_DIRS "@PACKAGE_CARTOGRAPHER_INCLUDE_DIRS@")
|
set(CARTOGRAPHER_INCLUDE_DIRS "@PACKAGE_CARTOGRAPHER_INCLUDE_DIRS@")
|
||||||
set(CARTOGRAPHER_LIBRARY_DIRS "@PACKAGE_CARTOGRAPHER_LIBRARY_DIRS@")
|
set(CARTOGRAPHER_LIBRARY_DIRS "@PACKAGE_CARTOGRAPHER_LIBRARY_DIRS@")
|
||||||
|
set(CARTOGRAPHER_CMAKE_DIR "@PACKAGE_CARTOGRAPHER_CMAKE_DIR@")
|
||||||
|
|
||||||
set(CARTOGRAPHER_LIBRARIES
|
set(CARTOGRAPHER_LIBRARIES
|
||||||
"@CARTOGRAPHER_LIBRARIES@"
|
"@CARTOGRAPHER_LIBRARIES@"
|
||||||
|
|
|
@ -25,6 +25,14 @@ macro(_parse_arguments ARGS)
|
||||||
USES_GLOG
|
USES_GLOG
|
||||||
USES_GFLAGS
|
USES_GFLAGS
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Options only used by projects using Cartographers cmake files.
|
||||||
|
list(APPEND OPTIONS
|
||||||
|
USES_CARTOGRAPHER
|
||||||
|
USES_ROS
|
||||||
|
USES_ZLIB
|
||||||
|
USES_PCL
|
||||||
|
)
|
||||||
set(ONE_VALUE_ARG )
|
set(ONE_VALUE_ARG )
|
||||||
set(MULTI_VALUE_ARGS SRCS HDRS DEPENDS)
|
set(MULTI_VALUE_ARGS SRCS HDRS DEPENDS)
|
||||||
cmake_parse_arguments(ARG
|
cmake_parse_arguments(ARG
|
||||||
|
@ -33,31 +41,29 @@ endmacro(_parse_arguments)
|
||||||
|
|
||||||
macro(_common_compile_stuff VISIBILITY)
|
macro(_common_compile_stuff VISIBILITY)
|
||||||
set(TARGET_COMPILE_FLAGS "${TARGET_COMPILE_FLAGS} ${GOOG_CXX_FLAGS}")
|
set(TARGET_COMPILE_FLAGS "${TARGET_COMPILE_FLAGS} ${GOOG_CXX_FLAGS}")
|
||||||
set_target_properties(${NAME} PROPERTIES
|
|
||||||
COMPILE_FLAGS ${TARGET_COMPILE_FLAGS})
|
|
||||||
|
|
||||||
if(ARG_USES_EIGEN)
|
if(ARG_USES_EIGEN)
|
||||||
target_include_directories("${NAME}" SYSTEM ${VISIBILITY}
|
target_include_directories("${NAME}" SYSTEM ${VISIBILITY}
|
||||||
"${EIGEN3_INCLUDE_DIR}")
|
"${EIGEN3_INCLUDE_DIR}")
|
||||||
target_link_libraries("${NAME}" "${EIGEN3_LIBRARIES}")
|
target_link_libraries("${NAME}" ${EIGEN3_LIBRARIES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(ARG_USES_CERES)
|
if(ARG_USES_CERES)
|
||||||
target_include_directories("${NAME}" SYSTEM ${VISIBILITY}
|
target_include_directories("${NAME}" SYSTEM ${VISIBILITY}
|
||||||
"${CERES_INCLUDE_DIRS}")
|
"${CERES_INCLUDE_DIRS}")
|
||||||
target_link_libraries("${NAME}" "${CERES_LIBRARIES}")
|
target_link_libraries("${NAME}" ${CERES_LIBRARIES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(ARG_USES_LUA)
|
if(ARG_USES_LUA)
|
||||||
target_include_directories("${NAME}" SYSTEM ${VISIBILITY}
|
target_include_directories("${NAME}" SYSTEM ${VISIBILITY}
|
||||||
"${LUA_INCLUDE_DIR}")
|
"${LUA_INCLUDE_DIR}")
|
||||||
target_link_libraries("${NAME}" "${LUA_LIBRARIES}")
|
target_link_libraries("${NAME}" ${LUA_LIBRARIES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(ARG_USES_BOOST)
|
if(ARG_USES_BOOST)
|
||||||
target_include_directories("${NAME}" SYSTEM ${VISIBILITY}
|
target_include_directories("${NAME}" SYSTEM ${VISIBILITY}
|
||||||
"{Boost_INCLUDE_DIRS}")
|
"{Boost_INCLUDE_DIRS}")
|
||||||
target_link_libraries("${NAME}" "${Boost_LIBRARIES}")
|
target_link_libraries("${NAME}" ${Boost_LIBRARIES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(ARG_USES_WEBP)
|
if(ARG_USES_WEBP)
|
||||||
|
@ -73,6 +79,38 @@ macro(_common_compile_stuff VISIBILITY)
|
||||||
target_link_libraries("${NAME}" gflags)
|
target_link_libraries("${NAME}" gflags)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(ARG_USES_ROS)
|
||||||
|
target_include_directories("${NAME}" SYSTEM ${VISIBILITY}
|
||||||
|
"${catkin_INCLUDE_DIRS}")
|
||||||
|
target_link_libraries("${NAME}" ${catkin_LIBRARIES})
|
||||||
|
add_dependencies("${NAME}" ${catkin_EXPORTED_TARGETS}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(ARG_USES_ZLIB)
|
||||||
|
target_include_directories("${NAME}" SYSTEM ${VISIBILITY}
|
||||||
|
"${ZLIB_INCLUDE_DIRS}")
|
||||||
|
target_link_libraries("${NAME}" ${ZLIB_LIBRARIES})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(ARG_USES_CARTOGRAPHER)
|
||||||
|
target_include_directories("${NAME}" SYSTEM ${VISIBILITY}
|
||||||
|
"${CARTOGRAPHER_INCLUDE_DIRS}")
|
||||||
|
target_link_libraries("${NAME}" ${CARTOGRAPHER_LIBRARIES})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(ARG_USES_PCL)
|
||||||
|
target_include_directories("${NAME}" SYSTEM ${VISIBILITY}
|
||||||
|
"${PCL_INCLUDE_DIRS}")
|
||||||
|
target_link_libraries("${NAME}" ${PCL_LIBRARIES})
|
||||||
|
foreach(DEFINITION ${PCL_DEFINITIONS})
|
||||||
|
set(TARGET_COMPILE_FLAGS "${TARGET_COMPILE_FLAGS} ${DEFINITION}")
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set_target_properties(${NAME} PROPERTIES
|
||||||
|
COMPILE_FLAGS ${TARGET_COMPILE_FLAGS})
|
||||||
|
|
||||||
# Add the binary directory first, so that port.h is included after it has
|
# Add the binary directory first, so that port.h is included after it has
|
||||||
# been generated.
|
# been generated.
|
||||||
target_include_directories("${NAME}" ${VISIBILITY} "${CMAKE_BINARY_DIR}")
|
target_include_directories("${NAME}" ${VISIBILITY} "${CMAKE_BINARY_DIR}")
|
||||||
|
@ -265,5 +303,38 @@ function(google_proto_library NAME)
|
||||||
"${PROTOBUF_INCLUDE_DIR}")
|
"${PROTOBUF_INCLUDE_DIR}")
|
||||||
# TODO(hrapp): This should not explicityly list pthread and use
|
# TODO(hrapp): This should not explicityly list pthread and use
|
||||||
# PROTOBUF_LIBRARIES, but that failed on first try.
|
# PROTOBUF_LIBRARIES, but that failed on first try.
|
||||||
target_link_libraries("${NAME}" "${PROTOBUF_LIBRARY}" pthread)
|
target_link_libraries("${NAME}" ${PROTOBUF_LIBRARY} pthread)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
macro(google_initialize_cartographer_project)
|
||||||
|
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
|
||||||
|
set(GOOG_CXX_FLAGS "-pthread -std=c++11 ${GOOG_CXX_FLAGS}")
|
||||||
|
|
||||||
|
google_add_flag(GOOG_CXX_FLAGS "-Wall")
|
||||||
|
google_add_flag(GOOG_CXX_FLAGS "-Wpedantic")
|
||||||
|
|
||||||
|
# Turn some warnings into errors.
|
||||||
|
google_add_flag(GOOG_CXX_FLAGS "-Werror=format-security")
|
||||||
|
google_add_flag(GOOG_CXX_FLAGS "-Werror=reorder")
|
||||||
|
google_add_flag(GOOG_CXX_FLAGS "-Werror=return-type")
|
||||||
|
google_add_flag(GOOG_CXX_FLAGS "-Werror=uninitialized")
|
||||||
|
|
||||||
|
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")
|
||||||
|
message(FATAL_ERROR "Compiling in debug mode is not supported.")
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Unknown CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
|
||||||
|
|
||||||
|
set(GMOCK_SRC_DIR "/usr/src/gmock" CACHE STRING "Path to google-mock sources.")
|
||||||
|
add_subdirectory(${GMOCK_SRC_DIR} "${CMAKE_CURRENT_BINARY_DIR}/gmock")
|
||||||
|
endmacro()
|
||||||
|
|
Loading…
Reference in New Issue