Skip to content

Commit 4a830c3

Browse files
[Build] Fix SCALAPACK LIBRARY find logic (#7214)
* Fix SCALAPACK LIBRARY find logic * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 78bfe12 commit 4a830c3

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

CMakeLists.txt

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,52 @@ elseif(NOT USE_SW)
555555
find_package(Lapack REQUIRED)
556556
include_directories(${FFTW3_INCLUDE_DIRS})
557557
list(APPEND math_libs FFTW3::FFTW3 LAPACK::LAPACK BLAS::BLAS)
558-
if(USE_DSP)
559-
target_link_libraries(${ABACUS_BIN_NAME} ${SCALAPACK_LIBRARY_DIR})
558+
if(SCALAPACK_LIBRARY_DIR)
559+
if(IS_DIRECTORY "${SCALAPACK_LIBRARY_DIR}")
560+
find_library(
561+
USER_SCALAPACK_LIBRARY
562+
NAMES scalapack scalapack-openmpi scalapack-mpi scalapack-mpich
563+
HINTS ${SCALAPACK_LIBRARY_DIR}
564+
PATH_SUFFIXES lib lib64
565+
NO_DEFAULT_PATH
566+
)
567+
if(USER_SCALAPACK_LIBRARY)
568+
list(APPEND math_libs ${USER_SCALAPACK_LIBRARY})
569+
else()
570+
find_package(ScaLAPACK QUIET)
571+
if(ScaLAPACK_FOUND)
572+
list(APPEND math_libs ScaLAPACK::ScaLAPACK)
573+
else()
574+
message(
575+
FATAL_ERROR
576+
"SCALAPACK_LIBRARY_DIR is set to '${SCALAPACK_LIBRARY_DIR}', but no compatible ScaLAPACK library was found there and find_package(ScaLAPACK) also failed."
577+
)
578+
endif()
579+
endif()
580+
else()
581+
if(NOT IS_ABSOLUTE "${SCALAPACK_LIBRARY_DIR}")
582+
message(
583+
FATAL_ERROR
584+
"SCALAPACK_LIBRARY_DIR is set to '${SCALAPACK_LIBRARY_DIR}', but this is not an absolute library path. Please provide either a directory containing libscalapack or a full absolute path to the ScaLAPACK library file."
585+
)
586+
elseif(NOT EXISTS "${SCALAPACK_LIBRARY_DIR}")
587+
message(
588+
FATAL_ERROR
589+
"SCALAPACK_LIBRARY_DIR is set to '${SCALAPACK_LIBRARY_DIR}', but this path does not exist. Please provide either a directory containing libscalapack or a full absolute path to the ScaLAPACK library file."
590+
)
591+
elseif(IS_DIRECTORY "${SCALAPACK_LIBRARY_DIR}")
592+
message(
593+
FATAL_ERROR
594+
"SCALAPACK_LIBRARY_DIR is set to '${SCALAPACK_LIBRARY_DIR}', but this value resolved to a directory in the full-library-path branch. Please provide either a directory containing libscalapack or a full absolute path to the ScaLAPACK library file."
595+
)
596+
endif()
597+
list(APPEND math_libs ${SCALAPACK_LIBRARY_DIR})
598+
endif()
599+
elseif(USE_DSP)
600+
message(
601+
FATAL_ERROR
602+
"USE_DSP is enabled, but SCALAPACK_LIBRARY_DIR is not set. Please provide -DSCALAPACK_LIBRARY_DIR=<scalapack dir or full library path>."
603+
)
560604
else()
561605
find_package(ScaLAPACK REQUIRED)
562606
list(APPEND math_libs ScaLAPACK::ScaLAPACK)

0 commit comments

Comments
 (0)