I am running a CMake (3.4.3) like this as explained in the CMake FAQ's:
export CC="cc_args.py $PWD/../bin/gcc"
export CXX="cc_args.py $PWD/../bin/g++"
cmake -DCMAKE_BUILD_TYPE=Debug ..
However when I print CMAKE_CXX_COMPILER
and CMAKE_C_COMPILER
it still points to the system's default compilers in /usr/bin
. It only works when I explicitly read-in the environment variables like this:
IF (NOT $ENV{CC} STREQUAL "")
SET(CMAKE_C_COMPILER $ENV{CC})
ENDIF ()
IF (NOT $ENV{CXX} STREQUAL "")
SET(CMAKE_CXX_COMPILER $ENV{CXX})
ENDIF ()
But even then the building fails with this message:
/bin/sh: 1: /home/peterg/bin/cc_args.py /home/peterg/Code/build/../bin/g++: not found
However I am certain that all paths are correct since executing just the path between the two colons outputs this as expected:
g++: fatal error: no input files
compilation terminated.
Update:
It seems the compiling process does not like spaces in the compiler paths. I've now created two scripts (one for GCC and one for CC) which wrap the commands and propagate the arguments and that seems to work. But it still seems I am doing something fundamentally wrong because CMake would also not accept the exported CC=proxy_script_cc.sh
and GCC=proxy_script_gcc.sh
variables without spaces by itself.
Pass
-DCMAKE_CXX_COMPILER=<path/to/compiler>
to your CMake call. That's less error prone compared to fiddling with shell variables.Turning my comment into an answer
Problem
I've given you code a try and could reproduce your problem
If I look at
CMakeDetermineCXXCompiler.cmake
code and atget_filename_component()
documentation, it just means that it didn't findcc_args.py
in "the system search path" or relative to your binary output directory.Solution
So it does work when you give a full path or a relative path to your binary output dir with something like
Alternative
CMake does allow to define "launcher scripts" e.g. with
CMAKE_<LANG>_COMPILER_LAUNCHER
References