0
$\begingroup$

Rosanswers logo

I want to share a filepath variable between the CMakeLists of two packages.

When I set in the first CMakeLists a variable using the following ways:

set(varABC "x" CACHE STRING "Description")
set( ENV{varDEF} x )

It won't appear in the second CmakeLists the following way:

find_package(packageA REQUIRED)
message(STATUS "${varABC}")
message(STATUS "${varDEF}")

Anybody knows how to do that the right way?


Originally posted by Flautz on ROS Answers with karma: 3 on 2018-12-12

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Each package is a separate CMake project. For each a separate CMake invocation is being used. So variables set in one are not available in the other.

The ament_cmake function ament_package has an argument CONFIG_EXTRAS (see https://github.com/ament/ament_cmake/blob/2d65d41e047e203cd0531df9b0987d8aaea7d6ca/ament_cmake_core/cmake/core/ament_package.cmake#L24-L32). You can provide you own CMake file which will be included when other packages find your package with find_package().

You will find examples how to use the argument in various packages (e.g. in rclcpp).


Originally posted by Dirk Thomas with karma: 16276 on 2018-12-12

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by Flautz on 2018-12-12:
Thanks, that seems to be the right thing!

Comment by Dirk Thomas on 2018-12-12:
Please mark the answer as correct (using the checkmark below the voting) if it answers the question. It just helps others to find answered questions in the future. Thanks.

$\endgroup$

Your Answer

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