Skip to content

Instantly share code, notes, and snippets.

View rockingdice's full-sized avatar
🤣
Fluttering

rockingdice

🤣
Fluttering
  • Tsinghua University
  • Beijing
View GitHub Profile
雌火竜 リオレイア
雌火竜 ヌシ・リオレイア
火竜 リオレウス
火竜 ヌシ・リオレウス
奇怪竜 フルフル
岩竜 バサルモス
角竜 ディアブロス
角竜 ヌシ・ディアブロス
金獅子 ラージャン
鋼龍 クシャルダオラ
@T1T4N
T1T4N / generate-xcode-compilation-database.md
Last active June 20, 2024 13:53
Generate a JSON Compilation Database from an Xcode project

Introduction

A JSON compilation database is a very handy output format which is parsed and used by many development tools. Unfortunately for us Apple Developers, it is not straightforward to generate one from within Xcode, as it is (probably) not Apple's priority and therefore there is no toggle/switch/setting that can be easily enabled to get this information.

There is however a solution, thanks to Apple using Clang/LLVM as their main toolchain.

Implementation

The standard way to generate this with clang would be to use the -MJ flag and give it a file name that typically corresponds to the input file. Using this flag indirectly through Xcode is hard, given that we're not aware of all the other arguments when a compiler call is executed.

However, there is a second hidden/badly documented LLVM flag: -gen-cdb-fragment-path - it is implemented in terms of -MJ and has the same functionality, but it's argument in contrast is an output directory.