Suppress clang warnings when using ROOT as third party library with CMake

I am using ROOT as third party library in a CMake project as follows

find_package(ROOT 6.30 CONFIG REQUIRED)
target_link_libraries(myLibrary PUBLIC ROOT::Core)
target_include_directories(myLibrary PRIVATE  ${CMAKE_SOURCE_DIR}/include/myLibrary)
ROOT_GENERATE_DICTIONARY(myLibrary_dict myLibrary.h MODULE myLibrary LINKDEF include/myLibrary/LinkDef.h)

This seems to work fine, but I am getting a long list of compiler warnings from A) the dictionary generated, e.g.

/build/myLibrary_dict.cxx:76:38: warning: use of old-style cast [clang-diagnostic-old-style-cast]
   if (!fgIsA.load()) { R__LOCKGUARD(gInterpreterMutex); fgIsA = ::ROOT::GenerateInitInstanceLocal((const ::MLogging*)nullptr)->GetClass(); }

and B) ROOT itself, e.g.:

/root/include/THashTable.h:48:73: warning: conversion to ‘Int_t’ {aka ‘int’} from ‘UInt_t’ {aka ‘unsigned int’} may change the sign of the result [-Wsign-conversion]
   48 |    Int_t       GetHashValue(const char *str) const { return ::Hash(str) % fSize; }

What is the recommended way of suppressing these warnings in the CMake configuration? It would be great if this could be added to the documentation!


Your question seems more related to cmake and not directly to ROOT.
Nevertheless @bellenot might have an idea about it.

You can try to disable the warnings for specific source files using something like: set_source_files_properties(myLibrary_dict.cxx PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast")
And possibly the same for source files using ROOT headers (-Wno-sign-conversion)
(check for the correct flags)
You can also disable the warnings for the whole project, but I would advise not to.
And FYI, I’m just trying to guess here…

Hi @couet and @bellenot,

I think your suggestion works for compiler warnings but not for clang-tidy. What I finally found to work was

set_target_properties(myLibrary_dict PROPERTIES COMPILE_FLAGS "-w" CXX_CLANG_TIDY "")

Interestingly, one (real) error message remains

Checking /workspaces/build/myLibrary_dict.cxx ...
/root/include/ROOT/span.hxx:18:0: error: failed to evaluate #if condition [preprocessorErrorDirective]
# if __has_include(<span>)

Everyting compiles fine, but I am wondering whether you are aware of this and where this comes from. I am using ROOT Version: 6.30/06.

I also think its worth putting this in the documentation (e.g. Integrating ROOT into CMake projects - ROOT) as people will likely always want to disable warnings from third-party libaries and we definitely should not encourage them to disable the warnings on a project level.

Thanks for the feedback and for the solution. We’ll see where to add add a clang-tidy specific paragraph in the doc. Note that you can also open a GH pull request if you want…

I’m not aware, but I’m working on Windows… I’ll check on other platforms, but I think we would have seen it in our CI if it was the case…

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.