0

I build my project with MS Build Tools. Previously, I had been using the default VS generator. But now I have tried nmake JOM Makefiles generator and get the warning cl : Command line warning D9025 : overriding '/W3' with '/W4 -- as I have cmake_minimum_required(VERSION 3.14) in my CMakeLists.txt.

However, this warning appeared only on the first build. Then it disappeared. I tried to clean the build of course and removed all the AppData/Local/Temp files. I encoutered this warning a couple of more times when building my project but could not spot the cue. What can be thereason of such a strange behvior. Is there any cache some where for MS Build Tools?

I need to understand this to be able to correct my CMakeLists.txt and check that nobody gets the warning when building my project.

UPDATE:

I noticed that this happens when I change something in my CMakeLists.txt and then run cmake --build <dir>.

Then I get:

cl   ... /DWIN32 /D_WINDOWS /W3 /GR /EHsc /EHsc /W4 /WX /Zi /Ob0 /Od /RTC1 -MTd   -UUNICODE -U_UNICODE /showIncludes /FoCMakeFiles\project.dir\main.cpp.obj /FdCMakeFiles\project.dir\ /FS -c C:\project\main.cpp
cl : Command line warning D9025 : overriding '/W3' with '/W4'

My project contains /EHsc /W4 /WX flags.

However, I do not add /W3 /GR and an extra /EHsc anywhere.

JenyaKh
  • 2,040
  • 17
  • 25
  • Something in **your project** sets `/W4` option for the target which already has `/W3` option. May be this is done *conditionally*, as you observe the warning not all the times. Not sure what do you want from us. It is not CMake by itself, which adds both options implicitly. It is your project which adds at least one option, and without the project's code (in form of [mcve]) we cannot help you. You could start debugging from inspecting which exact target gets these options. This information could be easily deduced from the warning message. – Tsyvarev Apr 14 '22 at 07:40
  • I have updated by question and also suggested an answer -- though it explains the problem only partially. – JenyaKh Apr 15 '22 at 08:46
  • The question https://stackoverflow.com/questions/45995784/how-to-set-compiler-options-with-cmake-in-visual-studio-2017 describes how to set options like `/W4` in CMake. – Tsyvarev Apr 15 '22 at 09:20

1 Answers1

0

The reason that I get the warning only some times was that I used

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /W4 /WX")

rather than add_compile_options(/EHsc /W4 /WX).

I am not sure why. Maybe, somebody could comment on this or write better answer.

Anyway, when I used add_compile_options, the warning persisted, i.e. it appeared all the time -- as expected and more understandable.

I got rid of it by using

string(REGEX REPLACE "/W[1-3]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

as suggested here.

JenyaKh
  • 2,040
  • 17
  • 25