Specifying compiler versions in travis for cmake builds - c++

The travis Building a C++ Project documentation shows how to specify gcc and clang compiler versions in build matrices. However, it does not show how to build projects with those compilers using cmake.
I amended the .travis.yml file here to specify gcc 9 and clang 8 as per the travis documentation, i.e.:
matrix:
include:
- compiler: gcc
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-9
env:
- MATRIX_EVAL="CC=gcc-9 && CXX=g++-9"
- compiler: clang
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-bionic-8
packages:
- clang-8
- libstdc++-8-dev
env:
- MATRIX_EVAL="CC=clang-8 && CXX=clang++-8"
before_install:
- eval "${MATRIX_EVAL}"
- pip install --user cpp-coveralls
...
script:
- mkdir _builds
- cd _builds
- cmake -DVIA_HTTPLIB_UNIT_TESTS=ON -DVIA_HTTPLIB_COVERAGE=ON ${CMAKE_OPTIONS} ..
- make
- ./via-httplib_test
But is caused build errors when running cmake, e.g.:
$ cmake -DVIA_HTTPLIB_UNIT_TESTS=ON -DVIA_HTTPLIB_COVERAGE=ON ${CMAKE_OPTIONS} ..
CMake Error at /usr/local/cmake-3.12.4/share/cmake-3.12/Modules/CMakeDetermineCCompiler.cmake:48 (message):
Could not find compiler set in environment variable CC:
gcc-9.
Call Stack (most recent call first):
CMakeLists.txt:9 (project)
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
See also "/home/travis/build/kenba/via-httplib/_builds/CMakeFiles/CMakeOutput.log".
The command "cmake -DVIA_HTTPLIB_UNIT_TESTS=ON -DVIA_HTTPLIB_COVERAGE=ON ${CMAKE_OPTIONS} .." exited with 1.
I tried fixing the errors by specifying CMAKE_C_COMPILER and CMAKE_CXX_COMPILER for cmake, but I could not get it to work.
However, it builds correctly with:
env:
- MATRIX_EVAL="CC=gcc && CXX=g++"
...
env:
- MATRIX_EVAL="CC=clang && CXX=clang++"
but builds with the default bionic gcc and clang compilers, i.e.: GCC 7.4.0 and Clang 7, not GCC 9 and Clang 8.
How to write a .travis.yml file so that cmake can find and use
the compiler versions specified in a matrix?

Perhaps it was a Travis issue? Simply adding the g++-9 package and changing the variable to MATRIX_EVAL="CC=gcc-9 && CXX=g++-9" results in a successful compilation of your project with GCC 9.3.0
This is a minimal example that I use for building my project:
language: cpp
matrix:
include:
- os: linux
addons:
apt:
sources:
- sourceline: 'ppa:ubuntu-toolchain-r/test'
packages:
- clang-8
env:
- MATRIX_EVAL="CC=clang-8 CXX=clang++-8"
- os: linux
addons:
apt:
sources:
- sourceline: 'ppa:ubuntu-toolchain-r/test'
packages:
- g++-9
env:
- MATRIX_EVAL="CC=gcc-9 CXX=g++-9"
before_install:
- eval "${MATRIX_EVAL}"
script:
- cmake .
- make

Related

How to use clang-10 or gcc-10 when building via Github Actions?

I'm writing a library in C++ that implements a few different coroutine primitives, and the library is targeted at the newly released C++20. As a result, it also makes use of things like concepts that were added to the language in C++20.
I want to use github actions to build the library, but builds are failing because ubuntu-latest uses GCC 9 and CLang 9, but my library requires at least GCC 10 or Clang 10 to build.
I attempted to configure the build action by setting -DCMAKE_CXX_COMPILER=g++-10, but the action fails in the Configure CMake phase because g++-10 can't be found on the system.
Is there any way specify github actions should use GCC 10 or Clang 10?
This is the most recent workflow file I tried running:
name: CMake
on: [push]
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow#configuring-a-build-matrix
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Create Build Environment
# Some projects don't allow in-source building, so create a separate build directory
# We'll use this as our working directory for all subsequent commands
run: cmake -E make_directory ${{runner.workspace}}/build
- name: Configure CMake
# Use a bash shell so we can use the same syntax for environment variable
# access regardless of the host operating system
shell: bash
working-directory: ${{runner.workspace}}/build
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_CXX_COMPILER=g++-10
- name: Build
working-directory: ${{runner.workspace}}/build
shell: bash
# Execute the build. You can specify a specific target with "--target <NAME>"
run: cmake --build . --config $BUILD_TYPE
- name: Test
working-directory: ${{runner.workspace}}/build
shell: bash
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C $BUILD_TYPE
And this is the point where it fails:
Run cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_CXX_COMPILER=g++-10
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:2 (project):
The CMAKE_CXX_COMPILER:
g++-10
is not a full path and was not found in the PATH.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "/home/runner/work/conduit/build/CMakeFiles/CMakeOutput.log".
See also "/home/runner/work/conduit/build/CMakeFiles/CMakeError.log".
##[error]Process completed with exit code 1.
As Some programmer dude mentioned, installing g++ from apt is the way to go (unless it's installed by default); adds a minute or two to the build. Then you can tell cmake which compiler it should use by passing CC and CXX variables during configure step:
- run: |
sudo apt update
sudo apt install gcc-10 g++-10
shell: bash
# ... #
- run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE
shell: bash
env:
CC: gcc-10
CXX: g++-10
Same solution applies when you want to use clang.
I am using both gcc-9 and clang-10 for C (only) project.
- name: Setup dependencies
if: startsWith(matrix.os, 'ubuntu')
run: |
sudo apt-get install -y gcc-9 llvm-10 clang-10
sudo update-alternatives \
--install /usr/bin/gcc gcc /usr/bin/gcc-9 100 \
--slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-9 \
--slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-9 \
--slave /usr/bin/gcov gcov /usr/bin/gcov-9
sudo update-alternatives \
--install /usr/bin/llvm-ar llvm-ar /usr/bin/llvm-ar-10 100 \
--slave /usr/bin/llvm-ranlib llvm-ranlib /usr/bin/llvm-ranlib-10 \
--slave /usr/bin/llvm-cov llvm-cov /usr/bin/llvm-cov-10
sudo update-alternatives \
--install /usr/bin/clang clang /usr/bin/clang-10 100
PS you need to update more alternatives for C++ project, just example.
You can see what's installed by visiting https://github.com/actions/virtual-environments.
If you're trying this in 2022, now ubuntu-latest has "GNU C++ 9.3.0, 10.3.0". g++ is linked to version 9, but g++-10 is available on the PATH without any extra installation steps.

Travis CI C++ Build succeed but travis exited with 1 and doesn't passes the test

I am trying to integrate my project with Travis CI, and when i build it everything seems to be ok, but the built is still failing and I get the message
Done. Your build exited with 1. but the CMake build give me message The command "cmake --build . -- -j2" exited with 0.
Here is my outupt of the build in travis-ci :
https://travis-ci.org/stelro/Fission-Engine
Here is the CMakeList.txt of the project:
https://github.com/stelro/Fission-Engine/blob/EntityComponentSystem/CMakeLists.txt
And here is the travis.yml:
https://github.com/stelro/Fission-Engine/blob/EntityComponentSystem/.travis.yml
Can someone help me and explaine me why I cannot pass the travis-ci build?
You are trying to install gcc-6 and set up links manually. Operations such as
ln -s /usr/bin/gcc-6 /usr/local/bin/gcc
require sudo which is disabled in your .travis.yml file. The better approach would be to specify gcc-6 as part of your build matrix:
matrix:
include:
# g++ builds
- os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-6
env:
- COMPILER="g++-6"

Travis CI seems to be reading from the wrong stdlib

I'm just getting started with using travis-CI, so I apologize if this is a silly or obvious question.
Following the instructions here:
I wrote the following travis.yml
language: cpp
dist: trusty
matrix:
include:
- os: linux
compiler: gcc
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-7
env:
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7"
- os: linux
compiler: clang
addons:
apt:
sources:
- llvm-toolchain-trusty-5.0
packages:
- clang-5.0
env:
- MATRIX_EVAL="CC=clang-5.0 && CXX=clang++-5.0"
before_install:
- eval "${MATRIX_EVAL}"
script:
- mkdir build
- cd build
- cmake -DCMAKE_VERBOSE_MAKEFILE=ON ..
- cmake --build .
- ctest
Which causes the following error in the clang build:
/home/travis/build/path_to_project/./include/abulafia/support/type_traits.h:20:12:
error: no member named 'decay_t' in namespace 'std'; did you mean
'decay'?
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/type_traits:1725:11:
note: 'decay' declared here
When compiling with the following command:
cd /home/travis/build/path_to_project/build/tests/char_set && /usr/bin/clang++-5.0 -Wall -pedantic -Wextra -std=c++17 -I/home/travis/build/path_to_project/./include -I/home/travis/build/path_to_project/googletest/googletest/include -o CMakeFiles/char_set_tests.dir/test_any.cpp.o -c
Which tells me it's loading gcc's libraries. Is there something I'm not understanding right here?
Thanks!
Yes, this is a well-known issue with the travis-ci build environment. It is compiling and linking against the default ubuntu-trusty libstdc++, which is the gcc 4-series stdlib and not even C++11 conforming.
See an issue I opened a long time ago.
If you need a C++14 libstdc++ with travis-ci, you should use docker and make a more recent ubuntu image. That's the best workaround AFAIK.
This can be fixed by installing g++7 alongside clang, to upgrade the standard library. The relevant matrix entry becomes:
matrix:
include:
- os: linux
addons:
apt:
sources:
- llvm-toolchain-trusty-5.0
- ubuntu-toolchain-r-test
packages:
- clang-5.0
- g++-7
env: MATRIX_EVAL="CC=clang-5.0 && CXX=clang++-5.0"
Replacing this into the OP's yaml should do the trick. Note: compiler: clang was in excess – its effects get overridden by the eval "${MATRIX_EVAL}" trick.

Travis-Ci Install and run CxxTest

I am trying to add Travis-Ci support for my open source project hosted on Github
Problem appears when CMake tries to find CxxTest. Travis-Ci runs on old Ubuntu version, in which CxxTest is not trusted. I achieved some results. At this state CxxTest installs fine, but CMake is unable to find cxxtestgen.
Question: How do I correctly install and use CxxTest in Travis-Ci ?
Build log on Travis
Travis.yml
language: cpp
compiler:
- gcc
before_install:
- lsb_release -c
- lsb_release -r
- sudo apt-add-repository 'deb http://archive.ubuntu.com/ubuntu vivid main universe multiverse restricted'
- sudo apt-add-repository 'deb http://archive.ubuntu.com/ubuntu trusty main universe multiverse restricted'
- sudo apt-key update
- sudo apt-get -y update
install:
- sudo apt-get --no-install-recommends -y install cxxtest;
- sudo find / -type f -name "cxxtestgen*"
- sudo ln /usr/share/cxxtest/cxxtest/cxxtestgen.py /usr/bin/cxxtestgen.py
- sudo find / -type f -name "cxxtestgen*"
- echo $PATH
before_script:
- cmake .
script: make
CMake log
$ cmake .
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/g++
-- Check for working CXX compiler: /usr/bin/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:91 (MESSAGE):
Could NOT find CxxTest (missing: CXXTEST_PERL_TESTGEN_EXECUTABLE)
Call Stack (most recent call first):
/usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:252 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-2.8/Modules/FindCxxTest.cmake:179 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
test/CMakeLists.txt:5 (find_package)
-- Configuring incomplete, errors occurred!
The command "cmake ." failed and exited with 1 during .
Your build has been stopped.
I found answer by myself.
language: cpp
compiler:
- gcc
cache:
apt: true
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- george-edison55/cmake-3.x
packages:
- gcc-6
- g++-6
- libboost-dev
- gcc-multilib
- gcc-6-multilib
- g++-multilib
- g++-6-multilib
- libc6-dev-i386
- libc6-i386
- cxxtest
- cmake
before_install:
- echo `getconf _NPROCESSORS_ONLN`
- lsb_release -c
- lsb_release -r
install:
- if [ "$CXX" = "g++" ]; then export CXX="g++-6" CC="gcc-6"; fi
before_script:
- cmake --version
- cmake .
script:
- make -j$((2 * `getconf _NPROCESSORS_ONLN`))
sudo: false
dist: trusty

Travis fails first build in matrix

I have started building my project on travis and, after managing to build with one compiler, I decided to cover more and use matrix builds to build with a variety of compilers on Linux. I have managed to get a configuration that builds successfully for all entries except the first one. The exact error I get is:
$ sudo -E apt-get -yq --no-install-suggests --no-install-recommends --force-yes install g++-5 libncurses5-dev
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package g++-5
E: Couldn't find any package by regex 'g++-5'
apt-get.diagnostics
apt-get install failed
My travis configuration looks like:
sudo: false
language: generic
matrix:
include:
- os: linux
env: COMPILER_NAME=g++ CXX=g++-5 CC=gcc-5
addons:
apt:
source: &sources
- llvm-toolchain-precise-3.8
- llvm-toolchain-precise-3.7
- llvm-toolchain-precise-3.6
- ubuntu-toolchain-r-test
packages:
- g++-5
- libncurses5-dev
- os: linux
env: COMPILER_NAME=clang++ CXX=clang++-3.8 CC=clang-3.8
addons:
apt:
sources: *sources
packages:
- clang-3.8
- libncurses5-dev
- os: linux
env: COMPILER_NAME=clang CXX=clang++-3.7 CC=clang-3.7
addons:
apt:
sources: *sources
packages:
- clang-3.7
- libncurses5-dev
- os: linux
env: COMPILER_NAME=clang CXX=clang++-3.6 CC=clang-3.6
addons:
apt:
sources: *sources
packages:
- clang-3.6
- libncurses5-dev
before_script:
- mkdir -p build
- cd build
script:
- cmake -DCMAKE_BUILD_TYPE=DEBUG .. && make && make runtests
At this point I feel like I am missing something obvious. I cannot find any solution to this problem (or simply don't know how to search for it effectively).
I feel I should mention that if I swap the gcc section with one of the clang sections that the clang section will fail and the gcc section will pass.
If I can provide anymore useful information then let me know! Thanks in advance for your help.
Simply misspelled sources in the first entry. Corrected that and removed the back referencing and everything is working.