# target\_compile\_options being applied to header files from FetchContent dependency

**URL:** <https://discourse.cmake.org/t/target-compile-options-being-applied-to-header-files-from-fetchcontent-dependency/8738>\
**Category:** Code\
**Tags:** os:linux\
**Created:** [August 15, 2023, 12:13pm UTC](https://discourse.cmake.org/t/target-compile-options-being-applied-to-header-files-from-fetchcontent-dependency/8738 "2023-08-15T12:13:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![SchizoidSage](https://discourse.cmake.org/user_avatar/discourse.cmake.org/schizoidsage/32/3718_2.png) [@SchizoidSage](https://discourse.cmake.org/u/SchizoidSage)\
**Post date:** [August 15, 2023, 12:13pm UTC](https://discourse.cmake.org/t/target-compile-options-being-applied-to-header-files-from-fetchcontent-dependency/8738/1 "2023-08-15T12:13:17Z")

</div>

I’m creating a Pong game project with a dependency on a Github project called [EnTT](https://github.com/skypjack/entt/tree/v3.12.0), a header-only library. Previously, I manually downloaded and installed EnTT in /usr/local, and included it with find\_package(EnTT), which worked.  
Now I want to replace find\_package with FetchContent\_Declare(entt). I have the following:

```auto
...
FetchContent_Declare(entt
  PREFIX dependencies/EnTT
  GIT_REPOSITORY https://github.com/skypjack/entt.git
  GIT_TAG v3.12.0
)
FetchContent_MakeAvailable(entt)
add_executable(pong "")
target_compile_options(pong
  PRIVATE 
    -pedantic-errors -Wall -Weffc++ -Wextra -Wsign-conversion -Werror
)
target_link_libraries(pong
  PRIVATE 
    [...]
    EnTT::EnTT
)
...

```

The build step fails because of errors generated in the EnTT header file, due to the compile options (such as sign-conversion errors). So the EnTT files need to be compiled without the target\_compile\_options above. I don’t understand why they are compiled with these options even though it is applied to the pong target. Is it possible to set different compile options for this dependency?

---

<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:** [August 15, 2023, 4:19pm UTC](https://discourse.cmake.org/t/target-compile-options-being-applied-to-header-files-from-fetchcontent-dependency/8738/2 "2023-08-15T16:19:08Z")

</div>

If it is indeed header-only, the EnTT headers are not compiled on their own. They are inheriting the options from those given to your sources (which then include the header). I think what probably changed is that `EnTT::EnTT` is not hiding warnings behind `-isystem`. Can you try setting the [`SYSTEM`](https://cmake.org/cmake/help/latest/prop_tgt/SYSTEM.html) property on `EnTT::EnTT` to see if that hides the warnings again?

---

<div class="post-metadata">

**Author:** ![SchizoidSage](https://discourse.cmake.org/user_avatar/discourse.cmake.org/schizoidsage/32/3718_2.png) [@SchizoidSage](https://discourse.cmake.org/u/SchizoidSage)\
**Post date:** [August 15, 2023, 5:43pm UTC](https://discourse.cmake.org/t/target-compile-options-being-applied-to-header-files-from-fetchcontent-dependency/8738/3 "2023-08-15T17:43:41Z")

</div>

The following solved the issue:

```auto
FetchContent_Declare(entt
  PREFIX dependencies/EnTT
  GIT_REPOSITORY https://github.com/skypjack/entt.git
  GIT_TAG v3.12.0
  SYSTEM
)

```

So you’re right, the issue was that the header files were not treated as system headers.

I noted that the SYSTEM property is only available in CMake version 3.25 and up. My package manager contains version 3.18, and I’d like to continue using that one if possible. Would it be possible to set this property on the target in an earlier version, without 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:** [August 15, 2023, 8:20pm UTC](https://discourse.cmake.org/t/target-compile-options-being-applied-to-header-files-from-fetchcontent-dependency/8738/4 "2023-08-15T20:20:24Z")

</div>

I’d try `set_property(TARGET EnTT::EnTT PROPERTY SYSTEM 1)`. If it works, then yes. If not, then I don’t think there’s a way.

---

<div class="post-metadata">

**Author:** ![SchizoidSage](https://discourse.cmake.org/user_avatar/discourse.cmake.org/schizoidsage/32/3718_2.png) [@SchizoidSage](https://discourse.cmake.org/u/SchizoidSage)\
**Post date:** [August 16, 2023, 4:08pm UTC](https://discourse.cmake.org/t/target-compile-options-being-applied-to-header-files-from-fetchcontent-dependency/8738/5 "2023-08-16T16:08:17Z")

</div>

The set\_property method does not work, since EnTT::EnTT is an alias, and set\_property may not be used on aliases. Same for set\_target\_properties. So it seems SYSTEM is the only way. Thank you for your help.

---

<div class="post-metadata">

**Author:** ![SchizoidSage](https://discourse.cmake.org/user_avatar/discourse.cmake.org/schizoidsage/32/3718_2.png) [@SchizoidSage](https://discourse.cmake.org/u/SchizoidSage)\
**Post date:** [August 16, 2023, 4:09pm UTC](https://discourse.cmake.org/t/target-compile-options-being-applied-to-header-files-from-fetchcontent-dependency/8738/6 "2023-08-16T16:09:30Z")

</div>

The set\_property function does not work since EnTT::EnTT is an alias, and set\_property does not work on aliases. Same for set\_target\_properties. So it seems SYSTEM is the only way. Thanks for your help.

---

<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:** [August 17, 2023, 2:05pm UTC](https://discourse.cmake.org/t/target-compile-options-being-applied-to-header-files-from-fetchcontent-dependency/8738/7 "2023-08-17T14:05:44Z")

</div>

You can ask the target for its `ALIASED_TARGET` property and then set it on that one.
