Why doesn't target_compile_options() print console warnings like set(CMAKE_LANG_FLAGS...)?

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. :slight_smile: 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
#)

No replies yet? Sadness…

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?