# \[Bug\] CMake Swift: Bad compile-commands.json

**URL:** <https://forums.swift.org/t/bug-cmake-swift-bad-compile-commands-json/38298>\
**Category:** Source Tooling\
**Tags:** linux, cmake, sourcekit-lsp\
**Created:** [July 8, 2020, 6:07pm UTC](https://forums.swift.org/t/bug-cmake-swift-bad-compile-commands-json/38298 "2020-07-08T18:07:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![atyshka](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/atyshka/32/7812_2.png) [@atyshka](https://forums.swift.org/u/atyshka)\
**Post date:** [July 8, 2020, 6:07pm UTC](https://forums.swift.org/t/bug-cmake-swift-bad-compile-commands-json/38298/1 "2020-07-08T18:07:21Z")

</div>

I am developing a swift package without SPM, instead using CMake, and would like to make use of Sourcekit-LSP in VSCode. However, I am experiencing the issue mentioned [Here](https://gitlab.kitware.com/cmake/cmake/-/issues/19443) where my compile\_commands.json is not functional. @compnerd I know you helped develop swift support for CMake, do you or anyone else know if there's a way to get this working properly? Or something other than compile\_commands.json that will let Sourcekit work with non-SPM libraries?

---

<div class="post-metadata">

**Author:** ![compnerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/compnerd/32/2165_2.png) [@compnerd](https://forums.swift.org/u/compnerd)\
**Post date:** [July 8, 2020, 6:26pm UTC](https://forums.swift.org/t/bug-cmake-swift-bad-compile-commands-json/38298/2 "2020-07-08T18:26:44Z")

</div>

The `compile_commands.json` only has the compilation commands. However, the Swift compilation model doesn't work the same way as C/C++, so we only have a link phase, which is not part of `compile_commands.json`. Emitting something which looks like the compile commands should be possible but I've not had time to work on that. I did have at one point the commands being generated, but never got it to be emitted into the file itself.

---

<div class="post-metadata">

**Author:** ![atyshka](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/atyshka/32/7812_2.png) [@atyshka](https://forums.swift.org/u/atyshka)\
**Post date:** [August 23, 2020, 1:55pm UTC](https://forums.swift.org/t/bug-cmake-swift-bad-compile-commands-json/38298/3 "2020-08-23T13:55:54Z")

</div>

Okay. Is it possible then to manually specify files for sourcekit? I know it's clunky but still better than not having any intellisense at all.

---

<div class="post-metadata">

**Author:** ![compnerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/compnerd/32/2165_2.png) [@compnerd](https://forums.swift.org/u/compnerd)\
**Post date:** [August 24, 2020, 3:40pm UTC](https://forums.swift.org/t/bug-cmake-swift-bad-compile-commands-json/38298/4 "2020-08-24T15:40:22Z")

</div>

I'm not sure if there is a way (@akyrtzi, @blangmuir, or someone on that team might know). However, if you are motivated, getting CMake to emit the information would be useful I think.

---

<div class="post-metadata">

**Author:** ![atyshka](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/atyshka/32/7812_2.png) [@atyshka](https://forums.swift.org/u/atyshka)\
**Post date:** [August 24, 2020, 5:23pm UTC](https://forums.swift.org/t/bug-cmake-swift-bad-compile-commands-json/38298/5 "2020-08-24T17:23:03Z")

</div>

I’m no cmake pro, but if you got the commands generated, emitting them to the file seems easy enough. Where’s your work in progress on that that I could continue?

---

<div class="post-metadata">

**Author:** ![compnerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/compnerd/32/2165_2.png) [@compnerd](https://forums.swift.org/u/compnerd)\
**Post date:** [August 24, 2020, 5:46pm UTC](https://forums.swift.org/t/bug-cmake-swift-bad-compile-commands-json/38298/6 "2020-08-24T17:46:05Z")

</div>

I don't have the patch handy right now. It's not exactly easy since wiring up the generation wasn't very straight forward since the two files are built in different phases/areas. The generation is not done in the CMake language but rather in the C++ generator part of CMake.

---

<div class="post-metadata">

**Author:** ![blangmuir](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/blangmuir/32/277_2.png) [@blangmuir](https://forums.swift.org/u/blangmuir)\
**Post date:** [August 25, 2020, 9:09pm UTC](https://forums.swift.org/t/bug-cmake-swift-bad-compile-commands-json/38298/7 "2020-08-25T21:09:38Z")

</div>

> [@atyshka](#):
>
> Okay. Is it possible then to manually specify files for sourcekit? I know it's clunky but still better than not having any intellisense at all.

Did you have something in mind that would be better than writing a compile\_commands.json file by hand? That's the only way at the moment.
