# One compilation database including external projects?

**URL:** https://discourse.cmake.org/t/one-compilation-database-including-external-projects/6544
**Category:** Code
**Created:** [September 21, 2022, 6:50pm UTC](https://discourse.cmake.org/t/one-compilation-database-including-external-projects/6544 "2022-09-21T18:50:35Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![cmak](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@cmak](https://discourse.cmake.org/u/cmak)
#### Post date: [September 21, 2022, 6:50pm UTC](https://discourse.cmake.org/t/one-compilation-database-including-external-projects/6544/1 "2022-09-21T18:50:35Z")

</div>

Is there a way to get cmake to generate one compilation database (`compile_commands.json`) for the entire project including external projects? Currently every external project gets its own db. Or is there a cmake way to merge all dbs to one?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [September 21, 2022, 8:08pm UTC](https://discourse.cmake.org/t/one-compilation-database-including-external-projects/6544/2 "2022-09-21T20:08:52Z")

</div>

CMake provides no mechanism as external projects are outside of its control beyond “a bag of commands to run in order”. Additionally, these databases wouldn’t exist until after the build is underway which is far after the local project’s database is written out. `jq` could probably be used to combine everything though.

---

<div class="post-metadata">

### Author: ![cmak](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@cmak](https://discourse.cmake.org/u/cmak)
#### Post date: [September 22, 2022, 8:30am UTC](https://discourse.cmake.org/t/one-compilation-database-including-external-projects/6544/3 "2022-09-22T08:30:02Z")

</div>

Valid point, forgot that the configure step for externals happens when build is underway. Thanks for the `jq` tip!

---

<div class="post-metadata">

### Author: ![cmak](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@cmak](https://discourse.cmake.org/u/cmak)
#### Post date: [September 26, 2022, 6:38am UTC](https://discourse.cmake.org/t/one-compilation-database-including-external-projects/6544/4 "2022-09-26T06:38:56Z")

</div>

Found a better way if using vscode, then let it merge the compilation databases by setting this attribute; `cmake.mergedCompileCommands`
