*NIX

This is a quick guide through the build process using CMake. Refer to the file README.CMake in the source directory for more details.

If you are accustomed to the GNU autotools build chain the CMake transition guide might be helpful.

Package maintainers note packaging recommendations.

Build and runtime dependencies

Install: Optionally install for more capabilities within GMT: Optionally install for building the documentation: Optionally install for running the tests:

Installing from package managers

Ubuntu/Debian

Install the development dependencies with

sudo apt-get install subversion build-essential cmake libnetcdf-dev libgdal1-dev libfftw3-dev libpcre3-dev liblapack-dev
and follow the instructions in the Building GMT section.

  • To enable testing you need GraphicsMagick:
    sudo apt-get install graphicsmagick
    
  • To build the documentation you need more packages still:
    sudo apt-get install texlive texlive-latex-extra
    sudo apt-get install python-sphinx
    

RHEL, CentOS, Fedora

GMT's dependencies are available from Extra Packages for Enterprise Linux. For RHEL and CentOS you can add this repository by telling yum:

sudo yum install epel-release

You then need to install at least the packages cmake, netcdf-devel and gdal-devel, e.g.:
sudo yum install cmake subversion netcdf-devel gdal-devel pcre-devel fftw3-devel lapack-devel

MacOSX with macports.

You need to install Apple's Xcode Developer Tools, found at the Apple Developer Connection site, on your Mac OS X installation CDs/DVD, or in the Mac App Store. Ensure that the optional components for command line development are installed ("Command Line Tools", "Command Line Support", or "UNIX Development").

  • Get and install dependent programs and libraries with macports:
    sudo port install cmake gmake ghostscript netcdf
    
    Optionally also install the GDAL, FFTW (single-precision) and PCRE packages (LAPACK is provided via the Accelerate Framework):
    sudo port install gdal +curl +geos +hdf5 +netcdf
    sudo port install fftw-3-single pcre
    
  • To enable testing you need GraphicsMagick:
    sudo port install GraphicsMagick
    
  • To build the documentation you need more packages still (This assumes Python 2.7; change 27 to some other version if different):
    sudo port install texlive texlive-latex-extra
    sudo port install py27-sphinx
    sudo port select --set python python27
    sudo port select --set sphinx py27-sphinx
    
  • If you want to get the coastline files conveniently through macports, use also:
    sudo port install gshhg-gmt dcw-gmt
    
  • Finally, to build releases, also get:
    sudo port install gnutar
    

MacOSX with Fink.

You need to install Apple's Xcode Developer Tools, found at the Apple Developer Connection site, on your Mac OS X installation CDs/DVD, or in the Mac App Store. Ensure that the optional components for command line development are installed ("Command Line Tools", "Command Line Support", or "UNIX Development").

  • Get and install dependent programs and libraries with Fink:
    sudo fink install cmake ghostscript netcdf-c7 gdal2-dev libpcre1 fftw3
    
  • To enable testing you need GraphicsMagick:
    sudo fink install graphicsmagick
    
  • To build the documentation you need more packages still (This assumes Python 2.7; change 27 to some other version if different):
    sudo fink install python27 setupdocs-py27 sphinx-py27 texlive
    
  • If you want to get the coastline files conveniently through Fink, use also:
    sudo fink install gshhg dcw-gmt
    

Cygwin

These are the steps to get a working system (if you know what you are doing you can take shortcuts):

  1. Make a directory for storing Cygwin-related tarballs and the setup program; call it C:\CygwinFiles.
  2. Download startup.exe from http://www.cygwin.com and save to C:\CygwinFiles.
  3. Run startup.exe (or startup-x86_64.exe for 64-bit Windows). Select your C:\CygwinFiles for storage of downloads and create C:\Cygwin[32|64] for where to install [under no circumstance should you pick a path that has a space in it!]. accept all defaults for now. This is the basic default Cygwin installation.
  4. Run startup.exe again, and this time use the search field to add these packages (unfortunately, while a gdal 2.0 package is available, it is built with an obsolete proj4 library and is thus messed up [OCt 26, 2016: This may change when then fix it]. Workaround is to not build with gdal or to build your own gdal library; for GMT 4 you also need the autoconf package):
    cmake, fftw, fftw-devel, gcc, g++, ghostscript, gv, libnetcdf7, libnetcdf7-devel,
    libnpcr0, libnpcr0-devel, make, openssh, subversion, xinit, zlib, zlib-devel, liblapack-devel
    
  5. Make sure you accept any dependencies that are found, then finish the install.
  6. Set the environmental parameter HDF5_DISABLE_VERSION_CHECK=2.

Now you can follow the "Building GMT from source" instructions.

Building GMT from source

  • Get GMT from source:trunk
    svn checkout svn://gmtserver.soest.hawaii.edu/gmt5/trunk gmt5-dev
    
  • Get GSHHG (coastlines, rivers, and political boundaries; filename: gshhg-gmt-x.x.x.tar.gz) from the download page or ftp://ftp.soest.hawaii.edu/gshhg and extract the files.
  • Get DCW (country polygons; filename: dcw-gmt-x.x.x.tar.gz) from the download page or ftp://ftp.soest.hawaii.edu/dcw and extract the files.
  • In the source tree copy cmake/ConfigUserTemplate.cmake to cmake/ConfigUser.cmake and edit the file according to your demands. This is an example:
    set (CMAKE_INSTALL_PREFIX /opt/gmt)
    set (GSHHG_ROOT <path to gshhg>)
    set (DCW_ROOT <path to dcw>)
    
  • Build and install GMT (note the two periods at the end of the cmake command that indicates the parent directory):
    cd <path to>/gmt5-dev
    mkdir build
    cd build
    cmake ..
    make
    make install
    

Generate Documentation (optional)

You need to install the Sphinx documentation builder and LaTeX (e.g., TeX Live) to generate manual pages, HTML, and PDF documentation:

make docs_man
make docs_html
make docs_pdf
make install
The documentation is also available online and as a platform independent gmt-5.x.x-doc.tar.gz package that you can install along with GMT.
You can choose to install documentation files from an external location instead of generating the manuals from the sources. This is convenient if Sphinx and/or LaTeX are not available. Set GMT_INSTALL_EXTERNAL_DOC in cmake/ConfigUser.cmake.

Packaging with CPack (optional)

If you just want to create a GMT package you do not need to make install.

CPack supports stand-alone TGZ and TBZ2 archives on *NIX, and on MacOSX CPack can also create application bundles. To include the GSHHG and DCW data you must set both COPY_GSHHG and COPY_DCW to true. After building GMT run:

make package

Dependency walking takes a long time so be patient. You can save some time if you are only interested in one of the package options. Invoke CPack instead:

cpack -G <TGZ|TBZ2|Bundle>

Source packages can be build as follows:

make gmt_release
make gmt_release_tar

Windows

Runtime dependencies

Ghostscript

Install a recent Ghostscript version.

Build dependencies

Microsoft Windows SDK >= v7.1

You don't need Visual Studio 2010. Be aware, that Visual Studio 2010 Express cannot compile x64 binaries. You need the Windows SDK for that.

Download and install Microsofts free SDK for Windows, e.g., v7.1

CMake

Install CMake and select option to add CMake to the system PATH.

Subversion

You need to install Subversion in order to fetch the sources. Make sure svn is in the PATH. A Windows version is available here

netCDF

Compiling netCDF from scratch on Windows is not an easy task since you need a lot of dependencies. You could either install a prepackaged development build from http://www.unidata.ucar.edu/software/netcdf/docs/winbin.html. For instance netCDF4.3.3.1-NC4-64.exe, and hope that it works. If it doesn't we suggest you build netCDF yourself from the CMake bundled sources of netCDF from source. See http://www.unidata.ucar.edu/software/netcdf/docs/getting_and_building_netcdf.html#netCDF-CMake

PCRE (optional)

In the following examples we assume that dependent libraries are installed in sudirectories of z:\software\ any other directory is fine though.

Get PCRE from http://www.pcre.org/ and extract pcre-8.30.zip in z:\software\src\pcre-8.30\

  • Open the SDK Command Prompt:
    cd z:\software\src\pcre-8.30\
    mkdir build
    cd build
    cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=z:\software -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON ..
    nmake install
    
  • Check if you can run pcregrep from the command prompt.

GDAL (optional, but a must have)

We assume that you already installed HDF4, HDF5, cURL, netCDF to z:\software.

Now that all dependent libraries are available we can proceed with GDAL. In the following we assume that the target install directory for GDAL is z:\software as well.

MSVC_VER       = 1600
WARNFLAGS      = /w
WIN64          = YES

GDAL_HOME      = z:\software

HDF4_PLUGIN    = NO
HDF4_DIR       = "c:\Program Files\HDF Group\HDF4\4.2.7" 
HDF4_LIB       = /LIBPATH:$(HDF4_DIR)\lib hdfdll.lib mfhdfdll.lib

HDF5_PLUGIN    = NO
HDF5_DIR       = "c:\Program Files\HDF Group\HDF5\1.8.8" 
HDF5_LIB       = /LIBPATH:$(HDF5_DIR)\lib hdf5dll.lib

PCIDSK_SETTING = OLD

NETCDF_PLUGIN  = NO
NETCDF_SETTING = yes
NETCDF_LIB     = z:\software\lib\netcdf.lib
NETCDF_INC_DIR = z:\software\include
NETCDF_HAS_NC4 = yes

CURL_DIR       = z:\software
CURL_INC       = -I$(CURL_DIR)\include
CURL_LIB       = $(CURL_DIR)\lib\libcurl_imp.lib Ws2_32.lib
Change the options according to your local setup. If unsure check the defaults in nmake.opt.
  • Open Windows SDK Command Prompt
    cd z:\software\src\gdal-1.9.0\
    nmake /f makefile.vc
    nmake /f makefile.vc devinstall
    
  • Make sure z:\software\bin is in the PATH and type ogr2ogr. It should greet you with usage information if everything is fine.

NSIS (optional)

You also need to install NSIS (Nullsoft Scriptable Install System) if you want to bundle GMT with all dependent DLLs and create a Windows intaller. Download from http://nsis.sourceforge.net/

Building GMT on Windows

Finally we are ready to compile GMT.

  • In the source tree copy cmake/ConfigUserTemplate.cmake to cmake/ConfigUser.cmake and edit the file according to your demands. This is an example:
    set (CMAKE_INSTALL_PREFIX z:/software/gmt5msc)
    set (GSHHG_ROOT z:/software/src/coast)
    set (NETCDF_DIR z:/software)
    set (GDAL_DIR z:/software)
    set (PCRE_DIR z:/software)
    set (FLOCK TRUE)
    
  • Open Windows SDK Command Prompt
    set PATH=%PATH%;z:\software\bin
    cd gmt5-dev
    mkdir build
    cd build
    
    cmake -G "NMake Makefiles" ..
    
    nmake
    nmake install
    
  • Typing gmt should get you with a short message. You need to set your PATH to the directory specified in CMAKE_INSTALL_PREFIX:
    set PATH=%PATH%;z:\software\gmt5msc\bin
    
    Congratulations you managed to install GMT on your machine!

Building GMT5.2dev on Windows

To build the 5.2 branch you need at least VS2013. It is also known to work with the free VS2015 Community Version

  • Get GMT from source:branches/5.2.0
    cd \software\src
    svn checkout svn://gmtserver.soest.hawaii.edu/gmt5/branches/5.2.0 gmt5-dev
    
  • proceed as above but using a command window where the VS environment variables have been set.

Packaging with NSIS (optional)

If you just want to create a GMT package you do not need to nmake install.

CPack supports stand-alone ZIP archives and NSIS installers on Windows. To include the GSHHG and DCW data you must set both COPY_GSHHG and COPY_DCW to true. After building GMT run:

nmake package

This will create both a ZIP archive and NSIS installer. If there are no issues then you will obtain three files, e.g.:
GMT-5.1.2-win64-Documentation.zip
GMT-5.1.2-win64-Runtime.zip
GMT-5.1.2-win64.exe

Dependency walking takes a long time so be patient. You can save some time if you are only interested in one of the two package options. Invoke CPack instead:

cpack -G <ZIP|NSIS>

The software packages are self contained and already include all dependent DLLs (netCDF, GDAL, PCRE, ...).

Users compiling with Windows SDK or Visual Studio Express note that the VC/Redist folder is missing. CMake will issue a warning. You then have to manually edit CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS in cmake/ConfigUser.cmake.