Skip to content

Commit

Permalink
Merge pull request #513 from mmuetzel/graphblas
Browse files Browse the repository at this point in the history
GraphBLAS: Support jitifyer without CMake for MinGW
  • Loading branch information
DrTimothyAldenDavis authored Nov 11, 2023
2 parents 199f62d + c697550 commit 19f1109
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 22 deletions.
10 changes: 5 additions & 5 deletions GraphBLAS/Config/GB_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

// GB_C_COMPILER: the C compiler used to compile GraphBLAS:
#ifndef GB_C_COMPILER
#define GB_C_COMPILER "/usr/bin/cc"
#define GB_C_COMPILER "/mingw64/bin/cc.exe"
#endif

// GB_C_FLAGS: the C compiler flags used to compile GraphBLAS. Used
Expand All @@ -36,10 +36,10 @@

// GB_LIB_SUFFIX: library suffix (.so for Linux/Unix, .dylib for Mac, etc):
#ifndef GB_LIB_SUFFIX
#define GB_LIB_SUFFIX ".so"
#define GB_LIB_SUFFIX ".dll"
#endif

// GB_OBJ_SUFFIX: object suffix (.o for Linux/Unix/Mac, .obj for Windows):
// GB_OBJ_SUFFIX: object suffix (.o for Linux/Unix/Mac/MinGW, .obj for MSVC):
#ifndef GB_OBJ_SUFFIX
#define GB_OBJ_SUFFIX ".o"
#endif
Expand All @@ -57,12 +57,12 @@

// GB_C_LIBRARIES: libraries to link with when using direct compile/link:
#ifndef GB_C_LIBRARIES
#define GB_C_LIBRARIES " -lm -ldl /usr/lib/gcc/x86_64-linux-gnu/9/libgomp.so /usr/lib/x86_64-linux-gnu/libpthread.so"
#define GB_C_LIBRARIES " -lgomp -lmingwthrd -lmingwthrd"
#endif

// GB_CMAKE_LIBRARIES: libraries to link with when using cmake
#ifndef GB_CMAKE_LIBRARIES
#define GB_CMAKE_LIBRARIES "m;dl;/usr/lib/gcc/x86_64-linux-gnu/9/libgomp.so;/usr/lib/x86_64-linux-gnu/libpthread.so"
#define GB_CMAKE_LIBRARIES "C:/msys64/mingw64/lib/libgomp.dll.a;C:/msys64/mingw64/lib/libmingwthrd.a;C:/msys64/mingw64/lib/libmingwthrd.a"
#endif

#endif
Expand Down
2 changes: 1 addition & 1 deletion GraphBLAS/Config/GB_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#define GB_LIB_SUFFIX "@GB_LIB_SUFFIX@"
#endif

// GB_OBJ_SUFFIX: object suffix (.o for Linux/Unix/Mac, .obj for Windows):
// GB_OBJ_SUFFIX: object suffix (.o for Linux/Unix/Mac/MinGW, .obj for MSVC):
#ifndef GB_OBJ_SUFFIX
#define GB_OBJ_SUFFIX "@GB_OBJ_SUFFIX@"
#endif
Expand Down
13 changes: 7 additions & 6 deletions GraphBLAS/Source/GB_jitifyer.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ static int64_t GB_jit_table_populated = 0 ;
static size_t GB_jit_table_allocated = 0 ;

static bool GB_jit_use_cmake =
#if GB_WINDOWS
true ; // Windows requires cmake
#if defined (_MSC_VER)
true ; // MSVC requires cmake
#else
false ; // otherwise, default is to skip cmake and compile directly
#endif
Expand Down Expand Up @@ -2320,8 +2320,9 @@ void GB_jitifyer_direct_compile (char *kernel_name, uint32_t bucket)
snprintf (GB_jit_temp, GB_jit_temp_allocated,

// compile:
"%s -DGB_JIT_RUNTIME=1 " // compiler command
"%s " // C flags
"sh -c \"" // execute with POSIX shell
"%s " // compiler command
"-DGB_JIT_RUNTIME=1 %s " // C flags
"-I%s/src " // include source directory
"%s " // openmp include directories
"-o %s/c/%02x/%s%s " // *.o output file
Expand All @@ -2336,8 +2337,8 @@ void GB_jitifyer_direct_compile (char *kernel_name, uint32_t bucket)
"-o %s/lib/%02x/%s%s%s " // lib*.so output file
"%s/c/%02x/%s%s " // *.o input file
"%s " // libraries to link with
"%s" // burble stdout
"%s %s ", // error log file
"%s " // burble stdout
"%s %s\"", // error log file

// compile:
GB_jit_C_compiler, // C compiler
Expand Down
41 changes: 31 additions & 10 deletions GraphBLAS/cmake_modules/GraphBLAS_JIT_configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
#-------------------------------------------------------------------------------

# construct the JIT compiler/link strings
set ( GB_C_COMPILER "${CMAKE_C_COMPILER}" )
if ( MINGW )
execute_process ( COMMAND cygpath -u "${CMAKE_C_COMPILER}"
OUTPUT_VARIABLE C_COMPILER_BINARY OUTPUT_STRIP_TRAILING_WHITESPACE )
else ( )
set ( C_COMPILER_BINARY "${CMAKE_C_COMPILER}" )
endif ( )
set ( GB_C_COMPILER "${C_COMPILER_BINARY}" )
set ( GB_C_FLAGS "${CMAKE_C_FLAGS}" )
set ( GB_C_LINK_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}" )
set ( GB_LIB_SUFFIX "${CMAKE_SHARED_LIBRARY_SUFFIX}" )
Expand All @@ -25,8 +31,8 @@ if ( APPLE )
set ( GB_C_FLAGS "${GB_C_FLAGS} -isysroot ${CMAKE_OSX_SYSROOT} " )
set ( GB_C_LINK_FLAGS "${GB_C_LINK_FLAGS} -dynamiclib " )
set ( GB_OBJ_SUFFIX ".o" )
elseif ( WIN32 )
# Windows
elseif ( MSVC )
# Microsoft compiler
set ( GB_OBJ_SUFFIX ".obj" )
else ( )
# Linux / Unix
Expand All @@ -48,15 +54,30 @@ else ( )
endif ( )

# construct the library list
string ( REPLACE "." "\\." LIBSUFFIX1 ${GB_LIB_SUFFIX} )
string ( REPLACE "." "\\." LIBSUFFIX2 ${CMAKE_STATIC_LIBRARY_SUFFIX} )
# This might be something like:
# /usr/lib/libgomp.so;/usr/lib/libpthread.a;m
# convert to -l flags to avoid relocation issues, i.e.: "-lgomp -lpthread -lm"
set ( GB_C_LIBRARIES "" )
foreach ( LIB_NAME ${GB_CMAKE_LIBRARIES} )
if (( LIB_NAME MATCHES ${LIBSUFFIX1} ) OR ( LIB_NAME MATCHES ${LIBSUFFIX2} ))
string ( APPEND GB_C_LIBRARIES " " ${LIB_NAME} )
else ( )
string ( APPEND GB_C_LIBRARIES " -l" ${LIB_NAME} )
foreach ( _lib ${GB_CMAKE_LIBRARIES} )
string ( FIND ${_lib} "." _pos REVERSE )
if ( ${_pos} EQUAL "-1" )
set ( GB_C_LIBRARIES "${GB_C_LIBRARIES} -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 ( GB_C_LIBRARIES "${GB_C_LIBRARIES} -l${_libname}" )
break ()
endif ( )
endif ( )
endforeach ( )
endforeach ( )

if ( NOT NJIT OR ENABLE_CUDA )
Expand Down

0 comments on commit 19f1109

Please sign in to comment.