Example of a gtest and cmake set up for C++ on Travis-CI.

Overview

Build Statuscodecov

What is this?

This is an example setup of Travis-CI with cmake and google test. I finally got all three working together nicely with the help of dmonopoly's cmake and gtest example. Hopefully it'll help someone get set up with cmake and google test on travis-ci.

Where are things?

build/ is where code is built - like where executables are.
ext/ includes googletest framework (git submodule) inlcude/ is where the header files are located (here: project1.h) src/ is where the source files are located (here: project1.cpp, main.cpp) test/ is where the test source files are located (here: test_project1.cpp) Rest of code in root:
-CMakeLists.txt must be in each subdirectory of the project

What do I do?

Use it on Travis-CI:

Please look at the travis.yml file to see the setup of travis. As the gtest library is located within your project. The procedure on Travis is quite simple. Note that I used a more recent version of cmake as provided in the ubuntu precise repositories. This is needed for the relatively recent command REMOVE_ITEM to exclude the main.cpp from the source file list as I am lazy and did not want to write out the files by name.

Use it locally:

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 -DBUILD_TESTS=ON ..

To run all tests easily,

make test

Note: cmake -DBUILD_TESTS=ON turns on the variable 'BUILD_TESTS', which is specified in the root CMakeLists.txt file. This is handy if you want to build in certain ways. Clear description here.

Run executables

Then you can do ./myexecutable for the generated executable, e.g.:

./project1

and if you did cmake with BUILD_TESTS=ON:

./runUnitTests

Acknowledgement and further details

This repository is based on the works of David Y. Zhang in this repository. He spent a lot of time figuring out all the details for cmake and gtest. Please refer to his repository README for more detail on his approach.

You might also like...
CMake checks cache helper modules – for fast CI CMake builds!

cmake-checks-cache Cross platform CMake projects do platform introspection by the means of "Check" macros. Have a look at CMake's How To Write Platfor

 cmake-font-lock - Advanced, type aware, highlight support for CMake
cmake-font-lock - Advanced, type aware, highlight support for CMake

cmake-font-lock - Advanced, type aware, highlight support for CMake

cmake-avr - a cmake toolchain for AVR projects

cmake-avr - a cmake toolchain for AVR projects Testing the example provided The toolchain was created and tested within the following environment: Lin

Make CMake less painful when trying to write Modern Flexible CMake
Make CMake less painful when trying to write Modern Flexible CMake

Izzy's eXtension Modules IXM is a CMake library for writing Modern flexible CMake. This means: Reducing the amount of CMake written Selecting reasonab

[CMake] [BSD-2] CMake module to find ICU

FindICU.cmake A CMake module to find International Components for Unicode (ICU) Library Note that CMake, since its version 3.7.0, includes a FindICU m

A program that automatically generates CMake and Meson configuration files for your Vala project

Autovala is a program and a library designed to help in the creation of projects with Vala and CMake. It also has support for Genie.

A template C++ repository, using CMake and Catch

C++ Project Template This is a template project for C++. It uses CMake to build and Catch for unit tests. It is integrated with Travis CI, and builds

CMake BASIS makes it easy to create sharable software and libraries that work together

CMake BASIS makes it easy to create sharable software and libraries that work together. This is accomplished by combining and documenting some of the best practices and utilities available. This project supplies a fully integrated suite of functionality to make the whole process seamless!

A simple CMake utility for building and deploying Qt based applications on Android without QtCreator

Qt Android CMake utility What it is When using Qt for Android development, QMake & QtCreator is the only sane option for compiling and deploying. But

Owner
Gunnar
Gunnar
Example library that shows best practices and proper usage of CMake by using targets

Modern CMake Sample Sample project that shows proper modern CMake usage on a dummy library and an executable that uses it. Accompanying code to my blo

Pablo Arias 601 Dec 29, 2022
This tries to be a minimal cmake example, that covers sources resources dependencies and packaging.

Minimal CMake Example This project tries to be a minimal cmake example. It covers sources, resources, dependencies and packaging. I created this proje

Arne Döring 158 Dec 25, 2022
Installation example for a C++ project (Windows) with Cmake.

CMakeInstallExample Installation example for a C++ project (Windows) with Cmake. Contents This project demonstrates how to use cmake with cpack to gen

Paul T 30 Jan 3, 2023
Example project which demonstrates various CMake features.

CMake example Example project which demonstrates various CMake features. CDash testing dashboard (probably empty but you can submit your test result t

Radovan Bast 142 Nov 4, 2022
Tutorial/Example to deal with modern cmake.

modern_cmake Tutorial/Example to deal with modern cmake. This tutorial assume that you already know how to write a CMakeLists.txt Introduction This re

Marc Schweitzer 24 Nov 14, 2022
A set of cmake modules to assist in building code

CMake 3 Tools Warning: These tools are being replaced by the Modern CMake. Some of the tools are still being maintained for now, but new projects shou

null 201 Dec 21, 2022
CMake scripts for painless usage of SuiteSparse+METIS from Visual Studio and the rest of Windows/Linux/OSX IDEs supported by CMake

CMake scripts for painless usage of Tim Davis' SuiteSparse (CHOLMOD,UMFPACK,AMD,LDL,SPQR,...) and METIS from Visual Studio and the rest of Windows/Lin

Jose Luis Blanco-Claraco 395 Dec 24, 2022
CMake module to enable code coverage easily and generate coverage reports with CMake targets.

CMake-codecov CMake module to enable code coverage easily and generate coverage reports with CMake targets. Include into your project To use Findcodec

HPC 82 Nov 30, 2022
unmaintained - CMake module to activate certain C++ standard, feature checks and appropriate automated workarounds - basically an improved version of cmake-compile-features

Compatibility This library provides an advanced target_compile_features() and write_compiler_detection_header(). The problem with those is that they a

Jonathan Müller 74 Dec 26, 2022
📦 CMake's missing package manager. A small CMake script for setup-free, cross-platform, reproducible dependency management.

Setup-free CMake dependency management CPM.cmake is a CMake script that adds dependency management capabilities to CMake. It's built as a thin wrapper

CPM.cmake 1.6k Jan 9, 2023