From 88a1ddf3906e3c5c69d525cfefd712103296d16b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=BCtzel?= Date: Tue, 28 Nov 2023 15:46:31 +0100 Subject: [PATCH] GraphBLAS: Don't use dllexport or dllimport attribute for static library Facilitate using the static GraphBLAS library on Windows by adding the necessary preprocessor definition to the CMake target and pkg-config file. --- GraphBLAS/CMakeLists.txt | 5 +++++ GraphBLAS/Config/GraphBLAS.h.in | 6 +++--- GraphBLAS/Config/GraphBLAS.pc.in | 1 + GraphBLAS/Include/GraphBLAS.h | 6 +++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/GraphBLAS/CMakeLists.txt b/GraphBLAS/CMakeLists.txt index 0c10d6c299..aa8c47fed0 100644 --- a/GraphBLAS/CMakeLists.txt +++ b/GraphBLAS/CMakeLists.txt @@ -304,6 +304,11 @@ if ( BUILD_STATIC_LIBS ) target_compile_definitions ( GraphBLAS_static PRIVATE "SUITESPARSE_CUDA" ) endif ( ) + if ( WIN32 ) + # On Windows, don't use __declspec ( dllimport ) for static library. + target_compile_definitions ( GraphBLAS PUBLIC GB_STATIC ) + endif ( ) + if ( NOT NJIT ) # Make sure compressed sources are built before library add_dependencies ( GraphBLAS_static grb_jitpackage ) diff --git a/GraphBLAS/Config/GraphBLAS.h.in b/GraphBLAS/Config/GraphBLAS.h.in index 726cd52f38..ecb71611b3 100644 --- a/GraphBLAS/Config/GraphBLAS.h.in +++ b/GraphBLAS/Config/GraphBLAS.h.in @@ -96,9 +96,9 @@ #define GB_GLOBAL extern __declspec ( dllexport ) #elif defined ( GB_STATIC ) // Compiling the user application on Windows, importing symbols from - // a static GraphBLAS library on Windows. The user application must do: - // #define GB_STATIC - // #include "GraphBLAS.h" + // a static GraphBLAS library on Windows. The user application must + // define GB_STATIC (e.g., with the pre-processor flag -DGB_STATIC) for + // all compilation units that include "GraphBLAS.h". #define GB_GLOBAL extern #else // Compiling the user application on Windows, importing symbols from diff --git a/GraphBLAS/Config/GraphBLAS.pc.in b/GraphBLAS/Config/GraphBLAS.pc.in index 9c6a50daee..05d5dfb76b 100644 --- a/GraphBLAS/Config/GraphBLAS.pc.in +++ b/GraphBLAS/Config/GraphBLAS.pc.in @@ -17,3 +17,4 @@ Requires.private: @GRAPHBLAS_STATIC_MODULES@ Libs: -L${libdir} -lgraphblas Libs.private: @GRAPHBLAS_STATIC_LIBS@ Cflags: -I${includedir} +Cflags.private: -DGB_STATIC diff --git a/GraphBLAS/Include/GraphBLAS.h b/GraphBLAS/Include/GraphBLAS.h index 0f51b036cf..506dd9ad63 100644 --- a/GraphBLAS/Include/GraphBLAS.h +++ b/GraphBLAS/Include/GraphBLAS.h @@ -96,9 +96,9 @@ #define GB_GLOBAL extern __declspec ( dllexport ) #elif defined ( GB_STATIC ) // Compiling the user application on Windows, importing symbols from - // a static GraphBLAS library on Windows. The user application must do: - // #define GB_STATIC - // #include "GraphBLAS.h" + // a static GraphBLAS library on Windows. The user application must + // define GB_STATIC (e.g., with the pre-processor flag -DGB_STATIC) for + // all compilation units that include "GraphBLAS.h". #define GB_GLOBAL extern #else // Compiling the user application on Windows, importing symbols from