Files
lammps/doc/html/Howto_cmake.html
2025-01-13 14:55:48 +00:00

690 lines
51 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>8.6.1. Using CMake with LAMMPS &mdash; LAMMPS documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/sphinx-design.min.css" type="text/css" />
<link rel="stylesheet" href="_static/css/lammps.css" type="text/css" />
<link rel="shortcut icon" href="_static/lammps.ico"/>
<link rel="canonical" href="https://docs.lammps.org/Howto_cmake.html" />
<!--[if lt IE 9]>
<script src="_static/js/html5shiv.min.js"></script>
<![endif]-->
<script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=5929fcd5"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/design-tabs.js?v=f930bc37"></script>
<script async="async" src="_static/mathjax/es5/tex-mml-chtml.js?v=cadf963e"></script>
<script src="_static/js/theme.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="8.6.2. LAMMPS GitHub tutorial" href="Howto_github.html" />
<link rel="prev" title="8.5.12. Magnetic spins" href="Howto_spins.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="Manual.html">
<img src="_static/lammps-logo.png" class="logo" alt="Logo"/>
</a>
<div class="lammps_version">Version: <b>19 Nov 2024</b></div>
<div class="lammps_release">git info: </div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<p class="caption" role="heading"><span class="caption-text">User Guide</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="Intro.html">1. Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="Install.html">2. Install LAMMPS</a></li>
<li class="toctree-l1"><a class="reference internal" href="Build.html">3. Build LAMMPS</a></li>
<li class="toctree-l1"><a class="reference internal" href="Run_head.html">4. Run LAMMPS</a></li>
<li class="toctree-l1"><a class="reference internal" href="Commands.html">5. Commands</a></li>
<li class="toctree-l1"><a class="reference internal" href="Packages.html">6. Optional packages</a></li>
<li class="toctree-l1"><a class="reference internal" href="Speed.html">7. Accelerate performance</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="Howto.html">8. Howto discussions</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="Howto.html#general-howto">8.1. General howto</a></li>
<li class="toctree-l2"><a class="reference internal" href="Howto.html#settings-howto">8.2. Settings howto</a></li>
<li class="toctree-l2"><a class="reference internal" href="Howto.html#analysis-howto">8.3. Analysis howto</a></li>
<li class="toctree-l2"><a class="reference internal" href="Howto.html#force-fields-howto">8.4. Force fields howto</a></li>
<li class="toctree-l2"><a class="reference internal" href="Howto.html#packages-howto">8.5. Packages howto</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="Howto.html#tutorials-howto">8.6. Tutorials howto</a><ul class="current">
<li class="toctree-l3 current"><a class="current reference internal" href="#">8.6.1. Using CMake with LAMMPS</a></li>
<li class="toctree-l3"><a class="reference internal" href="Howto_github.html">8.6.2. LAMMPS GitHub tutorial</a></li>
<li class="toctree-l3"><a class="reference internal" href="Howto_lammps_gui.html">8.6.3. Using LAMMPS-GUI</a></li>
<li class="toctree-l3"><a class="reference internal" href="Howto_moltemplate.html">8.6.4. Moltemplate Tutorial</a></li>
<li class="toctree-l3"><a class="reference internal" href="Howto_pylammps.html">8.6.5. PyLammps Tutorial</a></li>
<li class="toctree-l3"><a class="reference internal" href="Howto_wsl.html">8.6.6. Using LAMMPS on Windows 10 with WSL</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="Examples.html">9. Example scripts</a></li>
<li class="toctree-l1"><a class="reference internal" href="Tools.html">10. Auxiliary tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="Errors.html">11. Errors</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Programmer Guide</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="Library.html">1. LAMMPS Library Interfaces</a></li>
<li class="toctree-l1"><a class="reference internal" href="Python_head.html">2. Use Python with LAMMPS</a></li>
<li class="toctree-l1"><a class="reference internal" href="Modify.html">3. Modifying &amp; extending LAMMPS</a></li>
<li class="toctree-l1"><a class="reference internal" href="Developer.html">4. Information for Developers</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Command Reference</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="commands_list.html">Commands</a></li>
<li class="toctree-l1"><a class="reference internal" href="fixes.html">Fix Styles</a></li>
<li class="toctree-l1"><a class="reference internal" href="computes.html">Compute Styles</a></li>
<li class="toctree-l1"><a class="reference internal" href="pairs.html">Pair Styles</a></li>
<li class="toctree-l1"><a class="reference internal" href="bonds.html">Bond Styles</a></li>
<li class="toctree-l1"><a class="reference internal" href="angles.html">Angle Styles</a></li>
<li class="toctree-l1"><a class="reference internal" href="dihedrals.html">Dihedral Styles</a></li>
<li class="toctree-l1"><a class="reference internal" href="impropers.html">Improper Styles</a></li>
<li class="toctree-l1"><a class="reference internal" href="dumps.html">Dump Styles</a></li>
<li class="toctree-l1"><a class="reference internal" href="fix_modify_atc_commands.html">fix_modify AtC commands</a></li>
<li class="toctree-l1"><a class="reference internal" href="Bibliography.html">Bibliography</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="Manual.html">LAMMPS</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content style-external-links">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="Manual.html" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item"><a href="Howto.html"><span class="section-number">8. </span>Howto discussions</a></li>
<li class="breadcrumb-item active"><span class="section-number">8.6.1. </span>Using CMake with LAMMPS</li>
<li class="wy-breadcrumbs-aside">
<a href="https://www.lammps.org"><img src="_static/lammps-logo.png" width="64" height="16" alt="LAMMPS Homepage"></a> | <a href="Commands_all.html">Commands</a>
</li>
</ul><div class="rst-breadcrumbs-buttons" role="navigation" aria-label="Sequential page navigation">
<a href="Howto_spins.html" class="btn btn-neutral float-left" title="8.5.12. Magnetic spins" accesskey="p"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
<a href="Howto_github.html" class="btn btn-neutral float-right" title="8.6.2. LAMMPS GitHub tutorial" accesskey="n">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
</div>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<p><span class="math notranslate nohighlight">\(\renewcommand{\AA}{\text{Å}}\)</span></p>
<section id="using-cmake-with-lammps">
<h1><span class="section-number">8.6.1. </span>Using CMake with LAMMPS<a class="headerlink" href="#using-cmake-with-lammps" title="Link to this heading"></a></h1>
<p>The support for building LAMMPS with CMake is a recent addition to
LAMMPS thanks to the efforts of Christoph Junghans (LANL) and Richard
Berger (LANL). One of the key strengths of CMake is that it is not
tied to a specific platform or build system. Instead it generates the
files necessary to build and develop for different build systems and on
different platforms. Note, that this applies to the build system itself
not the LAMMPS code. In other words, without additional porting effort,
it is not possible - for example - to compile LAMMPS with Visual C++ on
Windows. The build system output can also include support files
necessary to program LAMMPS as a project in integrated development
environments (IDE) like Eclipse, Visual Studio, QtCreator, Xcode,
CodeBlocks, Kate and others.</p>
<p>A second important feature of CMake is that it can detect and validate
available libraries, optimal settings, available support tools and so
on, so that by default LAMMPS will take advantage of available tools
without requiring to provide the details about how to enable/integrate
them.</p>
<p>The downside of this approach is, that there is some complexity
associated with running CMake itself and how to customize the building
of LAMMPS. This tutorial will show how to manage this through some
selected examples. Please see the chapter about <a class="reference internal" href="Build.html"><span class="doc">building LAMMPS</span></a> for descriptions of specific flags and options for LAMMPS in
general and for specific packages.</p>
<p>CMake can be used through either the command-line interface (CLI)
program <code class="docutils literal notranslate"><span class="pre">cmake</span></code> (or <code class="docutils literal notranslate"><span class="pre">cmake3</span></code>), a text mode interactive user
interface (TUI) program <code class="docutils literal notranslate"><span class="pre">ccmake</span></code> (or <code class="docutils literal notranslate"><span class="pre">ccmake3</span></code>), or a graphical user
interface (GUI) program <code class="docutils literal notranslate"><span class="pre">cmake-gui</span></code>. All of them are portable
software available on all supported platforms and can be used
interchangeably. As of LAMMPS version 2 August 2023, the minimum
required CMake version is 3.16.</p>
<p>All details about features and settings for CMake are in the <a class="reference external" href="https://cmake.org/documentation/">CMake
online documentation</a>. We focus
below on the most important aspects with respect to compiling LAMMPS.</p>
<section id="prerequisites">
<h2>Prerequisites<a class="headerlink" href="#prerequisites" title="Link to this heading"></a></h2>
<p>This tutorial assumes that you are operating in a command-line environment
using a shell like Bash or Zsh.</p>
<ul class="simple">
<li><p>Linux: any Terminal window will work or text console</p></li>
<li><p>macOS: launch the Terminal application</p></li>
<li><p>Windows 10 or 11: install and run the <a class="reference internal" href="Howto_wsl.html"><span class="doc">Windows Subsystem for Linux</span></a></p></li>
<li><p>other Unix-like operating systems like FreeBSD</p></li>
</ul>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>It is also possible to use CMake on Windows 10 or 11 through either the Microsoft
Visual Studio IDE with the bundled CMake or from the Windows command prompt using
a separately installed CMake package, both using the native Microsoft Visual C++
compilers and (optionally) the Microsoft MPI SDK. This tutorial, however, only
covers unix-like command-line interfaces.</p>
</div>
<p>We also assume that you have downloaded and unpacked a recent LAMMPS source code package
or used Git to create a clone of the LAMMPS sources on your compilation machine.</p>
<p>You should change into the top level directory of the LAMMPS source tree all
paths mentioned in the tutorial are relative to that. Immediately after downloading
it should look like this:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>ls
<span class="go">bench doc lib potentials README tools</span>
<span class="go">cmake examples LICENSE python src</span>
</pre></div>
</div>
</section>
<section id="build-versus-source-directory">
<h2>Build versus source directory<a class="headerlink" href="#build-versus-source-directory" title="Link to this heading"></a></h2>
<p>When using CMake the build procedure is separated into multiple distinct phases:</p>
<blockquote>
<div><ol class="arabic simple">
<li><p><strong>Configuration:</strong> detect or define which features and settings
should be enable and used and how LAMMPS should be compiled</p></li>
<li><p><strong>Compilation:</strong> generate and compile all necessary source files
and build libraries and executables.</p></li>
<li><p><strong>Installation:</strong> copy selected files from the compilation into
your file system, so they can be used without having to keep the
source and build tree around.</p></li>
</ol>
</div></blockquote>
<p>The configuration and compilation of LAMMPS has to happen in a dedicated
<em>build directory</em> which must be different from the source directory.
Also the source directory (<code class="docutils literal notranslate"><span class="pre">src</span></code>) must remain pristine, so it is not
allowed to “install” packages using the traditional make process and
after an compilation attempt all created source files must be removed.
This can be achieved with <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">no-all</span> <span class="pre">purge</span></code>.</p>
<p>You can pick <strong>any</strong> folder outside the source tree. We recommend to
create a folder <code class="docutils literal notranslate"><span class="pre">build</span></code> in the top-level directory, or multiple
folders in case you want to have separate builds of LAMMPS with
different options (<code class="docutils literal notranslate"><span class="pre">build-parallel</span></code>, <code class="docutils literal notranslate"><span class="pre">build-serial</span></code>) or with
different compilers (<code class="docutils literal notranslate"><span class="pre">build-gnu</span></code>, <code class="docutils literal notranslate"><span class="pre">build-clang</span></code>, <code class="docutils literal notranslate"><span class="pre">build-intel</span></code>)
and so on. All the auxiliary files created by one build process
(executable, object files, log files, etc) are stored in this directory
or subdirectories within it that CMake creates.</p>
</section>
<section id="running-cmake">
<h2>Running CMake<a class="headerlink" href="#running-cmake" title="Link to this heading"></a></h2>
<section id="cli-version">
<h3>CLI version<a class="headerlink" href="#cli-version" title="Link to this heading"></a></h3>
<p>In the (empty) <code class="docutils literal notranslate"><span class="pre">build</span></code> directory, we now run the command <code class="docutils literal notranslate"><span class="pre">cmake</span>
<span class="pre">../cmake</span></code>, which will start the configuration phase and you will see
the progress of the configuration printed to the screen followed by a
summary of the enabled features, options and compiler settings. A typical
summary screen will look like this:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>cmake<span class="w"> </span>../cmake/
<span class="go">-- The CXX compiler identification is GNU 8.2.0</span>
<span class="go">-- Check for working CXX compiler: /opt/tools/gcc-8.2.0/bin/c++</span>
<span class="go">-- Check for working CXX compiler: /opt/tools/gcc-8.2.0/bin/c++ - works</span>
<span class="go">-- Detecting CXX compiler ABI info</span>
<span class="go">-- Detecting CXX compiler ABI info - done</span>
<span class="go">-- Detecting CXX compile features</span>
<span class="go">-- Detecting CXX compile features - done</span>
<span class="go">-- Found Git: /usr/bin/git (found version &quot;2.25.2&quot;)</span>
<span class="go">-- Running check for auto-generated files from make-based build system</span>
<span class="go">-- Found MPI_CXX: /usr/lib64/mpich/lib/libmpicxx.so (found version &quot;3.1&quot;)</span>
<span class="go">-- Found MPI: TRUE (found version &quot;3.1&quot;)</span>
<span class="go">-- Looking for C++ include omp.h</span>
<span class="go">-- Looking for C++ include omp.h - found</span>
<span class="go">-- Found OpenMP_CXX: -fopenmp (found version &quot;4.5&quot;)</span>
<span class="go">-- Found OpenMP: TRUE (found version &quot;4.5&quot;)</span>
<span class="go">-- Found JPEG: /usr/lib64/libjpeg.so (found version &quot;62&quot;)</span>
<span class="go">-- Found PNG: /usr/lib64/libpng.so (found version &quot;1.6.37&quot;)</span>
<span class="go">-- Found ZLIB: /usr/lib64/libz.so (found version &quot;1.2.11&quot;)</span>
<span class="go">-- Found GZIP: /usr/bin/gzip</span>
<span class="go">-- Found FFMPEG: /usr/bin/ffmpeg</span>
<span class="go">-- Performing Test COMPILER_SUPPORTS-ffast-math</span>
<span class="go">-- Performing Test COMPILER_SUPPORTS-ffast-math - Success</span>
<span class="go">-- Performing Test COMPILER_SUPPORTS-march=native</span>
<span class="go">-- Performing Test COMPILER_SUPPORTS-march=native - Success</span>
<span class="go">-- Looking for C++ include cmath</span>
<span class="go">-- Looking for C++ include cmath - found</span>
<span class="go">-- Generating style_angle.h...</span>
<span class="go">[...]</span>
<span class="go">-- Generating lmpinstalledpkgs.h...</span>
<span class="go">-- The following tools and libraries have been found and configured:</span>
<span class="go"> * Git</span>
<span class="go"> * MPI</span>
<span class="go"> * OpenMP</span>
<span class="go"> * JPEG</span>
<span class="go"> * PNG</span>
<span class="go"> * ZLIB</span>
<span class="go">-- &lt;&lt;&lt; Build configuration &gt;&gt;&gt;</span>
<span class="go"> Build type: RelWithDebInfo</span>
<span class="go"> Install path: /home/akohlmey/.local</span>
<span class="go"> Generator: Unix Makefiles using /usr/bin/gmake</span>
<span class="go">-- &lt;&lt;&lt; Compilers and Flags: &gt;&gt;&gt;</span>
<span class="go">-- C++ Compiler: /opt/tools/gcc-8.2.0/bin/c++</span>
<span class="go"> Type: GNU</span>
<span class="go"> Version: 8.2.0</span>
<span class="go"> C++ Flags: -O2 -g -DNDEBUG</span>
<span class="go"> Defines: LAMMPS_SMALLBIG;LAMMPS_MEMALIGN=64;LAMMPS_JPEG;LAMMPS_PNG;LAMMPS_GZIP;LAMMPS_FFMPEG</span>
<span class="go"> Options: -ffast-math;-march=native</span>
<span class="go">-- &lt;&lt;&lt; Linker flags: &gt;&gt;&gt;</span>
<span class="go">-- Executable name: lmp</span>
<span class="go">-- Static library flags:</span>
<span class="go">-- &lt;&lt;&lt; MPI flags &gt;&gt;&gt;</span>
<span class="go">-- MPI includes: /usr/include/mpich-x86_64</span>
<span class="go">-- MPI libraries: /usr/lib64/mpich/lib/libmpicxx.so;/usr/lib64/mpich/lib/libmpi.so;</span>
<span class="go">-- Configuring done</span>
<span class="go">-- Generating done</span>
<span class="go">-- Build files have been written to: /home/akohlmey/compile/lammps/build</span>
</pre></div>
</div>
<p>The <code class="docutils literal notranslate"><span class="pre">cmake</span></code> command has one mandatory argument, and that is a folder
with either the file <code class="docutils literal notranslate"><span class="pre">CMakeLists.txt</span></code> or <code class="docutils literal notranslate"><span class="pre">CMakeCache.txt</span></code>. The
<code class="docutils literal notranslate"><span class="pre">CMakeCache.txt</span></code> file is created during the CMake configuration run
and contains all active settings, thus after a first run of CMake
all future runs in the build folder can use the folder <code class="docutils literal notranslate"><span class="pre">.</span></code> and CMake
will know where to find the CMake scripts and reload the settings
from the previous step. This means, that one can modify an existing
configuration by re-running CMake, but only needs to provide flags
indicating the desired change, everything else will be retained. One
can also mix compilation and configuration, i.e. start with a minimal
configuration and then, if needed, enable additional features and
recompile.</p>
<p>The steps above <strong>will NOT compile the code</strong>. The compilation can be
started in a portable fashion with <code class="docutils literal notranslate"><span class="pre">cmake</span> <span class="pre">--build</span> <span class="pre">.</span></code>, or you use the
selected built tool, e.g. <code class="docutils literal notranslate"><span class="pre">make</span></code>.</p>
</section>
<section id="tui-version">
<h3>TUI version<a class="headerlink" href="#tui-version" title="Link to this heading"></a></h3>
<p>For the text mode UI CMake program the basic principle is the same.
You start the command <code class="docutils literal notranslate"><span class="pre">ccmake</span> <span class="pre">../cmake</span></code> in the <code class="docutils literal notranslate"><span class="pre">build</span></code> folder.</p>
<table class="docutils align-default">
<tbody>
<tr class="row-odd"><td><figure class="align-center" id="id1">
<a class="reference internal image-reference" href="_images/ccmake-initial.png"><img alt="_images/ccmake-initial.png" src="_images/ccmake-initial.png" style="width: 378.18px; height: 231.99px;" />
</a>
<figcaption>
<p><span class="caption-text">Initial <code class="docutils literal notranslate"><span class="pre">ccmake</span></code> screen</span><a class="headerlink" href="#id1" title="Link to this image"></a></p>
</figcaption>
</figure>
</td>
<td><figure class="align-center" id="id2">
<a class="reference internal image-reference" href="_images/ccmake-config.png"><img alt="_images/ccmake-config.png" src="_images/ccmake-config.png" style="width: 378.18px; height: 231.99px;" />
</a>
<figcaption>
<p><span class="caption-text">Configure output of <code class="docutils literal notranslate"><span class="pre">ccmake</span></code></span><a class="headerlink" href="#id2" title="Link to this image"></a></p>
</figcaption>
</figure>
</td>
<td><figure class="align-center" id="id3">
<a class="reference internal image-reference" href="_images/ccmake-options.png"><img alt="_images/ccmake-options.png" src="_images/ccmake-options.png" style="width: 378.18px; height: 231.99px;" />
</a>
<figcaption>
<p><span class="caption-text">Options screen of <code class="docutils literal notranslate"><span class="pre">ccmake</span></code></span><a class="headerlink" href="#id3" title="Link to this image"></a></p>
</figcaption>
</figure>
</td>
</tr>
</tbody>
</table>
<p>This will show you the initial screen (left image) with the empty
configuration cache. Now you type the c key to run the configuration
step. That will do a first configuration run and show the summary
(center image). You exit the summary screen with e and see now the
main screen with detected options and settings. You can now make changes
by moving and down with the arrow keys of the keyboard and modify
entries. For on/off settings, the enter key will toggle the state.
For others, hitting enter will allow you to modify the value and
you commit the change by hitting the enter key again or cancel using
the escape key. All “new” settings will be marked with a star *
and for as long as one setting is marked like this, you have to
re-run the configuration by hitting the c key again, sometimes
multiple times unless the TUI shows the word “generate” next to the
letter g and by hitting the g key the build files will be written
to the folder and the TUI exits. You can quit without generating
build files by hitting q.</p>
</section>
<section id="gui-version">
<h3>GUI version<a class="headerlink" href="#gui-version" title="Link to this heading"></a></h3>
<p>For the graphical CMake program the steps are similar to the TUI
version. You can type the command <code class="docutils literal notranslate"><span class="pre">cmake-gui</span> <span class="pre">../cmake</span></code> in the
<code class="docutils literal notranslate"><span class="pre">build</span></code> folder. In this case the path to the CMake script folder is
not required, it can also be entered from the GUI.</p>
<table class="docutils align-default">
<tbody>
<tr class="row-odd"><td><figure class="align-center" id="id4">
<a class="reference internal image-reference" href="_images/cmake-gui-initial.png"><img alt="_images/cmake-gui-initial.png" src="_images/cmake-gui-initial.png" style="width: 369.20000000000005px; height: 274.8px;" />
</a>
<figcaption>
<p><span class="caption-text">Initial <code class="docutils literal notranslate"><span class="pre">cmake-gui</span></code> screen</span><a class="headerlink" href="#id4" title="Link to this image"></a></p>
</figcaption>
</figure>
</td>
<td><figure class="align-center" id="id5">
<a class="reference internal image-reference" href="_images/cmake-gui-popup.png"><img alt="_images/cmake-gui-popup.png" src="_images/cmake-gui-popup.png" style="width: 304.8px; height: 232.2px;" />
</a>
<figcaption>
<p><span class="caption-text">Generator selection in <code class="docutils literal notranslate"><span class="pre">cmake-gui</span></code></span><a class="headerlink" href="#id5" title="Link to this image"></a></p>
</figcaption>
</figure>
</td>
<td><figure class="align-center" id="id6">
<a class="reference internal image-reference" href="_images/cmake-gui-options.png"><img alt="_images/cmake-gui-options.png" src="_images/cmake-gui-options.png" style="width: 369.20000000000005px; height: 274.8px;" />
</a>
<figcaption>
<p><span class="caption-text">Options screen of <code class="docutils literal notranslate"><span class="pre">cmake-gui</span></code></span><a class="headerlink" href="#id6" title="Link to this image"></a></p>
</figcaption>
</figure>
</td>
</tr>
</tbody>
</table>
<p>Again, you start with an empty configuration cache (left image) and need
to start the configuration step. For the very first configuration in a
folder, you will have a pop-up dialog (center image) asking to select
the desired build tool and some configuration settings (stick with the
default) and then you get the option screen with all new settings
highlighted in red. You can modify them (or not) and click on the
“configure” button again until satisfied and click on the “generate”
button to write out the build files. You can exit the GUI from the
“File” menu or hit “ctrl-q”.</p>
</section>
</section>
<section id="setting-options">
<h2>Setting options<a class="headerlink" href="#setting-options" title="Link to this heading"></a></h2>
<p>Options that enable, disable or modify settings are modified by setting
the value of CMake variables. This is done on the command-line with the
<em>-D</em> flag in the format <code class="docutils literal notranslate"><span class="pre">-D</span> <span class="pre">VARIABLE=value</span></code>, e.g. <code class="docutils literal notranslate"><span class="pre">-D</span>
<span class="pre">CMAKE_BUILD_TYPE=Release</span></code> or <code class="docutils literal notranslate"><span class="pre">-D</span> <span class="pre">BUILD_MPI=on</span></code>. There is one quirk:
when used before the CMake directory, there may be a space between the
<em>-D</em> flag and the variable, after it must not be. Such CMake variables
can have boolean values (on/off, yes/no, or 1/0 are all valid) or are
strings representing a choice, or a path, or are free format. If the
string would contain whitespace, it must be put in quotes, for example
<code class="docutils literal notranslate"><span class="pre">-D</span> <span class="pre">CMAKE_TUNE_FLAGS=&quot;-ftree-vectorize</span> <span class="pre">-ffast-math&quot;</span></code>.</p>
<p>CMake variables fall into two categories: 1) common CMake variables that
are used by default for any CMake configuration setup and 2) project
specific variables, i.e. settings that are specific for LAMMPS.
Also CMake variables can be flagged as <em>advanced</em>, which means they are
not shown in the text mode or graphical CMake program in the overview
of all settings by default, but only when explicitly requested (by hitting
the t key or clicking on the Advanced check-box).</p>
<section id="some-common-cmake-variables">
<h3>Some common CMake variables<a class="headerlink" href="#some-common-cmake-variables" title="Link to this heading"></a></h3>
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Variable</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">CMAKE_INSTALL_PREFIX</span></code></p></td>
<td><p>root directory of install location for <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">install</span></code> (default: <code class="docutils literal notranslate"><span class="pre">$HOME/.local</span></code>)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">LAMMPS_INSTALL_RPATH</span></code></p></td>
<td><p>set or remove runtime path setting from binaries for <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">install</span></code> (default: <code class="docutils literal notranslate"><span class="pre">off</span></code>)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">CMAKE_BUILD_TYPE</span></code></p></td>
<td><p>controls compilation options:
one of <code class="docutils literal notranslate"><span class="pre">RelWithDebInfo</span></code> (default), <code class="docutils literal notranslate"><span class="pre">Release</span></code>, <code class="docutils literal notranslate"><span class="pre">Debug</span></code>, <code class="docutils literal notranslate"><span class="pre">MinSizeRel</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">BUILD_SHARED_LIBS</span></code></p></td>
<td><p>if set to <code class="docutils literal notranslate"><span class="pre">on</span></code> build the LAMMPS library as shared library (default: <code class="docutils literal notranslate"><span class="pre">off</span></code>)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">CMAKE_MAKE_PROGRAM</span></code></p></td>
<td><p>name/path of the compilation command (default depends on <em>-G</em> option, usually <code class="docutils literal notranslate"><span class="pre">make</span></code>)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">CMAKE_VERBOSE_MAKEFILE</span></code></p></td>
<td><p>if set to <code class="docutils literal notranslate"><span class="pre">on</span></code> echo commands while executing during build (default: <code class="docutils literal notranslate"><span class="pre">off</span></code>)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">CMAKE_C_COMPILER</span></code></p></td>
<td><p>C compiler to be used for compilation (default: system specific, <code class="docutils literal notranslate"><span class="pre">gcc</span></code> on Linux)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">CMAKE_CXX_COMPILER</span></code></p></td>
<td><p>C++ compiler to be used for compilation (default: system specific, <code class="docutils literal notranslate"><span class="pre">g++</span></code> on Linux)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">CMAKE_Fortran_COMPILER</span></code></p></td>
<td><p>Fortran compiler to be used for compilation (default: system specific, <code class="docutils literal notranslate"><span class="pre">gfortran</span></code> on Linux)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">CXX_COMPILER_LAUNCHER</span></code></p></td>
<td><p>tool to launch the C++ compiler, e.g. <code class="docutils literal notranslate"><span class="pre">ccache</span></code> or <code class="docutils literal notranslate"><span class="pre">distcc</span></code> for faster compilation (default: empty)</p></td>
</tr>
</tbody>
</table>
</section>
<section id="some-common-lammps-specific-variables">
<h3>Some common LAMMPS specific variables<a class="headerlink" href="#some-common-lammps-specific-variables" title="Link to this heading"></a></h3>
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Variable</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">BUILD_MPI</span></code></p></td>
<td><p>build LAMMPS with MPI support (default: <code class="docutils literal notranslate"><span class="pre">on</span></code> if a working MPI available, else <code class="docutils literal notranslate"><span class="pre">off</span></code>)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">BUILD_OMP</span></code></p></td>
<td><p>build LAMMPS with OpenMP support (default: <code class="docutils literal notranslate"><span class="pre">on</span></code> if compiler supports OpenMP fully, else <code class="docutils literal notranslate"><span class="pre">off</span></code>)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">BUILD_TOOLS</span></code></p></td>
<td><p>compile some additional executables from the <code class="docutils literal notranslate"><span class="pre">tools</span></code> folder (default: <code class="docutils literal notranslate"><span class="pre">off</span></code>)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">BUILD_DOC</span></code></p></td>
<td><p>include building the HTML format documentation for packaging/installing (default: <code class="docutils literal notranslate"><span class="pre">off</span></code>)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">CMAKE_TUNE_FLAGS</span></code></p></td>
<td><p>common compiler flags, for optimization or instrumentation (default:)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">LAMMPS_MACHINE</span></code></p></td>
<td><p>when set to <code class="docutils literal notranslate"><span class="pre">name</span></code> the LAMMPS executable and library will be called <code class="docutils literal notranslate"><span class="pre">lmp_name</span></code> and <code class="docutils literal notranslate"><span class="pre">liblammps_name.a</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">FFT</span></code></p></td>
<td><p>select which FFT library to use: <code class="docutils literal notranslate"><span class="pre">FFTW3</span></code>, <code class="docutils literal notranslate"><span class="pre">MKL</span></code>, <code class="docutils literal notranslate"><span class="pre">KISS</span></code> (default, unless FFTW3 is found)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">FFT_KOKKOS</span></code></p></td>
<td><p>select which FFT library to use in Kokkos-enabled styles: <code class="docutils literal notranslate"><span class="pre">FFTW3</span></code>, <code class="docutils literal notranslate"><span class="pre">MKL</span></code>, <code class="docutils literal notranslate"><span class="pre">HIPFFT</span></code>, <code class="docutils literal notranslate"><span class="pre">CUFFT</span></code>, <code class="docutils literal notranslate"><span class="pre">MKL_GPU</span></code>, <code class="docutils literal notranslate"><span class="pre">KISS</span></code> (default)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">FFT_SINGLE</span></code></p></td>
<td><p>select whether to use single precision FFTs (default: <code class="docutils literal notranslate"><span class="pre">off</span></code>)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">WITH_JPEG</span></code></p></td>
<td><p>whether to support JPEG format in <a class="reference internal" href="dump_image.html"><span class="doc">dump image</span></a> (default: <code class="docutils literal notranslate"><span class="pre">on</span></code> if found)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">WITH_PNG</span></code></p></td>
<td><p>whether to support PNG format in <a class="reference internal" href="dump_image.html"><span class="doc">dump image</span></a> (default: <code class="docutils literal notranslate"><span class="pre">on</span></code> if found)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">WITH_GZIP</span></code></p></td>
<td><p>whether to support reading and writing compressed files (default: <code class="docutils literal notranslate"><span class="pre">on</span></code> if found)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">WITH_FFMPEG</span></code></p></td>
<td><p>whether to support generating movies with <a class="reference internal" href="dump_image.html"><span class="doc">dump movie</span></a> (default: <code class="docutils literal notranslate"><span class="pre">on</span></code> if found)</p></td>
</tr>
</tbody>
</table>
</section>
<section id="enabling-or-disabling-lammps-packages">
<h3>Enabling or disabling LAMMPS packages<a class="headerlink" href="#enabling-or-disabling-lammps-packages" title="Link to this heading"></a></h3>
<p>The LAMMPS software is organized into a common core that is always
included and a large number of <a class="reference internal" href="Packages.html"><span class="doc">add-on packages</span></a> that
have to be enabled to be included into a LAMMPS executable. Packages
are enabled through setting variables of the kind <code class="docutils literal notranslate"><span class="pre">PKG_&lt;NAME&gt;</span></code> to
<code class="docutils literal notranslate"><span class="pre">on</span></code> and disabled by setting them to <code class="docutils literal notranslate"><span class="pre">off</span></code> (or using <code class="docutils literal notranslate"><span class="pre">yes</span></code>,
<code class="docutils literal notranslate"><span class="pre">no</span></code>, <code class="docutils literal notranslate"><span class="pre">1</span></code>, <code class="docutils literal notranslate"><span class="pre">0</span></code> correspondingly). <code class="docutils literal notranslate"><span class="pre">&lt;NAME&gt;</span></code> has to be replaced by
the name of the package, e.g. <code class="docutils literal notranslate"><span class="pre">MOLECULE</span></code> or <code class="docutils literal notranslate"><span class="pre">EXTRA-PAIR</span></code>.</p>
</section>
</section>
<section id="using-presets">
<h2>Using presets<a class="headerlink" href="#using-presets" title="Link to this heading"></a></h2>
<p>Since LAMMPS has a lot of optional features and packages, specifying
them all on the command-line can be tedious. Or when selecting a
different compiler toolchain, multiple options have to be changed
consistently and that is rather error prone. Or when enabling certain
packages, they require consistent settings to be operated in a
particular mode. For this purpose, we are providing a selection of
“preset files” for CMake in the folder <code class="docutils literal notranslate"><span class="pre">cmake/presets</span></code>. They
represent a way to pre-load or override the CMake configuration cache by
setting or changing CMake variables. Preset files are loaded using the
<em>-C</em> command-line flag. You can combine loading multiple preset files or
change some variables later with additional <em>-D</em> flags. A few examples:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>cmake<span class="w"> </span>-C<span class="w"> </span>../cmake/presets/basic.cmake<span class="w"> </span>-D<span class="w"> </span><span class="nv">PKG_MISC</span><span class="o">=</span>on<span class="w"> </span>../cmake
cmake<span class="w"> </span>-C<span class="w"> </span>../cmake/presets/clang.cmake<span class="w"> </span>-C<span class="w"> </span>../cmake/presets/most.cmake<span class="w"> </span>../cmake
cmake<span class="w"> </span>-C<span class="w"> </span>../cmake/presets/basic.cmake<span class="w"> </span>-D<span class="w"> </span><span class="nv">BUILD_MPI</span><span class="o">=</span>off<span class="w"> </span>../cmake
</pre></div>
</div>
<p>The first command will install the packages <code class="docutils literal notranslate"><span class="pre">KSPACE</span></code>, <code class="docutils literal notranslate"><span class="pre">MANYBODY</span></code>,
<code class="docutils literal notranslate"><span class="pre">MOLECULE</span></code>, <code class="docutils literal notranslate"><span class="pre">RIGID</span></code> and <code class="docutils literal notranslate"><span class="pre">MISC</span></code>; the first four from the preset
file and the fifth from the explicit variable definition. The second
command will first switch the compiler toolchain to use the Clang
compilers and install a large number of packages that are not depending
on any special external libraries or tools and are not very unusual.
The third command will enable the first four packages like above and
then enforce compiling LAMMPS as a serial program (using the MPI STUBS
library).</p>
<p>It is also possible to do this incrementally.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>cmake<span class="w"> </span>-C<span class="w"> </span>../cmake/presets/basic.cmake<span class="w"> </span>../cmake
cmake<span class="w"> </span>-D<span class="w"> </span><span class="nv">PKG_MISC</span><span class="o">=</span>on<span class="w"> </span>.
</pre></div>
</div>
<p>will achieve the same final configuration as in the first example above.
In this scenario it is particularly convenient to do the second
configuration step using either the text mode or graphical user
interface (<code class="docutils literal notranslate"><span class="pre">ccmake</span></code> or <code class="docutils literal notranslate"><span class="pre">cmake-gui</span></code>).</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Using a preset to select a compiler package (<code class="docutils literal notranslate"><span class="pre">clang.cmake</span></code>,
<code class="docutils literal notranslate"><span class="pre">gcc.cmake</span></code>, <code class="docutils literal notranslate"><span class="pre">intel.cmake</span></code>, <code class="docutils literal notranslate"><span class="pre">oneapi.cmake</span></code>, or <code class="docutils literal notranslate"><span class="pre">pgi.cmake</span></code>)
are an exception to the mechanism of updating the configuration
incrementally, as they will trigger a reset of cached internal CMake
settings and thus reset settings to their default values.</p>
</div>
</section>
<section id="compilation-and-build-targets">
<h2>Compilation and build targets<a class="headerlink" href="#compilation-and-build-targets" title="Link to this heading"></a></h2>
<p>The actual compilation will be started by running the selected build
command (on Linux this is by default <code class="docutils literal notranslate"><span class="pre">make</span></code>, see below how to select
alternatives). You can also use the portable command <code class="docutils literal notranslate"><span class="pre">cmake</span> <span class="pre">--build</span> <span class="pre">.</span></code>
which will adapt to whatever the selected build command is.
This is particularly convenient, if you have set a custom build command
via the <code class="docutils literal notranslate"><span class="pre">CMAKE_MAKE_PROGRAM</span></code> variable.</p>
<p>When calling the build program, you can also select which “target” is to
be build through appending the <code class="docutils literal notranslate"><span class="pre">--target</span></code> flag and the name of the target
to the build command. When using <code class="docutils literal notranslate"><span class="pre">make</span></code> as build tool, you can just append
the target name to the command. Example: <code class="docutils literal notranslate"><span class="pre">cmake</span> <span class="pre">--build</span> <span class="pre">.</span> <span class="pre">--target</span> <span class="pre">all</span></code> or
<code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">all</span></code>. The following abstract targets are available:</p>
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Target</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">all</span></code></p></td>
<td><p>build “everything” (default)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">lammps</span></code></p></td>
<td><p>build the LAMMPS library and executable</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">doc</span></code></p></td>
<td><p>build the HTML documentation (if configured)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">install</span></code></p></td>
<td><p>install all target files into folders in <code class="docutils literal notranslate"><span class="pre">CMAKE_INSTALL_PREFIX</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">test</span></code></p></td>
<td><p>run some tests (if configured with <code class="docutils literal notranslate"><span class="pre">-D</span> <span class="pre">ENABLE_TESTING=on</span></code>)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">clean</span></code></p></td>
<td><p>remove all generated files</p></td>
</tr>
</tbody>
</table>
</section>
<section id="choosing-generators">
<h2>Choosing generators<a class="headerlink" href="#choosing-generators" title="Link to this heading"></a></h2>
<p>While CMake usually defaults to creating makefiles to compile software
with the <code class="docutils literal notranslate"><span class="pre">make</span></code> program, it supports multiple alternate build tools
(e.g. <code class="docutils literal notranslate"><span class="pre">ninja-build</span></code> which tends to be faster and more efficient in
parallelizing builds than <code class="docutils literal notranslate"><span class="pre">make</span></code>) and can generate project files for
integrated development environments (IDEs) like VisualStudio, Eclipse or
CodeBlocks. This is specific to how the local CMake version was
configured and compiled. The list of available options can be seen at
the end of the output of <code class="docutils literal notranslate"><span class="pre">cmake</span> <span class="pre">--help</span></code>. Example on Fedora 31 this is:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Generators
The following generators are available on this platform (* marks default):
* Unix Makefiles = Generates standard UNIX makefiles.
Green Hills MULTI = Generates Green Hills MULTI files
(experimental, work-in-progress).
Ninja = Generates build.ninja files.
Ninja Multi-Config = Generates build-&lt;Config&gt;.ninja files.
Watcom WMake = Generates Watcom WMake makefiles.
CodeBlocks - Ninja = Generates CodeBlocks project files.
CodeBlocks - Unix Makefiles = Generates CodeBlocks project files.
CodeLite - Ninja = Generates CodeLite project files.
CodeLite - Unix Makefiles = Generates CodeLite project files.
Sublime Text 2 - Ninja = Generates Sublime Text 2 project files.
Sublime Text 2 - Unix Makefiles
= Generates Sublime Text 2 project files.
Kate - Ninja = Generates Kate project files.
Kate - Unix Makefiles = Generates Kate project files.
Eclipse CDT4 - Ninja = Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.
</pre></div>
</div>
<p>Below is a screenshot of using the CodeBlocks IDE with the ninja build tool
after running CMake as follows:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>cmake<span class="w"> </span>-G<span class="w"> </span><span class="s1">&#39;CodeBlocks - Ninja&#39;</span><span class="w"> </span>../cmake/presets/most.cmake<span class="w"> </span>../cmake/
</pre></div>
</div>
<img alt="_images/cmake-codeblocks.png" class="align-center" src="_images/cmake-codeblocks.png" />
</section>
</section>
</div>
</div>
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
<a href="Howto_spins.html" class="btn btn-neutral float-left" title="8.5.12. Magnetic spins" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
<a href="Howto_github.html" class="btn btn-neutral float-right" title="8.6.2. LAMMPS GitHub tutorial" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
</div>
<hr/>
<div role="contentinfo">
<p>&#169; Copyright 2003-2025 Sandia Corporation.</p>
</div>
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(false);
});
</script>
</body>
</html>