Integrating gtest with cygwin and cmake on Windows

I had need to use Google’s C++ unit testing frame work, gtest, in one of my projects.  I spent a lot of time Googling on what folders to include, where to put it, how to configure cmake, etc.  Here’s the guide so you don’t end up pulling out your hair like I did.

When you download the latest release of gtest, put the entire repo (unzipped of course) into your project folder.  I put it in a folder called includes.

Now the cmake file, here is what CLion started me out with:

And this is all I had to add to get everything to compile and the tests to run:

The important bits are adding the subdirectory where you put the gtest repo and linking the gtest and gtest_main libraries to your project.  If you are using G++, the flag is needed too.

That’s it!

Google’s Test Framework on GitHub

The repo on Lupe Code’s GitLab where I used this