Toolchain: improve generate_cmake_options.sh (#4928)

This commit is contained in:
HE Zilong 2026-03-14 05:28:38 +08:00 committed by GitHub
parent 3b8dca457e
commit 01d6ff2c5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
47 changed files with 292 additions and 157 deletions

View file

@ -92,7 +92,7 @@ find_package(PkgConfig)
# Define the paths for static libraries and executables
# ##############################################################################
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
${cp2k_BINARY_DIR}/lib
${PROJECT_BINARY_DIR}/lib
CACHE PATH "Single output directory for building all libraries.")
# Search for rocm in common locations
@ -356,7 +356,7 @@ if(CP2K_ENABLE_CONSISTENCY_CHECKS)
endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
${cp2k_BINARY_DIR}/bin
${PROJECT_BINARY_DIR}/bin
CACHE PATH "Single output directory for building all executables.")
# Python
@ -1241,7 +1241,7 @@ endif()
message(
"\n\n" # let below line separate
"After building CP2K the regtests can be run with the following command:\n"
" ./tests/do_regtest.py ${cp2k_BINARY_DIR}/bin ${__cp2k_ext}\n\n")
" ./tests/do_regtest.py ${CMAKE_INSTALL_PREFIX}/bin ${__cp2k_ext}\n\n")
# files needed for cmake

View file

@ -46,7 +46,8 @@ RUN ./install_cp2k_toolchain.sh \
--enable-hip=yes \
--gpu-ver=Mi100 \
--with-dbcsr \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -46,7 +46,8 @@ RUN ./install_cp2k_toolchain.sh \
--enable-hip=yes \
--gpu-ver=Mi50 \
--with-dbcsr \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -26,7 +26,8 @@ RUN ./install_cp2k_toolchain.sh \
--mpi-mode=no \
--with-dbcsr \
--with-gcc=system \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -28,7 +28,8 @@ RUN ./install_cp2k_toolchain.sh \
--with-gcc=system \
--with-libtorch=no \
--with-deepmd=no \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -26,7 +26,8 @@ RUN ./install_cp2k_toolchain.sh \
--mpi-mode=mpich \
--with-dbcsr \
--with-gcc=system \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -26,7 +26,8 @@ RUN ./install_cp2k_toolchain.sh \
--mpi-mode=no \
--with-dbcsr \
--with-gcc=system \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -26,7 +26,8 @@ RUN ./install_cp2k_toolchain.sh \
--mpi-mode=mpich \
--with-dbcsr \
--with-gcc=system \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -26,7 +26,8 @@ RUN ./install_cp2k_toolchain.sh \
--mpi-mode=mpich \
--with-dbcsr \
--with-gcc=system \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -39,7 +39,8 @@ RUN ./install_cp2k_toolchain.sh \
--mpi-mode=mpich \
--enable-cuda=yes \
--gpu-ver=A100 \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -39,7 +39,8 @@ RUN ./install_cp2k_toolchain.sh \
--mpi-mode=mpich \
--enable-cuda=yes \
--gpu-ver=P100 \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -39,7 +39,8 @@ RUN ./install_cp2k_toolchain.sh \
--mpi-mode=mpich \
--enable-cuda=yes \
--gpu-ver=V100 \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -26,7 +26,8 @@ RUN ./install_cp2k_toolchain.sh \
--mpi-mode=mpich \
--with-dbcsr \
--with-gcc=system \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -63,7 +63,8 @@ RUN ./install_cp2k_toolchain.sh \
--with-libxsmm=no \
--with-spglib=no \
--with-libvori=no \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -63,7 +63,8 @@ RUN ./install_cp2k_toolchain.sh \
--with-libxsmm=no \
--with-spglib=no \
--with-libvori=no \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -63,7 +63,8 @@ RUN ./install_cp2k_toolchain.sh \
--with-libxsmm=no \
--with-spglib=no \
--with-libvori=no \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -63,7 +63,8 @@ RUN ./install_cp2k_toolchain.sh \
--with-libxsmm=no \
--with-spglib=no \
--with-libvori=no \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -67,7 +67,8 @@ RUN ./install_cp2k_toolchain.sh \
--with-libxsmm=no \
--with-spglib=no \
--with-libvori=no \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -63,7 +63,8 @@ RUN ./install_cp2k_toolchain.sh \
--with-libxsmm=no \
--with-spglib=no \
--with-libvori=no \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -63,7 +63,8 @@ RUN ./install_cp2k_toolchain.sh \
--with-libxsmm=no \
--with-spglib=no \
--with-libvori=no \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -27,7 +27,8 @@ RUN ./install_cp2k_toolchain.sh \
--with-dbcsr \
--with-gcc=system \
--target-cpu=generic \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -26,7 +26,8 @@ RUN ./install_cp2k_toolchain.sh \
--mpi-mode=no \
--with-dbcsr \
--with-gcc=system \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -26,7 +26,8 @@ RUN ./install_cp2k_toolchain.sh \
--mpi-mode=no \
--with-dbcsr \
--with-gcc=system \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -29,7 +29,8 @@ RUN ./install_cp2k_toolchain.sh \
--with-libsmeagol \
--with-libtorch=no \
--with-deepmd=no \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -29,7 +29,8 @@ RUN ./install_cp2k_toolchain.sh \
--with-libsmeagol \
--with-libtorch=no \
--with-deepmd=no \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -29,7 +29,8 @@ RUN ./install_cp2k_toolchain.sh \
--with-libsmeagol \
--with-libtorch=no \
--with-deepmd=no \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -29,7 +29,8 @@ RUN ./install_cp2k_toolchain.sh \
--with-libsmeagol \
--with-libtorch=no \
--with-deepmd=no \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -26,7 +26,8 @@ RUN ./install_cp2k_toolchain.sh \
--mpi-mode=mpich \
--with-dbcsr \
--with-gcc=system \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -63,7 +63,8 @@ RUN ./install_cp2k_toolchain.sh \
--with-libxsmm=no \
--with-spglib=no \
--with-libvori=no \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -26,7 +26,8 @@ RUN ./install_cp2k_toolchain.sh \
--mpi-mode=openmpi \
--with-dbcsr \
--with-gcc=system \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -26,7 +26,8 @@ RUN ./install_cp2k_toolchain.sh \
--mpi-mode=mpich \
--with-dbcsr \
--with-gcc=system \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -26,7 +26,8 @@ RUN ./install_cp2k_toolchain.sh \
--mpi-mode=mpich \
--with-dbcsr \
--with-gcc=system \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -39,7 +39,8 @@ RUN ./install_cp2k_toolchain.sh \
--mpi-mode=mpich \
--enable-cuda=yes \
--gpu-ver=A100 \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -39,7 +39,8 @@ RUN ./install_cp2k_toolchain.sh \
--mpi-mode=mpich \
--enable-cuda=yes \
--gpu-ver=P100 \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -39,7 +39,8 @@ RUN ./install_cp2k_toolchain.sh \
--mpi-mode=mpich \
--enable-cuda=yes \
--gpu-ver=V100 \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -26,7 +26,8 @@ RUN ./install_cp2k_toolchain.sh \
--mpi-mode=no \
--with-dbcsr \
--with-gcc=system \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -26,7 +26,8 @@ RUN ./install_cp2k_toolchain.sh \
--mpi-mode=mpich \
--with-dbcsr \
--with-gcc=system \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -26,7 +26,8 @@ RUN ./install_cp2k_toolchain.sh \
--mpi-mode=mpich \
--with-dbcsr \
--with-gcc=system \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -26,7 +26,8 @@ RUN ./install_cp2k_toolchain.sh \
--mpi-mode=no \
--with-dbcsr \
--with-gcc=system \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -26,7 +26,8 @@ RUN ./install_cp2k_toolchain.sh \
--mpi-mode=no \
--with-dbcsr \
--with-gcc=system \
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -603,7 +603,8 @@ COPY ./tools/toolchain/scripts/VERSION \
COPY ./tools/toolchain/install_cp2k_toolchain.sh .
RUN ./install_cp2k_toolchain.sh \
{install_args_str}
--dry-run
--dry-run \
--list-cmake-options=no
# Dry-run leaves behind config files for the followup install scripts.
# This breaks up the lengthy installation into smaller build steps.

View file

@ -79,83 +79,87 @@ $(basename "$SCRIPT_NAME") [options]
OPTIONS:
-h, --help Show this message and exit.
--help-hpc Show additional hints for HPC users and exit.
-j <n> Number of processors for parallel compiling.
If omitted, the script will automatically try to
determine the number of available processors and use
all of them by default.
--no-check-certificate Bypass verification of server's certificate while
downloading anything from internet via wget command.
In case wget errors about "certificate verification"
or "common name doesn't match requested host name"
occur while downloading tarballs, the recommended
solution is to install the latest wget release;
alternatively, this script can be rerun with this
option in command line.
Security wise this should still be okay as sha256
checksums are validated after every tarball
download. Nevertheless, use this option at your own
risk.
--install-all Set value of all --with-PKG options to "install"
(except --with-intel, --with-intelmpi, --with-amd).
By default, GNU compiler and MPICH are installed.
AFTER this option on the command line, you can set
specific --with-PKG options to another value again
for selective fine controls (see below).
--mpi-mode Select which MPI flavour to use. Available options
are: mpich, openmpi, intelmpi, and no.
If omitted, the script will automatically try to
determine the flavour based on the MPI library
available in system path; alternatively, if any of
--with-mpich, --with-openmpi or --with-intelmpi
options (see below) is explicitly set to values
other than no, the script will follow.
For CRAY (CLE) systems and the case that you use
"--with-mpi" but no MPI installation is detected,
the default flavour is mpich.
By selecting "no", MPI is unsupported and disabled.
--math-mode Select which core math library to use. Available
options are: acml, cray, mkl, and openblas.
If omitted, for non-CRAY systems, mkl is the default
when environment variable \$MKLROOT exists, otherwise
openblas is the drefault; for CRAY (CLE) systems,
cray is the default, corresponding to cray libsci.
Alternatively, if any of --with-acml, --with-mkl,
or --with-openblas options (see below) is explicitly
set to values other than no, the script will follow.
--target-cpu Select the target CPU architecture for compiling.
This option determines the value of -mtune flag in
CFLAGS for compilers. If omitted or set to "native",
compiling will be tuned/optimized for the native
host system, and some instruction sets will be
detected including AVX, AVX2, AVX512,etc.
Alternatively this option can be set depending on
actual target CPU microarchitecture, e.g. "haswell",
"skylake", or just "generic".
Default = native
--gpu-ver Select the target GPU architecture for compiling.
Available options are: K20X, K40, K80, P100, V100,
A100, H100, A40, Mi50, Mi100, Mi250, and no.
This option determines the value of nvcc -arch flag.
Default = no
--libint-lmax Maximum supported angular momentum by libint if the
"--with-libint" option is set to "install".
Available options are: 4, 5, 6, 7. Higher value will
result in more build time and larger library size.
Default = 5
--log-lines The number of final lines from the log file in the
corresponding directory that will be dumped to the
command line in case a package build returns a non-
zero exit code. Due to limited length, this snippet
may not contain the very first warning or error
message.
Default = 200
--dry-run After writing toolchain config and env files to the
install directory, just print a list of effective
settings after resolving known conflicts, then exit
without actually downloading tarballs or building
packages.
-h, --help Show this message and exit.
--help-hpc Show additional hints for HPC users and exit.
-j <n> Number of processors for parallel compiling.
If omitted, the script will automatically try to
determine the number of available processors and use
all of them by default.
--no-check-certificate Bypass verification of server's certificate while
downloading anything from internet via wget command.
In case wget errors about "certificate verification"
or "common name doesn't match requested host name"
occur while downloading tarballs, the recommended
solution is to install the latest wget release;
alternatively, this script can be rerun with this
option in command line.
Security wise this should still be okay as sha256
checksums are validated after every tarball
download. Nevertheless, use this option at your own
risk.
--install-all Set value of all --with-PKG options to "install"
(except --with-intel, --with-intelmpi, --with-amd).
By default, GNU compiler and MPICH are installed.
AFTER this option on the command line, you can set
specific --with-PKG options to another value again
for selective fine controls (see below).
--mpi-mode Select which MPI flavour to use. Available options
are: mpich, openmpi, intelmpi, and no.
If omitted, the script will automatically try to
determine the flavour based on the MPI library
available in system path; alternatively, if any of
--with-mpich, --with-openmpi or --with-intelmpi
options (see below) is explicitly set to values
other than no, the script will follow.
For CRAY (CLE) systems and the case that you use
"--with-mpi" but no MPI installation is detected,
the default flavour is mpich.
By selecting "no", MPI is unsupported and disabled.
--math-mode Select which core math library to use. Available
options are: acml, cray, mkl, and openblas.
If omitted, for non-CRAY systems, mkl is the default
when environment variable \$MKLROOT exists, otherwise
openblas is the drefault; for CRAY (CLE) systems,
cray is the default, corresponding to cray libsci.
Alternatively, if any of --with-acml, --with-mkl,
or --with-openblas options (see below) is explicitly
set to values other than no, the script will follow.
--target-cpu Select the target CPU architecture for compiling.
This option determines the value of -mtune flag in
CFLAGS for compilers. If omitted or set to "native",
compiling will be tuned/optimized for the native
host system, and some instruction sets will be
detected including AVX, AVX2, AVX512,etc.
Alternatively this option can be set depending on
actual target CPU microarchitecture, e.g. "haswell",
"skylake", or just "generic".
Default = native
--gpu-ver Select the target GPU architecture for compiling.
Available options are: K20X, K40, K80, P100, V100,
A100, H100, A40, Mi50, Mi100, Mi250, and no.
This option determines the value of nvcc -arch flag.
Default = no
--libint-lmax Maximum supported angular momentum by libint if the
"--with-libint" option is set to "install".
Available options are: 4, 5, 6, 7. Higher value will
result in more build time and larger library size.
Default = 5
--log-lines The number of final lines from the log file in the
corresponding directory that will be dumped to the
command line in case a package build returns a non-
zero exit code. Due to limited length, this snippet
may not contain the very first warning or error
message.
Default = 200
--dry-run After writing toolchain config and env files to the
install directory, just print a list of effective
settings after resolving known conflicts, then exit
without actually downloading tarballs or building
packages.
--list-cmake-options If yes, generate a list of CMake options for building
CP2K with the toolchain configuration as well as some
further instructions at the end of toolchain.
Default = yes
The --enable-FEATURE options follow the rules:
--enable-FEATURE=yes Enable this particular feature.
@ -549,6 +553,7 @@ else
fi
# default enable options
list_cmake_options="__TRUE__"
dry_run="__FALSE__"
enable_tsan="__FALSE__"
enable_opencl="__FALSE__"
@ -714,6 +719,13 @@ Otherwise use option no."
--dry-run)
dry_run="__TRUE__"
;;
--list-cmake-options*)
list_cmake_options=$(read_enable "${1}")
if [ "${list_cmake_options}" = "__INVALID__" ]; then
report_error "invalid value for --list-cmake-options, please use yes or no"
exit 1
fi
;;
--enable-tsan*)
enable_tsan=$(read_enable "${1}")
if [ "${enable_tsan}" = "__INVALID__" ]; then
@ -1292,17 +1304,19 @@ else
echo "Options have been parsed successfully."
echo "Compiling with ${NPROCS_OVERWRITE} processes for target ${TARGET_CPU}."
echo "# Leak suppressions" > "${INSTALLDIR}"/lsan.supp
./scripts/stage0/install_stage0.sh
./scripts/stage1/install_stage1.sh
./scripts/stage2/install_stage2.sh
./scripts/stage3/install_stage3.sh
./scripts/stage4/install_stage4.sh
./scripts/stage5/install_stage5.sh
./scripts/stage6/install_stage6.sh
./scripts/stage7/install_stage7.sh
./scripts/stage8/install_stage8.sh
./scripts/stage9/install_stage9.sh
"${SCRIPTDIR}"/stage0/install_stage0.sh
"${SCRIPTDIR}"/stage1/install_stage1.sh
"${SCRIPTDIR}"/stage2/install_stage2.sh
"${SCRIPTDIR}"/stage3/install_stage3.sh
"${SCRIPTDIR}"/stage4/install_stage4.sh
"${SCRIPTDIR}"/stage5/install_stage5.sh
"${SCRIPTDIR}"/stage6/install_stage6.sh
"${SCRIPTDIR}"/stage7/install_stage7.sh
"${SCRIPTDIR}"/stage8/install_stage8.sh
"${SCRIPTDIR}"/stage9/install_stage9.sh
fi
# Generate CMake options
./scripts/generate_cmake_options.sh
if [ "${list_cmake_options}" = "__TRUE__" ]; then
"${SCRIPTDIR}"/generate_cmake_options.sh
fi

View file

@ -12,13 +12,64 @@ source "${SCRIPT_DIR}"/signal_trap.sh
source "${INSTALLDIR}"/toolchain.conf
source "${INSTALLDIR}"/toolchain.env
export CP2K_ROOT=$(cd ${ROOTDIR}/../.. && pwd)
# This script assumes a working environment as follows:
# cp2k <- variable ${CP2K_ROOT}; CMake option -S
# ├── CMakeLists.txt <- * file to be parsed in this script
# ├── data <- CP2K data directory; CMake option -DCP2K_DATA_DIR
# ├── build <- to-be-created; CMake option -B
# ├── install <- to-be-created; CMake option -DCMAKE_INSTALL_PREFIX
# ├── src <- CP2K source code directory
# └── tools
# └── toolchain <- working directory; variable ${ROOTDIR}
# ├── install_cp2k_toolchain.sh <- script being executed calling this script
# ├── scripts <- variable ${SCRIPT_DIR}
# │ ├── common_vars.sh
# │ ├── tool_kit.sh
# │ └── generate_cmake_options.sh <- this script
# └── install <- variable ${INSTALLDIR}
# ├── setup <- * file to be parsed in this script
# ├── toolchain.conf <- * file to be parsed in this script
# └── toolchain.env <- * file to be parsed in this script
#
# First, validate existence of relevant upper-level directory and file
printf "\n========================== %s =========================\n" \
"Generating CMake options for building CP2K"
CP2K_ROOT=$(cd "${ROOTDIR}/../.." && pwd)
if [ -d "${CP2K_ROOT}/src" ]; then
cat << EOF
Root directory of CP2K with source code is found as ${CP2K_ROOT}
(path is exported to variable \${CP2K_ROOT}).
Build directory will be \${CP2K_ROOT}/build.
Install directory will be \${CP2K_ROOT}/install.
EOF
export CP2K_ROOT
CMAKE_OPTIONS="-S ${CP2K_ROOT} -B ${CP2K_ROOT}/build"
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_INSTALL_PREFIX=${CP2K_ROOT}/install"
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_INSTALL_LIBDIR=lib"
else
report_error ${LINENO} "\${CP2K_ROOT} does not have subdirectory src, so it
cannot be set as source path for CMake options."
return 1
fi
if [ -f "${CP2K_ROOT}/CMakeLists.txt" ] && [ -r "${CP2K_ROOT}/CMakeLists.txt" ]; then
echo "${CP2K_ROOT}/CMakeLists.txt exists; will be parsed for CMake options."
else
report_error ${LINENO} "${CP2K_ROOT}/CMakeLists.txt cannot be found or read;
suggested CMake option will be incomplete and/or incorrect."
return 1
fi
if [ -d "${CP2K_ROOT}/data" ]; then
echo "Data directory ${CP2K_ROOT}/data is found and set as -DCP2K_DATA_DIR."
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCP2K_DATA_DIR=${CP2K_ROOT}/data"
else
report_warning ${LINENO} "Data directory ${CP2K_ROOT}/data cannot be found;
please set -DCP2K_DATA_DIR to actual path manually."
fi
# ------------------------------------------------------------------------
# generate cmake options for compiling cp2k
# ------------------------------------------------------------------------
# Build the program in source tree for convenience
CMAKE_OPTIONS="-DCMAKE_INSTALL_PREFIX=../install -DCP2K_DATA_DIR=${CP2K_ROOT}/data"
if [ -n "$(grep -- "--install-all" ${INSTALLDIR}/setup)" ]; then
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCP2K_USE_EVERYTHING=ON -DCP2K_USE_DLAF=OFF -DCP2K_USE_PEXSI=OFF"
# Since "--install-all" can be used together with "--with-PKG=no", an extra safeguard is added here
@ -68,32 +119,69 @@ else
done
fi
# Export variable for CMake options to setup file
cat << EOF >> "${SETUPFILE}"
# ==================== Setup for CP2K ==================== #
export CP2K_ROOT="${CP2K_ROOT}"
export CP2K_CMAKE_OPTIONS="${CMAKE_OPTIONS}"
prepend_path PATH "${CP2K_ROOT}/install/bin"
prepend_path LD_LIBRARY_PATH "${CP2K_ROOT}/install/lib"
prepend_path LD_RUN_PATH "${CP2K_ROOT}/install/lib"
prepend_path LIBRARY_PATH "${CP2K_ROOT}/install/lib"
prepend_path PKG_CONFIG_PATH "${CP2K_ROOT}/install/lib/pkgconfig"
prepend_path CMAKE_PREFIX_PATH "${CP2K_ROOT}"
EOF
cat << EOF
Suggested cmake command if toolchain is built with your options:
cmake ${CMAKE_OPTIONS}
These options are also collected in the variable \${CP2K_CMAKE_OPTIONS} that is
exported at the end of setup file ${SETUPFILE}.
EOF
# -------------------------
# print out user instructions
# -------------------------
if [ "${dry_run}" = "__TRUE__" ]; then
cat << EOF
Suggested cmake command if toolchain is built with your options:
cmake .. ${CMAKE_OPTIONS}
EOF
else
if [ ! "${dry_run}" = "__TRUE__" ]; then
echo
cat << EOF | tee ${INSTALLDIR}/cp2k_installation_guide.txt
========================== usage =========================
Done! The "build" directory can now be removed.
========================== Epilogue =========================
Toolchain is now ready for building CP2K! Instructions for next steps:
To use the installed tools and libraries and cp2k version compiled with it you will first need to execute at the prompt:
source ${SETUPFILE}
(1) Optional - remove packages in ./build directory to free up disk space:
rm -rf ${BUILDDIR}
However, do NOT delete or move the ./install directory from now on.
It's recommended for you to build CP2K like this after executing above command:
cd ${CP2K_ROOT}
mkdir build && cd build
cmake .. ${CMAKE_OPTIONS}
make install -j $(get_nprocs)
(2) Required - source setup file to activate toolchain-configured dependencies:
source ${SETUPFILE}
This setup file MUST also be sourced whenever CP2K built with this toolchain
is executed. If modules have been used to estabilish environment variables
and paths, remember to load these modules prior to sourcing setup file.
When completed, you can run "make clean" or delete this build directory to free up some space.
(3) Required - go to root directory of CP2K and configure CMake with options
suggested above:
cd ${CP2K_ROOT}
cmake ${CMAKE_OPTIONS}
Other commands from ${CP2K_ROOT}/CMakeLists.txt can also be added. For more
information about available build options, see documentation:
https://manual.cp2k.org/trunk/getting-started/build-from-source.html.
Alternative to copy-paste long lines in terminal is to use a variable from
setup file for CMake options, which is not to be quoted so that whitespace
delimiters allow it to expand to command options in shell:
cmake \${CP2K_CMAKE_OPTIONS}
(4) Required - build CP2K with command:
cmake --build ${CP2K_ROOT}/build --target install -j $(get_nprocs)
It may be helpful to also save a copy of command line messages to log files:
cmake --build ${CP2K_ROOT}/build --target install -j $(get_nprocs) 2>&1 | tee install.log
(5) Optional - once build is completed, remove ./build directory like in (1):
cmake --build ${CP2K_ROOT}/build --target clean
Again, do not move the ./install directory from now on.
(6) Recommended - perform regtest as is suggested at the end of (3).
For more information about available build options, see: https://manual.cp2k.org/trunk/getting-started/build-from-source.html.
This message is saved to "${INSTALLDIR}/cp2k_installation_guide.txt".
EOF
fi

View file

@ -137,10 +137,7 @@ if [ "$with_openblas" != "__DONTUSE__" ]; then
prepend_path LD_LIBRARY_PATH "$pkg_install_dir/lib"
prepend_path LD_RUN_PATH "$pkg_install_dir/lib"
prepend_path LIBRARY_PATH "$pkg_install_dir/lib"
prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig"
prepend_path CMAKE_PREFIX_PATH "$pkg_install_dir"
prepend_path CPATH "$pkg_install_dir/include"
export OPENBLAS_ROOT=${pkg_install_dir}
EOF
fi
cat << EOF >> "${BUILDDIR}/setup_openblas"

View file

@ -250,8 +250,6 @@ prepend_path LD_LIBRARY_PATH "${COSMA_LIBDIR}"
prepend_path LD_RUN_PATH "${COSMA_LIBDIR}"
prepend_path LIBRARY_PATH "${COSMA_LIBDIR}"
prepend_path CPATH "$pkg_install_dir/include"
export COSMA_INCLUDE_DIR="$pkg_install_dir/include"
export COSMA_ROOT="${pkg_install_dir}"
prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig"
prepend_path CMAKE_PREFIX_PATH "$pkg_install_dir"
EOF

View file

@ -96,7 +96,6 @@ prepend_path LD_RUN_PATH "${pkg_install_dir}/lib"
prepend_path LIBRARY_PATH "${pkg_install_dir}/lib"
prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig"
prepend_path CMAKE_PREFIX_PATH "$pkg_install_dir"
export SCALAPACK_ROOT="${pkg_install_dir}"
EOF
fi
cat << EOF >> "${BUILDDIR}/setup_scalapack"

View file

@ -80,7 +80,6 @@ prepend_path LD_LIBRARY_PATH "${pkg_install_dir}/lib"
prepend_path LD_RUN_PATH "${pkg_install_dir}/lib"
prepend_path LIBRARY_PATH "${pkg_install_dir}/lib"
export LIBVORI_LIBS="${LIBVORI_LIBS}"
export LIBVORI_ROOT="${pkg_install_dir}"
prepend_path PKG_CONFIG_PATH "$pkg_install_dir/lib/pkgconfig"
prepend_path CMAKE_PREFIX_PATH "$pkg_install_dir"
EOF