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

cmake.cmakePath does not resolve environment variables from cmake-tools-kits-json

Open pickard1 opened this issue 2 years ago • 1 comments

Brief Issue Summary

From cmake-tools-kits.json we use this entry

{ "name": "Ipetronik-Logger (x86 Develop)", "environmentVariables": { "IPE_CMAKE_TARGET": "x86", "IPE_EMBLX_PATH": "/home/fabrice/embeddedLinux/Develop/x86_build_develop" }, "toolchainFile": "/home/fabrice/embeddedLinux/Develop/x86_build_develop/host/usr/share/buildroot/toolchainfile.cmake", "isTrusted": true },

Try to use the environment variables "IPE_EMBLX_PATH" and "IPE_CMAKE_TARGET" in settings.json like this

"cmake.cmakePath": "${env:IPE_EMBLX_PATH}/build/host-cmake-3.16.9/bin/cmake", "cmake.buildDirectory": "${workspaceFolder}/build/${buildType}/${env:IPE_CMAKE_TARGET}",

"IPE_CMAKE_TARGET" in cmake.buildDirectory is correctly resolved. But "IPE_EMBLX_PATH" in cmake.cmakePath is always empty

Bad CMake executable: "/build/host-cmake-3.16.9/bin/cmake". Check to make sure it is installed or the value of the "cmake.cmakePath" setting contains the correct path

There are already simular issues around the substitution of environment variables. But I'm not sure if this point fits in anywhere.

CMake Tools Diagnostics

{
  "os": "linux",
  "vscodeVersion": "1.82.0-insider",
  "cmtVersion": "1.14.34",
  "configurations": [
    {
      "folder": "/home/fabrice/IPEmotionRT/DevelopNeu/IPEmotionRT",
      "cmakeVersion": "unknown",
      "configured": false,
      "generator": "unknown",
      "usesPresets": false,
      "compilers": {}
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "Debug",
    "buildTypesSeen": [
      "Debug"
    ],
    "requests": [
      "file:///home/fabrice/IPEmotionRT/DevelopNeu/IPEmotionRT/packages/PcixcanxlinDriver/drivers/ipetronik/pcixcanxlin/hwpcixcanxlin.c"
    ],
    "responses": [],
    "partialMatches": [],
    "targetCount": 204,
    "executablesCount": 41,
    "librariesCount": 104,
    "targets": []
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": null
    }
  ]
}

Debug Log

No response

Additional Information

No response

pickard1 avatar Aug 09 '23 06:08 pickard1

Thanks for the report. cmake.cmakePath is documented as supporting ${env:...} substitution, but it's possible that the kit environment variables aren't being applies before evaluating the substitution. I'm marking this as a bug that we hope to investigate in the 1.16 release.

benmcmorran avatar Aug 09 '23 16:08 benmcmorran

Hi, @pickard1.

Due to having zero upvotes from the community and the niche scenario, rather than implementing this addition to our ${env:<>} expansion for the cmake.cmakePath, we would suggest that if you want to have configuration specific cmake executables, to switch to CMakePresets! Configure Presets in CMake Presets allows you to specify configuration specific cmake executables through the cmakeExecutable field. https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html#configure-preset

Closing as won't fix. Please create an issue for any problems you hit if you switch to CMakePresets!

A very simple stub for a Configure Preset would be the following (you'll likely want to add more information to fully control what compilers you use, etc.)

{
            "name": "Ipetronik-Logger",
            "displayName": "Ipetronik-Logger (x86 Develop)",
            "environment": {
                "IPE_CMAKE_TARGET": "x86",
                "IPE_EMBLX_PATH": "/home/fabrice/embeddedLinux/Develop/x86_build_develop"
            },
            "cmakeExecutable": "${env:IPE_EMBLX_PATH}/build/host-cmake-3.16.9/bin/cmake"
        }

gcampbell-msft avatar Jul 25 '24 12:07 gcampbell-msft