Extracting CMake with Kythe

You want to extract a C project using Kythe, but the project doesn't use a Kythe-supported build tool? You can, if you are willing to hack a bit and intercept the compiler.

Create a script mycc with the content:

#!/bin/bash
echo "$@" >> /tmp/mycc.log
KYTHE_OUTPUT_DIRECTORY=/tmp/entries /opt/kythe/extractors/cxx_extractor $@
gcc $@

Create a similar script mycxx, using g++ instead gcc. Then test your setup:

git clone https://github.com/ttroy50/cmake-examples
cd cmake-examples/01-basic/B-hello-headers
chmod +x ./mycc ./mycxx
mkdir /tmp/entries
CC=$(readlink -f /path/to/mycc) CXX=$(readlink -f mycxx) cmake .
CC=$(readlink -f /path/to/mycc) CXX=$(readlink -f mycxx) make

Now the Kythe entries are available, and you can continue the pipeline at indexing them.

Note This is not a complete solution. You will get errors when the extractor is invoked on linker arguments. You can ignore these, but don't be surprised if some gcc command-line massaging is needed for complicated situations.

Have fun hacking!

In the forge: Programming Without Anxiety ebook. Bye Blockage, Hello Productivity!