Pass includes and libs of MRPT as a dependency library

113 views Asked by At

Ive been using the library mrpt to wrap difodo algorithm aroung ROS. My system specifications are: Ubuntu 18.04 and Ive installed mrpt using the ppa from mrpt platform, currently Ive got version 1.9.9 of mrpt.

Ive been using the following in my cmake to use mrpt in the code Ive created like this:

find_package(MRPT REQUIRED poses gui vision)
# I got these variables
MRPT_LIBRARIES=mrpt::poses;mrpt::gui;mrpt::vision

MRPT_CONFIG=/usr/share/mrpt/mrpt-config.cmake
MRPT_CONSIDERED_CONFIGS=/usr/share/mrpt/mrpt-config.cmake
MRPT_CONSIDERED_VERSIONS=1.9.9
MRPT_DIR=/usr/share/mrpt
MRPT_FOUND=1
MRPT_LIBS=mrpt::poses;mrpt::gui;mrpt::vision
MRPT_VERSION=1.9.9
MRPT_VERSION_COUNT=3
MRPT_VERSION_MAJOR=1
MRPT_VERSION_MINOR=9
MRPT_VERSION_PATCH=9
MRPT_VERSION_TWEAK=0

.
.
.
target_link_libraries(MyexeA ${MRPT_LIBRARIES})
target_link_libraries(MyLibA ${MRPT_LIBRARIES})

This has work perfectly for MyExeA until now. Now I want to create a MyLibA and use this library on other project.

My goal is to include all MRPT dependencies (libs and include paths) automatically so when in projectB.CMakefile I do:

find_package(myprojectA REQUIRED)

MRPT is loaded automatically. That way the dependency tree is mrpt->projectA->ProjectB.

I want to avoid to have to find_package() MRPT again in projectB cmake.

What I've tried? Ive been using catkin_package() to add all dependencies and includes needed as follows:

catkin_package(
        INCLUDE_DIRS include
        LIBRARIES ${PROJECT_NAME} ${OpenCV_LIBS}
        CATKIN_DEPENDS roscpp cv_bridge image_transport rospy std_msgs
        DEPENDS OpenCV MRPT)

But when I do this, projectB cannot find includes from MRPT.

My next attempt was to use MRPT_LIBRARIES and MRPT_INCLUDE_DIRS variables to add in the catking package but MRPT doesnt seem to have an MRPT_INCLUDE_DIRS, so Ive got no way to know where the include dirs are.

How can I achieve this? Where is MRPT adding the INCLUDE_DIRS making CMAKE in projectA see the headers? Is there a better way besides catkin_package to pass the dependencies to the consumers of libA?

Regards.

1

There are 1 answers

0
Jose Luis Blanco On BEST ANSWER

You need to specify MRPT as a PUBLIC dependency of your project with:

target_link_libraries(MyexeA PUBLIC ${MRPT_LIBRARIES})

Also, add PUBLIC or PRIVATE for any other use of target_link_libraries().

And, as @Tsyvarev told you, you must export your project cmake targets for everything to work seamlessly. See this tutorial for example.