From de1656bda34e455599b290158243ef569a0978c3 Mon Sep 17 00:00:00 2001 From: Lenno Nagel Date: Mon, 16 Mar 2026 14:31:09 +0200 Subject: [PATCH 1/2] CMake: add digidocpp_STATIC define for static library builds When BUILD_SHARED_LIBS=OFF on Windows, DIGIDOCPP_EXPORT in Exports.h defaults to __declspec(dllimport), which is incorrect for both compiling the library and for consumers linking the static archive. Add a digidocpp_STATIC check in Exports.h that sets DIGIDOCPP_EXPORT to empty. Define digidocpp_STATIC as a PUBLIC compile definition on digidocpp, digidocpp_tsl, and digidocpp_util so downstream consumers also get the correct (empty) export macro. Also remove the duplicate static targets install, already covered by the install(TARGETS ...) export set, and fix if(NOT ...) style. --- src/CMakeLists.txt | 8 ++++---- src/Exports.h | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 31137bfda..ab3a533ad 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -255,8 +255,11 @@ if(SWIG_FOUND) endif() endif() -if(NOT ${BUILD_SHARED_LIBS}) +if(NOT BUILD_SHARED_LIBS) set(STATIC_TARGETS minizip digidocpp_tsl digidocpp_util) + target_compile_definitions(digidocpp PUBLIC digidocpp_STATIC) + target_compile_definitions(digidocpp_tsl PUBLIC digidocpp_STATIC) + target_compile_definitions(digidocpp_util PUBLIC digidocpp_STATIC) endif() install(TARGETS digidocpp ${STATIC_TARGETS} @@ -390,9 +393,6 @@ if( FRAMEWORK ) COMMAND zip -r ${PROJECT_BINARY_DIR}/libdigidocpp-dbg_${VERSION}$ENV{VER_SUFFIX}.zip libdigidocpp.dSYM ) else() - if(NOT ${BUILD_SHARED_LIBS}) - install( TARGETS minizip digidocpp_tsl digidocpp_util DESTINATION ${CMAKE_INSTALL_LIBDIR} ) - endif() if( BUILD_TOOLS ) install( TARGETS digidoc-tool DESTINATION ${CMAKE_INSTALL_BINDIR} ) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/digidoc-tool.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 ) diff --git a/src/Exports.h b/src/Exports.h index 6bbc7bb85..e1466ef66 100644 --- a/src/Exports.h +++ b/src/Exports.h @@ -21,7 +21,9 @@ #ifdef WIN32 #include - #ifdef digidocpp_EXPORTS + #ifdef digidocpp_STATIC + #define DIGIDOCPP_EXPORT + #elifdef digidocpp_EXPORTS #define DIGIDOCPP_EXPORT __declspec(dllexport) #else #define DIGIDOCPP_EXPORT __declspec(dllimport) From e53d5c47204bbda901f124b61574c7b080578a5b Mon Sep 17 00:00:00 2001 From: Lenno Nagel Date: Tue, 24 Mar 2026 15:56:40 +0200 Subject: [PATCH 2/2] Use generator expression for digidocpp_EXPORTS/digidocpp_STATIC Replace the unconditional digidocpp_EXPORTS on digidocpp_tsl and digidocpp_util with a generator expression that selects digidocpp_EXPORTS for shared builds and digidocpp_STATIC for static builds. This avoids having both defines set simultaneously. --- src/CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ab3a533ad..d0884d93c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -81,9 +81,10 @@ add_library(digidocpp_tsl STATIC ) set_target_properties(digidocpp_util digidocpp_tsl PROPERTIES - COMPILE_DEFINITIONS digidocpp_EXPORTS POSITION_INDEPENDENT_CODE YES ) +target_compile_definitions(digidocpp_tsl PUBLIC $,digidocpp_EXPORTS,digidocpp_STATIC>) +target_compile_definitions(digidocpp_util PUBLIC $,digidocpp_EXPORTS,digidocpp_STATIC>) target_include_directories(digidocpp_tsl PUBLIC $) @@ -258,8 +259,6 @@ endif() if(NOT BUILD_SHARED_LIBS) set(STATIC_TARGETS minizip digidocpp_tsl digidocpp_util) target_compile_definitions(digidocpp PUBLIC digidocpp_STATIC) - target_compile_definitions(digidocpp_tsl PUBLIC digidocpp_STATIC) - target_compile_definitions(digidocpp_util PUBLIC digidocpp_STATIC) endif() install(TARGETS digidocpp ${STATIC_TARGETS}