From c817ef25da6925ac550da8d890516f8af4339b18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=BCtzel?= Date: Thu, 30 Nov 2023 13:39:01 +0100 Subject: [PATCH 1/2] Add dependency to system libraries after SuiteSparse libraries This might help with the search order of include and library directories. Use OpenMP CMake target instead of library and include folder names. Maybe helps with the issue described in #175. --- CHOLMOD/CMakeLists.txt | 123 ++++++++++++++++++++--------------------- 1 file changed, 60 insertions(+), 63 deletions(-) diff --git a/CHOLMOD/CMakeLists.txt b/CHOLMOD/CMakeLists.txt index 680ce0529d..b13a6e0d29 100644 --- a/CHOLMOD/CMakeLists.txt +++ b/CHOLMOD/CMakeLists.txt @@ -357,40 +357,6 @@ if ( BUILD_STATIC_LIBS ) endif ( ) endif ( ) -# OpenMP: -if ( OPENMP_FOUND ) - message ( STATUS "OpenMP C libraries: ${OpenMP_C_LIBRARIES} ") - message ( STATUS "OpenMP C include: ${OpenMP_C_INCLUDE_DIRS} ") - message ( STATUS "OpenMP C flags: ${OpenMP_C_FLAGS} ") - if ( BUILD_SHARED_LIBS ) - target_link_libraries ( CHOLMOD PRIVATE ${OpenMP_C_LIBRARIES} ) - endif ( ) - if ( BUILD_STATIC_LIBS ) - target_link_libraries ( CHOLMOD_static PUBLIC ${OpenMP_C_LIBRARIES} ) - list ( APPEND CHOLMOD_STATIC_LIBS ${OpenMP_C_LIBRARIES} ) - endif ( ) - set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS} " ) - set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_C_FLAGS} " ) - include_directories ( ${OpenMP_C_INCLUDE_DIRS} ) -else ( ) - # to fix METIS: use threadprivate variables for GKRAND instead globals, - # so multiple user threads can call cholmod_analyze in parallel on - # different matrices, and avoid global locking of the system rand. - include ( SuiteSparse__thread ) -endif ( ) - -# libm: -if ( NOT WIN32 ) - if ( BUILD_SHARED_LIBS ) - target_link_libraries ( CHOLMOD PRIVATE m ) - endif ( ) - if ( BUILD_STATIC_LIBS ) - list ( APPEND CHOLMOD_STATIC_LIBS "m" ) - target_link_libraries ( CHOLMOD_static PUBLIC m ) - endif ( ) -endif ( ) - list ( APPEND CHOLMOD_STATIC_LIBS "m" ) - # AMD: if ( BUILD_SHARED_LIBS ) target_link_libraries ( CHOLMOD PRIVATE SuiteSparse::AMD ) @@ -415,35 +381,6 @@ if ( BUILD_STATIC_LIBS ) endif ( ) endif ( ) -# BLAS and LAPACK: for the Supernodal Module -if ( NOT NSUPERNODAL ) - # LAPACK: - message ( STATUS "LAPACK libraries: ${LAPACK_LIBRARIES} ") - message ( STATUS "LAPACK include: ${LAPACK_INCLUDE_DIRS} ") - message ( STATUS "LAPACK linker flags: ${LAPACK_LINKER_FLAGS} ") - if ( BUILD_SHARED_LIBS ) - target_link_libraries ( CHOLMOD PRIVATE ${LAPACK_LIBRARIES} ) - endif ( ) - if ( BUILD_STATIC_LIBS ) - list ( APPEND CHOLMOD_STATIC_LIBS ${LAPACK_LIBRARIES} ) - target_link_libraries ( CHOLMOD_static PUBLIC ${LAPACK_LIBRARIES} ) - endif ( ) - include_directories ( ${LAPACK_INCLUDE_DIR} ) - - # BLAS: - message ( STATUS "BLAS libraries: ${BLAS_LIBRARIES} ") - message ( STATUS "BLAS include: ${BLAS_INCLUDE_DIRS} ") - message ( STATUS "BLAS linker flags: ${BLAS_LINKER_FLAGS} ") - if ( BUILD_SHARED_LIBS ) - target_link_libraries ( CHOLMOD PRIVATE ${BLAS_LIBRARIES} ) - endif ( ) - if ( BUILD_STATIC_LIBS ) - list ( APPEND CHOLMOD_STATIC_LIBS ${BLAS_LIBRARIES} ) - target_link_libraries ( CHOLMOD_static PUBLIC ${BLAS_LIBRARIES} ) - endif ( ) - include_directories ( ${BLAS_INCLUDE_DIRS} ) -endif ( ) - # CAMD and CCOLAMD: if ( NOT NCAMD ) if ( BUILD_SHARED_LIBS ) @@ -471,6 +408,66 @@ if ( NOT NCAMD ) endif ( ) endif ( ) +# OpenMP: +if ( OPENMP_C_FOUND ) + message ( STATUS "OpenMP C libraries: ${OpenMP_C_LIBRARIES}" ) + message ( STATUS "OpenMP C include: ${OpenMP_C_INCLUDE_DIRS}" ) + message ( STATUS "OpenMP C flags: ${OpenMP_C_FLAGS}" ) + if ( BUILD_SHARED_LIBS ) + target_link_libraries ( CHOLMOD PRIVATE OpenMP::OpenMP_C ) + endif ( ) + if ( BUILD_STATIC_LIBS ) + target_link_libraries ( CHOLMOD_static PUBLIC OpenMP::OpenMP_C ) + list ( APPEND CHOLMOD_STATIC_LIBS ${OpenMP_C_LIBRARIES} ) + endif ( ) +else ( ) + # to fix METIS: use threadprivate variables for GKRAND instead globals, + # so multiple user threads can call cholmod_analyze in parallel on + # different matrices, and avoid global locking of the system rand. + include ( SuiteSparse__thread ) +endif ( ) + +# libm: +if ( NOT WIN32 ) + if ( BUILD_SHARED_LIBS ) + target_link_libraries ( CHOLMOD PRIVATE m ) + endif ( ) + if ( BUILD_STATIC_LIBS ) + list ( APPEND CHOLMOD_STATIC_LIBS "m" ) + target_link_libraries ( CHOLMOD_static PUBLIC m ) + endif ( ) +endif ( ) + list ( APPEND CHOLMOD_STATIC_LIBS "m" ) + +# BLAS and LAPACK: for the Supernodal Module +if ( NOT NSUPERNODAL ) + # LAPACK: + message ( STATUS "LAPACK libraries: ${LAPACK_LIBRARIES}" ) + message ( STATUS "LAPACK include: ${LAPACK_INCLUDE_DIRS}" ) + message ( STATUS "LAPACK linker flags: ${LAPACK_LINKER_FLAGS}" ) + if ( BUILD_SHARED_LIBS ) + target_link_libraries ( CHOLMOD PRIVATE ${LAPACK_LIBRARIES} ) + endif ( ) + if ( BUILD_STATIC_LIBS ) + list ( APPEND CHOLMOD_STATIC_LIBS ${LAPACK_LIBRARIES} ) + target_link_libraries ( CHOLMOD_static PUBLIC ${LAPACK_LIBRARIES} ) + endif ( ) + include_directories ( ${LAPACK_INCLUDE_DIR} ) + + # BLAS: + message ( STATUS "BLAS libraries: ${BLAS_LIBRARIES}" ) + message ( STATUS "BLAS include: ${BLAS_INCLUDE_DIRS}" ) + message ( STATUS "BLAS linker flags: ${BLAS_LINKER_FLAGS}" ) + if ( BUILD_SHARED_LIBS ) + target_link_libraries ( CHOLMOD PRIVATE ${BLAS_LIBRARIES} ) + endif ( ) + if ( BUILD_STATIC_LIBS ) + list ( APPEND CHOLMOD_STATIC_LIBS ${BLAS_LIBRARIES} ) + target_link_libraries ( CHOLMOD_static PUBLIC ${BLAS_LIBRARIES} ) + endif ( ) + include_directories ( ${BLAS_INCLUDE_DIRS} ) +endif ( ) + # METIS and the Partition module: if ( NOT NPARTITION ) include_directories ( SuiteSparse_metis/GKlib ) From 195f652d08b056a0a658357f43b1f43251337f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=BCtzel?= Date: Thu, 30 Nov 2023 17:46:41 +0100 Subject: [PATCH 2/2] CHOLMOD: Automatically check for OpenMP when importing target --- CHOLMOD/Config/CHOLMODConfig.cmake.in | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHOLMOD/Config/CHOLMODConfig.cmake.in b/CHOLMOD/Config/CHOLMODConfig.cmake.in index d37f3ede36..31c92530d6 100644 --- a/CHOLMOD/Config/CHOLMODConfig.cmake.in +++ b/CHOLMOD/Config/CHOLMODConfig.cmake.in @@ -51,6 +51,19 @@ if ( NOT _dependencies_found ) return ( ) endif ( ) +# Look for OpenMP +if ( NOT @NOPENMP@ AND NOT OpenMP_C_FOUND ) + find_dependency ( OpenMP ) + if ( NOT OpenMP_C_FOUND ) + set ( _dependencies_found OFF ) + endif ( ) +endif ( ) + +if ( NOT _dependencies_found ) + set ( CHOLMOD_FOUND OFF ) + return ( ) +endif ( ) + # Look for SuiteSparse_config, COLAMD, and AMD targets if ( @SUITESPARSE_IN_BUILD_TREE@ ) if ( NOT TARGET SuiteSparse::SuiteSparseConfig )