更新时间:2022-06-13 01:16:07
Daniel Pffeifer的"Effective Cmake"(
Recommended way to use static analysis tools with CMake was presented in Daniel Pffeifer's "Effective Cmake" (https://www.***.com/watch?v=rLopVhns4Zs&=&t=77m13s).
您可以在调用 cmake
时定义它,例如:
You can either define it when calling cmake
, eg.:
cmake "-DCMAKE_CXX_CPPLINT=cpplint" ..
或将其放入 CMakeLists.txt
:
set(CMAKE_CXX_CPPLINT "cpplint")
推荐选项是第一个(我们不应该在项目中定义非项目要求的内容).
Recommended option is the first one (we shouldn't define in a project what isn't a project requirement).
CMake将为其编译的每个文件调用 cpplint
.您可以在分号后传递其他参数(例如 -DCMAKE_CXX_CPPLINT = cpplint;-linelength = 100
).
CMake will call cpplint
for each file it compiles. You can pass extra arguments after semicolon (e.g. -DCMAKE_CXX_CPPLINT=cpplint;--linelength=100
).
此方法的缺点:
cpplint
). cpplint
进行扫描)cpplint
is invoked for each file separately).cpplint
).请注意,您可以以相同的方式使用其他静态分析工具:
Note that you can use other static analysis tools the same way:
-DCMAKE_CXX_CLANG_TIDY =/usr/bin/clang-tidy-3.9; -checks = *"
-DCMAKE_CXX_CPPCHECK =/usr/bin/cppcheck;-std = c ++ 11"
-DCMAKE_CXX_INCLUDE_WHAT_YOU_USE =/usr/bin/iwyu;-transitive_includes_only"
cmake -DCMAKE_LINK_WHAT_YOU_USE = TRUE
其中一些将需要编译数据库"(设置(CMAKE_EXPORT_COMPILE_COMMANDS ON)
).
Some of them will require "compilation database" (set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
).