ruby-qml gem をインストール

[RubyとQML/Qt Quickでデスクトップ用GUIアプリを書けるgem「ruby-qml」を作った - Qiita](http://qiita.com/seanchas_t/items/ec8b5376b80eee22ea15)
をインストールしようとして、いきなり失敗したので、その備忘録。
##環境
MacBook Pro with Retina 13" (Late 2013) 2.4 GHz Intel Core i5
#Qt インストーラのダウンロード
[Download Qt | Qt Project](http://qt-project.org/downloads)
から
[Qt Online Installer for MacOS (9.4 MB)](http://download.qt-project.org/official_releases/online_installers/qt-opensource-mac-x64-1.6.0-4-online.dmg)（インストーラのバージョンは1.6.0）
をダウンロード。
#Qt インストール
詳細を記録し落としたのですが、インストール先は標準にしていたと思います。
現在のインストール先は `~/Qt`です。
Qt 5.3.1 (Clang 5.0 (Apple), 64bit) の Qt Creator がインストールされました。

#2014/7/1追記：ruby-qml-0.0.5 でインストールに成功
上記手順で Qt をインストールしたあとに
[ruby-qml by seanchas116](http://seanchas116.github.io/ruby-qml/) に記載されているように

```bash
$ brew install pkg-config libffi
$ gem install qml -- --with-libffi-dir=$(brew --prefix libffi) --with-qt-dir=$HOME/Qt/5.3/clang_64
```
を実行することでインストールが出来ました（`--with-qt-dir=$HOME/Qt/5.3/clang_64` の部分は Qt インストール環境に合わせてください）。
Homebrew で Qt もインストールする場合には

```bash
$ brew install pkg-config libffi qt5
$ gem install qml -- --with-libffi-dir=$(brew --prefix libffi) --with-qt-dir=$(brew --prefix qt5)
```
で行えるそうです。

#以下は ruby-qml-0.0.4 での履歴です
念のために残しておきます。
##ruby-qml gem をインストール（失敗１）
```bash
$ gem install qml 
Fetching: qml-0.0.4.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing qml:
        ERROR: Failed to build gem native extension.

        /Users/riocampos/.rbenv/versions/1.9.3-p484/bin/ruby extconf.rb
checking for pkg-config... yes
checking for qmake... no
checking for moc... no
qmake executable not found
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
	--with-opt-dir
	--without-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/Users/riocampos/.rbenv/versions/1.9.3-p484/bin/ruby
	--with-pkg-config
	--without-pkg-config
	--with-qt-dir
	--without-qt-dir
	--with-libffi-dir
	--without-libffi-dir


Gem files will remain installed in /Users/riocampos/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/qml-0.0.4 for inspection.
Results logged to /Users/riocampos/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/qml-0.0.4/ext/qml/gem_make.out
```
native extensionsのビルドで失敗したと思われます。 `qmake` が見付からない、らしい。
##qmake はどこだ
Qtのインストール先が `~/Qt` なので `qmake` は `~/Qt/5.3/clang_64/bin` にありました。しかし PATH が通っていません。通しましょう。

```bash:~/.bashrc
# Qt5.3
export PATH="$HOME/Qt/5.3/clang_64/bin:$PATH"
```
##ruby-qml gem をインストール（失敗２）
```bash
$ gem install qml
Building native extensions.  This could take a while...
ERROR:  Error installing qml:
        ERROR: Failed to build gem native extension.

        /Users/riocampos/.rbenv/versions/1.9.3-p484/bin/ruby extconf.rb
checking for pkg-config... yes
checking for qmake... yes
checking for moc... yes
building plugins...
　：（中略）
Package Qt5Core was not found in the pkg-config search path.
Perhaps you should add the directory containing `Qt5Core.pc'
to the PKG_CONFIG_PATH environment variable
No package 'Qt5Core' found
Package Qt5Core was not found in the pkg-config search path.
Perhaps you should add the directory containing `Qt5Core.pc'
to the PKG_CONFIG_PATH environment variable
No package 'Qt5Core' found
Package Qt5Gui was not found in the pkg-config search path.
Perhaps you should add the directory containing `Qt5Gui.pc'
to the PKG_CONFIG_PATH environment variable
No package 'Qt5Gui' found
Package Qt5Gui was not found in the pkg-config search path.
Perhaps you should add the directory containing `Qt5Gui.pc'
to the PKG_CONFIG_PATH environment variable
No package 'Qt5Gui' found
Package Qt5Widgets was not found in the pkg-config search path.
Perhaps you should add the directory containing `Qt5Widgets.pc'
to the PKG_CONFIG_PATH environment variable
No package 'Qt5Widgets' found
Package Qt5Widgets was not found in the pkg-config search path.
Perhaps you should add the directory containing `Qt5Widgets.pc'
to the PKG_CONFIG_PATH environment variable
No package 'Qt5Widgets' found
Package Qt5Qml was not found in the pkg-config search path.
Perhaps you should add the directory containing `Qt5Qml.pc'
to the PKG_CONFIG_PATH environment variable
No package 'Qt5Qml' found
Package Qt5Qml was not found in the pkg-config search path.
Perhaps you should add the directory containing `Qt5Qml.pc'
to the PKG_CONFIG_PATH environment variable
No package 'Qt5Qml' found
Package Qt5Quick was not found in the pkg-config search path.
Perhaps you should add the directory containing `Qt5Quick.pc'
to the PKG_CONFIG_PATH environment variable
No package 'Qt5Quick' found
Package Qt5Quick was not found in the pkg-config search path.
Perhaps you should add the directory containing `Qt5Quick.pc'
to the PKG_CONFIG_PATH environment variable
No package 'Qt5Quick' found
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing `libffi.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libffi' found
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing `libffi.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libffi' found
Package Qt5Core was not found in the pkg-config search path.
Perhaps you should add the directory containing `Qt5Core.pc'
to the PKG_CONFIG_PATH environment variable
No package 'Qt5Core' found
Package Qt5Core was not found in the pkg-config search path.
Perhaps you should add the directory containing `Qt5Core.pc'
to the PKG_CONFIG_PATH environment variable
No package 'Qt5Core' found
checking for QObject... no
header not found: QObject
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
	--with-opt-dir
	--without-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/Users/riocampos/.rbenv/versions/1.9.3-p484/bin/ruby
	--with-pkg-config
	--without-pkg-config
	--with-qt-dir
	--without-qt-dir
	--with-libffi-dir
	--without-libffi-dir
	--enable-debug
	--disable-debug


Gem files will remain installed in /Users/riocampos/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/qml-0.0.4 for inspection.
Results logged to /Users/riocampos/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/qml-0.0.4/ext/qml/gem_make.out
```
`PKG_CONFIG_PATH` に `Qt5Core.pc` などのあるディレクトリを指定しろということですね。
##Qt5Core.pc とかはどこだ
`~/Qt/5.3/clang_64/lib/pkgconfig` にあります（が、全てでは無かったですorz）。
ので

```bash
export PKG_CONFIG_PATH="$HOME/Qt/5.3/clang_64/lib/pkgconfig"
```
 として場所を教えましょう。
##ruby-qml gem をインストール（失敗３）
エラーログの要点のみを。

```bash
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing `libffi.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libffi' found
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing `libffi.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libffi' found
checking for QObject... no
header not found: QObject
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.
```
##libffi はどこよ
入ってませんでした。Homebrew でインストールできます。

```bash
$ brew install libffi
Warning: libffi-3.0.13 already installed
```
ありゃ。

```bash
$ brew info libffi
libffi: stable 3.0.13 (bottled), HEAD
http://sourceware.org/libffi/

This formula is keg-only.
Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.

Some formulae require a newer version of libffi.

/usr/local/Cellar/libffi/3.0.13 (13 files, 388K)
  Poured from bottle
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/libffi.rb
```
Keg-only なので動いてませんね。動かしましょう。

```bash
brew link libffi --force
Linking /usr/local/Cellar/libffi/3.0.13... 9 symlinks created
```
##ruby-qml gem をインストール（失敗４）
残ったエラーはこれだけ。

```bash
checking for QObject... no
header not found: QObject
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.
```
もう分からんですorz
ヘッダファイル `~/Qt/5.3/clang_64/lib/QtCore.framework/Versions/5/Headers/qobject.h` のディレクトリを訊ねているのかと思って

```bash
export PKG_CONFIG_PATH="$HOME/Qt/5.3/clang_64/lib/QtCore.framework/Versions/5/Headers:$HOME/Qt/5.3/clang_64/lib/pkgconfig"
```
を指定したけれども同じエラーが返ってきた。

エラーログ `~/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/qml-0.0.4/ext/qml/mkmf.log` は
[qml-0.0.4 gem install error log](https://gist.github.com/riocampos/6c2fa7cf443289756930)
に置きました。