# declare imported targets as system to suppress warnings

**URL:** https://discourse.cmake.org/t/declare-imported-targets-as-system-to-suppress-warnings/555
**Category:** Usage
**Tags:** os:linux
**Created:** [January 30, 2020, 2:31pm UTC](https://discourse.cmake.org/t/declare-imported-targets-as-system-to-suppress-warnings/555 "2020-01-30T14:31:11Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![schrodinbug](https://discourse.cmake.org/user_avatar/discourse.cmake.org/schrodinbug/32/315_2.png) [@schrodinbug](https://discourse.cmake.org/u/schrodinbug)
#### Post date: [January 30, 2020, 2:31pm UTC](https://discourse.cmake.org/t/declare-imported-targets-as-system-to-suppress-warnings/555/1 "2020-01-30T14:31:11Z")

</div>

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

```auto
target_include_directories(my_target
    SYSTEM
    PUBLIC
    ${EIGEN3_INCLUDE_DIR}
)

```

however the `SYSTEM` option doesn’t work with `target_link_libraries`:

```auto
target_link_libraries(my_target
    SYSTEM
    PUBLIC
    Eigen3::Eigen
)

```

I found this solution

> <https://stackoverflow.com/questions/52135983/cmake-target-link-libraries-include-as-system-to-suppress-compiler-warnings>

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)

---

<div class="post-metadata">

### Author: ![robert.maynard](https://discourse.cmake.org/user_avatar/discourse.cmake.org/robert.maynard/32/4_2.png) [@robert.maynard](https://discourse.cmake.org/u/robert.maynard)
#### Post date: [February 3, 2020, 2:26pm UTC](https://discourse.cmake.org/t/declare-imported-targets-as-system-to-suppress-warnings/555/2 "2020-02-03T14:26:56Z")

</div>

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`.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 28, 2020, 9:51pm UTC](https://discourse.cmake.org/t/declare-imported-targets-as-system-to-suppress-warnings/555/3 "2020-02-28T21:51:21Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Ryanf55](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ryanf55/32/3516_2.png) [@Ryanf55](https://discourse.cmake.org/u/Ryanf55)
#### Post date: [June 24, 2023, 2:46am UTC](https://discourse.cmake.org/t/declare-imported-targets-as-system-to-suppress-warnings/555/4 "2023-06-24T02:46:14Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [June 25, 2023, 8:11pm UTC](https://discourse.cmake.org/t/declare-imported-targets-as-system-to-suppress-warnings/555/5 "2023-06-25T20:11:36Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Ryanf55](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ryanf55/32/3516_2.png) [@Ryanf55](https://discourse.cmake.org/u/Ryanf55)
#### Post date: [June 27, 2023, 3:19pm UTC](https://discourse.cmake.org/t/declare-imported-targets-as-system-to-suppress-warnings/555/6 "2023-06-27T15:19:25Z")

</div>

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.
