Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inconsistent behavior with CMakePreset.json file and cmake settings #3287

Closed
rhbroberg opened this issue Aug 7, 2023 · 3 comments
Closed

Comments

@rhbroberg
Copy link

Brief Issue Summary

Adding a CMakePresets.json file causes settings (user/remote/workspace) to be eventually ignored.

Create a project, add a single cpp file and a CMakeLists.txt to build it. In vscode, set the 'workspace' setting for 'cmake: build directory' to some unique path. Build and it will store objects in that path.

Add a CMakePresets.json file, define a preset. Choose a different compiler (clang vs. gcc for instance). Clean and build. It will store objects in the path defined in the 'cmake: build directory' as before.

Close directory, open it again. Now the project is starting out with the CMakePresets.json file present. Build the project: it will store the objects in ${sourceDir}/out/build/$preset-name. It now ignores the 'cmake: build directory' setting at the workspace (and user or remote level). In fact, many settings for cmake: are now ignored, not just the build directory.

This behavior persists until the CMakeUserPresets.json file is removed and vscode is restarted on that directory, then the behavior goes back to normal.

Essentially, a cmake preset causes cmake settings to be ignored. I would expect settings like 'build directory', or 'parallel jobs' if present in the vscode cmake extension, to take precedence over the preset as defined, but that does not seem to be the case.

CMake Tools Diagnostics

{
  "os": "linux",
  "vscodeVersion": "1.81.0",
  "cmtVersion": "1.15.30",
  "configurations": [
    {
      "folder": "/var/tmp/weird",
      "cmakeVersion": "3.20.2",
      "configured": true,
      "generator": "Unix Makefiles",
      "usesPresets": true,
      "compilers": {
        "C": "/usr/bin/clang",
        "CXX": "/usr/bin/clang++"
      }
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "Debug",
    "buildTypesSeen": [
      "Debug"
    ],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 1,
    "executablesCount": 1,
    "librariesCount": 0,
    "targets": [
      {
        "name": "groot",
        "type": "EXECUTABLE"
      }
    ]
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": null
    }
  ]
}

Debug Log

[main] Building folder: weird 
[main] Saving open files before configure/build
[build] Starting build
[driver] Start build all
[proc] Executing command: /usr/local/bin/cmake --build "/var/tmp/weird/out/build/clang me" --parallel 18 --target all
[proc]   with environment: {"HOSTNAME":"dev","SHELL":"/bin/bash","TMPDIR":"/tmp","VSCODE_AGENT_FOLDER":"/home/.vscode-server","PATH":"/home/.vscode-server/bin/6445d93c81ebe42c4cbd7a60712e0b17d9463e97/bin/remote-cli:/usr/java/default/bin:/opt/oracle/developerstudio12.6/bin:/usr/local/bin:/usr/lib/oracle/12.2/client64/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/sbin:/sbin:/bin","PWD":"/home/.vscode-server/bin/6445d93c81ebe42c4cbd7a60712e0b17d9463e97","JAVA_HOME":"/usr/java/default","LANG":"en_US.UTF-8","TZ":"US/Eastern","SHLVL":"2","HOME":"/home","container":"oci","_":"/usr/bin/cat","VSCODE_HANDLES_SIGPIPE":"true","VSCODE_AMD_ENTRYPOINT":"vs/workbench/api/node/extensionHostProcess","VSCODE_HANDLES_UNCAUGHT_ERRORS":"true","VSCODE_NLS_CONFIG":"{\"locale\":\"en\",\"osLocale\":\"en\",\"availableLanguages\":{}}","HISTSIZE":"1000","REMOTE_CONTAINERS_SOCKETS":"[\"/tmp/vscode-ssh-auth-cf19cc64-5cae-47b6-953c-b8f518abf631.sock\",\"/home/.gnupg/S.gpg-agent\"]","USER":"user","LD_LIBRARY_PATH":"/usr/lib/oracle/12.2/client64/lib","REMOTE_CONTAINERS_IPC":"/tmp/vscode-remote-containers-ipc-cf19cc64-5cae-47b6-953c-b8f518abf631.sock","MAIL":"/var/spool/mail/user","PLATFORM":"x86_64-unknown-linux-gnu","HISTCONTROL":"ignoredups","LOGNAME":"user","LESSOPEN":"||/usr/bin/lesspipe.sh %s","ORACLE_HOME":"/usr/lib/oracle/12.2/client64","SSH_AUTH_SOCK":"/tmp/vscode-ssh-auth-cf19cc64-5cae-47b6-953c-b8f518abf631.sock","REMOTE_CONTAINERS":"true","BROWSER":"/home/.vscode-server/bin/6445d93c81ebe42c4cbd7a60712e0b17d9463e97/bin/helpers/browser.sh","VSCODE_CWD":"/home/.vscode-server/bin/6445d93c81ebe42c4cbd7a60712e0b17d9463e97","ELECTRON_RUN_AS_NODE":"1","VSCODE_IPC_HOOK_CLI":"/tmp/vscode-ipc-a1316db5-29fa-4038-bbb5-db5c853045b9.sock","APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL":"1","VSCODE_L10N_BUNDLE_LOCATION":""}
[build] [100%] Built target groot
[driver] Build completed: 00:00:00.073
[cmakefileapi-parser] Read reply folder: /var/tmp/weird/out/build/clang me/.cmake/api/v1/reply
[cmakefileapi-parser] Found index files: ["cache-v2-898b9f0eab4f57295dc6.json","cmakeFiles-v1-f1ce79deddc1c0fbe751.json","codemodel-v2-68485b85a60ffb3fe0ac.json","index-2023-08-04T23-10-20-0771.json","target-groot-Debug-8c93840539a280d5f3a6.json","toolchains-v1-a68abc1439db6e2f3995.json"]
[build] Build finished with exit code 0
[cache] Reading CMake cache file /var/tmp/weird/out/build/clang me/CMakeCache.txt
[cache] Parsing CMake cache string
[extension] [6334] cmake.build finished (returned 0)
[cache] Reading CMake cache file /var/tmp/weird/out/build/clang me/CMakeCache.txt
[cache] Parsing CMake cache string

Additional Information

No response

@benmcmorran
Copy link
Member

Thanks for the report. This is related to #1836, and we plan to more holistically evaluate how settings from VS Code should interact with settings from CMakePresets in an upcoming release. I'm merging this issue with #1836.

@hamaney
Copy link

hamaney commented Sep 22, 2023

I've encountered this issue, and it's somewhat annoying. Thank you for working on fixing the root cause.

@jellybeane
Copy link

Sorry for necro-ing, but for anyone else still struggling with build dir settings:
#1836 and #3537 added support for overriding some CMakePresets settings, but not all.
In particular cmake.buildDirectory is not overridden: the build objects still go into ${sourceDir}/out/build/$preset-name instead of the Build Directory in the extension settings.

For reference, the specific fields that are supported:

  • cmake.environment (any cmake command)
  • cmake.configureArgs (configure)
  • cmake.configureEnvironment (configure)
  • cmake.buildArgs (build)
  • cmake.buildEnvironment (build)
  • cmake.buildToolsArgs (build, but specific to the build tool)
  • cmake.ctestArgs (test)
  • cmake.testEnvironment (test)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants