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 -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake