diff --git a/CMakeLists.txt b/CMakeLists.txt index dd237d5e2b..b418b189a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -396,10 +396,21 @@ if(MKLROOT) list(APPEND math_libs -lifcore) endif() else() + # In compatibility to builtin FindLAPACK.cmake before v3.5.4 + if(DEFINED LAPACK_DIR) + string(APPEND CMAKE_PREFIX_PATH ";${LAPACK_DIR}") + endif() + if(DEFINED LAPACK_LIBRARY) + set(LAPACK_LIBRARIES ${LAPACK_LIBRARY}) + endif() + if(DEFINED BLAS_DIR) + string(APPEND CMAKE_PREFIX_PATH ";${BLAS_DIR}") + endif() + find_package(FFTW3 REQUIRED) find_package(LAPACK REQUIRED) include_directories(${FFTW3_INCLUDE_DIRS}) - list(APPEND math_libs FFTW3::FFTW3 LAPACK::LAPACK) + list(APPEND math_libs FFTW3::FFTW3 LAPACK::LAPACK BLAS::BLAS) if(ENABLE_LCAO) find_package(ScaLAPACK REQUIRED) @@ -733,4 +744,4 @@ endif() if(ENABLE_RAPIDJSON) target_link_libraries(${ABACUS_BIN_NAME} json_output) -endif() \ No newline at end of file +endif() diff --git a/cmake/FindELPA.cmake b/cmake/FindELPA.cmake index 4105e47592..904be208a5 100644 --- a/cmake/FindELPA.cmake +++ b/cmake/FindELPA.cmake @@ -9,11 +9,27 @@ find_package(PkgConfig) +# Compatible layer towards old manual routines +if(DEFINED ELPA_INCLUDE_DIR) + set(ELPA_INCLUDE_DIRS ${ELPA_INCLUDE_DIR}) +endif() +if(DEFINED ELPA_LIBRARIES) + set(ELPA_LINK_LIBRARIES ${ELPA_LIBRARIES}) +endif() + find_path(ELPA_INCLUDE_DIRS elpa/elpa.h HINTS ${ELPA_DIR} PATH_SUFFIXES "include" "include/elpa" ) +# Fix #3589 +# First if judges if ELPA dir specified +if(ELPA_INCLUDE_DIRS MATCHES "^/usr/include/elpa/.*") + # Second if judges if global visible ELPA header found + if(DEFINED ELPA_DIR OR CMAKE_PREFIX_PATH MATCHES ".*elpa.*") + unset(ELPA_INCLUDE_DIRS) + endif() +endif() if(USE_OPENMP) find_library(ELPA_LINK_LIBRARIES NAMES elpa_openmp elpa @@ -28,6 +44,9 @@ else() ) endif() +# Incompatible with ELPA earlier than 2021.11.001 +# Before ELPA 2021.11.001, its pkg-config file +# is named like "elpa-2021.05.002.pc". if(NOT ELPA_INCLUDE_DIRS AND PKG_CONFIG_FOUND) if(DEFINED ELPA_DIR) string(APPEND CMAKE_PREFIX_PATH ";${ELPA_DIR}") diff --git a/cmake/FindLAPACK.cmake b/cmake/FindLAPACK.cmake deleted file mode 100644 index c240d5facf..0000000000 --- a/cmake/FindLAPACK.cmake +++ /dev/null @@ -1,31 +0,0 @@ -# - Find LAPACK -# Find the native double precision ScaLAPACK headers and libraries. -# -# LAPACK_LIBRARIES - List of libraries when using ScaLAPACK. -# LAPACK_FOUND - True if ScaLAPACK is found. -# - -find_library(LAPACK_LIBRARY - NAMES openblas blas - HINTS ${LAPACK_DIR} - PATH_SUFFIXES "lib" -) - -# Handle the QUIET and REQUIRED arguments and -# set ScaLAPACK_FOUND to TRUE if all variables are non-zero. -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(LAPACK DEFAULT_MSG LAPACK_LIBRARY) - -# Copy the results to the output variables and target. -if(LAPACK_FOUND) - set(LAPACK_LIBRARIES ${LAPACK_LIBRARY}) - - if(NOT TARGET LAPACK::LAPACK) - add_library(LAPACK::LAPACK UNKNOWN IMPORTED) - set_target_properties(LAPACK::LAPACK PROPERTIES - IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${LAPACK_LIBRARY}") - endif() -endif() - -mark_as_advanced(LAPACK_LIBRARY) diff --git a/cmake/FindLibxc.cmake b/cmake/FindLibxc.cmake index 4a3c04cba7..2800942ca9 100644 --- a/cmake/FindLibxc.cmake +++ b/cmake/FindLibxc.cmake @@ -3,21 +3,24 @@ include(FindPackageHandleStandardArgs) if(DEFINED Libxc_DIR) string(APPEND CMAKE_PREFIX_PATH ";${Libxc_DIR}") endif() -# Using CMake interface as default. +# Using pkg-config interface as default, to +# avoid linking to wrong global visible Libxc instead of +# specified one. # NO REQUIRED here, otherwhile it would throw error # with no LibXC found. -find_package(Libxc HINTS +find_package(PkgConfig) +if(PKG_CONFIG_FOUND) + pkg_search_module(Libxc IMPORTED_TARGET GLOBAL libxc) + find_package_handle_standard_args(Libxc DEFAULT_MSG Libxc_LINK_LIBRARIES Libxc_INCLUDE_DIRS) +endif() +if(NOT Libxc_FOUND) + find_package(Libxc REQUIRED 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.