# Why doesn't target\_compile\_options() print console warnings like set(CMAKE\_LANG\_FLAGS...)?

**URL:** https://discourse.cmake.org/t/why-doesnt-target-compile-options-print-console-warnings-like-set-cmake-lang-flags/11371
**Category:** Usage
**Tags:** tool:cmake
**Created:** [August 1, 2024, 10:34pm UTC](https://discourse.cmake.org/t/why-doesnt-target-compile-options-print-console-warnings-like-set-cmake-lang-flags/11371 "2024-08-01T22:34:16Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![RudyFisher7](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rudyfisher7/32/4820_2.png) [@RudyFisher7](https://discourse.cmake.org/u/RudyFisher7)
#### Post date: [August 1, 2024, 10:34pm UTC](https://discourse.cmake.org/t/why-doesnt-target-compile-options-print-console-warnings-like-set-cmake-lang-flags/11371/1 "2024-08-01T22:34:16Z")

</div>

The title says it all really. I’ve built a handful of c++ project with CMake now. set(CMAKE\_CXX\_FLAGS…) needs to be used in order to get the compiler warnings to print during compilation. target\_compile\_options() never prints the warnings. This behavior is experienced with VSCode, CLion, and the good old trusty command line. Is this normal? My understanding is the latter is the recommended mechanism since it allows to control them per-target, but don’t know how this would help if ya can’t see the warnings using it. 🙂 Thanks! Here is a minimal reproducible CMakeLists.txt:

cmake\_minimum\_required(VERSION 3.13)  
project(\<projectname\> VERSION 0.0.1 LANGUAGES CXX)

set(CMAKE\_CXX\_STANDARD 11)  
set(CMAKE\_CXX\_STANDARD\_REQUIRED ON)

# this is used because of explanation above (prints warnings about code smells, ISO violations, etc.). -std=c++11 might be unnecessary but honestly not confident at this point.  
set(CMAKE\_CXX\_FLAGS “${CMAKE\_CXX\_FLAGS} -std=c++11 -Wall -Wpedantic”)

message(STATUS “CMAKE\_CXX\_FLAGS: ${CMAKE\_CXX\_FLAGS}”)

add\_library(${PROJECT\_NAME} STATIC  
\<sources (shouldn’t be important)\>  
)

target\_include\_directories(${PROJECT\_NAME} PUBLIC  
include  
)

# commented out because it doesn’t produce desired warnings in console during build stage  
#target\_compile\_options(${PROJECT\_NAME} PRIVATE  
# -Wall  
# -Wpedantic  
#)

---

<div class="post-metadata">

### Author: ![RudyFisher7](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rudyfisher7/32/4820_2.png) [@RudyFisher7](https://discourse.cmake.org/u/RudyFisher7)
#### Post date: [September 23, 2024, 11:53am UTC](https://discourse.cmake.org/t/why-doesnt-target-compile-options-print-console-warnings-like-set-cmake-lang-flags/11371/2 "2024-09-23T11:53:20Z")

</div>

No replies yet? Sadness…

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [September 23, 2024, 12:19pm UTC](https://discourse.cmake.org/t/why-doesnt-target-compile-options-print-console-warnings-like-set-cmake-lang-flags/11371/3 "2024-09-23T12:19:33Z")

</div>

I’ve tried creating a minimal example, and `target_compile_options` resulted in pedantic warnings being printed just fine. Can you provide a minimal reproducer for the incorrect behaviour you’re getting?

---

<div class="post-metadata">

### Author: ![RudyFisher7](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rudyfisher7/32/4820_2.png) [@RudyFisher7](https://discourse.cmake.org/u/RudyFisher7)
#### Post date: [December 5, 2024, 8:10pm UTC](https://discourse.cmake.org/t/why-doesnt-target-compile-options-print-console-warnings-like-set-cmake-lang-flags/11371/4 "2024-12-05T20:10:36Z")

</div>

Interesting. I just attempted to narrow it down with a minimal example. I added -Wextra to the compile options and saw that they now work with target\_compile\_options() in this example.
