|
| 1 | +if (${RX_USE_SUITESPARSE}) |
| 2 | + include(FetchContent) |
| 3 | + |
| 4 | + # =========================================================== |
| 5 | + # 1. BLAS (try system first, else build OpenBLAS) |
| 6 | + # =========================================================== |
| 7 | + set(BLA_VENDOR OpenBLAS) |
| 8 | + find_package(BLAS QUIET COMPONENTS CBLAS) |
| 9 | + |
| 10 | + if (NOT BLAS_FOUND) |
| 11 | + message(STATUS "No BLAS on the system – building OpenBLAS") |
| 12 | + |
| 13 | + FetchContent_Declare( |
| 14 | + openblas |
| 15 | + GIT_REPOSITORY https://github.com/xianyi/OpenBLAS.git |
| 16 | + GIT_TAG v0.3.27 |
| 17 | + ) |
| 18 | + # We need the LAPACK symbols for SuiteSparse |
| 19 | + set(BUILD_WITHOUT_LAPACK OFF CACHE BOOL "" FORCE) |
| 20 | + FetchContent_MakeAvailable(openblas) |
| 21 | + |
| 22 | + # 1) Pick the real OpenBLAS target (may be an alias) |
| 23 | + set(_blas_target "") |
| 24 | + if(TARGET openblas) |
| 25 | + # openblas is usually an ALIAS → follow it |
| 26 | + get_property(_aliased TARGET openblas PROPERTY ALIASED_TARGET) |
| 27 | + if(_aliased) |
| 28 | + set(_blas_target ${_aliased}) # real imported library |
| 29 | + else() |
| 30 | + set(_blas_target openblas) # openblas *is* the real one |
| 31 | + endif() |
| 32 | + elseif(TARGET OpenBLAS::OpenBLAS) |
| 33 | + set(_blas_target OpenBLAS::OpenBLAS) # MinGW / some Linux builds |
| 34 | + else() |
| 35 | + message(FATAL_ERROR "OpenBLAS was built but exported no usable target") |
| 36 | + endif() |
| 37 | + |
| 38 | + # 2) Provide a canonical BLAS::BLAS, but only once |
| 39 | + if(NOT TARGET BLAS::BLAS) |
| 40 | + add_library(BLAS::BLAS ALIAS ${_blas_target}) |
| 41 | + endif() |
| 42 | + |
| 43 | + # 3) LAPACK shim (SuiteSparse needs it) |
| 44 | + if(NOT TARGET LAPACK::LAPACK) |
| 45 | + add_library(LAPACK::LAPACK ALIAS ${_blas_target}) |
| 46 | + endif() |
| 47 | + |
| 48 | + |
| 49 | + # 4) Legacy cache variables so FindBLAS/LAPACK are satisfied |
| 50 | + set(BLAS_LIBRARIES BLAS::BLAS CACHE STRING "" FORCE) |
| 51 | + set(BLAS_FOUND TRUE CACHE BOOL "" FORCE) |
| 52 | + set(LAPACK_LIBRARIES LAPACK::LAPACK CACHE STRING "" FORCE) |
| 53 | + set(LAPACK_FOUND TRUE CACHE BOOL "" FORCE) |
| 54 | + set(LAPACK_LIBRARIES ${BLAS_LIBRARIES} CACHE STRING "" FORCE) |
| 55 | + set(LAPACK_FOUND TRUE CACHE BOOL "" FORCE) |
| 56 | + endif() |
| 57 | + |
| 58 | + # =========================================================== |
| 59 | + # 3. Fetch & build SuiteSparse |
| 60 | + # =========================================================== |
| 61 | + set(WITH_FORTRAN OFF CACHE BOOL "" FORCE) |
| 62 | + set(WITH_CUDA ON CACHE BOOL "" FORCE) |
| 63 | + set(WITH_PARTITION ON CACHE BOOL "" FORCE) |
| 64 | + set(WITH_DEMOS OFF CACHE BOOL "" FORCE) |
| 65 | + set(SuiteSparse_ENABLE_LAPACK ON CACHE BOOL "" FORCE) |
| 66 | + |
| 67 | + FetchContent_Declare( |
| 68 | + suitesparse |
| 69 | + GIT_REPOSITORY https://github.com/sergiud/SuiteSparse.git |
| 70 | + GIT_TAG cmake |
| 71 | + ) |
| 72 | + FetchContent_MakeAvailable(suitesparse) |
| 73 | +endif() |
0 commit comments