# Compiler option stripped by Visual Studio generator?

**URL:** https://discourse.cmake.org/t/compiler-option-stripped-by-visual-studio-generator/6476
**Category:** Code
**Tags:** os:windows, gen:vs
**Created:** [September 13, 2022, 6:54pm UTC](https://discourse.cmake.org/t/compiler-option-stripped-by-visual-studio-generator/6476 "2022-09-13T18:54:34Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![bradlit](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/90ced4/32.png) [@bradlit](https://discourse.cmake.org/u/bradlit)
#### Post date: [September 13, 2022, 6:54pm UTC](https://discourse.cmake.org/t/compiler-option-stripped-by-visual-studio-generator/6476/1 "2022-09-13T18:54:34Z")

</div>

It seems the VS 16 code generator is stripping /Wall (all warnings), while the NMake and Ninja generators do not. Is this expected?

`cmake version 3.23.1`  
CMakeLists.txt:

```auto
cmake_minimum_required(VERSION 3.16.3)
project(hello)
add_executable(hello hello.c)
target_compile_options(hello PUBLIC /WX /Wall /W4)

```

`cmake -B cmake_out -S . -G "Visual Studio 16 2019" -A Win32`  
Resulting compiler command:

```auto
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\bin\HostX64\x86\CL.exe /c /Zi /nologo /W4 /WX /diagnostics:column /Od /Ob0 /Oy- /D _MBCS /D WIN32 /D _WINDOWS /D "CMAKE_INTDIR=\"Debug\"" /Gm- /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"hello.dir\Debug\\" /Fd"hello.dir\Debug\vc142.pdb" /external:W4 /Gd /TC /analyze- /errorReport:queue C:\dev\toolchain\hello.c

```

Notice that /Wall does not appear on the command line.

`cmake -B cmake_out -S . -G "NMake Makefiles"`  
With NMake, /Wall is present:

```auto
        echo /nologo /DWIN32 /D_WINDOWS /Zi /Ob0 /Od /RTC1 -MDd /WX /Wall /W4 /showIncludes /FoCMakeFiles\hello.dir\hello.c.obj /FdCMakeFiles\hello.dir\ /FS -c C:\dev\toolchain\hello.c > c:\dev\temp\nm522D.tmp
        C:\dev\cmake-3.23.1-windows-x86_64\cmake-3.23.1-windows-x86_64\bin\cmake.exe -E cmake_cl_compile_depends --dep-file=CMakeFiles\hello.dir\hello.c.obj.d --working-dir=C:\dev\toolchain\cmake_out --filter-prefix="Note: including file: " -- C:\PROGRA~2\MICROS~4\2019\ENTERP~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x86\cl.exe @c:\dev\temp\nm522D.tmp

```

Is this expected?

---

<div class="post-metadata">

### Author: ![bradlit](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/90ced4/32.png) [@bradlit](https://discourse.cmake.org/u/bradlit)
#### Post date: [September 13, 2022, 7:13pm UTC](https://discourse.cmake.org/t/compiler-option-stripped-by-visual-studio-generator/6476/2 "2022-09-13T19:13:20Z")

</div>

Looks like this is a result of a “lossy” translation to vcxproj and back.

Turns out `Wall` isn’t being stripped specifically, but earlier options are lost:

```auto
Wall: target_compile_options(hello PUBLIC /WX /W4 /Wall)
  W4: target_compile_options(hello PUBLIC /WX /Wall /W4)

```

The generated vcxproj has the Visual Studio XML setting for warning:

```auto
      <WarningLevel>Level4</WarningLevel>

```

or

```auto
      <WarningLevel>EnableAllWarnings</WarningLevel>

```

based on the last compile option given.

This results in a last-writer-wins overwrite that is different from the behavior of the compiler when both options are provided on the command line (the most verbose option wins).

I had expected target\_compile\_options to show up as raw compile options on the command line.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [September 14, 2022, 8:56pm UTC](https://discourse.cmake.org/t/compiler-option-stripped-by-visual-studio-generator/6476/3 "2022-09-14T20:56:58Z")

</div>

Sounds like an issue to me, though I’m not sure of the best way to fix it (sounds like a policy would be necessary).

Cc: @brad.king

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [September 15, 2022, 12:23pm UTC](https://discourse.cmake.org/t/compiler-option-stripped-by-visual-studio-generator/6476/4 "2022-09-15T12:23:06Z")

</div>

The VS generators parse out flags known to map to specific `.vcxproj` settings, and generate the settings instead. Both `/W4` and `/Wall` map to the `WarningLevel` setting. The last one wins, just as `/W3 /W4` would choose the latter in a direct `cl` command-line invocation.
