clang-tidy cmake 从检查中排除文件 [英] clang-tidy cmake exclude file from check

查看:115
本文介绍了clang-tidy cmake 从检查中排除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有一个依赖项作为源,我无法控制.我正在使用 cmake 的 clang-tidy 集成来分析我的代码,并且这种依赖会引发很多警告.有没有办法告诉 cmake 不要在特定文件上运行 clang-tidy ?
我试图将文件添加到 clang-tidy 的 -line-filter 选项,但这不起作用:

I have a dependency as source in my project that I have no control over. I'm using cmake's clang-tidy integration to analyze my code, and this dependency is firing A LOT of warnings. Is there a way to tell cmake not to run clang-tidy on specific files ?
I tried to add the files to the -line-filter option of clang-tidy, but this doesn't work:

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 等其他静态分析器一起使用,那就太好了.谢谢.

If the solution could work with other static analyzers like cppcheck it would be really nice. Thanks.

推荐答案

如果某些属性 - 如 CXX_CLANG_TIDY - 仅在目标级别可用,您必须移动要具有不同设置的文件for 到一个单独的新目标本身.

If some property - like CXX_CLANG_TIDY - is only available on target level, you have to move the files you want to have different settings for into a separate new target itself.

这可以通过使用OBJECT.

This can be done by using OBJECT libraries.

在你的情况下是这样的:

In your case something like:

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>)

参考资料

这篇关于clang-tidy cmake 从检查中排除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆