microsoft / vscode-cmake-tools

CMake integration in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=vector-of-bool.cmake-tools
MIT License
1.43k stars 430 forks source link

presets: setting cmake.buildToolArgs in configuration leads to build failures #3754

Closed JeremieA closed 6 days ago

JeremieA commented 1 month ago

Brief Issue Summary

-- is missing in the cmake build command line. Simple repro case attached (cmake-presets-build-tool-args.tar.gz) Steps to reproduce:

  1. uncompress the archive
  2. open the folder with vscode
  3. configure & try to build with cmake => FAIL (see log below)
  4. remove either CMakePresets.json or .vscode/settings.json and try again => SUCCESS

CMake Tools Diagnostics

No response

Debug Log

[main] Building folder: cmake-presets-build-tool-args 
[main] Configuring project: cmake-presets-build-tool-args 
[driver] NOTE: You are configuring with preset Default Config, but there are some overrides being applied from your VS Code settings.
[proc] Executing command: /usr/bin/cmake -S/home/jallard/cmake-presets-build-tool-args -B/home/jallard/cmake-presets-build-tool-args/build/default -G Ninja
[cmake] -- Configuring done (0.0s)
[cmake] -- Generating done (0.0s)
[cmake] -- Build files have been written to: /home/jallard/cmake-presets-build-tool-args/build/default
[build] Starting build
[driver] NOTE: You are building with preset default, but there are some overrides being applied from your VS Code settings.
[proc] Executing command: /usr/bin/cmake --build /home/jallard/cmake-presets-build-tool-args/build/default -n
[build] Unknown argument -n
[build] Usage: cmake --build <dir>             [options] [-- [native-options]]
[build]        cmake --build --preset <preset> [options] [-- [native-options]]
[build] Options:
[build]   <dir>          = Project binary directory to be built.
[build]   --preset <preset>, --preset=<preset>
[build]                  = Specify a build preset.
[build]   --list-presets[=<type>]
[build]                  = List available build presets.
[build]   --parallel [<jobs>], -j [<jobs>]
[build]                  = Build in parallel using the given number of jobs. 
[build]                    If <jobs> is omitted the native build tool's 
[build]                    default number is used.
[build]                    The CMAKE_BUILD_PARALLEL_LEVEL environment variable
[build]                    specifies a default parallel level when this option
[build]                    is not given.
[build]   -t <tgt>..., --target <tgt>...
[build]                  = Build <tgt> instead of default targets.
[build]   --config <cfg> = For multi-configuration tools, choose <cfg>.
[build]   --clean-first  = Build target 'clean' first, then build.
[build]                    (To clean only, use --target 'clean'.)
[build]   --resolve-package-references={on|only|off}
[build]                  = Restore/resolve package references during build.
[build]   -v, --verbose  = Enable verbose output - if supported - including
[build]                    the build commands to be executed. 
[build]   --             = Pass remaining options to the native tool.
[proc] The command: /usr/bin/cmake --build /home/jallard/cmake-presets-build-tool-args/build/default -n exited with code: 1
[driver] Build completed: 00:00:00.012
[build] Build finished with exit code 1

Additional Information

I already have a simple fix, will submit a PR...

Yingzi1234 commented 1 month ago

@JeremieA Thank you for your GitHub issue! We are trying to reproduce your issue, but in the process we have the following problem and we wanted to check with you, is this the expected result?

Repro steps:

  1. Download and open this project(cmake-presets-build-tool-args.tar.gz) by VSCode
  2. Click F1 to run "CMake: Build" command
  3. Re-run "CMake: Build" command

Actual result: Both builds fail with the following error in the output window

Output window: [main] Building folder: cmake-presets-build-tool-args [main] Configuring project: cmake-presets-build-tool-args [proc] Executing command: "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.EXE" -SC:/Users/v-cathyzhang/Desktop/cmake-presets-build-tool-args/cmake-presets-build-tool-args -BC:/Users/v-cathyzhang/Desktop/cmake-presets-build-tool-args/cmake-presets-build-tool-args/build/default -G Ninja [cmake] CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool. [cmake] CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage [cmake] -- Configuring incomplete, errors occurred! [proc] The command: "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.EXE" -SC:/Users/v-cathyzhang/Desktop/cmake-presets-build-tool-args/cmake-presets-build-tool-args -BC:/Users/v-cathyzhang/Desktop/cmake-presets-build-tool-args/cmake-presets-build-tool-args/build/default -G Ninja exited with code: 1 image

JeremieA commented 1 month ago

@Yingzi1234 thanks for trying to reproduce it. I should have mentioned that my repro case was only tested on Linux.

It should work on Windows by replacing the presets file with this version: CMakePresets.json After updating the file and opening the folder in VSCode, the "Ninja/MSVC v143" configure preset needs to be selected.

Here is the output in this case:

[main] Building folder: cmake-presets-build-tool-args 
[main] Configuring project: cmake-presets-build-tool-args 
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" -DCMAKE_C_COMPILER=cl -SF:/cmake-presets-build-tool-args -BF:/cmake-presets-build-tool-args/build/ninja_msvc -G "Ninja Multi-Config"
[cmake] -- The C compiler identification is MSVC 19.36.32534.0
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe - skipped
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Configuring done (1.5s)
[cmake] -- Generating done (0.0s)
[cmake] -- Build files have been written to: F:/cmake-presets-build-tool-args/build/ninja_msvc
[build] Starting build
[driver] NOTE: You are building with preset ninja_msvc, but there are some overrides being applied from your VS Code settings.
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build F:/cmake-presets-build-tool-args/build/ninja_msvc -n
[build] Unknown argument -n
[build] Usage: cmake --build <dir>             [options] [-- [native-options]]
[build]        cmake --build --preset <preset> [options] [-- [native-options]]
[build] Options:
[build]   <dir>          = Project binary directory to be built.
[build]   --preset <preset>, --preset=<preset>
[build]                  = Specify a build preset.
[build]   --list-presets[=<type>]
[build]                  = List available build presets.
[build]   --parallel [<jobs>], -j [<jobs>]
[build]                  = Build in parallel using the given number of jobs. 
[build]                    If <jobs> is omitted the native build tool's 
[build]                    default number is used.
[build]                    The CMAKE_BUILD_PARALLEL_LEVEL environment variable
[build]                    specifies a default parallel level when this option
[build]                    is not given.
[build]   -t <tgt>..., --target <tgt>...
[build]                  = Build <tgt> instead of default targets.
[build]   --config <cfg> = For multi-configuration tools, choose <cfg>.
[build]   --clean-first  = Build target 'clean' first, then build.
[build]                    (To clean only, use --target 'clean'.)
[build]   --resolve-package-references={on|only|off}
[build]                  = Restore/resolve package references during build.
[build]   -v, --verbose  = Enable verbose output - if supported - including
[build]                    the build commands to be executed. 
[build]   --             = Pass remaining options to the native tool.
[proc] The command: "C:\Program Files\CMake\bin\cmake.EXE" --build F:/cmake-presets-build-tool-args/build/ninja_msvc -n exited with code: 1
[driver] Build completed: 00:00:00.065
[build] Build finished with exit code 1
Yingzi1234 commented 1 month ago

@gcampbell-msft @JeremieA We can reproduce this issue on latest version, you can get the details below.

ENV: VSCode version: 1.89.1 CMake tools version: v1.18.39(pre-release) C/C++ version: v1.20.5

Repro steps:

  1. Open this project cmake-presets-build-tool-args.zip with VSCode
  2. Click F1 to run "CMake: Build" command
  3. Select the configure preset "Ninja/MSVC v143"

Actual result: The build will fail.

Output window:

[proc] The command: C:\Windows\System32\where.exe cl exited with code: 1
[preset] Configure preset ninja_msvc: No toolset version specified for cl.exe, using latest by default
[preset] Using developer environment from Visual Studio (instance fafbec2e, version 17.9.34902.65, installed at "C:\Program Files\Microsoft Visual Studio\2022\Community")
[proc] Executing command: chcp
[visual-studio] Patch Windows SDK path from C:\Program Files (x86)\Windows Kits\10\bin\x64 to C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64 for C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat
[proc] The command: C:\Windows\System32\where.exe ninja exited with code: 1
[preset] Ninja is not set on PATH, trying to use C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja\ninja.exe
[main] Configuring project: cmake-presets-build-tool-args 
[proc] Executing command: "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.EXE" -DCMAKE_C_COMPILER=cl "-SC:/Users/v-cathyzhang/Desktop/cmake-presets-build-tool-args (1)/cmake-presets-build-tool-args" "-BC:/Users/v-cathyzhang/Desktop/cmake-presets-build-tool-args (1)/cmake-presets-build-tool-args/build/ninja_msvc" -G "Ninja Multi-Config"
[cmake] -- The C compiler identification is MSVC 19.39.33523.0
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64/cl.exe - skipped
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Configuring done (10.4s)
[cmake] -- Generating done (0.0s)
[cmake] -- Build files have been written to: C:/Users/v-cathyzhang/Desktop/cmake-presets-build-tool-args (1)/cmake-presets-build-tool-args/build/ninja_msvc
[main] Building folder: cmake-presets-build-tool-args 
[build] Starting build
[driver] NOTE: You are building with preset ninja_msvc, but there are some overrides being applied from your VS Code settings.
[proc] Executing command: "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.EXE" --build "C:/Users/v-cathyzhang/Desktop/cmake-presets-build-tool-args (1)/cmake-presets-build-tool-args/build/ninja_msvc" -n
[build] Unknown argument -n
[build] Usage: cmake --build <dir>             [options] [-- [native-options]]
[build]        cmake --build --preset <preset> [options] [-- [native-options]]
[build] Options:
[build]   <dir>          = Project binary directory to be built.
[build]   --preset <preset>, --preset=<preset>
[build]                  = Specify a build preset.
[build]   --list-presets[=<type>]
[build]                  = List available build presets.
[build]   --parallel [<jobs>], -j [<jobs>]
[build]                  = Build in parallel using the given number of jobs. 
[build]                    If <jobs> is omitted the native build tool's 
[build]                    default number is used.
[build]                    The CMAKE_BUILD_PARALLEL_LEVEL environment variable
[build]                    specifies a default parallel level when this option
[build]                    is not given.
[build]   -t <tgt>..., --target <tgt>...
[build]                  = Build <tgt> instead of default targets.
[build]   --config <cfg> = For multi-configuration tools, choose <cfg>.
[build]   --clean-first  = Build target 'clean' first, then build.
[build]                    (To clean only, use --target 'clean'.)
[build]   --resolve-package-references={on|only|off}
[build]                  = Restore/resolve package references during build.
[build]   -v, --verbose  = Enable verbose output - if supported - including
[build]                    the build commands to be executed. 
[build]   --             = Pass remaining options to the native tool.
[proc] The command: "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.EXE" --build "C:/Users/v-cathyzhang/Desktop/cmake-presets-build-tool-args (1)/cmake-presets-build-tool-args/build/ninja_msvc" -n exited with code: 1
[driver] Build completed: 00:00:00.431
[build] Build finished with exit code 1