Skip to content

Commit

Permalink
GraphBLAS: Create pkg-config file
Browse files Browse the repository at this point in the history
  • Loading branch information
mmuetzel committed Aug 15, 2023
1 parent 1ba0cf4 commit c618289
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
55 changes: 54 additions & 1 deletion GraphBLAS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 ( )
Expand All @@ -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 ( )
Expand All @@ -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 ( )
Expand All @@ -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 ( )
Expand Down Expand Up @@ -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
#-------------------------------------------------------------------------------
Expand Down
18 changes: 18 additions & 0 deletions GraphBLAS/Config/GraphBLAS.pc.in
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit c618289

Please sign in to comment.