A question about cmake-gui

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 :

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 :

# -- MT 
foreach(CompilerFlag ${CompilerFlags})
  string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")

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 MDs to MTs 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

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


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.

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.