From ba7795ff8929f06fd5a7a61cb7efa07877acea41 Mon Sep 17 00:00:00 2001 From: Lenno Nagel Date: Mon, 16 Mar 2026 14:31:09 +0200 Subject: [PATCH 1/4] 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 a617eed5c..bf2947424 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -261,8 +261,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} @@ -398,9 +401,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 0d89fa9e94eeeff0f93fbaaf8885db93e5b2bbf6 Mon Sep 17 00:00:00 2001 From: Lenno Nagel Date: Tue, 24 Mar 2026 15:56:40 +0200 Subject: [PATCH 2/4] 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 bf2947424..c7e965f3b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -85,9 +85,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 $) @@ -264,8 +265,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} From 99fe8cfedd52883bd3a6b60c934f262e0529a837 Mon Sep 17 00:00:00 2001 From: Raul Metsma Date: Mon, 1 Jun 2026 10:35:01 +0300 Subject: [PATCH 3/4] Do not leak digidocpp_EXPORTS to modules Signed-off-by: Raul Metsma --- src/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c7e965f3b..ff85c48f8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -87,8 +87,8 @@ add_library(digidocpp_tsl STATIC set_target_properties(digidocpp_util digidocpp_tsl PROPERTIES 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_compile_definitions(digidocpp_tsl PRIVATE $,digidocpp_EXPORTS,digidocpp_STATIC>) +target_compile_definitions(digidocpp_util PRIVATE $,digidocpp_EXPORTS,digidocpp_STATIC>) target_include_directories(digidocpp_tsl PUBLIC $) From 23ba11fb947237397091afa2fb21cb1c5e1ff4a5 Mon Sep 17 00:00:00 2001 From: Raul Metsma Date: Fri, 29 May 2026 10:00:11 +0300 Subject: [PATCH 4/4] Load config from correct location with static build IB-8961 Signed-off-by: Raul Metsma --- .github/workflows/build.yml | 39 +++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 4 +--- src/util/File.cpp | 39 ++++++++++++++++--------------------- src/util/File.h | 3 --- 4 files changed, 57 insertions(+), 28 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 68482f2a9..074ca0898 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -277,6 +277,45 @@ jobs: with: name: msi_${{ matrix.toolset }}_${{ matrix.platform }} path: ./*.msi + static: + name: Static build on Windows + needs: python + runs-on: windows-2025-vs2026 + env: + VCPKG_BINARY_SOURCES: clear;files,${{ github.workspace }}/vcpkg_cache,readwrite + CXXFLAGS: '/D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR' + steps: + - name: Checkout + uses: actions/checkout@v6 + - name: Cache vcpkg + uses: actions/cache@v5 + with: + path: ${{ github.workspace }}/vcpkg_cache + key: vcpkg-static-x64-${{ hashFiles('vcpkg.json') }} + - name: Install dependencies + run: winget install --silent --accept-source-agreements --accept-package-agreements swig + - name: Download Python + uses: actions/download-artifact@v8 + with: + name: python + path: python/ + - uses: actions/setup-java@v5 + with: + distribution: 'temurin' + java-version: '17' + - name: Build + run: | + $swig = (Get-Item "$env:LOCALAPPDATA\Microsoft\WinGet\Links\swig.exe").Target + cmake -B build -S . ` + -DCMAKE_TOOLCHAIN_FILE="C:/vcpkg/scripts/buildsystems/vcpkg.cmake" ` + -DVCPKG_TARGET_TRIPLET=x64-windows-static-md ` + -DVCPKG_MANIFEST_FEATURES=tests ` + -DBUILD_SHARED_LIBS=OFF ` + -DSWIG_EXECUTABLE="$swig" ` + -DPython3_ROOT_DIR="${{ github.workspace }}/python/x64" ` + -DCMAKE_DISABLE_FIND_PACKAGE_Doxygen=YES + cmake --build build --config RelWithDebInfo + cmake --build build --config RelWithDebInfo --target check pages: name: Deploy pages if: github.repository == 'open-eid/libdigidocpp' && contains(github.ref, 'master') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ff85c48f8..fa7bcc8bd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -84,11 +84,9 @@ add_library(digidocpp_tsl STATIC XMLDocument.h ) -set_target_properties(digidocpp_util digidocpp_tsl PROPERTIES - POSITION_INDEPENDENT_CODE YES -) target_compile_definitions(digidocpp_tsl PRIVATE $,digidocpp_EXPORTS,digidocpp_STATIC>) target_compile_definitions(digidocpp_util PRIVATE $,digidocpp_EXPORTS,digidocpp_STATIC>) +set_target_properties(digidocpp_util digidocpp_tsl PROPERTIES POSITION_INDEPENDENT_CODE YES) target_include_directories(digidocpp_tsl PUBLIC $) diff --git a/src/util/File.cpp b/src/util/File.cpp index c57643f15..32f1a9cb6 100644 --- a/src/util/File.cpp +++ b/src/util/File.cpp @@ -19,6 +19,7 @@ #include "File.h" +#include "../Container.h" #include "log.h" #include @@ -54,17 +55,15 @@ namespace fs = filesystem; #define f_stat _wstat64 #define f_utime _wutime64 using f_statbuf = struct _stat64; -using f_utimbuf = struct __utimbuf64; #else #define f_stat stat #define f_utime utime using f_statbuf = struct stat; -using f_utimbuf = struct utimbuf; #endif stack File::tempFiles; -static string decodeName(fs::path path) +static string decodeName(const fs::path &path) { auto name = path.u8string(); return {reinterpret_cast(name.data()), name.size()}; @@ -72,12 +71,22 @@ static string decodeName(fs::path path) string File::confPath() { -#if defined(__APPLE__) +#ifdef __APPLE__ return frameworkResourcesPath("ee.ria.digidocpp"); -#elif defined(_WIN32) && defined(_DEBUG) - return dllPath("digidocppd.dll"); -#elif defined(_WIN32) - return dllPath("digidocpp.dll"); +#elifdef _WIN32 + if(HMODULE handle {}; + GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | + GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + reinterpret_cast(&digidoc::terminate), + &handle)) + { + wstring path(MAX_PATH, 0); + path.resize(GetModuleFileNameW(handle, path.data(), DWORD(path.size()))); + if(size_t pos = path.find_last_of(L"/\\"); pos != wstring::npos) + path.resize(pos); + return decodeName(std::move(path)); + } + return {}; #else fs::path result; if(char *var = getenv("SNAP")) @@ -107,20 +116,6 @@ bool File::fileExists(const string& path) return fs::is_regular_file(encodeName(path)); } -#ifdef _WIN32 -string File::dllPath(string_view dll) -{ -#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) - HMODULE handle = GetModuleHandleW(encodeName(dll).c_str()); - wstring path(MAX_PATH, 0); - path.resize(GetModuleFileNameW(handle, path.data(), DWORD(path.size()))); - return decodeName(fs::path(path).parent_path()); -#else - return {}; -#endif -} -#endif - /** * Returns last modified time * diff --git a/src/util/File.h b/src/util/File.h index ccc24f1e8..626004720 100644 --- a/src/util/File.h +++ b/src/util/File.h @@ -53,9 +53,6 @@ namespace digidoc static std::vector hexToBin(std::string_view in); private: -#ifdef _WIN32 - static std::string dllPath(std::string_view dll); -#endif #ifdef __APPLE__ static std::string frameworkResourcesPath(std::string_view name); #endif