diff --git a/CMakeLists.txt b/CMakeLists.txt index 431f844993..d3db9f529d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -508,11 +508,8 @@ if(DEFINED Libxc_DIR) set(ENABLE_LIBXC ON) endif() if(ENABLE_LIBXC) - find_package(Libxc REQUIRED HINTS - ${Libxc_DIR}/share/cmake/Libxc - ${Libxc_DIR}/lib/cmake/Libxc - ${Libxc_DIR}/lib64/cmake/Libxc - ) + # use `cmake/FindLibxc.cmake` to detect Libxc installation with `pkg-config` + find_package(Libxc REQUIRED) message(STATUS "Found Libxc: version " ${Libxc_VERSION}) if(${Libxc_VERSION} VERSION_LESS 5.1.7) message(FATAL_ERROR "LibXC >= 5.1.7 is required.") diff --git a/cmake/FindELPA.cmake b/cmake/FindELPA.cmake index 5769f7248c..328b75035f 100644 --- a/cmake/FindELPA.cmake +++ b/cmake/FindELPA.cmake @@ -7,34 +7,49 @@ # ELPA_INCLUDE_DIR - Where to find ELPA headers. # -find_path(ELPA_INCLUDE_DIR +find_package(PkgConfig) + +if(PKG_CONFIG_FOUND) + if(DEFINED ELPA_DIR) + string(APPEND CMAKE_PREFIX_PATH ";${ELPA_DIR}") + endif() + if(USE_OPENMP) + pkg_search_module(ELPA REQUIRED IMPORTED_TARGET GLOBAL elpa_openmp) + else() + pkg_search_module(ELPA REQUIRED IMPORTED_TARGET GLOBAL elpa) + endif() +else() + find_path(ELPA_INCLUDE_DIRS elpa/elpa.h HINTS ${ELPA_DIR} PATH_SUFFIXES "include" "include/elpa" ) -if(USE_OPENMP) - find_library(ELPA_LIBRARY - NAMES elpa_openmp elpa - HINTS ${ELPA_DIR} - PATH_SUFFIXES "lib" - ) -else() - find_library(ELPA_LIBRARY - NAMES elpa - HINTS ${ELPA_DIR} - PATH_SUFFIXES "lib" - ) + if(USE_OPENMP) + find_library(ELPA_LINK_LIBRARIES + NAMES elpa_openmp elpa + HINTS ${ELPA_DIR} + PATH_SUFFIXES "lib" + ) + else() + find_library(ELPA_LINK_LIBRARIES + NAMES elpa + HINTS ${ELPA_DIR} + PATH_SUFFIXES "lib" + ) + endif() + #message( + # "ELPA : We need pkg-config to get all information about the elpa library") endif() # Handle the QUIET and REQUIRED arguments and # set ELPA_FOUND to TRUE if all variables are non-zero. include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(ELPA DEFAULT_MSG ELPA_LIBRARY ELPA_INCLUDE_DIR) +find_package_handle_standard_args(ELPA DEFAULT_MSG ELPA_LINK_LIBRARIES ELPA_INCLUDE_DIRS) # Copy the results to the output variables and target. if(ELPA_FOUND) - set(ELPA_LIBRARIES ${ELPA_LIBRARY}) - set(ELPA_INCLUDE_DIR ${ELPA_INCLUDE_DIR}) + set(ELPA_LIBRARY ${ELPA_LINK_LIBRARIES}) + set(ELPA_INCLUDE_DIR ${ELPA_INCLUDE_DIRS}) if(NOT TARGET ELPA::ELPA) add_library(ELPA::ELPA UNKNOWN IMPORTED) diff --git a/cmake/FindLibxc.cmake b/cmake/FindLibxc.cmake new file mode 100644 index 0000000000..4a3c04cba7 --- /dev/null +++ b/cmake/FindLibxc.cmake @@ -0,0 +1,36 @@ +include(FindPackageHandleStandardArgs) + +if(DEFINED Libxc_DIR) + string(APPEND CMAKE_PREFIX_PATH ";${Libxc_DIR}") +endif() +# Using CMake interface as default. +# NO REQUIRED here, otherwhile it would throw error +# with no LibXC found. +find_package(Libxc HINTS + ${Libxc_DIR}/share/cmake/Libxc + ${Libxc_DIR}/lib/cmake/Libxc + ${Libxc_DIR}/lib64/cmake/Libxc + ) +if(NOT TARGET Libxc::xc) + find_package(PkgConfig REQUIRED) + pkg_search_module(Libxc REQUIRED IMPORTED_TARGET GLOBAL libxc) + find_package_handle_standard_args(Libxc DEFAULT_MSG Libxc_LINK_LIBRARIES Libxc_INCLUDE_DIRS) +endif() + + +# Copy the results to the output variables and target. +# if find_package() above works, Libxc::xc would be present and +# below would be skipped. +if(Libxc_FOUND AND NOT TARGET Libxc::xc) + set(Libxc_LIBRARY ${Libxc_LINK_LIBRARIES}) + set(Libxc_LIBRARIES ${Libxc_LIBRARY}) + set(Libxc_INCLUDE_DIR ${Libxc_INCLUDE_DIRS}) + add_library(Libxc::xc UNKNOWN IMPORTED) + set_target_properties(Libxc::xc PROPERTIES + IMPORTED_LOCATION "${Libxc_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${Libxc_INCLUDE_DIR}") +endif() + +set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${Libxc_INCLUDE_DIR}) + +mark_as_advanced(Libxc_INCLUDE_DIR Libxc_LIBRARY) diff --git a/docs/quick_start/easy_install.md b/docs/quick_start/easy_install.md index 957b9d3262..45adc8e60a 100644 --- a/docs/quick_start/easy_install.md +++ b/docs/quick_start/easy_install.md @@ -28,7 +28,7 @@ These requirements support the calculation of plane-wave basis in ABACUS. For LC Some of these packages can be installed with popular package management system, such as `apt` and `yum`: ```bash -sudo apt update && sudo apt install -y libopenblas-openmp-dev liblapack-dev libscalapack-mpi-dev libelpa-dev libfftw3-dev libcereal-dev libxc-dev g++ make cmake bc git +sudo apt update && sudo apt install -y libopenblas-openmp-dev liblapack-dev libscalapack-mpi-dev libelpa-dev libfftw3-dev libcereal-dev libxc-dev g++ make cmake bc git pkgconf ``` > Installing ELPA by apt only matches requirements on Ubuntu 22.04. For earlier linux distributions, you should build ELPA from source. @@ -111,12 +111,12 @@ Here, 'build' is the path for building ABACUS; and '-D' is used for setting up s - `LAPACK_DIR`: Path to OpenBLAS library `libopenblas.so`(including BLAS and LAPACK) - `SCALAPACK_DIR`: Path to ScaLAPACK library `libscalapack.so` - `ELPA_DIR`: Path to ELPA install directory; should be the folder containing 'include' and 'lib'. - > Note: If you install ELPA from source, please add a symlink to avoid the additional include file folder with version name: `ln -s elpa/include/elpa-2021.05.002/elpa elpa/include/elpa`. This is a known behavior of ELPA. + > Note: In ABACUS v3.5.1 or earlier, if you install ELPA from source , please add a symlink to avoid the additional include file folder with version name: `ln -s elpa/include/elpa-2021.05.002/elpa elpa/include/elpa` to help the build system find ELPA headers. - `FFTW3_DIR`: Path to FFTW3. - `CEREAL_INCLUDE_DIR`: Path to the parent folder of `cereal/cereal.hpp`. Will download from GitHub if absent. - `Libxc_DIR`: (Optional) Path to Libxc. - > Note: Building Libxc from source with Makefile does NOT support using it in CMake here. Please compile Libxc with CMake instead. + > Note: In ABACUS v3.5.1 or earlier, Libxc built from source with Makefile is NOT supported; please compile Libxc with CMake instead. - `LIBRI_DIR`: (Optional) Path to LibRI. - `LIBCOMM_DIR`: (Optional) Path to LibComm.