CMake でコンパイルコマンドを JSON 形式で出力する

CMake を弄っているときに見つけたんですが CMAKE_EXPORT_COMPILE_COMMANDS:BOOL っていうのがあるんですね。これを ON にしてジェネレートするとビルドディレクトリに compile_commands.json っていうファイルが出来上がります。

ではここでちょっと RawTherape のコンパイルコマンドを出力した compile_commands.json を10行ほど抜き出してみます。

[
{
  "directory": "/usr/local/src/build/rtexif",
  "command": "/opt/local/bin/g++-mp-4.7   -DBZIP_SUPPORT -DMYFILE_MMAP  -mtune=generic -fopenmp -O3 -DNDEBUG -arch i386 -isysroot /Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6 -I/opt/local/include/glib-2.0 -I/opt/local/lib/glib-2.0/include -I/opt/local/include -I/opt/local/include/glibmm-2.4 -I/opt/local/lib/glibmm-2.4/include -I/opt/local/include/sigc++-2.0 -I/opt/local/lib/sigc++-2.0/include -I/opt/local/include/gtk-2.0 -I/opt/local/lib/gtk-2.0/include -I/opt/local/include/atk-1.0 -I/opt/local/include/cairo -I/opt/local/include/gdk-pixbuf-2.0 -I/opt/local/include/pango-1.0 -I/opt/local/include/pixman-1 -I/opt/local/include/freetype2 -I/opt/local/include/libpng14 -I/opt/local/include/gtkmm-2.4 -I/opt/local/lib/gtkmm-2.4/include -I/opt/local/include/atkmm-1.6 -I/opt/local/include/giomm-2.4 -I/opt/local/lib/giomm-2.4/include -I/opt/local/include/pangomm-1.4 -I/opt/local/lib/pangomm-1.4/include -I/opt/local/include/gtk-unix-print-2.0 -I/opt/local/include/gdkmm-2.4 -I/opt/local/lib/gdkmm-2.4/include -I/opt/local/include/cairomm-1.0 -I/opt/local/lib/cairomm-1.0/include     -ffast-math -fexpensive-optimizations -fPIC -o CMakeFiles/rtexif.dir/rtexif.cc.o -c /usr/local/src/rawtherapee/rtexif/rtexif.cc",
  "file": "/usr/local/src/rawtherapee/rtexif/rtexif.cc"
},
{
  "directory": "/usr/local/src/build/rtexif",
  "command": "/opt/local/bin/g++-mp-4.7   -DBZIP_SUPPORT -DMYFILE_MMAP  -mtune=generic -fopenmp -O3 -DNDEBUG -arch i386 -isysroot /Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6 -I/opt/local/include/glib-2.0 -I/opt/local/lib/glib-2.0/include -I/opt/local/include -I/opt/local/include/glibmm-2.4 -I/opt/local/lib/glibmm-2.4/include -I/opt/local/include/sigc++-2.0 -I/opt/local/lib/sigc++-2.0/include -I/opt/local/include/gtk-2.0 -I/opt/local/lib/gtk-2.0/include -I/opt/local/include/atk-1.0 -I/opt/local/include/cairo -I/opt/local/include/gdk-pixbuf-2.0 -I/opt/local/include/pango-1.0 -I/opt/local/include/pixman-1 -I/opt/local/include/freetype2 -I/opt/local/include/libpng14 -I/opt/local/include/gtkmm-2.4 -I/opt/local/lib/gtkmm-2.4/include -I/opt/local/include/atkmm-1.6 -I/opt/local/include/giomm-2.4 -I/opt/local/lib/giomm-2.4/include -I/opt/local/include/pangomm-1.4 -I/opt/local/lib/pangomm-1.4/include -I/opt/local/include/gtk-unix-print-2.0 -I/opt/local/include/gdkmm-2.4 -I/opt/local/lib/gdkmm-2.4/include -I/opt/local/include/cairomm-1.0 -I/opt/local/lib/cairomm-1.0/include     -ffast-math -fexpensive-optimizations -fPIC -o CMakeFiles/rtexif.dir/stdattribs.cc.o -c /usr/local/src/rawtherapee/rtexif/stdattribs.cc",
  "file": "/usr/local/src/rawtherapee/rtexif/stdattribs.cc"

おお〜、こんな感じでコンパイルコマンドが全て把握出来るのですね。

しかし、今はまだ中を確認する以外の使い道がわかりません。

将来何かに役に立つかもしれないメモ。