From dc2cf8de0455c126b3587d085e40df5ed51ffedc Mon Sep 17 00:00:00 2001 From: "David J. Gardner" Date: Thu, 20 Jun 2024 19:17:23 -0700 Subject: [PATCH 01/13] use LAPACK imported target --- cmake/SUNDIALSConfig.cmake.in | 4 + cmake/tpl/SundialsLapack.cmake | 243 +++++++----------- cmake/tpl/SundialsTPL.cmake.template | 52 ++-- examples/arkode/F2003_serial/CMakeLists.txt | 3 - examples/cvode/F2003_serial/CMakeLists.txt | 3 - examples/cvode/serial/CMakeLists.txt | 3 - examples/cvodes/serial/CMakeLists.txt | 3 - examples/ida/serial/CMakeLists.txt | 3 - examples/idas/serial/CMakeLists.txt | 3 - examples/kinsol/serial/CMakeLists.txt | 3 - examples/sunlinsol/lapackband/CMakeLists.txt | 8 +- examples/sunlinsol/lapackdense/CMakeLists.txt | 8 +- src/sunlinsol/lapackband/CMakeLists.txt | 13 +- src/sunlinsol/lapackdense/CMakeLists.txt | 13 +- 14 files changed, 145 insertions(+), 217 deletions(-) diff --git a/cmake/SUNDIALSConfig.cmake.in b/cmake/SUNDIALSConfig.cmake.in index 9cbe9e6c23..1d7a0130a0 100644 --- a/cmake/SUNDIALSConfig.cmake.in +++ b/cmake/SUNDIALSConfig.cmake.in @@ -108,6 +108,10 @@ if("@ENABLE_KOKKOS_KERNELS@" AND NOT TARGET Kokkos::kokkoskernels) find_dependency(KokkosKernels PATHS "@KokkosKernels_DIR@") endif() +if("@ENABLE_LAPACK@" AND NOT TARGET LAPACK::LAPACK) + find_dependency(LAPACK) +endif() + if("@ENABLE_PETSC@" AND NOT TARGET SUNDIALS::PETSC) add_library(SUNDIALS::PETSC INTERFACE IMPORTED) target_link_libraries(SUNDIALS::PETSC INTERFACE "@PETSC_LIBRARIES@") diff --git a/cmake/tpl/SundialsLapack.cmake b/cmake/tpl/SundialsLapack.cmake index 74261bb469..af76973889 100644 --- a/cmake/tpl/SundialsLapack.cmake +++ b/cmake/tpl/SundialsLapack.cmake @@ -26,11 +26,7 @@ # Section 1: Include guard # ----------------------------------------------------------------------------- -if(NOT DEFINED SUNDIALS_LAPACK_INCLUDED) - set(SUNDIALS_LAPACK_INCLUDED) -else() - return() -endif() +include_guard(GLOBAL) # ----------------------------------------------------------------------------- # Section 2: Check to make sure options are compatible @@ -38,29 +34,25 @@ endif() # LAPACK does not support extended precision if(ENABLE_LAPACK AND SUNDIALS_PRECISION MATCHES "EXTENDED") - print_error("LAPACK is not compatible with ${SUNDIALS_PRECISION} precision") + message(FATAL_ERROR "LAPACK is not compatible with ${SUNDIALS_PRECISION} precision") endif() # ----------------------------------------------------------------------------- # Section 3: Find the TPL # ----------------------------------------------------------------------------- -# If LAPACK libraries are undefined, try to find them. -if(NOT LAPACK_LIBRARIES) - find_package(LAPACK REQUIRED) -endif() +find_package(LAPACK REQUIRED) -# If we have the LAPACK libraries, display progress message. -if(LAPACK_LIBRARIES) - message(STATUS "Looking for LAPACK libraries... OK") - set(LAPACK_FOUND TRUE) +# get path to LAPACK library to use in generated makefiles for examples, if +# LAPACK_LIBRARIES contains multiple items only use the path of the first entry +list(LENGTH LAPACK_LIBRARIES len) +if(len EQUAL 1) + get_filename_component(LAPACK_LIBRARY_DIR ${LAPACK_LIBRARIES} PATH) else() - message(STATUS "Looking for LAPACK libraries... FAILED") - set(LAPACK_FOUND FALSE) + list(GET LAPACK_LIBRARIES 0 TMP_LAPACK_LIBRARIES) + get_filename_component(LAPACK_LIBRARY_DIR ${TMP_LAPACK_LIBRARIES} PATH) endif() -message(STATUS "LAPACK_LIBRARIES: ${LAPACK_LIBRARIES}") - # ----------------------------------------------------------------------------- # Section 4: Test the TPL # ----------------------------------------------------------------------------- @@ -69,16 +61,15 @@ message(STATUS "LAPACK_LIBRARIES: ${LAPACK_LIBRARIES}") # Determining the name-mangling scheme if needed # --------------------------------------------------------------- # In general, names of symbols with and without underscore may be mangled -# differently (e.g. g77 mangles mysub to mysub_ and my_sub to my_sub__), we have -# to consider both cases. +# differently (e.g. g77 mangles mysub to mysub_ and my_sub to my_sub__), +# we have to consider both cases. # # Method: -# -# 1. create a library from a Fortran source file which defines a function "mysub" -# 2. attempt to link with this library a C source file which calls the "mysub" -# function using various possible schemes (6 different schemes, corresponding -# to all combinations lower/upper case and none/one/two underscores). -# 3. define the name-mangling scheme based on the test that was successful. +# 1) create a library from a Fortran source file which defines a function "mysub" +# 2) attempt to link with this library a C source file which calls the "mysub" +# function using various possible schemes (6 different schemes, corresponding +# to all combinations lower/upper case and none/one/two underscores). +# 3) define the name-mangling scheme based on the test that was successful. # # On exit, if we were able to infer the scheme, the variables # CMAKE_Fortran_SCHEME_NO_UNDERSCORES and CMAKE_Fortran_SCHEME_WITH_UNDERSCORES @@ -93,10 +84,9 @@ if(NEED_FORTRAN_NAME_MANGLING) set(FortranTest_DIR ${PROJECT_BINARY_DIR}/FortranTest) file(MAKE_DIRECTORY ${FortranTest_DIR}) - # Create a CMakeLists.txt file which will generate the "flib" library and an - # executable "ftest" - file( - WRITE ${FortranTest_DIR}/CMakeLists.txt + # Create a CMakeLists.txt file which will generate the "flib" library + # and an executable "ftest" + file(WRITE ${FortranTest_DIR}/CMakeLists.txt "CMAKE_MINIMUM_REQUIRED(VERSION ${CMAKE_VERSION})\n" "PROJECT(ftest Fortran)\n" "SET(CMAKE_VERBOSE_MAKEFILE ON)\n" @@ -111,35 +101,36 @@ if(NEED_FORTRAN_NAME_MANGLING) "ADD_EXECUTABLE(ftest ftest.f)\n" "TARGET_LINK_LIBRARIES(ftest flib)\n") - # Create the Fortran source flib.f which defines two subroutines, "mysub" and - # "my_sub" + # Create the Fortran source flib.f which defines two subroutines, "mysub" and "my_sub" file(WRITE ${FortranTest_DIR}/flib.f - " SUBROUTINE mysub\n" " RETURN\n" " END\n" - " SUBROUTINE my_sub\n" " RETURN\n" " END\n") + " SUBROUTINE mysub\n" + " RETURN\n" + " END\n" + " SUBROUTINE my_sub\n" + " RETURN\n" + " END\n") # Create the Fortran source ftest.f which calls "mysub" and "my_sub" file(WRITE ${FortranTest_DIR}/ftest.f - " PROGRAM ftest\n" " CALL mysub()\n" - " CALL my_sub()\n" " END\n") + " PROGRAM ftest\n" + " CALL mysub()\n" + " CALL my_sub()\n" + " END\n") # Use TRY_COMPILE to make the targets "flib" and "ftest" - try_compile( - FTEST_OK ${FortranTest_DIR} - ${FortranTest_DIR} ftest - OUTPUT_VARIABLE MY_OUTPUT) + try_compile(FTEST_OK ${FortranTest_DIR} ${FortranTest_DIR} + ftest OUTPUT_VARIABLE MY_OUTPUT) - # To ensure we do not use stuff from the previous attempts, we must remove the - # CMakeFiles directory. + # To ensure we do not use stuff from the previous attempts, + # we must remove the CMakeFiles directory. file(REMOVE_RECURSE ${FortranTest_DIR}/CMakeFiles) # Proceed based on test results if(FTEST_OK) # Infer Fortran name-mangling scheme for symbols WITHOUT underscores. - # Overwrite CMakeLists.txt with one which will generate the "ctest1" - # executable - file( - WRITE ${FortranTest_DIR}/CMakeLists.txt + # Overwrite CMakeLists.txt with one which will generate the "ctest1" executable + file(WRITE ${FortranTest_DIR}/CMakeLists.txt "CMAKE_MINIMUM_REQUIRED(VERSION ${CMAKE_VERSION})\n" "PROJECT(ctest1 C)\n" "SET(CMAKE_VERBOSE_MAKEFILE ON)\n" @@ -165,25 +156,23 @@ if(NEED_FORTRAN_NAME_MANGLING) while(${iopt} LESS ${imax}) # Get the current list entry (current scheme) list(GET options ${iopt} opt) - # Generate C source which calls the "mysub" function using the current - # scheme + # Generate C source which calls the "mysub" function using the current scheme file(WRITE ${FortranTest_DIR}/ctest1.c - "extern void ${opt}();\n" "int main(void){${opt}();return(0);}\n") - # Use TRY_COMPILE to make the "ctest1" executable from the current C - # source and linking to the previously created "flib" library. - try_compile( - CTEST_OK ${FortranTest_DIR} - ${FortranTest_DIR} ctest1 - OUTPUT_VARIABLE MY_OUTPUT) + "extern void ${opt}();\n" + "int main(void){${opt}();return(0);}\n") + # Use TRY_COMPILE to make the "ctest1" executable from the current C source + # and linking to the previously created "flib" library. + try_compile(CTEST_OK ${FortranTest_DIR} ${FortranTest_DIR} + ctest1 OUTPUT_VARIABLE MY_OUTPUT) # Write output compiling the test code file(WRITE ${FortranTest_DIR}/ctest1_${opt}.out "${MY_OUTPUT}") - # To ensure we do not use stuff from the previous attempts, we must remove - # the CMakeFiles directory. + # To ensure we do not use stuff from the previous attempts, + # we must remove the CMakeFiles directory. file(REMOVE_RECURSE ${FortranTest_DIR}/CMakeFiles) - # Test if we successfully created the "ctest" executable. If yes, save the - # current scheme, and set the counter "iopt" to "imax" so that we exit the - # while loop. Otherwise, increment the counter "iopt" and go back in the - # while loop. + # Test if we successfully created the "ctest" executable. + # If yes, save the current scheme, and set the counter "iopt" to "imax" + # so that we exit the while loop. + # Otherwise, increment the counter "iopt" and go back in the while loop. if(CTEST_OK) set(CMAKE_Fortran_SCHEME_NO_UNDERSCORES ${opt}) set(iopt ${imax}) @@ -194,8 +183,7 @@ if(NEED_FORTRAN_NAME_MANGLING) # Infer Fortran name-mangling scheme for symbols WITH underscores. # Practically a duplicate of the previous steps. - file( - WRITE ${FortranTest_DIR}/CMakeLists.txt + file(WRITE ${FortranTest_DIR}/CMakeLists.txt "CMAKE_MINIMUM_REQUIRED(VERSION ${CMAKE_VERSION})\n" "PROJECT(ctest2 C)\n" "SET(CMAKE_VERBOSE_MAKEFILE ON)\n" @@ -216,11 +204,10 @@ if(NEED_FORTRAN_NAME_MANGLING) while(${iopt} LESS ${imax}) list(GET options ${iopt} opt) file(WRITE ${FortranTest_DIR}/ctest2.c - "extern void ${opt}();\n" "int main(void){${opt}();return(0);}\n") - try_compile( - CTEST_OK ${FortranTest_DIR} - ${FortranTest_DIR} ctest2 - OUTPUT_VARIABLE MY_OUTPUT) + "extern void ${opt}();\n" + "int main(void){${opt}();return(0);}\n") + try_compile(CTEST_OK ${FortranTest_DIR} ${FortranTest_DIR} + ctest2 OUTPUT_VARIABLE MY_OUTPUT) file(WRITE ${FortranTest_DIR}/ctest2_${opt}.out "${MY_OUTPUT}") file(REMOVE_RECURSE ${FortranTest_DIR}/CMakeFiles) if(CTEST_OK) @@ -233,8 +220,7 @@ if(NEED_FORTRAN_NAME_MANGLING) # If a name-mangling scheme was found set the C preprocessor macros to use # that scheme. Otherwise default to lower case with one underscore. - if(CMAKE_Fortran_SCHEME_NO_UNDERSCORES - AND CMAKE_Fortran_SCHEME_WITH_UNDERSCORES) + if(CMAKE_Fortran_SCHEME_NO_UNDERSCORES AND CMAKE_Fortran_SCHEME_WITH_UNDERSCORES) message(STATUS "Determining Fortran name-mangling scheme... OK") else() message(STATUS "Determining Fortran name-mangling scheme... DEFAULT") @@ -247,23 +233,19 @@ if(NEED_FORTRAN_NAME_MANGLING) set(LAPACK_MANGLE_MACRO1 "#define SUNDIALS_LAPACK_FUNC(name,NAME) name") endif() if(${CMAKE_Fortran_SCHEME_NO_UNDERSCORES} MATCHES "mysub_") - set(LAPACK_MANGLE_MACRO1 - "#define SUNDIALS_LAPACK_FUNC(name,NAME) name ## _") + set(LAPACK_MANGLE_MACRO1 "#define SUNDIALS_LAPACK_FUNC(name,NAME) name ## _") endif() if(${CMAKE_Fortran_SCHEME_NO_UNDERSCORES} MATCHES "mysub__") - set(LAPACK_MANGLE_MACRO1 - "#define SUNDIALS_LAPACK_FUNC(name,NAME) name ## __") + set(LAPACK_MANGLE_MACRO1 "#define SUNDIALS_LAPACK_FUNC(name,NAME) name ## __") endif() if(${CMAKE_Fortran_SCHEME_NO_UNDERSCORES} MATCHES "MYSUB") set(LAPACK_MANGLE_MACRO1 "#define SUNDIALS_LAPACK_FUNC(name,NAME) NAME") endif() if(${CMAKE_Fortran_SCHEME_NO_UNDERSCORES} MATCHES "MYSUB_") - set(LAPACK_MANGLE_MACRO1 - "#define SUNDIALS_LAPACK_FUNC(name,NAME) NAME ## _") + set(LAPACK_MANGLE_MACRO1 "#define SUNDIALS_LAPACK_FUNC(name,NAME) NAME ## _") endif() if(${CMAKE_Fortran_SCHEME_NO_UNDERSCORES} MATCHES "MYSUB__") - set(LAPACK_MANGLE_MACRO1 - "#define SUNDIALS_LAPACK_FUNC(name,NAME) NAME ## __") + set(LAPACK_MANGLE_MACRO1 "#define SUNDIALS_LAPACK_FUNC(name,NAME) NAME ## __") endif() # Symbols WITH underscores @@ -271,30 +253,28 @@ if(NEED_FORTRAN_NAME_MANGLING) set(LAPACK_MANGLE_MACRO2 "#define SUNDIALS_LAPACK_FUNC_(name,NAME) name") endif() if(${CMAKE_Fortran_SCHEME_WITH_UNDERSCORES} MATCHES "my_sub_") - set(LAPACK_MANGLE_MACRO2 - "#define SUNDIALS_LAPACK_FUNC_(name,NAME) name ## _") + set(LAPACK_MANGLE_MACRO2 "#define SUNDIALS_LAPACK_FUNC_(name,NAME) name ## _") endif() if(${CMAKE_Fortran_SCHEME_WITH_UNDERSCORES} MATCHES "my_sub__") - set(LAPACK_MANGLE_MACRO2 - "#define SUNDIALS_LAPACK_FUNC_(name,NAME) name ## __") + set(LAPACK_MANGLE_MACRO2 "#define SUNDIALS_LAPACK_FUNC_(name,NAME) name ## __") endif() if(${CMAKE_Fortran_SCHEME_WITH_UNDERSCORES} MATCHES "MY_SUB") set(LAPACK_MANGLE_MACRO2 "#define SUNDIALS_LAPACK_FUNC_(name,NAME) NAME") endif() if(${CMAKE_Fortran_SCHEME_WITH_UNDERSCORES} MATCHES "MY_SUB_") - set(LAPACK_MANGLE_MACRO2 - "#define SUNDIALS_LAPACK_FUNC_(name,NAME) NAME ## _") + set(LAPACK_MANGLE_MACRO2 "#define SUNDIALS_LAPACK_FUNC_(name,NAME) NAME ## _") endif() if(${CMAKE_Fortran_SCHEME_WITH_UNDERSCORES} MATCHES "MY_SUB__") - set(LAPACK_MANGLE_MACRO2 - "#define SUNDIALS_LAPACK_FUNC_(name,NAME) NAME ## __") + set(LAPACK_MANGLE_MACRO2 "#define SUNDIALS_LAPACK_FUNC_(name,NAME) NAME ## __") endif() # name-mangling scheme has been set set(NEED_FORTRAN_NAME_MANGLING FALSE) - configure_file(${PROJECT_SOURCE_DIR}/src/sundials/sundials_lapack_defs.h.in - ${PROJECT_BINARY_DIR}/src/sundials/sundials_lapack_defs.h) + configure_file( + ${PROJECT_SOURCE_DIR}/src/sundials/sundials_lapack_defs.h.in + ${PROJECT_BINARY_DIR}/src/sundials/sundials_lapack_defs.h + ) else(FTEST_OK) message(STATUS "Determining Fortran name-mangling scheme... FAILED") @@ -302,33 +282,16 @@ if(NEED_FORTRAN_NAME_MANGLING) endif() -# If we have the LAPACK libraries, determine if they work. -if(LAPACK_LIBRARIES AND (NOT LAPACK_WORKS)) - # Create the LapackTest directory - set(LapackTest_DIR ${PROJECT_BINARY_DIR}/LapackTest) - file(MAKE_DIRECTORY ${LapackTest_DIR}) +# Try building a simple test +if(NOT LAPACK_WORKS) - # Create a CMakeLists.txt file - file( - WRITE ${LapackTest_DIR}/CMakeLists.txt - "CMAKE_MINIMUM_REQUIRED(VERSION ${CMAKE_VERSION})\n" - "PROJECT(ltest C)\n" - "SET(CMAKE_VERBOSE_MAKEFILE ON)\n" - "SET(CMAKE_BUILD_TYPE \"${CMAKE_BUILD_TYPE}\")\n" - "SET(CMAKE_C_COMPILER \"${CMAKE_C_COMPILER}\")\n" - "SET(CMAKE_C_STANDARD \"${CMAKE_C_STANDARD}\")\n" - "SET(CMAKE_C_FLAGS \"${CMAKE_C_FLAGS}\")\n" - "SET(CMAKE_C_FLAGS_RELEASE \"${CMAKE_C_FLAGS_RELEASE}\")\n" - "SET(CMAKE_C_FLAGS_DEBUG \"${CMAKE_C_FLAGS_DEBUG}\")\n" - "SET(CMAKE_C_FLAGS_RELWITHDEBUGINFO \"${CMAKE_C_FLAGS_RELWITHDEBUGINFO}\")\n" - "SET(CMAKE_C_FLAGS_MINSIZE \"${CMAKE_C_FLAGS_MINSIZE}\")\n" - "ADD_EXECUTABLE(ltest ltest.c)\n" - "TARGET_LINK_LIBRARIES(ltest ${LAPACK_LIBRARIES})\n") - - # Create a C source file which calls a Blas function (dcopy) and an Lapack - # function (dgetrf) - file( - WRITE ${LapackTest_DIR}/ltest.c + message(CHECK_START "Testing LAPACK") + + # Create the test directory + set(LAPACK_TEST_DIR ${PROJECT_BINARY_DIR}/LAPACK_TEST) + + # Create a C source file calling a BLAS (dcopy) and LAPACK (dgetrf) function + file(WRITE ${LAPACK_TEST_DIR}/test.c "${LAPACK_MANGLE_MACRO1}\n" "#define dcopy_f77 SUNDIALS_LAPACK_FUNC(dcopy, DCOPY)\n" "#define dgetrf_f77 SUNDIALS_LAPACK_FUNC(dgetrf, DGETRF)\n" @@ -340,49 +303,23 @@ if(LAPACK_LIBRARIES AND (NOT LAPACK_WORKS)) "double y=1.0;\n" "dcopy_f77(&n, &x, &n, &y, &n);\n" "dgetrf_f77(&n, &n, &x, &n, &n, &n);\n" - "return(0);\n" + "return 0;\n" "}\n") - # Attempt to build and link the "ltest" executable - try_compile( - COMPILE_OK ${LapackTest_DIR} - ${LapackTest_DIR} ltest - OUTPUT_VARIABLE COMPILE_OUTPUT) - - # To ensure we do not use stuff from the previous attempts, we must remove the - # CMakeFiles directory. - file(REMOVE_RECURSE ${LapackTest_DIR}/CMakeFiles) + # 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::LAPACK OUTPUT_VARIABLE COMPILE_OUTPUT) - # Process test result + # Check the result if(COMPILE_OK) - message(STATUS "Checking if LAPACK works with SUNDIALS... OK") - set(LAPACK_WORKS - TRUE - CACHE BOOL "LAPACK works with SUNDIALS as configured" FORCE) - - # get path to LAPACK library to use in generated makefiles for examples, if - # LAPACK_LIBRARIES contains multiple items only use the path of the first - # entry - list(LENGTH LAPACK_LIBRARIES len) - if(len EQUAL 1) - get_filename_component(LAPACK_LIBRARY_DIR ${LAPACK_LIBRARIES} PATH) - else() - list(GET LAPACK_LIBRARIES 0 TMP_LAPACK_LIBRARIES) - get_filename_component(LAPACK_LIBRARY_DIR ${TMP_LAPACK_LIBRARIES} PATH) - endif() - else(COMPILE_OK) - set(LAPACK_WORKS - FALSE - CACHE BOOL "LAPACK does not work with SUNDIALS as configured" FORCE) - message(STATUS "Checking if LAPACK works with SUNDIALS... FAILED") - message(STATUS "Check output: ") - message("${COMPILE_OUTPUT}") - message(FATAL_ERROR "SUNDIALS interface to LAPACK is not functional.") + message(CHECK_PASS "success") + else() + message(CHECK_FAIL "failed") + file(WRITE ${LAPACK_TEST_DIR}/compile.out "${COMPILE_OUTPUT}") + message(FATAL_ERROR "Could not compile LAPACK test. Check output in ${LAPACK_TEST_DIR}/compile.out") endif() -elseif(LAPACK_LIBRARIES AND LAPACK_WORKS) - message( - STATUS - "Skipped LAPACK tests, assuming LAPACK works with SUNDIALS. Set LAPACK_WORKS=FALSE to (re)run compatibility test." - ) +else() + message(STATUS "Skipped LAPACK test. Set LAPACK_WORKS=FALSE to test.") endif() diff --git a/cmake/tpl/SundialsTPL.cmake.template b/cmake/tpl/SundialsTPL.cmake.template index e95255b18e..add4f38ab0 100644 --- a/cmake/tpl/SundialsTPL.cmake.template +++ b/cmake/tpl/SundialsTPL.cmake.template @@ -26,11 +26,7 @@ # Section 1: Include guard # ----------------------------------------------------------------------------- -if(NOT DEFINED SUNDIALS__INCLUDED) - set(SUNDIALS__INCLUDED) -else() - return() -endif() +include_guard(GLOBAL) # ----------------------------------------------------------------------------- # Section 2: Check to make sure options are compatible @@ -46,38 +42,36 @@ find_package( REQUIRED) # Section 4: Test the TPL # ----------------------------------------------------------------------------- -if(_FOUND AND (NOT _WORKS)) - # Do any checks which don't require compilation first. +# Do any checks which don't require compilation first. - # Create the _TEST directory - set(_TEST_DIR ${PROJECT_BINARY_DIR}/_TEST) - file(MAKE_DIRECTORY ${_TEST_DIR}) +# Try building a simple test +if(NOT _WORKS) - # Create a CMakeLists.txt file - file(WRITE ${_TEST_DIR}/CMakeLists.txt "") + message(CHECK_START "Testing ") - # Create a C source file - file(WRITE ${_TEST_DIR}/ltest.c "") + # Create the test directory + set(_TEST_DIR ${PROJECT_BINARY_DIR}/_TEST) - # To ensure we do not use stuff from the previous attempts, - # we must remove the CMakeFiles directory. - file(REMOVE_RECURSE ${_TEST_DIR}/CMakeFiles) + # Create a C source file + file(WRITE ${_TEST_DIR}/test.c + "int main(void) {\n" + "return 0;\n" + "}\n") - # Attempt to build and link the "ltest" executable - try_compile(COMPILE_OK ${_TEST_DIR} ${_TEST_DIR} ltest - OUTPUT_VARIABLE COMPILE_OUTPUT) + # 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 ${_TEST_DIR} ${_TEST_DIR}/test.c + LINK_LIBRARIES LAPACK::LAPACK OUTPUT_VARIABLE COMPILE_OUTPUT) - # Process test result + # Check the result if(COMPILE_OK) - message(STATUS "Checking if works with SUNDIALS... OK") - set(_WORKS TRUE CACHE BOOL " works with SUNDIALS as configured" FORCE) + message(CHECK_PASS "success") else() - message(STATUS "Checking if works with SUNDIALS... FAILED") - message(STATUS "Check output: ") - message("${COMPILE_OUTPUT}") - message(FATAL_ERROR "SUNDIALS interface to is not functional.") + message(CHECK_FAIL "failed") + file(WRITE ${_TEST_DIR}/compile.out "${COMPILE_OUTPUT}") + message(FATAL_ERROR "Could not compile test. Check output in ${_TEST_DIR}/compile.out") endif() -elseif(_FOUND AND _WORKS) - message(STATUS "Skipped tests, assuming works with SUNDIALS.") +else() + message(STATUS "Skipped test. Set _WORKS=FALSE to test.") endif() diff --git a/examples/arkode/F2003_serial/CMakeLists.txt b/examples/arkode/F2003_serial/CMakeLists.txt index bac936e149..66388f07cb 100644 --- a/examples/arkode/F2003_serial/CMakeLists.txt +++ b/examples/arkode/F2003_serial/CMakeLists.txt @@ -152,9 +152,6 @@ if(BUILD_SUNLINSOL_LAPACKDENSE) set(SUNLINSOLLAPACK_LIBS sundials_sunlinsollapackdense sundials_fsunlinsollapackdense_mod) - # LAPACK libraries - list(APPEND SUNLINSOLLAPACK_LIBS ${LAPACK_LIBRARIES}) - foreach(example_tuple ${FARKODE_examples_LAPACK}) # parse the example tuple diff --git a/examples/cvode/F2003_serial/CMakeLists.txt b/examples/cvode/F2003_serial/CMakeLists.txt index 28d3e9db36..b6ab36ffa4 100644 --- a/examples/cvode/F2003_serial/CMakeLists.txt +++ b/examples/cvode/F2003_serial/CMakeLists.txt @@ -135,9 +135,6 @@ if(BUILD_SUNLINSOL_LAPACKBAND AND BUILD_SUNLINSOL_LAPACKDENSE) set(SUNLINSOLLAPACK_LIBS sundials_sunlinsollapackdense sundials_fsunlinsollapackdense_mod) - # LAPACK libraries - list(APPEND SUNLINSOLLAPACK_LIBS ${LAPACK_LIBRARIES}) - foreach(example_tuple ${FCVODE_examples_LAPACK}) # parse the example tuple diff --git a/examples/cvode/serial/CMakeLists.txt b/examples/cvode/serial/CMakeLists.txt index be033dce06..bebbdad0ce 100644 --- a/examples/cvode/serial/CMakeLists.txt +++ b/examples/cvode/serial/CMakeLists.txt @@ -121,9 +121,6 @@ if(BUILD_SUNLINSOL_LAPACKBAND AND BUILD_SUNLINSOL_LAPACKDENSE) set(SUNLINSOLLAPACK_LIBS sundials_sunlinsollapackband sundials_sunlinsollapackdense) - # LAPACK libraries - list(APPEND SUNLINSOLLAPACK_LIBS ${LAPACK_LIBRARIES}) - foreach(example_tuple ${CVODE_examples_BL}) # parse the example tuple diff --git a/examples/cvodes/serial/CMakeLists.txt b/examples/cvodes/serial/CMakeLists.txt index 4089accc24..50be2bcaf3 100644 --- a/examples/cvodes/serial/CMakeLists.txt +++ b/examples/cvodes/serial/CMakeLists.txt @@ -140,9 +140,6 @@ if(BUILD_SUNLINSOL_LAPACKBAND AND BUILD_SUNLINSOL_LAPACKDENSE) set(SUNLINSOLLAPACK_LIBS sundials_sunlinsollapackband sundials_sunlinsollapackdense) - # LAPACK libraries - list(APPEND SUNLINSOLLAPACK_LIBS ${LAPACK_LIBRARIES}) - foreach(example_tuple ${CVODES_examples_BL}) # parse the example tuple diff --git a/examples/ida/serial/CMakeLists.txt b/examples/ida/serial/CMakeLists.txt index 809c6be76d..dc0e1a183d 100644 --- a/examples/ida/serial/CMakeLists.txt +++ b/examples/ida/serial/CMakeLists.txt @@ -107,9 +107,6 @@ if(BUILD_SUNLINSOL_LAPACKBAND AND BUILD_SUNLINSOL_LAPACKDENSE) set(SUNLINSOLLAPACK_LIBS sundials_sunlinsollapackband sundials_sunlinsollapackdense) - # LAPACK libraries - list(APPEND SUNLINSOLLAPACK_LIBS ${LAPACK_LIBRARIES}) - foreach(example_tuple ${IDA_examples_BL}) # parse the example tuple diff --git a/examples/idas/serial/CMakeLists.txt b/examples/idas/serial/CMakeLists.txt index c90e776019..6b873b90ab 100644 --- a/examples/idas/serial/CMakeLists.txt +++ b/examples/idas/serial/CMakeLists.txt @@ -116,9 +116,6 @@ if(BUILD_SUNLINSOL_LAPACKBAND AND BUILD_SUNLINSOL_LAPACKDENSE) set(SUNLINSOLLAPACK_LIBS sundials_sunlinsollapackband sundials_sunlinsollapackdense) - # LAPACK libraries - list(APPEND SUNLINSOLLAPACK_LIBS ${LAPACK_LIBRARIES}) - foreach(example_tuple ${IDAS_examples_BL}) # parse the example tuple diff --git a/examples/kinsol/serial/CMakeLists.txt b/examples/kinsol/serial/CMakeLists.txt index 47d5fae83a..a822a31077 100644 --- a/examples/kinsol/serial/CMakeLists.txt +++ b/examples/kinsol/serial/CMakeLists.txt @@ -111,9 +111,6 @@ if(BUILD_SUNLINSOL_LAPACKBAND AND BUILD_SUNLINSOL_LAPACKDENSE) set(SUNLINSOLLAPACK_LIBS sundials_sunlinsollapackband sundials_sunlinsollapackdense) - # LAPACK libraries - list(APPEND SUNLINSOLLAPACK_LIBS ${LAPACK_LIBRARIES}) - foreach(example_tuple ${KINSOL_examples_BL}) # parse the example tuple diff --git a/examples/sunlinsol/lapackband/CMakeLists.txt b/examples/sunlinsol/lapackband/CMakeLists.txt index fefcb00eb3..8e7b12927a 100644 --- a/examples/sunlinsol/lapackband/CMakeLists.txt +++ b/examples/sunlinsol/lapackband/CMakeLists.txt @@ -48,9 +48,11 @@ foreach(example_tuple ${sunlinsol_lapackband_examples}) set_target_properties(${example} PROPERTIES FOLDER "Examples") # libraries to link against - target_link_libraries( - ${example} sundials_nvecserial sundials_sunmatrixband - sundials_sunlinsollapackband ${LAPACK_LIBRARIES} ${EXE_EXTRA_LINK_LIBS}) + target_link_libraries(${example} + sundials_nvecserial + sundials_sunmatrixband + sundials_sunlinsollapackband + ${EXE_EXTRA_LINK_LIBS}) endif() # check if example args are provided and set the test name diff --git a/examples/sunlinsol/lapackdense/CMakeLists.txt b/examples/sunlinsol/lapackdense/CMakeLists.txt index e5ff8e32b4..94f7996aa8 100644 --- a/examples/sunlinsol/lapackdense/CMakeLists.txt +++ b/examples/sunlinsol/lapackdense/CMakeLists.txt @@ -57,9 +57,11 @@ foreach(example_tuple ${sunlinsol_lapackdense_examples}) set_target_properties(${example} PROPERTIES FOLDER "Examples") # libraries to link against - target_link_libraries( - ${example} sundials_nvecserial sundials_sunmatrixdense - sundials_sunlinsollapackdense ${LAPACK_LIBRARIES} ${EXE_EXTRA_LINK_LIBS}) + target_link_libraries(${example} + sundials_nvecserial + sundials_sunmatrixdense + sundials_sunlinsollapackdense + ${EXE_EXTRA_LINK_LIBS}) endif() # check if example args are provided and set the test name diff --git a/src/sunlinsol/lapackband/CMakeLists.txt b/src/sunlinsol/lapackband/CMakeLists.txt index 4da37454dd..70fff6e828 100644 --- a/src/sunlinsol/lapackband/CMakeLists.txt +++ b/src/sunlinsol/lapackband/CMakeLists.txt @@ -24,9 +24,14 @@ sundials_add_library( INCLUDE_SUBDIR sunlinsol LINK_LIBRARIES PUBLIC sundials_core OBJECT_LIBRARIES - LINK_LIBRARIES PUBLIC sundials_sunmatrixband "${LAPACK_LIBRARIES}" - OUTPUT_NAME sundials_sunlinsollapackband - VERSION ${sunlinsollib_VERSION} - SOVERSION ${sunlinsollib_SOVERSION}) + LINK_LIBRARIES + PUBLIC sundials_sunmatrixband LAPACK::LAPACK + OUTPUT_NAME + sundials_sunlinsollapackband + VERSION + ${sunlinsollib_VERSION} + SOVERSION + ${sunlinsollib_SOVERSION} +) message(STATUS "Added SUNLINSOL_LAPACKBAND module") diff --git a/src/sunlinsol/lapackdense/CMakeLists.txt b/src/sunlinsol/lapackdense/CMakeLists.txt index f8161667f3..206f04e7d8 100644 --- a/src/sunlinsol/lapackdense/CMakeLists.txt +++ b/src/sunlinsol/lapackdense/CMakeLists.txt @@ -24,10 +24,15 @@ sundials_add_library( INCLUDE_SUBDIR sunlinsol LINK_LIBRARIES PUBLIC sundials_core OBJECT_LIBRARIES - LINK_LIBRARIES PUBLIC sundials_sunmatrixdense "${LAPACK_LIBRARIES}" - OUTPUT_NAME sundials_sunlinsollapackdense - VERSION ${sunlinsollib_VERSION} - SOVERSION ${sunlinsollib_SOVERSION}) + LINK_LIBRARIES + PUBLIC sundials_sunmatrixdense LAPACK::LAPACK + OUTPUT_NAME + sundials_sunlinsollapackdense + VERSION + ${sunlinsollib_VERSION} + SOVERSION + ${sunlinsollib_SOVERSION} +) message(STATUS "Added SUNLINSOL_LAPACKDENSE module") From fa151eb6b9cd05c3716d8ee1eabd88be293d9ce1 Mon Sep 17 00:00:00 2001 From: "David J. Gardner" Date: Thu, 20 Jun 2024 19:17:35 -0700 Subject: [PATCH 02/13] add install guide to Makefile --- doc/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/Makefile b/doc/Makefile index 3788c1d82a..4b25c396fa 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -22,9 +22,9 @@ DIRS = arkode/guide arkode/examples \ kinsol/guide # prefix with desired command to create unique dependencies/targets -LATEXDIRS = $(DIRS:%=latexpdf-%) +LATEXDIRS = $(DIRS:%=latexpdf-%) latexpdf-install_guide HTMLDIRS = $(DIRS:%=html-%) html-superbuild -CLEANDIRS = $(DIRS:%=clean-%) clean-superbuild +CLEANDIRS = $(DIRS:%=clean-%) clean-superbuild clean-install_guide latexpdf: $(LATEXDIRS) $(LATEXDIRS): From 6967545366c8754982389ccecfb955fca1eba46a Mon Sep 17 00:00:00 2001 From: "David J. Gardner" Date: Thu, 20 Jun 2024 22:00:59 -0700 Subject: [PATCH 03/13] update template --- cmake/tpl/SundialsTPL.cmake.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/tpl/SundialsTPL.cmake.template b/cmake/tpl/SundialsTPL.cmake.template index add4f38ab0..a199a1b8c4 100644 --- a/cmake/tpl/SundialsTPL.cmake.template +++ b/cmake/tpl/SundialsTPL.cmake.template @@ -61,7 +61,7 @@ if(NOT _WORKS) # 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 ${_TEST_DIR} ${_TEST_DIR}/test.c - LINK_LIBRARIES LAPACK::LAPACK OUTPUT_VARIABLE COMPILE_OUTPUT) + LINK_LIBRARIES OUTPUT_VARIABLE COMPILE_OUTPUT) # Check the result if(COMPILE_OK) From 49ce6dd75ada63698866cc38e9c76423126b0c16 Mon Sep 17 00:00:00 2001 From: "David J. Gardner" Date: Fri, 21 Jun 2024 18:25:12 -0700 Subject: [PATCH 04/13] remove LAPACK_WORKS from post build option --- cmake/SundialsBuildOptionsPost.cmake | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/cmake/SundialsBuildOptionsPost.cmake b/cmake/SundialsBuildOptionsPost.cmake index 2bf6acd14f..2fe2cc1758 100644 --- a/cmake/SundialsBuildOptionsPost.cmake +++ b/cmake/SundialsBuildOptionsPost.cmake @@ -241,18 +241,14 @@ sundials_option( ADVANCED) list(APPEND SUNDIALS_BUILD_LIST "BUILD_SUNLINSOL_KOKKOSDENSE") -sundials_option( - BUILD_SUNLINSOL_LAPACKBAND BOOL - "Build the SUNLINSOL_LAPACKBAND module (requires LAPACK)" ON - DEPENDS_ON ENABLE_LAPACK LAPACK_WORKS - ADVANCED) +sundials_option(BUILD_SUNLINSOL_LAPACKBAND BOOL "Build the SUNLINSOL_LAPACKBAND module (requires LAPACK)" ON + DEPENDS_ON ENABLE_LAPACK + ADVANCED) list(APPEND SUNDIALS_BUILD_LIST "BUILD_SUNLINSOL_LAPACKBAND") -sundials_option( - BUILD_SUNLINSOL_LAPACKDENSE BOOL - "Build the SUNLINSOL_LAPACKDENSE module (requires LAPACK)" ON - DEPENDS_ON ENABLE_LAPACK LAPACK_WORKS - ADVANCED) +sundials_option(BUILD_SUNLINSOL_LAPACKDENSE BOOL "Build the SUNLINSOL_LAPACKDENSE module (requires LAPACK)" ON + DEPENDS_ON ENABLE_LAPACK + ADVANCED) list(APPEND SUNDIALS_BUILD_LIST "BUILD_SUNLINSOL_LAPACKDENSE") sundials_option( From 635d12f909b7f0dccd1814b7c3410010b5982977 Mon Sep 17 00:00:00 2001 From: "David J. Gardner" Date: Sun, 14 Jul 2024 10:32:23 +0800 Subject: [PATCH 05/13] trigger formatting --- .github/workflows/check-format.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/check-format.yml b/.github/workflows/check-format.yml index b3d0850ca9..e7fc376cd9 100644 --- a/.github/workflows/check-format.yml +++ b/.github/workflows/check-format.yml @@ -3,6 +3,7 @@ name: Checks - formatting on: pull_request: workflow_dispatch: + push: jobs: format_check: From d3a7c31033eb7909fededa5a6a7b1372b5f51bef Mon Sep 17 00:00:00 2001 From: "David J. Gardner" Date: Mon, 15 Jul 2024 09:54:08 +0800 Subject: [PATCH 06/13] apply formatting --- cmake/SundialsBuildOptionsPost.cmake | 16 ++- cmake/tpl/SundialsLapack.cmake | 131 ++++++++++-------- examples/sunlinsol/lapackband/CMakeLists.txt | 7 +- examples/sunlinsol/lapackdense/CMakeLists.txt | 8 +- src/sunlinsol/lapackband/CMakeLists.txt | 13 +- src/sunlinsol/lapackdense/CMakeLists.txt | 13 +- 6 files changed, 98 insertions(+), 90 deletions(-) diff --git a/cmake/SundialsBuildOptionsPost.cmake b/cmake/SundialsBuildOptionsPost.cmake index 2fe2cc1758..c353aff69d 100644 --- a/cmake/SundialsBuildOptionsPost.cmake +++ b/cmake/SundialsBuildOptionsPost.cmake @@ -241,14 +241,18 @@ sundials_option( ADVANCED) list(APPEND SUNDIALS_BUILD_LIST "BUILD_SUNLINSOL_KOKKOSDENSE") -sundials_option(BUILD_SUNLINSOL_LAPACKBAND BOOL "Build the SUNLINSOL_LAPACKBAND module (requires LAPACK)" ON - DEPENDS_ON ENABLE_LAPACK - ADVANCED) +sundials_option( + BUILD_SUNLINSOL_LAPACKBAND BOOL + "Build the SUNLINSOL_LAPACKBAND module (requires LAPACK)" ON + DEPENDS_ON ENABLE_LAPACK + ADVANCED) list(APPEND SUNDIALS_BUILD_LIST "BUILD_SUNLINSOL_LAPACKBAND") -sundials_option(BUILD_SUNLINSOL_LAPACKDENSE BOOL "Build the SUNLINSOL_LAPACKDENSE module (requires LAPACK)" ON - DEPENDS_ON ENABLE_LAPACK - ADVANCED) +sundials_option( + BUILD_SUNLINSOL_LAPACKDENSE BOOL + "Build the SUNLINSOL_LAPACKDENSE module (requires LAPACK)" ON + DEPENDS_ON ENABLE_LAPACK + ADVANCED) list(APPEND SUNDIALS_BUILD_LIST "BUILD_SUNLINSOL_LAPACKDENSE") sundials_option( diff --git a/cmake/tpl/SundialsLapack.cmake b/cmake/tpl/SundialsLapack.cmake index af76973889..53a65b1049 100644 --- a/cmake/tpl/SundialsLapack.cmake +++ b/cmake/tpl/SundialsLapack.cmake @@ -34,7 +34,8 @@ include_guard(GLOBAL) # LAPACK does not support extended precision if(ENABLE_LAPACK AND SUNDIALS_PRECISION MATCHES "EXTENDED") - message(FATAL_ERROR "LAPACK is not compatible with ${SUNDIALS_PRECISION} precision") + message( + FATAL_ERROR "LAPACK is not compatible with ${SUNDIALS_PRECISION} precision") endif() # ----------------------------------------------------------------------------- @@ -84,9 +85,10 @@ if(NEED_FORTRAN_NAME_MANGLING) set(FortranTest_DIR ${PROJECT_BINARY_DIR}/FortranTest) file(MAKE_DIRECTORY ${FortranTest_DIR}) - # Create a CMakeLists.txt file which will generate the "flib" library - # and an executable "ftest" - file(WRITE ${FortranTest_DIR}/CMakeLists.txt + # Create a CMakeLists.txt file which will generate the "flib" library and an + # executable "ftest" + file( + WRITE ${FortranTest_DIR}/CMakeLists.txt "CMAKE_MINIMUM_REQUIRED(VERSION ${CMAKE_VERSION})\n" "PROJECT(ftest Fortran)\n" "SET(CMAKE_VERBOSE_MAKEFILE ON)\n" @@ -101,36 +103,35 @@ if(NEED_FORTRAN_NAME_MANGLING) "ADD_EXECUTABLE(ftest ftest.f)\n" "TARGET_LINK_LIBRARIES(ftest flib)\n") - # Create the Fortran source flib.f which defines two subroutines, "mysub" and "my_sub" + # Create the Fortran source flib.f which defines two subroutines, "mysub" and + # "my_sub" file(WRITE ${FortranTest_DIR}/flib.f - " SUBROUTINE mysub\n" - " RETURN\n" - " END\n" - " SUBROUTINE my_sub\n" - " RETURN\n" - " END\n") + " SUBROUTINE mysub\n" " RETURN\n" " END\n" + " SUBROUTINE my_sub\n" " RETURN\n" " END\n") # Create the Fortran source ftest.f which calls "mysub" and "my_sub" file(WRITE ${FortranTest_DIR}/ftest.f - " PROGRAM ftest\n" - " CALL mysub()\n" - " CALL my_sub()\n" - " END\n") + " PROGRAM ftest\n" " CALL mysub()\n" + " CALL my_sub()\n" " END\n") # Use TRY_COMPILE to make the targets "flib" and "ftest" - try_compile(FTEST_OK ${FortranTest_DIR} ${FortranTest_DIR} - ftest OUTPUT_VARIABLE MY_OUTPUT) + try_compile( + FTEST_OK ${FortranTest_DIR} + ${FortranTest_DIR} ftest + OUTPUT_VARIABLE MY_OUTPUT) - # To ensure we do not use stuff from the previous attempts, - # we must remove the CMakeFiles directory. + # To ensure we do not use stuff from the previous attempts, we must remove the + # CMakeFiles directory. file(REMOVE_RECURSE ${FortranTest_DIR}/CMakeFiles) # Proceed based on test results if(FTEST_OK) # Infer Fortran name-mangling scheme for symbols WITHOUT underscores. - # Overwrite CMakeLists.txt with one which will generate the "ctest1" executable - file(WRITE ${FortranTest_DIR}/CMakeLists.txt + # Overwrite CMakeLists.txt with one which will generate the "ctest1" + # executable + file( + WRITE ${FortranTest_DIR}/CMakeLists.txt "CMAKE_MINIMUM_REQUIRED(VERSION ${CMAKE_VERSION})\n" "PROJECT(ctest1 C)\n" "SET(CMAKE_VERBOSE_MAKEFILE ON)\n" @@ -156,23 +157,25 @@ if(NEED_FORTRAN_NAME_MANGLING) while(${iopt} LESS ${imax}) # Get the current list entry (current scheme) list(GET options ${iopt} opt) - # Generate C source which calls the "mysub" function using the current scheme + # Generate C source which calls the "mysub" function using the current + # scheme file(WRITE ${FortranTest_DIR}/ctest1.c - "extern void ${opt}();\n" - "int main(void){${opt}();return(0);}\n") - # Use TRY_COMPILE to make the "ctest1" executable from the current C source - # and linking to the previously created "flib" library. - try_compile(CTEST_OK ${FortranTest_DIR} ${FortranTest_DIR} - ctest1 OUTPUT_VARIABLE MY_OUTPUT) + "extern void ${opt}();\n" "int main(void){${opt}();return(0);}\n") + # Use TRY_COMPILE to make the "ctest1" executable from the current C + # source and linking to the previously created "flib" library. + try_compile( + CTEST_OK ${FortranTest_DIR} + ${FortranTest_DIR} ctest1 + OUTPUT_VARIABLE MY_OUTPUT) # Write output compiling the test code file(WRITE ${FortranTest_DIR}/ctest1_${opt}.out "${MY_OUTPUT}") - # To ensure we do not use stuff from the previous attempts, - # we must remove the CMakeFiles directory. + # To ensure we do not use stuff from the previous attempts, we must remove + # the CMakeFiles directory. file(REMOVE_RECURSE ${FortranTest_DIR}/CMakeFiles) - # Test if we successfully created the "ctest" executable. - # If yes, save the current scheme, and set the counter "iopt" to "imax" - # so that we exit the while loop. - # Otherwise, increment the counter "iopt" and go back in the while loop. + # Test if we successfully created the "ctest" executable. If yes, save the + # current scheme, and set the counter "iopt" to "imax" so that we exit the + # while loop. Otherwise, increment the counter "iopt" and go back in the + # while loop. if(CTEST_OK) set(CMAKE_Fortran_SCHEME_NO_UNDERSCORES ${opt}) set(iopt ${imax}) @@ -183,7 +186,8 @@ if(NEED_FORTRAN_NAME_MANGLING) # Infer Fortran name-mangling scheme for symbols WITH underscores. # Practically a duplicate of the previous steps. - file(WRITE ${FortranTest_DIR}/CMakeLists.txt + file( + WRITE ${FortranTest_DIR}/CMakeLists.txt "CMAKE_MINIMUM_REQUIRED(VERSION ${CMAKE_VERSION})\n" "PROJECT(ctest2 C)\n" "SET(CMAKE_VERBOSE_MAKEFILE ON)\n" @@ -204,10 +208,11 @@ if(NEED_FORTRAN_NAME_MANGLING) while(${iopt} LESS ${imax}) list(GET options ${iopt} opt) file(WRITE ${FortranTest_DIR}/ctest2.c - "extern void ${opt}();\n" - "int main(void){${opt}();return(0);}\n") - try_compile(CTEST_OK ${FortranTest_DIR} ${FortranTest_DIR} - ctest2 OUTPUT_VARIABLE MY_OUTPUT) + "extern void ${opt}();\n" "int main(void){${opt}();return(0);}\n") + try_compile( + CTEST_OK ${FortranTest_DIR} + ${FortranTest_DIR} ctest2 + OUTPUT_VARIABLE MY_OUTPUT) file(WRITE ${FortranTest_DIR}/ctest2_${opt}.out "${MY_OUTPUT}") file(REMOVE_RECURSE ${FortranTest_DIR}/CMakeFiles) if(CTEST_OK) @@ -220,7 +225,8 @@ if(NEED_FORTRAN_NAME_MANGLING) # If a name-mangling scheme was found set the C preprocessor macros to use # that scheme. Otherwise default to lower case with one underscore. - if(CMAKE_Fortran_SCHEME_NO_UNDERSCORES AND CMAKE_Fortran_SCHEME_WITH_UNDERSCORES) + if(CMAKE_Fortran_SCHEME_NO_UNDERSCORES + AND CMAKE_Fortran_SCHEME_WITH_UNDERSCORES) message(STATUS "Determining Fortran name-mangling scheme... OK") else() message(STATUS "Determining Fortran name-mangling scheme... DEFAULT") @@ -233,19 +239,23 @@ if(NEED_FORTRAN_NAME_MANGLING) set(LAPACK_MANGLE_MACRO1 "#define SUNDIALS_LAPACK_FUNC(name,NAME) name") endif() if(${CMAKE_Fortran_SCHEME_NO_UNDERSCORES} MATCHES "mysub_") - set(LAPACK_MANGLE_MACRO1 "#define SUNDIALS_LAPACK_FUNC(name,NAME) name ## _") + set(LAPACK_MANGLE_MACRO1 + "#define SUNDIALS_LAPACK_FUNC(name,NAME) name ## _") endif() if(${CMAKE_Fortran_SCHEME_NO_UNDERSCORES} MATCHES "mysub__") - set(LAPACK_MANGLE_MACRO1 "#define SUNDIALS_LAPACK_FUNC(name,NAME) name ## __") + set(LAPACK_MANGLE_MACRO1 + "#define SUNDIALS_LAPACK_FUNC(name,NAME) name ## __") endif() if(${CMAKE_Fortran_SCHEME_NO_UNDERSCORES} MATCHES "MYSUB") set(LAPACK_MANGLE_MACRO1 "#define SUNDIALS_LAPACK_FUNC(name,NAME) NAME") endif() if(${CMAKE_Fortran_SCHEME_NO_UNDERSCORES} MATCHES "MYSUB_") - set(LAPACK_MANGLE_MACRO1 "#define SUNDIALS_LAPACK_FUNC(name,NAME) NAME ## _") + set(LAPACK_MANGLE_MACRO1 + "#define SUNDIALS_LAPACK_FUNC(name,NAME) NAME ## _") endif() if(${CMAKE_Fortran_SCHEME_NO_UNDERSCORES} MATCHES "MYSUB__") - set(LAPACK_MANGLE_MACRO1 "#define SUNDIALS_LAPACK_FUNC(name,NAME) NAME ## __") + set(LAPACK_MANGLE_MACRO1 + "#define SUNDIALS_LAPACK_FUNC(name,NAME) NAME ## __") endif() # Symbols WITH underscores @@ -253,28 +263,30 @@ if(NEED_FORTRAN_NAME_MANGLING) set(LAPACK_MANGLE_MACRO2 "#define SUNDIALS_LAPACK_FUNC_(name,NAME) name") endif() if(${CMAKE_Fortran_SCHEME_WITH_UNDERSCORES} MATCHES "my_sub_") - set(LAPACK_MANGLE_MACRO2 "#define SUNDIALS_LAPACK_FUNC_(name,NAME) name ## _") + set(LAPACK_MANGLE_MACRO2 + "#define SUNDIALS_LAPACK_FUNC_(name,NAME) name ## _") endif() if(${CMAKE_Fortran_SCHEME_WITH_UNDERSCORES} MATCHES "my_sub__") - set(LAPACK_MANGLE_MACRO2 "#define SUNDIALS_LAPACK_FUNC_(name,NAME) name ## __") + set(LAPACK_MANGLE_MACRO2 + "#define SUNDIALS_LAPACK_FUNC_(name,NAME) name ## __") endif() if(${CMAKE_Fortran_SCHEME_WITH_UNDERSCORES} MATCHES "MY_SUB") set(LAPACK_MANGLE_MACRO2 "#define SUNDIALS_LAPACK_FUNC_(name,NAME) NAME") endif() if(${CMAKE_Fortran_SCHEME_WITH_UNDERSCORES} MATCHES "MY_SUB_") - set(LAPACK_MANGLE_MACRO2 "#define SUNDIALS_LAPACK_FUNC_(name,NAME) NAME ## _") + set(LAPACK_MANGLE_MACRO2 + "#define SUNDIALS_LAPACK_FUNC_(name,NAME) NAME ## _") endif() if(${CMAKE_Fortran_SCHEME_WITH_UNDERSCORES} MATCHES "MY_SUB__") - set(LAPACK_MANGLE_MACRO2 "#define SUNDIALS_LAPACK_FUNC_(name,NAME) NAME ## __") + set(LAPACK_MANGLE_MACRO2 + "#define SUNDIALS_LAPACK_FUNC_(name,NAME) NAME ## __") endif() # name-mangling scheme has been set set(NEED_FORTRAN_NAME_MANGLING FALSE) - configure_file( - ${PROJECT_SOURCE_DIR}/src/sundials/sundials_lapack_defs.h.in - ${PROJECT_BINARY_DIR}/src/sundials/sundials_lapack_defs.h - ) + configure_file(${PROJECT_SOURCE_DIR}/src/sundials/sundials_lapack_defs.h.in + ${PROJECT_BINARY_DIR}/src/sundials/sundials_lapack_defs.h) else(FTEST_OK) message(STATUS "Determining Fortran name-mangling scheme... FAILED") @@ -291,7 +303,8 @@ if(NOT LAPACK_WORKS) set(LAPACK_TEST_DIR ${PROJECT_BINARY_DIR}/LAPACK_TEST) # Create a C source file calling a BLAS (dcopy) and LAPACK (dgetrf) function - file(WRITE ${LAPACK_TEST_DIR}/test.c + file( + WRITE ${LAPACK_TEST_DIR}/test.c "${LAPACK_MANGLE_MACRO1}\n" "#define dcopy_f77 SUNDIALS_LAPACK_FUNC(dcopy, DCOPY)\n" "#define dgetrf_f77 SUNDIALS_LAPACK_FUNC(dgetrf, DGETRF)\n" @@ -308,8 +321,11 @@ if(NOT LAPACK_WORKS) # 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::LAPACK OUTPUT_VARIABLE COMPILE_OUTPUT) + try_compile( + COMPILE_OK ${LAPACK_TEST_DIR} + ${LAPACK_TEST_DIR}/test.c + LINK_LIBRARIES LAPACK::LAPACK + OUTPUT_VARIABLE COMPILE_OUTPUT) # Check the result if(COMPILE_OK) @@ -317,7 +333,10 @@ if(NOT LAPACK_WORKS) else() message(CHECK_FAIL "failed") file(WRITE ${LAPACK_TEST_DIR}/compile.out "${COMPILE_OUTPUT}") - message(FATAL_ERROR "Could not compile LAPACK test. Check output in ${LAPACK_TEST_DIR}/compile.out") + message( + FATAL_ERROR + "Could not compile LAPACK test. Check output in ${LAPACK_TEST_DIR}/compile.out" + ) endif() else() diff --git a/examples/sunlinsol/lapackband/CMakeLists.txt b/examples/sunlinsol/lapackband/CMakeLists.txt index 8e7b12927a..8e4b763763 100644 --- a/examples/sunlinsol/lapackband/CMakeLists.txt +++ b/examples/sunlinsol/lapackband/CMakeLists.txt @@ -48,11 +48,8 @@ foreach(example_tuple ${sunlinsol_lapackband_examples}) set_target_properties(${example} PROPERTIES FOLDER "Examples") # libraries to link against - target_link_libraries(${example} - sundials_nvecserial - sundials_sunmatrixband - sundials_sunlinsollapackband - ${EXE_EXTRA_LINK_LIBS}) + target_link_libraries(${example} sundials_nvecserial sundials_sunmatrixband + sundials_sunlinsollapackband ${EXE_EXTRA_LINK_LIBS}) endif() # check if example args are provided and set the test name diff --git a/examples/sunlinsol/lapackdense/CMakeLists.txt b/examples/sunlinsol/lapackdense/CMakeLists.txt index 94f7996aa8..5cb269fbe2 100644 --- a/examples/sunlinsol/lapackdense/CMakeLists.txt +++ b/examples/sunlinsol/lapackdense/CMakeLists.txt @@ -57,11 +57,9 @@ foreach(example_tuple ${sunlinsol_lapackdense_examples}) set_target_properties(${example} PROPERTIES FOLDER "Examples") # libraries to link against - target_link_libraries(${example} - sundials_nvecserial - sundials_sunmatrixdense - sundials_sunlinsollapackdense - ${EXE_EXTRA_LINK_LIBS}) + target_link_libraries( + ${example} sundials_nvecserial sundials_sunmatrixdense + sundials_sunlinsollapackdense ${EXE_EXTRA_LINK_LIBS}) endif() # check if example args are provided and set the test name diff --git a/src/sunlinsol/lapackband/CMakeLists.txt b/src/sunlinsol/lapackband/CMakeLists.txt index 70fff6e828..fd1259145a 100644 --- a/src/sunlinsol/lapackband/CMakeLists.txt +++ b/src/sunlinsol/lapackband/CMakeLists.txt @@ -24,14 +24,9 @@ sundials_add_library( INCLUDE_SUBDIR sunlinsol LINK_LIBRARIES PUBLIC sundials_core OBJECT_LIBRARIES - LINK_LIBRARIES - PUBLIC sundials_sunmatrixband LAPACK::LAPACK - OUTPUT_NAME - sundials_sunlinsollapackband - VERSION - ${sunlinsollib_VERSION} - SOVERSION - ${sunlinsollib_SOVERSION} -) + LINK_LIBRARIES PUBLIC sundials_sunmatrixband LAPACK::LAPACK + OUTPUT_NAME sundials_sunlinsollapackband + VERSION ${sunlinsollib_VERSION} + SOVERSION ${sunlinsollib_SOVERSION}) message(STATUS "Added SUNLINSOL_LAPACKBAND module") diff --git a/src/sunlinsol/lapackdense/CMakeLists.txt b/src/sunlinsol/lapackdense/CMakeLists.txt index 206f04e7d8..59825bb88d 100644 --- a/src/sunlinsol/lapackdense/CMakeLists.txt +++ b/src/sunlinsol/lapackdense/CMakeLists.txt @@ -24,15 +24,10 @@ sundials_add_library( INCLUDE_SUBDIR sunlinsol LINK_LIBRARIES PUBLIC sundials_core OBJECT_LIBRARIES - LINK_LIBRARIES - PUBLIC sundials_sunmatrixdense LAPACK::LAPACK - OUTPUT_NAME - sundials_sunlinsollapackdense - VERSION - ${sunlinsollib_VERSION} - SOVERSION - ${sunlinsollib_SOVERSION} -) + LINK_LIBRARIES PUBLIC sundials_sunmatrixdense LAPACK::LAPACK + OUTPUT_NAME sundials_sunlinsollapackdense + VERSION ${sunlinsollib_VERSION} + SOVERSION ${sunlinsollib_SOVERSION}) message(STATUS "Added SUNLINSOL_LAPACKDENSE module") From 827aae6c2a5462fffb0b6678bde3f6124bd9d619 Mon Sep 17 00:00:00 2001 From: "David J. Gardner" Date: Mon, 15 Jul 2024 13:23:35 +0800 Subject: [PATCH 07/13] fix list formatting --- cmake/tpl/SundialsLapack.cmake | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/cmake/tpl/SundialsLapack.cmake b/cmake/tpl/SundialsLapack.cmake index 53a65b1049..9e4dc3d7d6 100644 --- a/cmake/tpl/SundialsLapack.cmake +++ b/cmake/tpl/SundialsLapack.cmake @@ -62,15 +62,16 @@ endif() # Determining the name-mangling scheme if needed # --------------------------------------------------------------- # In general, names of symbols with and without underscore may be mangled -# differently (e.g. g77 mangles mysub to mysub_ and my_sub to my_sub__), -# we have to consider both cases. +# differently (e.g. g77 mangles mysub to mysub_ and my_sub to my_sub__), we have +# to consider both cases. # # Method: -# 1) create a library from a Fortran source file which defines a function "mysub" -# 2) attempt to link with this library a C source file which calls the "mysub" -# function using various possible schemes (6 different schemes, corresponding -# to all combinations lower/upper case and none/one/two underscores). -# 3) define the name-mangling scheme based on the test that was successful. +# +# 1. create a library from a Fortran source file which defines a function "mysub" +# 2. attempt to link with this library a C source file which calls the "mysub" +# function using various possible schemes (6 different schemes, corresponding +# to all combinations lower/upper case and none/one/two underscores). +# 3. define the name-mangling scheme based on the test that was successful. # # On exit, if we were able to infer the scheme, the variables # CMAKE_Fortran_SCHEME_NO_UNDERSCORES and CMAKE_Fortran_SCHEME_WITH_UNDERSCORES From 033f5cc36b77789dff9d8f35a81c62b240070c9a Mon Sep 17 00:00:00 2001 From: "David J. Gardner" Date: Mon, 15 Jul 2024 13:45:38 +0800 Subject: [PATCH 08/13] remove run on push --- .github/workflows/check-format.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/check-format.yml b/.github/workflows/check-format.yml index e7fc376cd9..b3d0850ca9 100644 --- a/.github/workflows/check-format.yml +++ b/.github/workflows/check-format.yml @@ -3,7 +3,6 @@ name: Checks - formatting on: pull_request: workflow_dispatch: - push: jobs: format_check: From b7e2a2f3b782d44c37618524609876a17c4b51be Mon Sep 17 00:00:00 2001 From: "David J. Gardner" Date: Tue, 16 Jul 2024 23:48:10 +0800 Subject: [PATCH 09/13] set BLAS_LIBRARIES for Jenkins CI --- test/config_cmake.py | 11 +++++++++++ test/env/default.sh | 2 ++ 2 files changed, 13 insertions(+) diff --git a/test/config_cmake.py b/test/config_cmake.py index f1574b6257..ac2a6f079e 100644 --- a/test/config_cmake.py +++ b/test/config_cmake.py @@ -926,6 +926,17 @@ def main(): dependson="--lapack", ) + add_arg( + group, + "--blas-libs", + "BLAS_LIBRARIES", + "BLAS_LIBRARIES", + None, + "STRING", + "BLAS libraries", + dependson="--lapack", + ) + # KLU group = parser.add_argument_group("KLU Options") diff --git a/test/env/default.sh b/test/env/default.sh index 4f72c3f7f5..801c5b8213 100644 --- a/test/env/default.sh +++ b/test/env/default.sh @@ -269,9 +269,11 @@ if [ "$SUNDIALS_PRECISION" != "extended" ]; then LAPACK_ROOT="$(spack location -i openblas@0.3.20 +ilp64 %"$compiler")" fi export LAPACK_LIBRARIES="${LAPACK_ROOT}/lib/libopenblas.so" + export BLAS_LIBRARIES="${LAPACK_LIBRARIES}" else export SUNDIALS_LAPACK=OFF unset LAPACK_LIBRARIES + unset BLAS_LIBRARIES fi # --- From 7e982f3ebff2f4aac7df44bd4dc9d6aad647f9c7 Mon Sep 17 00:00:00 2001 From: "David J. Gardner" Date: Thu, 18 Jul 2024 14:29:52 +0800 Subject: [PATCH 10/13] workaround bug in older CMake versions --- cmake/tpl/SundialsLapack.cmake | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/cmake/tpl/SundialsLapack.cmake b/cmake/tpl/SundialsLapack.cmake index de8ac20d90..791ff1be1d 100644 --- a/cmake/tpl/SundialsLapack.cmake +++ b/cmake/tpl/SundialsLapack.cmake @@ -322,11 +322,23 @@ if(NOT LAPACK_WORKS) # 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::LAPACK - OUTPUT_VARIABLE COMPILE_OUTPUT) + 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/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) + else() + try_compile( + COMPILE_OK ${LAPACK_TEST_DIR} + ${LAPACK_TEST_DIR}/test.c + LINK_LIBRARIES LAPACK::LAPACK + OUTPUT_VARIABLE COMPILE_OUTPUT) + endif() # Check the result if(COMPILE_OK) From 1b3bcf2656849951989fcbca444c546dc7e2cb0a Mon Sep 17 00:00:00 2001 From: "David J. Gardner" Date: Thu, 18 Jul 2024 14:38:37 +0800 Subject: [PATCH 11/13] apply formatting --- cmake/tpl/SundialsLapack.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/tpl/SundialsLapack.cmake b/cmake/tpl/SundialsLapack.cmake index 791ff1be1d..aa203faee3 100644 --- a/cmake/tpl/SundialsLapack.cmake +++ b/cmake/tpl/SundialsLapack.cmake @@ -322,11 +322,11 @@ if(NOT LAPACK_WORKS) # Attempt to build and link the test executable, pass --debug-trycompile to # the cmake command to save build files for debugging - if (CMAKE_VERSION VERSION_LESS 3.20) + 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/Targets.cmake - # created by try_compile + # ${LAPACK_TEST_DIR}/CMakeFiles/CMakeTmp/Targets.cmake created + # by try_compile try_compile( COMPILE_OK ${LAPACK_TEST_DIR} ${LAPACK_TEST_DIR}/test.c From c370e2ffb34114a0b233bb14fd2ae05a8eacd013 Mon Sep 17 00:00:00 2001 From: "David J. Gardner" Date: Thu, 18 Jul 2024 15:36:26 +0800 Subject: [PATCH 12/13] work around CMake bug with LAPACK::LAPACK not including BLAS::BLAS --- cmake/tpl/SundialsLapack.cmake | 30 +++++++++++------------- src/sunlinsol/lapackband/CMakeLists.txt | 10 +++++++- src/sunlinsol/lapackdense/CMakeLists.txt | 10 +++++++- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/cmake/tpl/SundialsLapack.cmake b/cmake/tpl/SundialsLapack.cmake index aa203faee3..8181df7b7d 100644 --- a/cmake/tpl/SundialsLapack.cmake +++ b/cmake/tpl/SundialsLapack.cmake @@ -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/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/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") diff --git a/src/sunlinsol/lapackband/CMakeLists.txt b/src/sunlinsol/lapackband/CMakeLists.txt index fd1259145a..c4206daf27 100644 --- a/src/sunlinsol/lapackband/CMakeLists.txt +++ b/src/sunlinsol/lapackband/CMakeLists.txt @@ -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 @@ -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}) diff --git a/src/sunlinsol/lapackdense/CMakeLists.txt b/src/sunlinsol/lapackdense/CMakeLists.txt index 59825bb88d..e6f9673120 100644 --- a/src/sunlinsol/lapackdense/CMakeLists.txt +++ b/src/sunlinsol/lapackdense/CMakeLists.txt @@ -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 @@ -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}) From 51cbea8de996649d4f5c0e5fcbb42aa0d696bb47 Mon Sep 17 00:00:00 2001 From: "David J. Gardner" Date: Thu, 18 Jul 2024 15:46:51 +0800 Subject: [PATCH 13/13] apply formatting --- cmake/tpl/SundialsLapack.cmake | 8 ++++---- src/sunlinsol/lapackband/CMakeLists.txt | 4 ++-- src/sunlinsol/lapackdense/CMakeLists.txt | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cmake/tpl/SundialsLapack.cmake b/cmake/tpl/SundialsLapack.cmake index 8181df7b7d..7d1b9e67f6 100644 --- a/cmake/tpl/SundialsLapack.cmake +++ b/cmake/tpl/SundialsLapack.cmake @@ -320,10 +320,10 @@ if(NOT LAPACK_WORKS) "return 0;\n" "}\n") - # 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/Targets.cmake created - # by try_compile + # 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/Targets.cmake created by + # try_compile if(CMAKE_VERSION VERSION_LESS 3.20) set(_lapack_targets LAPACK::LAPACK BLAS::BLAS) else() diff --git a/src/sunlinsol/lapackband/CMakeLists.txt b/src/sunlinsol/lapackband/CMakeLists.txt index c4206daf27..70c8b74a23 100644 --- a/src/sunlinsol/lapackband/CMakeLists.txt +++ b/src/sunlinsol/lapackband/CMakeLists.txt @@ -16,8 +16,8 @@ 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 +# 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() diff --git a/src/sunlinsol/lapackdense/CMakeLists.txt b/src/sunlinsol/lapackdense/CMakeLists.txt index e6f9673120..3077104c4a 100644 --- a/src/sunlinsol/lapackdense/CMakeLists.txt +++ b/src/sunlinsol/lapackdense/CMakeLists.txt @@ -16,8 +16,8 @@ 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 +# 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()