using different libc++ versions on travis for clang - c++

Travis uses Ubuntu Trusty and the default libc++ version there is svn199600.
However I would like to test with different (newer) versions as I already do with different clang versions.
My current .travis.yml looks as follows:
language: generic
dist: trusty
sudo: required
matrix:
include:
- env: CXX=g++-7 CC=gcc-7
addons:
apt:
packages:
- g++-7
sources: &sources
- ubuntu-toolchain-r-test
- llvm-toolchain-precise
- llvm-toolchain-precise-3.9
- llvm-toolchain-precise-3.8
- llvm-toolchain-precise-3.7
- llvm-toolchain-precise-3.6
- sourceline: 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-4.0 main'
key_url: 'http://apt.llvm.org/llvm-snapshot.gpg.key'
- env: CXX=g++-6 CC=gcc-6
addons:
apt:
packages:
- g++-6
sources: *sources
- env: CXX=g++-5 CC=gcc-5
addons:
apt:
packages:
- g++-5
sources: *sources
- env: CXX=g++-4.9 CC=gcc-4.9
addons:
apt:
packages:
- g++-4.9
sources: *sources
- env: CXX=clang++-4.0 CC=clang-4.0
addons:
apt:
packages:
- clang-4.0
- libc++-dev
sources: *sources
- env: CXX=clang++-3.9 CC=clang-3.9
addons:
apt:
packages:
- clang-3.9
- libc++-dev
sources: *sources
- env: CXX=clang++-3.8 CC=clang-3.8
addons:
apt:
packages:
- clang-3.8
- libc++-dev
sources: *sources
- env: CXX=clang++-3.7 CC=clang-3.7
addons:
apt:
packages:
- clang-3.7
- libc++-dev
sources: *sources
- env: CXX=clang++-3.6 CC=clang-3.6
addons:
apt:
packages:
- clang-3.6
- libc++-dev
sources: *sources
script:
- ./build_and_test.sh
before_install:
- ./before_install.sh
Replacing libc++-dev with libc++-dev-3.9 for example does not help (still uses old library version), even when adding the following line:
- sourceline: 'deb-src http://apt.llvm.org/trusty/ llvm-toolchain-trusty-3.9 main'
I also attempted to add the following to my before_install.sh without success (also still old library):
sudo apt-add-repository "deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.9 main"
sudo apt-get update
sudo apt-get install -y libc++-dev libc++-helpers libc++1 libc++abi-dev lldb-3.9
How is it done correctly without building from source?

It looks like it is not possible to do it without building from source. The range-v3 library uses a script doing exactly this.
I adjusted my travis.yml to use it too:
language: generic
dist: trusty
sudo: required
matrix:
include:
- os: linux
compiler: gcc
env: GCC_VERSION=7
- CC=gcc-7
- CXX=g++-7
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-7']
- os: linux
compiler: gcc
env: GCC_VERSION=6
- CC=gcc-6
- CXX=g++-6
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-6']
- os: linux
compiler: gcc
env: GCC_VERSION=5
- CC=gcc-5
- CXX=g++-5
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-5']
- os: linux
compiler: clang
env: CLANG_VERSION=5.0 LIBCXX=On
- CC=clang-5.0
- CXX=clang++-5.0
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-5.0']
packages: ['clang-5.0', 'g++-6']
- os: linux
compiler: clang
env: CLANG_VERSION=4.0 LIBCXX=On
- CC=clang-4.0
- CXX=clang++-4.0
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-4.0']
packages: ['clang-4.0', 'g++-6']
- os: linux
compiler: clang
env: CLANG_VERSION=3.9 LIBCXX=On
- CC=clang-3.9
- CXX=clang++-3.9
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-3.9']
packages: ['clang-3.9', 'g++-6']
- os: linux
compiler: clang
env: CLANG_VERSION=3.8 LIBCXX=On
- CC=clang-3.8
- CXX=clang++-3.8
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-3.8']
packages: ['clang-3.8', 'g++-6']
before_install:
- wget https://raw.githubusercontent.com/onqtam/doctest/master/doctest/doctest.h
- sudo mv ./doctest.h /usr/local/include/doctest.h
- |
if [ -n "$GCC_VERSION" ]; then
export CXX="g++-${GCC_VERSION}" CC="gcc-${GCC_VERSION}"
fi
if [ -n "$CLANG_VERSION" ]; then
export CXX="clang++-${CLANG_VERSION}" CC="clang-${CLANG_VERSION}"
fi
if [ "$LIBCXX" == "On" ]; then
sudo apt-get purge cmake
sudo apt-get install cmake3
cmake --version
sudo CXX="$CXX" CC="$CC"
sudo ./cmake/install_libcxx.sh
export CXXFLAGS="-stdlib=libc++"
fi
install:
- mkdir -p build && cd build
- cmake .. -DUNITTEST=ON
script:
- which $CXX
- $CXX --version
- cmake --build . --target unittest --config Release -- -j4

Related

Specifying compiler versions in travis for cmake builds

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

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.

CI for Qt app: build with different Qt versions

I use Travis-CI for continuous integration for my simple Qt app. My .travis.yml file looks like this (based on this gist):
language: cpp
before_install:
- sudo add-apt-repository --yes ppa:ubuntu-sdk-team/ppa
- sudo apt-get update -qq
- sudo apt-get install -qq g++ qt4-qmake libqt4-dev qt5-qmake qtbase5-dev
script:
- qmake -qt=qt4 -v
- qmake -qt=qt4
- make
- make -k check
- make clean
- qmake -qt=qt5 -v
- qmake -qt=qt5
- make
- make -k check
This configuration allows me to build my app (and run tests) with default Qt libraries in Ubuntu (Qt 4.8.1 and Qt 5.0.2).
Is there any way to build app with other Qt versions (4.7.x, 4.8.x, 5.1.x and so on)?
Inspired by AlexandreP answer and .travis.yml file of Twofold-Qt project with many thanks to Stephan Binner.
language: cpp
matrix:
include:
- os: linux
dist: trusty
sudo: required
compiler: gcc
env:
- QT_BASE=48
- os: linux
dist: trusty
sudo: required
compiler: gcc
env:
- QT_BASE=51
- os: linux
dist: trusty
sudo: required
compiler: gcc
env:
- QT_BASE=52
- os: linux
dist: trusty
sudo: required
compiler: gcc
env:
- QT_BASE=53
- os: linux
dist: trusty
sudo: required
compiler: gcc
env:
- QT_BASE=54
- os: linux
dist: trusty
sudo: required
compiler: gcc
env:
- QT_BASE=55
- os: osx
compiler: clang
env:
- QT_BASE=55
- os: linux
dist: trusty
sudo: required
compiler: gcc
env:
- QT_BASE=56
- os: linux
dist: trusty
sudo: required
compiler: gcc
env:
- QT_BASE=57
- os: osx
compiler: clang
env:
- QT_BASE=57
before_install:
- if [ "$QT_BASE" = "48" ]; then sudo add-apt-repository ppa:beineri/opt-qt487-trusty -y; fi
- if [ "$QT_BASE" = "51" ]; then sudo add-apt-repository ppa:beineri/opt-qt511-trusty -y; fi
- if [ "$QT_BASE" = "52" ]; then sudo add-apt-repository ppa:beineri/opt-qt521-trusty -y; fi
- if [ "$QT_BASE" = "53" ]; then sudo add-apt-repository ppa:beineri/opt-qt532-trusty -y; fi
- if [ "$QT_BASE" = "54" ]; then sudo add-apt-repository ppa:beineri/opt-qt542-trusty -y; fi
- if [[ "$QT_BASE" = "55" && "$TRAVIS_OS_NAME" = "linux" ]]; then sudo add-apt-repository ppa:beineri/opt-qt551-trusty -y; fi
- if [ "$QT_BASE" = "56" ]; then sudo add-apt-repository ppa:beineri/opt-qt562-trusty -y; fi
- if [[ "$QT_BASE" = "57" && "$TRAVIS_OS_NAME" = "linux" ]]; then sudo add-apt-repository ppa:beineri/opt-qt571-trusty -y; fi
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then
sudo apt-get update -qq;
else
brew update;
fi
install:
- if [ "$QT_BASE" = "48" ]; then sudo apt-get install -qq opt-qt4-qmake opt-qt4-dev-tools; source /opt/qt-4.8/bin/qt-4.8-env.sh; fi
- if [ "$QT_BASE" = "51" ]; then sudo apt-get install -qq qt51base; source /opt/qt51/bin/qt51-env.sh; fi
- if [ "$QT_BASE" = "52" ]; then sudo apt-get install -qq qt52base; source /opt/qt52/bin/qt52-env.sh; fi
- if [ "$QT_BASE" = "53" ]; then sudo apt-get install -qq qt53base; source /opt/qt53/bin/qt53-env.sh; fi
- if [ "$QT_BASE" = "54" ]; then sudo apt-get install -qq qt54base; source /opt/qt54/bin/qt54-env.sh; fi
- if [ "$QT_BASE" = "55" ]; then
if [ "$TRAVIS_OS_NAME" = "linux" ]; then
sudo apt-get install -qq qt55base; source /opt/qt55/bin/qt55-env.sh;
else
brew install qt55;
brew link --force qt55;
fi
fi
- if [ "$QT_BASE" = "56" ]; then sudo apt-get install -qq qt56base; source /opt/qt56/bin/qt56-env.sh; fi
- if [ "$QT_BASE" = "57" ]; then
if [ "$TRAVIS_OS_NAME" = "linux" ]; then
sudo apt-get install -qq qt57base; source /opt/qt57/bin/qt57-env.sh;
else
brew install qt5;
brew link --force qt5;
fi
fi
script:
- qmake -v
- qmake -r
- make
notifications:
email: false
With this .travis.yml you will get 10 separate build jobs - number of elements in matrix section. Each build job will install specified Qt version and use it for app building in Ubuntu with Qt 4.8 - 5.7 and OS X with Qt 5.5 and 5.7 (or latest version).
If you want to build your app for Windows, you can try AppVeyor CI service. Example config (Qt 5.3 - 5.7):
version: '{build}'
init:
- git config --global core.autocrlf input
environment:
matrix:
- QT5: C:\Qt\5.3\mingw482_32
MINGW: C:\Qt\Tools\mingw482_32
- QT5: C:\Qt\5.4\mingw491_32
MINGW: C:\Qt\Tools\mingw491_32
- QT5: C:\Qt\5.5\mingw492_32
MINGW: C:\Qt\Tools\mingw492_32
- QT5: C:\Qt\5.6\mingw49_32
MINGW: C:\Qt\Tools\mingw492_32
- QT5: C:\Qt\5.7\mingw53_32
MINGW: C:\Qt\Tools\mingw530_32
matrix:
fast_finish: true
before_build:
- set PATH=%MINGW%\bin;%QT5%\bin;%PATH%
build_script:
- qmake -v
- qmake -r
- mingw32-make
I use these configs in my project - qtcsv. See it for updates and build logs.
You can find more version of Qt by adding this beineri's ppa.
For example, version 5.4 can be added:
before_install:
- sudo add-apt-repository ppa:beineri/opt-qt541 -y
install:
- sudo apt-get install qt54base qt54websockets
script:
- source /opt/qt54/bin/qt54-env.sh