Reputation: 7739
Here's the setup:
$ cmake --version
cmake version 3.4.3
I want it to pick up these compilers:
$ ll /dist/gcc-4.8.2/bin/gcc
-rwxr-xr-x 3 root root 3112176 Nov 8 2013 /dist/gcc-4.8.2/bin/gcc
$# /dist/gcc-4.8.2/bin/gcc --version
gcc (GCC) 4.8.2
$ ll /dist/gcc-4.8.2/bin/g++
-rwxr-xr-x 4 root root 3121866 Nov 8 2013 /dist/gcc-4.8.2/bin/g++
$ /dist/gcc-4.8.2/bin/g++ --version
g++ (GCC) 4.8.2
... not the system compilers:
$ ll /usr/bin/cc
lrwxrwxrwx. 1 root root 3 Nov 20 2014 /usr/bin/cc -> gcc
$ ll /usr/bin/gcc
-rwxr-xr-x. 2 root root 263952 Nov 21 2013 /usr/bin/gcc
$ /usr/bin/cc --version
cc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4)
ll /usr/bin/c++
-rwxr-xr-x. 4 root root 267888 Nov 21 2013 /usr/bin/c++
$ /usr/bin/c++ --version
c++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4)
When I run cmake it picks up the system compilers:
$ cmake CXX=/dist/gcc-4.8.2/bin/g++ CC=/dist/gcc-4.8.2/bin/gcc ~/source/
-- The C compiler identification is GNU 4.4.7
-- The CXX compiler identification is GNU 4.4.7
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
Isn't that odd?
Upvotes: 0
Views: 586
Reputation: 42969
What you are doing cannot work, because CMake does not understand the flags you use.
You need to specify the environment variables definitions before invoking CMake:
$ CXX=/dist/gcc-4.8.2/bin/g++ CC=/dist/gcc-4.8.2/bin/gcc cmake ~/source/
which is normal shell syntax to specify environment variables for the following command.
However, the more correct way to do so is to define CMake variables from the command-line instead:
$ cmake -DCMAKE_CXX_COMPILER=/dist/gcc-4.8.2/bin/g++ -DCMAKE_C_COMPILER=/dist/gcc-4.8.2/bin/gcc ~/source/
According to the CMake FAQ:
For C and C++, set the CC and CXX environment variables. This method is not guaranteed to work for all generators. (Specifically, if you are trying to set Xcode's GCC_VERSION, this method confuses Xcode.)
Also, be careful to delete completely the target directory when switching compilers, because if some generated CMake files remain, no method will work at all.
Upvotes: 2