Visual Studio Multi-config solution

Hello,

we are currently investigating switching from MPC (GitHub - DOCGroup/MPC: MPC (The Makefile, Project, and Workspace Creator)) to CMake. As a test, I am trying to convert a slightly larger C++ project to CMake. Now I am stuck on generating the Visual Studio solution.
With MPC we have generated one Visual Studio solution with 8 different configurations for the Windows platform:

  • Dll_Unicode_Release_StaticRTL = DLL, Unicode character set, release, statically linked runtime library (MultiThreaded)
  • Dll_Unicode_Debug_StaticRTL = DLL, Unicode character set, debug, statically linked debug runtime library (MultiThreadedDebug)
  • Dll_Unicode_Release_DllRTL = DLL, Unicode character set, release, dynamically linked runtime library (MultiThreadedDLL)
  • Dll_Unicode_Debug_DllRTL = DLL, Unicode character set, release, dynamically linked runtime library debug (MultiThreadedDebugDLL)
  • Dll_Ansi_Release_StaticRTL = The same with multi-byte character set
  • Dll_Ansi_Debug_StaticRTL = …
  • Dll_Ansi_Release_DllRTL = …
  • Dll_Ansi_Debug_DllRTL = …

My idea was to map this project structure using presets. I was able to create a solution with the different configurations, but then I failed to assign the different options to the individual configurations within the solution. I didn’t find a way to do this either in the presets themselves or via generator expressions.

Since I’m relatively new to CMake, I wanted to ask here what is the right way to do something like this in Cmake? Is something like this even possible with Cmake? Or is the only sensible solution to create 8 different Visual Studion solutions for the described configurations?

Here is a small snippet of the preset, which shows what I want to achive. Mabe it helps a little bit.

{
    "version": 6,
    "include": [
        "CMakeBasicPresets.json"
    ],
    "configurePresets": [
        {
            "name": "vc14_multiconfig",
            "description": "All Windows x86 Win32 configurations combined in one solution",
            "inherits": [ "vc14_win32_generic" ],
            "cacheVariables": {
                "CMAKE_CONFIGURATION_TYPES": "VC14_DLL_ANSI_RELEASE_STATICRTL;VC14_DLL_ANSI_DEBUG_STATICRTL;VC14_DLL_UNICODE_RELEASE_DLLRTL;VC14_DLL_UNICODE_DEBUG_DLLRTL",
                "CMAKE_CXX_FLAGS_VC14_DLL_ANSI_RELEASE_STATICRTL": "/W1 /MP /Zi",
                "CMAKE_CXX_FLAGS_VC14_DLL_ANSI_DEBUG_STATICRTL": "/W1 /MP",
                "CMAKE_CXX_FLAGS_VC14_DLL_UNICODE_RELEASE_DLLRTL": "/W1 /MP /Zi /D _UNICODE",
                "CMAKE_CXX_FLAGS_VC14_DLL_UNICODE_DEBUG_DLLRTL": "/W1 /MP /D _UNICODE",

                "CMAKE_SHARED_LINKER_FLAGS_VC14_DLL_ANSI_RELEASE_STATICRTL":"/DEBUG /OPT:REF /OPT:ICF",
                "CMAKE_SHARED_LINKER_FLAGS_VC14_DLL_UNICODE_RELEASE_DLLRTL":"/DEBUG /OPT:REF /OPT:ICF",

                "CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreadedDebugDLL"
            }
        }
    ],
    "buildPresets": [
        {
            "name": "VC14_DLL_UNICODE_RELEASE_DLLRTL",
            "displayName": "VC14_DLL_UNICODE_RELEASE_DLLRTL",
            "configurePreset": "vc14_multiconfig",
            "targets": "install",
            "jobs": 12,
            "cleanFirst": true,
            "configuration": "VC14_DLL_UNICODE_RELEASE_DLLRTL",
            "inherits": [ "vc14" ]
        }
    ],
    "workflowPresets": [
        {
            "name": "VC14_DLL_UNICODE_RELEASE_DLLRTL",
            "steps": [
                {
                    "type": "configure",
                    "name": "vc14_multiconfig"
                },
                {
                    "type": "build",
                    "name": "VC14_DLL_UNICODE_RELEASE_DLLRTL"
                }
            ]
        }
    ]
}

This works so far, except for the configuration specifc assignment of the Windows runtime library. As far as I know, there is no configuration specific CMAKE_MSVC_RUNTIME_LIBRARY variable. And I can´t set the compiler/linker flags for the runtime library directly, because it will be overwritten by the default value of the CMAKE_MSVC_RUNTIME_LIBRARY variable defined internaly by CMake.

Can anyone help me to solve this? How can I set CMAKE_MSVC_RUNTIME_LIBRARY on a configuration specific basis?