From f18a628255bc260889b9eb63ab263d730b0ef61b Mon Sep 17 00:00:00 2001 From: yizeyi18 <18586016708@163.com> Date: Tue, 20 Feb 2024 22:13:45 +0800 Subject: [PATCH 1/9] fix #3589 --- cmake/FindELPA.cmake | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/cmake/FindELPA.cmake b/cmake/FindELPA.cmake index 4105e47592..61f9523a42 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}") @@ -49,8 +68,10 @@ find_package_handle_standard_args(ELPA DEFAULT_MSG ELPA_LINK_LIBRARIES ELPA_INCL # Copy the results to the output variables and target. if(ELPA_FOUND) + message("Current ELPA_LINK_LIBRARIES is ${ELPA_LINK_LIBRARIES}") list(GET ELPA_LINK_LIBRARIES 0 ELPA_LIBRARY) set(ELPA_INCLUDE_DIR ${ELPA_INCLUDE_DIRS}) + message("Current ELPA_LIBRARY is ${ELPA_LIBRARY}") if(NOT TARGET ELPA::ELPA) add_library(ELPA::ELPA UNKNOWN IMPORTED) From 5b8f0a38e1840cdad8b483934dd6691c069c258e Mon Sep 17 00:00:00 2001 From: yizeyi18 <18586016708@163.com> Date: Tue, 20 Feb 2024 22:35:32 +0800 Subject: [PATCH 2/9] fix libxc link issue similar to ELPA --- cmake/FindLibxc.cmake | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cmake/FindLibxc.cmake b/cmake/FindLibxc.cmake index 4a3c04cba7..52d33341a0 100644 --- a/cmake/FindLibxc.cmake +++ b/cmake/FindLibxc.cmake @@ -3,21 +3,23 @@ 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) +pkg_search_module(Libxc IMPORTED_TARGET GLOBAL libxc) +find_package_handle_standard_args(Libxc DEFAULT_MSG Libxc_LINK_LIBRARIES Libxc_INCLUDE_DIRS) + +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. From 5e131ec803caed088d2c56e027c02cd1111510d8 Mon Sep 17 00:00:00 2001 From: yizeyi18 <18586016708@163.com> Date: Wed, 21 Feb 2024 17:17:05 +0800 Subject: [PATCH 3/9] add stand-alone blas lib-finder --- cmake/FindBLAS.cmake | 23 +++++++++++++++++++++++ cmake/FindLAPACK.cmake | 4 +++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 cmake/FindBLAS.cmake diff --git a/cmake/FindBLAS.cmake b/cmake/FindBLAS.cmake new file mode 100644 index 0000000000..b7997cd3b3 --- /dev/null +++ b/cmake/FindBLAS.cmake @@ -0,0 +1,23 @@ +find_library(BLAS_LIBRARY + NAMES openblas blas blis + HINTS ${BLAS_DIR} ${LAPACK_DIR} + PATH_SUFFIXES "lib" +) + +# Handle the QUIET and REQUIRED arguments. +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(BLAS DEFAULT_MSG BLAS_LIBRARY) + +# Copy the results to the output variables and target. +if(BLAS_FOUND) + set(BLAS_LIBRARIES ${BLAS_LIBRARY}) + + if(NOT TARGET BLAS::BLAS) + add_library(BLAS::BLAS UNKNOWN IMPORTED) + set_target_properties(BLAS::BLAS PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${BLAS_LIBRARY}") + endif() +endif() + +mark_as_advanced(BLAS_LIBRARY) diff --git a/cmake/FindLAPACK.cmake b/cmake/FindLAPACK.cmake index c240d5facf..97f7828386 100644 --- a/cmake/FindLAPACK.cmake +++ b/cmake/FindLAPACK.cmake @@ -5,8 +5,10 @@ # LAPACK_FOUND - True if ScaLAPACK is found. # +find_package(BLAS REQUIRED) + find_library(LAPACK_LIBRARY - NAMES openblas blas + NAMES openblas lapack flame HINTS ${LAPACK_DIR} PATH_SUFFIXES "lib" ) From dea9050c0116ced763f0e7c3ed296fb69cb210cd Mon Sep 17 00:00:00 2001 From: yizeyi18 <18586016708@163.com> Date: Wed, 21 Feb 2024 17:30:38 +0800 Subject: [PATCH 4/9] remove test output --- cmake/FindELPA.cmake | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmake/FindELPA.cmake b/cmake/FindELPA.cmake index 61f9523a42..904be208a5 100644 --- a/cmake/FindELPA.cmake +++ b/cmake/FindELPA.cmake @@ -68,10 +68,8 @@ find_package_handle_standard_args(ELPA DEFAULT_MSG ELPA_LINK_LIBRARIES ELPA_INCL # Copy the results to the output variables and target. if(ELPA_FOUND) - message("Current ELPA_LINK_LIBRARIES is ${ELPA_LINK_LIBRARIES}") list(GET ELPA_LINK_LIBRARIES 0 ELPA_LIBRARY) set(ELPA_INCLUDE_DIR ${ELPA_INCLUDE_DIRS}) - message("Current ELPA_LIBRARY is ${ELPA_LIBRARY}") if(NOT TARGET ELPA::ELPA) add_library(ELPA::ELPA UNKNOWN IMPORTED) From 3e4519fe818c77ee983ad891bec4d991a4e5e880 Mon Sep 17 00:00:00 2001 From: yizeyi18 <18586016708@163.com> Date: Wed, 21 Feb 2024 17:31:51 +0800 Subject: [PATCH 5/9] add BLAS link command in CMakeLists.txt --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dd237d5e2b..4373d8a07e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -399,7 +399,7 @@ else() 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 +733,4 @@ endif() if(ENABLE_RAPIDJSON) target_link_libraries(${ABACUS_BIN_NAME} json_output) -endif() \ No newline at end of file +endif() From ceecd0ba6165d1bcfc127fd5b8448783fa0d6ea6 Mon Sep 17 00:00:00 2001 From: yizeyi18 <18586016708@163.com> Date: Wed, 21 Feb 2024 19:18:35 +0800 Subject: [PATCH 6/9] fix compatibility for cmake routines in FindLibxc.cmake --- cmake/FindLibxc.cmake | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmake/FindLibxc.cmake b/cmake/FindLibxc.cmake index 52d33341a0..5420cd698c 100644 --- a/cmake/FindLibxc.cmake +++ b/cmake/FindLibxc.cmake @@ -10,14 +10,16 @@ endif() # with no LibXC found. find_package(PkgConfig) pkg_search_module(Libxc IMPORTED_TARGET GLOBAL libxc) -find_package_handle_standard_args(Libxc DEFAULT_MSG Libxc_LINK_LIBRARIES Libxc_INCLUDE_DIRS) +#find_package_handle_standard_args(Libxc DEFAULT_MSG Libxc_LINK_LIBRARIES Libxc_INCLUDE_DIRS) -if(NOT Libxc_FOUND) +if(NOT DEFINED Libxc_LINK_LIBRARIES OR NOT DEFINED Libxc_INCLUDE_DIRS) find_package(Libxc REQUIRED HINTS ${Libxc_DIR}/share/cmake/Libxc ${Libxc_DIR}/lib/cmake/Libxc ${Libxc_DIR}/lib64/cmake/Libxc ) +else() + find_package_handle_standard_args(Libxc DEFAULT_MSG Libxc_LINK_LIBRARIES Libxc_INCLUDE_DIRS) endif() # Copy the results to the output variables and target. From fb9559c559c59685bcd82e7972a4ee5cc37b019c Mon Sep 17 00:00:00 2001 From: yizeyi18 <18586016708@163.com> Date: Wed, 21 Feb 2024 19:30:17 +0800 Subject: [PATCH 7/9] Libxc fix --- cmake/FindLibxc.cmake | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cmake/FindLibxc.cmake b/cmake/FindLibxc.cmake index 5420cd698c..2800942ca9 100644 --- a/cmake/FindLibxc.cmake +++ b/cmake/FindLibxc.cmake @@ -9,17 +9,16 @@ endif() # NO REQUIRED here, otherwhile it would throw error # with no LibXC found. find_package(PkgConfig) -pkg_search_module(Libxc IMPORTED_TARGET GLOBAL libxc) -#find_package_handle_standard_args(Libxc DEFAULT_MSG Libxc_LINK_LIBRARIES Libxc_INCLUDE_DIRS) - -if(NOT DEFINED Libxc_LINK_LIBRARIES OR NOT DEFINED Libxc_INCLUDE_DIRS) +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 ) -else() - find_package_handle_standard_args(Libxc DEFAULT_MSG Libxc_LINK_LIBRARIES Libxc_INCLUDE_DIRS) endif() # Copy the results to the output variables and target. From 7726850f408c8a6a70f7631e5bc8f13d74cbea99 Mon Sep 17 00:00:00 2001 From: yizeyi18 <18586016708@163.com> Date: Fri, 23 Feb 2024 20:58:23 +0800 Subject: [PATCH 8/9] modify CMakeLists.txt in ease to use cmake's FindBLAS --- CMakeLists.txt | 6 ++++++ cmake/FindBLAS.cmake | 23 ----------------------- cmake/FindLAPACK.cmake | 33 --------------------------------- 3 files changed, 6 insertions(+), 56 deletions(-) delete mode 100644 cmake/FindBLAS.cmake delete mode 100644 cmake/FindLAPACK.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 4373d8a07e..bb498723f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -396,6 +396,12 @@ if(MKLROOT) list(APPEND math_libs -lifcore) endif() else() + if(DEFINED LAPACK_DIR) + string(APPEND CMAKE_PREFIX_PATH ";${LAPACK_DIR}") + 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}) diff --git a/cmake/FindBLAS.cmake b/cmake/FindBLAS.cmake deleted file mode 100644 index b7997cd3b3..0000000000 --- a/cmake/FindBLAS.cmake +++ /dev/null @@ -1,23 +0,0 @@ -find_library(BLAS_LIBRARY - NAMES openblas blas blis - HINTS ${BLAS_DIR} ${LAPACK_DIR} - PATH_SUFFIXES "lib" -) - -# Handle the QUIET and REQUIRED arguments. -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(BLAS DEFAULT_MSG BLAS_LIBRARY) - -# Copy the results to the output variables and target. -if(BLAS_FOUND) - set(BLAS_LIBRARIES ${BLAS_LIBRARY}) - - if(NOT TARGET BLAS::BLAS) - add_library(BLAS::BLAS UNKNOWN IMPORTED) - set_target_properties(BLAS::BLAS PROPERTIES - IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${BLAS_LIBRARY}") - endif() -endif() - -mark_as_advanced(BLAS_LIBRARY) diff --git a/cmake/FindLAPACK.cmake b/cmake/FindLAPACK.cmake deleted file mode 100644 index 97f7828386..0000000000 --- a/cmake/FindLAPACK.cmake +++ /dev/null @@ -1,33 +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_package(BLAS REQUIRED) - -find_library(LAPACK_LIBRARY - NAMES openblas lapack flame - 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) From 97f818df6cb05c7cda55d429f75f794977cd016e Mon Sep 17 00:00:00 2001 From: yizeyi18 <18586016708@163.com> Date: Fri, 23 Feb 2024 21:15:28 +0800 Subject: [PATCH 9/9] more variable wrapper --- CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bb498723f4..b418b189a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -396,12 +396,17 @@ 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}") + string(APPEND CMAKE_PREFIX_PATH ";${BLAS_DIR}") endif() + find_package(FFTW3 REQUIRED) find_package(LAPACK REQUIRED) include_directories(${FFTW3_INCLUDE_DIRS})