Skip to content

Refactor RTABMapConfig.cmake to use targets #903

@matlabbe

Description

@matlabbe

The current config file is generating absolute paths in linked dependencies. Use the more modern approach from https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html to generate targets that will use relative dependencies, in particular when installing the package.

This would also fix the problem of having to manually add rtabmap's dependencies explicitly in a downstream projects. For example, those lines:

FIND_PACKAGE(OpenCV REQUIRED)
FIND_PACKAGE(PCL 1.7 REQUIRED)
# Find Qt5 first
FIND_PACKAGE(Qt5 COMPONENTS Widgets Core Gui Svg QUIET)
IF(NOT Qt5_FOUND)
FIND_PACKAGE(Qt4 COMPONENTS QtCore QtGui QtSvg)
ENDIF(NOT Qt5_FOUND)

would not be required anymore as find_package(RTABMap) will already include those dependencies (include directories and libraries). The target rtabmap would include everything to build, so the downstream project would need only this in its CMakeLists.txt file:

find_package(RTABMap REQUIRED)
add_executable(app main.cpp)
target_link_libraries(app rtabmap)

With main.cpp:

#include <rtabmap/corelib/Rtabmap.h>
#include <rtabmap/utilite/ULogger.h>

int main(int argc, char* argv[])
{
   UINFO("Launching rtabmap...");
   Rtabmap rtabmap;
   cv::Mat image;
   pcl::PointCloud<pcl::PointXYZ> cloud;
   ...
}

This would also fix the installation issues in introlab/rtabmap_ros#813

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions