From c61828962b554ff0761d3d497a8f7ae4d4a29f3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=BCtzel?= Date: Tue, 15 Aug 2023 18:10:55 +0200 Subject: [PATCH] GraphBLAS: Create pkg-config file --- GraphBLAS/CMakeLists.txt | 55 +++++++++++++++++++++++++++++++- GraphBLAS/Config/GraphBLAS.pc.in | 18 +++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 GraphBLAS/Config/GraphBLAS.pc.in diff --git a/GraphBLAS/CMakeLists.txt b/GraphBLAS/CMakeLists.txt index c6c341adb9..8cfe2829fc 100644 --- a/GraphBLAS/CMakeLists.txt +++ b/GraphBLAS/CMakeLists.txt @@ -11,7 +11,7 @@ # get the version #------------------------------------------------------------------------------- -cmake_minimum_required ( VERSION 3.16 ) +cmake_minimum_required ( VERSION 3.20 ) set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake_modules ) @@ -324,6 +324,7 @@ if ( NOT WIN32 ) set ( GB_M "m" ) target_link_libraries ( graphblas PRIVATE m ) if ( NOT NSTATIC ) + list ( APPEND GRAPHBLAS_STATIC_LIBS "m" ) target_link_libraries ( graphblas_static PUBLIC m ) endif ( ) endif ( ) @@ -332,6 +333,7 @@ endif ( ) if ( NOT WIN32 ) target_link_libraries ( graphblas PRIVATE dl ) if ( NOT NSTATIC ) + list ( APPEND GRAPHBLAS_STATIC_LIBS "dl" ) target_link_libraries ( graphblas_static PUBLIC dl ) endif ( ) endif ( ) @@ -341,6 +343,7 @@ include ( SuiteSparseAtomic ) if ( LIBATOMIC_REQUIRED ) target_link_libraries ( graphblas PRIVATE atomic ) if ( NOT NSTATIC ) + list ( APPEND GRAPHBLAS_STATIC_LIBS "atomic" ) target_link_libraries ( graphblas_static PUBLIC atomic ) endif ( ) endif ( ) @@ -360,6 +363,7 @@ if ( OPENMP_FOUND ) # So this breaks: # target_link_libraries ( graphblas PRIVATE OpenMP::OpenMP_C ) if ( NOT NSTATIC ) + list ( APPEND GRAPHBLAS_STATIC_LIBS ${OpenMP_C_LIBRARIES} ) target_link_libraries ( graphblas_static PUBLIC ${OpenMP_C_LIBRARIES} ) # target_link_libraries ( graphblas_static PUBLIC OpenMP::OpenMP_C ) endif ( ) @@ -497,6 +501,55 @@ install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/GraphBLASConfigVersion.cmake DESTINATION ${SUITESPARSE_LIBDIR}/cmake/GraphBLAS ) +# create pkg-config file + +# This might be something like: +# /usr/lib/libgomp.so;/usr/lib/libpthread.a;m +# convert to -l flags for pkg-config, i.e.: "-lgomp -lpthread -lm" +set ( GRAPHBLAS_STATIC_LIBS_LIST ${GRAPHBLAS_STATIC_LIBS} ) +set ( GRAPHBLAS_STATIC_LIBS "" ) +foreach ( _lib ${GRAPHBLAS_STATIC_LIBS_LIST} ) + string ( FIND ${_lib} "." _pos REVERSE ) + if ( ${_pos} EQUAL "-1" ) + set ( GRAPHBLAS_STATIC_LIBS "${GRAPHBLAS_STATIC_LIBS} -l${_lib}" ) + continue () + endif ( ) + foreach ( _kind IN ITEMS "IMPORT" "SHARED" "STATIC" ) + set ( _regex ".*\\/(lib)?([^\\.]*)(${CMAKE_${_kind}_LIBRARY_SUFFIX})" ) + if ( ${_lib} MATCHES ${_regex} ) + string ( REGEX REPLACE ${_regex} "\\2" _libname ${_lib} ) + if ( NOT "${_libname}" STREQUAL "" ) + set ( GRAPHBLAS_STATIC_LIBS "${GRAPHBLAS_STATIC_LIBS} -l${_libname}" ) + break () + endif ( ) + endif ( ) + endforeach ( ) +endforeach ( ) +message ( STATUS "GRAPHBLAS_STATIC_LIBS: ${GRAPHBLAS_STATIC_LIBS}" ) + +set ( prefix "${CMAKE_INSTALL_PREFIX}" ) +set ( exec_prefix "\${prefix}" ) +cmake_path ( IS_ABSOLUTE SUITESPARSE_LIBDIR SUITESPARSE_LIBDIR_IS_ABSOLUTE ) +if (SUITESPARSE_LIBDIR_IS_ABSOLUTE) + set ( libdir "${SUITESPARSE_LIBDIR}") +else ( ) + set ( libdir "\${exec_prefix}/${SUITESPARSE_LIBDIR}") +endif ( ) +cmake_path ( IS_ABSOLUTE SUITESPARSE_INCLUDEDIR SUITESPARSE_INCLUDEDIR_IS_ABSOLUTE ) +if (SUITESPARSE_INCLUDEDIR_IS_ABSOLUTE) + set ( includedir "${SUITESPARSE_INCLUDEDIR}") +else ( ) + set ( includedir "\${prefix}/${SUITESPARSE_INCLUDEDIR}") +endif ( ) +configure_file ( + Config/GraphBLAS.pc.in + GraphBLAS.pc + @ONLY + NEWLINE_STYLE LF ) +install ( FILES + ${CMAKE_CURRENT_BINARY_DIR}/GraphBLAS.pc + DESTINATION ${SUITESPARSE_LIBDIR}/pkgconfig ) + #------------------------------------------------------------------------------- # configure the JITs #------------------------------------------------------------------------------- diff --git a/GraphBLAS/Config/GraphBLAS.pc.in b/GraphBLAS/Config/GraphBLAS.pc.in new file mode 100644 index 0000000000..a9aa4d3029 --- /dev/null +++ b/GraphBLAS/Config/GraphBLAS.pc.in @@ -0,0 +1,18 @@ +# GraphBLAS, Copyright (c) 2017-2023, Timothy A. Davis. +# All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +# FIXME: Which flags do we need to statically link CUDA? + +Name: GraphBLAS +URL: https://github.com/DrTimothyAldenDavis/SuiteSparse +Description: Complete implementation of the GraphBLAS standard in SuiteSparse +Version: @GraphBLAS_VERSION_MAJOR@.@GraphBLAS_VERSION_MINOR@.@GraphBLAS_VERSION_SUB@ +Libs: -L${libdir} -lgraphblas +Libs.private: @GRAPHBLAS_STATIC_LIBS@ +Cflags: -I${includedir}