Skip to content

Commit

Permalink
work around CMake bug with LAPACK::LAPACK not including BLAS::BLAS
Browse files Browse the repository at this point in the history
  • Loading branch information
gardner48 committed Jul 18, 2024
1 parent 1b3bcf2 commit c370e2f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
30 changes: 14 additions & 16 deletions cmake/tpl/SundialsLapack.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -320,26 +320,24 @@ if(NOT LAPACK_WORKS)
"return 0;\n"
"}\n")

# Attempt to build and link the test executable, pass --debug-trycompile to
# the cmake command to save build files for debugging
# Workaround bug in older versions of CMake where the BLAS::BLAS target,
# which LAPACK::LAPACK depends on, is not defined in the file
# ${LAPACK_TEST_DIR}/CMakeFiles/CMakeTmp/<random_name>Targets.cmake created
# by try_compile
if(CMAKE_VERSION VERSION_LESS 3.20)
# Workaround bug in older versions of CMake where the BLAS::BLAS target,
# which LAPACK::LAPACK depends on, is not defined in the file
# ${LAPACK_TEST_DIR}/CMakeFiles/CMakeTmp/<random_name>Targets.cmake created
# by try_compile
try_compile(
COMPILE_OK ${LAPACK_TEST_DIR}
${LAPACK_TEST_DIR}/test.c
LINK_LIBRARIES LAPACK::LAPACK BLAS::BLAS
OUTPUT_VARIABLE COMPILE_OUTPUT)
set(_lapack_targets LAPACK::LAPACK BLAS::BLAS)
else()
try_compile(
COMPILE_OK ${LAPACK_TEST_DIR}
${LAPACK_TEST_DIR}/test.c
LINK_LIBRARIES LAPACK::LAPACK
OUTPUT_VARIABLE COMPILE_OUTPUT)
set(_lapack_targets LAPACK::LAPACK)
endif()

# Attempt to build and link the test executable, pass --debug-trycompile to
# the cmake command to save build files for debugging
try_compile(
COMPILE_OK ${LAPACK_TEST_DIR}
${LAPACK_TEST_DIR}/test.c
LINK_LIBRARIES ${_lapack_targets}
OUTPUT_VARIABLE COMPILE_OUTPUT)

# Check the result
if(COMPILE_OK)
message(CHECK_PASS "success")
Expand Down
10 changes: 9 additions & 1 deletion src/sunlinsol/lapackband/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@

install(CODE "MESSAGE(\"\nInstall SUNLINSOL_LAPACKBAND\n\")")

# Workaround bug in older versions of CMake where the BLAS::BLAS target,
# which LAPACK::LAPACK depends on, is not picked up by LINK_LIBRARIES
if(CMAKE_VERSION VERSION_LESS 3.20)
set(_lapack_targets LAPACK::LAPACK BLAS::BLAS)
else()
set(_lapack_targets LAPACK::LAPACK)
endif()

# Add the library
sundials_add_library(
sundials_sunlinsollapackband
Expand All @@ -24,7 +32,7 @@ sundials_add_library(
INCLUDE_SUBDIR sunlinsol
LINK_LIBRARIES PUBLIC sundials_core
OBJECT_LIBRARIES
LINK_LIBRARIES PUBLIC sundials_sunmatrixband LAPACK::LAPACK
LINK_LIBRARIES PUBLIC sundials_sunmatrixband ${_lapack_targets}
OUTPUT_NAME sundials_sunlinsollapackband
VERSION ${sunlinsollib_VERSION}
SOVERSION ${sunlinsollib_SOVERSION})
Expand Down
10 changes: 9 additions & 1 deletion src/sunlinsol/lapackdense/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@

install(CODE "MESSAGE(\"\nInstall SUNLINSOL_LAPACKDENSE\n\")")

# Workaround bug in older versions of CMake where the BLAS::BLAS target,
# which LAPACK::LAPACK depends on, is not picked up by LINK_LIBRARIES
if(CMAKE_VERSION VERSION_LESS 3.20)
set(_lapack_targets LAPACK::LAPACK BLAS::BLAS)
else()
set(_lapack_targets LAPACK::LAPACK)
endif()

# Add the library
sundials_add_library(
sundials_sunlinsollapackdense
Expand All @@ -24,7 +32,7 @@ sundials_add_library(
INCLUDE_SUBDIR sunlinsol
LINK_LIBRARIES PUBLIC sundials_core
OBJECT_LIBRARIES
LINK_LIBRARIES PUBLIC sundials_sunmatrixdense LAPACK::LAPACK
LINK_LIBRARIES PUBLIC sundials_sunmatrixdense ${_lapack_targets}
OUTPUT_NAME sundials_sunlinsollapackdense
VERSION ${sunlinsollib_VERSION}
SOVERSION ${sunlinsollib_SOVERSION})
Expand Down

0 comments on commit c370e2f

Please sign in to comment.