GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing docs.lammps.org — 3.2. Build LAMMPS with CMake — LAMMPS documentation 3.2. Build LAMMPS with CMakeThis page describes how to use CMake in general to build LAMMPS. Details for specific compile time settings and options to enable and configure add-on packages are discussed with those packages. Links to those pages on the Build overview page. The following text assumes some familiarity with CMake and focuses on
using the command-line tool Note LAMMPS currently requires CMake version 3.27 or later. Warning You must not mix the traditional make based
LAMMPS build procedure with using CMake. No packages may be
installed or a build been previously attempted in the LAMMPS source
directory by using 3.2.1. Advantages of using CMakeCMake is the preferred way of compiling LAMMPS in contrast to the legacy build system based on GNU make and through (manually customized) makefiles. Using CMake has multiple advantages that are specifically helpful for people with limited experience in compiling software or for people that want to modify or extend LAMMPS.
3.2.2. Getting startedBuilding LAMMPS with CMake is a two-step process. In the first step,
you use CMake to generate a build environment in a new directory. For
that purpose you can use either the command-line utility cd lammps # change to the LAMMPS source distribution directory cmake -S cmake -B build # configure the "build" folder with CMake scripts from "cmake" cmake --build build # compile LAMMPS in the "build" folder This will create a folder called Compilation can take a long time, since LAMMPS is a large project with
many features. If your machine has multiple CPU cores (most do these
days), you can speed this up by compiling multiple source files in
parallel: add After the initial build, whenever you edit LAMMPS source files, enable
or disable packages, change compiler flags or build options, you must
re-compile and relink the LAMMPS executable with After compilation, you may optionally install the LAMMPS executable into your system with: cmake --install build # optional, copy compiled files into installation location This will install the LAMMPS executable and library, some tools (if
configured) and additional files like LAMMPS API headers, manpages,
potential and force field files. The location of the installation tree
defaults to Note If you have set -D CMAKE_INSTALL_PREFIX to install LAMMPS into a system location on a Linux machine, you also have to run (as root) the ldconfig program to update the cache file for fast lookup of system shared libraries. Using the installed library The CMake installation functionality is an experimental work in progress and thus not without problems, especially when writing your own program that is trying to use the LAMMPS C++ classes directly. While there is a well-defined C-language interface with the The following is a minimal CMake example file for using the installed LAMMPS package which represents the current state of development: cmake_minimum_required(VERSION 3.27) project(simpleCC CXX) # set this to the LAMMPS installation location if(NOT CMAKE_PREFIX_PATH) set(CMAKE_PREFIX_PATH $ENV{HOME}/.local) endif() find_package(LAMMPS REQUIRED) add_executable(simpleCC simple.cpp) target_link_libraries(simpleCC PRIVATE LAMMPS::LAMMPS) The #include <lammps/lammps.h> #include <lammps/input.h> #include <lammps/atom.h> #include <lammps/library.h> Using the $ cmake -S . -B build -D CMAKE_PREFIX_PATH=$HOME/Downloads/test-install -- The CXX compiler identification is GNU 15.2.1 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/lib64/ccache/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Found MPI_CXX: /usr/lib64/mpich/lib/libmpicxx.so (found version "4.1") -- Found MPI: TRUE (found version "4.1") found components: CXX -- Found OpenMP_CXX: -fopenmp (found version "4.5") -- Found OpenMP: TRUE (found version "4.5") found components: CXX -- Found LAMMPS: /home/akohlmey/Downloads/test-install/lib64/liblammps.so.0 -- Configuring done (0.9s) -- Generating done (0.0s) -- Build files have been written to: /home/akohlmey/Downloads/test-simple/build $ cmake --build build [ 50%] Building CXX object CMakeFiles/simpleCC.dir/simple.cpp.o [100%] Linking CXX executable simpleCC [100%] Built target simpleCC 3.2.3. Configuration and build optionsThe CMake commands have one mandatory argument: a folder containing a
file called To modify settings, enable or disable features, you need to set
variables with either the For your convenience, we provide CMake presets
that combine multiple settings to enable optional LAMMPS packages or use
a different compiler tool chain. Those are loaded with the Generating files for alternate build tools (e.g. the Ninja build
tool) or project files for IDEs like Xcode or Visual
Studio can be selected using the 3.2.4. Build targetsThe LAMMPS CMake files are set up to have multiple “targets”, one for each component that is set up to be built. If you do not provide an explicit target when building, the target “all” is assumed. This should build all configured targets and include re-running CMake to update the build files when files have changed or new files were added which could require updates in the build process. The most important individual targets are “lammps” to build the LAMMPS library and “lmp” to build the LAMMPS executable. If you want to selectively want to update only one of them you can use the command: cmake --build build --target lmp Especially, when programming LAMMPS and you are making only local changes, or only want to make certain that the code still compiles and links, you may want to skip many of the extra steps that are run by default and then append “/fast” to the target. Example: cmake --build build --target lammps/fast Note that this speeds up the build by avoiding to re-run CMake and skipping a lot of checks for possible dependencies, so you may occasionally need to compile without the “/fast” suffix or use the “all” (= default) target to update everything. This would be required when adding new files, additional dependencies, or making changes to the CMake scripts. Some custom targets, e.g. “install-python” are explicitly excluded from the “all” target and must be built individually. 3.2.5. Multi-configuration build systemsThroughout this manual, it is mostly assumed that LAMMPS is being built
on a Unix-like operating system with “make” or “ninja” as the underlying
“builder”, since this is the most common case. In this case the build
“configuration” is chosen using cmake --build build-multi --config Release In that case the resulting binaries are not in the build folder directly
but in subdirectories corresponding to the build type (i.e. Release in
the example from above). Similarly, for running unit tests the
configuration is selected with the ctest --test-dir build-multi -C Debug The CMake scripts in LAMMPS have basic support for being compiled using
a multi-config build system, but not all of it has been ported. This is
in particular applicable to compiling packages that require additional
libraries that would be downloaded and compiled by CMake. The
3.2.6. Installing CMakeCheck if your machine already has CMake installed: which cmake # do you have it? cmake --version # what specific version you have On clusters or supercomputers which use environment modules to manage software packages, do this: module list # is a module for cmake already loaded? module avail # is a module for cmake available? module load cmake # load cmake module with appropriate name Most Linux distributions offer pre-compiled cmake packages through their
package management system. Some long-term-support distributions,
however, ship a CMake version that is too old for LAMMPS. In that case
you can download pre-compiled binaries of the latest version from
https://cmake.org/download/, or install
CMake into a Python virtual environment with |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |