Comments (10)
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.
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.
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.
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.
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.
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.
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](https://private-user-images.githubusercontent.com/12106021/339590762-1fbac0b9-4e2a-49e4-a011-6d891ea92f4c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk4NDY2MDIsIm5iZiI6MTcxOTg0NjMwMiwicGF0aCI6Ii8xMjEwNjAyMS8zMzk1OTA3NjItMWZiYWMwYjktNGUyYS00OWU0LWEwMTEtNmQ4OTFlYTkyZjRjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzAxVDE1MDUwMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTBkODFlOGNhNTYxYmIyMDU3YjYxZWUzYzM1ZjA3NTJmMGRmNGYzMjIwMzQ2ZmY5MDNiZWM5ZmFhMzQwZWQxMDAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.Tq6tWC5n8xHMe8BI9IUexJFTlAZxyIgfmsAul2tielc)
{
"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.
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.
@inkbottle-9 Thank you very much for your reply, our developers will continue to improve this document!
from vscode-cmake-tools.
@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)
- project outline doesn't show header files if grpc src (.cc) is added HOT 1
- Why CMAKE_BUILD_TYPE is always Debug? HOT 16
- Why not add a feature to set launch args and debug args just in the GUI tool? HOT 1
- How come my build presets don't show up in the Build Preset List? HOT 3
- Source and build directories should be configurable per kit
- CMake Error: Not a file: G:/dev/cmaketest HOT 4
- CMake Tools cause probleme HOT 1
- `CMakeUserPresets.json` not visible in PROJECT OUTLINE HOT 1
- I dont now what is this error HOT 1
- Old project name present in Project Outline after project was renamed HOT 3
- Please configure CMake to build and run the tests I'm running HOT 1
- Test Discovery and Test results not working due to Path problem HOT 2
- Feature Request: Make `Compile active file` a first-class citizen
- Project Outline Does Not Show included cmake files HOT 1
- Custom visualStudio kit PATH setting is ineffective HOT 2
- When a compiler is upgraded, the older version of the compiler is not removed from the toolkit list. HOT 1
- usepresets context is not set after manually creating a cmakepresets.json HOT 3
- The CMake: Select a kit command does not work the first time you click on it.
- The code in the main.cpp file generated using CMake: Quick start is C code HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vscode-cmake-tools.