Skip to content

Commit

Permalink
LAGraph v1.1.0: changes required for SuiteSparse integration
Browse files Browse the repository at this point in the history
  • Loading branch information
DrTimothyAldenDavis committed Nov 29, 2023
1 parent 7887f54 commit 58d229e
Show file tree
Hide file tree
Showing 74 changed files with 1,476 additions and 670 deletions.
283 changes: 202 additions & 81 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,44 @@

cmake_minimum_required ( VERSION 3.13 )

set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
${CMAKE_SOURCE_DIR}/cmake_modules
${CMAKE_SOURCE_DIR}/../cmake_modules
${CMAKE_SOURCE_DIR}/../SuiteSparse/cmake_modules
)

cmake_policy ( SET CMP0042 NEW )
cmake_policy ( SET CMP0048 NEW )
set ( CMAKE_MACOSX_RPATH TRUE )

# version of LAGraph
set ( LAGraph_DATE "Aug 2, 2023" )
set ( LAGraph_VERSION_MAJOR 1 )
set ( LAGraph_VERSION_MINOR 0 )
set ( LAGraph_VERSION_SUB 2 )
set ( LAGraph_DATE "Dec 30, 2023" )
set ( LAGraph_VERSION_MAJOR 1 CACHE STRING "" FORCE )
set ( LAGraph_VERSION_MINOR 1 CACHE STRING "" FORCE )
set ( LAGraph_VERSION_SUB 0 CACHE STRING "" FORCE )

#-------------------------------------------------------------------------------
# define the project
#-------------------------------------------------------------------------------

project ( lagraph
VERSION "${LAGraph_VERSION_MAJOR}.${LAGraph_VERSION_MINOR}.${LAGraph_VERSION_SUB}" )

#-------------------------------------------------------------------------------
# SuiteSparse policies
#-------------------------------------------------------------------------------

set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
${PROJECT_SOURCE_DIR}/cmake_modules
${PROJECT_SOURCE_DIR}/../cmake_modules
${PROJECT_SOURCE_DIR}/../SuiteSparse_config/cmake_modules
)

include ( SuiteSparsePolicy )

enable_language ( C )

option ( NOPENMP "ON: do not use OpenMP. OFF (default): use OpenMP" OFF )

# configure LAGraph.h with the LAGraph date and version
configure_file (
"config/LAGraph.h.in"
"${PROJECT_SOURCE_DIR}/include/LAGraph.h" )
"${PROJECT_SOURCE_DIR}/include/LAGraph.h"
NEWLINE_STYLE LF )

#-------------------------------------------------------------------------------
# code coverage and build type
Expand All @@ -73,30 +88,28 @@ configure_file (
# make test_coverage

if ( "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
if ( COVERAGE )
message ( STATUS "============== Code coverage enabled ===============" )
set ( CMAKE_BUILD_TYPE Debug )
# On the Mac, you need gcov-11 from homebrew (part of gcc-11):
# and uncomment this line:
# set ( GCOV_PATH /usr/local/bin/gcov-11)
include ( CodeCoverage )

append_coverage_compiler_flags ( )

# turn off optimization for non-skewed coverage reports
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -DCOVERAGE" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0" )

setup_target_for_coverage_lcov (
NAME test_coverage
EXECUTABLE ctest
DEPENDENCIES ${PROJECT_NAME}
BASE_DIRECTORY "."
NO_DEMANGLE TRUE
EXCLUDE "*/benchmark/*" "deps/json*/*"
"src/test/include/acutest.h"
)
endif ( )
if ( COVERAGE )
message ( STATUS "============== Code coverage enabled ===============" )
set ( CMAKE_BUILD_TYPE Debug )
# On the Mac, you need gcov-11 from homebrew (part of gcc-11):
# and uncomment this line:
# set ( GCOV_PATH /usr/local/bin/gcov-11)
include ( CodeCoverage )

append_coverage_compiler_flags ( )

# turn off optimization for non-skewed coverage reports
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -DCOVERAGE" )

setup_target_for_coverage_lcov (
NAME test_coverage
EXECUTABLE ctest
DEPENDENCIES ${PROJECT_NAME}
BASE_DIRECTORY "."
NO_DEMANGLE TRUE
EXCLUDE "*/benchmark/*" "deps/json*/*" "src/test/include/acutest.h"
)
endif ( )
endif ( )

# For development only, not for end-users:
Expand All @@ -110,15 +123,32 @@ endif ( )
# Find the GraphBLAS installation
#-------------------------------------------------------------------------------

# If GraphBLAS is not in a standard installation location, either
# export GRAPHBLAS_ROOT <path>
# or
# GRAPHBLAS_ROOT=<path> cmake ..
# or uncomment the next line:
# set ( ENV{GRAPHBLAS_ROOT} ${CMAKE_SOURCE_DIR}/../GraphBLAS )
message ( STATUS "GraphBLAS_ROOT: ${GraphBLAS_ROOT} $ENV{GraphBLAS_ROOT}" )
message ( STATUS "GRAPHBLAS_ROOT: ${GRAPHBLAS_ROOT} $ENV{GRAPHBLAS_ROOT}" )
find_package (GraphBLAS 7.0.1 REQUIRED MODULE)
if ( SUITESPARSE_ROOT_CMAKELISTS )

if ( TARGET GraphBLAS )
add_library ( GraphBLAS::GraphBLAS ALIAS GraphBLAS )
else ( )
add_library ( GraphBLAS::GraphBLAS ALIAS GraphBLAS_static )
endif ( )
if ( TARGET GraphBLAS_static )
add_library ( GraphBLAS::GraphBLAS_static ALIAS GraphBLAS_static )
endif ( )

else ( )

# If GraphBLAS is not in a standard installation location, either
# export GRAPHBLAS_ROOT <path>
# or
# GRAPHBLAS_ROOT=<path> cmake ..
# or uncomment the next line:
# set ( ENV{GRAPHBLAS_ROOT} ${PROJECT_SOURCE_DIR}/../GraphBLAS )

message ( STATUS "GraphBLAS_ROOT: ${GraphBLAS_ROOT} $ENV{GraphBLAS_ROOT}" )
message ( STATUS "GRAPHBLAS_ROOT: ${GRAPHBLAS_ROOT} $ENV{GRAPHBLAS_ROOT}" )

find_package ( GraphBLAS 8.3.0 MODULE REQUIRED )

endif ( )

#-------------------------------------------------------------------------------
# determine what user threading model to use
Expand All @@ -127,10 +157,14 @@ find_package (GraphBLAS 7.0.1 REQUIRED MODULE)
if ( COVERAGE )
message ( STATUS "OpenMP disabled for test coverage" )
else ( )
include ( FindOpenMP )
include ( FindThreads )
if ( OPENMP_FOUND )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS} " )
if ( NOPENMP )
set ( OPENMP_C_FOUND OFF )
else ( )
find_package ( OpenMP )
if ( OPENMP_C_FOUND AND BUILD_STATIC_LIBS )
list ( APPEND LAGRAPH_STATIC_LIBS ${OpenMP_C_LIBRARIES} )
endif ( )
find_package ( Threads )
endif ( )
endif ( )

Expand All @@ -139,8 +173,8 @@ endif ( )
#-------------------------------------------------------------------------------

message ( STATUS "CMAKE build type: " ${CMAKE_BUILD_TYPE} )
message ( STATUS "CMAKE source directory: " ${CMAKE_SOURCE_DIR} )
message ( STATUS "CMAKE build directory: " ${CMAKE_BINARY_DIR} )
message ( STATUS "CMAKE source directory: " ${PROJECT_SOURCE_DIR} )
message ( STATUS "CMAKE build directory: " ${PROJECT_BINARY_DIR} )

if ( ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
message ( STATUS "CMAKE C Flags debug: " ${CMAKE_C_FLAGS_DEBUG} )
Expand All @@ -152,63 +186,54 @@ message ( STATUS "CMAKE compiler ID: " ${CMAKE_C_COMPILER_ID} )
message ( STATUS "CMAKE thread library: " ${CMAKE_THREAD_LIBS_INIT} )
message ( STATUS "CMAKE have pthreads: " ${CMAKE_USE_PTHREADS_INIT} )
message ( STATUS "CMAKE have Win32 pthreads: " ${CMAKE_USE_WIN32_THREADS_INIT} )
message ( STATUS "CMAKE have OpenMP: " ${OPENMP_FOUND} )
message ( STATUS "CMAKE have OpenMP: " ${OPENMP_C_FOUND} )

#-------------------------------------------------------------------------------
# include directories for LAGraph library
#-------------------------------------------------------------------------------

include_directories ( ${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/src/utility
${CMAKE_SOURCE_DIR}/test/include
${GRAPHBLAS_INCLUDE_DIR} )
include_directories ( ${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/src/utility
${PROJECT_SOURCE_DIR}/test/include )
include_directories ( "/usr/local/include" )

# tell LAGraph where to find its own source (for LAGraph/data files)
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLGDIR=${CMAKE_SOURCE_DIR}" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLGDIR=${PROJECT_SOURCE_DIR}" )
# set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O" )

#-------------------------------------------------------------------------------
# compiler options
#-------------------------------------------------------------------------------

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED True)

# check which compiler is being used. If you need to make
# compiler-specific modifications, here is the place to do it.
if ( "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
# cmake 2.8 workaround: gcc needs to be told to do ANSI C11.
# cmake 3.0 doesn't have this problem.
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -lm -Wno-pragmas " )
# check all warnings:
# set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wpedantic -Werror " )
# set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g " )
#if ( CMAKE_C_COMPILER_VERSION VERSION_LESS 4.9 )
# message ( FATAL_ERROR "gcc version must be at least 4.9" )
#endif ( )
elseif ( "${CMAKE_C_COMPILER_ID}" STREQUAL "Intel" )
# options for icc: also needs -std=c11
# note that -g can be used, for VTune. Comment out the following line
# to compile without -g.
# set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g " )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 " )
# check all warnings:
# set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w3 " )
#if ( CMAKE_C_COMPILER_VERSION VERSION_LESS 18.0 )
# message ( FATAL_ERROR "icc version must be at least 18.0" )
#endif ( )
elseif ( "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" )
# options for clang
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -std=c11 " )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 " )
#if ( CMAKE_C_COMPILER_VERSION VERSION_LESS 3.3 )
# message ( FATAL_ERROR "clang version must be at least 3.3" )
#endif ( )
elseif ( "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC" )
# options for MicroSoft Visual Studio
elseif ( "${CMAKE_C_COMPILER_ID}" STREQUAL "PGI" )
# options for PGI pgcc compiler
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -acc -Minfo=accel -Mcuda -Mnoopenmp -noswitcherror -c11 -lm -fPIC " )
set ( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -acc -Minfo=accel -Mcuda -Mnoopenmp -D__GCC_ATOMIC_TEST_AND_SET_TRUEVAL=1 -noswitcherror --c++11 -lm -fPIC " )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -acc -Minfo=accel -Mcuda -Mnoopenmp -noswitcherror -fPIC " )
endif ( )

if ( ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
Expand Down Expand Up @@ -238,10 +263,6 @@ message ( STATUS "CMAKE C flags: " ${CMAKE_C_FLAGS} )
# enable testing and add subdirectories
#-------------------------------------------------------------------------------

# allow ctest to find the binaries:
set ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} )
set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} )

enable_testing ( )

add_subdirectory ( src )
Expand All @@ -254,17 +275,117 @@ endif ( )
# LAGraph installation location
#-------------------------------------------------------------------------------

# install in ${CMAKE_INSTALL_PREFIX}/lib and ${CMAKE_INSTALL_PREFIX}/include.
# Requires "sudo make install" if this is /usr/local (default).
include ( CMakePackageConfigHelpers )

message ( STATUS "Installation in: ${CMAKE_INSTALL_PREFIX}" )
include ( GNUInstallDirs )
if ( BUILD_SHARED_LIBS )
install ( TARGETS LAGraph LAGraphX
EXPORT LAGraphTargets
LIBRARY DESTINATION ${SUITESPARSE_LIBDIR}
ARCHIVE DESTINATION ${SUITESPARSE_LIBDIR}
RUNTIME DESTINATION ${SUITESPARSE_BINDIR}
PUBLIC_HEADER DESTINATION ${SUITESPARSE_INCLUDEDIR} )
endif ( )

install ( TARGETS lagraph lagraphx
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
if ( BUILD_STATIC_LIBS )
install ( TARGETS LAGraph_static LAGraphX_static
EXPORT LAGraphTargets
ARCHIVE DESTINATION ${SUITESPARSE_LIBDIR}
PUBLIC_HEADER DESTINATION ${SUITESPARSE_INCLUDEDIR} )
endif ( )


# create (temporary) export target file during build
export ( EXPORT LAGraphTargets
NAMESPACE SuiteSparse::
FILE ${CMAKE_CURRENT_BINARY_DIR}/LAGraphTargets.cmake )

# install export target, config and version files for find_package
install ( EXPORT LAGraphTargets
NAMESPACE SuiteSparse::
DESTINATION ${SUITESPARSE_PKGFILEDIR}/cmake/LAGraph )

# generate config file to be used in common build tree
set ( SUITESPARSE_IN_BUILD_TREE ON )
configure_package_config_file (
config/LAGraphConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/LAGraphConfig.cmake
INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/LAGraphConfig.cmake )

# generate config file to be installed
set ( SUITESPARSE_IN_BUILD_TREE OFF )
configure_package_config_file (
config/LAGraphConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/target/LAGraphConfig.cmake
INSTALL_DESTINATION ${SUITESPARSE_PKGFILEDIR}/cmake/LAGraph )

write_basic_package_version_file (
${CMAKE_CURRENT_BINARY_DIR}/LAGraphConfigVersion.cmake
COMPATIBILITY SameMajorVersion )

install ( FILES
${CMAKE_CURRENT_BINARY_DIR}/target/LAGraphConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/LAGraphConfigVersion.cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindGraphBLAS.cmake
DESTINATION ${SUITESPARSE_PKGFILEDIR}/cmake/LAGraph )

install ( TARGETS lagraph_static lagraphx_static
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
#-------------------------------------------------------------------------------
# create pkg-config file
#-------------------------------------------------------------------------------

if ( NOT MSVC )
if ( BUILD_STATIC_LIBS )
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
# convert to -l flags for pkg-config, i.e.: "-lgomp -lpthread -lm"
set ( LAGRAPH_STATIC_LIBS_LIST ${LAGRAPH_STATIC_LIBS} )
set ( LAGRAPH_STATIC_LIBS "" )
foreach ( _lib ${LAGRAPH_STATIC_LIBS_LIST} )
string ( FIND ${_lib} "." _pos REVERSE )
if ( ${_pos} EQUAL "-1" )
set ( LAGRAPH_STATIC_LIBS "${LAGRAPH_STATIC_LIBS} -l${_lib}" )
continue ()
endif ( )
set ( _kinds "SHARED" "STATIC" )
if ( WIN32 )
list ( PREPEND _kinds "IMPORT" )
endif ( )
foreach ( _kind IN LISTS _kinds )
set ( _regex ".*\\/(lib)?([^\\.]*)(${CMAKE_${_kind}_LIBRARY_SUFFIX})" )
if ( ${_lib} MATCHES ${_regex} )
string ( REGEX REPLACE ${_regex} "\\2" _libname ${_lib} )
if ( NOT "${_libname}" STREQUAL "" )
set ( LAGRAPH_STATIC_LIBS "${LAGRAPH_STATIC_LIBS} -l${_libname}" )
break ()
endif ( )
endif ( )
endforeach ( )
endforeach ( )

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/LAGraph.pc.in
LAGraph.pc
@ONLY
NEWLINE_STYLE LF )
install ( FILES
${CMAKE_CURRENT_BINARY_DIR}/LAGraph.pc
DESTINATION ${SUITESPARSE_PKGFILEDIR}/pkgconfig )
endif ( )
Loading

0 comments on commit 58d229e

Please sign in to comment.