Don’t know if it helps or if it’s remotely right way but this is an example of what I do:
# Unfortunately, nlohmann_json does not set its headers as SYSTEM,
# so we get errors with our warning level.
get_target_property(_inc nlohmann_json::nlohmann_json INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(nlohmann_json SYSTEM INTERFACE ${_inc})
So in short - I find the right target and alter INTERFACE_INCLUDE_DIRECTORIES to be seen as SYSTEM. Solves the problem for me.
What do you mean by your comment with “Unfortunately the lib does not set its headers as SYSTEM” … is that some best practice for libs I didn’t know about?
Your solution works for me, although I wonder if there is a better way to do this. Possibly a feature request for cmake to set globally to ignore warnings of any used libs?
I especially don’t like about the approach that you have to know the internal name of the target.
I don’t know best practise but I’d say that the target you’re supposed to link against should have it set. That way the consumer doesn’t have to care. Many libraries do not do it which is a pity in my opinion. Somebody please correct me if I’m wrong.
That probably won’t work because after you fetch the external projects, you add it witch add_subdirectory() to your build tree. So it becomes a part of your build and all the targets become “your” targets - it’s no longer an external library. For that you’d probably need ExternalProject…
Me neither. I’m just saying it works and I have no time looking for more sophisticated solution.
If that only scaled… It might be a solution if you need 1-2 headers. I am not going to write something like that for each and every 3-party header (and keep it up to date with changes they introduce).
Asking the devs to fix it is fine. Except when you can only use released versions because of reasons and you need it now (like it usually is).
If you know the targets that are providing the headers in question, you could potentially add to that target’s INTERFACE_SYSTEM_INCLUDE_DIRECTORIES property to contain the directories where that target’s headers reside. Then anything linking to those targets should treat those headers as system headers, which should prevent compiler warnings being generated for them. Note that you can call set_property(TARGET blah APPEND PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ...) from any directory, not just the directory in which the target blah is defined.