Ask Your Question
3

Can catkin/cmake detect the version of a dependency?

asked 2013-11-14 16:05:05 -0500

The idea would be to pass dependency version information through as a flag and conditionally compile different code paths.

The specific scenario is having packages which depend on a package which I'm in the process of pushing several upstream changes to. In my local workspace, I'd like to build the package against my version of the dependency, but still have it build correctly on the buildfarm against the dependency's upstream (and then ideally switch over to the new code path when upstream merges my changes).

A perhaps better alternative would be using SFINAE tricks to detect if the specific methods I want to take advantage of are present in the class.

Is there an official recommendation for this type of situation?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2013-11-14 19:52:17 -0500

gvdhoorn gravatar image

updated 2013-11-14 20:13:14 -0500

CMake itself does support specifying versions of packages (see cmake.html#find_package), but only if the FindX.cmake script implements it. AFAIK many of the find scripts provided with the binary CMake distribution do.

I may be wrong, but Catkin does not seem to (currently) expose this in its catkin_package(..) macro AFAICT (see groovy-devel/cmake/catkin_package.cmake). There is some version checking going on in groovy-devel/cmake/catkin_package.cmake around line 188, but I can't tell from the source how that should work. See edit.

As for detecting support for features vs relying on version numbers: that approach would seem superiour, and is the one that's been advocated by the javascript / browser-based application developer community for a long time now. Plain CMake may be able to help you with this, see cmake.html#CheckFunctionExists.


Edit: according to REP-127, it is possible to specificy versioned dependencies (from the example in that REP):

<build_depend version_gte="1.1" version_lt="2.0">genmsg</build_depend>

I assume this information is then passed to the version checking in groovy-devel/cmake/catkin_package.cmake.

edit flag offensive delete link more

Comments

Yes, have used build_depend version specification, but it's not a great fit if you're trying to target multiple versions of a dependency with slightly different code.

mikepurvis gravatar imagemikepurvis ( 2013-11-15 00:14:44 -0500 )edit

Looks like CheckFunctionExists would be great, but it only works with bare C functions, not class methods or things in namespaces. However, it is possible to roll ones own using the similar check_cxx_source_compiles macro.

mikepurvis gravatar imagemikepurvis ( 2013-11-15 00:16:08 -0500 )edit
mikepurvis gravatar imagemikepurvis ( 2013-11-15 00:16:34 -0500 )edit

@mikepurvis: right, I didn't take into account that CheckFunctionExists only works for plain C. As you say, it shouldn't be too hard to create something like a CheckFunctionExistsCXX() or similar. re: versioned depends: yes, that does seem to be a usecase not covered by REP-127.

gvdhoorn gravatar imagegvdhoorn ( 2013-11-15 03:43:40 -0500 )edit

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: 2013-11-14 16:05:05 -0500

Seen: 446 times

Last updated: Nov 14 '13