iamantony iamantony - 2 months ago 13
C++ Question

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)?

Answer

Inspired by AlexandreP answer and .travis.yml file of Twofold-Qt project with many thanks to Stephan Binner.

language: cpp

compiler:
  - gcc

sudo: required
dist: trusty

env:
  - QT_BASE=48
  - QT_BASE=51
  - QT_BASE=52
  - QT_BASE=53
  - QT_BASE=54
  - QT_BASE=55
  - QT_BASE=56

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" ]; then sudo add-apt-repository ppa:beineri/opt-qt551-trusty -y; fi
  - if [ "$QT_BASE" = "56" ]; then sudo add-apt-repository ppa:beineri/opt-qt561-trusty -y; fi
  - if [ "$QT_BASE" = "57" ]; then sudo add-apt-repository ppa:beineri/opt-qt57-trusty -y; fi
  - sudo apt-get update -qq

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 sudo apt-get install -qq qt55base; source /opt/qt55/bin/qt55-env.sh; 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 sudo apt-get install -qq qt57base; source /opt/qt57/bin/qt57-env.sh; fi

script:
  - qmake -r
  - make
  - make check

notifications:
  email: false

With this er... settings Travis-CI will start 7 separate build jobs (see Environment Variables) - number of defined QT_BASE variables. Each build job will install specified Qt version and use it for app building.

Comments