yaml-cpp icon indicating copy to clipboard operation
yaml-cpp copied to clipboard

Embedding of gtest/gmock in source tree

Open rleigh-codelibre opened this issue 7 years ago • 6 comments

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

rleigh-codelibre avatar Apr 25 '17 16:04 rleigh-codelibre

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.

keith-bennett-gbg avatar Apr 25 '17 16:04 keith-bennett-gbg

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!

rleigh-codelibre avatar Apr 25 '17 17:04 rleigh-codelibre

It looks like GTest does have some accommodation for this issue: https://github.com/google/googletest/blob/main/CMakeLists.txt#L32

PhilMiller avatar Feb 07 '23 20:02 PhilMiller

I'll post a PR, I guess

PhilMiller avatar Feb 07 '23 20:02 PhilMiller

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

rleigh-codelibre avatar Feb 07 '23 21:02 rleigh-codelibre

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.

PhilMiller avatar Feb 07 '23 23:02 PhilMiller