Don't know how to prevent CMake from generating /MDd compiler option

Hi all.
I am new to using CMake and have a very basic use case to build a cpp application on windows.
My current CMakeList.txt consists only consists of a view lines:

cmake_minimum_required(VERSION 3.15)
project(keep_awake VERSION 1.0)
add_executable(keep_awake keep_awake_non_svc.cpp WinCmdLineLauncher.cpp NetSessionResultParser.cpp)

When I build CMake generates a compiler command line with several compiler options:
cl /c /Zi /W1 /WX- /diagnostics:column /Od /Ob0 /Oy- /D _MBCS /D WIN32 /D _WINDOWS /D “CMAKE_INTDIR="Debug"” /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /Fo"keep_awake.dir\Debug\" /Fd"keep_awake.dir\Debug\vc143.pdb" /external:W1 /Gd /TP /analyze- /errorReport:queue E:\MyCppProjects\keep_awake\keep_awake_non_svc.cpp E:\MyCppProjects\keep_awake\WinCmdLineLauncher.cpp E:\MyCppProjects\keep_awake\NetSessionResultParser.cpp

However: I don’t want the “/MDd” flag.
How can I switch off such flags and the /MDd flag in particular?

Thanks a lot for any advice.

P.S.: One addition: I tried adding set(CMAKE_MSVC_RUNTIME_LIBRARY “”) to my CMakeLists.txt already. Then /MD is generated instead of /MDd which is also not what i want: I want to no /MD option at all

With CMake, MSVC is a multi-config generator, so you have muliple configurations generated in one go. The /MMd flag is included, because CMake defaults to building the debug version with MSVC.

The release version doesn’t have the debug options set. To compile the release version, type the following:
make --build --config Release

Hi Hans. Thanks a lot for your answer. I know how to steer whether /MD or /MDd or /MT or /MTd are used by switching configuration and/ or using the CMAKE_MSVC:RUNTIME_LIBRARY parameter. What i want is to have none of these four compiler flags (/MD /MDd /MT /MTd) in the call to the compiler. Also I would like to understand the mechanism how cmake “knows” that /MD should be a default compiler option.

Ah, okay. I don’t know if that’s possible. The MSVC_RUNTIME_LIBRARY documentation says that even if you set MSVC_RUNTIME_LIBRARY to “”, then the Visual Studio generator “may choose to add its own default runtime library selection flag.”

Hi all. After some reading and experimenting I discovered that cl.exe behaves identically with /MT specified and without /MT option.
So that for my use case the solution is to add:
set(CMAKE_MSVC_RUNTIME_LIBRARY “MultiThreaded$<$CONFIG:Debug:Debug>”)
set(CMAKE_MSVC_RUNTIME_LIBRARY “MultiThreaded$<$CONFIG:Release:Release>”)
to my CMakeLists.txt