CMake Lists
CMake Lists
---------------------------------------------------------------------------------
----------------!
#! CP2K: A general program to perform molecular dynamics simulations
!
#! Copyright 2000-2022 CP2K developers group <https://cp2k.org>
!
#!
!
#! SPDX-License-Identifier: GPL-2.0-or-later
!
#!---------------------------------------------------------------------------------
----------------!
cmake_minimum_required(VERSION 3.22)
#
===================================================================================
==============
# REQUIRE OUT-OF-SOURCE BUILDS
file(TO_CMAKE_PATH "${PROJECT_BINARY_DIR}/CMakeLists.txt" LOC_PATH)
if(EXISTS "${LOC_PATH}")
message(
FATAL_ERROR
"You cannot build in a source directory (or any directory with a
CMakeLists.txt file). Please make a build subdirectory."
)
endif()
#
===================================================================================
==============
# PROJECT AND VERSION
include(CMakeDependentOption)
cmake_policy(SET CMP0048 NEW)
set(VERSION_MAJOR 22)
# anything above 12 is to indicate that it is devel-branch. The git hash commit
# is the only important information to give. It is retrieved few lines below.
set(VERSION_MINOR 99)
set(VERSION_PATCH 00)
project(
cp2k
DESCRIPTION "CP2K"
HOMEPAGE_URL "https://www.cp2k.org"
VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
LANGUAGES Fortran C CXX)
set(cp2k_APIVERSION ${cp2k_VERSION_MAJOR}.${cp2k_VERSION_MINOR})
find_package(PkgConfig)
# ##############################################################################
# Define the paths for static libraries and executables
# ##############################################################################
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
${cp2k_BINARY_DIR}/lib
CACHE PATH "Single output directory for building all libraries.")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
${cp2k_BINARY_DIR}/bin
CACHE PATH "Single output directory for building all executables.")
#
===================================================================================
==============
# OPTIONS
cmake_dependent_option(CP2K_ENABLE_ELPA_OPENMP_SUPPORT
"Enable elpa openmp support" OFF "CP2K_USE_ELPA" OFF)
cmake_dependent_option(CP2K_ENABLE_FFTW3_OPENMP_SUPPORT
"Enable FFTW openmp support" ON "CP2K_USE_FFTW3" OFF)
cmake_dependent_option(CP2K_ENABLE_FFTW3_THREADS_SUPPORT
"Enable FFTW THREADS support" OFF "CP2K_USE_FFTW3" OFF)
# ##############################################################################
# # gpu related options # #
# ##############################################################################
set(CP2K_WITH_GPU
"P100"
CACHE STRING
"Set the CUDA GPU architecture if HIP is enabled (default: P100)")
set_property(
CACHE CP2K_WITH_GPU PROPERTY STRINGS ${CP2K_SUPPORTED_CUDA_ARCHITECTURES}
${CP2K_SUPPORTED_HIP_ARCHITECTURES})
set(CP2K_USE_ACCEL
"NONE"
CACHE STRING "Set hardware acceleartion support: CUDA, HIP")
set_property(CACHE CP2K_USE_ACCEL
PROPERTY STRINGS ${CP2K_SUPPORTED_ACCELERATION_TARGETS})
cmake_dependent_option(
CP2K_USE_SPLA_GEMM_OFFLOADING ON
"Enable SPLA dgemm offloading (only valid with gpu support on)"
"(NOT CP2K_USE_ACCEL MATCHES \"NONE\") AND (CP2K_USE_SPLA)" OFF)
# ##############################################################################
#
# GPU debug options
#
# ##############################################################################
cmake_dependent_option(
CP2K_DISABLE_GRID_GPU
OFF
"disable the hardware accelerated backend for grid related functions. It is only
effective when general gpu support is enabled."
"CP2K_DEBUG_MODE"
OFF)
cmake_dependent_option(
CP2K_DISABLE_PW_GPU
OFF
"disable the ffts accelerated (mostly GPU) backend. It is only effective when
general gpu support is enabled."
"CP2K_DEBUG_MODE"
OFF)
cmake_dependent_option(
CP2K_DISABLE_DBM_GPU
OFF
"disable the dbm accelerated (mostly GPU) backend. It is only effective when
general gpu support is enabled."
"CP2K_DEBUG_MODE"
OFF)
cmake_dependent_option(
CP2K_DBCSR_CPU_ONLY "Use DBCSR compiled without GPU support." OFF
"CP2K_DEBUG_MODE" OFF)
# Python
#
# this module looks preferably for version 3 of Python. If not found, version 2
# is searched. In CMake 3.15, if a python virtual environment is activated, it
# will search the virtual environment for a python interpreter before searching
# elsewhere in the system. In CMake <3.15, the system is searched before the
# virtual environment.
if(NOT Python_EXECUTABLE)
# If the python interpreter isn't specified as a command line option, look for
# it:
find_package(
Python
COMPONENTS Interpreter
REQUIRED)
endif()
# get the git hash Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE CP2K_GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND hostnamectl --transient
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE CP2K_HOST_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE)
add_custom_target(
AlwaysCheckGit
COMMAND
${CMAKE_COMMAND} -DRUN_CHECK_GIT_VERSION=1
-Dpre_configure_dir=${pre_configure_dir}
-Dpost_configure_file=${post_configure_dir}
-DGIT_HASH_CACHE=${GIT_HASH_CACHE} -P ${CURRENT_LIST_DIR}/CheckGit.cmake
BYPRODUCTS ${post_configure_file})
# MPI
if(NOT MPI_Fortran_HAVE_F90_MODULE)
message(
FATAL_ERROR
"\
The listed MPI implementation does not provide the required mpi.mod interface. \
When using the GNU compiler in combination with Intel MPI, please use the \
Intel MPI compiler wrappers. Check the INSTALL.md for more information.")
endif()
if("${MPI_Fortran_LIBRARY_VERSION_STRING}" MATCHES "Open MPI v2.1"
OR "${MPI_Fortran_LIBRARY_VERSION_STRING}" MATCHES "Open MPI v3.1")
message(
WARNING
"RMA with ${MPI_Fortran_LIBRARY_VERSION_STRING} is not supported due to
issues with its implementation."
" Please use a newer version of OpenMPI or switch to MPICH if you plan on
using MPI-RMA."
)
endif()
set(CP2K_USE_HIP OFF)
set(CP2K_USE_CUDA OFF)
enable_language(CUDA)
find_package(CUDAToolkit REQUIRED)
# set cuda architecture number and compilation flags. Taken from dbcsr
set(CP2K_ACC_ARCH_NUMBER ${CP2K_GPU_ARCH_NUMBER_${CP2K_WITH_GPU}})
set(CMAKE_CUDA_ARCHITECTURES ${CP2K_ACC_ARCH_NUMBER})
set(CUDA_ARCHITECTURES ${CP2K_ACC_ARCH_NUMBER})
if(WITH_CUDA_PROFILING)
find_library(
CUDA_NVTOOLSEXT nvToolsExt
PATHS ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}
DOC "Building with CUDA profiling requires the nvToolsExt CUDA library"
REQUIRED)
message(STATUS "Found nvToolsExt: ${CUDA_NVTOOLSEXT}")
endif()
set(CP2K_USE_CUDA ON)
message(STATUS ``"-- CUDA compiler and libraries found")
elseif(CP2K_USE_ACCEL MATCHES "HIP")
enable_language(HIP)
# Find hip
find_package(hip REQUIRED IMPORTED CONFIG)
find_package(hipfft REQUIRED IMPORTED CONFIG)
find_package(hipblas REQUIRED IMPORTED CONFIG)
set(CMAKE_HIP_ARCHITECTURES gfx801 gfx900 gfx90a)
if(NOT CMAKE_BUILD_TYPE)
set(HIP_RELEASE_OPTIONS "-O3 -g -DNDEBUG")
elseif(${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo")
set(HIP_RELEASE_OPTIONS "-O3 -g -DNDEBUG")
elseif(${CMAKE_BUILD_TYPE} STREQUAL "Release")
set(HIP_RELEASE_OPTIONS "-O3 -DNDEBUG")
elseif(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
set(HIP_RELEASE_OPTIONS "-O0 -g")
endif()
set(CP2K_ACC_ARCH_NUMBER ${CP2K_GPU_ARCH_NUMBER_${CP2K_WITH_GPU}})
set(CP2K_USE_HIP ON)
endif()
#
===================================================================================
==============
# PACKAGE DISCOVERY (compiler configuration can impact package discovery)
# ==================================
if(CP2K_USE_ELPA)
find_package(Elpa REQUIRED)
endif()
if(CP2K_USE_LIBXC)
find_package(LibXC 6.0.0 REQUIRED)
endif()
if(CP2K_USE_COSMA)
find_package(cosma REQUIRED HINTS "${COSMA_ROOT}" "$ENV(COSMA_ROOT)")
get_target_property(COSMA_INCLUDE_DIRS cosma::cosma
INTERFACE_INCLUDE_DIRECTORIES)
if(NOT COSMA_INCLUDE_DIRS)
set(COSMA_INCLUDE_DIRS "/usr/include;/usr/include/cosma")
endif()
if(CP2K_USE_VORI)
find_package(LibVORI REQUIRED)
endif()
# FFTW3
if(CP2K_USE_FFTW3)
find_package(Fftw REQUIRED)
if(CP2K_ENABLE_FFTW3_THREADS_SUPPORT AND CP2K_ENABLE_FFTW3_OPENMP_SUPPORT)
message(
FATAL_ERROR
"Fftw3 threads and openmp supports can not be used at the same time")
endif()
# QUIP
if(CP2K_USE_QUIP)
find_package(Quip REQUIRED)
endif()
# libint
if(CP2K_USE_LIBINT2)
find_package(Libint2 REQUIRED)
endif()
# spglib
if(CP2K_USE_SPGLIB)
find_package(LibSPG REQUIRED)
endif()
if(CP2K_USE_SPLA)
find_package(SPLA REQUIRED)
get_target_property(SPLA_INCLUDE_DIRS SPLA::spla
INTERFACE_INCLUDE_DIRECTORIES)
if(NOT SPLA_INCLUDE_DIRS)
set(SPLA_INCLUDE_DIRS "/usr/include;/usr/include/spla")
endif()
if(CP2K_USE_SUPERLU)
find_package(SuperLU REQUIRED)
endif()
if(CP2K_USE_PARMETIS)
find_package(Metis)
endif()
if(CP2K_USE_PTSCOTCH)
find_package(Ptscotch REQUIRED)
endif()
if(CP2K_USE_PEXSI)
# PEXSI 1.2 uses cmake as build system
find_package(PEXSI REQUIRED)
endif()
if(CP2K_USE_PLUMED)
find_package(Plumed REQUIRED)
endif()
if(CP2K_USE_LIBTORCH)
find_package(Torch REQUIRED)
endif()
# OPTION HANDLING
# subdirectories
add_subdirectory(src)
include(CustomTargets)
include(GNUInstallDirs)
message(
STATUS "--------------------------------------------------------------------")
message(
STATUS "- -")
message(
STATUS "- Summary of enabled dependencies -")
message(
STATUS "- -")
message(
STATUS "--------------------------------------------------------------------")
if(CP2K_USE_LIBXC)
message(STATUS " ")
message(
STATUS
"- LIBXC (note to package managers : libxc can be build with cmake as well)"
)
message(STATUS " - include directories : " ${CP2K_LIBXC_INCLUDE_DIRS})
message(STATUS " - libraries : " ${CP2K_LIBXC_LINK_LIBRARIES})
endif()
if(CP2K_USE_LIBTORCH)
message(STATUS " ")
message(STATUS "- LIBTORCH")
message(STATUS " - libraries : " ${CP2K_LIBTORCH_LIBRARIES})
endif()
if(CP2K_USE_FFTW3)
message(STATUS " ")
message(STATUS "- FFTW3")
message(STATUS " - include directories : " ${CP2K_FFTW3_INCLUDE_DIRS})
message(STATUS " - libraries : " ${CP2K_FFTW3_LINK_LIBRARIES})
endif()
if(CP2K_USE_LIBXSMM)
message(STATUS " ")
message(STATUS "- libxsmm")
message(STATUS " - include directories : " ${CP2K_LIBXSMM_INCLUDE_DIRS})
message(STATUS " - libraries : " ${CP2K_LIBXSMM_LINK_LIBRARIES})
endif()
if(CP2K_USE_SPLA)
message(STATUS " ")
message(STATUS "- SPLA :")
message(STATUS " - include directories : " ${SPLA_INCLUDE_DIRS})
message(STATUS " - lbraries : " "${SPLA_LIBRARIES}")
endif()
if(CP2K_USE_SIRIUS)
message(STATUS " ")
message(STATUS "- SIRIUS :")
message(STATUS " - include directories : " ${SIRIUS_INCLUDE_DIRS})
message(STATUS " - libraries : " ${SIRIUS_LIBRARIES})
if(CP2K_USE_COSMA)
message(STATUS " ")
message(STATUS "- COSMA")
message(STATUS " - include directories : " ${COSMA_INCLUDE_DIRS})
message(STATUS " - libraries : " ${COSMA_LIBRARIES})
endif()
if(CP2K_USE_QUIP)
message(STATUS " ")
message(STATUS "- QUIP")
message(STATUS " - include directories : " ${CP2K_LIBQUIP_INCLUDE_DIRS})
message(STATUS " - libraries : " ${CP2K_LIBQUIP_LINK_LIBRARIES})
endif()
if(CP2K_USE_PEXSI)
message(STATUS " ")
message(STATUS "- PEXSI")
endif()
if(CP2K_USE_LIBINT2)
message(STATUS " ")
message(STATUS "- libint2")
message(STATUS " - include directories : " ${CP2K_LIBINT2_INCLUDE_DIRS})
message(STATUS " - libraries : " ${CP2K_LIBINT2_LINK_LIBRARIES})
endif()
if(CP2K_USE_VORI)
message(STATUS " ")
message(STATUS "- libvori")
message(STATUS " - include directories : " ${CP2K_LIBVORI_INCLUDE_DIRS})
message(STATUS " - libraries : " ${CP2K_LIBVORI_LINK_LIBRARIES})
endif()
if(CP2K_USE_SPGLIB)
message(STATUS " ")
message(STATUS "- spglib")
message(STATUS " - include directories : " ${CP2K_LIBSPG_INCLUDE_DIRS})
message(STATUS " - libraries : " ${CP2K_LIBSPG_LINK_LIBRARIES})
endif()
if(CP2K_USE_ELPA)
message(STATUS "- ELPA")
message(STATUS " - include directories : " ${CP2K_ELPA_INCLUDE_DIRS})
message(STATUS " - libraries : " ${CP2K_ELPA_LINK_LIBRARIES})
endif()
if(CP2K_USE_SUPERLU)
message(STATUS " ")
message(STATUS "- superlu")
message(STATUS " - include directories : " ${CP2K_SUPERLU_INCLUDE_DIRS})
message(STATUS " - libraries : " ${CP2K_SUPERLU_LINK_LIBRARIES})
endif()
message(STATUS " ")
message(
STATUS "--------------------------------------------------------------------")
message(
STATUS "- -")
message(
STATUS "- List of dependencies not included in this build -")
message(
STATUS "- -")
message(
STATUS "--------------------------------------------------------------------")
if(NOT CP2K_USE_SIRIUS)
message(STATUS " - SIRIUS")
endif()
if(NOT CP2K_USE_SPGLIB)
message(STATUS " - SPGLIB")
endif()
if(NOT CP2K_USE_COSMA)
message(STATUS " - COSMA")
endif()
if(NOT CP2K_USE_SPLA)
message(STATUS " - SPLA")
endif()
if(NOT CP2K_USE_ELPA)
message(STATUS " - ELPA")
endif()
if(NOT CP2K_USE_PLUMMED)
message(STATUS " - PLUMMED")
endif()
if(NOT CP2K_USE_QUIP)
message(STATUS " - QUIP")
endif()
if(NOT CP2K_USE_LIBXSMM)
message(STATUS " - LIBXSMM")
endif()
if(NOT CP2K_USE_LIBINT2)
message(STATUS " - LIBINT2")
endif()
if(NOT CP2K_USE_LIBXC)
message(STATUS " - LIBXC")
endif()
if(NOT CP2K_USE_VORI)
message(STATUS " - LIBVORI")
endif()
if(NOT CP2K_USE_FFTW3)
message(STATUS " - FFTW3")
endif()
if(NOT CP2K_USE_PEXSI)
message(STATUS " - PEXSI")
endif()
if(NOT CP2K_USE_SUPERLU)
message(STATUS " - SUPERLU")
endif()
if(NOT CP2K_USE_LIBTORCH)
message(STATUS " - libtorch")
endif()
message(
STATUS " ")
message(
STATUS " ")