I have a CMake project, which I am building with Microsoft Visual Studio 2019. I am trying to fix and remove all warnings, but there is one type which I can't disable or fix.
All of them are of the type:
Command line warning D9025: overriding '/W4' with '/w'
Command line warning D9025: overriding '/W3' with '/W4'
I tried fixing them, but I can't find out what's causing all of them.
My question is:
How can I disable the warnings using CMake? Or is there a surefire way to find the underlying cause of them and fix them?
This issue has been raised (here and here), and depending on your CMake version there are a couple solutions.
When building for MSVC with CMake, the compiler warning flags (like /W3) are added by default. In CMake 3.15, CMake introduced a fix for this, and the compiler warning flags are no longer automatically added so the warning should no longer appear. From the docs:
CMake 3.15 and above prefer to leave out warning flags from the value of
CMAKE_<LANG>_FLAGSby default.
Along with this fix, CMake introduced policy CMP0092, which allows you to switch back to the OLD behavior (adding the warning flags by default) if necessary.
If you are tied to a CMake version older than 3.15, you can manually manipulate the CMAKE_<LANG>_FLAGS variable to replace the warnings yourself using CMake's regular expressions. You can try something like this:
string(REGEX REPLACE "/W[3|4]" "/w" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With