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

catkin export definitions

asked 2014-01-28 10:42:01 -0500

brice rebsamen gravatar image

packages that use PCL need to add those 2 lines in the CMakeLists:

add_definitions(${PCL_DEFINITIONS})
link_directories(${PCL_LIBRARY_DIRS})

Is there an option to pass those flags and apply them automatically to all packages that use PCL indirectly, by depending on a package that uses PCL?

e.g. let's a package A that uses PCL and so it has the 2 lines above in its CMakeLists, and a package B that uses package A, but does not use PCL directly. It's CMakeLists thus does not include those 2 lines.

I does not seem practical to request a package developer to check all the packages depended upon and check what flags they require... So I bet there is a solution...

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2014-01-28 11:52:07 -0500

brice rebsamen gravatar image

updated 2015-07-26 18:35:13 -0500

Based on dirk-thomas' answer, here is the complete solution for reference:

1- I created A/cmake/A-extras.cmake.in with the following content:

# force automatic escaping of preprocessor definitions
cmake_policy(PUSH)
cmake_policy(SET CMP0005 NEW)

add_definitions(@PCL_DEFINITIONS@)
link_directories(@PCL_LIBRARY_DIRS@)

cmake_policy(POP)

2- I modified A's CMakeLists file as follow:

2.1- I added

CFG_EXTRAS A-extras.cmake

to the catkin_package() macro

2.2- I added

include(${CATKIN_DEVEL_PREFIX}/share/${PROJECT_NAME}/cmake/A-extras.cmake)

to A's CMakeLists.txt so that the definitions are used to build A itself

edit flag offensive delete link more

Comments

The last bit (2.2) should not be necessary: the cmake snippets exported in catkin_package(.. CFG_EXTRAS ..) are automatically included byt the dependent package. Unless of course you are including A-extras.cmake in A itself as well.

gvdhoorn gravatar image gvdhoorn  ( 2014-01-28 19:24:18 -0500 )edit
2

answered 2014-01-28 11:03:32 -0500

Dirk Thomas gravatar image

Your package can create a CMake extra file. That file is registered with catkin_package(CFG_EXTRAS ...) and will be included every time your package is find_packaged() by others.

As an example you can look at: https://github.com/ros/ros_comm/blob/hydro-devel/tools/rosconsole/CMakeLists.txt#L47 and https://github.com/ros/ros_comm/blob/hydro-devel/tools/rosconsole/cmake/rosconsole-extras.cmake.in

May be the API doc will also help what you can actually pass as an argument and what kind of templates you can use: http://docs.ros.org/api/catkin/html/dev_guide/generated_cmake_api.html#catkin-package

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-01-28 10:42:01 -0500

Seen: 1,184 times

Last updated: Jul 26 '15