I have had a request to add support for CMake projects in the VS Code Swift extension.
The LSP server SourceKit-LSP supports CMake projects which have either a compile_commands.json or compile_flags.txt in their root folder. Given this I have added a trigger to enable the Swift extension whenever I find the file compile_commands.json (will add compile_flags.txt if this is required). This then will run SourceKit-LSP for that folder and give the user standard LSP functionality (code completion, jump to definition...).
I was wondering if there was any other CMake functionality users would want. For example generating compile_commands.json from CMakeFile.txt. I don't know a great deal about CMake, so don't know what might be needed. I don't intend to add support for features that are already provided by other CMake extensions though.
I don't have any feature requests (though I'm sure some of my colleagues do – particularly @ktoso@etcwilde@Douglas_Gregor) but just wanted to reply saying thank you for doing this! With the upcoming C++ interoperability, Swift is positioned as the ideal language to transition large C++ codebases to, and good integration with CMake will be key to this.
Thanks for fixing this. compile_flags.txt seems limited to providing flags for a single compiler/language and I can't remember the last time I only had one language in a project, so I don't really have a use for it.
No, you shouldn't have to do anything for generating the commands. CMake is supposed to produce the compile_commands.json file for the files in the project if you have CMAKE_EXPORT_COMPILE_COMMANDS set. There is a known bug where it doesn't produce the arguments/flags for Swift files due to how we're modeling Swift in the build at the moment. This will take a bit of refactoring. At least with your fix, VSCode will work out of the box once that starts working (or if someone hand edits the compile_commands.json file to include the compiler invocations for files they're interested in).