Skip to content

refactor: make cmake.install a first-class operation using cmake --install#4758

Open
Copilot wants to merge 6 commits intomainfrom
copilot/add-cmake-install-component
Open

refactor: make cmake.install a first-class operation using cmake --install#4758
Copilot wants to merge 6 commits intomainfrom
copilot/add-cmake-install-component

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 25, 2026

This change addresses item #4281

This changes visible behavior

cmake.install was implemented as this.build(['install']), forcing install through cmake --build <dir> --target install. This doesn't match CMake's command model where build and install are distinct CLI actions, and blocks future install-specific flags like --component.

The following changes are proposed:

  • CMakeDriver.install() — new first-class driver method using cmake --install <dir>, with concurrency gating, telemetry, output encoding, and cancellation matching the existing build() pattern
  • CMakeDriver.getCMakeInstallCommand() — constructs install command with --config (multi-config generators) and --prefix (from cmake.installPrefix)
  • CMakeProject.install() — refactored from one-liner this.build(['install']) to proper install flow: ensureConfigured()drv.install() with progress/cancellation/output UX
  • CMakeTaskProvider.runInstallTask() — install tasks call cmakeDriver.install() directly instead of routing through runBuildTask()
  • Version fallback — CMake < 3.15 (where --install doesn't exist) automatically falls back to cmake --build --target install
  • 6 unit tests for install command construction covering single/multi-config, --prefix, and version gating

Before → After:

# Before: routed through build
cmake --build <dir> --config Release --target install

# After: first-class install
cmake --install <dir> --config Release --prefix /usr/local

Other Notes/Information

  • getCMakeInstallCommand() is public and returns a structured command object — adding --component in a follow-up is a one-line change
  • No API surface, telemetry event names, or cancellation behavior changes
  • Dead CommandType.install branch removed from correctTargets() since install no longer flows through build task dispatch
Original prompt

This section details on the original issue you should resolve

<issue_title>add CMake: Install Component</issue_title>
<issue_description>### Brief Issue Summary

This is a feature request for CMake: Build Target via Ctrl+Shift+P.

For build I can call CMake: Build and CMake: Build Target.

For install I can call CMake: Install but not CMake: Install Component because its missing. It should work analogously to CMake: Build Target.

Additional Information

I use CMake Tools 1.19.52 with VS Code 1.97.2.</issue_description>

<agent_instructions>You are Copilot coding agent acting as a senior maintainer for microsoft/vscode-cmake-tools. You are deeply familiar with CMake, CMake CLI modes (build, install, configure), VS Code extension APIs, and this TypeScript-heavy repo. Resolve the issue below safely, matching existing patterns.

SOURCE OF TRUTH

#4281 — Feature: Add CMake: Install Component command. The maintainer @gcampbell-msft confirmed this is a "medium" feature that should follow the pattern of CMake: Build Target. Read the full issue thread including comments.

ISSUE CONTEXT

CMake: Install runs cmake --build <dir> --target install, installing all components. CMake supports component-based install via cmake --install <dir> --component <name> (docs). There is no VS Code command to install a specific component.

Critical implementation detail: --component requires the cmake --install CLI mode (CMake 3.15+), which is a fundamentally different command than cmake --build --target install. The current install() method delegates to build(['install']) — this path cannot support components. A new execution path is needed.

KEY CODE LOCATIONS

Current install implementation:

  • src/cmakeProject.ts ~L2543: install()this.build(['install'], false, false, cancellationToken). No component support via this path.
  • src/extension.ts ~L1534-1547: ExtensionManager.install() and installAll() — command entry points. Follow this pattern for installComponent().
  • src/api.ts ~L146-157: CMakeProjectWrapper.install() and installWithResult() — API surface. Add installComponent variant.

Pattern to follow — CMake: Build Target:

  • src/cmakeProject.ts ~L2258-2274: buildWithTarget(specified_target?) — shows showTargetSelector() picker if no target specified, then builds. Mirror this for installComponent(component?).
  • src/cmakeProject.ts ~L2277-2367: showTargetSelector() — quick pick with fallback to showInputBox when no targets available. Create analogous showComponentSelector().
  • src/extension.ts ~L1579-1591: ExtensionManager.buildWithTarget() — command registration pattern to follow exactly.

CMake driver (where cmake is invoked):

  • src/drivers/cmakeDriver.ts ~L1950-2020: generateBuildCommandFromPreset() and getCMakeBuildCommand() — build command construction. You need a NEW method like runCMakeInstall(component, config?) that produces cmake --install <binaryDir> --component <name> [--config <config>] [--prefix <prefix>] and executes it via proc.execute.
  • src/drivers/cmakeDriver.ts ~L863: binaryDir getter — the build directory for cmake --install.
  • src/drivers/cmakeDriver.ts ~L883: installDir getter — use for --prefix if configured.
  • src/cmakeExecutable.ts ~L49-65: getCMakeExecutableInformation() — version detection. Use to enforce CMake ≥ 3.15.

Component discovery:

  • CMake does NOT expose install components via the File API. The CodeModelKind.InstallInfo (~src/drivers/cmakeFileApi.ts L140) has destinations/prefix but NOT component names.
  • Components ARE listed in <buildDir>/cmake_install.cmake as if(CMAKE_INSTALL_COMPONENT STREQUAL "<name>") blocks. Parse this file with a regex.
  • Fallback: if parsing fails or file doesn't exist, use showInputBox (matching how showTargetSelector falls back when drv.targets.length === 0).

Task provider:

  • src/cmakeTaskProvider.ts ~L21-70: CommandType enum and CMakeTaskDefinition. Add installComponent type with optional component field.
  • src/cmakeTaskProvider.ts ~L422-439: correctTargets() — hardcodes targets = ['install'] for install type. New type needs different handling.

Command registration:

  • package.json ~L484: cmake.install command. Add cmake.installComponent next to it.
  • package.nls.json ~L42: cmake-tools.command.cmake.install.title. Add installComponent title.
  • i18n files in i18n/*/package.i18n.json — add translations for the new command.

WHAT TO IMPLEMENT

  1. Component discoverygetInstallComponents() method on CMakeProject:
    • Read <buildDir>/cmake_install.cmake
    • Regex-extract component names from if(CMAKE_INSTALL_COMPONENT STREQUAL "<name>") patterns
    • Return `strin...

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI changed the title [WIP] Add CMake: Install Component command Add CMake: Install Component command Feb 25, 2026
Copilot AI requested a review from hanniavalera February 25, 2026 01:07
@hanniavalera hanniavalera marked this pull request as ready for review February 25, 2026 16:04
@hanniavalera hanniavalera force-pushed the copilot/add-cmake-install-component branch 2 times, most recently from 1f27e5d to a05c9c1 Compare February 27, 2026 18:56
@hanniavalera hanniavalera force-pushed the copilot/add-cmake-install-component branch from 7a216a5 to e4c6e3c Compare February 27, 2026 19:34
Copilot AI changed the title Add CMake: Install Component command Surface cmake --install stderr in Output channel and add permission error hint Feb 27, 2026
Copilot AI and others added 2 commits March 9, 2026 08:25
Add a new 'CMake: Install Component' command that uses 'cmake --install
<dir> --component <name>' to install specific CMake install components.

- Add parseInstallComponentsFromContent() to parse cmake_install.cmake
- Add getInstallComponents() method on CMakeProject
- Add showComponentSelector() with QuickPick and InputBox fallback
- Add installComponent() method on CMakeProject and ExtensionManager
- Register cmake.installComponent command in package.json
- Add unit tests for component parsing
- Require CMake >= 3.15 with version guard

Co-authored-by: hanniavalera <90047725+hanniavalera@users.noreply.github.com>
Co-authored-by: hanniavalera <90047725+hanniavalera@users.noreply.github.com>
@hanniavalera hanniavalera force-pushed the copilot/add-cmake-install-component branch from e4c6e3c to b9c91f2 Compare March 9, 2026 13:25
Copilot AI and others added 3 commits March 9, 2026 20:15
…stall

Previously, cmake.install was implemented as `this.build(['install'])`,
routing through `cmake --build <dir> --target install`. This didn't
match CMake's actual command model where build and install are distinct
CLI actions.

Now install uses `cmake --install <dir>` (CMake >= 3.15):
- Add CMakeDriver.getCMakeInstallCommand() for command construction
- Add CMakeDriver.install() as a first-class driver method with its own
  concurrency gating, telemetry, and output handling
- Refactor CMakeProject.install() to use drv.install() with proper
  progress/cancellation/output UX
- Add CMakeTaskProvider.runInstallTask() so install tasks use the new
  path instead of routing through runBuildTask
- Falls back to cmake --build --target install for CMake < 3.15
- Add 6 unit tests for install command construction

All existing API surface, telemetry, cancellation, and output behavior
is preserved. The install task and command-palette install now use the
same coherent code path.

Co-authored-by: hanniavalera <90047725+hanniavalera@users.noreply.github.com>
Remove the installComponent/installUtils code from previous PR
iterations. This branch should only contain the install refactor
that makes cmake.install a first-class operation.

Co-authored-by: hanniavalera <90047725+hanniavalera@users.noreply.github.com>
…t docs

Co-authored-by: hanniavalera <90047725+hanniavalera@users.noreply.github.com>
Copilot AI changed the title Surface cmake --install stderr in Output channel and add permission error hint refactor: make cmake.install a first-class operation using cmake --install Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add CMake: Install Component

2 participants