Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 996
mark Avatar asked Oct 24 '25 09:10

mark


1 Answers

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.

like image 105
Michael Veksler Avatar answered Oct 25 '25 22:10

Michael Veksler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!