clang-tidy cmake exclude file from check

后端 未结 2 1474
别那么骄傲
别那么骄傲 2020-12-19 06:31

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 o

相关标签:
2条回答
  • 2020-12-19 07:06

    In case you have a header only library I use SYSTEM (should also be possible for OBJECT libraries)

    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
    )
    

    I couldn't use this approach for a long time due to following bug

    https://bugs.launchpad.net/gcc-arm-embedded/+bug/1698539

    But with GNU Arm Embedded Toolchain Version 9-2020-q2-update it seems resolved :)

    0 讨论(0)
  • 2020-12-19 07:08

    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
    0 讨论(0)
提交回复
热议问题