我使用clang的扫描构建工具进行静态分析构建的以下脚本:
#!/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`
首次执行时脚本运行正常,但以下执行会在无限循环中执行此操作:
-- 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
.
.
.
我没有更改任何内容,只删除整个构建目录以使该cmake调用再次工作。此外,仅调用scan-build
而不是cmake没有问题。
我发现,通过对整个cmake生成的文件进行对等,它引用了-DCMAKE_CXX_COMPILER
设置的完整路径,我只传递c++-analyzer
,因为它在我的路径上。我怀疑c++analyzer
与其完整路径之间存在一些失败的比较。然后解决方法是在调用cmake时使用绝对路径传递-DCMAKE_CXX_COMPILER
,以便比较成功。这看起来像个错误。
答案 0 :(得分:1)
正如编辑问题中所解释的,解决方法是使用:
cmake -DCMAKE_C_COMPILER=`which ccc-analyzer` \
-DCMAKE_CXX_COMPILER=`which c++-analyzer` ../..