This is a quick recipe for setting up CMake to use googletest in your projects.
First, make a tests
folder in the root of your project. Then, add
add_subdirectory(tests)
to your CMakeLists.txt
, after you’ve finished adding
the libraries in your project. Note that the way I’ve written this probably
requires CMake 3.4+.
GTest Submodule
Note: There is a better way to do this described here.
If you’ve ever tried apt-get
or brew
to try to install gtest, you are
probably familiar with the fact that gtest is not “recommend” for global install
on your system. As an alternative, the recommendation is that you make it part
of your project. The process for making gtest part of your project, however, is
not well documented, at least for modern git projects. What follows is the
procedure I used to do so.