Giter Site home page Giter Site logo

Comments (10)

tengai650 avatar tengai650 commented on July 20, 2024 2

Ok, now this makes sense. However, I need to urge Microsoft they need to do a better job at explaining how "buildPresets" and "configurePresets" work in the IDE.

For example, this needs to be better explained:

  • single-config generators (e.g. Ninja) do not need buildPresets unless you want to set up different command line options for the build. The build type is already set during the configuration step.
  • multi-config generators (e.g. Visual Studio, Ninja Multi-Config) do need buildPresets - at the very least to select the active build type for the build.
  • When to add "CMAKE_BUILD_TYPE": "Release|Debug" and when to use "configuration": "Release|Debug" (so important!)

Unfortunately, the CMake documentation doesn't make these real-use-case very clear.

I was coming from Mac Visual Code and everything is working correctly. But this is because it uses "Unix makefiles" which is single-config generator and I was convinced the Visual Code and CMake on Windows was broken.

Thanks for the clarification!

Patrick

from vscode-cmake-tools.

bobbrow avatar bobbrow commented on July 20, 2024 1

I believe the understanding is: "many to one", many "buildPresets" to one "configurePresets". Originally, I thought it was "one to one".

You're almost there. The one correction is that it is actually one to one for single-config generators like Ninja. So your presets file would look more like this:

{
    "version": 6,
    "configurePresets": [
        {
            "name": "VS_x64",
            "hidden": false,
            "generator": "Visual Studio 17 2022",
            "binaryDir": "${workspaceFolder}/build/${presetName}",
            "description": "Visual build.",
            "cacheVariables": {
                 "BOOST_ROOT": "G:/dev/boost/boost_1_85_0"
            }
        },
        {
            "name": "Ninja_x64_Debug",
            "hidden": false,
            "generator": "Ninja",
            "binaryDir": "${workspaceFolder}/build/${presetName}",
            "description": "Ninja build.",
            "cacheVariables": {
                "CMAKE_EXPORT_COMPILE_COMMANDS": "YES",
                "BOOST_ROOT": "G:/dev/boost/boost_1_85_0",
                "CMAKE_BUILD_TYPE": "Debug"
            }
        },
        {
            "name": "Ninja_x64_Release",
            "hidden": false,
            "generator": "Ninja",
            "binaryDir": "${workspaceFolder}/build/${presetName}",
            "description": "Ninja build.",
            "cacheVariables": {
                "CMAKE_EXPORT_COMPILE_COMMANDS": "YES",
                "BOOST_ROOT": "G:/dev/boost/boost_1_85_0",
                "CMAKE_BUILD_TYPE": "Release"
            }
        }
    ],
    "buildPresets": [
        {
            "name": "Release_VC",
            "hidden": false,
            "description": "",
            "displayName": "",
            "configuration": "Release",
            "configurePreset": "VS_x64"
        },
        {
            "name": "Debug_VC",
            "hidden": false,
            "description": "",
            "displayName": "",
            "configuration": "Debug",
            "configurePreset": "VS_x64"
        }
    ]
}

It's somewhat confusing but an unfortunate artifact of the difference between single-config generators and multi-config generators.

  • single-config generators (e.g. Ninja) do not need buildPresets unless you want to set up different different command line options for the build. The build type is already set during the configuration step.
  • multi-config generators (e.g. Visual Studio, Ninja Multi-Config) do need buildPresets - at the very least to select the active build type for the build.

from vscode-cmake-tools.

bobbrow avatar bobbrow commented on July 20, 2024

CMAKE_BUILD_TYPE is not set by CMake when using a multi-config generator such as "Visual Studio 17 2022." This is because all build types will be generated in a single configuration pass. If you would like to select which build types are generated, you can use the CMAKE_CONFIGURATION_TYPES variable. Otherwise, if you need for CMAKE_BUILD_TYPE to exist during generation, you will need to switch to a single-config generator, such as Ninja.

from vscode-cmake-tools.

tengai650 avatar tengai650 commented on July 20, 2024

Ok, but VC is only building a debug exe. Why wouldn't it be buidling all types? How do I get a release build?

And what about this CMAKE_BUILD_TYPE_INT being set to debug? What is its purpose and how is it set to "release"?

from vscode-cmake-tools.

bobbrow avatar bobbrow commented on July 20, 2024

Ok, but VC is only building a debug exe. Why wouldn't it be buidling all types? How do I get a release build?

I'll need to set up a test case to double check, but to answer your question quickly, I believe you will need to add "buildPresets" to your CMakePresets.json. When you use a multi-config generator but don't provide any build presets, I believe CMake just picks the first one in the CMAKE_CONFIGURATION_TYPES variable when you try to build.

Starting with the information you shared earlier, it would like something like this (not tested, there could be a stray comma somewhere 😄)

{
  "version": 3,
  "configurePresets": [
    {
      "name": "vs",
      "displayName": "VS Custom preset",
      "description": "Sets Visual Studio generator, build and install directory",
      "generator": "Visual Studio 17 2022",
      "binaryDir": "${workspaceFolder}/build/${presetName}",
      "architecture": {
        "value": "x64",
        "strategy": "set"
      },
      "cacheVariables": {
        "BOOST_ROOT": "G:/dev/boost_1_85_0"
      }
    }
  ],
  "buildPresets": [
    {
      "name": "vs_debug",
      "configurePreset": "vs",
      "configuration": "Debug"
    },
    {
      "name": "vs_release",
      "configurePreset": "vs",
      "configuration": "Release"
    }
  ]
}

from vscode-cmake-tools.

bobbrow avatar bobbrow commented on July 20, 2024

And what about this CMAKE_BUILD_TYPE_INT being set to debug? What is its purpose and how is it set to "release"?

I don't see any documentation for it, so I suppose it is an internal variable and probably matches the first build type in the CMAKE_CONFIGURATION_TYPES list. You could probably test out that theory by changing CMAKE_CONFIGURATION_TYPES to something else. (e.g. Release;Debug;RelWithDebInfo;MinSizeRel)

from vscode-cmake-tools.

tengai650 avatar tengai650 commented on July 20, 2024

Ok. I think I'm starting to understand how "configurePresets" and "buildPresets" work.

I believe the understanding is: "many to one", many "buildPresets" to one "configurePresets". Originally, I thought it was "one to one".

For example here are Release/Debug "buildPresets" for different "configurePresets".

image
{
    "version": 6,
    "configurePresets": [
        {
            "name": "VS_x64",
            "hidden": false,
            "generator": "Visual Studio 17 2022",
            "binaryDir": "${workspaceFolder}/build/${presetName}",
            "description": "Visual build.",
            "cacheVariables": {
                 "BOOST_ROOT": "G:/dev/boost/boost_1_85_0"
            }
        },
        {
            "name": "Ninja_x64",
            "hidden": false,
            "generator": "Ninja",
            "binaryDir": "${workspaceFolder}/build/${presetName}",
            "description": "Ninja build.",
            "cacheVariables": {
                "CMAKE_EXPORT_COMPILE_COMMANDS": "YES",
                "BOOST_ROOT": "G:/dev/boost/boost_1_85_0"
            }
        }
    ],
    "buildPresets": [
        {
            "name": "Release_VC",
            "hidden": false,
            "description": "",
            "displayName": "",
            "configuration": "Release",
            "configurePreset": "VS_x64"
        },
        {
            "name": "Debug_VC",
            "hidden": false,
            "description": "",
            "displayName": "",
            "configuration": "Debug",
            "configurePreset": "VS_x64"
        },
        {
            "name": "Release_Ninja",
            "hidden": false,
            "description": "",
            "displayName": "",
            "configuration": "Release",
            "configurePreset": "Ninja_x64"
        },
        {
            "name": "Debug_Ninja",
            "hidden": false,
            "description": "",
            "displayName": "",
            "configuration": "Debug",
            "configurePreset": "Ninja_x64"
        }
    ]
}

from vscode-cmake-tools.

inkbottle-9 avatar inkbottle-9 commented on July 20, 2024

Ok, now this makes sense. However, I need to urge Microsoft they need to do a better job at explaining how "buildPresets" and "configurePresets" work in the IDE.

For example, this needs to be better explained:
...
Unfortunately, the CMake documentation doesn't make these real-use-case very clear.

I've almost encountered the same issue as you, and these discussions have now helped me understand. I couldn't agree with you more; the documentation indeed lacks some crucial (and conspicuous) explanations.

from vscode-cmake-tools.

v-frankwang avatar v-frankwang commented on July 20, 2024

@inkbottle-9 Thank you very much for your reply, our developers will continue to improve this document!

from vscode-cmake-tools.

gcampbell-msft avatar gcampbell-msft commented on July 20, 2024

@inkbottle-9 @tengai650 Thanks for the feedback. We've made notes on our side, but to best help move this forward, could you also create an issue on the Kitware repository so that they can be made aware of this feedback as well?
https://gitlab.kitware.com/cmake/cmake/-/issues

from vscode-cmake-tools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.