Build from Source
CP2K uses the CMake build system, which detects dependencies and controls the compilation process. This page describes how to obtain a complete CP2K source tree, prepare the dependencies and build and install CP2K.
Note
Historical releases from 2025 or prior used a custom system based on GNU Make and ARCH files, which has been deprecated due to portability and maintenance difficulties. There is no longer interest in providing tech support and documentation for it outside of legacy materials.
The 2026.1 release was the first to exclusively rely on the CMake build system, but the appropriate
CMake configuration options had to be assembled manually due to a lack
of automation. The inconvenience has been addressed since the subsequent 2026.2 release, which
introduced the scripts build_cp2k.sh (for a Toolchain-based build) and
make_cp2k.sh (for a Spack-based build via make_cp2k.sh).
As such, the following documentation applies to the current CP2K master branch and release versions
2026.2 and newer.
Obtaining source code
CP2K is available as a versioned release tarball or through the Git repository. The directory
produced by either method is the root of the CP2K source tree, referred to below as CP2K_ROOT.
Release tarballs
For a stable released version, download the versioned cp2k-{version}.tar.bz2 asset from the
CP2K releases page and unpack it:
tar -xjf cp2k-{version}.tar.bz2
cd cp2k-{version}
Tip
It is strongly recommended to use the versioned release tarball rather than GitHub’s automatically
generated Source code archive, especially for version <=2025.2. The versioned tarball is the
release artifact and contains any source components bundled for that release.
A good practice for downloading anything from the Internet is to verify the file integrity with a
checksum. Use sha256sum cp2k-{version}.tar.bz2 (or the equivalent on other Linux distro) to get
the SHA256 string of the downloaded file, and compare it with what is provided on the releases page
for the version tarball; only when they match should the file be trusted.
Git checkout
A Git checkout is appropriate for development builds or when a particular branch is required:
git clone https://github.com/cp2k/cp2k.git cp2k
cd cp2k
To check out a supported release branch, replace the branch name as appropriate:
git clone --recursive -b support/v{version} https://github.com/cp2k/cp2k.git cp2k
cd cp2k
The --recursive is important for versions <=2025.2, since it includes the DBCSR submodule. If the
repository was cloned without --recursive, initialize the required submodule before building:
git submodule update --init --recursive
Warning
When configuring CP2K with CMake after building the toolchain inside a CP2K Git checkout with tags, DBCSR revision detection can use the enclosing CP2K repository and generate incorrect DBCSR version metadata, causing CMake report an error regarding the DBCSR package discovery; see issue #5184. Therefore, use the versioned release artifact rather than a Git tag for released CP2K versions.
Setting up dependencies and building CP2K
At a minimum, CP2K requires a modern suite of C and Fortran compiler compliant with the C99 and the F2008 standard respectively. For currently supported compiler versions, see the GitHub Wiki page on Compiler Support.
In addition, CP2K requires DBCSR, BLAS, and LAPACK; on top of these, MPI builds require MPI and ScaLAPACK.
Detailed descriptions of available dependencies can be found in the technologies section:
Utilities available from package managers apt-get, dnf and the like, such as python3, pip,
git, less, make, sed, tar, wget, zlib, unzip, bzip2, and xz (this is not an
exhaustive list) are assumed to be readily available infrastructure.
The following two methods provide a CP2K-managed dependency stack. For a manually managed environment, use the CMake configuration described at the end.
Toolchain-based build
The toolchain scripts under the tools/toolchain directory build a CP2K-compatible, self-contained
dependency stack and prepare the environment for a subsequent CP2K build. It is operated from the
install_cp2k_toolchain.sh script and accompanied by build_cp2k.sh. To enter the directory from
CP2K_ROOT and read help messages and the complete list of options, run:
cd ./tools/toolchain/
./install_cp2k_toolchain.sh --help
./build_cp2k.sh --help
To configure and install the dependencies requested by default options, run:
./install_cp2k_toolchain.sh
By default, the dependencies will be built under tools/toolchain/build/ and installed under
tools/toolchain/install/. After completion, run the suggested command in the same working
directory to build and install a copy of CP2K that is linked against them:
./build_cp2k.sh -j {nprocs} --preset native-gnu-x86_64
The -j {nprocs} argument sets the number of parallel build jobs; it can be omitted for automatic
detection of all available CPUs on the current machine, or it can be specified to overwrite the
default value. The --preset argument specifies a CMake preset, which will be explained below at
CMake configuration options; here, the install_cp2k_toolchain.sh option --target-cpu=native
(default if omitted) will suggest an appropriate preset based on the compiler and architecture.
Everything is under the CP2K_ROOT directory mentioned above by default: the CP2K build tree in
build/, and the headers, modules, binary executables and a cp2k_env file in install/. Options
are also available to make installed dependencies and program outside of the source tree.
./install_cp2k_toolchain.sh --install-dir=/opt/cp2k/toolchain
./build_cp2k.sh --prefix /opt/cp2k -j {nprocs} --preset native-gnu-x86_64
Remember to always source the cp2k_env file before starting the program in the current shell and
session. (This is easy to miss on a HPC server where one submits jobs from a login node to another
computing node with job scripts!) For instance, if CP2K_ROOT is /opt/cp2k, the --prefix option
of build_cp2k.sh is the default (i.e. install), then a quick look at the version information
would use the commands below (as input to the command line prompt or as part of the job script).
source /opt/cp2k/install/cp2k_env
cp2k.psmp -v
The intended output is something like this, with the block of compiler options omitted for brevity.
CP2K version 2026.2
Source code revision git:c92cc08
cp2kflags: omp libint fftw3 libxc elpa parallel scalapack mpi_f08 cosma libxs spglib openblas libdftd4 s_dftd3 mctc-lib tblite libvori libbqb
compiler: GCC version 14.3.1 20251022 (Red Hat 14.3.1-4)
compiler target: cpuid 1002 (x86_avx2)
compiler options:
[...]
Pros and Cons
The toolchain-based build is suitable for cases where only the (near-)minimal essential dependencies are desired. Its reliance and interference with external package managers and internet connection is also minimal, and as such it comes in more handy in an offline scenario.
The toolchain does not cover every optional dependency or feature combination, such as DLA-Future, PEXSI, and optional SIRIUS features including NLCG. Its support for GPU-accelerated builds is also limited. If these features are needed, the Spack-based build as detailed in the next section is the more recommended method. In fact, due to difficulties in extending the toolchain for increasingly sophisticated configurations involving nested dependencies, it may be slimmed down or retired in favor of the modern, well-maintained Spack workflow in the future.
Spack-based build via make_cp2k.sh
make_cp2k.sh installs the selected dependency stack with Spack and
then configures, builds, and installs CP2K with CMake. It operates in CP2K_ROOT, the root of the
CP2K source tree.
Run the script with its default options to perform a full build including (almost) all features:
./make_cp2k.sh
For a minimal build from scratch, run:
./make_cp2k.sh -bd -df all
Based on which desired features can be added explicitly for building a tailored CP2K binary.
./make_cp2k.sh -bd -df all -ef libint -ef libxc -ef spglib -ef tblite
Use ./make_cp2k.sh --help to display the complete list of options:
Click to see all options (version 2.4)
Usage: make_cp2k.sh [-bd | --build_deps]
[-ase ASE_VERSION]
[-bd_only | --build_deps_only]
[-bp | --build_path PATH]
[-bsl | --build_static_libcp2k]
[-bt | --build_type (Debug | Release | RelWithDebInfo)]
[-cc | --check_conventions]
[-cray]
[-cv | --cp2k_version (pdbg | psmp | sdbg | ssmp | ssmp-static)]
[-df | --disable | --disable_feature (all | FEATURE | PACKAGE | none)]
[-ef | --enable | --enable_feature (all | FEATURE | PACKAGE | none)]
[-gm | -gpu | --gpu_model (<CUDA SM code> | P100 | V100 | T400 | A100 | H100 | H200 | GH200 | B200 | none)]
[-gromacs GROMACS_VERSION]
[-gv | --gcc_version (10 | 11 | 12 | 13 | 14 | 15 | 16)]
[-h | --help]
[-ip | --install_path PATH]
[-j #PROCESSES]
[-mpi | --mpi_mode (mpich | no | openmpi)]
[-np | --num_packages #PACKAGES]
[-opencl]
[-preset (native-gnu-x86_64 | native-gnu-arm64 | native-intel | none)]
[-rc | --rebuild_cp2k]
[-t | --test "TESTOPTS"]
[-ta | --test_ase]
[-tc | --test_coverage]
[-tg | --test_gromacs]
[-tp | --test_performance "BENCHMARK_PROFILE"]
[-uc | --use_cache (folder | minio | no | none)]
[-ue | --use_externals]
[-v | --verbose]
Flags:
-ase : Build CP2K with ASE support
--build_deps : Force a rebuild of all CP2K dependencies from scratch (removes the spack folder)
--build_deps_only : Rebuild ONLY the CP2K dependencies from scratch (removes the spack folder)
--build_path : Define the CP2K build path (default: ${CP2K_ROOT})
--build_static_libcp2k: Build a static CP2K library libcp2k.a instead of the default shared one libcp2k.so
--build_type : Set preferred CMake build type for CP2K (default: "Release")
--check_conventions : Check compliance with CP2K's coding conventions
--cp2k_version : CP2K version to be built (default: "psmp")
-cray : Use Cray specific spack configuration
--enable_feature : Enable feature or package (default: all)
--disable_feature : Disable feature or package
-gromacs : Build GROMACS with CP2K support
--help : Print this help information
--gcc_version : Use the specified GCC version (default: automatically decided by spack)
--gpu_model : Select GPU model (default: none)
--install_path : Define the CP2K installation path (default: ./install)
-j : Maximum number of processes used in parallel
--mpi_mode : Set preferred MPI mode (default: "mpich")
--num_packages : Maximum number of packages built by spack in parallel (default: 4)
-opencl : Enable the use of the Open Computing Language (OpenCL)
-preset : Use a CMake configure preset, see "cmake --list-presets" (default: native-gnu-x86_64)
--rebuild_cp2k : Rebuild CP2K: removes the build folder (default: no)
--test : Perform a regression test run after a successful build
--test_ase : Build and test CP2K with ASE support
--test_coverage : Analyse the code coverage and generate a coverage report
--test_gromacs : Build and test GROMACS with CP2K support
--test_performance : Perform a benchmark run after a successful build
--use_cache : Use a "folder", a "MinIO" object storage container (requires podman) or "no" cache
Set the environment variable SPACK_CACHE to specify the folder name, e.g.
SPACK_CACHE="file://${CP2K_ROOT}/spack_cache" (default)
--use_externals : Use external packages installed on the host system. This results in much
faster build times, but it can also cause conflicts with outdated packages
pulled in from the host system, e.g. old python or gcc versions
--verbose : Write verbose output
Hints:
- Remove the folder ${CP2K_ROOT}/build to (re)build CP2K from scratch
(see also --rebuild_cp2k flag)
- Remove the folder ${CP2K_ROOT}/spack to (re)build CP2K and all its dependencies from scratch
(see also --build_deps flag)
- The folder ${CP2K_ROOT}/install is updated after each successful run
Packages: all | ace | cosma | deepmd | dftd4 | dlaf | elpa | fftw3 | gauxc | greenx | hdf5 | libfci |
libgint | libint | libsmeagol | libtorch | libvdwxc | libxs | mimic | openpmd | pexsi | plumed |
sirius | spfft | spglib | spla | tblite | trexio | vori
Features: cray_pm_accel_energy | cusolver_mp | dbm_gpu | elpa_gpu | grid_gpu | pw_gpu |
spla_gemm_offloading | unified_memory
make_cp2k.sh creates and reuses a spack/ directory under the CP2K_ROOT. It contains the local
Spack installation and dependency stack. Remove or rename it to rebuild all dependencies from
scratch; --build_deps and --build_deps_only provide the same behavior from the script.
By default, compiled packages are also stored in a local cache. This significantly accelerates later
dependency builds; see --use_cache for the available cache backends.
Note
The way Spack resolves a dependency stack is very different from that in a toolchain-based build; even with the same set of libraries intended to be freshly installed and linked to CP2K, the package download and disk usage can still make an overall difference.
The CP2K built with Spack can be started with the launcher script install/bin/launch. Suppose
CP2K_ROOT is /opt/cp2k, then a version check goes as follows.
/opt/cp2k/install/bin/launch cp2k.psmp -v
Testing
To run a regression test immediately after a successful build, add -t or --test followed by test
options surrounded by double quotes ("TESTOPTS"). The test options will be passed to the script
tests/do_regtest.py as arguments.
./make_cp2k.sh --test "--maxtasks 16 --flagslow"
# Alternatively: in case no options are needed, use an empty quote string
./make_cp2k.sh --test ""
Alternatively, the script install/bin/run_tests produced after a successful build can be used to
start a regression test later. The script prints usage examples at the end of a successful run.
ASE/CP2K
CP2K (>2026.2) can be built and tested with support for the Atomic Simulation Environment (ASE) using
./make_cp2k.sh -bd --test_ase
A Dockerfile for building ASE/CP2K within a container with podman is also available. A usage
example is given in the header of that
Dockerfile.
By default, ASE/CP2K is built using the ASE master branch.
Alternatively, the ASE version can be specified explicitly using the -ase flag
./make_cp2k.sh -bd -ase 3.29.0 --test_ase
but note that the current CP2K development works only with the ASE master branch.
GROMACS/CP2K QM/MM
The latest supported GROMACS release (currently v2026.3) for GROMACS/CP2K QM/MM simulations can be built and tested with
./make_cp2k.sh -bd --test_gromacs
for CP2K versions newer than v2026.2. Other (older) GROMACS versions can be built and tested with
./make_cp2k.sh -bd -gromacs v2025.2 --test_gromacs
A Dockerfile for building GROMACS/CP2K within a container with podman is also available. A usage
example is given in the header of that
Dockerfile.
CMake configuration options
Both toolchain and Spack utilize CMake configurations automatically for convenience after preparing the dependencies. Many of these options allow for CP2K to be built with support of a linked library; refer to the technologies section for details together with description of available dependencies.
Here are some other important general options you may want to know:
-S {Source}Specifies the path to source tree that contains thesrcdirectory and theCMakeLists.txtfile. WithCP2K_ROOTas the working directory, simply use-S .for it.-B {Build}Specifies the path to build. CMake is typically run out-of-tree in a separatebuild/directory under theCP2K_ROOT, corresponding to the-B buildusage. Note that any in-source build or build in any directory with aCMakeLists.txtfile is strictly forbidden.-G {Generator}Specifies which type of build files would be generated. Default isUnix Makefiles, which generates a GNU Makefile and allows you to build with runningmakein the build directory. For GPU-accelerated builds, it is strongly advised to useNinjaas generator, which is also used bymake_cp2k.sh; in this case, please ensure that Ninja is installed on your host system.-DCMAKE_BUILD_TYPEValid vaules areRelease(default) andDebug(enables debug settings and generatespdbgorsdbginstead ofpsmporssmp; recommended for development).-DCMAKE_INSTALL_PREFIXSpecifies the installation path.-DCMAKE_INSTALL_LIBDIRSpecifies the library path under the installation path. The default is defined by CMake’sGNUInstallDirsmodule and is dependent on the host system and architecture. Both toolchainbuild_cp2k.shand Spack-basedmake_cp2k.shset-DCMAKE_INSTALL_LIBDIR=libfor convenience, while an install from package manager distributions respects theGNUInstallDirsconvention.-DBUILD_SHARED_LIBSSpecifies if shared libraries (e.g.libcp2k.so) will be built. Default isON; if setOFF, static libraries (e.g.libcp2k.a) will be built instead.-DCMAKE_POSITION_INDEPENDENT_CODESpecifies if position-independent code is enabled.
Along with some options with CP2K:
-DCP2K_USE_EVERYTHINGEnables all dependencies or not.-DCP2K_DATA_DIRSpecifies the location of the data for basis sets, pseudopotentials, etc. Any data filename specified in the CP2K input without absolute path will be interpreted as under this directory, which CP2K prioritizes when attempting to retrieve the data. It should always be specified as an absolute path. It is created by copying over the existingdatadirectory to the location during installation. Default isshare/cp2k/dataunder-DCMAKE_INSTALL_PREFIX.-DCP2K_ENABLE_CONSISTENCY_CHECKSOnly used for testing.-DCP2K_USE_CRAY_PM_ENERGYEnables power monitoring on Cray systems.-DCP2K_USE_CRAY_PM_ACCEL_ENERGYEnables power monitoring of accelerators on Cray systems.-DCP2K_USE_DBCSR_CONFIGMake dbcsr cmake options (DBCSR_USE_BLA) available.
The options above do not cover architecture- and compiler-specific optimization profiles. Instead,
they are handled by CMake presets
as defined in CMakePresets.json. For instance, the preset native-gnu-x86_64 applies the flag
-march=native to the GNU compilers (namely gfortran, gcc, g++; use --help=target on any of
these, say gfortran --help=target, for more information on the flag) via CMAKE_{LANG}_FLAGS
variables. It will produce binary executables that are optimized against the host machine by
detecting and utilizing the appropriate native CPU instruction sets on the target x86_64
architecture. (Again, be careful on a HPC server where login node and computing node are distinct!)
Currently available CMake presets are listed with the command cmake -S . --list-presets under the
CP2K_ROOT; the native-* ones are more relevant to practical use, while others are meant for
specific developer instrumentation. For non-native optimization, just fall back to the preset none
which does not apply any extraneous compiler flags.
Example
The following example builds CP2K on a x86_64 machine with native optimization in GNU compilers, also enabling CUDA acceleration for Nvidia A100 GPUs and a few optional dependencies:
cd {CP2K_ROOT}
mkdir build/
cmake -S . -B build --preset native-gnu-x86_64 \
-GNinja \
-DCMAKE_INSTALL_PREFIX=install \
-DCMAKE_INSTALL_LIBDIR=lib \
-DCP2K_USE_MPI=ON \
-DCP2K_USE_LIBXC=ON \
-DCP2K_USE_LIBINT2=ON \
-DCP2K_USE_SPGLIB=ON \
-DCP2K_USE_ELPA=ON \
-DCP2K_USE_SPLA=ON \
-DCP2K_USE_SIRIUS=ON \
-DCP2K_USE_COSMA=ON \
-DCP2K_USE_ACCEL=CUDA \
-DCP2K_WITH_GPU=A100
cmake --build build -j 32
cmake --install build
Tip
The commands cmake --build build -j 32 and cmake --install build can be replaced by a single
command cmake --build build --target install -j 32.
Two directories will be created under CP2K_ROOT in this procedure.
build/(name determined by CMake-Bor--buildoptions) contains the CMake build tree and cache. It can be preserved for future rebuilds of CP2K with the same configuration. It can also be removed after installation in order to save disk space or to make way for reconfiguring and rebuilding from scratch; either the CMake commandcmake --build build --target cleanor the genericrm -r build/will work.install/(name determined by-DCMAKE_INSTALL_PREFIX) contains the installed CP2K files. Unlikebuild/,install/must be kept in place as it includes several important subdirectories:binfor binary executables likecp2k.psmpand soft links;includefor module files and headers;liborlib64(name determined by-DCMAKE_INSTALL_LIBDIR) for libraries; andsharefor some other files such as basis data (-DCP2K_DATA_DIR).