*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.

Build and runtime dependencies

Install Ghostscript, Subversion, CMake (>=2.8.5), netCDF (>=4.0, netCDF-4/HDF5 support mandatory). Optionally install PCRE and GDAL.

Ubuntu/Debian

Install the development dependencies with

sudo aptitude install ghostscript build-essential cmake libnetcdf-dev libgdal1-dev
and follow the instructions in the Building GMT section.

MacOSX

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, e.g., with macports:

sudo port install cmake ghostscript netcdf
Optionally also install the GDAL and PCRE packages:
sudo port install gdal +curl +hdf4 +hdf5 +netcdf
sudo port install pcre
On Mountain Lion you may need to additionally install Athena Widgets toolkit:
sudo port install xorg-libXaw

Or use Fink to install the required packages:

fink install cmake ghostscript netcdf7
Optionally also install GDAL and/or PCRE:
fink install gdal pcre

Building GMT from source

  • Get GMT from source:trunk
    svn checkout svn://gmtserver.soest.hawaii.edu/gmt5/trunk gmt-dev
    
  • Get GSHHG (coastlines, rivers, and political boundaries) from ftp://ftp.soest.hawaii.edu/pwessel/gshhs/gshhg-gmt-nc4-2.2.2.tar.gz
  • 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>/coast)
    set (FLOCK TRUE)
    
  • Build and install GMT:
    cd <path to>/gmt-dev
    mkdir build
    cd build
    cmake ..
    make
    make manpages_all
    make install
    

Generate Documentation (not manpages, optional)

You need LaTeX (e.g., TeX Live) to generate the PDF documentation with

make gmt_pdf_manpages
make gmt_doc
make gmt_doc_shrink
make install
The documentation is also available online and as a platform independent package that you can install along with GMT.
You can choose to install documentation files from an external location instead of generating the PDF and HTML files from the sources. This is convenient if LaTeX is 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. 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 two package options. Invoke CPack instead:

cpack -G <TGZ|TBZ2|Bundle>

Windows

Runtime dependencies

Ghostscript

Install a recent Ghostscript version. We recommend the 32 bit 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.gfd-dennou.org/arch/ucar/netcdf/contrib/win32/. For instance netcdf-4.1.1-win32-bin.zip, and hope that it works. Most certainly it will just not. Hence, we suggest you build netCDF yourself from the CMake bundled sources of netCDF from source:sandbox/win32-dev/netcdf-4.1.3. Because this is a lengthy process we provide the build instructions on a dedicated page.

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)

We assume that you already installed HDF4, HDF5, cURL, netCDF to z:\software. If that is not the case get the sources of netCDF for Windows from source:sandbox/win32-dev/netcdf-4.1.3 and follow the instructions in README.CMake in the source directory.

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 (GMT_INSTALL_MONOLITHIC ON)
    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!

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. 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.0.0-win64-Documentation.zip
GMT-5.0.0-win64-Runtime.zip
GMT-5.0.0-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.