From 2848e4f51424ad3a97c76400650f5974e4919662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=BCtzel?= Date: Thu, 19 Oct 2023 16:15:55 +0200 Subject: [PATCH] SPQR/SPQR_CUDA: Automatically check for dependencies when importing target --- SPQR/CMakeLists.txt | 4 ++-- SPQR/Config/SPQRConfig.cmake.in | 36 ++++++++++++++++++++++++++++ SPQR/Config/SPQR_CUDAConfig.cmake.in | 22 +++++++++++++++++ SPQR/SPQRGPU/CMakeLists.txt | 9 +++++++ 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/SPQR/CMakeLists.txt b/SPQR/CMakeLists.txt index c1f8f6fbe..a11705444 100644 --- a/SPQR/CMakeLists.txt +++ b/SPQR/CMakeLists.txt @@ -264,14 +264,14 @@ install ( EXPORT SPQRTargets DESTINATION ${SUITESPARSE_LIBDIR}/cmake/SPQR ) # generate config file to be used in common build tree -set ( SUITESPARSE_IN_BUILD_TREE on ) +set ( SUITESPARSE_IN_BUILD_TREE ON ) configure_package_config_file ( Config/SPQRConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/SPQRConfig.cmake INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/SPQRConfig.cmake ) # generate config file to be installed -set ( SUITESPARSE_IN_BUILD_TREE off ) +set ( SUITESPARSE_IN_BUILD_TREE OFF ) configure_package_config_file ( Config/SPQRConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/target/SPQRConfig.cmake diff --git a/SPQR/Config/SPQRConfig.cmake.in b/SPQR/Config/SPQRConfig.cmake.in index d75acac3d..7f73ad048 100644 --- a/SPQR/Config/SPQRConfig.cmake.in +++ b/SPQR/Config/SPQRConfig.cmake.in @@ -37,8 +37,44 @@ set ( SPQR_VERSION "@SPQR_VERSION_MAJOR@.@SPQR_VERSION_MINOR@.@SPQR_VERSION_SUB@ # Check for dependent targets include ( CMakeFindDependencyMacro ) + set ( _dependencies_found ON ) +# Look for SuiteSparse_config and CHOLMOD targets +if ( @SUITESPARSE_IN_BUILD_TREE@ ) + if ( NOT TARGET SuiteSparse::SuiteSparseConfig ) + # First check in a common build tree + find_dependency ( SuiteSparse_config @SUITESPARSE_CONFIG_VERSION_MAJOR@.@SUITESPARSE_CONFIG_VERSION_MINOR@ + PATHS ${CMAKE_SOURCE_DIR}/../SuiteSparse_config/build NO_DEFAULT_PATH ) + # Then, check in the currently active CMAKE_MODULE_PATH + if ( NOT SuiteSparse_config_FOUND ) + find_dependency ( SuiteSparse_config @SUITESPARSE_CONFIG_VERSION_MAJOR@.@SUITESPARSE_CONFIG_VERSION_MINOR@ ) + endif ( ) + endif ( ) + + if ( NOT TARGET SuiteSparse::CHOLMOD ) + # First check in a common build tree + find_dependency ( CHOLMOD @CHOLMOD_VERSION_MAJOR@.@CHOLMOD_VERSION_MINOR@ + PATHS ${CMAKE_SOURCE_DIR}/../CHOLMOD/build NO_DEFAULT_PATH ) + # Then, check in the currently active CMAKE_MODULE_PATH + if ( NOT CHOLMOD_FOUND ) + find_dependency ( CHOLMOD @CHOLMOD_VERSION_MAJOR@.@CHOLMOD_VERSION_MINOR@ ) + endif ( ) + endif ( ) + +else ( ) + if ( NOT TARGET SuiteSparse::SuiteSparseConfig ) + find_dependency ( SuiteSparse_config @SUITESPARSE_CONFIG_VERSION_MAJOR@.@SUITESPARSE_CONFIG_VERSION_MINOR@ ) + endif ( ) + if ( NOT TARGET SuiteSparse::CHOLMOD ) + find_dependency ( CHOLMOD @CHOLMOD_VERSION_MAJOR@.@CHOLMOD_VERSION_MINOR@ ) + endif ( ) +endif ( ) + +if ( NOT SuiteSparse_config_FOUND OR NOT CHOLMOD_FOUND ) + set ( _dependencies_found OFF ) +endif ( ) + if ( @SUITESPARSE_CUDA@ ) # Look for imported targets of additional dependency if SPQR was built with CUDA diff --git a/SPQR/Config/SPQR_CUDAConfig.cmake.in b/SPQR/Config/SPQR_CUDAConfig.cmake.in index 83297a234..99e431706 100644 --- a/SPQR/Config/SPQR_CUDAConfig.cmake.in +++ b/SPQR/Config/SPQR_CUDAConfig.cmake.in @@ -38,6 +38,28 @@ set ( SPQR_CUDA_VERSION "@SPQR_VERSION_MAJOR@.@SPQR_VERSION_MINOR@.@SPQR_VERSION include ( CMakeFindDependencyMacro ) set ( _dependencies_found ON ) +# Look for CHOLMOD target +if ( @SUITESPARSE_IN_BUILD_TREE@ ) + if ( NOT TARGET SuiteSparse::CHOLMOD ) + # First check in a common build tree + find_dependency ( CHOLMOD @CHOLMOD_VERSION_MAJOR@.@CHOLMOD_VERSION_MINOR@ + PATHS ${CMAKE_SOURCE_DIR}/../CHOLMOD/build NO_DEFAULT_PATH ) + # Then, check in the currently active CMAKE_MODULE_PATH + if ( NOT CHOLMOD_FOUND ) + find_dependency ( CHOLMOD @CHOLMOD_VERSION_MAJOR@.@CHOLMOD_VERSION_MINOR@ ) + endif ( ) + endif ( ) + +else ( ) + if ( NOT TARGET SuiteSparse::CHOLMOD ) + find_dependency ( CHOLMOD @CHOLMOD_VERSION_MAJOR@.@CHOLMOD_VERSION_MINOR@ ) + endif ( ) +endif ( ) + +if ( NOT CHOLMOD_FOUND ) + set ( _dependencies_found OFF ) +endif ( ) + # Look for NVIDIA CUDA toolkit if ( NOT CUDAToolkit_FOUND ) find_dependency ( CUDAToolkit @CUDAToolkit_VERSION_MAJOR@ ) diff --git a/SPQR/SPQRGPU/CMakeLists.txt b/SPQR/SPQRGPU/CMakeLists.txt index b63a4ef8a..f41e49be4 100644 --- a/SPQR/SPQRGPU/CMakeLists.txt +++ b/SPQR/SPQRGPU/CMakeLists.txt @@ -127,9 +127,18 @@ install ( EXPORT SPQR_CUDATargets NAMESPACE SuiteSparse:: DESTINATION ${SUITESPARSE_LIBDIR}/cmake/SPQR_CUDA ) +# generate config file to be used in common build tree +set ( SUITESPARSE_IN_BUILD_TREE ON ) configure_package_config_file ( ../Config/SPQR_CUDAConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/../SPQR_CUDAConfig.cmake + INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/../SPQR_CUDAConfig.cmake ) + +# generate config file to be installed +set ( SUITESPARSE_IN_BUILD_TREE OFF ) +configure_package_config_file ( + ../Config/SPQR_CUDAConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/../target/SPQR_CUDAConfig.cmake INSTALL_DESTINATION ${SUITESPARSE_LIBDIR}/cmake/SPQR_CUDA ) write_basic_package_version_file (