Skip to content

Add abstraction to control compile warning flags

Jiang Yi requested to merge jiangyilism/cmake:compile_warning_prop_tgt into master

As discussed in issue #19085 two target properties COMPILE_WARNING_MODE and COMPILE_WARNING_AS_ERROR are added.

COMPILE_WARNING_MODE is initialized by CMAKE_COMPILE_WARNING_MODE global variable. It takes the following values: DEFAULT (expands to nothing), DISABLED(expands to "-w" for clang/gcc/msvc), HIGH(expands to "-Wall -Wextra").

COMPILE_WARNING_AS_ERROR is initialized by CMAKE_COMPILE_WARNING_AS_ERROR. It is a boolean variable. If it is true, it expands to "-Werror" for clang/gcc and "-WX" for msvc. It expands to nothing otherwise.

These two target properties do not have INTERFACE_* counterparts thus do not propagate to targets that depend on them.

Not all compilers are fully supported. Those that are currently unsupported act like CMAKE_COMPILE_WARNING_MODE=DEFAULT and COMPILE_WARNING_AS_ERROR=OFF.

PS. I have only tested on clang/gcc

Issue: #19085

Edited by Jiang Yi

Merge request reports