使用apt addon为Travis-CI安装Qt5

时间:2016-01-31 16:43:40

标签: c++ linux qt travis-ci

如何在Travis-CI docker基础设施上安装Qt5软件包?我想通过apt addon执行此操作,因为它比使用sudo的虚拟机快得多。

我已查看apt-whitelistapt-source-whitelist。我不确定哪种组合能让我有效安装Qt5。我已经尝试手动构建Qt5,但它太大而且无法完成。

这是我的.travis.yml:

language: cpp

compiler:
- clang
- gcc

os:
- linux
- osx

env:
  global:
    - BOOST_VERSION="1.59.0"
    - BOOST_ROOT="${TRAVIS_BUILD_DIR}/vendor/boost"
    - QT_ROOT="${TRAVIS_BUILD_DIR}/vendor/qt5"

cache:
  directories:
    - vendor

before_install:
- ./install.deps.sh

script:
- if [ "${TRAVIS_OS_NAME}" == "linux" ] && [ "${CC}" == "clang" ]; then export CC="clang-3.6" ; export CXX="clang++-3.6" ; echo "Rexported clang" ; fi
- |
  echo "Configuration info:"
  echo "BOOST_ROOT=${BOOST_ROOT}"
  cmake --version
  $CC --version
  $CXX --version
  qmake --version

- mkdir build; cd build
- |
    cmake -DBOOST_ROOT:path="${BOOST_ROOT}" \
          -DCMAKE_PREFIX_PATH:path="${CMAKE_PREFIX_PATH}:${QT_ROOT}" \
          ..

- make -j2 run_tests
- ./bin/run_tests

addons:
  apt:
    sources:
    - george-edison55-precise-backports
    - ubuntu-toolchain-r-test
    - llvm-toolchain-precise-3.6
    # - ubuntu-sdk-team
    packages:
    - cmake
    - cmake-data
    - clang-3.6
    # - qtbase5-dev

脚本install.deps.sh

#!/usr/bin/env bash

# This script installs and configures the dependencies for the project

declare OS_NAME

case `uname` in 
    Darwin)     OS_NAME="osx"    ;;
    Linux)      OS_NAME="linux"  ;;
esac

echo "Building on: ${OS_NAME}"

if env | grep -qE '^(?:TRAVIS|CI)='; then
#    We're on Travis, intialize variables:
    echo "Detected CI Build -> CI=${CI}"
else
#   We're building locally
    export CI=false
    echo "Detected Local Build -> CI=${CI}"
fi


install_os_deps() {
    # Install all of the OS specific OS dependencies

    case ${OS_NAME} in
        osx)
            echo "brew update ..."; brew update > /dev/null

            if [ "${CC}" = "gcc" ]; then 
                export CC=gcc-4.8 
                export CXX=g++-4.8
            fi

            brew unlink cmake
            brew unlink boost 
            brew install qt5 cmake boost
            brew link qt5 --force
            ln -s /usr/local/Cellar/qt5/5.5.1_2/mkspecs /usr/local/mkspecs
            ln -s /usr/local/Cellar/qt5/5.5.1_2/plugins /usr/local/plugins

            export BOOST_ROOT="/usr/local/"

        ;;

        linux) 
            if [ "${OS_NAME}" == "linux" ] && [ "${CC}" == "clang" ]; then 
                export CC="clang-3.6" ;
                export CXX="clang++-3.6" ;
            fi 

            if [ ! -d vendor/src ]; then mkdir vendor/ ; mkdir vendor/src; fi
            cd vendor/src         

            local b_underscore=`echo ${BOOST_VERSION} | sed 's/\./_/g'`
            local b_url="http://downloads.sourceforge.net/project/boost/boost/${BOOST_VERSION}/boost_${b_underscore}.tar.bz2"
            local b_archive="boost_${b_underscore}.tar.bz2"
            if [ ! -f "./${b_archive}" ]; then 
                echo "Downloading Boost ${BOOST_VERSION}"
                wget --no-check-certificate ${b_url} -O ${b_archive}

            fi

            if [ ! -d "${BOOST_ROOT}" ]; then  
                echo "Extracting ${b_archive} ..." 
                tar xjf ${b_archive}

                # Build it:
                echo "Installing Boost ${BOOST_VERSION} ..."
                cd boost_${b_underscore}
                rm -rf ${BOOST_ROOT}
                ./bootstrap.sh --prefix=${BOOST_ROOT}
                ./b2 clean
                ./b2 -j 2 -d1 install --with-system --with-filesystem --with-signals \
                                      --with-program_options --with-exception \
                                      --with-chrono --with-thread --with-log

                cd -
            else 
                echo "Found cached Boost ${BOOST_VERSION} @ ${b_archive}"
            fi

        ;;
    esac
}

# install_manual_deps() {

# }

install_os_deps

# install_manual_deps

顺便说一句,我目前正在手工构建和安装Boost ..如果有人有更好的解决方案,我会全力以赴。

0 个答案:

没有答案