Skip to content

alexkozy/cmake-kythe

 
 

Repository files navigation

CMake-Kythe

This script helps running Kythe pipeline for cmake-compiled projects. Main goal is to run Kythe against WebKit source.

Example

Let's build index for a sample cmake project: bast/cmake-example.

  1. First things first - clone cmake-kythe and install dependencies.
user:~$ git clone https://github.com/aslushnikov/cmake-kythe
user:~$ cd cmake-kythe
user:~/cmake-kythe$ npm i
user:~/cmake-kythe$ cd ..
user:~$

cmake-kythe has a few NPM dependencies so it should be pretty quick.

  1. Second - let's clone our sample cmake project bast/cmake-example.
user:~$ git clone https://github.com/bast/cmake-example
user:~$ cd cmake-example
user:~/cmake-example$
  1. CMake-Kythe relies on compilation database to produce its indexes. Thus a cmake project has to be configured first to export CMake compilation database. This is done with a -DCMAKE_EXPORT_COMPILE_COMMANDS flag.

Build cmake-example, generating compilation database:

user:~/cmake-example$ cmake -H. -Bbuild -DCMAKE_EXPORT_COMPILE_COMMANDS=1

This command should produce a ~/cmake-example/build directory, with a compilation database under ~/cmake-example/build/compile_commands.json.

NOTE: if this steps throw an error for you, make sure that there's C++ compiler available on your system. Also, cmake-example wants to have Fortran available on your system. This can be avoided by removing "Fortran" from the list of supported langauges in //CMakeLists.txt.

  1. Let's actually compile the cmake-example so that it produces all the intermediate generated files.
user:~/cmake-example$ cd build
user:~/cmake-example/build$ cmake --build .

This should succeed.

  1. Now, we need to install Kythe separately to the system. cmake-kythe is tested to work well with Kythe v0.0.30, so I'd recommend downloading Kythe v0.0.30 and extracting it into /opt/kythe on your system.

You should end up with /opt/kythe directory that has various subdirectories, e.g. /opt/kythe/tools, /opt/kythe/indexers and so on.

  1. cmake-kythe requires a small config for it to deal with the project.

Save the following to the ~/cmake-example/config.json:

{
  // Path to Kythe installation.
  "kythe_path": "/opt/kythe",
  // This is the port to serve Kythe basic UI. Drop "localhost" if you want server to be reachable
  // from outside.
  "kythe_web_ui_port": "localhost:8080",
  // Parallelization level.
  "parallel": 1,
  // Project directory. Relative paths are resolved wrt config's location.
  "project_directory": ".",
  // Path to cmake's compilation database.
  "cmake_compilation_database": "./build/compile_commands.json",
  // Where to put index.
  "output_directory": "/tmp/cmake-example"
}
  1. Last step - run indexing!
user:~/cmake-example$ node ../cmake-kythe/index.js config.js

This step takes ~5 minutes for me. Please, give it some time. Once it's done, basic Kythe UI will be served at localhost:8080.

About

helpers to get kythe working with webkit on linux

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 97.0%
  • Shell 1.7%
  • C++ 1.3%