As far I know the best way to change the target C++ compiler used by cmake is to change the CXX
environment variable just before the call to cmake:
$ export CXX="clang++" && cmake --build
The Travis CI build sets the CXX
and CC
accordingly to the settings of the build. So if you have this in your .travis.yml
:
language: cpp
compiler:
- gcc
- clang
script:
- cmake --build
- ./bin/foo
The first time cmake
should use GCC and Clang on the latter isn't?
Instead, the GCC build compiles just fine (Its the default compiler used by cmake), but the Clang version uses GCC too:
0.01s$ echo $CC $CXX
clang clang++
The command "echo $CC $CXX" exited with 0.0.02s$ $CXX --version
clang version 3.4 (tags/RELEASE_34/final) Target: x86_64-unknown-linux-gnu Thread model: posixRunning: cmake -G "Unix Makefiles" -Wno-dev ../cmake
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
I even tried to set those variables again just before the call:
- if [ "$CXX" == "clang++" ]; then export CXX="clang++" && cmake --build; fi
- if [ "$CXX" == "g++" ]; then export CXX="g++" && cmake --build; fi
Which has no much sense I think...
Here is the successful build using GCC, and here the (Supposed to be) clang build.
My question is: How I can change the compiler used by cmake under Travis CI?
Here is my .travis.yml.
The first time cmake should use GCC and Clang on the latter isn't?
this approach should work fine. However I prefer to use cmake toolchains, it's more flexible. Example: linux and mac – user2288008CXX
, which isclang++
– Manu343726