GMT のインストール


GMT (Generic Mapping Tools) のインストール. 5 以降のバージョンの話.

sourceファイルからビルド

GMT 本体以外のデータセット

NetCDF4のインストールが済んでいないとおそらくインストールできない.cmake も必要.
sourceファイルのダウンロードは GMT Release Files から(本体はGitHubでも可).
【追記 2020年11月】ダウンロードのサイトが変わっていた.Download - The Generic Mapping Tools から.

dcw-gmt-1.1.4.tar.gz
gmt-5.4.3-src.tar.gz # 本体
gshhg-gmt-2.3.7.tar.gz

の3つの.tar.gzをダウンロードした.
dcw と gshhg については解凍したものを /opt/ に置き,リンクを貼っておいた.

tar -zxf dcw-gmt-1.1.4.tar.gz
tar -zxf gshhg-gmt-2.3.7.tar.gz
sudo mv dcw-gmt-1.1.4 /opt/
sudo mv gshhg-gmt-2.3.7 /opt/
cd /opt
sudo ln -s dcw-gmt-1.1.4 dcw
sudo ln -s gshhg-gmt-2.3.7 gshhg



GMT 5

解凍した GMT 本体のソースディレクトリ内で以下のように cmake のファイルをコピーする.

tar -zxf gmt-5.4.4-src.tar.gz
cd gmt-5.4.4
cp -p cmake/ConfigUserTemplate.cmake cmake/ConfigUser.cmake

次に,コピーした ConfigUser.cmake でインストールするパス等を指定する.
デフォルト設定がファイル内に書いてあるので,変更したい場合は set (HOGE 'HOGEHOGE') となっている部分のコメントを外す.NetCDF4 のあるライブラリもここで定義する.

  • cmake/ConfigUser.cmake
    # コメントを外した箇所だけ記載.下記以外は変更なしで実行した
    
    ##
    ## Section 1: Installation paths
    ##
    
    # Installation path (usually defaults to /usr/local) [auto]: 
    set (CMAKE_INSTALL_PREFIX "/usr/local/gmt") 
    
    ##
    ## Section 2: Build dependencies (should only be needed if CMake cannot
    ## automatically detect the rights version or path.)
    ##
    
    # Set path to GSHHG Shoreline Database [auto]:
    set (GSHHG_ROOT "/opt/gshhg") # ここに解凍したGSHHGのファイルパスを書き込む
    
    # Copy GSHHG files to $/coast [FALSE]:
    set (COPY_GSHHG TRUE)
    
    # Set path to DCW Digital Chart of the World for GMT [auto]:
    set (DCW_ROOT "/opt/dcw") # ここに解凍したDCWのファイルパスを書き込む
    
    # Copy DCW files to $/dcw [FALSE]:
    set (COPY_DCW TRUE)
    
    # Set location of NetCDF (can be root directory, path to header file or path
    # to nc-config) [auto]:
    set (NETCDF_ROOT "/usr/local/netcdf4") # NetCDF4の root, またはnc-configがある netcdf4/bin
    NETCDF_ROOT は nc-config のパスが通っていれば自動で取得するので設定しなくても大丈夫.

このあと,

mkdir build && cd build
cmake ..

で preprocess が完了するはず.
あとはいつも通りにビルド,インストールを行う.

make
sudo make install

バージョン 6.0.0 でも方法は同じで問題なかった.
最後に,bin/gmt のシンボリックリンクをパスの通った場所に貼って完了.

$ gmt --version
5.4.4

で確認する.


GMT 6.1

GMT 6.1.1 をクラスターの自分の環境にインストールした.
基本的には GMT 5と同じ.
cmake のファイルに普通の Template と AdvancedTemplate が用意されていた.

cmake
├── ConfigDefault.cmake
├── ConfigUserAdvancedTemplate.cmake
├── ConfigUserTemplate.cmake


ConfigUserTemplate.cmake は GMT をインストールする prefix, gshhg と dcw のパスなど基本的な項目だけを指定する.
この設定を適用するためには GMT5 と同様に

cp -p cmake/ConfigUserTemplate.cmake cmake/ConfigUser.cmake

とコピーして,コピーした ConfigUser.cmake を書き換える.

  • cmake/ConfigUser.cmake
    # 1.  Installation path (usually defaults to /usr/local) [auto]:
    set (CMAKE_INSTALL_PREFIX "/home/miyashita/local/gmt-6.1.1")
    
    # 2.  Install convenience links for GMT modules.  Uncomment to make direct links
    #     to modules so you can run "module options" without the leading "gmt" [FALSE]:
    #set (GMT_INSTALL_MODULE_LINKS TRUE)
    
    # 3a. Set full path to the GSHHG Shoreline Database directory [auto]:
    set (GSHHG_ROOT "/cluster_tools/utility/gshhg-gmt-2.3.7")
    # 3b. Copy GSHHG files to ${GMT_DATADIR}/coast [TRUE]?:
    #set (COPY_GSHHG FALSE)
    
    # 4a. Set full path to the DCW Digital Chart of the World for GMT directory [auto]:
    set (DCW_ROOT "/cluster_tools/utility/dcw-gmt-2.0.0")
    # 4b. Copy DCW files to ${GMT_DATADIR}/dcw [TRUE]?:
    #set (COPY_DCW FALSE)

ConfigUserAdvancedTemplate.cmake はその他諸々の設定を行う.
同様にこれも ConfigUserAdvanced.cmake にコピーして編集する.

cp -p cmake/ConfigUserAdvancedTemplate cmake/ConfigUserAdvanced.cmake

NetCDF や FFTW を自動検出でなく,手動でパス指定したいときは以下の通り.

  • cmake/ConfigUserAdvanced.cmake
    ##
    ## Section 2: Build dependencies (should only be needed if CMake cannot
    ## automatically detect the rights version or path.)
    ##
    
    # Set URL to GMT Data server [auto]:
    #set (GMT_DATA_SERVER "data_server_url")
    
    # Set location of NetCDF (can be root directory, path to header file or path
    # to nc-config) [auto]:
    set (NETCDF_ROOT "/cluster_tools/build_gnu/netcdf-c-4.7.4")
    
    # Set location of GDAL (can be root directory, path to header file or path to
    # gdal-config) [auto]:
    set (GDAL_ROOT "/home/miyashita/local/src/gdal-3.5.0/bin")
    
    # Set location of GEOS (can be root directory, path to header file or path to
    # geos-config) [auto]:
    set (GEOS_ROOT "/home/miyashita/local/src/geos-3.5.2/bin")
    
    # Set location of PCRE (can be root directory, path to header file or path to
    # pcre-config) [auto]:
    #set (PCRE_ROOT "pcre_install_prefix")
    # Alternatively, set location of PCRE2 (can be root directory, path to header file or path to
    # pcre2-config) [auto]:
    #set (PCRE2_ROOT "pcre2_install_prefix")
    
    # Set location of single precision FFTW (can be root directory or path to
    # header file) [auto]:
    set (FFTW3_ROOT "/home/miyashita/local/src/fftw-3.3.9")

あとはお決まりのパターン.

mkdir build && cd build
cmake ..

cmake のときに geos のパスを指定しても,include だけ反映されて lib の方は /usr/lib の方を参照してしまう事態が発生した.
その場合は下記のようにライブラリのパスを cmake のオプションで明記する.

cmake .. -DGEOS_LIBRARY:FILEPATH=/home/miyashita/local/src/geos-3.5.2/lib/libgeos_c.so

その後は通常の make の流れ.

make
make install

今回は自分の local のインストールなので make install に sudo は不要.

実は,apt で gmt 本体はインストールせず下のように dcw や gshhg だけを apt 経由でインストールすれば,ソースから gmt 本体をコンパイルする時に勝手に見つけてくれるっぽい.

sudo apt install gmt-dcw gmt-gshhg gmt-gshhg-full gmt-gshhg-high gmt-gshhg-low

この場合 dcw や gshhg は /usr/share/ に入る.

GMT 6.5.0

6.1と同様に cmake にあるテンプレートをコピーして,各種ライブラリの場所を見る.

cp -p ConfigUserTemplate.cmake ConfigUser.cmake
cp -p ConfigUserAdvancedTemplate.cmake ConfigUserAdvanced.cmake

以下は研究室のクラスター計算機で設定したときのファイルの編集.

  • ConfigUser.cmake
    # 1.  Installation path (usually defaults to /usr/local) [auto]:
    set (CMAKE_INSTALL_PREFIX "/home/miyashita/local")
    # 3a. Set full path to the GSHHG Shoreline Database directory [auto]:
    set (GSHHG_ROOT "/cluster_tools/utility/gshhg-gmt-2.3.7")
    # 3b. Copy GSHHG files to ${GMT_DATADIR}/coast [TRUE]?:
    #set (COPY_GSHHG FALSE)
    
    # 4a. Set full path to the DCW Digital Chart of the World for GMT directory [auto]:
    set (DCW_ROOT "/cluster_tools/utility/dcw-gmt-2.0.0")
    # 4b. Copy DCW files to ${GMT_DATADIR}/dcw [TRUE]?:
    #set (COPY_DCW FALSE)

  • ConfigUserAdvanced.cmake
    # Set location of GDAL (can be root directory, path to header file or path to
    # gdal-config) [auto]:
    set (GDAL_ROOT "/cluster_tools/build_gnu/gdal-3.4.1")
    # Set location of single precision FFTW (can be root directory or path to
    # header file) [auto]:
    set (FFTW3_ROOT "/home/miyashita/local")
    なんとか-config 系のコマンドや pkgconfig のパスがしっかりしている場合は,ここで指定しなくても勝手に見つけてくれるはず. cmake のファイルの中でちゃんと場所を指定しても libfftw3f.so のシンボリックリンクがなくて libfftw3f.so.3 しかない場合に NOT FOUND になるのがよくあるので,シンボリックリンクを作成したりした.

あとは cmake コマンドでなんとかする.

mkdir build
cd build
cmake ..

Ninja というビルドツールがあると

cmake .. -G Ninja

としたほうが速く終わるらしい.なくても可.

cmake --build .
cmake --build . --target install




バイナリをインストール

こちらは NetCDF4 がなくてもインストールできた.
もちろん pscoast や grdview などは NetCDF4 がインストールされていないと使えない.

sudo apt install gmt gmt-doc gmt-dcw gmt-gshhg gmt-gshhg-full gmt-gshhg-high gmt-gshhg-low

この方法を採用すると,

/usr/bin/gmt # gmtのバイナリ実行ファイル
/usr/share/gmt-dcw # dcw
/usr/share/gmt-gshhg # gshhg

の構成になる.


Front page   Edit Diff Attach Copy Rename Reload   New List of pages Search Recent changes   Help   RSS of recent changes
Last-modified: 2024-03-19 (Tue) 08:44:49 (38d)