# Compiler warning flags for all except ExternalProjects

**URL:** https://discourse.cmake.org/t/compiler-warning-flags-for-all-except-externalprojects/4176
**Category:** Code
**Created:** [September 30, 2021, 12:41pm UTC](https://discourse.cmake.org/t/compiler-warning-flags-for-all-except-externalprojects/4176 "2021-09-30T12:41:25Z")
**Posts on this page:** 1
**Showing post:** 3

<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: [October 1, 2021, 11:37am UTC](https://discourse.cmake.org/t/compiler-warning-flags-for-all-except-externalprojects/4176/3 "2021-10-01T11:37:09Z")

</div>

You can make a target that carries the flags and you link to from each of your targets (either manually or via something like looping over `BUILDSYSTEM_TARGETS`):

> [@Setting \`CMAKE\_CXX\_FLAGS\` within a function](https://discourse.cmake.org/t/setting-cmake-cxx-flags-within-a-function/4163/7):
>
> Note that the better solution these days is something like: add\_library(buildflags INTERFACE) target\_compile\_options(buildflags INTERFACE -Wsome-warning) # For each target target\_link\_libraries(mytgt PRIVATE buildflags)

---

_[View the full topic](https://discourse.cmake.org/t/compiler-warning-flags-for-all-except-externalprojects/4176)._
