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

Configuration from build presets ignored by Intellisense and launch #2099

Closed
vdilecce opened this issue Sep 1, 2021 · 4 comments
Closed

Comments

@vdilecce
Copy link

vdilecce commented Sep 1, 2021

Brief Issue Summary

When a multi-configuration generator is used, switching between build presets with different configuration field does not have any effect on Intellisense and on running a target.

Could be a duplicate of #2048, though presets are not mentioned there.

Expected:

When a build preset specifying a configuration is selected within a multi-configuration generator, the Intellisense should update accordingly, e.g. greying out configuration-specific macros, and when a target is run, the corresponding configuration should be run.

Apparent Behavior:

Independently of the configuration explicitly set in the build preset, Intellisense and launch stick to one specific configuration (e.g. Debug for Visual Studio 2017, or Release for Ninja Multi-Config on Linux).

CMake Tools Log

Despite a preset with configuration Release was selected, the target was run with cwd being the Debug subdirectory (which had not been built).

[main] Building folder: BugConfig main
[main] Saving open files before configure/build
[build] Starting build
[driver] Start build main
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build <...>/BugConfig/build --config Release --target main
[build] Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
[build] Copyright (C) Microsoft Corporation. All rights reserved.
[build] 
[build]   Checking Build System
[build]   Building Custom Rule <...>/BugConfig/CMakeLists.txt
[build]   main.cpp
[build]   main.vcxproj -> <...>\BugConfig\build\Release\main.exe
[cmakefileapi-parser] Read reply folder: <...>\BugConfig\build\.cmake\api\v1\reply
[cmakefileapi-parser] Found index files: ["cache-v2-121ff3c9589ebb0b21e3.json","codemodel-v2-c3617ff8fb2e27d9026a.json","index-2021-09-01T10-38-09-0353.json","target-ALL_BUILD-Debug-26f43c8a8230e42424ad.json","target-ALL_BUILD-MinSizeRel-26f43c8a8230e42424ad.json","target-ALL_BUILD-Release-26f43c8a8230e42424ad.json","target-ALL_BUILD-RelWithDebInfo-26f43c8a8230e42424ad.json","target-main-Debug-7a57a55050479694df12.json","target-main-MinSizeRel-3a14e363594358f25078.json","target-main-Release-3352a43c5c394f068913.json","target-main-RelWithDebInfo-d3caf86ba3c44bf7f1e8.json","target-ZERO_CHECK-Debug-27f3775ee8104935cb1f.json","target-ZERO_CHECK-MinSizeRel-27f3775ee8104935cb1f.json","target-ZERO_CHECK-Release-27f3775ee8104935cb1f.json","target-ZERO_CHECK-RelWithDebInfo-27f3775ee8104935cb1f.json","toolchains-v1-68ca53601f238da31200.json"]
[driver] Run _refreshExpansions
[driver] Run _refreshExpansions cb
[build] Build finished with exit code 0
[extension] [1015] cmake.build finished (returned 0)
[cache] Reading CMake cache file <...>/BugConfig/build/CMakeCache.txt
[cache] Parsing CMake cache string
[extension] [4786] cmake.launchTarget started
[main] Building folder: BugConfig main
[main] Saving open files before configure/build
[build] Starting build
[driver] Start build main
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build <...>/BugConfig/build --config Release --target main
[build] Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
[build] Copyright (C) Microsoft Corporation. All rights reserved.
[build] 
[build]   main.vcxproj -> <...>\BugConfig\build\Release\main.exe
[cmakefileapi-parser] Read reply folder: <...>\BugConfig\build\.cmake\api\v1\reply
[cmakefileapi-parser] Found index files: ["cache-v2-121ff3c9589ebb0b21e3.json","codemodel-v2-c3617ff8fb2e27d9026a.json","index-2021-09-01T10-38-09-0353.json","target-ALL_BUILD-Debug-26f43c8a8230e42424ad.json","target-ALL_BUILD-MinSizeRel-26f43c8a8230e42424ad.json","target-ALL_BUILD-Release-26f43c8a8230e42424ad.json","target-ALL_BUILD-RelWithDebInfo-26f43c8a8230e42424ad.json","target-main-Debug-7a57a55050479694df12.json","target-main-MinSizeRel-3a14e363594358f25078.json","target-main-Release-3352a43c5c394f068913.json","target-main-RelWithDebInfo-d3caf86ba3c44bf7f1e8.json","target-ZERO_CHECK-Debug-27f3775ee8104935cb1f.json","target-ZERO_CHECK-MinSizeRel-27f3775ee8104935cb1f.json","target-ZERO_CHECK-Release-27f3775ee8104935cb1f.json","target-ZERO_CHECK-RelWithDebInfo-27f3775ee8104935cb1f.json","toolchains-v1-68ca53601f238da31200.json"]
[driver] Run _refreshExpansions
[driver] Run _refreshExpansions cb
[build] Build finished with exit code 0
[cache] Reading CMake cache file <...>/BugConfig/build/CMakeCache.txt
[cache] Parsing CMake cache string
[extension] [4786] cmake.launchTarget finished (returned {"name":"CMake/Launch","processId":{},"creationOptions":{"name":"CMake/Launch","env":{<...>},"cwd":"<...>\\BugConfig\\build\\Debug","shellPath":"C:\\WINDOWS\\system32\\cmd.exe"}})

Minimal files to reproduce the issue:

settings.json:

{
  "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
  "C_Cpp.loggingLevel": "Debug",
  "cmake.loggingLevel": "debug",
  "cmake.useCMakePresets": "always"
}

CMakePresets.json (Here Visual Studio 2017 is considered, though Ninja Multi-Config shows the same behavior on Linux):

{
  "version": 2,
  "cmakeMinimumRequired": {
    "major": 3,
    "minor": 20,
    "patch": 0
  },
  "configurePresets": [
    {
      "name": "vs2017",
      "binaryDir": "build",
      "architecture": {
        "value": "x64",
        "strategy": "set"
      },
      "toolset": {
        "value": "host=x64",
        "strategy": "set"
      },
      "displayName": "Visual Studio 2017",
      "description": "Architecture x64 - Toolset v141",
      "generator": "Visual Studio 15 2017"
    }
  ],
  "buildPresets": [
    {
      "name": "vs2017-debug",
      "displayName": "Debug",
      "configuration": "Debug",
      "configurePreset": "vs2017"
    },
    {
      "name": "vs2017-release",
      "displayName": "Release",
      "configuration": "Release",
      "configurePreset": "vs2017"
    },
    {
      "name": "vs2017-relwithdebinfo",
      "displayName": "RelWithDebInfo",
      "configuration": "RelWithDebInfo",
      "configurePreset": "vs2017"
    },
    {
      "name": "vs2017-minsizerel",
      "displayName": "MinSizeRel",
      "configuration": "MinSizeRel",
      "configurePreset": "vs2017"
    }
  ]
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.20)

project(MAIN LANGUAGES CXX)

add_compile_definitions(
  "$<$<CONFIG:Debug>:CONFIG_DEBUG>"
  "$<$<CONFIG:Release>:CONFIG_RELEASE>"
  "$<$<CONFIG:RelWithDebInfo>:CONFIG_RELWITHDEBINFO>"
  "$<$<CONFIG:MinSizeRel>:CONFIG_MINSIZEREL>"
)

add_executable(main main.cpp)

main.cpp (Intellisense does not grey out the code according to the configuration selected):

#include <iostream>
#include <string>

int
main(int argc, char* argv[])
{
    std::string x;

#ifdef CONFIG_DEBUG
    x = "Debug";
#endif

#ifdef CONFIG_RELEASE
    x = "Release";
#endif

#ifdef CONFIG_RELWITHDEBINFO
    x = "RelWithDebInfo";
#endif

#ifdef CONFIG_MINSIZEREL
    x = "MinSizeRel";
#endif

    std::cout << x << std::endl;

    return 0;
}

Platform and Versions

  • Operating System: Windows 10 / Linux
  • CMake Version: 3.20.5
  • VSCode Version: 1.59.1
  • CMake Tools Extension Version: 1.8.0
  • C/C++ Extension Version: 1.6.0
  • Compiler/Toolchain: Visual Studio 2017 (Windows) / GCC with Ninja Multi-Config (Linux)
@bobbrow
Copy link
Member

bobbrow commented Sep 1, 2021

@xisui-MSFT could you take a look at this one?

@pilarArr
Copy link

I've had the same problem. Looking forward to the fix.

The workaround I'm using is defining CMAKE_BUILD_TYPE on the configuration preset.
It makes the CMakePresets longer since now you have to define two configurations, one for release and one for debug, and then two others on the build presets, one for release and one for debug.

Adding to the Preset above it would go like this.

{
  "version": 2,
  "cmakeMinimumRequired": {
    "major": 3,
    "minor": 20,
    "patch": 0
  },
  "configurePresets": [
    {
      "name": "vs2017-base",
      "binaryDir": "build",
      "architecture": {
        "value": "x64",
        "strategy": "set"
      },
      "toolset": {
        "value": "host=x64",
        "strategy": "set"
      },
      "hidden": true,
      "displayName": "Visual Studio 2017",
      "description": "Architecture x64 - Toolset v141",
      "generator": "Visual Studio 15 2017"
    },
    {
      "name": "config_debug",
      "hidden": true,
      "cacheVariables": {
        "CMAKE_BUILD_TYPE": {
          "type": "STRING",
          "value": "Debug"
        }
      }
    },
    {
      "name": "config_release",
      "hidden": true,
      "cacheVariables": {
        "CMAKE_BUILD_TYPE": {
          "type": "STRING",
          "value": "Release"
        }
      }
    },
    {
      "name": "vs2017-release",
      "inherits": ["vs2017-base", "config_release"],
      "displayName": "Visual Studio 2017 - Release"
    },
    {
      "name": "vs2017-debug",
      "inherits": ["vs2017-base", "config_debug"],
      "displayName": "Visual Studio 2017 - Debug"
    }
  ],
  "buildPresets": [
    {
      "name": "vs2017-debug",
      "displayName": "Debug",
      "configuration": "Debug",
      "configurePreset": "vs2017-debug"
    },
    {
      "name": "vs2017-release",
      "displayName": "Release",
      "configuration": "Release",
      "configurePreset": "vs2017-release"
    }
  ]
}

@xisui-MSFT
Copy link
Collaborator

The workaround I'm using is defining CMAKE_BUILD_TYPE on the configuration preset.
It makes the CMakePresets longer since now you have to define two configurations, one for release and one for debug, and then two others on the build presets, one for release and one for debug.

@pilarArr This only works around the problem in the original issue partially. Although launch would follow the type set in CMAKE_BUILD_TYPE, intellisense would still be wrong. Definitions like "$<$<CONFIG:Debug>:CONFIG_DEBUG>" depends on build configuration instead of CMAKE_BUILD_TYPE.

@andreeis andreeis added this to the 1.9.0 milestone Oct 4, 2021
@andreeis
Copy link
Contributor

This fix is included in the 1.9.0 CMake Tools release. Please upgrade your extension in VSCode and let us know if you encounter any other issues.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants