CI for Qt app: build with different Qt versions - c++

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

Related

using different libc++ versions on travis for clang

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

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.

PX4/Firmware make error

Question: When I run make px4fmu-v2_default, I get this:
rootroot:~/Firmware$ make px4fmu-v2_default
Makefile:44: Not a valid CMake version or CMake not installed.
Makefile:45: On Ubuntu, install or upgrade via:
Makefile:46:
Makefile:47: 3rd party PPA:
Makefile:48: sudo add-apt-repository ppa:george-edison55/cmake-3.x -y
Makefile:49: sudo apt-get update
Makefile:50: sudo apt-get install cmake
Makefile:51:
Makefile:52: Official website:
Makefile:53: wget https://cmake.org/files/v3.3/cmake-3.3.2-Linux-x86_64.sh
Makefile:54: chmod +x cmake-3.3.2-Linux-x86_64.sh
Makefile:55: sudo mkdir /opt/cmake-3.3.2
Makefile:56: sudo ./cmake-3.3.2-Linux-x86_64.sh --prefix=/opt/cmake-3.3.2 --exclude-subdir
Makefile:57: export PATH=/opt/cmake-3.3.2/bin:$PATH
Makefile:58:
Makefile:59: *** Fatal。 停止。
My CMAKE version
root#root:~/Firmware$ cmake --version
cmake version 3.0.2
CMake suite maintained and supported by Kitware (kitware.com/cmake).
Why?
https://github.com/PX4/Firmware/blob/master/Tools/check_cmake.sh:
if [[ $cmake_ver == *" 2.8"* ]] || [[ $cmake_ver == *" 2.9"* ]] || [[ $cmake_ver == *" 3.0"* ]] || [[ $cmake_ver == *" 3.1"* ]]
then
exit 1;
fi
The code explicitly rejects cmake versions 2.8, 2.9, 3.0 (including your 3.0.2), 3.1.
You need to upgrade your cmake to at least version 3.2.

Travis CI: "Unable to locate package python-opencv" Python 2.7

On a normal non-virtualenv Ubuntu machine I can run:
sudo apt-get install python-opencv
And then from Python 2.7 I can run import cv2. Success!
But when I try to do the very same thing in my .travis.yml file for automated testing, I get the error:
E: Unable to locate package python-opencv
How can I get apt-get to locate python-opencv in my Travis-CI build?
I've tried the following; all were unsuccessful:
From https://askubuntu.com/questions/339217/, I tried appending these lines to /etc/apt/sources.list:
echo "deb http://de.archive.ubuntu.com/ubuntu precise main restricted universe" | sudo tee -a /etc/apt/sources.list
echo "deb-src http://de.archive.ubuntu.com/ubuntu precise restricted main multiverse universe" | sudo tee -a /etc/apt/sources.list
echo "deb http://de.archive.ubuntu.com/ubuntu precise-updates main restricted universe" | sudo tee -a /etc/apt/sources.list
echo "deb-src http://de.archive.ubuntu.com/ubuntu precise-updates restricted main multiverse universe" | sudo tee -a /etc/apt/sources.list
From here I tried adding these lines right before:
sudo apt-get install python-software-properties
sudo add-apt-repository python-opencv
Following this, with updated method from here, I tried using this instead of 2.7:
python:
- "2.7_with_system_site_packages"
(My full .travis.yml file is here.)
Update
Burhan Khalid's answer did get OpenCV installed, so the error went away. However, then when I tried find the package using import cv2 it still couldn't find it, because the Travis-CI build machine is wrapped in a virtualenv. So we can't access packages outside of our hermetically-sealed build environment.
So I build from source. (References: here, here and here)
Here's how to do it in the .travis.yml file:
env:
global:
# Dependencies
- DEPS_DIR="`readlink -f $TRAVIS_BUILD_DIR/..`"
- OPENCV_BUILD_DIR=$DEPS_DIR/opencv/build
And then, in the before_install section:
- travis_retry git clone --depth 1 https://github.com/Itseez/opencv.git $DEPS_DIR/opencv
- mkdir $OPENCV_BUILD_DIR && cd $OPENCV_BUILD_DIR
- |
if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then
cmake -DBUILD_TIFF=ON -DBUILD_opencv_java=OFF -DWITH_CUDA=OFF -DENABLE_AVX=ON -DWITH_OPENGL=ON -DWITH_OPENCL=ON -DWITH_IPP=ON -DWITH_TBB=ON -DWITH_EIGEN=ON -DWITH_V4L=ON -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=$(python -c "import sys; print(sys.prefix)") -DPYTHON_EXECUTABLE=$(which python) -DPYTHON_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") -DPYTHON_PACKAGES_PATH=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") ..
else
cmake -DBUILD_TIFF=ON -DBUILD_opencv_java=OFF -DWITH_CUDA=OFF -DENABLE_AVX=ON -DWITH_OPENGL=ON -DWITH_OPENCL=ON -DWITH_IPP=ON -DWITH_TBB=ON -DWITH_EIGEN=ON -DWITH_V4L=ON -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=$(python3 -c "import sys; print(sys.prefix)") -DPYTHON_EXECUTABLE=$(which python3) -DPYTHON_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") -DPYTHON_PACKAGES_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") ..
fi
- make -j4
- sudo make install
- echo "/usr/local/lib" | sudo tee -a /etc/ld.so.conf.d/opencv.conf
- sudo ldconfig
- echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig" | sudo tee -a /etc/bash.bashrc
- echo "export PKG_CONFIG_PATH" | sudo tee -a /etc/bash.bashrc
- export PYTHONPATH=$OPENCV_BUILD_DIR/lib/python3.3/site-packages:$PYTHONPATH
After:
sudo add-apt-repository python-opencv
You need
sudo apt-get update
So that the new repository information is correctly updated; before you can add packages from that repository.

clang 3.4 C++14 support

I am using travis.ci to do automated test builds of my git repositories.
For linux they use: Ubuntu 12.04
With clang 3.4
According to the clang page all C++ 14 language features are supported by Clang 3.4 (as long as you use the -std=c++1y flag).
So far so good:
I also need to use std::index_sequence<t0,...,tn> which is library feature N3658 not a language feature. But I can not find any specific documentation on updating the C++ standard library for clang to make sure this feature is supported (it is not supported out of the box).
TestCode:
#include <utility>
int main() {
std::index_sequence<1,2,3,4> seq;
}
TestBuild:
> clang++ -std=c++1y pl.cpp
pl.cpp:3:10: error: no member named 'index_sequence' in namespace 'std'
std::index_sequence<1,2,3,4> seq;
~~~~~^
pl.cpp:3:37: error: use of undeclared identifier 'seq'
std::index_sequence<1,2,3,4> seq;
^
2 errors generated.
Update:
Based on the suggestion below I tried to use libc++.
Pretty sure I did something wrong but I have never tried to use an alternative standard library so am not sure what is going wrong here. Will digg in tonight. But if you have a suggestion then please leave a comment.
> sudo apt-get install -qq libc++1 libc6 libc++-dev
> clang++ -stdlib=libc++ pl.cpp
pl.cpp:1:10: fatal error: 'utility' file not found
#include <utility>
^
1 error generated.
Well the answer seems to be to install g++-4.9
This will update the standard libraries already installed to a point where clang will be able to compile the code.
sudo apt-get install python-software-properties
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install g++-4.9
## Because I also use llvm-cov from my makefile
## I have to make sure it is in the path.
a=$(sudo find / -name llvm-cov | head -1)
sudo ln -s ${a} /usr/bin/llvm-cov
So this is what I added to travis.yml file
before_install:
- if [ "$TRAVIS_OS_NAME" == "linux" -a "$CXX" == "clang++" ]; then sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test;fi
- if [ "$TRAVIS_OS_NAME" == "linux" -a "$CXX" == "clang++" ]; then sudo apt-get update;fi
- if [ "$TRAVIS_OS_NAME" == "linux" -a "$CXX" == "clang++" ]; then sudo apt-get install g++-4.9;fi
- if [ "$TRAVIS_OS_NAME" == "linux" -a "$CXX" == "clang++" ]; then a=$(sudo find / -name llvm-cov | head -1);sudo ln -s ${a} /usr/bin/llvm-cov;fi
After I consolidate my g++ and clang++ pre-build code:
before_install:
- if [ "$TRAVIS_OS_NAME" == "linux"]; then sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y;fi
- if [ "$TRAVIS_OS_NAME" == "linux"]; then sudo apt-get update;fi
- if [ "$TRAVIS_OS_NAME" == "linux"]; then sudo apt-get install -qq g++-4.9;fi
- if [ "$TRAVIS_OS_NAME" == "linux" -a "$CXX" == "g++" ]; then sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 90;fi
- if [ "$TRAVIS_OS_NAME" == "linux" -a "$CXX" == "g++" ]; then sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 90;fi
- if [ "$TRAVIS_OS_NAME" == "linux" -a "$CXX" == "g++" ]; then sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-4.9 90;fi
- if [ "$TRAVIS_OS_NAME" == "linux" -a "$CXX" == "clang++" ]; then a=$(sudo find / -name llvm-cov | head -1);sudo ln -s ${a} /usr/bin/llvm-cov;fi
According to https://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html, libstdc++ supports this at least given the most recent version. Ubuntu 12.04 contains GCC 4.4, where this is obviously not supported. precise-backports does not contain a newer version of libstdc++.
However, via https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test, newer versions of GCC and with it, libstdc++, can be obtained. I don't know whether Travis supports installing from other repositories, or not, though.