Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 892
Niverton Avatar asked Mar 31 '18 19:03

Niverton


1 Answers

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

  • CMake/Tutorials/Object Library
like image 107
Florian Avatar answered Nov 10 '22 08:11

Florian