From 6b057e27c9032b9fbfb6d3e6b63daf47dc44b4eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=BCtzel?= Date: Tue, 12 Sep 2023 18:16:31 +0200 Subject: [PATCH 1/6] KLU: Don't link explicitly to CHOLMOD_CUDA. It is a transient target of CHOLMOD when needed. Also remove explicitly importing the CHOLMOD_CUDA target because it will already be found by importing the CHOLMOD target if needed. --- KLU/CMakeLists.txt | 8 -------- KLU/Config/KLU_CHOLMOD.pc.in | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/KLU/CMakeLists.txt b/KLU/CMakeLists.txt index 833e2e2fd..0142e24c8 100644 --- a/KLU/CMakeLists.txt +++ b/KLU/CMakeLists.txt @@ -86,14 +86,6 @@ if ( NOT NCHOLMOD ) find_package ( CHOLMOD 4.2.0 ) endif ( ) - if ( SUITESPARSE_CUDA ) - find_package ( CHOLMOD_CUDA 4.2.0 - PATHS ${CMAKE_SOURCE_DIR}/../CHOLMOD/build NO_DEFAULT_PATH ) - if ( NOT TARGET SuiteSparse::CHOLMOD_CUDA ) - find_package ( CHOLMOD_CUDA 4.2.0 ) - endif ( ) - endif ( ) - # look for CHOLMOD's dependencies: AMD and COLAMD are required. CAMD and # CCOLAMD are optional, but must be found if CHOLMOD was built with them. find_package ( CAMD 3.2.0 diff --git a/KLU/Config/KLU_CHOLMOD.pc.in b/KLU/Config/KLU_CHOLMOD.pc.in index a0db411bb..0c3dcb81e 100644 --- a/KLU/Config/KLU_CHOLMOD.pc.in +++ b/KLU/Config/KLU_CHOLMOD.pc.in @@ -11,6 +11,6 @@ Name: KLU_CHOLMOD URL: https://github.com/DrTimothyAldenDavis/SuiteSparse Description: Routines for sample ordering for KLU in SuiteSparse Version: @KLU_VERSION_MAJOR@.@KLU_VERSION_MINOR@.@KLU_VERSION_SUB@ -Requires.private: KLU BTF CHOLMOD CHOLMOD_CUDA +Requires.private: KLU BTF CHOLMOD Libs: -L${libdir} -lklu_cholmod Cflags: -I${includedir} From 2838aa0f2b3c5da3bbd210d8ac2d87a4dc77cf69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=BCtzel?= Date: Tue, 12 Sep 2023 18:24:27 +0200 Subject: [PATCH 2/6] UMFPACK: Don't link explicitly to CHOLMOD_CUDA. It is a transient target of CHOLMOD when needed. Also remove explicitly importing the CHOLMOD_CUDA target because it will already be found by importing the CHOLMOD target if needed. --- UMFPACK/CMakeLists.txt | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/UMFPACK/CMakeLists.txt b/UMFPACK/CMakeLists.txt index 359822f05..4c0e52850 100644 --- a/UMFPACK/CMakeLists.txt +++ b/UMFPACK/CMakeLists.txt @@ -83,14 +83,6 @@ if ( NOT NCHOLMOD ) find_package ( CHOLMOD 4.2.0 ) endif ( ) - if ( SUITESPARSE_CUDA ) - find_package ( CHOLMOD_CUDA 4.2.0 - PATHS ${CMAKE_SOURCE_DIR}/../CHOLMOD/build NO_DEFAULT_PATH ) - if ( NOT TARGET SuiteSparse::CHOLMOD_CUDA ) - find_package ( CHOLMOD_CUDA 4.2.0 ) - endif ( ) - endif ( ) - # look for CHOLMOD's dependencies: AMD and COLAMD are required. CAMD and # CCOLAMD are optional, but must be found if CHOLMOD was built with them. find_package ( COLAMD 3.2.0 @@ -255,13 +247,9 @@ include_directories ( ${BLAS_INCLUDE_DIRS} ) # CHOLMOD: if ( NOT NCHOLMOD ) # link with CHOLMOD and its dependencies, both required and optional - message ( STATUS "CHOLMOD cuda libraries: " ${CHOLMOD_CUDA_LIBRARIES} ) - target_link_libraries ( UMFPACK PRIVATE - SuiteSparse::CHOLMOD ${CHOLMOD_CUDA_LIBRARIES} ) + target_link_libraries ( UMFPACK PRIVATE SuiteSparse::CHOLMOD ) if ( NOT NSTATIC ) - set ( UMFPACK_STATIC_MODULES "${UMFPACK_STATIC_MODULES} CHOLMOD CHOLMOD_CUDA" ) - target_link_libraries ( UMFPACK_static PUBLIC - ${CHOLMOD_CUDA_STATIC} ) + set ( UMFPACK_STATIC_MODULES "${UMFPACK_STATIC_MODULES} CHOLMOD" ) if ( TARGET SuiteSparse::CHOLMOD_static ) target_link_libraries ( UMFPACK_static PUBLIC SuiteSparse::CHOLMOD_static ) else ( ) From 006c81ed5291fd71fcef77feda8158dcc5d3258a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=BCtzel?= Date: Tue, 12 Sep 2023 19:09:48 +0200 Subject: [PATCH 3/6] CI: Keep ccache for compilation with and without OpenMP separate --- .github/workflows/build.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index d70ad2861..54de7ca06 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -562,7 +562,7 @@ jobs: shell: msys2 {0} run: | echo "ccachedir=$(cygpath -m $(${CCACHE} -k cache_dir))" >> $GITHUB_OUTPUT - echo "key=ccache:msvc:${{ github.ref }}:$(date +"%Y-%m-%d_%H-%M-%S"):${{ github.sha }}" >> $GITHUB_OUTPUT + echo "key=ccache:msvc:${{ matrix.openmp }}:${{ github.ref }}:$(date +"%Y-%m-%d_%H-%M-%S"):${{ github.sha }}" >> $GITHUB_OUTPUT - name: restore ccache # Setup the GitHub cache used to maintain the ccache from one job to the next @@ -572,8 +572,8 @@ jobs: key: ${{ steps.ccache-prepare.outputs.key }} # Prefer caches from the same branch. Fall back to caches from the dev branch. restore-keys: | - ccache:msvc:${{ github.ref }} - ccache:msvc + ccache:msvc:${{ matrix.openmp }}:${{ github.ref }} + ccache:msvc:${{ matrix.openmp }} - name: configure ccache # Limit the maximum size and switch on compression to avoid exceeding the total disk or cache quota. From 5f80bb7aac756bea16738dfab778052f22f6c39f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=BCtzel?= Date: Tue, 12 Sep 2023 19:51:41 +0200 Subject: [PATCH 4/6] CHOLMOD: Add CHOLMOD_CUDA to dependencies in .pc file if needed --- CHOLMOD/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHOLMOD/CMakeLists.txt b/CHOLMOD/CMakeLists.txt index 7644a2c46..dd1307c51 100644 --- a/CHOLMOD/CMakeLists.txt +++ b/CHOLMOD/CMakeLists.txt @@ -474,8 +474,8 @@ endif ( ) # CHOLMOD_CUDA if ( SUITESPARSE_CUDA ) - message ( STATUS "CHOLMOD cuda: " ${CHOLMOD_CUDA} ) target_link_libraries ( CHOLMOD PRIVATE CHOLMOD_CUDA ${CUDA_LIBRARIES} ) + set ( CHOLMOD_STATIC_MODULES " ${CHOLMOD_STATIC_MODULES} CHOLMOD_CUDA" ) if ( NOT NSTATIC ) target_link_libraries ( CHOLMOD_static PUBLIC CHOLMOD_CUDA_static ${CUDA_LIBRARIES} ) endif ( ) From 999af9fce89a73c450a1d909002520752a81db66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=BCtzel?= Date: Tue, 12 Sep 2023 20:13:11 +0200 Subject: [PATCH 5/6] CHOLMOD: Add definition of SUITESPARSE_CUDA to CMake target and .pc file Same for CHOLMOD_CUDA. --- CHOLMOD/CMakeLists.txt | 5 ++++- CHOLMOD/Config/CHOLMOD.pc.in | 4 +++- CHOLMOD/Config/CHOLMOD_CUDA.pc.in | 2 +- CHOLMOD/GPU/CMakeLists.txt | 8 +++++--- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHOLMOD/CMakeLists.txt b/CHOLMOD/CMakeLists.txt index dd1307c51..eea8f4ad2 100644 --- a/CHOLMOD/CMakeLists.txt +++ b/CHOLMOD/CMakeLists.txt @@ -475,9 +475,12 @@ endif ( ) # CHOLMOD_CUDA if ( SUITESPARSE_CUDA ) target_link_libraries ( CHOLMOD PRIVATE CHOLMOD_CUDA ${CUDA_LIBRARIES} ) - set ( CHOLMOD_STATIC_MODULES " ${CHOLMOD_STATIC_MODULES} CHOLMOD_CUDA" ) + set ( CHOLMOD_STATIC_MODULES "${CHOLMOD_STATIC_MODULES} CHOLMOD_CUDA" ) + set ( CHOLMOD_CFLAGS "${CHOLMOD_CFLAGS} -DSUITESPARSE_CUDA" ) + target_compile_definitions ( CHOLMOD PUBLIC "SUITESPARSE_CUDA" ) if ( NOT NSTATIC ) target_link_libraries ( CHOLMOD_static PUBLIC CHOLMOD_CUDA_static ${CUDA_LIBRARIES} ) + target_compile_definitions ( CHOLMOD_static PUBLIC "SUITESPARSE_CUDA" ) endif ( ) target_link_libraries ( CHOLMOD PRIVATE CUDA::nvrtc CUDA::cudart_static CUDA::nvToolsExt CUDA::cublas ) diff --git a/CHOLMOD/Config/CHOLMOD.pc.in b/CHOLMOD/Config/CHOLMOD.pc.in index 7c079cbfe..1620ba35d 100644 --- a/CHOLMOD/Config/CHOLMOD.pc.in +++ b/CHOLMOD/Config/CHOLMOD.pc.in @@ -7,6 +7,8 @@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ +# FIXME: Which flags do we need to statically link CUDA if needed? + Name: CHOLMOD URL: https://github.com/DrTimothyAldenDavis/SuiteSparse Description: Routines for factorizing sparse symmetric positive definite matrices in SuiteSparse @@ -14,4 +16,4 @@ Version: @CHOLMOD_VERSION_MAJOR@.@CHOLMOD_VERSION_MINOR@.@CHOLMOD_VERSION_SUB@ Requires.private: SuiteSparse_config AMD COLAMD @CHOLMOD_STATIC_MODULES@ Libs: -L${libdir} -lcholmod Libs.private: @CHOLMOD_STATIC_LIBS@ -Cflags: -I${includedir} +Cflags: -I${includedir} @CHOLMOD_CFLAGS@ diff --git a/CHOLMOD/Config/CHOLMOD_CUDA.pc.in b/CHOLMOD/Config/CHOLMOD_CUDA.pc.in index 1c48f12ca..552f784ce 100644 --- a/CHOLMOD/Config/CHOLMOD_CUDA.pc.in +++ b/CHOLMOD/Config/CHOLMOD_CUDA.pc.in @@ -14,4 +14,4 @@ URL: https://github.com/DrTimothyAldenDavis/SuiteSparse Description: CHOLMOD/GPU module in SuiteSparse Version: @CHOLMOD_VERSION_MAJOR@.@CHOLMOD_VERSION_MINOR@.@CHOLMOD_VERSION_SUB@ Libs: -L${libdir} -lcholmod_cuda -Cflags: -I${includedir} +Cflags: -I${includedir} -DSUITESPARSE_CUDA diff --git a/CHOLMOD/GPU/CMakeLists.txt b/CHOLMOD/GPU/CMakeLists.txt index 2a009b499..f0194e978 100644 --- a/CHOLMOD/GPU/CMakeLists.txt +++ b/CHOLMOD/GPU/CMakeLists.txt @@ -75,13 +75,15 @@ target_include_directories ( CHOLMOD_CUDA PRIVATE ${CHOLMOD_CUDA_INCLUDES} ) set_target_properties ( CHOLMOD_CUDA PROPERTIES POSITION_INDEPENDENT_CODE ON ) set_target_properties ( CHOLMOD_CUDA PROPERTIES CUDA_SEPARABLE_COMPILATION ON ) +target_compile_definitions ( CHOLMOD_CUDA PUBLIC "SUITESPARSE_CUDA" ) if ( NOT NSTATIC ) -target_include_directories ( CHOLMOD_CUDA_static PRIVATE + target_include_directories ( CHOLMOD_CUDA_static PRIVATE ${CUDAToolkit_INCLUDE_DIRS} ${CHOLMOD_CUDA_INCLUDES} ) -set_target_properties ( CHOLMOD_CUDA_static PROPERTIES CUDA_SEPARABLE_COMPILATION on ) -set_target_properties ( CHOLMOD_CUDA_static PROPERTIES POSITION_INDEPENDENT_CODE on ) + set_target_properties ( CHOLMOD_CUDA_static PROPERTIES CUDA_SEPARABLE_COMPILATION on ) + set_target_properties ( CHOLMOD_CUDA_static PROPERTIES POSITION_INDEPENDENT_CODE on ) + target_compile_definitions ( CHOLMOD_CUDA_static PUBLIC "SUITESPARSE_CUDA" ) endif ( ) target_link_libraries ( CHOLMOD_CUDA PRIVATE CUDA::nvrtc CUDA::cudart_static From 833a22aa3538cd7a2eafcb20f5d5cb7f97a893ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=BCtzel?= Date: Tue, 12 Sep 2023 20:51:25 +0200 Subject: [PATCH 6/6] GraphBLAS: Export CMake target for GraphBLAS_CUDA. --- GraphBLAS/CMakeLists.txt | 6 +- GraphBLAS/CUDA/CMakeLists.txt | 53 ++++++-- .../CUDA/Config/GraphBLAS_CUDAConfig.cmake.in | 121 ++++++++++++++++++ 3 files changed, 166 insertions(+), 14 deletions(-) create mode 100644 GraphBLAS/CUDA/Config/GraphBLAS_CUDAConfig.cmake.in diff --git a/GraphBLAS/CMakeLists.txt b/GraphBLAS/CMakeLists.txt index 8a6b7ddcf..2f60eb024 100644 --- a/GraphBLAS/CMakeLists.txt +++ b/GraphBLAS/CMakeLists.txt @@ -63,7 +63,7 @@ if ( SUITESPARSE_CUDA ) # with CUDA and RMM set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSUITESPARSE_CUDA" ) add_subdirectory ( CUDA ) - set ( GB_CUDA graphblascuda ${CUDA_LIBRARIES} ) + set ( GB_CUDA GraphBLAS_CUDA ${CUDA_LIBRARIES} ) set ( GB_RMM rmm_wrap ${CUDA_LIBRARIES} ) add_subdirectory ( rmm_wrap ) include_directories ( "rmm_wrap" ${CUDA_INCLUDE_DIRS} @@ -245,7 +245,7 @@ target_include_directories ( GraphBLAS $ ) if ( SUITESPARSE_CUDA ) - add_dependencies ( GraphBLAS graphblascuda ) + add_dependencies ( GraphBLAS GraphBLAS_CUDA ) # add_dependencies ( GraphBLAS rmm_wrap ) endif ( ) @@ -279,7 +279,7 @@ if ( NOT NSTATIC ) $ ) if ( SUITESPARSE_CUDA ) - add_dependencies ( GraphBLAS_static graphblascuda ) + add_dependencies ( GraphBLAS_static GraphBLAS_CUDA ) # add_dependencies ( GraphBLAS_static rmm_wrap ) endif ( ) endif ( ) diff --git a/GraphBLAS/CUDA/CMakeLists.txt b/GraphBLAS/CUDA/CMakeLists.txt index 1195a9e0c..41a5c5cb4 100644 --- a/GraphBLAS/CUDA/CMakeLists.txt +++ b/GraphBLAS/CUDA/CMakeLists.txt @@ -34,9 +34,9 @@ message ( STATUS "C++ flags for CUDA: ${CMAKE_CXX_FLAGS}" ) file ( GLOB GRAPHBLAS_CUDA_SOURCES "*.cu" "*.c" "*.cpp" ) -add_library ( graphblascuda SHARED ${GRAPHBLAS_CUDA_SOURCES} ) +add_library ( GraphBLAS_CUDA SHARED ${GRAPHBLAS_CUDA_SOURCES} ) -set_target_properties ( graphblascuda PROPERTIES +set_target_properties ( GraphBLAS_CUDA PROPERTIES VERSION ${GraphBLAS_VERSION_MAJOR}.${GraphBLAS_VERSION_MINOR}.${GraphBLAS_VERSION_SUB} SOVERSION ${GraphBLAS_VERSION_MAJOR} C_STANDARD 11 @@ -59,29 +59,60 @@ set ( GRAPHBLAS_CUDA_INCLUDES message ( STATUS "GraphBLAS CUDA includes: ${GRAPHBLAS_CUDA_INCLUDES}" ) #------------------------------------------------------------------------------- -# graphblascuda properties +# GraphBLAS_CUDA properties #------------------------------------------------------------------------------- -target_include_directories(graphblascuda PUBLIC +target_include_directories(GraphBLAS_CUDA PRIVATE ${CUDAToolkit_INCLUDE_DIRS} ${GRAPHBLAS_CUDA_INCLUDES}) -set_target_properties(graphblascuda PROPERTIES POSITION_INDEPENDENT_CODE ON) -set_target_properties(graphblascuda PROPERTIES CUDA_SEPARABLE_COMPILATION ON) +set_target_properties(GraphBLAS_CUDA PROPERTIES POSITION_INDEPENDENT_CODE ON) +set_target_properties(GraphBLAS_CUDA PROPERTIES CUDA_SEPARABLE_COMPILATION ON) # FIXME: use SUITESPARSE_CUDA_ARCHITECTURES -set_target_properties(graphblascuda PROPERTIES CUDA_ARCHITECTURES "52;75;80" ) +set_target_properties(GraphBLAS_CUDA PROPERTIES CUDA_ARCHITECTURES "52;75;80" ) -target_link_libraries(graphblascuda CUDA::nvrtc CUDA::cudart_static CUDA::cuda_driver CUDA::nvToolsExt ) +target_link_libraries(GraphBLAS_CUDA CUDA::nvrtc CUDA::cudart_static CUDA::cuda_driver CUDA::nvToolsExt ) + +target_include_directories ( GraphBLAS_CUDA + INTERFACE $ + $ ) #------------------------------------------------------------------------------- # installation location #------------------------------------------------------------------------------- -install ( TARGETS graphblascuda +include ( CMakePackageConfigHelpers ) + +install ( TARGETS GraphBLAS_CUDA + EXPORT GraphBLAS_CUDATargets LIBRARY DESTINATION ${SUITESPARSE_LIBDIR} ARCHIVE DESTINATION ${SUITESPARSE_LIBDIR} RUNTIME DESTINATION ${SUITESPARSE_BINDIR} PUBLIC_HEADER DESTINATION ${SUITESPARSE_INCLUDEDIR} ) +# create (temporary) export target file during build +export ( EXPORT GraphBLAS_CUDATargets + NAMESPACE SuiteSparse:: + FILE ${CMAKE_CURRENT_BINARY_DIR}/GraphBLAS_CUDATargets.cmake ) + +# install export target and config for find_package +install ( EXPORT GraphBLAS_CUDATargets + NAMESPACE SuiteSparse:: + DESTINATION ${SUITESPARSE_LIBDIR}/cmake/GraphBLAS ) + +configure_package_config_file ( + Config/GraphBLAS_CUDAConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/GraphBLAS_CUDAConfig.cmake + INSTALL_DESTINATION ${SUITESPARSE_LIBDIR}/cmake/GraphBLAS ) + +write_basic_package_version_file ( + ${CMAKE_CURRENT_BINARY_DIR}/GraphBLAS_CUDAConfigVersion.cmake + COMPATIBILITY SameMajorVersion ) + +install ( FILES + ${CMAKE_CURRENT_BINARY_DIR}/GraphBLAS_CUDAConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/GraphBLAS_CUDAConfigVersion.cmake + DESTINATION ${SUITESPARSE_LIBDIR}/cmake/GraphBLAS ) + #------------------------------------------------------------------------------- # test suite for the CUDA kernels #------------------------------------------------------------------------------- @@ -181,14 +212,14 @@ set_target_properties(graphblascuda_test PROPERTIES CUDA_ARCHITECTURES "52;75;80 include(GoogleTest) add_dependencies(graphblascuda_test GraphBLAS) -add_dependencies(graphblascuda_test graphblascuda) +add_dependencies(graphblascuda_test GraphBLAS_CUDA) add_dependencies(graphblascuda_test gtest_main) add_dependencies(graphblascuda_test rmm_wrap) target_link_libraries(graphblascuda_test PUBLIC GraphBLAS - graphblascuda + GraphBLAS_CUDA rmm_wrap CUDA::cudart_static CUDA::nvrtc diff --git a/GraphBLAS/CUDA/Config/GraphBLAS_CUDAConfig.cmake.in b/GraphBLAS/CUDA/Config/GraphBLAS_CUDAConfig.cmake.in new file mode 100644 index 000000000..a3a24151f --- /dev/null +++ b/GraphBLAS/CUDA/Config/GraphBLAS_CUDAConfig.cmake.in @@ -0,0 +1,121 @@ +#------------------------------------------------------------------------------- +# SuiteSparse/GraphBLAS/cmake_modules/GraphBLASConfig.cmake +#------------------------------------------------------------------------------- + +# The following copyright and license applies to just this file only, not to +# the library itself: +# GraphBLASConfig.cmake, Copyright (c) 2023, Timothy A. Davis. All Rights Reserved. +# SPDX-License-Identifier: BSD-3-clause + +#------------------------------------------------------------------------------- + +# Finds the GraphBLAS_CUDA include file and compiled library. +# The following targets are defined: +# SuiteSparse::GRAPHBLAS_CUDA - for the shared library (if available) +# SuiteSparse::GRAPHBLAS_CUDA_static - for the static library (if available) + +# For backward compatibility the following variables are set: + +# GRAPHBLAS_CUDA_INCLUDE_DIR - where to find GraphBLAS.h, etc. +# GRAPHBLAS_CUDA_LIBRARY - dynamic GraphBLAS library +# GRAPHBLAS_CUDA_STATIC - static GraphBLAS library +# GRAPHBLAS_CUDA_LIBRARIES - libraries when using GraphBLAS +# GRAPHBLAS_CUDA_FOUND - true if GraphBLAS found + +# Set ``CMAKE_MODULE_PATH`` to the parent folder where this module file is +# installed. + +#------------------------------------------------------------------------------- + +@PACKAGE_INIT@ + +set ( GRAPHBLAS_CUDA_DATE "@GraphBLAS_DATE@" ) +set ( GRAPHBLAS_CUDA_VERSION_MAJOR @GraphBLAS_VERSION_MAJOR@ ) +set ( GRAPHBLAS_CUDA_VERSION_MINOR @GraphBLAS_VERSION_MINOR@ ) +set ( GRAPHBLAS_CUDA_VERSION_PATCH @GraphBLAS_VERSION_SUB@ ) +set ( GRAPHBLAS_CUDA_VERSION "@GraphBLAS_VERSION_MAJOR@.@GraphBLAS_VERSION_MINOR@.@GraphBLAS_VERSION_SUB@" ) + +include ( ${CMAKE_CURRENT_LIST_DIR}/GraphBLAS_CUDATargets.cmake ) + +# The following is only for backward compatibility with FindGraphBLAS_CUDA. + +set ( _target_shared SuiteSparse::GraphBLAS_CUDA ) +set ( _target_static SuiteSparse::GraphBLAS_CUDA_static ) +set ( _var_prefix "GRAPHBLAS_CUDA" ) + +get_target_property ( ${_var_prefix}_INCLUDE_DIR ${_target_shared} INTERFACE_INCLUDE_DIRECTORIES ) +if ( ${_var_prefix}_INCLUDE_DIR ) + # First item in SuiteSparse targets contains the "main" header directory. + list ( GET ${_var_prefix}_INCLUDE_DIR 0 ${_var_prefix}_INCLUDE_DIR ) +endif ( ) +get_target_property ( ${_var_prefix}_LIBRARY ${_target_shared} IMPORTED_IMPLIB ) +if ( NOT ${_var_prefix}_LIBRARY ) + get_target_property ( _library_chk ${_target_shared} IMPORTED_LOCATION ) + if ( EXISTS ${_library_chk} ) + set ( ${_var_prefix}_LIBRARY ${_library_chk} ) + endif ( ) +endif ( ) +if ( TARGET ${_target_static} ) + get_target_property ( ${_var_prefix}_STATIC ${_target_static} IMPORTED_LOCATION ) +endif ( ) + +# Check for most common build types +set ( _config_types "Debug" "Release" "RelWithDebInfo" "MinSizeRel" ) + +get_property ( _isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG ) +if ( _isMultiConfig ) + # For multi-configuration generators (e.g., Visual Studio), prefer those + # configurations. + list ( PREPEND _config_types ${CMAKE_CONFIGURATION_TYPES} ) +else ( ) + # For single-configuration generators, prefer the current configuration. + list ( PREPEND _config_types ${CMAKE_BUILD_TYPE} ) +endif ( ) + +list ( REMOVE_DUPLICATES _config_types ) + +foreach ( _config ${_config_types} ) + string ( TOUPPER ${_config} _uc_config ) + if ( NOT ${_var_prefix}_LIBRARY ) + get_target_property ( _library_chk ${_target_shared} + IMPORTED_IMPLIB_${_uc_config} ) + if ( EXISTS ${_library_chk} ) + set ( ${_var_prefix}_LIBRARY ${_library_chk} ) + endif ( ) + endif ( ) + if ( NOT ${_var_prefix}_LIBRARY ) + get_target_property ( _library_chk ${_target_shared} + IMPORTED_LOCATION_${_uc_config} ) + if ( EXISTS ${_library_chk} ) + set ( ${_var_prefix}_LIBRARY ${_library_chk} ) + endif ( ) + endif ( ) + if ( TARGET ${_target_static} AND NOT ${_var_prefix}_STATIC ) + get_target_property ( _library_chk ${_target_static} + IMPORTED_LOCATION_${_uc_config} ) + if ( EXISTS ${_library_chk} ) + set ( ${_var_prefix}_STATIC ${_library_chk} ) + endif ( ) + endif ( ) +endforeach ( ) + +set ( GRAPHBLAS_CUDA_LIBRARIES ${GRAPHBLAS_CUDA_LIBRARY} ) + +macro ( suitesparse_check_exist _var _files ) + # ignore generator expressions + string ( GENEX_STRIP "${_files}" _files2 ) + + foreach ( _file ${_files2} ) + if ( NOT EXISTS "${_file}" ) + message ( FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist!" ) + endif ( ) + endforeach () +endmacro ( ) + +suitesparse_check_exist ( GRAPHBLAS_CUDA_INCLUDE_DIR ${GRAPHBLAS_CUDA_INCLUDE_DIR} ) +suitesparse_check_exist ( GRAPHBLAS_CUDA_LIBRARY ${GRAPHBLAS_CUDA_LIBRARY} ) + +message ( STATUS "GraphBLAS_CUDA version: ${GRAPHBLAS_CUDA_VERSION}" ) +message ( STATUS "GraphBLAS_CUDA include: ${GRAPHBLAS_CUDA_INCLUDE_DIR}" ) +message ( STATUS "GraphBLAS_CUDA library: ${GRAPHBLAS_CUDA_LIBRARY}" ) +message ( STATUS "GraphBLAS_CUDA static: ${GRAPHBLAS_CUDA_STATIC}" )