yaml-cpp
yaml-cpp copied to clipboard
Embedding of gtest/gmock in source tree
The current approach used by yaml-cpp is to embed gtest/gmock in test/gmock-1.7.0
. While this works fine for the most part, it doesn't work well when you're integrating it into a larger build which also includes its own gtest, e.g. a later version such as 1.8.0. It would be nice if this could be made optional. The headers and libraries can conflict.
As a suggestion, this is the approach I took in a different project: GTest.cmake. Here, we pass in a variable GTEST_SOURCE
which points to the location of the sources. If unset, we simply use find_package
and use an external version. If set, we use the internal version (or the version pointed to outside the source tree). An option could be added to yaml-cpp to do an equivalent action, e.g. build-gtest
or build-gmock
. It could even be defaulted based upon the result of find_package
.
Also worth noting: gtest 1.8 combines gmock and no longer enforces the requirement to "vendor" into a source tree. It's now locally installable again, with the proviso that it needs building with a compatible set of compiler options (so no different than most other libraries!).
Regards, Roger
I had a hell of a time trying to get gtest to play nice with other projects that also do the Bad Thing add_subdirectory(googletest)
. I spent more than a day fighting this without much luck.
I ended up just building and installing yaml-cpp. I should probably do the same for gtest, but that doesn't solve the issue that more than one repository is doing Bad Things.
In an ideal world, no project would do the embedding thing. gtest
made this difficult due to its draconian (and IMO unjustified) restrictions on installing. I've switched to using the system gtest or building it as a regular package in a super-build setup. For either case, being able to disable it in each leaf package is generally sufficient to fix things!
It looks like GTest does have some accommodation for this issue: https://github.com/google/googletest/blob/main/CMakeLists.txt#L32
I'll post a PR, I guess
Since I originally reported the issue nearly six years ago, googletest is now distributed in a directly usable form by most Linux distributions, homebrew, vcpkg etc. I and others did the work to have it properly packaged for all common platforms. So the need to "vendor" it is now greatly reduced. I've ceased to do so in all of my own projects.
Kind regards, Roger
Sadly, I'm still in an environment dealing with a lot of projects that do vendor it. I would hope the maintainers consider this worth accepting a fix for.