Skip to content

build: resolve cmake executable at configuration time#319

Merged
devcrocod merged 2 commits intodevelopfrom
build/detect-cmake-path
Apr 21, 2026
Merged

build: resolve cmake executable at configuration time#319
devcrocod merged 2 commits intodevelopfrom
build/detect-cmake-path

Conversation

@devcrocod
Copy link
Copy Markdown
Collaborator

Summary

  • When Gradle is launched from a GUI IDE on macOS (e.g. IntelliJ started via Spotlight/Dock), the Gradle daemon does not inherit Homebrew's /opt/homebrew/bin in PATH. The configure_cmake / compile_cmake Exec tasks invoke commandLine("cmake", ...) and fail with Cannot run program 'cmake', even when cmake is installed.
  • Resolve the cmake binary to an absolute path at configuration time via a new CmakeDetection helper:
    1. $CMAKE env var, if set and executable.
    2. Walk $PATH for the cmake (or cmake.exe) binary.
    3. Fall back to common install locations per platform (/opt/homebrew/bin, /usr/local/bin, /usr/bin, C:\Program Files\CMake\bin\cmake.exe, …).
    4. Last-resort: plain "cmake" (preserves current behaviour on unusual setups).
  • Updates multik.cmake-build.gradle.kts to use the resolved executable everywhere.

No behaviour change for CI (gcc/cmake are on PATH there); fixes the "works in terminal, fails in IDE" gotcha locally.

Test plan

  • ./gradlew :multik-openblas:build_cmake from a terminal shell — still works.
  • Reproduce the original failure: launch IDEA from Dock (no Homebrew PATH inherited) and run :multik-openblas:build_cmake — previously failed, now picks up /opt/homebrew/bin/cmake.
  • CMAKE=/some/other/cmake ./gradlew :multik-openblas:configureCmake — honours the env override.

Copilot AI review requested due to automatic review settings April 21, 2026 20:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves local developer experience by making the CMake invocation in multik-openblas Gradle tasks robust to missing PATH entries when Gradle is launched from GUI IDEs (notably on macOS), by resolving the cmake executable to a usable path up front.

Changes:

  • Add a CmakeDetection helper in buildSrc that selects a cmake executable from $CMAKE, $PATH, or common install locations.
  • Update the CMake Exec tasks to use the resolved executable instead of hardcoding "cmake".

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
buildSrc/src/main/kotlin/org/jetbrains/kotlinx/multik/builds/CmakeDetection.kt Introduces cmake discovery logic (env/PATH/common locations) for more reliable Exec execution.
buildSrc/src/main/kotlin/multik.cmake-build.gradle.kts Switches CMake task invocations to use CmakeDetection.executable.

@devcrocod devcrocod force-pushed the build/detect-cmake-path branch from 622d351 to 8f2411d Compare April 21, 2026 20:52
devcrocod added a commit that referenced this pull request Apr 21, 2026
Address Copilot review nits on #319:

- `File.canExecute()` alone returns true for directories with +x on POSIX,
  so a directory named `cmake` under a PATH entry (or in common install
  locations) could be incorrectly selected. Require `isFile && canExecute()`.
- A relative `$CMAKE` value (e.g. `./cmake-wrapper`) was returned as-is,
  contradicting the "absolute path" KDoc. Normalize all detected candidates
  via `absolutePath`.
GUI-launched IDEs on macOS don't inherit Homebrew's /opt/homebrew/bin PATH,
so the configure/compile Exec tasks invoking `commandLine("cmake", ...)`
can fail with "Cannot run program 'cmake'" even when cmake is installed.
Resolve an absolute cmake path at configuration time via CmakeDetection:
check $CMAKE env var, scan $PATH, then fall back to common install paths
for macOS/Linux/Windows.
Address Copilot review nits on #319:

- `File.canExecute()` alone returns true for directories with +x on POSIX,
  so a directory named `cmake` under a PATH entry (or in common install
  locations) could be incorrectly selected. Require `isFile && canExecute()`.
- A relative `$CMAKE` value (e.g. `./cmake-wrapper`) was returned as-is,
  contradicting the "absolute path" KDoc. Normalize all detected candidates
  via `absolutePath`.
@devcrocod devcrocod force-pushed the build/detect-cmake-path branch from d620cb0 to c54c17a Compare April 21, 2026 21:40
@devcrocod devcrocod merged commit 078ed37 into develop Apr 21, 2026
7 checks passed
@devcrocod devcrocod deleted the build/detect-cmake-path branch April 21, 2026 22:18
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.

2 participants