<div dir="ltr">From what I understand from a very limited quick search just now, it seems that /W3 is the default warning level for Visual Studio (according to the <a href="https://docs.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level?view=vs-2017">Microsoft docs</a>), but CMake <a href="https://gitlab.kitware.com/cmake/cmake/blob/master/Modules/Platform/Windows-MSVC.cmake#L360">explicitly adds it</a> as a default compiler flag in CMAKE_<LANG>_FLAGS_INIT. This makes me wonder if it has always been the default, otherwise it isn't clear why it was deemed necessary to add it. More to the point, unless there's a reason not to, perhaps we could consider removing it from the default flags CMake sets. I think this would largely address the situation you're describing and shouldn't actually change the behavior of existing projects. I've CC'ed the developer's list and suggest that follow-up discussion should occur there.<div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Sun, Dec 9, 2018 at 8:07 AM Mateusz Loskot <<a href="mailto:mateusz@loskot.net">mateusz@loskot.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
I define a target for a library, and set warning level for MSVC compiler:<br>
<br>
target_compile_options(mylib PRIVATE $<$<CXX_COMPILER_ID:MSVC>:-W4>)<br>
<br>
Although this works well, the compiler throws this warning:<br>
<br>
cl : Command line warning D9025: overriding '/W3' with '/W4'<br>
<br>
I want to get rid of this warning, so I fix it this way<br>
<br>
if(MSVC)<br>
  string(REGEX REPLACE "/W3" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})<br>
  string(REGEX REPLACE "-W3" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})<br>
endif()<br>
<br>
target_compile_options(mylib PRIVATE $<$<CXX_COMPILER_ID:MSVC>:-W4>)<br>
<br>
This works like charm, but leaves me with sour feeling that<br>
something is not right here.The REGEX REPLACE clean-up<br>
has become such a habit, it's almost canonical thing I do in<br>
all my CMake-based projects.<br>
<br>
Shouldn't CMake drop the default when target_compile_options is called?<br>
Is this behaviour by design, for MSVC?<br>
Could anyone help me to understand if this is actually a bug<br>
or am I misunderstanding anything?<br>
<br>
Best regards,<br>
-- <br>
Mateusz Loskot, <a href="http://mateusz.loskot.net" rel="noreferrer" target="_blank">http://mateusz.loskot.net</a><br>
-- <br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/listinfo/cmake</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr">Craig Scott<br><div>Melbourne, Australia</div><div><a href="https://crascit.com" target="_blank">https://crascit.com</a><br></div><div><br></div><div>New book released: <a href="https://crascit.com/professional-cmake/" target="_blank">Professional CMake: A Practical Guide</a><br></div></div></div></div></div></div></div>