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

Vim、ShellScriptについてよく書く

stellariumのbuild&install(linux編 on Docker)

f:id:rasukarusan:20181203002749p:plain

今日もね、星の話をしたい。

前回はMacでstellariumを起動するところまでをやった。 今回はlinux上でstellariumを起動するところまでやる。

linuxの環境構築

Docker上に環境を構築していく。ディレクトリ構成は以下。

docker-stellarium
    |_docker-compose.yml
    |_web
      |_Dockerfile
      |_index.php

URLにアクセスしてstellariumを起動する形にしたかったので適当にphpのイメージを使用。

Dockerfile

FROM php:7.0-apache
RUN apt-get update && apt-get install -y \
  zip \
  unzip \
  git-core \
  vim \
  wget \
  && apt-get clean

docker-compose.yml

version: '2'
services:
  web:
    build: ./web
    ports:
      - '8080:80'
    environment:
      - TZ=Japan
    volumes:
      - ./web:/var/www/html

docker-compose up -dした後にdocker-compose exec web bashでコンテナに入れればOK。 ここにstellariumに必要なものをズコズコ入れていく。

Cmakeのインストール

stellariumをコンパイルするためにCmakeが必要なのでいれる。

wget https://cmake.org/files/v3.13/cmake-3.13.0.tar.gz
tar -zxvf cmake-3.13.0.tar.gz
rm cmake-3.13.0.tar.gz
cd cmake-3.13.0
./bootstrap && make && make install

Qt関連をインストール

1つずつ説明するのは無理なのでstellariumのビルドに必要だったのものを列挙しておきますね。 (全部sudo apt-get installでインストール可能)

公式Wikiにも乗っているやつ

libgps-dev
libqt5positioning5
qtpositioning5-dev
libqt5positioning5-plugins
qtmultimedia5-dev
libqt5multimedia5-plugins

Wikiには乗っていなかったけど必要だったやつ

libqt5serialport5
libqt5serialport5-dev
qtscript5-dev
qttools5-dev

Wikiに乗っていなかったもので必要だったやつは、stellariumのコンパイル時のcmakeでエラーが起きるたびに追加したもの。 例えばlibqt5serialport5は入れていないと以下のようなエラーが出る。

root@01d318f2c446:/var/www/html/stellarium-0.18.2/builds/unix# cmake ../..
-- Found CMake 3.13.0
-- Platform: Linux-4.9.93-linuxkit-aufs
-- Found Qt5: /usr/lib/x86_64-linux-gnu/qt5/bin/qmake (found suitable version "5.7.1")
CMake Error at CMakeLists.txt:370 (FIND_PACKAGE):
  By not providing "FindQt5SerialPort.cmake" in CMAKE_MODULE_PATH this
  project has asked CMake to find a package configuration file provided by
  "Qt5SerialPort", but CMake did not find one.

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

    Qt5SerialPortConfig.cmake
    qt5serialport-config.cmake

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

-- Configuring incomplete, errors occurred!
See also "/var/www/html/stellarium-0.18.2/builds/unix/CMakeFiles/CMakeOutput.log".

stellariumのビルド

あとはstellariumのソースをダウンロードしてビルドしていくだけ。

$ git clone https://github.com/Stellarium/stellarium.git
$ cd stellarium
$ mkdir -p builds/unix
$ cd builds/unix
$ cmake ../..
$ make
$ make install

いざ実行

もしかしたらcmakeの実行時に、以下のように「qt5のバージョンが足りてないよ」と言われる場合があるが、その場合はapt-get installによるインストールではなくソースからインストールすればOK。

# cmakeでエラー
CMake Error at CMakeLists.txt:358 (MESSAGE):
  Found Qt5: /usr/lib/x86_64-linux-gnu/qt5/bin/qmake (found unsuitable
  version "5.3.2", required is "5.4.0")

ではstellariumを実行する

$ cd stellarium/builds/unix
$ src/stellarium
QXcbConnection: Could not connect to display
Aborted

...

成功だ。もう一度言おう、成功だ
お気づきかもしれないがDocker上のlinuxにGUIという概念は存在しない。
しかしstellariumは本来GUI上で操作するものだ。GUIがない環境では起動しないに決まっている。

QXcbConnection: Could not connect to display
Aborted

これは「出力先のGUIが見つからないよ」というエラーだ。Yes, Aborted。
Docker上でstellariumを起動するというのはつまりheadlessでstellariumを起動するということだ。
この問題、解決しましょう。

まとめ

ホントはheadlessの起動法まで書きたかったんですが体力切れです。別記事にします。大丈夫ですちゃんとheadless版Stellariumできます。
とりあえずせっかくDockerでやっているのでDockerfileに今回の操作等をまとめておきましょう。

FROM php:7.0-apache
RUN apt-get update && apt-get install -y \
  zip \
  unzip \
  git-core \
  vim \
  wget \
  libgps-dev \
  libqt5positioning5 \
  qtpositioning5-dev \
  libqt5positioning5-plugins \
  libqt5serialport5 \
  libqt5serialport5-dev\
  qtmultimedia5-dev \
  libqt5multimedia5-plugins \
  qt5-default \
  qtscript5-dev \
  qtmultimedia5-dev \
  qttools5-dev \
  && apt-get clean

# Cmakeのインストール
WORKDIR /home/www/html/
RUN wget https://cmake.org/files/v3.13/cmake-3.13.0.tar.gz && \
    tar -zxvf cmake-3.13.0.tar.gz && \
    rm cmake-3.13.0.tar.gz
WORKDIR /home/www/html/cmake-3.13.0
RUN ./bootstrap && make && make install

# stellariumのソースダウンロード
WORKDIR /home/www/html/
RUN wget https://github.com/Stellarium/stellarium/releases/download/v0.18.2/stellarium-0.18.2.tar.gz && \
    tar -zxvf stellarium-0.18.2.tar.gz && \
    mv stellarium-0.18.2 stellarium && \
    rm stellarium-0.18.2.tar.gz

# stellariumのビルド
WORKDIR /home/www/html/stellarium
RUN mkdir -p build/unix

WORKDIR /home/www/html/stellarium/build/unix
RUN cmake ../../ && \
    make && \
    make install

やりたいことまでもう少し、頑張れ俺。