2020年度版 PhantomJS のビルド(macOS篇)
2020年度版 PhantomJS のビルド
何故か今になって PhontomJS をビルドしていみる。
下準備
Xcode はインストール済みとする
QT5 のインストール
ここは簡単Honebrewを使用してインスールするだけ
brew install qt5
これで全て上手く行く。ここまでは。
QTWebKit のビルド
この GitHub Wiki Building QtWebKit on macOS を参考にビルド
必要なもの
git clone https://github.com/qtwebkit/qtwebkit.git
QTWebKit のリポジトリをクローン
brew install conan
パッケージマネージャのインストール (pip3 install conan でもインストール可能)
ビルド
Tools/qt/build-qtwebkit-conan.py --qt=<path_to_your_qt_installation> [--install]
--install オプションとして渡すと指定した QT のパスにインストールされる
Homebrew でインストールされた QT のパスにインストールする場合は以下のようになる
Tools/qt/build-qtwebkit-conan.py --qt=/usr/local/Cellar/qt/5.15.1 --install
しかし WebKit のビルドなので相当ビルド時間がかかる。詳細は後述するが、生成された QtWebKit.Framework などのリンクパスがおかしかったりした。
PhantomJS のビルド
git clone https://github.com/ariya/phantomjs.git で Git からクローンし phontomjs ディレクトリに移動
CMake の Find_Package が検索するパスに QT の CMake ファイルが含まれるように export CMAKE_PREFIX_PATH=/usr/local/Cellar/qt/5.15.1 を設定して ./configure
しかし
CMake エラー
Checking file [/usr/local/Cellar/qt/5.15.1/lib/cmake/Qt5/Qt5Config.cmake] Checking file [/usr/local/Cellar/qt/5.15.1/lib/cmake/Qt5Core/Qt5CoreConfig.cmake] Checking file [/usr/local/Cellar/qt/5.15.1/lib/cmake/Qt5Network/Qt5NetworkConfig.cmake] Checking file [/usr/local/Cellar/qt/5.15.1/lib/cmake/Qt5WebKitWidgets/Qt5WebKitWidgetsConfig.cmake] Checking file [/usr/local/Cellar/qt/5.15.1/lib/cmake/Qt5WebKit/Qt5WebKitConfig.cmake] Checking file [/usr/local/Cellar/qt/5.15.1/lib/cmake/Qt5Gui/Qt5GuiConfig.cmake] CMake Error at /usr/local/Cellar/qt/5.15.1/lib/cmake/Qt5WebKit/Qt5WebKitConfig.cmake:100 (get_target_property): get_target_property() called with non-existent target "Qt5::WebKit". Call Stack (most recent call first): /usr/local/Cellar/cmake/3.12.2/share/cmake/Modules/CMakeFindDependencyMacro.cmake:48 (find_package) /usr/local/Cellar/qt/5.15.1/lib/cmake/Qt5WebKitWidgets/Qt5WebKitWidgetsConfig.cmake:83 (find_dependency) /usr/local/Cellar/qt/5.15.1/lib/cmake/Qt5/Qt5Config.cmake:28 (find_package) CMakeLists.txt:6 (find_package) CMake Error at /usr/local/Cellar/qt/5.15.1/lib/cmake/Qt5WebKit/Qt5WebKitConfig.cmake:101 (get_target_property): get_target_property() called with non-existent target "Qt5::WebKit". Call Stack (most recent call first): /usr/local/Cellar/cmake/3.12.2/share/cmake/Modules/CMakeFindDependencyMacro.cmake:48 (find_package) /usr/local/Cellar/qt/5.15.1/lib/cmake/Qt5WebKitWidgets/Qt5WebKitWidgetsConfig.cmake:83 (find_dependency) /usr/local/Cellar/qt/5.15.1/lib/cmake/Qt5/Qt5Config.cmake:28 (find_package) CMakeLists.txt:6 (find_package) CMake Error at /usr/local/Cellar/qt/5.15.1/lib/cmake/Qt5WebKit/Qt5WebKitConfig.cmake:118 (get_target_property): get_target_property() called with non-existent target "Qt5::WebKit". Call Stack (most recent call first): /usr/local/Cellar/cmake/3.12.2/share/cmake/Modules/CMakeFindDependencyMacro.cmake:48 (find_package) /usr/local/Cellar/qt/5.15.1/lib/cmake/Qt5WebKitWidgets/Qt5WebKitWidgetsConfig.cmake:83 (find_dependency) /usr/local/Cellar/qt/5.15.1/lib/cmake/Qt5/Qt5Config.cmake:28 (find_package) CMakeLists.txt:6 (find_package)
とエラーが発生。しかたなく QT5::WebKit となっている箇所を QT5::WebKitLegacy と書き換える事で対応。再度 ./configure && make
export CMAKE_PREFIX_PATH=/usr/local/Cellar/qt/5.15.1; ./configure && make
あとはできあがった bin/phnatomjs を実行できれば OK なのだが……
とりあえずの仕上げ
エラーで動作しない!
実行しようとすると
Scanning dependencies of target check FATAL: Version check failed ## dyld: Library not loaded: QtWebKitWidgets.framework/Versions/5/QtWebKitWidgets ## Referenced from: /Users/mtakagi/Downloads/phantomjs/bin/phantomjs ## Reason: image not found
とあえなく表示されエラーで動作せず。
otool -l でリンクされているフレームワークを調べる。
otool -L bin/phantomjs bin/phantomjs: /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.0.0) QtWebKitWidgets.framework/Versions/5/QtWebKitWidgets (compatibility version 5.212.0, current version 5.212.0) /usr/local/opt/qt/lib/QtWidgets.framework/Versions/5/QtWidgets (compatibility version 5.15.0, current version 5.15.1) QtWebKit.framework/Versions/5/QtWebKit (compatibility version 5.212.0, current version 5.212.0) /usr/local/opt/qt/lib/QtNetwork.framework/Versions/5/QtNetwork (compatibility version 5.15.0, current version 5.15.1) /usr/local/opt/qt/lib/QtGui.framework/Versions/5/QtGui (compatibility version 5.15.0, current version 5.15.1) /usr/local/opt/qt/lib/QtCore.framework/Versions/5/QtCore (compatibility version 5.15.0, current version 5.15.1) /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 800.7.0)
QtWebKitWidgets.Frameworks と QtWebKit.framework/Versions/5/QtWebKit のパスがカレントからロードされるようにみえる。 そこで install_name_tool を使用しリンクパスを修正する事にした。
リンクしたフレームワークのパスの変更
install_name_tool を使用しphantomjsのリンクを以下のように修正
install_name_tool -change QtWebKitWidgets.framework/Versions/5/QtWebKitWidgets /usr/local/opt/qt/lib/QtWebKitWidgets.framework/Versions/5/QtWebKitWidgets bin/phantomjs install_name_tool -change QtWebKit.framework/Versions/5/QtWebKit /usr/local/opt/qt/lib/QtWebKit.framework/Versions/5/QtWebKit bin/phantomjs
しかし phantomjs を実行しようとすると無情にも
FATAL: Version check failed ## dyld: Library not loaded: QtWebKit.framework/Versions/5/QtWebKit ## Referenced from: /usr/local/Cellar/qt/5.15.1/lib/QtWebKitWidgets.framework/Versions/5/QtWebKitWidgets ## Reason: image not found ## exit -6
ビルドした QTWebKtWidgets のロードするフレームワークがパスおかしかったのです。そこで再度QtWebKitWidgets に install_name_tool で以下のように修正したところ
install_name_tool -change QtWebKit.framework/Versions/5/QtWebKit /usr/local/opt/qt/lib/QtWebKit.framework/Versions/5/QtWebKit /usr/local/Cellar/qt/5.15.1/lib/QtWebKitWidgets.framework/Versions/5/QtWebKitWidgets
一通り完了
var sys = require("system") sys.stdout.write("hello, world!"); phantom.exit();
実行成功?
bin/phantomjs hello.js hello, world!%















