vscode-cmake-tools: Setting "cmake.exportCompileCommandsFile": true does not work with CMake Presets

Brief Issue Summary

Setting "cmake.exportCompileCommandsFile": true does not work with CMake Presets.

Expected:

  1. Set "cmake.exportCompileCommandsFile": true
  2. -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON is added to the CMake configure call even when on the presets path

Platform and Versions

  • Operating System: Ubuntu
  • CMake Version: 3.20.2
  • VSCode Version: 1.55.0
  • CMake Tools Extension Version: 1.7.1
  • Compiler/Toolchain: GCC 9.3.0

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 15 (2 by maintainers)

Most upvoted comments

I had the same issue last week. I am sad that the provided solution was not that intuitive… Using clangd or intellisense is an IDE related setting. Thus, I would expect those kind of settings that are not “build” related but rather “tooling” related, to pass through. On the other hand, I understand the hassle. Can we at least remove the “cmake.exportCompileCommandsFile” option if a cmake preset is detected? It is the default way to do cmake nowadays and it took me two days to understand what was going on. I think that @globberwops @mpusz and @bobbrow who reported this in the past will agree with the conditional removal of this setting

Ok, so this is by design. I can understand this as you want Cmake yield the same result regardless if launched from VS Code or command line. I think for users familiar with the variant/kit system transitioning to the preset system this is something with must be expressed very clearly in the documentation.

And yes, setting CMAKE_EXPORT_COMPILE_COMMANDS in the preset environment works, this is what we are presently doing:

    "configurePresets": [
        {
...
            "environment": {
                "CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
            },

But I still think that exportCompileCommandsFile is a setting not for cmake itself but for the IDE controlling it so I believe cmake.exportCompileCommandsFile should flow through as it does not affect the build but allows VS Code to parse it and offer compile command for single C files.

I like to add that

    "cmake.configureEnvironment": {
        "CMAKE_EXPORT_COMPILE_COMMANDS": "ON",  
    },

does not work either for presets.

As this setting relates more to the IDE and configures IDE features (eg compile commands being available to the IDE) I would think this should be controlled by the IDE’s cmake.exportCompileCommandsFile setting. The setting would not be required for out-of IDE builds and as such should not be in the configurePresets. It also would avoid having to edit existing project’s build settings just to get an IDE feature working.

Thank you for opening this report. You can specify this in the preset as well. I just verified that it works. “cacheVariables”: { “CMAKE_EXPORT_COMPILE_COMMANDS”: “ON” }

@xisui-MSFT, I don’t see any reason why presets wouldn’t pick up from regular settings but I am not sure, please confirm if this behavior is by design or we should fix something in CMake Tools. Is the user supposed to define the above when wanting compile_commands.json or the usual setting we had should have effect even with presets on?