[CMake] [MSVC] Setting warning level on target feels like long-time bug
Mateusz Loskot
mateusz at loskot.net
Sat Dec 8 16:07:15 EST 2018
Hi,
I define a target for a library, and set warning level for MSVC compiler:
target_compile_options(mylib PRIVATE $<$<CXX_COMPILER_ID:MSVC>:-W4>)
Although this works well, the compiler throws this warning:
cl : Command line warning D9025: overriding '/W3' with '/W4'
I want to get rid of this warning, so I fix it this way
if(MSVC)
string(REGEX REPLACE "/W3" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
string(REGEX REPLACE "-W3" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
endif()
target_compile_options(mylib PRIVATE $<$<CXX_COMPILER_ID:MSVC>:-W4>)
This works like charm, but leaves me with sour feeling that
something is not right here.The REGEX REPLACE clean-up
has become such a habit, it's almost canonical thing I do in
all my CMake-based projects.
Shouldn't CMake drop the default when target_compile_options is called?
Is this behaviour by design, for MSVC?
Could anyone help me to understand if this is actually a bug
or am I misunderstanding anything?
Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
More information about the CMake
mailing list