Skip to content

Commit 093f003

Browse files
authored
cp2k: 2025.1 -> 2025.2, switch to CMake build (#429106)
2 parents fd1e6f4 + dc215d0 commit 093f003

File tree

28 files changed

+864
-302
lines changed

28 files changed

+864
-302
lines changed
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
{
2+
lib,
3+
stdenv,
4+
fetchFromGitHub,
5+
mpiCheckPhaseHook,
6+
cmake,
7+
python3,
8+
gfortran,
9+
blas,
10+
lapack,
11+
dbcsr,
12+
fftw,
13+
libint,
14+
libvori,
15+
libxc,
16+
dftd4,
17+
simple-dftd3,
18+
tblite,
19+
mpi,
20+
gsl,
21+
scalapack,
22+
makeWrapper,
23+
libxsmm,
24+
spglib,
25+
which,
26+
pkg-config,
27+
plumed,
28+
zlib,
29+
hdf5-fortran,
30+
sirius,
31+
libvdwxc,
32+
spla,
33+
spfft,
34+
trexio,
35+
toml-f,
36+
greenx,
37+
gmp,
38+
enableElpa ? false,
39+
elpa,
40+
cudaPackages,
41+
rocmPackages,
42+
config,
43+
gpuBackend ? (
44+
if config.cudaSupport then
45+
"cuda"
46+
else if config.rocmSupport then
47+
"rocm"
48+
else
49+
"none"
50+
),
51+
# Change to a value suitable for your target GPU.
52+
# see https://github.com/cp2k/cp2k/blob/master/CMakeLists.txt#L433
53+
hipTarget ? "gfx908",
54+
cudaTarget ? "80",
55+
}:
56+
57+
assert builtins.elem gpuBackend [
58+
"none"
59+
"cuda"
60+
"rocm"
61+
];
62+
63+
stdenv.mkDerivation rec {
64+
pname = "cp2k";
65+
version = "2025.2";
66+
67+
src = fetchFromGitHub {
68+
owner = "cp2k";
69+
repo = "cp2k";
70+
rev = "v${version}";
71+
hash = "sha256-vfl5rCoFeGtYuZ7LcsVsESjKxFbN5IYDvBSzOqsd64w=";
72+
fetchSubmodules = true;
73+
};
74+
75+
patches = [
76+
# Remove the build command line from the source.
77+
# This avoids dependencies to .dev inputs
78+
./remove-compiler-options.patch
79+
80+
# Fix pkg-config path generation
81+
./pkgconfig.patch
82+
];
83+
84+
nativeBuildInputs = [
85+
python3
86+
cmake
87+
which
88+
makeWrapper
89+
pkg-config
90+
]
91+
++ lib.optional (gpuBackend == "cuda") cudaPackages.cuda_nvcc;
92+
93+
buildInputs = [
94+
gfortran
95+
fftw
96+
gsl
97+
libint
98+
libvori
99+
libxc
100+
dftd4
101+
simple-dftd3
102+
tblite
103+
libxsmm
104+
mpi
105+
spglib
106+
scalapack
107+
blas
108+
lapack
109+
dbcsr
110+
plumed
111+
zlib
112+
hdf5-fortran
113+
sirius
114+
spla
115+
spfft
116+
libvdwxc
117+
trexio
118+
toml-f
119+
greenx
120+
gmp
121+
]
122+
++ lib.optional enableElpa elpa
123+
++ lib.optionals (gpuBackend == "cuda") [
124+
cudaPackages.cuda_cudart
125+
cudaPackages.libcublas
126+
cudaPackages.cuda_nvrtc
127+
]
128+
++ lib.optionals (gpuBackend == "rocm") [
129+
rocmPackages.clr
130+
rocmPackages.rocm-core
131+
rocmPackages.hipblas
132+
rocmPackages.hipfft
133+
rocmPackages.rocblas
134+
];
135+
136+
propagatedBuildInputs = [ (lib.getBin mpi) ];
137+
propagatedUserEnvPkgs = [ mpi ];
138+
139+
postPatch = ''
140+
patchShebangs tools exts/dbcsr/tools/build_utils exts/dbcsr/.cp2k
141+
substituteInPlace exts/build_dbcsr/Makefile \
142+
--replace '/usr/bin/env python3' '${python3}/bin/python' \
143+
--replace 'SHELL = /bin/sh' 'SHELL = bash'
144+
'';
145+
146+
cmakeFlags = [
147+
(lib.strings.cmakeBool "CP2K_USE_DFTD4" true)
148+
(lib.strings.cmakeBool "CP2K_USE_TBLITE" true)
149+
(lib.strings.cmakeBool "CP2K_USE_FFTW3" true)
150+
(lib.strings.cmakeBool "CP2K_USE_HDF5" true)
151+
(lib.strings.cmakeBool "CP2K_USE_LIBINT2" true)
152+
(lib.strings.cmakeBool "CP2K_USE_LIBXC" true)
153+
(lib.strings.cmakeBool "CP2K_USE_MPI" true)
154+
(lib.strings.cmakeBool "CP2K_USE_VORI" true)
155+
(lib.strings.cmakeBool "CP2K_USE_TREXIO" true)
156+
(lib.strings.cmakeBool "CP2K_USE_SPGLIB" true)
157+
(lib.strings.cmakeBool "CP2K_USE_SPLA" true)
158+
(lib.strings.cmakeBool "CP2K_USE_LIBXSMM" true)
159+
(lib.strings.cmakeBool "CP2K_USE_SIRIUS" true)
160+
(lib.strings.cmakeBool "CP2K_USE_LIBVDWXC" true)
161+
(lib.strings.cmakeBool "CP2K_USE_PLUMED" true)
162+
(lib.strings.cmakeBool "CP2K_USE_GREENX" true)
163+
(lib.strings.cmakeBool "CP2K_USE_ELPA" enableElpa)
164+
(lib.strings.cmakeBool "BUILD_SHARED_LIBS" (!stdenv.hostPlatform.isStatic))
165+
]
166+
++ lib.optionals (gpuBackend == "rocm") [
167+
(lib.strings.cmakeFeature "CP2K_USE_ACCEL" "HIP")
168+
(lib.strings.cmakeFeature "CMAKE_HIP_ARCHITECTURES" hipTarget)
169+
]
170+
++ lib.optionals (gpuBackend == "cuda") [
171+
(lib.strings.cmakeFeature "CP2K_USE_ACCEL" "CUDA")
172+
(lib.strings.cmakeFeature "CMAKE_CUDA_ARCHITECTURES" cudaTarget)
173+
];
174+
175+
nativeCheckInputs = [
176+
mpiCheckPhaseHook
177+
];
178+
179+
passthru = {
180+
inherit mpi;
181+
};
182+
183+
postInstall = ''
184+
mkdir -p $out/share/cp2k
185+
cp -r ../data/* $out/share/cp2k
186+
187+
for i in $out/bin/*; do
188+
wrapProgram $i \
189+
--set-default CP2K_DATA_DIR $out/share/cp2k \
190+
--set-default OMP_NUM_THREADS 1
191+
done
192+
'';
193+
194+
doInstallCheck = gpuBackend == "none";
195+
196+
installCheckPhase = ''
197+
runHook preInstallCheck
198+
199+
for TEST in $out/bin/{dbt_tas,dbt,libcp2k,parallel_rng_types,gx_ac}_unittest.psmp; do
200+
mpirun -n 2 $TEST
201+
done
202+
203+
runHook postInstallCheck
204+
'';
205+
206+
meta = {
207+
description = "Quantum chemistry and solid state physics program";
208+
homepage = "https://www.cp2k.org";
209+
license = lib.licenses.gpl2Plus;
210+
maintainers = [ lib.maintainers.sheepforce ];
211+
platforms = [ "x86_64-linux" ];
212+
};
213+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
diff --git a/cmake/libcp2k.pc.in b/cmake/libcp2k.pc.in
2+
index 618af55e28..8d08a51a0c 100644
3+
--- a/cmake/libcp2k.pc.in
4+
+++ b/cmake/libcp2k.pc.in
5+
@@ -1,7 +1,7 @@
6+
prefix="@CMAKE_INSTALL_PREFIX@"
7+
exec_prefix="${prefix}"
8+
-libdir="${prefix}/@CMAKE_INSTALL_LIBDIR@"
9+
-includedir="${prefix}/@CMAKE_INSTALL_INCLUDEDIR@"
10+
+libdir=CMAKE_INSTALL_FULL_LIBDIR@"
11+
+includedir="@CMAKE_INSTALL_FULL_INCLUDEDIR@"
12+
13+
Name: @PROJECT_NAME@
14+
Description: @CMAKE_PROJECT_DESCRIPTION@

0 commit comments

Comments
 (0)