Ninjaのテストにgtest 1.6.0以降を使う
NinjaはテストのためにGoogle C++ Testing Framework(以下gtest)が使われているが、当初はシステムにインストールされたgtestをテストプログラム(ninja_test)のビルドに利用されていた。しかしgtestの最新版である1.6.0以降はシステムへのインストールできなくなり、gtestを使う各プロジェクト毎にビルドする形になった。その理由はgtestのFAQにて説明されている。
Why is it not recommended to install a pre-compiled copy of Google Test (for example, into /usr/local)?
僕が使っている環境(Mac OS X + Homebrew)でもgtest 1.5.0を使用できるが、gtest 1.6.0とうっかり混ざるとコンパイルエラーになり、かつ今自分がgtest 1.5.0とgtest 1.6.0のどちらを利用しているのか判別つかないことが多々あり、自分の環境ではgtest 1.6.0で統一しようと考えた。
そこでNinjaでもgtest 1.6.0を使うことになるが、2012-01-06現在のNinjaではconfigure.pyからgtestを展開したディレクトリを指定するオプションが用意されているため、そのオプションを利用する。
% ./configure.py --help Usage: configure.py [options] Options: -h, --help show this help message and exit --platform=PLATFORM target platform (linux/freebsd/mingw/windows) --host=HOST host platform (linux/freebsd/mingw/windows) --debug enable debugging flags --profile=TYPE enable profiling (gmon/pprof) --with-gtest=PATH use gtest unpacked in directory PATH --with-python=EXE use EXE as the Python interpreter % ./configure.py --with-gtest=./gtest-1.6.0 % ./ninja ninja_test
これでninja_testが出来上がる。