ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

find_package catkin several times

asked 2018-11-14 04:38:00 -0500

mcamurri gravatar image

Hi all, let's say I have a catkin package which builds several executables.

Each one of these executables depends on a different set of catkin packages (i.e. catkin CMake components).

How can I link properly these executables? Is it ok to call find_package(catkin REQUIRED COMPONENTS ...) several times?

E.g.,

cmake_minimum_required(VERSION 2.8.3)
project(myproject)
find_package(catkin REQUIRED COMPONENTS roscpp sensor_msgs)
add_executable(myexec1 myexec1.cpp)
target_link_libraries(myexec1 ${catkin_LIBRARIES})
find_package(catkin REQUIRED COMPONENTS roscpp std_msgs)
add_executable(myexec2 myexec2.cpp)
target_link_libraries(myexec2 ${catkin_LIBRARIES})

how about the include_directories statements?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-11-14 05:06:09 -0500

gvdhoorn gravatar image

updated 2018-11-14 05:09:09 -0500

How can I link properly these executables? Is it ok to call find_package(catkin REQUIRED COMPONENTS ...) several times?

No, that won't work (due to caching, CMake may not actually even call find_package() again).

A work-around could be to not use find_package(catkin .. COMPONENTS ..), but to find_package(..) each of your dependencies separately (so find_package(sensor_msgs REQUIRED) and find_package(std_msgs REQUIRED)) and then manually add the results of those calls to the include and link paths of the respective binaries.

how about the include_directories statements?

CMake supports per target properties, such as include and link paths (with either set_target_properties(..) or target_include_directories(..)). You could use those.


But an observation: if the executables are really so different that they don't have (m)any shared dependencies, I would ask myself whether these executables should be hosted by the same package.

Perhaps they should be in a package of their own.

edit flag offensive delete link more

Comments

Note: your question is more a CMake question than a ROS/Catkin one. Even without any ROS involved you would/could run into the same issues (and your question about per-executable include_directories(..) reinforces this).

gvdhoorn gravatar image gvdhoorn  ( 2018-11-14 05:07:05 -0500 )edit

Yes, but since of the unique feature of catkin seeing the other packages as components of itself (to avoid per-package find_package statements) I ran into this question. In a plain CMake project I would find all the libraries I need and then add only the generated variables I need per executable

mcamurri gravatar image mcamurri  ( 2018-11-14 07:53:28 -0500 )edit

To reply to the original observation about splitting the code in multiple packages, I didn't mention that 1) this is no my code 2) I oversimplified the problem to the bare minimum. There are multiple nested CMake subprojects into this package. It is a complex cmake project converted to catkin.

mcamurri gravatar image mcamurri  ( 2018-11-14 07:55:58 -0500 )edit

Yes, but since of the unique feature of catkin seeing the other packages as components of itself

as you already comment: this is just convenience. You don't need to use that. A simple find_package(catkin REQUIRED) with the rest in their own find_package(..) is also fine and will work ok.

gvdhoorn gravatar image gvdhoorn  ( 2018-11-14 07:56:21 -0500 )edit

Ok then I will use the catkin components only for the shared resources among all binaries and individual ones for the others. Thanks.

mcamurri gravatar image mcamurri  ( 2018-11-14 11:09:53 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2018-11-14 04:38:00 -0500

Seen: 456 times

Last updated: Nov 14 '18