How to use travis-ci to build modern c++ using modern cmake?

henne90gen

Is it possible to use travis-ci to build a c++ application/project that uses cmake, gcc-6 and g++-6?

henne90gen

Configuring travis to use the right compiler is a bit tricky. This is how it can be done:

First of all you need to set the distribution to trusty (the newest version of ubuntu that's supported by travis-ci) and require sudo.

dist: trusty
sudo: require

Next up we set the language and the compiler:

language: cpp
compiler: gcc

So far so good. Now we can go about setting up the apt install configuration:

addons:
  apt:
    sources:
      - ubuntu-toolchain-r-test
    packages:
      - gcc-6
      - g++-6
      - cmake

This adds the ppa for the newer version of our build tools and installs them. The next step is setting up links to the new gcc and g++. /usr/local/bin is being searched before /usr/bin, so that our newly installed version 6 compilers are going to be accessible with just gcc and g++. The beginning of your script: should look like this:

script:
    - sudo ln -s /usr/bin/gcc-6 /usr/local/bin/gcc
    - sudo ln -s /usr/bin/g++-6 /usr/local/bin/g++

Add the next line as well, if you want to verify the versions of those tools:

    - gcc -v && g++ -v && cmake --version

The versions that come back from these commands are as follows:

gcc: 6.2.0
g++: 6.2.0
cmake: 3.2.2

That's basically it. The complete .travis.yml looks like this:

dist: trusty
sudo: required
language:
  - cpp
compiler:
  - gcc
addons:
  apt:
    sources:
      - ubuntu-toolchain-r-test
    packages:
      - gcc-6
      - g++-6
      - cmake
script:
  # Link gcc-6 and g++-6 to their standard commands
  - ln -s /usr/bin/gcc-6 /usr/local/bin/gcc
  - ln -s /usr/bin/g++-6 /usr/local/bin/g++
  # Export CC and CXX to tell cmake which compiler to use
  - export CC=/usr/bin/gcc-6
  - export CXX=/usr/bin/g++-6
  # Check versions of gcc, g++ and cmake
  - gcc -v && g++ -v && cmake --version
  # Run your build commands next

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Download and build Lua with modern CMake

how can I replicate the "build and run" functionality of modern IDEs using CMake?

How to use allocators in modern C++

How to use Youtube Player with modern UI in Android using YoutubePlayerSupportFragment

How to transpose a 2d vector using modern c++?

Defining preprocessor in modern CMake

How to add more than one CUDA gencode using modern CMAKE (per target)?

How to use dotnet tool during Travis-CI build?

How to use SameText for AnsiStrings in modern Delphi?

Use several test files with Boost.Test and modern CMake

How to deploy a successful build using Travis CI and Scalr

How could this macro be rewritten in modern C++?

How to create/destroy objects in "modern" C++?

How to convert in modern C++ a double into a datetime

Travis CI, update CMake using the packages cache

Modern CMake transitive Dependency not found

Clarification about modern CMake structure

How to resolve C++ Error C2039 using Sciplot modern C++ library?

Modern GPUs: How "intelligent" are they?

Use of raw pointers in modern C++ post C++11

Travis-ci C language Build matrix

Does modern compilers use copy elision when using the builder pattern

NSIS can't use a macro when using Modern UI

How to build MacOSX executables on Travis CI?

How to build on travis-ci with gradle and cobertura

Is this use of raw pointers in modern C++ bad practice?

How to use modern CPU instructions in Delphi? (Java faster than Delphi?)

How to upgrade SSRS 2005 report project for use with modern SSRS versions?

How do I use the mousein event in modern browsers?