Ask Your Question
2

catkin export cmake definitions/variables to depending packages

asked 2014-09-10 01:36:23 -0500

Wolf gravatar image

Is there a way to set cmake variables in one package and export them to all depending packages?

For clarity:

If I set a cmake variable in one packages CMakeLists.txt like:

set( My_Var "Hello World" )

I can it now has the value in this package, I can e. g. echo it like

message( "My_Var = ${My_Var}" )

which will result in the output:

My_Var = Hello World

However, if I put the same output in another package (which depends on the previous one), the result is empty:

message( "My_Var = ${My_Var}" )

Resulting output:

My_Var =

Apparently, both packages have separate cmake namespaces. Now Is there a way to set a variable in one package, the mark it in some kind of way to be exported into depending packages and access its value in the depending packages?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2014-09-10 02:04:50 -0500

Wolf gravatar image

Found solution:

*##########################################################################

1 ) created a folder cmake in the "first package" and added a file pkg_config_extras.cmake into it. It contains:

cmake_minimum_required(VERSION 2.8.3)

set( My_Var "Hello World" )

*##########################################################################

2) to make My_Var viewable in the "first package" 's CMakeLists.txt I added:

include( cmake/pkg_config_extras.cmake )

----> now I can output it there with correct result:

message( "My_Var = ${My_Var}" )

----> Result:

My_Var = Hello World

*##########################################################################

3) to make My_Var viewable in the "second package" 's CMakeLists.txt ("second package" depends on the "first package") I needed to add in the "first package" 's CMakeLists.txt a CFG_EXTRAS when calling catkin_package:

catkin_package(
  INCLUDE_DIRS include                  # unchanged, whatever was there before
  LIBRARIES ${PROJECT_NAME}             # unchanged, whatever was there before
  CATKIN_DEPENDS roscpp                 # unchanged, whatever was there before
  DEPENDS OpenCV                        # unchanged, whatever was there before
  CFG_EXTRAS pkg_config_extras.cmake    # added this line !!!!
)

----> now I can also output it in the "second package" 's CmakeLists.txt with correct result:

message( "My_Var = ${My_Var}" )

----> Result:

My_Var = Hello World
edit flag offensive delete link more
1

answered 2014-09-10 02:00:47 -0500

BennyRe gravatar image

I never used it and I haven't tried tried it but there's a PARENT_SCOPE parameter for set. See the command reference.

Maybe this works. I'm not a cmake expert.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-09-10 01:36:23 -0500

Seen: 752 times

Last updated: Sep 10 '14