Daniel
Daniel

Reputation: 8451

Why is Travis not recognising installed CMake in script?

I'm trying to put together a Travis CI script for my application, which requires CMake 3.5 or greater. The entire Travis script can be found here. Following advice I found elsewhere, I use the following to install CMake:

 install:
    - DEPS_DIR="${TRAVIS_BUILD_DIR}/deps"
    - mkdir -p ${DEPS_DIR} && cd ${DEPS_DIR}

    - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
        CMAKE_URL="https://cmake.org/files/v3.7/cmake-3.7.2-Linux-x86_64.tar.gz";
        mkdir cmake && travis_retry wget --no-check-certificate --quiet -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C cmake;
        export PATH=${DEPS_DIR}/cmake/bin:${PATH};
      else
        brew outdated cmake || brew upgrade cmake;
      fi
    - cmake --version

Then I fill out the build matrix with various OS/compiler combinations, and finally I run a Python installation script (see here):

before_script:
    - cd "${TRAVIS_BUILD_DIR}"

script:
    - ./install.py --compiler=$COMPILER

The Python script essentially just calls cmake and make, the first CMakeLists.txt can be found here.

The OSX builds which install CMake using Homebrew works perfectly. However, all of the Linux builds fail at the script stage due to CMake not meeting the minimum requirement:

CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
  CMake 3.5 or higher is required.  You are running version 3.2.2

Even though CMake 3.7 was successfully installed during install:

$ cmake --version
cmake version 3.7.2

What am I doing wrong?

Upvotes: 3

Views: 559

Answers (1)

ollo
ollo

Reputation: 25380

This is strange, the preinstalled version of CMake (= v3.2 on Travis) is used instead of the newer one – but only when called from Python.

You can try these:

Solution 1: Remove the CMake shipped by Travis

This will prevent the usage of the older version. If this doesn't work (eg. maybe because "Cmake isn't found"), this will show the actual reason of the problem.

You can add this to your linux branch of the install step:

sudo apt-get purge cmake

Or:

sudo apt-get remove cmake

(Possible you need to add -y for confirmation, so it becomes remove -y).

Solution 2: Use the CMake installer

Installation through the CMake Installer is a much cleaner way. It turned out the be the faster one on Travis btw.

...
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
    CMAKE_INSTALLER=install-cmake.sh
    curl -sSL https://cmake.org/files/v3.7/cmake-3.7.2-Linux-x86_64.sh -o ${CMAKE_INSTALLER}
    chmod +x ${CMAKE_INSTALLER}
    sudo ./${CMAKE_INSTALLER} --prefix=/usr/local --skip-license
  else
    ...

I'm using curl instead of wget + travis_retry, but this doesn't matter. You can still use them as before.


If both don't work, you should check where the Python script looks for executables.

Upvotes: 3

Related Questions