How can I specify the path to Ninja in VS Code CMake configuration without modifying my system's PATH environment variable?

huangapple go评论89阅读模式
英文:

How can I specify the path to Ninja in VS Code CMake configuration without modifying my system's PATH environment variable?

问题

以下是您要翻译的内容:

如您所见,我尝试了几种方法,但都没有成功:

CMakeSettings.json

{
    "configurations": [
        {
            "name": "riscv32",
            "generator": "Ninja"
        }
    ]
}

cmake-kits.json

[
  {
    "name": "riscv32-esp-elf-gcc",
    "isTrusted": true,
    "compilers": {
      "C": "/ProgramData/esp-idf-tools/tools/riscv32-esp-elf/esp-2022r1-11.2.0/riscv32-esp-elf/bin/riscv32-esp-elf-gcc.exe",
      "CXX": "/ProgramData/esp-idf-tools/tools/riscv32-esp-elf/esp-2022r1-11.2.0/riscv32-esp-elf/bin/riscv32-esp-elf-g++.exe"
    },
    "toolchainFile": "/ProgramData/esp-idf/tools/cmake/toolchain-esp32c3.cmake",
    "preferredGenerator": {
      "name": "Ninja"
    }
  }
]

settings.json

{

    "cmake.cmakePath": "/ProgramData/esp-idf-tools/tools/cmake/3.24.0/bin/cmake.exe",
    "cmake.configureArgs": [
        "-DCMAKE_MAKE_PROGRAM=/ProgramData/esp-idf-tools/tools/ninja/1.10.2/ninja.exe"
    ],
    "cmake.buildArgs": [
        "-DCMAKE_MAKE_PROGRAM=/ProgramData/esp-idf-tools/tools/ninja/1.10.2/ninja.exe"
    ],
    "cmake.additionalCompilerSearchDirs": [
        "/ProgramData/esp-idf-tools/tools/ninja/1.10.2"
    ]
}

加载时我总是得到以下错误:

[proc] The command: ninja --version failed with error: Error: spawn ninja ENOENT
[proc] The command: ninja-build --version failed with error: Error: spawn ninja-build ENOENT
[main] Unable to determine what CMake generator to use. Please install or configure a preferred generator, or update settings.json, your Kit configuration or PATH variable. Error: No usable generator found.

我希望避免向操作系统的 PATH 添加(又一个)条目。

英文:

As you can see I've tried a few approaches and none work:

CMakeSettings.json

{
    "configurations": [
        {
            "name": "riscv32",
            "generator": "Ninja"
        }
    ]
}

cmake-kits.json

[
  {
    "name": "riscv32-esp-elf-gcc",
    "isTrusted": true,
    "compilers": {
      "C": "/ProgramData/esp-idf-tools/tools/riscv32-esp-elf/esp-2022r1-11.2.0/riscv32-esp-elf/bin/riscv32-esp-elf-gcc.exe",
      "CXX": "/ProgramData/esp-idf-tools/tools/riscv32-esp-elf/esp-2022r1-11.2.0/riscv32-esp-elf/bin/riscv32-esp-elf-g++.exe"
    },
    "toolchainFile": "/ProgramData/esp-idf/tools/cmake/toolchain-esp32c3.cmake",
    "preferredGenerator": {
      "name": "Ninja"
    }
  }
]

settings.json

{

    "cmake.cmakePath": "/ProgramData/esp-idf-tools/tools/cmake/3.24.0/bin/cmake.exe",
    "cmake.configureArgs": [
        "-DCMAKE_MAKE_PROGRAM=/ProgramData/esp-idf-tools/tools/ninja/1.10.2/ninja.exe"
    ],
    "cmake.buildArgs": [
        "-DCMAKE_MAKE_PROGRAM=/ProgramData/esp-idf-tools/tools/ninja/1.10.2/ninja.exe"
    ],
    "cmake.additionalCompilerSearchDirs": [
        "/ProgramData/esp-idf-tools/tools/ninja/1.10.2"
    ]
}

On load I always get

[proc] The command: ninja --version failed with error: Error: spawn ninja ENOENT
[proc] The command: ninja-build --version failed with error: Error: spawn ninja-build ENOENT
[main] Unable to determine what CMake generator to use. Please install or configure a preferred generator, or update settings.json, your Kit configuration or PATH variable. Error: No usable generator found.

I want to avoid adding (yet another) entry to the operating system's PATH.

答案1

得分: 1

如果您不想修改系统的PATH环境变量,并且不是通过命令行调用CMake(在这种情况下,我建议您将您的命令包装在cmake -D env中,以添加到PATH),并且您正在尝试的方法尚未生效(您可以尝试重置扩展状态,可以使用命令面板中的CMake: Reset CMake Tools Extension State来执行此操作),那么您可以尝试在CMake工具的cmake.environment设置中使用${env:...} VS Code变量。例如:"cmake.environment": { "PATH": "<path-to-your-ninja>${pathSeparator}${env:PATH}" }

英文:

If you don't want to modify the system PATH environment variable, and you're not invoking CMake via commandline (in which case I'd suggest you wrap your commands with cmake -D env to prepend to the PATH), and what you're trying isn't already working (you might want to try resetting the extensions state, which you can do with the CMake: Reset CMake Tools Extension State in the command palette), then you can try using ${env:...} VS Code variables in CMake tools' cmake.environment setting. Ex. &quot;cmake.environment&quot;: { &quot;PATH&quot;: &quot;&lt;path-to-your-ninja&gt;${pathSeparator}${env:PATH}&quot; }.

huangapple
  • 本文由 发表于 2023年5月7日 03:59:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76190862.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定