c++ - Qt 应用程序 : build with different Qt versions 的 CI

标签 c++ qt continuous-integration travis-ci

我使用 Travis-CI 为我的简单 Qt 应用程序进行持续集成。我的 .travis.yml 文件看起来像这样(基于 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

此配置允许我使用 Ubuntu(Qt 4.8.1 和 Qt 5.0.2)中的默认 Qt 库构建我的应用程序(并运行测试)。

有什么方法可以使用其他 Qt 版本(4.7.x、4.8.x、5.1.x 等)构建应用程序吗?

最佳答案

灵感来自 AlexandreP回答和.travis.yml file of Twofold-Qt project非常感谢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

有了这个 .travis.yml,您将获得 10 个独立的构建作业 - 矩阵部分中的元素数量。每个构建作业都将安装指定的 Qt 版本,并将其用于在带有 Qt 4.8 - 5.7 的 Ubuntu 和带有 Qt 5.5 和 5.7(或最新版本)的 OS X 中构建应用程序。

如果你想为 Windows 构建你的应用程序,你可以尝试 AppVeyor CI 服务。示例配置(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

我在我的项目中使用这些配置 - qtcsv .查看它以获取更新和构建日志。

关于c++ - Qt 应用程序 : build with different Qt versions 的 CI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29721240/

相关文章:

c++ - 释放包含 malloc 字符串的 malloc 结构

c++ - 查找从未调用的函数

c++ - 这个函数调用有什么问题

qt - Qt 5.1 的模块及其相互依赖性?

c++ - 将字符串 vector 连接(连接)到字符缓冲区,零字节作为分隔符/终止符

c++ - 我的功能实现有什么问题吗?

qt - MAC地址为零指的是什么?

node.js - 模拟全局键盘快捷键以在 travis-ci 和 appveyor 中测试 Electron 应用程序

c# - Windows 上 Git 的持续集成

deployment - 你如何维护开发代码和生产代码?