catkin: How to configure_file differently in develspace and installspace?

asked 2021-01-30 17:27:06 -0500

peci1 gravatar image

I've got a catkin package where I'd like to configure a C++ header file to contain a variable with an absolute path to a project directory. This file should then get installed (in installspace) or used from the generated location (in develspace). The path in the file needs to be used both by downstream packages and by targets during this package's build.

An example of such a generated file would be a like this:

#define SUBT_INSTALL_WORLD_DIR "${CMAKE_INSTALL_PREFIX}/share/subt_ign/worlds"

configured with:

configure_file (${PROJECT_SOURCE_DIR}/include/subt_ign/ ${PROJECT_BINARY_DIR}/include/subt_ign/Config.hh)

I don't think this is something uncommon, yet I haven't found a way to do this with catkin so that both develspace and installspace are correct. There is no CMake variable set by catkin that would tell the buildsystem whether this is a develspace or installspace build. I guess it might even get a bit difficult taking into account that people can call make install manually from the build directory, which happens after the CMake configuration phase.

There are some similar concepts - like the possibility to use @[if DEVELSPACE]@ in env hooks or CMake's $<BUILD_INTERFACE> and $<INSTALL_INTERFACE>. However, the generator expressions are only used when calling install(EXPORT), which isn't the case with Catkin if I'm not mistaken.

I've also found out that catkin_make_isolated and catkin build set CMAKE_INSTALL_PREFIX to develspace in case the project exports <build_type>cmake</build_type>. But that's not the case with my project, I want it to be a normal catkin project.

So, what other ways are there? I think using rospack to find the path during runtime might be the best bet here, but still, it isn't the same as burning the absolute path in during build.

Thanks for any ideas.

edit retag flag offensive close merge delete