我在我的项目中有一个我无法控制的依赖项作为源代码。我正在使用cmake的整洁集成来分析我的代码,并且这个依赖项引发了很多警告。有没有办法告诉cmake不要在特定的文件上运行clang-tidy?
我尝试将文件添加到clang-tidy的-line-filter选项中,但这不起作用:
set_target_properties(target PROPERTIES
CXX_CLANG_TIDY "${clang_tidy_loc};\
${TIDY_CONFIG} \
-line-filter=\"[\
{\"name\":\"path/to/file.cpp\"},\
{\"name\":\"path/to/file.h\"}\
]\"")如果这个解决方案可以与其他静态分析器一起工作,比如cppcheck,那就太好了。谢谢。
发布于 2018-04-01 04:05:24
如果某些属性-如CXX_CLANG_TIDY -仅在目标级别上可用,则必须将您希望其具有不同设置的文件移动到单独的新目标本身。
这可以通过使用OBJECT libraries来完成。
在您的示例中,类似于:
add_library(
target_no_static_code_analysis
OBJECT
path/to/file.cpp
path/to/file.h
)
# NOTE: Resetting only needed if you have a global CMAKE_CXX_CLANG_TIDY
set_target_properties(
target_no_static_code_analysis
PROPERTIES
CXX_CLANG_TIDY ""
)
...
add_library(target ${other_srcs} $<TARGET_OBJECTS:target_no_static_code_analysis>)参考
发布于 2020-11-09 17:21:46
如果你有一个只有头文件的库,我使用系统(也可以用于对象库)
add_library(
header_only_library_no_static_code_analysis
INTERFACE
)
target_include_directories(
header_only_library_no_static_code_analysis
SYSTEM # Adds -isystem instead of -I and this tells clang-tidy not to analyze these includes
INTERFACE
path/to
)由于下面的错误,我很长一段时间都不能使用这种方法
https://bugs.launchpad.net/gcc-arm-embedded/+bug/1698539
但随着GNU Arm嵌入式工具链版本9-2020-q2-update的出现,问题似乎得到了解决:)
https://stackoverflow.com/questions/49591804
复制相似问题