The travis Building a C++ Project documentation shows how to specify gcc and clang compiler versions in build matrices. However, it does not show how to build projects with those compilers using cmake.
I amended the .travis.yml
file here to specify gcc 9 and clang 8 as per the travis documentation, i.e.:
matrix: include: - compiler: gcc addons: apt: sources: - ubuntu-toolchain-r-test packages: - g++-9 env: - MATRIX_EVAL="CC=gcc-9 && CXX=g++-9" - compiler: clang addons: apt: sources: - ubuntu-toolchain-r-test - llvm-toolchain-bionic-8 packages: - clang-8 - libstdc++-8-dev env: - MATRIX_EVAL="CC=clang-8 && CXX=clang++-8"before_install: - eval "${MATRIX_EVAL}" - pip install --user cpp-coveralls...script: - mkdir _builds - cd _builds - cmake -DVIA_HTTPLIB_UNIT_TESTS=ON -DVIA_HTTPLIB_COVERAGE=ON ${CMAKE_OPTIONS} .. - make - ./via-httplib_test
But is caused build errors when running cmake
, e.g.:
$ cmake -DVIA_HTTPLIB_UNIT_TESTS=ON -DVIA_HTTPLIB_COVERAGE=ON ${CMAKE_OPTIONS} ..CMake Error at /usr/local/cmake-3.12.4/share/cmake-3.12/Modules/CMakeDetermineCCompiler.cmake:48 (message): Could not find compiler set in environment variable CC: gcc-9.Call Stack (most recent call first): CMakeLists.txt:9 (project)CMake Error: CMAKE_C_COMPILER not set, after EnableLanguageCMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage-- Configuring incomplete, errors occurred!See also "/home/travis/build/kenba/via-httplib/_builds/CMakeFiles/CMakeOutput.log".The command "cmake -DVIA_HTTPLIB_UNIT_TESTS=ON -DVIA_HTTPLIB_COVERAGE=ON ${CMAKE_OPTIONS} .." exited with 1.
I tried fixing the errors by specifying CMAKE_C_COMPILER
and CMAKE_CXX_COMPILER
for cmake, but I could not get it to work. However, it builds correctly with:
env: - MATRIX_EVAL="CC=gcc && CXX=g++" ... env: - MATRIX_EVAL="CC=clang && CXX=clang++"
but builds with the default bionicgcc
and clang
compilers, i.e.: GCC 7.4.0 and Clang 7, not GCC 9 and Clang 8.
How to write a .travis.yml
file so that cmake
can find and use the compiler versions specified in a matrix?