vscode-cmake-tools icon indicating copy to clipboard operation
vscode-cmake-tools copied to clipboard

[Bug] Running command `CMake: Set Build Target` does not show available targets in build folder

Open johnfranklinrickard opened this issue 6 months ago • 5 comments

Brief Issue Summary

Reproduce:

  • CTRL + SHIFT + P
  • Run: CMake: Set Build Target
  • Prompt asks me to select a default target

Expected to see a list of buildable cmake targets to select a build target from.

Bug: Actually just saw one build preset name and [Targets In Preset]

CMake Tools Diagnostics

{
  "os": "win32",
  "vscodeVersion": "1.101.0",
  "cmtVersion": "1.20.53",
  "configurations": [
    {
      "folder": "d:\\workspace\\mw2",
      "cmakeVersion": "4.0.2",
      "configured": true,
      "generator": "Ninja",
      "usesPresets": true,
      "compilers": {
        "C": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe",
        "CXX": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe"
      }
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "RelWithDebInfo",
    "buildTypesSeen": [
      "RelWithDebInfo"
    ],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 810,
    "executablesCount": 188,
    "librariesCount": 615,
    "targets": []
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": true
    }
  ]
}

Debug Log

[extension] [6976] cmake.setDefaultTarget started
[extension] [6976] cmake.setDefaultTarget finished (returned undefined)
[cache] Reading CMake cache file D:/workspace/mw2/buildninja/CMakeCache.txt
[cache] Parsing CMake cache string
[cache] Reading CMake cache file D:/workspace/mw2/buildninja/CMakeCache.txt
[cache] Parsing CMake cache string

Additional Information

The cmake.loggingLevel debug output is when I select [Targets In Preset].

Other features (like selecting debug or launch targets) correctly display all available cmake targets so that I can choose from them. But for some reason CMake: Set Build Target does not show all targets (and not even all my build presets, but thats unrelated to this case)

My current workaround is: Click the CMake button on the left (showing PROJECT STATUS, PROJECT OUTLINE, etc.) Then I go to PROJECT OUTLINE -> Search my target I want to build -> Right click -> Set as Build Target. Then it correctly sets the build target for the cmake extension (showing that it works to just set build targets that have no preset, its just not possible via the CMake: Set Build Target command.

johnfranklinrickard avatar Jul 09 '25 09:07 johnfranklinrickard

Hi @johnfranklinrickard, thank you for reporting this issue. We tried to check this issue in Visual Studio Code v1.101.0 + CMake Tools v1.20.53/v1.21.36. But we can't reproduce this issue. Could you help to take a look at it? If we missed something, please let us know. Thanks.

Image

yanghhhhhhh avatar Jul 10 '25 09:07 yanghhhhhhh

Hi, I might be experiencing the same issue. My target list is here: (completely empty)

Image

If i type a valid target name into it, it works as expected (starting a build passes --target correctly)

I am on Cursor (VSCode Version: 1.99.3) / CMake Tools 1.21.36

Other repositories I configure work correctly. Is there an upper limit of the number of targets? this new project has a higher target count.

I am using a base with a user presets

CMakePresets.json

{
    "version": 8,
    "cmakeMinimumRequired": {
        "major": 3,
        "minor": 27,
        "patch": 7
    },
    "configurePresets": [
        {
            "name": "ninja-debug-base",
            "displayName": "Ninja Debug BASE",
            "hidden": true,
            "description": "BASE CLASS Debug build using Ninja generator",
            "generator": "Ninja",
            "binaryDir": "${sourceDir}/build",
            "cacheVariables": {
                "CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
            }
        }
    ]
}

CMakeUserPresets.json

{
    "version": 8,
    "cmakeMinimumRequired": {
        "major": 3,
        "minor": 27,
        "patch": 7
    },
    "configurePresets": [
        {
            "name": "ninja-debug",
            "inherits": "ninja-debug-base",
            "displayName": "Ninja Debug",
            "description": "Default build using Ninja generator",
            "toolchainFile": "/Users/kevin/projects/vcpkg/scripts/buildsystems/vcpkg.cmake",
            "cacheVariables": {
                "HYDRA_FEATURE_DEBUGGER": "ON"
            }
        }
    ],
    "buildPresets": [
        {
            "name": "ninja-debug",
            "configurePreset": "ninja-debug",
            "jobs": 8
        }
    ]
}

kevin-- avatar Oct 28 '25 17:10 kevin--

Hi @kevin--, thank you for reporting this issue. We tried to check this issue in a simple project using Visual Studio Code v1.105.1 + CMake Tools v1.21.36. When executing the ‘CMake: Set Build Target’ command, the targets displayed are “all” and ‘Test’. Could you help to take a look at this issue? If we missed something, please let us know. Thanks.

Image

yanghhhhhhh avatar Oct 29 '25 03:10 yanghhhhhhh

Hi @yanghhhhhhh I'm not sure how exactly to reproduce it. I only know I have 1 repo that always works and 1 repo that does not work (same for other devs at my org)

If there are some commands / logs / diagnostics I can gather please let me know

kevin-- avatar Oct 30 '25 20:10 kevin--

@kevin-- Thank you for your reply. It seems this issue only occurs in specific projects. Is there any special configuration in your project and VS Code? Could you provide us with a sample project so that we can reproduce this issue? Thank you.

yanghhhhhhh avatar Oct 31 '25 03:10 yanghhhhhhh

I ran into the same (or similar) issue, where CMake: Set Build Target shows an empty list (and evaluation of ${command:cmake.launchTargetPath} fails). Note, I don't have cpptools installed, but clangd and CodeLLDB instead. Don't know if that has an impact.

Running the debugger with CMake Tools, I noticed that the _target_map in CMakeFileApiDriver has the desired target under the empty key ''. However, the lookup key is currentBuildType which is Debug, for example. So under this key nothing is found.

One solution was to explicitly set the build type in the preset:

CMakePresets.json

{
    "version": 10,
    "configurePresets": [
        {
            "name": "default",
            "generator": "Ninja",
            "binaryDir": "${sourceDir}/build/${presetName}",
            "cacheVariables": {
                "CMAKE_BUILD_TYPE": "Debug"
            }
        }
    ]
}

Is it a bug, to list no targets if they don't have a build type configured? Or is the user to blame?

chanselka avatar Dec 11 '25 23:12 chanselka

I have an empty CMake: Set Build Target list as well, using a multi-config generator (in which case setting CMAKE_BUILD_TYPE in "configurePresets" is nonsensical):

{
  "version": 9,
  "configurePresets": [
    {
      "name": "default",
      "generator": "Visual Studio 17 2022",
      "architecture": "x64",
      "binaryDir": "build",
      "toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
    }
  ],
  "buildPresets": [
    {
      "name": "default-release",
      "configurePreset": "default",
      "configuration": "release"
    },
    {
      "name": "default-relwithdebinfo",
      "configurePreset": "default",
      "configuration": "relwithdebinfo"
    },
    {
      "name": "default-debug",
      "configurePreset": "default",
      "configuration": "debug"
    }
  ]
}

MHebes avatar Dec 12 '25 19:12 MHebes

@MHebes have you tried using

            "cacheVariables": {
                "CMAKE_CONFIGURATION_TYPES": "Debug;Release;RelWithDebInfo"
            }

instead? See CMAKE_CONFIGURATION_TYPES.

Also, I noted that your configurations are lowercase. For me (using Ninja Multi-Target) I get an error that the configurations don't exist. Maybe changing them to upper helps...?

chanselka avatar Dec 13 '25 11:12 chanselka

Hi @MHebes, thank you for checking this issue. We tried to repro this issue using the sample code, could you please check if our repro steps are the same as yours? Please let us know if we missed anything. Thank you. Image

yanghhhhhhh avatar Dec 15 '25 06:12 yanghhhhhhh