MAVSDK icon indicating copy to clipboard operation
MAVSDK copied to clipboard

Structure Cmake for Cpp package managers

Open bazfp opened this issue 3 years ago • 8 comments

It would be useful to be able to use MAVSDK with cpp package managers (Hunter, Conan etc) for automatic dependency resolution. Instead of depending on a SUPERBUILD or local dependencies.

I've been implementing this library with hunter and have found success by doing the following:

  1. SUPERBUILD=OFF
  2. Remove git commands from Cmakelists.txt, such as getting version from git tags
  3. Don't use git submodules
  4. Remove Find modules provided by https://github.com/mavlink/MAVSDK/blob/main/src/cmake/Modules/
  5. Use common lib names when linking: JsonCpp::jsoncpp -> jsoncpp_lib tinyxml2::tinyxml2 -> tinyxml2

This won't work for mavsdk_server but it is a start. There is likely to be more changes to this to get it to work (for Hunter I have included Hunter_gate but obviously this differs for each manager :) )

bazfp avatar Mar 31 '21 17:03 bazfp

How did you update Findtinyxml2.cmake? Does it still work for the other cases?

JonasVautherin avatar Mar 31 '21 17:03 JonasVautherin

I removed lines 18-23.

It is unlikely to work in other cases - that why I have not submitted a PR.

bazfp avatar Mar 31 '21 17:03 bazfp

But why doesn't find_package(TINYXML2) work in the first place? Isn't the package manager (e.g. hunter) supposed to work with it? Like by setting some CMAKE_PREFIX_PATH or something?

We use pkgconfig as a fallback already...

JonasVautherin avatar Mar 31 '21 21:03 JonasVautherin

Yes you're correct. It was not working due to the aliased lib names in the provided Find cmake modules. I no longer use the provided src/cmake/Modules/Find* modules now and lean on the package manager for finding packages. I have had to rename the libs that were linked as they were incorrect.

Jsoncpp::jsoncpp -> jsoncpp_lib tinyxml2::tinyxml2 -> tinyxml2

bazfp avatar Apr 01 '21 11:04 bazfp

FYI, I believe it should be fixed for jsoncpp using https://github.com/mavlink/MAVSDK/pull/1395. It's not a release yet, so I don't really know how it goes with Hunter, but I think jsoncpp now has the behavior you expect.

JonasVautherin avatar May 05 '21 18:05 JonasVautherin

Aha, Good news :)

I will wait for fresh jsoncpp & tinyxml2 releases with the namespaced library names, and push them to hunter.

Once this is all done I will update the PR #1393, it should be a relatively light-touch hunter integration at that point :)

bazfp avatar May 14 '21 15:05 bazfp

@bazfp: Updated tinyxml2 here: https://github.com/mavlink/MAVSDK/pull/1436

JonasVautherin avatar May 17 '21 18:05 JonasVautherin

Progressing hunter to include MAVSDK as a lib, I have noticed the build fails due to missing submodules in sources.tar.gz. It does not have .git info and so it is impossible fetch submodules from this.

I think the solution here is to put the mavlink headers into hunter, and on HUNTER_ENABLED=ON use hunter instead of the submodules.

bazfp avatar Oct 29 '21 16:10 bazfp