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

export gcc flags though catkin? CFG_EXTRAS?

asked 2014-06-18 12:51:51 -0500

Benny gravatar image

I have the gcc c++0x flag set for a few of my packages. All the packages that depend on these package also needs the c++0x flag if they must not throw warning when the header files are processed.

Is there a way for catkin to export the flags? I saw the CFG_EXTRAS option for catkin_package(), Do I set the CFG_EXTRAS? What does it stand for?

Thanking you, Benzun

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2014-06-18 14:22:13 -0500

Dirk Thomas gravatar image

You can pass multiple "CMake configuration extra" files via catkin_package(CFG_EXTRAS) to be included when downstream packages find your package:

catkin_package(
  CFG_EXTRAS ${PROJECT_NAME}-extras.cmake
)

An example for such a file would be cmake/${PROJECT_NAME}-extras.cmake:

#  for older versions of clang, libstdc++ is used by default and we need to explicitly request libc++ instead
if(APPLE)
  set(CMAKE_CXX_FLAGS "-std=c++0x -stdlib=libc++ ${CMAKE_CXX_FLAGS}")
else()
  set(CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}")
endif ()
edit flag offensive delete link more

Comments

I think the cmake file must be saved with the ".in" extension i.e. cmake/$PROJECT_NAME-extras.cmake.in. I couldn't get it to work with just .cmake

Jeremy Corbett gravatar image Jeremy Corbett  ( 2014-10-12 22:03:52 -0500 )edit

Using only the extension ".cmake" is supported. E.g. the following package does exactly that: https://github.com/ros/class_loader

Dirk Thomas gravatar image Dirk Thomas  ( 2014-10-13 12:18:28 -0500 )edit
0

answered 2014-06-18 13:04:39 -0500

gvdhoorn gravatar image

updated 2014-06-18 14:20:18 -0500

Not really an answer (I do think you can use CFG_EXTRAS for this btw), but afaik packages are not supposed to to use (or at least, I think it will not be releasable) anything but C++03 (from REP3, Rationale, C++):

We use the C++03 (ISO/IEC 14882:2003) standard [..]

Use of C++[0|1]x or tr1 features are only allowed if support for that feature is checked at compile time, and equivalent functionality exists without requiring C++[0|1]x code. A wholesale jump to C++[0|1]x will not happen until all commonly used OS platforms fully support it.

There have been numerous questions regarding updating REP3 though, see for instance Revisit REP3 with respect to C++11?.


Edit: CFG_EXTRAS expects to be passed a path to a file (see the catkin_package() doc). This file may contain any combination of valid CMake statements. You could for instance set(..) a MY_PKG_CXX_FLAGS or similar, which exports your specific flags. The contents of the file is automatically loaded whenever someone depends on your package (ie, via find_package(YOUR_PKG) or as a component in find_package(catkin REQUIRED COMPONENTS ..)).

All they would then have to do would be to append your flags to the CMAKE_CXX_FLAGS for instance.

PS: it might be worthwhile to check whether CMake or catkin has some best practices defined regarding naming of .._CXX_FLAGS and / or appending to the CMAKE_CXX_FLAGS variable(s).

edit flag offensive delete link more

Comments

The REP requires me to validate if C++01 is available on the computer and based on the availability adjust the code. Even though your answer degress, if I do find C++01 feature available I need to be able to pass the flag.

Benny gravatar image Benny  ( 2014-06-18 13:34:15 -0500 )edit

CFG_extras looks for a file and I dont have any documentation on how to use it.

Benny gravatar image Benny  ( 2014-06-18 14:11:57 -0500 )edit

I agree in principle, but I've noticed that a lot of the time having to implement things twice (once for C++01 and once without) incurs significant overhead, to the point where it can sometimes negate the benefits of using any advanced features in the first place.

gvdhoorn gravatar image gvdhoorn  ( 2014-06-18 14:12:34 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-06-18 12:51:51 -0500

Seen: 2,573 times

Last updated: Jun 18 '14