[CMake] Chicken/egg w/CMAKE_C_COMPILER
Andrew Melo
andrew.melo at gmail.com
Mon May 23 12:32:39 EDT 2016
Hi all,
I'm wanting to enable a couple of different options to enable/disable
compiler wrappers in my project. I would like to do something roughly
like this (and something similar to make ccache work right)
option(ENABLE_FUZZ "Use AFL fuzz wrapper" OFF)
if(ENABLE_FUZZ)
set(AFL_PATH /*depends on CMAKE_C_COMPILER_ID*/)
set(ENV{AFL_CC} ${CMAKE_C_COMPILER})
set(CMAKE_C_COMPILER ${AFL_PATH})
endif()
..but I hit a chicken and the egg problem. If I place project() above
this, cmake gets mad that I changed the compiler with "You have
changed variables that require your cache to be deleted....", and
messes up all of the set variables. If I place project() below this,
CMAKE_C_COMPILER_ID is unset, which means I can't choose the right
wrapper for AFL_PATH. Finally, if I do none of the above, and force
everyone to do "cmake -DCMAKE_C_COMPILER=<afl wrapper path> ..", the
user has to remember to always manually set the AFL_CC environment
variable each time they build, or the wrong underlying compiler is
chosen
What's the best move here? Is there some other "magic" variable I can
set to change the actual executable cmake calls, while not triggering
a cache rebuild? Is there a robust way to get the "presumptive"
compiler ID before project() is called?
Thanks!
Andrew
--
--
Andrew Melo
More information about the CMake
mailing list