Search code examples
cmakeenvironment-variablescray

Why does Cmake Always Choose GCC?


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?


Solution

  • 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 .