Is it a good idea to keep googletest
source code (say googletest-release-1.8.1.tar.gz
) as a part of a C++ project and build it every time the test
target is invoked?
My Linux distribution has both gtest
and gmock
but not all distributions have them. Moreover, nowadays both gtest
and gmock
are under single repo umberella https://github.com/google/googletest and therefore I'm not sure how gtest
and gmock
will look like in the future. Having googletest
source code as a part of a project would probably solve my concerns. But I'm not sure whether it is inline with the C++ best practices. I could not find any recommended ways doing that in Linux.
Building googletest as a prerequisite of your test target is common practice. For CMake-managed projects, Googletest documents how to incorporate in an existing CMake project. For autotools managed projects, How can I use Google Test with my project that builds via autotools? has a well-regarded solution on SO.
Building googletest as a prerequisite of a project test suite ensures that the googletest code with which a downstream user of your project builds and runs your tests is the same code that you built and ran upstream. It ensures that googletest is built with the same compilation and linkage options as the code under test.
These advantages come at an acceptable cost because Googletest is a cheap build-target whose only dependencies are the C++ toolchain and pthreads (and even pthreads is optional).