<!---
N.B.  The definitive Markdown source of this file is located in the
doc/wiki_source subdirectory of the PLplot source tree.  So only use
the ctrl-v and delete capabilities of the GUI file editor at
SourceForge to make changes to the SourceForge version of this file,
where ctrl-v is used to complete a cut and paste from the definitive
version of this file in the PLplot source tree that is being edited
with your favorite file editor, and delete used to remove extraneous
unmodified text whose changed form has been copied with the cut and
paste.
-->

All PLplot builds are done with our CMake-based build system which gives good results on Linux, Mac OS X, and traditional Unices, and on Windows (Cygwin, MinGW, MinGW/MSYS, and MSVC). After reading this section you should consult [specifics for various platforms](Specifics for various platforms "wikilink") for more details. Also, after a build and install is completed you should follow up by [testing PLplot](testing PLplot "wikilink").

### Building PLplot with our CMake-based build system

To get the most out of our build system, it is important to consult the CMake documentation. That documentation is quite thorough but tends to be a bit scattered so we have collected what we think are the best [general CMake documentation links](general CMake documentation links "wikilink") for your convenience.

After consulting that documentation, [install](http://www.cmake.org/HTML/Install.html) the appropriate package of [CMake](http://www.cmake.org) for your system platform. Note, you must use at least version 2.8.9 of CMake for your PLplot configuration, but our build system works with the latest version (3.0.2) of CMake as well.

### <a name="Generic_Unix_instructions_for_our_build_system"></a>Generic Unix instructions for our build system

#### (Optional) set environment variables to help cmake find system components that are installed in non-standard locations

Here is one particular example (which must be executed before the cmake invocation discussed below).

`export CMAKE_INCLUDE_PATH=/home/software/shapelib/install/include`
`export CMAKE_LIBRARY_PATH=`/home/software/shapelib/install/lib`
`export PKG_CONFIG_PATH=/home/software/libLASi/install/lib/pkgconfig`

For this particular example, <tt>CMAKE_INCLUDE_PATH</tt> and <tt>CMAKE_LIBRARY_PATH</tt> helps cmake to find the headers and library for <tt>shapelib</tt> in a non-standard install location, and <tt>PKG_CONFIG_PATH</tt> helps cmake to use the <tt>pkg-config</tt> command internally to find a libLASi pkg-config module file that is installed in a non-standard location.  Use colon separation if more than one non-standard install location needs to be specified with <tt>CMAKE_INCLUDE_PATH</tt> , <tt>CMAKE_LIBRARY_PATH</tt>, and/or <tt>PKG_CONFIG_PATH</tt>.  Also, although not used in the specific example above, the colon-separated environment variable <tt>PATH</tt> helps cmake find executables that are installed in non-standard locations.

#### (Optional) set environment variables to specify the compilers and compiler flags

Here is one particular example (which must be executed before the cmake invocation discussed below).

`export CC="gcc -O2"`
`export CXX="g++ -O2"`
`export FC="gfortran -O2"`

If you don't set the environment variables above, then by default no compiler options (i.e., no optimization and no debugging symbols) are used for gcc-related compilers for our build system which makes for fast builds, but slow execution.

#### cmake invocation

Here is one typical example.

`mkdir build_dir`
`cd build_dir`
`cmake -DCMAKE_INSTALL_PREFIX=/my/prefix \`
`../plplot.git >& cmake.out`

(CMake is capable of generating builds within the source tree, but we have emphasized a build with a separate build tree here because of its fundamental advantage that the source tree remains clean with no generated files in it.)

Check the cmake.out file for any configuration issues, especially WARNING messages which signal that a component of PLplot has been removed because required system components for that component have not been found.

There are a large number of [CMake options for PLplot](CMake options for PLplot "wikilink") which can be set for cmake to personalize your build. Use the ccmake front end to cmake to obtain documentation of all these options. In the above case we have specified a particular install prefix "/my/prefix".

Note in the above example an initially empty build directory (arbitrarily) named build_dir is used to insure a clean start, and ../plplot.git is the (arbitrary) name of the top-level directory of a freshly cloned git repository. If instead you use a freshly unpacked PLplot source distribution tarball "../plplot.git" will need to be replaced by "../plplot-5.10.0" (for our latest release at time of writing).

To start a fresh build, simply execute

`cd build_dir`
`rm -rf \*`

before invoking cmake. Of course, that "rm" command is an extremely dangerous command (since it removes everything in the current directory and all subdirectories), but you should be okay so long as you cd to the correct directory before executing the "rm" command.

#### Build and install

`make VERBOSE=1 >& make.out`
`make VERBOSE=1 install >& make_install.out`

Check make.out and make_install.out for any errors. Follow up by [testing PLplot](testing PLplot "wikilink").

#### Useful problem reports
If you encounter a problem with the above, then it is important to report the problem with sufficient details (typically to either the plplot-general or plplot-devel mailing lists) so that those familiar with PLplot builds can help you.  This section lists the details that are typically required in a useful problem report.

* Include all environment variables that were set in your report. (The easiest way to do this on Unix is to invoke the command
`printenv > printenv.out`
and  include printenv.out in your report.)

* State the cmake command that was used in your report.

* Include the cmake output (captured as cmake.out above) in your report

* State the PLplot version that was used (e.g., commit ID if you are following the git master branch or release version number if you are using a release tarball) in your report.

* Include the CMake cache file, CMakeCache.txt, in your report.

* Include the verbose results of your build (captured as make.out above) in your report.

* Include the verbose results of your install (captured as make_install.out above) in your report.

The content of this page is available under the [GNU Free Documentation License 1.2](http://www.gnu.org/copyleft/fdl.html).
