Make SuiteSparse partitioning detection more robust FindSuiteSparse skipped the METIS lookup if METIS_FOUND was defined. Other find modules, such as the one shipped by COLMAP, define this variable without providing the METIS::METIS target. The Partition component was then reported as missing even though CHOLMOD supports it. Search for METIS whenever its target is unavailable and report why a required Partition component is missing. Change-Id: I9cb66f34b79cb036c94b4b4448d3b4872944ee3d
diff --git a/cmake/FindSuiteSparse.cmake b/cmake/FindSuiteSparse.cmake index aa4086b..63bb387 100644 --- a/cmake/FindSuiteSparse.cmake +++ b/cmake/FindSuiteSparse.cmake
@@ -597,9 +597,12 @@ # NOTE If SuiteSparse was compiled as a static library we'll need to link # against METIS already during the check. Otherwise, the check can fail due to # undefined references even though SuiteSparse was compiled with METIS. - if (NOT DEFINED METIS_FOUND) + # + # Other METIS find modules may define METIS_FOUND without providing the + # METIS::METIS target required for linking. + if (NOT TARGET METIS::METIS) find_package (METIS) - endif() + endif (NOT TARGET METIS::METIS) if (TARGET METIS::METIS) cmake_push_check_state (RESET) @@ -607,6 +610,11 @@ check_symbol_exists (cholmod_metis cholmod.h SuiteSparse_CHOLMOD_USES_METIS) cmake_pop_check_state () + if (NOT SuiteSparse_CHOLMOD_USES_METIS AND SuiteSparse_FIND_REQUIRED_Partition) + list (APPEND CMAKE_FIND_PACKAGE_REASON + "Partition: CHOLMOD was not compiled with METIS support.") + endif (NOT SuiteSparse_CHOLMOD_USES_METIS AND SuiteSparse_FIND_REQUIRED_Partition) + if (SuiteSparse_CHOLMOD_USES_METIS) set_property (TARGET SuiteSparse::CHOLMOD APPEND PROPERTY INTERFACE_LINK_LIBRARIES $<LINK_ONLY:METIS::METIS>) @@ -620,6 +628,9 @@ set_property (TARGET SuiteSparse::Partition APPEND PROPERTY INTERFACE_LINK_LIBRARIES SuiteSparse::CHOLMOD) endif (SuiteSparse_CHOLMOD_USES_METIS) + elseif (SuiteSparse_FIND_REQUIRED_Partition) + list (APPEND CMAKE_FIND_PACKAGE_REASON + "Partition: METIS could not be found.") endif (TARGET METIS::METIS) endif (TARGET SuiteSparse::CHOLMOD)