# How to limit C\_FLAGS to certain libraries

**URL:** <https://discourse.cmake.org/t/how-to-limit-c-flags-to-certain-libraries/853>\
**Category:** Code\
**Created:** [March 24, 2020, 3:04pm UTC](https://discourse.cmake.org/t/how-to-limit-c-flags-to-certain-libraries/853 "2020-03-24T15:04:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Allen](https://discourse.cmake.org/user_avatar/discourse.cmake.org/allen/32/4767_2.png) [@Allen](https://discourse.cmake.org/u/Allen)\
**Post date:** [March 24, 2020, 3:04pm UTC](https://discourse.cmake.org/t/how-to-limit-c-flags-to-certain-libraries/853/1 "2020-03-24T15:04:44Z")

</div>

We are trying to reduce warnings in our code base by promoting some warnings to errors.  
We build the list of warnings during configure time and add them to CMAKE\_C\_FLAGS.  
This was fine until we started implementing the list of -Werror=xxx.  
First was CMake FortranCInterface failed to compile with:  
-Werror=missing-declarations  
-Werror=missing-prototypes  
After fixing that, then the errors in examples and tests started failing - libraries and programs outside the intended code base for the stricter warnings.

I am looking for advice and how to selectively choose which library/sub-folder/target get which list of flags. Is there an easy way to set the CMAKE\_C\_FLAGS only on a specific library/sub-folder/target?

Allen

---

<div class="post-metadata">

**Author:** ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)\
**Post date:** [March 24, 2020, 3:27pm UTC](https://discourse.cmake.org/t/how-to-limit-c-flags-to-certain-libraries/853/2 "2020-03-24T15:27:14Z")

</div>

Use [target properties](https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#target-properties) (Mainly [target COMPILE\_OPTIONS](https://cmake.org/cmake/help/latest/prop_tgt/COMPILE_OPTIONS.html)).

Properties can also be set at directory level (see [directory COMPILE\_OPTIONS](https://cmake.org/cmake/help/latest/prop_dir/COMPILE_OPTIONS.html)).
