How to use travis-ci to create modern C ++ using modern cmake?

Is it possible to use travis-ci to create a C ++ application / project using cmake, gcc-6 and g ++ - 6?

+12
source share
4 answers

Configuring travis to use the correct compiler is a bit complicated. Here's how to do it:

First of all, you need to configure the distribution to the correct one (the latest version of ubuntu supported by travis-ci) and require sudo.

dist: trusty sudo: require 

Next, we install the language and compiler:

 language: cpp compiler: gcc 

So far so good. Now we can configure the apt install configuration:

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

This adds ppa for the new version of our build tools and installs them. The next step is to configure links to the new gcc and g ++. /usr/local/bin searches up to /usr/bin , so our newly installed version 6 compilers will only be available with 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++ 

Also add the following line if you want to check the versions of these tools:

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

The versions returned from these commands are as follows:

 gcc: 6.2.0 g++: 6.2.0 cmake: 3.2.2 

This is basically it. The full .travis.yml is as follows:

 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 
+17
source

I found some errors in @ henne90gen's answer (or maybe they just changed). In particular:

  • You do not need sudo .
  • You do not need to install CMake from apt. This will install the old version of CMake 2.8 from Trusty. Fortunately, the build image already comes with CMake 3.9.2 (for now).
  • gcc-7 not installed on /usr/local/bin and is already in PATH .

This should work:

 dist: trusty language: cpp addons: apt: sources: - ubuntu-toolchain-r-test packages: - gcc-7 - g++-7 script: - export CC=gcc-7 - export CXX=g++-7 - ... 

Here is a longer example that includes the modern version of Qt (with the QtSVG that I use) and works on OSX and Linux.

 os: - linux - osx language: cpp dist: trusty addons: apt: sources: - ubuntu-toolchain-r-test - sourceline: "ppa:beineri/opt-qt-5.10.1-trusty" packages: - gcc-7 - g++-7 - qt510-meta-minimal - qt510svg - qt510imageformats - qt510tools before_install: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; brew install qt5 cmake ; brew link --force qt ; fi script: - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export CC=gcc-7 ; export CXX=g++-7 ; source /opt/qt510/bin/qt510-env.sh ; fi - cmake --version - qmake --version - ... 
+5
source

Adding a semi-connected solution after a long struggle with this. Hope this helps someone else avoid the time that I spent on going through the travis.yml update cycle, committing, waiting for Travis ... repeat until it works.

I had a C extension in a Python project that started producing failed tests in Travis, but passed locally. In the end, I traced it to the old version of gcc in xenial. Here is the Travis YAML file that finally solved the problem for me:

 dist: xenial language: python before_install: - sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y - sudo apt-get update -q - sudo apt-get install -y gcc-7 - export CC=/usr/bin/gcc-7 python: - "3.6" - "3.7" install: - pip install -r requirements.txt - python setup.py build_ext --inplace script: - python run_tests.py 

Also, will anyone else find that they want to run the Travis build on a specific commit to find out exactly where the problem occurred?

0
source

Use dist: bionic . This should fit most cases.

0
source

Source: https://habr.com/ru/post/1263524/


All Articles