# A question about cmake-gui

**URL:** https://discourse.cmake.org/t/a-question-about-cmake-gui/2362
**Category:** Code
**Created:** [December 13, 2020, 4:34am UTC](https://discourse.cmake.org/t/a-question-about-cmake-gui/2362 "2020-12-13T04:34:23Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Coderx7](https://discourse.cmake.org/user_avatar/discourse.cmake.org/coderx7/32/837_2.png) [@Coderx7](https://discourse.cmake.org/u/Coderx7)
#### Post date: [December 13, 2020, 4:34am UTC](https://discourse.cmake.org/t/a-question-about-cmake-gui/2362/1 "2020-12-13T04:34:23Z")

</div>

Hello everyone, hope you are having a great day.  
I’m pretty new to CMake and I have some questions that I’d greatly appreciate if you could lend me a helping hand.  
Basically, I’m trying to build Pytorch from source on Windows and I want to build it using `/MT` flag instead of the `/MD` which is the default.  
I noticed if I use `cmake-gui` inside Pytorch’s root I am faced with something like this :

 ![image](https://discourse.cmake.org/uploads/default/original/2X/a/a09f8a72aaea4d3d1e0a3ff6f24a1e1114d6096f.png)  
As you can see there are build Options under the CMAKE group which I have already changed all MDs to MTs.  
This will create a visual studio project which I can use to build the libs and all is fine.  
However, I want to find out the exact files that these variables have come from (are defined inside) So that I can set the `MT` flag by default in them (for example set a variable that when enabled change the MDs to MTs and vice versa).  
Is there a way to know this? How should I go about this?  
Previously I went ahead and tried to change all cmake files that I find with snippets like :

```auto
# -- MT 
set(CompilerFlags
        CMAKE_CXX_FLAGS
        CMAKE_CXX_FLAGS_DEBUG
        CMAKE_CXX_FLAGS_RELEASE
        CMAKE_C_FLAGS
        CMAKE_C_FLAGS_DEBUG
        CMAKE_C_FLAGS_RELEASE
        )
foreach(CompilerFlag ${CompilerFlags})
  string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()

```

spuriously everywhere! and I got it to build but on debug configuration, I faced the `0xc0000142` error which I believe may have something to do with the way I’m changing the flags from `MD` to `MT`. Since when I changed the `MD`s to `MT`s from the options you can see above, I no more get that exception but a different error pops up at runtime (some linker like error :

> The procedure entry point ?mutable\_grad@AutogradMeta@autograd@torch@@UEAAAEAVTensor@at@@XY could not be located in the dynamic link library

to be exact )

Anyway being able to change that in the respective files would be a great help as I can further investigate this with the devs and they may be able to replicate this using Pytorch’s own script that builds the libraries (build\_libtorch.py which builds the libs without visual studio)

I appreciate any kind of help and thank you all a lot in advance

---

<div class="post-metadata">

### Author: ![anon45792294](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@anon45792294](https://discourse.cmake.org/u/anon45792294)
#### Post date: [December 13, 2020, 7:10pm UTC](https://discourse.cmake.org/t/a-question-about-cmake-gui/2362/2 "2020-12-13T19:10:23Z")

</div>

This problem of building with the static/dynamic library libraries on Windows was actually fixed very nicely in cmake 3.15 (Which is why I always recommend at least 3.15 for windows devs to my friends).

[https://cmake.org/cmake/help/latest/variable/CMAKE\_MSVC\_RUNTIME\_LIBRARY.html](https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html)

Using this variable you should be able to use the version of the library you desire.  
Usually I set this variable in my scripts right after the first project call.

```auto
project(foobar ...)

# Setup MSVC runtime to be static
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

```

This will override any manually set compiler flags that specified /MD /MT, as long as projects aren’t manually specifying the MSVC\_RUNTIME\_LIBRARY property.

I’m not sure how you should set this from cmake-gui though. I don’t really use cmake-gui that much.
