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

Specifying CMake options for external CMake project

asked 2019-04-30 12:49:52 -0600

wxm gravatar image

Hi! I'd like to use the following to wrap a CMake-native project in a catkin environment by exporting the build_type as cmake:

(Code preview on GitHub issue: https://github.com/ros/catkin/issues/... )

While this works great to build, it defaults all options as in the CMake project. In many cases, we'd like to set a few of those - e.g., not to build tests etc. (what we would usually do by cmake .. -DBUILD_TESTS=OFF). Is there a way to do this, or a convenient work-around?

Thanks, Wolfgang

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
0

answered 2019-04-30 13:17:25 -0600

Dirk Thomas gravatar image

If you build your workspace with colcon you can put a colcon.pkg file beside the manifest to specify custom cmake-args just for that package.

edit flag offensive delete link more

Comments

So you can specify this in the source of the package and you can customize the defaults for that package (compared to a non-colcon build just using cmake) when built with colcon, which is great. But is there a way to change the options per-package when building / configuring a workspace? I.e. having some options in one workspace, and another set in another workspace, without changing the package source, just by different colcon commands / workspace-wide config.

demmeln gravatar image demmeln  ( 2019-04-30 13:29:48 -0600 )edit

Wait, I think I misunderstood how the .meta files work. It should be possible with those (either with name or path).

demmeln gravatar image demmeln  ( 2019-04-30 13:36:38 -0600 )edit

The difference of a colcon.pkg file is that it can be co-located with the package in source - rather than .meta / .mixin files which are usually outside the workspace and might need to be referenced explicitly.

Dirk Thomas gravatar image Dirk Thomas  ( 2019-04-30 13:57:05 -0600 )edit
1

answered 2019-04-30 13:06:31 -0600

demmeln gravatar image

If you building your workspace with catkin_tools, you can specify cmake args (--cmake-args I believe), but the caveat is that they are passed to all packages.

Another approach that gives you more control is to wrap your plane cmake package into a catkin package, e.g. using ExternalProject. Here is an example: https://github.com/uzh-rpg/pangolin_c...

edit flag offensive delete link more

Comments

Thank you very much for the answer - I am currently using ExternalProject but wanted to see whether I can directly pass option on a per-package level in catkin (it's likely a feature request for catkin). My use case is exactly as yours - I am packaging a package as a catkin wrapper and use ExternalProject. the --cmake-args options sets it workspace-wide, which is not what I want, given that I intend to bloom-release the package where I do not have this liberty.

wxm gravatar image wxm  ( 2019-04-30 13:14:57 -0600 )edit

Doesn't bloom allow you to include "patch files" that can tweak the defaults of options in the CMakeLists.txt as needed?

demmeln gravatar image demmeln  ( 2019-04-30 13:19:08 -0600 )edit

There are two parts to catkin: the CMake functions provided (the build system part) and the scripts catkin_make(_isolated) which invokes CMake on a set of packages (the build tool part). This kind of functionality you are looking for is in the build tool part. catkin_tools is a separate package providing a better build tool (though it is not actively maintained). Another build tool is colcon which was developed for ROS 2 (and non-ROS projects, also works for ROS 1).

Dirk Thomas gravatar image Dirk Thomas  ( 2019-04-30 13:21:46 -0600 )edit

Good call! While this is an option for bloom, that wouldn't work out of the box for someone building the package in the workspace, I presume (unless I rebase the patch for the workspace repository)?

wxm gravatar image wxm  ( 2019-04-30 13:25:35 -0600 )edit

Wait, if you use ExternalProject, you can specify any options you want in the wrapper project, no? Or are you asking how to replace it and not have a wrapper project? How would you get the package.xml (or colcon.pkg) file in the package root?

demmeln gravatar image demmeln  ( 2019-04-30 13:32:33 -0600 )edit

@demmeln: Correct, I am currently using ExternalProject but due to some shortcomings with the generation of pkg-config files in catkin (and downstream may use pkg-config rather than find_package(catkin REQUIRED COMPONENTS xyz)), I need to manually export a CFG_EXTRAS to set the equivalent variables - which is error-prone. I have the chance to get the package.xml upstream-ed into the project so it would build fine in a workspace as a cmake-buildtype-project. However, some extra CMake options need to be set by the user and do not auto-configure - that's why I asked. With ExternalProject, I directly pass them in.

wxm gravatar image wxm  ( 2019-04-30 15:58:20 -0600 )edit

Makes sense. So I guess the answer is, its possible with colcon, e.g. with a colcon.pkg file (instead of package.xml) in the upstream repo, but as of now not with catkin_tools.

demmeln gravatar image demmeln  ( 2019-05-02 17:34:27 -0600 )edit
0

answered 2019-07-01 11:20:28 -0600

Levi-Armstrong gravatar image

It looks like the issue is per cmake documentation that options must be before the path to the source and from what I can tell catkin passes all arguments after providing source path. I assume they would need to add a --cmake-options and insert these before the source path so things are configured properly. The only way I have been able to get things to work when using options is performing a clean build then pass the option on first build or delete the CMake cache for the package prior to rebuilding.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2019-04-30 12:49:52 -0600

Seen: 888 times

Last updated: Jul 01 '19