0
$\begingroup$

Rosanswers logo

I am building an external library that will be linked in as part of a ros package, but is built outside of Catkin.

I'd like to use some of the ROS messages (e.g. ROS_INFO, ROS_DEBUG) inside this library for debugging.

I have manually modified the CMake to include_directories( /opt/ros/kinetic/include/) and the code works as I want.

I'd like to do something like:

find_package( roscpp )
if (ROSCPP_FOUND)
   include_directories(${ROSCPP_INCLUDE_DIRS})
...

Unfortunately, CMake can't find roscpp without all of the catkin magic.
I don't want to find_package(catkin) as it messes with the normal CMake build setup for the library.

One hack I can think of is to check the ROS_ROOT environment variable, and if it exists, make the include relative to that. But that is a hack that I'd prefer to avoid.

Is there a clean minimal setup that can discover the ROS include directory with pure CMake?


Originally posted by dcconner on ROS Answers with karma: 476 on 2016-07-06

Post score: 1

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

Your variable names just have the wrong case. You must use roscpp_FOUND and roscpp_INCLUDE_DIRS.


Originally posted by Dirk Thomas with karma: 16276 on 2016-07-06

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by dcconner on 2016-07-07:
Gah! Thanks. I thought the example I was following made the tags all upper case.

$\endgroup$
0
$\begingroup$

Rosanswers logo

You might want to look at: https://github.com/gerkey/ros1_external_use.git


Originally posted by William with karma: 17335 on 2016-07-06

This answer was NOT ACCEPTED on the original site

Post score: 3


Original comments

Comment by ReedHedges on 2019-06-03:
Great resource. If you're making a real ROS package, and will be defining new/custom messages, actionlib actions, services etc. then catkin might be your best bet, followed by CMake as described in this link. If you just need to use the roscpp lib, rosserial, predefined message types, etc. then it's possible to just call pkg-config from a Makefile (or similar) to get appropriate flags and other info, also as described in this link. You will need to identify which components provide which roscpp classes/symbols you are using, to pass the pkg-config names when calling pkg-config.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.