Search code examples
c++cmakec++20conanclang-tidy

ClangTidy + CMake - ignore third party headers from Conan


I am trying to use ClangTidy on some working source code but I cannot get it to ignore / bypass lib{fmt} and see lots of noise such as:

~/.conan/data/fmt/9.1.0///package/2c09c8f84c016041549fcee94e4caae5d89424b6/ include/fmt/core.h:2955:15: warning: 5 uninitialized fields at the end of the constructor call [clang-analyzer-optin.cplusplus.UninitializedObject] types_{ ^ ~/.conan/data/fmt/9.1.0///package/2c09c8f84c016041549fcee94e4caae5d89424b6/ include/fmt/core.h:732:7: note: uninitialized field 'this->context_.num_args_' int num_args_; ^~~~~~~~~

I am using CMake + Conan and the diagnostic messages I have come from lib{fmt}.

How can I silence them? For CppCheck it was simply a case of specifying that all files under ~/.conan/ should be ignored.

How do I tell Clang-tidy to ignore all files under ~/.conan/

Note I have seen clang-tidy - ignore third party headers code which does not answer my question


Solution

  • System header files do not generate warnings. You need to mark the fmt header-files as system header-files.

    NOTE: I am using cmake and CPMAddPackage() to bring fmt into my build environment, your millage my vary:

    CPMAddPackage("gh:fmtlib/fmt#10.1.1")
    

    This defines the cmake-variable FMT_SOURCE_DIR which points to the location of the header files. Use this variable to set-up the fmt include:

    include_directories(
      SYSTEM
      ${FMT_SOURCE_DIR}/include)
    

    This fixed the issue for me. Your setup may create a different variable for exactly the same purpose. You can consult SO answer, about printing all variables, to find the name of the variable you need.