From e8b1b90920af27542638f14d3bfe4dc5bb64c847 Mon Sep 17 00:00:00 2001 From: Reinhold Gschweicher Date: Tue, 15 Jan 2019 10:14:48 +0100 Subject: [PATCH] hunter: prefer CXSparse from SuiteSparse Change-Id: I1cfd837d45e1c7edf4c8eaa4feea2c631517efcf --- CMakeLists.txt | 51 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 48cb10b948..efde031cee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -310,7 +310,48 @@ else (SUITESPARSE) endif (SUITESPARSE) # CXSparse. -if (CXSPARSE) +if (CXSPARSE AND TARGET SuiteSparse::cxsparse) + # use suitesparse provided cxsparse target + # Extract CXSparse version from cs.h + set(CXSPARSE_INCLUDE_DIR "${SuiteSparse_INCLUDE_DIRS}/suitesparse") + if (CXSPARSE_INCLUDE_DIR) + set(CXSPARSE_VERSION_FILE ${CXSPARSE_INCLUDE_DIR}/cs.h) + if (NOT EXISTS ${CXSPARSE_VERSION_FILE}) + message( + "Could not find file: ${CXSPARSE_VERSION_FILE} " + "containing version information in CXSparse install located at: " + "${CXSPARSE_INCLUDE_DIR}.") + else (NOT EXISTS ${CXSPARSE_VERSION_FILE}) + file(READ ${CXSPARSE_INCLUDE_DIR}/cs.h CXSPARSE_VERSION_FILE_CONTENTS) + + string(REGEX MATCH "#define CS_VER [0-9]+" + CXSPARSE_MAIN_VERSION "${CXSPARSE_VERSION_FILE_CONTENTS}") + string(REGEX REPLACE "#define CS_VER ([0-9]+)" "\\1" + CXSPARSE_MAIN_VERSION "${CXSPARSE_MAIN_VERSION}") + + string(REGEX MATCH "#define CS_SUBVER [0-9]+" + CXSPARSE_SUB_VERSION "${CXSPARSE_VERSION_FILE_CONTENTS}") + string(REGEX REPLACE "#define CS_SUBVER ([0-9]+)" "\\1" + CXSPARSE_SUB_VERSION "${CXSPARSE_SUB_VERSION}") + + string(REGEX MATCH "#define CS_SUBSUB [0-9]+" + CXSPARSE_SUBSUB_VERSION "${CXSPARSE_VERSION_FILE_CONTENTS}") + string(REGEX REPLACE "#define CS_SUBSUB ([0-9]+)" "\\1" + CXSPARSE_SUBSUB_VERSION "${CXSPARSE_SUBSUB_VERSION}") + + # This is on a single line s/t CMake does not interpret it as a list of + # elements and insert ';' separators which would result in 3.;1.;2 nonsense. + set(CXSPARSE_VERSION "${CXSPARSE_MAIN_VERSION}.${CXSPARSE_SUB_VERSION}.${CXSPARSE_SUBSUB_VERSION}") + endif (NOT EXISTS ${CXSPARSE_VERSION_FILE}) + endif (CXSPARSE_INCLUDE_DIR) + if (NOT CXSPARSE_VERSION) + set(CXSPARSE_VERSION ${SuiteSparse_VERSION}) + endif() + set(CXSPARSE_LIBRARIES SuiteSparse::cxsparse) + set(CXSPARSE_FOUND TRUE) + message("-- Using target SuiteSparse::cxsparse with version: ${CXSPARSE_VERSION}, " + "building with CXSparse.") +elseif (CXSPARSE) # Don't search with REQUIRED as we can continue without CXSparse. find_package(CXSparse) if (CXSPARSE_FOUND) @@ -324,7 +365,7 @@ if (CXSPARSE) update_cache_variable(CXSPARSE OFF) list(APPEND CERES_COMPILE_OPTIONS CERES_NO_CXSPARSE) endif (CXSPARSE_FOUND) -else (CXSPARSE) +else () message("-- Building without CXSparse.") list(APPEND CERES_COMPILE_OPTIONS CERES_NO_CXSPARSE) # Mark as advanced (remove from default GUI view) the CXSparse search @@ -333,7 +374,7 @@ else (CXSPARSE) # CXSPARSE instead of setting them. mark_as_advanced(FORCE CXSPARSE_INCLUDE_DIR CXSPARSE_LIBRARY) -endif (CXSPARSE) +endif () # Ensure that the user understands they have disabled all sparse libraries. if (NOT SUITESPARSE AND NOT CXSPARSE AND NOT EIGENSPARSE) @@ -597,10 +638,6 @@ include_directories( # as system headers. include_directories(SYSTEM ${EIGEN_INCLUDE_DIRS}) -if (CXSPARSE) - include_directories(${CXSPARSE_INCLUDE_DIRS}) -endif (CXSPARSE) - if (GFLAGS) include_directories(${GFLAGS_INCLUDE_DIRS}) endif (GFLAGS)