Compilation option flags settings and default

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

1 Like

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