This is an example setup of cmake with google test on CircleCI with Docker. Hopefully it'll help someone get set up with C++ and google test on CI service.
build/
is where code is built - like where executables are.
lib/
includes gtest-1.7.0.
Rest of code in root:
CMakeLists.txt
must be in each subdirectory of the projectmain.cpp
is just a driver file - the common place to run the normal applicationproject1.cpp
andproject1.h
have code for the class 'Project1'test_project1.cpp
has code to test Project1
CI files:
Dockerfile
has buid info to CentOS6 image. That image is used by CircleCIcircle.yml
is CircleCI config file. Contants is about building container and running test.
If you want to test it all out through the common gtest procedure, first delete build/ (if present). Then...
In the project root:
mkdir build
cd build
cmake ..
By now Makefiles should be created. Then, to build executables and do all that linking stuff,
make
To prepare all your tests, run this:
cmake -Dtest=ON ..
To run all tests easily,
make test
if you want run test on Docker image ( CentOS )
sudo docker pull yutakakinjyo/gtest-cmake-example:master
sudo docker run --rm=true yutakakinjyo/gtest-cmake-example:master /bin/sh -c 'cd build; make test'
$ cmake -P build.cmake
Then you can do ./myexecutable for the generated executable, e.g.:
./project1
and if you did cmake with test=ON:
./runUnitTests
cmake -Dtest=ON
turns on the variable 'test', which is specified in the root
CMakeLists.txt file. This is handy if you want to build in certain ways. Clear
description
here.