declare imported targets as system to suppress warnings

Normally to suppress warnings in a third party library, I would use something like:

target_include_directories(my_target
    SYSTEM
    PUBLIC
    ${EIGEN3_INCLUDE_DIR}
)

however the SYSTEM option doesn’t work with target_link_libraries:

target_link_libraries(my_target
    SYSTEM
    PUBLIC
    Eigen3::Eigen
)

I found this solution

on stackoverflow, but it still seems hacky. It there a better way to suppress warnings for third party libs? (Eigen doesn’t actually emit any warnings, it was just the first example I could find in my code)

My initial thoughts mirror the solution that Sebastian posted on Stackoverflow.
A possible ‘cleaner’ approach would be a function that moves the contents of INTERFACE_INCLUDE_DIRECTORIES to INTERFACE_SYSTEM_INCLUDE_DIRECTORIES.

Currently, CMake expects the library author not the consumer to set the which include directories should be considered SYSTEM.

IMPORTED targets should already have their include directories treated as SYSTEM though. There is the NO_SYSTEM_FROM_IMPORTED target property to disable it.

That’s unfortunately not the behavior I get in CMake 3.27, Ubuntu 23.04, and Eigen 3.4.0-4.

Eigen’s compiler warnings on g++12 are still causing issues downstream by me linking to Google’s Ceres solver. Despite each library appearing to use imported targets, the compiler is still treating them as warnings a few library layers up all the way in my library.

Are the warnings coming from template instantiations made in your code or just from the headers existing. That is, are the warning triggered by what you’ve written or is it just the #include that causes them?

I’m still looking into it, due to the template complexity generating 15,000 lines of error output, it’s a bit hard to reason through. I’ll report back if I can figure it out.