Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

static analysis - clang-tidy cmake exclude file from check

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"}
]"")

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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

References


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...