ハイパーマッスルエンジニア

Vim、ShellScriptについてよく書く

stellariumをソースからbuild&installする(Mac編)

f:id:rasukarusan:20181128003414p:plain

皆さん星を見るツール知ってますか。
プラネタリウムをお家のPCで実現できる「stellarium」というものがあるんですよ。

stellarium.org

stellarium導入の準備

前置きはすっ飛ばして必要な作業だけ書いていきますね。早く星見たいですもんね。
といっても必要なものは以下の通り少ないです。もしかしたらXcodeインストールしたときに付随するアレが必要かもしれませんがそこはアレしてください。

  • Cmake
  • Qt5

Cmakeのインストール

stellariumがC++で作られているのでコンパイルのためにCmakeが必要です。 以下のサイトを参考にさせていただきました。

qiita.com

やることはdmgファイルをダウンロードしてインストールしてPATHを追加する、またはmac portsでサクッとインストールします。
私はdmgファイルをダウンロード、インストールしてPATHを追加する方法でいきました。

$ export PATH="/Applications/CMake.app/Contents/bin":$PATH

Qt5のインストール

Qtはアレです。C++でGUIのアプリを開発するときのフレームワークです。
ごめんなさい詳しくは知らないけどとりあえず「C++のGUIアプリを動かすのに必要なやつ」です。

# brew でサクッ
$ brew install qt

# PATHを追加
$ export PATH=/usr/local/opt/qt/bin:$PATH

ちなみにこのQtを入れておかないと後々でするcmakeのコンパイル時にエラーが吐かれてしまいます。

# cmakeのエラー
$ cmake ../..
-- Found CMake 3.13.0-rc3
-- Platform: Darwin-16.7.0
CMake Error at CMakeLists.txt:355 (FIND_PACKAGE):
  By not providing "FindQt5Core.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Qt5Core", but
  CMake did not find one.

  Could not find a package configuration file provided by "Qt5Core" with any
  of the following names:

    Qt5CoreConfig.cmake
    qt5core-config.cmake

  Add the installation prefix of "Qt5Core" to CMAKE_PREFIX_PATH or set
  "Qt5Core_DIR" to a directory containing one of the above files.  If
  "Qt5Core" provides a separate development package or SDK, be sure it has
  been installed.


-- Configuring incomplete, errors occurred!
See also "/Users/workdir/stellarium/builds/macosx/CMakeFiles/CMakeOutput.log".

いざstellariumのビルド

もう準備完了です。サクサクとエラーなく進めるはずです。信じましょう。

# stellariumのソースコードをダウンロード
$ git clone https://github.com/Stellarium/stellarium.git

# ビルド用のディレクトリを作成
$ cd stellarium
$ mkdir -p builds/macosx
$ cd builds/macosx

# コンパイル
$ cmake ../..
-- Found CMake 3.13.0-rc3
-- Platform: Darwin-16.7.0
-- Found Qt5: /usr/local/opt/qt/bin/qmake (found suitable version "5.11.2")
-- GPS: support by Qt\'s NMEA handling enabled.
-- GPS: Could not find GPS library - GPSD query disabled!
-- Using system-provided zlib at /usr/lib/libz.dylib
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Could NOT find Gettext (missing: GETTEXT_MSGMERGE_EXECUTABLE GETTEXT_MSGFMT_EXECUTABLE)
-- Found PythonInterp: /Users/rasukaru/.pyenv/shims/python (found version "2.7.15")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/rasukaru/Desktop/stellarium/stellarium/builds/macosx

# ビルド
$ make
Scanning dependencies of target Supernovae-static_autogen
[  0%] Automatic MOC for target Supernovae-static
[  0%] Built target Supernovae-static_autogen
...(中略)
[100%] Generating ../../translations/stellarium-remotecontrol/zh_HK.qm
[100%] Generating ../../translations/stellarium-remotecontrol/zh_TW.qm
[100%] Built target translations-stellarium-remotecontrol

さあ星を見よう

# stellariumの実行。ビルドが成功していたらbuild/macos/src/stellariumに実行ファイルがあるはず。
$ ./src/stellarium

動作画面

f:id:rasukarusan:20181128002859g:plain

すでに設定を色々いじってしまっているためデフォルトとはだいぶ違う見え方になってしまっているが、デフォルトだと下のような感じのはず。設定関連はまた別記事で紹介します。 f:id:rasukarusan:20181128002147p:plain

まとめ

Macで星を見ることができるようになりました。
次はDocker上でGUIがない環境、いわゆるheadlessでstellariumを起動するまでを紹介したい。
目的は「指定した緯度・経度の星空のスクリーンショットを撮る」ことです。頑張れ俺。

とりあえず今回は星を見れて精神を癒やすことに成功できたので良しです。