# Compilation option flags settings and default

**URL:** https://discourse.cmake.org/t/compilation-option-flags-settings-and-default/3393
**Category:** Code
**Tags:** os:windows
**Created:** [May 24, 2021, 1:29pm UTC](https://discourse.cmake.org/t/compilation-option-flags-settings-and-default/3393 "2021-05-24T13:29:25Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![serge](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/5f8ce5/32.png) [@serge](https://discourse.cmake.org/u/serge)
#### Post date: [May 24, 2021, 1:29pm UTC](https://discourse.cmake.org/t/compilation-option-flags-settings-and-default/3393/1 "2021-05-24T13:29:25Z")

</div>

Here is my code on windows OS:

* * *

## cmake\_minimum\_required (VERSION 3.19) project (try) set (CMAKE\_CXX\_FLAGS “”) set (CMAKE\_CXX\_FLAGS\_DEBUG “”) add\_executable(hello hello.cpp)

hello.cpp got compiled in the following way:  
CL.exe /c /nologo /W1 /WX- /diagnostics:classic /O2 /Oy- /D “CMAKE\_INTDIR="Debug"” /D \_MBCS /Gm- /MDd /GS /fp:precise /Zc:wchar\_t /Zc:forScope /Zc:inline /Fo"hello.dir\Debug\" /Fd"hello.dir\Debug\vc141.pdb" /Gd /TP /analyze- /errorReport:queue C:\Users\sayoun\work\tmp\hello.cpp

Remark:  
cmake is adding “/W1 /WX- /O2 /Oy- MDd /GS /fp:precise /Zc:wchar\_t /Zc:forScope /Zc:inline” although those were specifically emptied.  
Questions:

1. How do I reset completely the compilation flags - I do not want cmake to intervene and I would like to be able to do that for either debug or release configurations: complete control.
2. I would like to do the same with the linker options: not having cmake doing wise but wrong decisions.
3. Compilation / linking flags seem to be a complicated topic with add\_options / target\_add\_option / CMAKE\__FLAGS_ variable setting and also the COMPILE\_OPTIONS property - all those are involved to set the final compilation command in some order and priorities. Is there a clear documentation that explains how is this done by cmake.

Thanks,  
Serge

---

<div class="post-metadata">

### Author: ![serge](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/5f8ce5/32.png) [@serge](https://discourse.cmake.org/u/serge)
#### Post date: [May 26, 2021, 10:34am UTC](https://discourse.cmake.org/t/compilation-option-flags-settings-and-default/3393/2 "2021-05-26T10:34:33Z")

</div>

Answering to myself regarding (1) and (2)  
After looking extensively and it seems this question was a concern for a few in the past.  
Those flags are not initialized by cmake but by msbuild environment as a default. cmake does not add them by itself.  
So the question now is how to have msbuild environment to start from scratch.  
It would probably be a good request as a future feature to have a clean start build environment.

Thanks,  
Serge
