Why does Cmake Always Choose GCC?

4.2k views Asked by At

For reasons that I cannot completely understand, Cmake awlays chooses the GNU compiler toolset when compiling software.

My enviroment looks like this:

which cc
/opt/cray/xt-asyncpe/4.9/bin/cc
which CC
/opt/cray/xt-asyncpe/4.9/bin/CC
echo $CC
/opt/cray/xt-asyncpe/4.9/bin/cc
echo $CXX
/opt/cray/xt-asyncpe/4.9/bin/CC

but when I use cmake I get this

Using existing /opt/cmake/2.8.4/bin/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

And it builds all the software with g++ commands. Why is this going on? How does one set the compiler?

2

There are 2 answers

1
Fraser On BEST ANSWER

I'm not sure why CMake favours GCC.

However, to set the compilers, use:

cmake <path to CMakeLists.txt> -DCMAKE_C_COMPILER=/opt/cray/xt-asyncpe/4.9/bin/cc -DCMAKE_CXX_COMPILER=/opt/cray/xt-asyncpe/4.9/bin/CC

These values will be cached, so subsequent runs of CMake (if required) can simply be invoked by:

cmake .
1
Bill Hoffman On

You can also set the env vars CC and CXX much like autotools.

CC=cc CXX=CC cmake ...

Make sure you start with an empty build tree.