Unit testing with gtest and cmake

After coding two years for Google, I got used to unit tests. Fortunately, part of the google testing framework is open source, it is called gtest. Using gtest is great, but it is usually not installed on the machine on which I want to compile my stuff. One option to address this problem would be to copy gtest sources in all my projects. That is not very satisfying.

I came up with another solution. Since I’m using cmake anyway, I wrote cmake files that would download sources and compile gtest at project compilation time. This solution avoids code duplication and limits system dependency to subversion which is rather common and easy to install on most development platforms.

If you like the simplicity of this approach, have a look at it and let me know if it works for you. Your pull requests on github are welcome if there is something wrong.

2 thoughts on “Unit testing with gtest and cmake

    1. Julien Pilet Post author

      You could download sources with “apt-get source”. I would not recommend it, because you do not control the version you’ll get. Using “apt-get install” is not a good idea: we do not want our build system to modify the compilation host. It probably does not have the rights, any way. “apt-get” is not portable enough in my opinion.

      Regarding maven, I have no idea. It seems that google finds plenty of things when searching for “cmake maven”…

Comments are closed.