MAVSDK
MAVSDK copied to clipboard
Structure Cmake for Cpp package managers
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:
-
SUPERBUILD=OFF
- Remove git commands from Cmakelists.txt, such as getting version from git tags
- Don't use git submodules
- Remove Find modules provided by https://github.com/mavlink/MAVSDK/blob/main/src/cmake/Modules/
- 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 :) )
How did you update Findtinyxml2.cmake
? Does it still work for the other cases?
I removed lines 18-23.
It is unlikely to work in other cases - that why I have not submitted a PR.
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...
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
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.
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: Updated tinyxml2 here: https://github.com/mavlink/MAVSDK/pull/1436
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.