Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release target, Debug output #3829

Open
tengai650 opened this issue Jun 13, 2024 · 10 comments
Open

Release target, Debug output #3829

tengai650 opened this issue Jun 13, 2024 · 10 comments
Labels
documentation related to documentation of the extension question
Milestone

Comments

@tengai650
Copy link

Brief Issue Summary

Target is Release by setting "CMAKE_BUILD_TYPE": "Release" in the CMakePresets.json file.

using the CMake Debugger I see inconsistent values set:

image image

Output from build:
[build] Building Custom Rule G:/dev/cmaketest/CMakeLists.txt
[build] main.cpp
[build] cmaketest.vcxproj -> G:\dev\cmaketest\bin\Debug\cmaketest.exe

CMake Tools Diagnostics

[main] Building folder: cmaketest 
[expand] expanding cmake
[main] Saving open files before configure/build
[expand] expanding cmake
[expand] expanding cmake
[build] Starting build
[driver] Start build 
[expand] expanding --build
[expand] expanding g:/dev/cmaketest/build/vs_release
[expand] expanding --parallel
[expand] expanding 34
[proc] Executing command: "C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" --build g:/dev/cmaketest/build/vs_release --parallel 34
[proc]   with environment: {"ALLUSERSPROFILE":"C:\\ProgramData","AMDRMSDKPATH":"C:\\Program Files\\AMD\\RyzenMasterSDK\\","APPDATA":"C:\\Users\\tengai\\AppData\\Roaming","APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL":"1","CHROME_CRASHPAD_PIPE_NAME":"\\\\.\\pipe\\crashpad_40236_FRQZBGHRRJHZTDPK","COMPUTERNAME":"MSI_MAG","ComSpec":"C:\\Windows\\system32\\cmd.exe","CommonProgramFiles":"C:\\Program Files\\Common Files","CommonProgramFiles(x86)":"C:\\Program Files (x86)\\Common Files","CommonProgramW6432":"C:\\Program Files\\Common Files","DriverData":"C:\\Windows\\System32\\Drivers\\DriverData","EFC_6040":"1","ELECTRON_RUN_AS_NODE":"1","HOMEDRIVE":"C:","HOMEPATH":"\\Users\\tengai","LOCALAPPDATA":"C:\\Users\\tengai\\AppData\\Local","LOGONSERVER":"\\\\MSI_MAG","NUMBER_OF_PROCESSORS":"32","ORIGINAL_XDG_CURRENT_DESKTOP":"undefined","OS":"Windows_NT","OneDrive":"C:\\Users\\tengai\\OneDrive","PATHEXT":".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC","PROCESSOR_ARCHITECTURE":"AMD64","PROCESSOR_IDENTIFIER":"AMD64 Family 25 Model 97 Stepping 2, AuthenticAMD","PROCESSOR_LEVEL":"25","PROCESSOR_REVISION":"6102","PSModulePath":"C:\\Program Files\\WindowsPowerShell\\Modules;C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules","PUBLIC":"C:\\Users\\Public","Path":"C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;","ProgramData":"C:\\ProgramData","ProgramFiles":"C:\\Program Files","ProgramFiles(x86)":"C:\\Program Files (x86)","ProgramW6432":"C:\\Program Files","SESSIONNAME":"Console","SystemDrive":"C:","SystemRoot":"C:\\Windows","TEMP":"C:\\Users\\tengai\\AppData\\Local\\Temp","TMP":"C:\\Users\\tengai\\AppData\\Local\\Temp","USERDOMAIN":"MSI_MAG","USERDOMAIN_ROAMINGPROFILE":"MSI_MAG","USERNAME":"tengai","USERPROFILE":"C:\\Users\\tengai","VSCODE_AMD_ENTRYPOINT":"vs/workbench/api/node/extensionHostProcess","VSCODE_CODE_CACHE_PATH":"C:\\Users\\tengai\\AppData\\Roaming\\Code\\CachedData\\611f9bfce64f25108829dd295f54a6894e87339d","VSCODE_CRASH_REPORTER_PROCESS_TYPE":"extensionHost","VSCODE_CWD":"C:\\Users\\tengai\\AppData\\Local\\Programs\\Microsoft VS Code","VSCODE_HANDLES_UNCAUGHT_ERRORS":"true","VSCODE_IPC_HOOK":"\\\\.\\pipe\\e3ec2487-1.90.1-main-sock","VSCODE_L10N_BUNDLE_LOCATION":"","VSCODE_NLS_CONFIG":"{\"locale\":\"en-us\",\"osLocale\":\"en-us\",\"availableLanguages\":{},\"_languagePackSupport\":true}","VSCODE_PID":"40236","windir":"C:\\Windows"}
[build] MSBuild version 17.10.4+10fbfbf2e for .NET Framework
[build] 
[build]   1>Checking Build System
[build]   Building Custom Rule G:/dev/cmaketest/CMakeLists.txt
[build]   main.cpp
[build]   cmaketest.vcxproj -> G:\dev\cmaketest\bin\Debug\cmaketest.exe
[driver] Build completed: 00:00:00.676
[cmakefileapi-parser] Read reply folder: g:\dev\cmaketest\build\vs_release\.cmake\api\v1\reply
[cmakefileapi-parser] Found index files: ["cache-v2-4cdfd5cd365193e95fa0.json","cmakeFiles-v1-a99b99d1dcae1d8b6cbe.json","codemodel-v2-5aa90601171cace3b494.json","directory-.-Debug-d0094a50bb2071803777.json","directory-.-MinSizeRel-d0094a50bb2071803777.json","directory-.-Release-d0094a50bb2071803777.json","directory-.-RelWithDebInfo-d0094a50bb2071803777.json","index-2024-06-13T21-59-33-0164.json","target-ALL_BUILD-Debug-4f031107cb65c5d86a82.json","target-ALL_BUILD-MinSizeRel-4f031107cb65c5d86a82.json","target-ALL_BUILD-Release-4f031107cb65c5d86a82.json","target-ALL_BUILD-RelWithDebInfo-4f031107cb65c5d86a82.json","target-cmaketest-Debug-583dc167010728bf41c2.json","target-cmaketest-MinSizeRel-7b20aa68503247c998bd.json","target-cmaketest-Release-caf7a8a5d9ac7faaddd3.json","target-cmaketest-RelWithDebInfo-201f29ce9bf298a820d7.json","target-ZERO_CHECK-Debug-6262fa8b4446a7988aa8.json","target-ZERO_CHECK-MinSizeRel-6262fa8b4446a7988aa8.json","target-ZERO_CHECK-Release-6262fa8b4446a7988aa8.json","target-ZERO_CHECK-RelWithDebInfo-6262fa8b4446a7988aa8.json","toolchains-v1-9a5931a20e5c7dd3bed0.json"]
[expand] expanding cmake
[expand] expanding G:/dev/cmaketest
[build] Build finished with exit code 0
[expand] expanding cmake
[cache] Reading CMake cache file g:/dev/cmaketest/build/vs_release/CMakeCache.txt
[cache] Parsing CMake cache string
[expand] expanding cmake
[extension] [1603] cmake.build finished (returned 0)
[expand] expanding cmake
[cache] Reading CMake cache file g:/dev/cmaketest/build/vs_release/CMakeCache.txt
[cache] Parsing CMake cache string

Debug Log

No response

Additional Information

configurePresets": [
{
"name": "vs_release",
"displayName": "VS Release Custom preset",
"description": "Sets Visual Studio generator, build and install directory",
"generator": "Visual Studio 17 2022",
"binaryDir": "${workspaceFolder}/build/${presetName}",
"architecture": {
"value": "x64",
"strategy": "external"
},
"cacheVariables": {
"BOOST_ROOT": "G:/dev/boost_1_85_0",
"CMAKE_BUILD_TYPE": "Release"
}
}
]

@bobbrow
Copy link
Member

bobbrow commented Jun 13, 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.

@tengai650
Copy link
Author

tengai650 commented Jun 13, 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"?

@bobbrow
Copy link
Member

bobbrow commented Jun 13, 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"
    }
  ]
}

@bobbrow
Copy link
Member

bobbrow commented Jun 13, 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)

@tengai650
Copy link
Author

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"
        }
    ]
}

@bobbrow
Copy link
Member

bobbrow commented Jun 14, 2024

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.

@v-frankwang v-frankwang added more info needed More info is needed from the community for us to properly triage and investigate. and removed triage labels Jun 14, 2024
@bobbrow bobbrow added question and removed more info needed More info is needed from the community for us to properly triage and investigate. labels Jun 14, 2024
@tengai650
Copy link
Author

tengai650 commented Jun 14, 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:

  • 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

@bobbrow bobbrow added the documentation related to documentation of the extension label Jun 17, 2024
@inkbottle-9
Copy link

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.

@v-frankwang
Copy link
Collaborator

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

@gcampbell-msft gcampbell-msft added this to the Backlog milestone Jun 25, 2024
@gcampbell-msft
Copy link
Collaborator

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation related to documentation of the extension question
Projects
Status: Triage Needed
Development

No branches or pull requests

5 participants