Troubles overriding MT/MD compilation flags

Hi!
I was working on transferring the project from using msbuild/make to cmake, and I encountered a problem overriding the -MD/-MDd compilation options

The FAQ | Wiki suggests using either manual replace or cmake flags override:
https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#how-can-i-build-my-msvc-application-with-a-static-runtime

However, at least for my configuration (CMake version 3.24.2, Ninja generator bundled with CLion 2022.3.2 version 1.10.2) none of it worked.

I have the following C/CXX overrides:

if(MSVC)
    set(CMAKE_C_FLAGS_DEBUG_INIT "/D_DEBUG /MTd /Zi /Ob0 /Od /RTC1")
    set(CMAKE_C_FLAGS_MINSIZEREL_INIT     "/MT /O1 /Ob1 /D NDEBUG")
    set(CMAKE_C_FLAGS_RELEASE_INIT        "/MT /O2 /Ob2 /D NDEBUG")
    set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "/MT /Zi /O2 /Ob1 /D NDEBUG")
endif()

if(MSVC)
    set(CMAKE_CXX_FLAGS_DEBUG_INIT "/D_DEBUG /MTd /Zi /Ob0 /Od /RTC1")
    set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT     "/MT /O1 /Ob1 /D NDEBUG")
    set(CMAKE_CXX_FLAGS_RELEASE_INIT        "/MT /O2 /Ob2 /D NDEBUG")
    set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "/MT /Zi /O2 /Ob1 /D NDEBUG")
endif()

These are set using:

# It is important to setup these flags before declaring client project
set(CMAKE_USER_MAKE_RULES_OVERRIDE "${CMAKE_SOURCE_DIR}/cmake/Setup/CFlagsOverride.cmake")
set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX "${CMAKE_SOURCE_DIR}/cmake/Setup/CXXFlagsOverride.cmake")

If I use my default generator - Visual Studio 16 2019 - it seems to work just fine
But for some reason, Ninja seems to add -MDd manually, resulting in unexpected behavior:

Below is an example of such an override, from CMake generation logs:

			"compileCommandFragments" : 
			[
				{
					"fragment" : "/DWIN32 /D_WINDOWS /GR /EHsc /D_DEBUG /MTd /Zi /Ob0 /Od /RTC1 -std:c++14 -MDd"
				},
...

I am pretty sure I do not override this anywhere else, as well as I am sure that none of my subprojects does, so it seems to me like a sort of generator bug or something.

For anyone who will meet the same problem: it seems that CMake implicitly adds CMAKE_MSVC_RUNTIME_LIBRARY as a compilation option parameter, and, by default, it seems to be evaluated as -MDd (The default value of the variable seems to be an empty string, tho I’m pretty sure there is some sort of naughty check, that adds the default value (-MD/-MDd) instead).
So, the best option here is to manually specify CMAKE_MSVC_RUNTIME_LIBRARY to something like this:

set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")