diff --git a/cmake/modules/AddSuiteSparseFlags.cmake b/cmake/modules/AddSuiteSparseFlags.cmake new file mode 100644 index 0000000000000000000000000000000000000000..9a91beef542ced592ce7c232b678c6903f563bd2 --- /dev/null +++ b/cmake/modules/AddSuiteSparseFlags.cmake @@ -0,0 +1,23 @@ +# Defines the functions to use SuiteSparse +# +# .. cmake_function:: add_dune_suitesparse_flags +# +# .. cmake_param:: targets +# :positional: +# :single: +# :required: +# +# A list of targets to use SuiteSparse with. +# + +function(add_dune_suitesparse_flags _targets) + if(SUITESPARSE_FOUND) + foreach(_target ${_targets}) + target_link_libraries(${_target} ${SUITESPARSE_DUNE_LIBRARIES}) + get_target_property(_props ${_target} COMPILE_FLAGS) + string(REPLACE "_props-NOTFOUND" "" _props "${_props}") + set_target_properties(${_target} PROPERTIES COMPILE_FLAGS + "${_props} ${SUITESPARSE_DUNE_COMPILE_FLAGS} -DENABLE_SUITESPARSE=1") + endforeach(_target ${_targets}) + endif(SUITESPARSE_FOUND) +endfunction(add_dune_suitesparse_flags) diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt index e28366dfe5cef5a0d9156577ce1d800714410768..7554299f586690d18bbb44e3f0d6f209dcc5169f 100644 --- a/cmake/modules/CMakeLists.txt +++ b/cmake/modules/CMakeLists.txt @@ -3,6 +3,7 @@ install(FILES AddMETISFlags.cmake AddParMETISFlags.cmake AddPTScotchFlags.cmake + AddSuiteSparseFlags.cmake AddUMFPackFlags.cmake CheckCXXFeatures.cmake CheckForPthreads.c @@ -27,6 +28,7 @@ install(FILES FindParMETIS.cmake FindPTScotch.cmake FindSphinx.cmake + FindSuiteSparse.cmake FindThreadsCMake31.cmake FindUMFPack.cmake Headercheck.cmake diff --git a/cmake/modules/FindSuiteSparse.cmake b/cmake/modules/FindSuiteSparse.cmake new file mode 100644 index 0000000000000000000000000000000000000000..7012ab4b1fa269745eca0addc06a7f32a2fbdd14 --- /dev/null +++ b/cmake/modules/FindSuiteSparse.cmake @@ -0,0 +1,246 @@ +# .. cmake_module:: +# +# Find the SuiteSparse libraries like UMFPACK or SPQR. +# +# Example which tries to find Suite Sparse's UMFPack component: +# +# :code:`find_package(SuiteSparse OPTIONAL_COMPONENTS UMFPACK)` +# +# `OPTIONAL_COMPONENTS` +# A list of components. Components are: +# AMD, BTF, CAMD, CCOLAMD, CHOLMOD, COLAMD, CXSPARSE, +# KLU, LDL, RBIO, SPQR, UMFPACK +# +# :ref:`SuiteSparse_ROOT` +# Path list to search for SuiteSparse +# +# Sets the following variables: +# +# :code:`SuiteSparse_FOUND` +# True if SuiteSparse was found. +# +# :code:`SuiteSparse_INCLUDE_DIRS` +# Path to the SuiteSparse include dirs. +# +# :code:`SuiteSparse_LIBRARIES` +# Name of the SuiteSparse libraries. +# +# :code:`SuiteSparse_<COMPONENT>_FOUND` +# Whether <COMPONENT> was found as part of SuiteSparse. +# +# .. cmake_variable:: SuiteSparse_ROOT +# +# You may set this variable to have :ref:`FindSuiteSparse` look +# for SuiteSparse in the given path before inspecting +# system paths. +# + +find_package(BLAS QUIET) + +# look for desired componenents +set(SUITESPARSE_COMPONENTS ${SuiteSparse_FIND_COMPONENTS}) + +# resolve inter-component dependencies +list(FIND SUITESPARSE_COMPONENTS "UMFPACK" WILL_USE_UMFPACK) +if(NOT WILL_USE_UMFPACK EQUAL -1) + list(APPEND SUITESPARSE_COMPONENTS AMD CHOLMOD) +endif() +list(FIND SUITESPARSE_COMPONENTS "CHOLMOD" WILL_USE_CHOLMOD) +if(NOT WILL_USE_CHOLMOD EQUAL -1) + list(APPEND SUITESPARSE_COMPONENTS AMD CAMD COLAMD CCOLAMD) +endif() + +if(SUITESPARSE_COMPONENTS) + list(REMOVE_DUPLICATES SUITESPARSE_COMPONENTS) +endif() + +# find SuiteSparse config: +# look for library at positions given by the user +find_library(SUITESPARSE_CONFIG_LIB + NAMES "suitesparseconfig" + PATHS ${SuiteSparse_ROOT} + PATH_SUFFIXES "lib" "lib32" "lib64" "Lib" + NO_DEFAULT_PATH +) +# now also include the deafult paths +find_library(SUITESPARSE_CONFIG_LIB + NAMES "suitesparseconfig" + PATH_SUFFIXES "lib" "lib32" "lib64" "Lib" +) + +#look for header files at positions given by the user +find_path(SUITESPARSE_INCLUDE_DIR + NAMES "SuiteSparse_config.h" + PATHS ${SuiteSparse_ROOT} + PATH_SUFFIXES "SuiteSparse_config" "SuiteSparse_config/include" "suitesparse" "include" "src" "SuiteSparse_config/Include" + NO_DEFAULT_PATH +) +#now also look for default paths +find_path(SUITESPARSE_INCLUDE_DIR + NAMES "SuiteSparse_config.h" + PATH_SUFFIXES "SuiteSparse_config" "SuiteSparse_config/include" "suitesparse" "include" "src" "SuiteSparse_config/Include" +) + +foreach(_component ${SUITESPARSE_COMPONENTS}) + string(TOLOWER ${_component} _componentLower) + + #look for library at positions given by the user + find_library(${_component}_LIBRARY + NAMES "${_componentLower}" + PATHS ${SuiteSparse_ROOT} + PATH_SUFFIXES "lib" "lib32" "lib64" "${_component}" "${_component}/Lib" + NO_DEFAULT_PATH + ) + #now also include the deafult paths + find_library(${_component}_LIBRARY + NAMES "${_componentLower}" + PATH_SUFFIXES "lib" "lib32" "lib64" "${_component}" "${_component}/Lib" + ) + + #look for header files at positions given by the user + find_path(${_component}_INCLUDE_DIR + NAMES "${_componentLower}.h" + PATHS ${SuiteSparse_ROOT} + PATH_SUFFIXES "${_componentLower}" "include/${_componentLower}" "suitesparse" "include" "src" "${_component}" "${_component}/Include" + NO_DEFAULT_PATH + ) + #now also look for default paths + find_path(${_component}_INCLUDE_DIR + NAMES "${_componentLower}.h" + PATH_SUFFIXES "${_componentLower}" "include/${_componentLower}" "suitesparse" "include" "${_component}" "${_component}/Include" + ) +endforeach() + +# SPQR has different header file name SuiteSparseQR.hpp +#look for header files at positions given by the user +find_path(SPQR_INCLUDE_DIR + NAMES "SuiteSparseQR.hpp" + PATHS ${SuiteSparse_ROOT} + PATH_SUFFIXES "spqr" "include/spqr" "suitesparse" "include" "src" "SPQR" "SPQR/Include" + NO_DEFAULT_PATH +) +#now also look for default paths +find_path(SPQR_INCLUDE_DIR + NAMES "SuiteSparseQR.hpp" + PATH_SUFFIXES "spqr" "include/spqr" "suitesparse" "include" "SPQR" "SPQR/Include" +) + +# resolve inter-modular dependencies + +# CHOLMOD requires AMD, COLAMD; CAMD and CCOLAMD are optional +if(CHOLMOD_LIBRARY) + if(NOT (AMD_LIBRARY AND COLAMD_LIBRARY)) + message(WARNING "CHOLMOD requires AMD and COLAMD which were not found, skipping the test.") + set(SuiteSparse_CHOLMOD_FOUND "CHOLMOD requires AMD and COLAMD-NOTFOUND") + endif() + + list(APPEND CHOLMOD_LIBRARY ${AMD_LIBRARY} ${COLAMD_LIBRARY}) + if(CAMD_LIBRARY) + list(APPEND CHOLMOD_LIBRARY ${CAMD_LIBRARY}) + endif() + if(CCOLAMD_LIBRARY) + list(APPEND CHOLMOD_LIBRARY ${CCOLAMD_LIBRARY}) + endif() + list(REVERSE CHOLMOD_LIBRARY) + # remove duplicates + list(REMOVE_DUPLICATES CHOLMOD_LIBRARY) + list(REVERSE CHOLMOD_LIBRARY) +endif() + +# UMFPack requires AMD, can depend on CHOLMOD +if(UMFPACK_LIBRARY) + # check wether cholmod was found + if(CHOLMOD_LIBRARY) + list(APPEND UMFPACK_LIBRARY ${CHOLMOD_LIBRARY}) + else() + list(APPEND UMFPACK_LIBRARY ${AMD_LIBRARY}) + endif() + list(REVERSE UMFPACK_LIBRARY) + # remove duplicates + list(REMOVE_DUPLICATES UMFPACK_LIBRARY) + list(REVERSE UMFPACK_LIBRARY) +endif() + +# check wether everything was found +foreach(_component ${SUITESPARSE_COMPONENTS}) + # variable used for component handling + set(SuiteSparse_${_component}_FOUND (${_component}_LIBRARY AND ${_component}_INCLUDE_DIR)) + set(HAVE_SUITESPARSE_${_component} SuiteSparse_${_component}_FOUND) + if(SuiteSparse_${_component}_FOUND) + list(APPEND SUITESPARSE_INCLUDE_DIR "${${_component}_INCLUDE_DIR}") + list(APPEND SUITESPARSE_LIBRARY "${${_component}_LIBRARY}") + endif() + + mark_as_advanced( + HAVE_SUITESPARSE_${_component} + SuiteSparse_${_component}_FOUND + ${_component}_INCLUDE_DIR + ${_component}_LIBRARY) +endforeach() + +list(APPEND SUITESPARSE_LIBRARY ${SUITESPARSE_CONFIG_LIB}) + +# make them unique +if(SUITESPARSE_INCLUDE_DIR) + list(REMOVE_DUPLICATES SUITESPARSE_INCLUDE_DIR) +endif() +if(SUITESPARSE_LIBRARY) + list(REVERSE SUITESPARSE_LIBRARY) + list(REMOVE_DUPLICATES SUITESPARSE_LIBRARY) + list(REVERSE SUITESPARSE_LIBRARY) +endif() + +# behave like a CMake module is supposed to behave +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + "SuiteSparse" + FOUND_VAR SuiteSparse_FOUND + REQUIRED_VARS + BLAS_FOUND + SUITESPARSE_INCLUDE_DIR + SUITESPARSE_LIBRARY + HANDLE_COMPONENTS +) + +mark_as_advanced( + SUITESPARSE_INCLUDE_DIR + SUITESPARSE_LIBRARY + SUITESPARSE_CONFIG_LIB + WILL_USE_CHOLMOD + WILL_USE_UMFPACK) + +# if both headers and library are found, store results +if(SuiteSparse_FOUND) + set(SuiteSparse_LIBRARIES ${SUITESPARSE_LIBRARY}) + set(SuiteSparse_INCLUDE_DIRS ${SUITESPARSE_INCLUDE_DIR}) + # log result + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining location of SuiteSparse succeded:\n" + "Include directory: ${SuiteSparse_INCLUDE_DIRS}\n" + "Library directory: ${SuiteSparse_LIBRARIES}\n\n") + set(SuiteSparse_COMPILER_FLAGS) + foreach(dir ${SuiteSparse_INCLUDE_DIRS}) + set(SuiteSparse_COMPILER_FLAGS "${SuiteSparse_COMPILER_FLAGS} -I${dir}/") + endforeach() + set(SuiteSparse_DUNE_COMPILE_FLAGS ${SuiteSparse_COMPILER_FLAGS} + CACHE STRING "Compile Flags used by DUNE when compiling with SuiteSparse programs") + set(SuiteSparse_DUNE_LIBRARIES ${BLAS_LIBRARIES} ${SuiteSparse_LIBRARIES} + CACHE STRING "Libraries used by DUNE when linking SuiteSparse programs") +else() + # log errornous result + file(APPEND ${CMAKE_BINARY_DIR}${CMAKES_FILES_DIRECTORY}/CMakeError.log + "Determing location of SuiteSparse failed:\n" + "Include directory: ${SuiteSparse_INCLUDE_DIRS}\n" + "Library directory: ${SuiteSparse_LIBRARIES}\n\n") +endif() + +#set HAVE_SUITESPARSE for config.h +set(HAVE_SUITESPARSE ${SuiteSparse_FOUND}) + +# register all SuiteSparse related flags +if(SuiteSparse_FOUND) + dune_register_package_flags( + COMPILE_DEFINITIONS "ENABLE_SUITESPARSE=1" + LIBRARIES "${SuiteSparse_LIBRARIES}" + INCLUDE_DIRS "${SuiteSparse_INCLUDE_DIRS}") +endif() diff --git a/cmake/modules/FindUMFPack.cmake b/cmake/modules/FindUMFPack.cmake index 4e68fcb56a48996cd9a1ba8c492d388bcc2b8be9..222b1542f7c4b9e7a34fba81aa805f0b4a3c8050 100644 --- a/cmake/modules/FindUMFPack.cmake +++ b/cmake/modules/FindUMFPack.cmake @@ -2,6 +2,9 @@ # # Find the UMFPack library # +# .. deprecated:: 3.0 +# Use :code:`find_package(SuiteSparse OPTIONAL_COMPONENTS UMFPACK)` instead +# # You may set the following variables to modify the # behaviour of this module: # @@ -26,76 +29,37 @@ # system paths. # -find_package(BLAS QUIET REQUIRED) -if(NOT BLAS_FOUND) - message(WARNING "UMFPack requires BLAS which was not found, skipping the test.") - return() -endif() - -find_library(AMD_LIBRARY - NAMES "amd" - PATHS ${UMFPACK_ROOT} - PATH_SUFFIXES "lib" "lib32" "lib64" "AMD" "AMD/Lib" - NO_DEFAULT_PATH -) - -find_library(AMD_LIBRARY - NAMES "amd" - PATH_SUFFIXES "lib" "lib32" "lib64" "AMD" "AMD/Lib" -) - -if(NOT AMD_LIBRARY) - message(WARNING "UMFPack requires AMD (approximate minimum degree ordering) which was not found, skipping the test.") - return() -endif() +find_package(SuiteSparse OPTIONAL_COMPONENTS UMFPACK) -#look for header files at positions given by the user -find_path(UMFPACK_INCLUDE_DIR - NAMES "umfpack.h" - PATHS ${UMFPACK_ROOT} - PATH_SUFFIXES "umfpack" "include/umfpack" "suitesparse" "include" "src" "UMFPACK" "UMFPACK/Include" - NO_DEFAULT_PATH -) -#now also look for default paths -find_path(UMFPACK_INCLUDE_DIR - NAMES "umfpack.h" - PATH_SUFFIXES "umfpack" "include/umfpack" "suitesparse" "include" "UMFPACK" "UMFPACK/Include" -) +# use find_package(SuiteSparse OPTIONAL_COMPONENTS UMFPACK) instead +message(WARNING "find_package(UMFPack) is deprecated, please use FindSuiteSparse instead") -#look for library at positions given by the user -find_library(UMFPACK_LIBRARY - NAMES "umfpack" - PATHS ${UMFPACK_ROOT} - PATH_SUFFIXES "lib" "lib32" "lib64" "UMFPACK" "UMFPACK/Lib" - NO_DEFAULT_PATH -) -#now also include the deafult paths -find_library(UMFPACK_LIBRARY - NAMES "umfpack" - PATH_SUFFIXES "lib" "lib32" "lib64" "UMFPACK" "UMFPACK/Lib" -) +set(UMFPACK_INCLUDE_DIRS ${SuiteSparse_INCLUDE_DIRS}) +set(UMFPACK_LIBRARIES ${SuiteSparse_LIBRARIES}) # behave like a CMake module is supposed to behave include(FindPackageHandleStandardArgs) find_package_handle_standard_args( "UMFPack" DEFAULT_MSG - UMFPACK_INCLUDE_DIR - UMFPACK_LIBRARY + UMFPACK_INCLUDE_DIRS + UMFPACK_LIBRARIES ) -mark_as_advanced(UMFPACK_INCLUDE_DIR UMFPACK_LIBRARY) +mark_as_advanced(UMFPACK_INCLUDE_DIRS UMFPACK_LIBRARIES) # if both headers and library are found, store results if(UMFPACK_FOUND) - set(UMFPACK_INCLUDE_DIRS ${UMFPACK_INCLUDE_DIR}) - set(UMFPACK_LIBRARIES ${UMFPACK_LIBRARY}) + foreach( dir ${UMFPACK_INCLUDE_DIR} ) + list( APPEND UMFPACK_INCLUDE_FLAGS "-I${dir}/ " ) + endforeach() + set(UMFPACK_LIBRARIES ${UMFPACK_LIBRARIES}) # log result file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log "Determining location of UMFPack succeded:\n" "Include directory: ${UMFPACK_INCLUDE_DIRS}\n" "Library directory: ${UMFPACK_LIBRARIES}\n\n") - set(UMFPACK_DUNE_COMPILE_FLAGS "-I${UMFPACK_INCLUDE_DIRS}" + set(UMFPACK_DUNE_COMPILE_FLAGS "${UMFPACK_INCLUDE_FLAGS}" CACHE STRING "Compile Flags used by DUNE when compiling with UMFPack programs") set(UMFPACK_DUNE_LIBRARIES ${UMFPACK_LIBRARIES} ${BLAS_LIBRARIES} ${AMD_LIBRARY} CACHE STRING "Libraries used by DUNE when linking UMFPack programs") @@ -109,6 +73,7 @@ endif(UMFPACK_FOUND) #set HAVE_UMFPACK for config.h set(HAVE_UMFPACK ${UMFPACK_FOUND}) +set(HAVE_SUITESPARSE_UMFPACK ${UMFPACK_FOUND}) # register all umfpack related flags if(UMFPACK_FOUND) diff --git a/config.h.cmake b/config.h.cmake index 6777d43d554c96c72db3b0d155415dc3d94ba0bc..335d348840eace6a0c7b9a9a224f422b4ea90ed7 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -100,9 +100,48 @@ /* Define to 1 if the compiler properly supports testing for operator[] */ #cmakedefine HAVE_IS_INDEXABLE_SUPPORT 1 -/* Define to if the UMFPack library is available */ +/* Define to ENABLE_UMFPACK if the UMFPack library is available */ #cmakedefine HAVE_UMFPACK ENABLE_UMFPACK +/* Define to ENABLE_SUITESPARSE if the SuiteSparse library is available */ +#cmakedefine HAVE_SUITESPARSE ENABLE_SUITESPARSE + +/* Define to ENABLE_SUITESPARSE if the SuiteSparse's AMD library is available */ +#cmakedefine HAVE_SUITESPARSE_AMD ENABLE_SUITESPARSE + +/* Define to ENABLE_SUITESPARSE if the SuiteSparse's BTF library is available */ +#cmakedefine HAVE_SUITESPARSE_BTF ENABLE_SUITESPARSE + +/* Define to ENABLE_SUITESPARSE if the SuiteSparse's CAMD library is available */ +#cmakedefine HAVE_SUITESPARSE_CAMD ENABLE_SUITESPARSE + +/* Define to ENABLE_SUITESPARSE if the SuiteSparse's CCOLAMD library is available */ +#cmakedefine HAVE_SUITESPARSE_CCOLAMD ENABLE_SUITESPARSE + +/* Define to ENABLE_SUITESPARSE if the SuiteSparse's CHOLMOD library is available */ +#cmakedefine HAVE_SUITESPARSE_CHOLMOD ENABLE_SUITESPARSE + +/* Define to ENABLE_SUITESPARSE if the SuiteSparse's COLAMD library is available */ +#cmakedefine HAVE_SUITESPARSE_COLAMD ENABLE_SUITESPARSE + +/* Define to ENABLE_SUITESPARSE if the SuiteSparse's CXSPARSE library is available */ +#cmakedefine HAVE_SUITESPARSE_CXSPARSE ENABLE_SUITESPARSE + +/* Define to ENABLE_SUITESPARSE if the SuiteSparse's KLU library is available */ +#cmakedefine HAVE_SUITESPARSE_KLU ENABLE_SUITESPARSE + +/* Define to ENABLE_SUITESPARSE if the SuiteSparse's LDL library is available */ +#cmakedefine HAVE_SUITESPARSE_LDL ENABLE_SUITESPARSE + +/* Define to ENABLE_SUITESPARSE if the SuiteSparse's RBIO library is available */ +#cmakedefine HAVE_SUITESPARSE_RBIO ENABLE_SUITESPARSE + +/* Define to ENABLE_SUITESPARSE if the SuiteSparse's SPQR library is available */ +#cmakedefine HAVE_SUITESPARSE_SPQR ENABLE_SUITESPARSE + +/* Define to ENABLE_SUITESPARSE if the SuiteSparse's UMFPACK library is available */ +#cmakedefine HAVE_SUITESPARSE_UMFPACK ENABLE_SUITESPARSE + /* Define to ENABLE_PARMETIS if you have the Parmetis library. This is only true if MPI was found by configure _and_ if the application uses the PARMETIS_CPPFLAGS */