Search code examples
visual-studiocmakecmake-presets

Visual Studio 2022 CMake Presets


I'm using CMake in my project and I'm beginning to explore the possibilities of CMakePresets

I managed to create a default windows preset. Currently my Windows default preset sets the CMAKE_BUILD_TYPE to debug. now I'd like to select the config in the left drop-down and the Build Type in the right drop-down (see image)

Is this somehow possible?

Thx for your help

enter image description here


Solution

  • I'm just understanding this myself, but I believe what you want is to set up "buildPresets" like so:

    {
       "name": "windows-debug",
       "displayName": "Debug",
       "configurePreset": "windows-default",
       "configuration": "Debug"
    },
    {
       "name": "windows-release",
       "displayName": "Release",
       "configurePreset": "windows-default",
       "configuration": "Release"
    }
    

    I believe "configuration" should be used instead of CMAKE_BUILD_TYPE as its identical to the flag --config as in

    > cmake --build . --config Release
    

    Source: https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html#build-preset