I have the following script for a static analysis build using clang's scan-build tool:
#!/usr/bin/env bash
export CC=clang
export CXX=clang++
export CCC_CC=$CC
export CCC_CXX=$CXX
mkdir -p static-analysis/build
cd static-analysis/build
cmake -DCMAKE_C_COMPILER=ccc-analyzer -DCMAKE_CXX_COMPILER=c++-analyzer ../..
scan-build -o .. --use-analyzer /usr/local/bin/clang --html-title="craft static analysis" make -j`getconf _NPROCESSORS_ONLN`
The script works OK on first execution, but the following executions give this in an infinite loop:
-- Configuring done
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_CXX_COMPILER= c++-analyzer
-- Configuring done
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_CXX_COMPILER= c++-analyzer
.
.
.
I didn't change anything, only removing the entire build directory for that cmake call to work again. Also, invoking just scan-build
and not cmake has no problems.
I've discovered by peering throughout cmake generated files that it was refering to the full path for the -DCMAKE_CXX_COMPILER
setting, for which I pass just c++-analyzer
, since it's on my path. I suspected there was some failed comparison between c++analyzer
and the full path of it. The workaround then is to pass -DCMAKE_CXX_COMPILER
with absolute path when invoking cmake so the comparison succeeds. This looks like a bug.
As explained in the question EDIT, the workaround for this is to use:
cmake -DCMAKE_C_COMPILER=`which ccc-analyzer` \
-DCMAKE_CXX_COMPILER=`which c++-analyzer` ../..