Skip to content

CMake: define digidocpp_EXPORTS for static builds#723

Open
lnagel wants to merge 1 commit intoopen-eid:masterfrom
namespace-ee:fix-static-exports
Open

CMake: define digidocpp_EXPORTS for static builds#723
lnagel wants to merge 1 commit intoopen-eid:masterfrom
namespace-ee:fix-static-exports

Conversation

@lnagel
Copy link

@lnagel lnagel commented Mar 16, 2026

Summary

  • When BUILD_SHARED_LIBS=OFF on Windows, CMake does not define digidocpp_EXPORTS on the digidocpp target (only done automatically for shared libraries)
  • This causes DIGIDOCPP_EXPORT in Exports.h to resolve to __declspec(dllimport) instead of __declspec(dllexport)
  • Applies the same pattern already used for digidocpp_util and digidocpp_tsl (line 83-84): sets COMPILE_DEFINITIONS digidocpp_EXPORTS on the target for static builds

Test plan

  • Build with BUILD_SHARED_LIBS=OFF on Windows — DIGIDOCPP_EXPORT should resolve to __declspec(dllexport)
  • Build with BUILD_SHARED_LIBS=ON on Windows — no change, CMake defines digidocpp_EXPORTS automatically

@lnagel lnagel force-pushed the fix-static-exports branch from bfd0d1d to d47e4dc Compare March 16, 2026 14:16
@lnagel lnagel force-pushed the fix-static-exports branch from d47e4dc to abab31b Compare March 16, 2026 19:23
@lnagel lnagel requested a review from metsma March 19, 2026 06:14
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.
@lnagel lnagel force-pushed the fix-static-exports branch from abab31b to de1656b Compare March 20, 2026 16:47
@lnagel lnagel requested a review from metsma March 20, 2026 16:49
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)
Copy link
Contributor

@metsma metsma Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it will cause any issues but there is on line 83-84 digidocpp_EXPORTS defines.

set_target_properties(digidocpp_util digidocpp_tsl PROPERTIES
    COMPILE_DEFINITIONS digidocpp_EXPORTS

maybe add to line 83

target_compile_definitions(digidocpp_tsl PUBLIC $<IF:$<BOOL:BUILD_SHARED_LIBS>,digidocpp_EXPORTS,digidocpp_STATIC>)
target_compile_definitions(digidocpp_util PUBLIC $<IF:$<BOOL:BUILD_SHARED_LIBS>,digidocpp_EXPORTS,digidocpp_STATIC>)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants