From 55ad380b4daa47b99a27fc50385a858b1066db3c Mon Sep 17 00:00:00 2001 From: Tim Davis Date: Sat, 9 Dec 2023 16:39:37 -0600 Subject: [PATCH] updates to build system --- CMakeLists.txt | 15 ++++++-- cmake_modules/FindGraphBLAS.cmake | 57 +++++++++++++++++++++++++++++-- config/LAGraph.pc.in | 4 +-- src/test/CMakeLists.txt | 2 +- 4 files changed, 71 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bd5c754002..8be60f2349 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -341,7 +341,6 @@ if ( NOT MSVC ) if ( NOT WIN32 ) list ( APPEND LAGRAPH_STATIC_LIBS "m" ) endif ( ) - list ( APPEND LAGRAPH_STATIC_LIBS ${GRAPHBLAS_LIBRARY} ) endif ( ) # This might be something like: # /usr/lib/libgomp.so;/usr/lib/libpthread.a;m @@ -369,6 +368,9 @@ if ( NOT MSVC ) endif ( ) endforeach ( ) endforeach ( ) + if ( BUILD_STATIC_LIBS ) + set ( LAGRAPH_STATIC_LIBS "-l$ ${LAGRAPH_STATIC_LIBS}" ) + endif ( ) set ( prefix "${CMAKE_INSTALL_PREFIX}" ) set ( exec_prefix "\${prefix}" ) @@ -384,11 +386,20 @@ if ( NOT MSVC ) else ( ) set ( includedir "\${prefix}/${SUITESPARSE_INCLUDEDIR}") endif ( ) + if ( BUILD_SHARED_LIBS ) + set ( SUITESPARSE_LIB_BASE_NAME $ ) + else ( ) + set ( SUITESPARSE_LIB_BASE_NAME $ ) + endif ( ) configure_file ( config/LAGraph.pc.in - LAGraph.pc + LAGraph.pc.out @ONLY NEWLINE_STYLE LF ) + file ( GENERATE + OUTPUT LAGraph.pc + INPUT ${CMAKE_CURRENT_BINARY_DIR}/LAGraph.pc.out + NEWLINE_STYLE LF ) install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/LAGraph.pc DESTINATION ${SUITESPARSE_PKGFILEDIR}/pkgconfig ) diff --git a/cmake_modules/FindGraphBLAS.cmake b/cmake_modules/FindGraphBLAS.cmake index 110ac3457c..086eaf4351 100644 --- a/cmake_modules/FindGraphBLAS.cmake +++ b/cmake_modules/FindGraphBLAS.cmake @@ -340,15 +340,68 @@ endif ( ) if ( GRAPHBLAS_LIBRARY ) message ( STATUS "Create target GraphBLAS::GraphBLAS" ) + # Get library name from filename of library + # This might be something like: + # /usr/lib/libgraphblas.so or /usr/lib/libgraphblas.a or graphblas64 + # convert to library name that can be used with -l flags for pkg-config + set ( GRAPHBLAS_LIBRARY_TMP ${GRAPHBLAS_LIBRARY} ) + string ( FIND ${GRAPHBLAS_LIBRARY} "." _pos REVERSE ) + if ( ${_pos} EQUAL "-1" ) + set ( _graphblas_library_name ${GRAPHBLAS_LIBRARY} ) + else ( ) + set ( _kinds "SHARED" "STATIC" ) + if ( WIN32 ) + list ( PREPEND _kinds "IMPORT" ) + endif ( ) + foreach ( _kind IN LISTS _kinds ) + set ( _regex ".*\\/(lib)?([^\\.]*)(${CMAKE_${_kind}_LIBRARY_SUFFIX})" ) + if ( ${GRAPHBLAS_LIBRARY} MATCHES ${_regex} ) + string ( REGEX REPLACE ${_regex} "\\2" _libname ${GRAPHBLAS_LIBRARY} ) + if ( NOT "${_libname}" STREQUAL "" ) + set ( _graphblas_library_name ${_libname} ) + break () + endif ( ) + endif ( ) + endforeach ( ) + endif ( ) + add_library ( GraphBLAS::GraphBLAS UNKNOWN IMPORTED ) set_target_properties ( GraphBLAS::GraphBLAS PROPERTIES IMPORTED_LOCATION "${GRAPHBLAS_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${GRAPHBLAS_INCLUDE_DIR}" ) + INTERFACE_INCLUDE_DIRECTORIES "${GRAPHBLAS_INCLUDE_DIR}" + OUTPUT_NAME ${_graphblas_library_name} ) endif ( ) + if ( GRAPHBLAS_STATIC ) message ( STATUS "Create target GraphBLAS::GraphBLAS_static" ) + # Get library name from filename of library + # This might be something like: + # /usr/lib/libgraphblas.so or /usr/lib/libgraphblas.a or graphblas64 + # convert to library name that can be used with -l flags for pkg-config + set ( GRAPHBLAS_LIBRARY_TMP ${GRAPHBLAS_STATIC} ) + string ( FIND ${GRAPHBLAS_STATIC} "." _pos REVERSE ) + if ( ${_pos} EQUAL "-1" ) + set ( _graphblas_library_name ${GRAPHBLAS_STATIC} ) + else ( ) + set ( _kinds "SHARED" "STATIC" ) + if ( WIN32 ) + list ( PREPEND _kinds "IMPORT" ) + endif ( ) + foreach ( _kind IN LISTS _kinds ) + set ( _regex ".*\\/(lib)?([^\\.]*)(${CMAKE_${_kind}_LIBRARY_SUFFIX})" ) + if ( ${GRAPHBLAS_STATIC} MATCHES ${_regex} ) + string ( REGEX REPLACE ${_regex} "\\2" _libname ${GRAPHBLAS_STATIC} ) + if ( NOT "${_libname}" STREQUAL "" ) + set ( _graphblas_library_name ${_libname} ) + break () + endif ( ) + endif ( ) + endforeach ( ) + endif ( ) + add_library ( GraphBLAS::GraphBLAS_static UNKNOWN IMPORTED ) set_target_properties ( GraphBLAS::GraphBLAS_static PROPERTIES IMPORTED_LOCATION "${GRAPHBLAS_STATIC}" - INTERFACE_INCLUDE_DIRECTORIES "${GRAPHBLAS_INCLUDE_DIR}" ) + INTERFACE_INCLUDE_DIRECTORIES "${GRAPHBLAS_INCLUDE_DIR}" + OUTPUT_NAME ${_graphblas_library_name} ) endif ( ) diff --git a/config/LAGraph.pc.in b/config/LAGraph.pc.in index 4df3b04fc5..7cfd98c18e 100644 --- a/config/LAGraph.pc.in +++ b/config/LAGraph.pc.in @@ -12,7 +12,7 @@ URL: https://github.com/DrTimothyAldenDavis/SuiteSparse Description: Library plus test harness for collecting algorithms that use GraphBLAS in SuiteSparse Version: @LAGraph_VERSION_MAJOR@.@LAGraph_VERSION_MINOR@.@LAGraph_VERSION_SUB@ Requires.private: GraphBLAS -Libs: -L${libdir} -llagraph@CMAKE_RELEASE_POSTFIX@ -Libs.private: -lgraphblas @LAGRAPH_STATIC_LIBS@ +Libs: -L${libdir} -l@SUITESPARSE_LIB_BASE_NAME@ +Libs.private: @LAGRAPH_STATIC_LIBS@ Cflags: -I${includedir} -DLG_DLL Cflags.private: -ULG_DLL diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 6a0dbb4ed3..025b1b35ab 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -112,7 +112,7 @@ foreach( testsourcefile ${TEST_SOURCES} ) ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$;PATH=path_list_prepend:$" ) else ( ) set_tests_properties ( ${ctestname} PROPERTIES - ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$>" ) + ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$" ) endif ( ) endif ( ) endforeach( testsourcefile ${TEST_SOURCES} )