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

**URL:** <https://discourse.cmake.org/t/dont-know-how-to-prevent-cmake-from-generating-mdd-compiler-option/10545>\
**Category:** Code\
**Tags:** os:windows\
**Created:** [March 31, 2024, 7:41pm UTC](https://discourse.cmake.org/t/dont-know-how-to-prevent-cmake-from-generating-mdd-compiler-option/10545 "2024-03-31T19:41:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![c4711](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/4af34b/32.png) [@c4711](https://discourse.cmake.org/u/c4711)\
**Post date:** [March 31, 2024, 7:41pm UTC](https://discourse.cmake.org/t/dont-know-how-to-prevent-cmake-from-generating-mdd-compiler-option/10545/1 "2024-03-31T19:41:49Z")

</div>

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)  
set(CMAKE\_EXPORT\_COMPILE\_COMMANDS ON)  
set(CMAKE\_VERBOSE\_MAKEFILE ON)  
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

---

<div class="post-metadata">

**Author:** ![ksdhans](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ksdhans/32/3964_2.png) [@ksdhans](https://discourse.cmake.org/u/ksdhans)\
**Post date:** [April 1, 2024, 4:26am UTC](https://discourse.cmake.org/t/dont-know-how-to-prevent-cmake-from-generating-mdd-compiler-option/10545/2 "2024-04-01T04:26:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![c4711](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/4af34b/32.png) [@c4711](https://discourse.cmake.org/u/c4711)\
**Post date:** [April 1, 2024, 6:36am UTC](https://discourse.cmake.org/t/dont-know-how-to-prevent-cmake-from-generating-mdd-compiler-option/10545/3 "2024-04-01T06:36:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ksdhans](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ksdhans/32/3964_2.png) [@ksdhans](https://discourse.cmake.org/u/ksdhans)\
**Post date:** [April 1, 2024, 7:31am UTC](https://discourse.cmake.org/t/dont-know-how-to-prevent-cmake-from-generating-mdd-compiler-option/10545/4 "2024-04-01T07:31:36Z")

</div>

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.”

---

<div class="post-metadata">

**Author:** ![c4711](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/4af34b/32.png) [@c4711](https://discourse.cmake.org/u/c4711)\
**Post date:** [April 1, 2024, 9:48am UTC](https://discourse.cmake.org/t/dont-know-how-to-prevent-cmake-from-generating-mdd-compiler-option/10545/5 "2024-04-01T09:48:03Z")

</div>

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
