Skip to content

Commit

Permalink
Refactoring RTABMapConfig.cmake with targets (#904)
Browse files Browse the repository at this point in the history
* Config: Using cmake targets

* fixed RTABMAP_DEPRECATED build error

* fixed melodic build

* cleanup

* Fixed qhull exported library error

* Update svg depend private

* removed g2o from public interface

* Fixed Windows with external project

* removed some required dep

* Fixed nsis error (also fixed unspecified components)

* updated workflow rules
  • Loading branch information
matlabbe authored Feb 13, 2023
1 parent 437ed09 commit 89e3e10
Show file tree
Hide file tree
Showing 191 changed files with 1,151 additions and 2,200 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/cmake-ros.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: CMake-ROS

on:
push:
branches:
- '**'
branches:
- master
pull_request:
branches:
branches:
- '**'

env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CMake
on:
push:
branches:
- '**'
- master
pull_request:
branches:
- '**'
Expand Down
188 changes: 89 additions & 99 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake_modules")
# VERSION
#######################
SET(RTABMAP_MAJOR_VERSION 0)
SET(RTABMAP_MINOR_VERSION 20)
SET(RTABMAP_PATCH_VERSION 23)
SET(RTABMAP_MINOR_VERSION 21)
SET(RTABMAP_PATCH_VERSION 0)
SET(RTABMAP_VERSION
${RTABMAP_MAJOR_VERSION}.${RTABMAP_MINOR_VERSION}.${RTABMAP_PATCH_VERSION})

Expand Down Expand Up @@ -296,10 +296,7 @@ IF(WITH_QT)
# look for Qt5 (if vtk>5 is installed) before Qt4
IF("${VTK_MAJOR_VERSION}" GREATER 5)
if(RTABMAP_QT_VERSION STREQUAL "AUTO" OR RTABMAP_QT_VERSION STREQUAL "5")
FIND_PACKAGE(Qt5 COMPONENTS Widgets Core Gui PrintSupport QUIET)
IF(Qt5_FOUND)
FIND_PACKAGE(Qt5 COMPONENTS Widgets Core Gui PrintSupport OPTIONAL_COMPONENTS Svg)
ENDIF(Qt5_FOUND)
FIND_PACKAGE(Qt5 COMPONENTS Widgets Core Gui PrintSupport OpenGL OPTIONAL_COMPONENTS Svg)
ENDIF(RTABMAP_QT_VERSION STREQUAL "AUTO" OR RTABMAP_QT_VERSION STREQUAL "5")
ENDIF("${VTK_MAJOR_VERSION}" GREATER 5)

Expand Down Expand Up @@ -823,11 +820,6 @@ ENDIF(APPLE AND BUILD_AS_BUNDLE)

####### SOURCES (Projects) #######

# CONF_DEPENDENCIES contains only dependencies not required by the headers
SET(CONF_DEPENDENCIES
${ZLIB_LIBRARIES}
)

# OpenCV2 has nonfree if OPENCV_NONFREE_FOUND
# OpenCV<=3.4.2 has nonfree if OPENCV_XFEATURES2D_FOUND
# OpenCV>3.4.2 has nonfree if OPENCV_XFEATURES2D_FOUND and OPENCV_ENABLE_NONFREE is defined
Expand All @@ -848,15 +840,12 @@ IF(NOT G2O_FOUND)
SET(G2O "//")
SET(G2O_CPP_CONF "//")
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${G2O_LIBRARIES})
IF(NOT G2O_CPP11)
SET(G2O_CPP_CONF "//")
SET(G2O_CPP_CONF "//")
ENDIF(NOT G2O_CPP11)
ENDIF()
IF(NOT GTSAM_FOUND)
SET(GTSAM "//")
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${GTSAM_LIBRARIES})
ENDIF()
IF(NOT MRPT_FOUND)
SET(MRPT "//")
Expand All @@ -872,8 +861,6 @@ IF(NOT WITH_VERTIGO)
ENDIF(NOT WITH_VERTIGO)
IF(NOT cvsba_FOUND)
SET(CVSBA "//")
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${cvsba_LIBRARIES})
ENDIF()
IF(NOT libpointmatcher_FOUND)
SET(POINTMATCHER "//")
Expand Down Expand Up @@ -901,61 +888,61 @@ IF(NOT floam_FOUND)
ENDIF(NOT floam_FOUND)
IF(NOT Freenect_FOUND)
SET(FREENECT "//")
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${Freenect_LIBRARIES})
ENDIF()
IF(NOT freenect2_FOUND)
SET(FREENECT2 "//")
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${freenect2_LIBRARIES})
ENDIF()
IF(NOT KinectSDK2_FOUND)
SET(K4W2 "//")
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${KinectSDK2_LIBRARIES})
ENDIF()
IF(NOT k4a_FOUND)
SET(K4A "//")
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${k4a_LIBRARIES})
SET(CONF_WITH_K4A 0)
ELSE()
SET(CONF_WITH_K4A 1)
IF(WIN32)
install(
FILES
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindK4A.cmake"
DESTINATION ${INSTALL_CMAKE_DIR}/Modules/.
COMPONENT devel
)
ENDIF(WIN32)
ENDIF()
IF(NOT OpenNI2_FOUND)
SET(OPENNI2 "//")
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${OpenNI2_LIBRARIES})
ENDIF()
IF(NOT DC1394_FOUND)
SET(DC1394 "//")
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${DC1394_LIBRARIES})
ENDIF()
IF(NOT FlyCapture2_FOUND)
SET(FLYCAPTURE2 "//")
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${FlyCapture2_LIBRARIES})
ENDIF()
IF(NOT ZED_FOUND)
SET(ZED "//")
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${ZED_LIBRARIES} ${CUDA_LIBRARIES})
ENDIF()
IF(NOT ZEDOC_FOUND)
SET(ZEDOC "//")
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${ZEDOC_LIBRARIES})
ENDIF()
IF(NOT RealSense_FOUND)
SET(REALSENSE "//")
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${RealSense_LIBRARIES})
ENDIF()
IF(NOT RealSenseSlam_FOUND)
SET(REALSENSESLAM "//")
ENDIF(NOT RealSenseSlam_FOUND)
IF(NOT realsense2_FOUND)
SET(REALSENSE2 "//")
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${realsense2_LIBRARIES})
SET(CONF_WITH_REALSENSE2 0)
ELSE()
SET(CONF_WITH_REALSENSE2 1)
IF(WIN32)
install(
FILES
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindRealSense2.cmake"
DESTINATION ${INSTALL_CMAKE_DIR}/Modules/.
COMPONENT devel
)
ENDIF(WIN32)
ENDIF()
IF(NOT mynteye_FOUND)
SET(MYNTEYE "//")
Expand All @@ -965,65 +952,45 @@ IF(NOT depthai_FOUND)
SET(DEPTHAI "//")
ELSE()
SET(CONF_DEPTH_AI ON)
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} depthai::core depthai::opencv)
ENDIF()
IF(NOT octomap_FOUND)
SET(OCTOMAP "//")
SET(CONF_WITH_OCTOMAP 0)
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${OCTOMAP_LIBRARIES})
SET(CONF_WITH_OCTOMAP 1)
ENDIF()
IF(NOT CPUTSDF_FOUND)
SET(CPUTSDF "//")
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${CPUTSDF_LIBRARIES})
ENDIF()
IF(NOT open_chisel_FOUND)
SET(OPENCHISEL "//")
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${open_chisel_LIBRARIES})
ENDIF()
IF(NOT AliceVision_FOUND)
SET(ALICE_VISION "//")
ENDIF(NOT AliceVision_FOUND)
IF(NOT libfovis_FOUND)
SET(FOVIS "//")
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${libfovis_LIBRARIES})
ENDIF()
IF(NOT libviso2_FOUND)
SET(VISO2 "//")
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${libviso2_LIBRARIES})
ENDIF()
IF(NOT dvo_core_FOUND)
SET(DVO "//")
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${dvo_core_LIBRARIES})
ENDIF()
IF(NOT okvis_FOUND)
SET(OKVIS "//")
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${OKVIS_LIBRARIES})
ENDIF()
IF(NOT msckf_vio_FOUND)
SET(MSCKF_VIO "//")
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${msckf_vio_LIBRARIES})
ENDIF()
IF(NOT vins_FOUND)
SET(VINS "//")
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${vins_LIBRARIES})
ENDIF()
IF(NOT ov_msckf_FOUND)
SET(OPENVINS "//")
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${ov_msckf_LIBRARIES})
ENDIF()
IF(NOT ORB_SLAM_FOUND)
SET(ORB_SLAM "//")
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${ORB_SLAM_LIBRARIES})
ENDIF()
IF(NOT WITH_ORB_OCTREE)
SET(ORB_OCTREE "//")
Expand All @@ -1036,22 +1003,16 @@ IF(NOT WITH_PYTHON OR NOT Python3_FOUND)
ENDIF()
IF(ADD_VTK_GUI_SUPPORT_QT_TO_CONF)
SET(CONF_VTK_QT true)
IF("${VTK_MAJOR_VERSION}" GREATER 8)
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} VTK::GUISupportQt)
ELSE()
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} vtkGUISupportQt)
ENDIF()
ELSE()
SET(CONF_VTK_QT false)
ENDIF()
IF(VTK_USE_QVTK)
SET(CONF_DEPENDENCIES ${CONF_DEPENDENCIES} ${QVTK_LIBRARY})
ENDIF(VTK_USE_QVTK)
IF(NOT WITH_MADGWICK)
SET(MADGWICK "//")
ENDIF()

CONFIGURE_FILE(Version.h.in ${CMAKE_CURRENT_BINARY_DIR}/corelib/include/${PROJECT_PREFIX}/core/Version.h)
CONFIGURE_FILE(Version.h.in ${CMAKE_CURRENT_BINARY_DIR}/corelib/src/include/${PROJECT_PREFIX}/core/Version.h)

include(GenerateExportHeader)

ADD_SUBDIRECTORY( utilite )
ADD_SUBDIRECTORY( corelib )
Expand Down Expand Up @@ -1088,55 +1049,79 @@ ADD_CUSTOM_TARGET(uninstall
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")

####
# Setup RTABMapConfig.cmake
# Global Export Target
####
# Create the RTABMapConfig.cmake and RTABMapConfigVersion files
file(RELATIVE_PATH REL_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/${INSTALL_CMAKE_DIR}" "${CMAKE_INSTALL_PREFIX}/${INSTALL_INCLUDE_DIR}")
file(RELATIVE_PATH REL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/${INSTALL_CMAKE_DIR}" "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")

# ... for the build tree
set(CONF_INCLUDE_DIRS "${PROJECT_BINARY_DIR}/corelib/include"
"${PROJECT_SOURCE_DIR}/corelib/include"
"${PROJECT_SOURCE_DIR}/guilib/include"
"${PROJECT_SOURCE_DIR}/utilite/include")
set(CONF_LIB_DIR "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
add_library(rtabmap INTERFACE)
IF(QT4_FOUND OR Qt5_FOUND)
set(CONF_WITH_GUI ON)
IF(QT4_FOUND)
set(CONF_QT_VERSION 4)
ELSE()
set(CONF_QT_VERSION 5)
ENDIF()
target_link_libraries(rtabmap INTERFACE rtabmap_utilite rtabmap_core rtabmap_gui)
ELSE()
set(CONF_WITH_GUI OFF)
target_link_libraries(rtabmap INTERFACE rtabmap_utilite rtabmap_core)
ENDIF()
configure_file(RTABMapConfig.cmake.in
"${PROJECT_BINARY_DIR}/RTABMapConfig.cmake" @ONLY)

# ... for the install tree
set(CONF_INCLUDE_DIRS "\${RTABMap_CMAKE_DIR}/${REL_INCLUDE_DIR}")
set(CONF_LIB_DIR "\${RTABMap_CMAKE_DIR}/${REL_LIB_DIR}")
configure_file(RTABMapConfig.cmake.in
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/RTABMapConfig.cmake" @ONLY)
install(TARGETS rtabmap EXPORT rtabmapTargets)
export(EXPORT rtabmapTargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake"
)
install(EXPORT rtabmapTargets
FILE
${PROJECT_NAME}Targets.cmake
DESTINATION
${INSTALL_CMAKE_DIR}
COMPONENT
devel
)

####
# Setup RTABMapConfig.cmake
####
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)

# Build tree:
SET(CONF_MODULES_DIR "../cmake_modules")
configure_file(
${PROJECT_NAME}Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
@ONLY
)

# Install tree:
SET(CONF_MODULES_DIR "Modules")
configure_file(
${PROJECT_NAME}Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Config.cmake"
@ONLY
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION
${INSTALL_CMAKE_DIR}
COMPONENT
devel
)

# ... for both
configure_file(RTABMapConfigVersion.cmake.in
"${PROJECT_BINARY_DIR}/RTABMapConfigVersion.cmake" @ONLY)

# Install the RTABMapConfig.cmake and RTABMapConfigVersion.cmake
install(FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/RTABMapConfig.cmake"
"${PROJECT_BINARY_DIR}/RTABMapConfigVersion.cmake"
DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT devel)
####

### Install package.xml for catkin
install(FILES package.xml DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_PREFIX}")
install(FILES package.xml DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_PREFIX}" COMPONENT devel)

#######################
# CPACK (Packaging)
#######################
IF(BUILD_AS_BUNDLE)
SET(CMAKE_INSTALL_SYSTEM_RUNTIME_COMPONENT runtime)
INCLUDE(InstallRequiredSystemLibraries)
ENDIF(BUILD_AS_BUNDLE)

Expand All @@ -1153,6 +1138,7 @@ SET(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
#SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
SET(CPACK_PACKAGE_CONTACT "[email protected]")


set(CPACK_SOURCE_IGNORE_FILES
"\\\\.svn/"
"\\\\.settings/"
Expand Down Expand Up @@ -1557,7 +1543,11 @@ MESSAGE(STATUS " With RealSense = NO (librealsense not found)")
ENDIF()

IF(realsense2_FOUND)
IF(WIN32)
MESSAGE(STATUS " With RealSense2 = YES (License: Apache-2)")
ELSE()
MESSAGE(STATUS " With RealSense2 ${realsense2_VERSION} = YES (License: Apache-2)")
ENDIF()
ELSEIF(NOT WITH_REALSENSE2)
MESSAGE(STATUS " With RealSense2 = NO (WITH_REALSENSE2=OFF)")
ELSE()
Expand Down
Loading

0 comments on commit 89e3e10

Please sign in to comment.