Skip to content

CMake: define digidocpp_EXPORTS for static builds#723

Open
lnagel wants to merge 2 commits intoopen-eid:masterfrom
namespace-ee:fix-static-exports
Open

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

Conversation

@lnagel
Copy link
Copy Markdown

@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
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.
@lnagel lnagel requested a review from metsma March 24, 2026 13:58
@metsma
Copy link
Copy Markdown
Contributor

metsma commented Mar 25, 2026

Something is still missing:

LINK Pass 1: command "C:\PROGRA~1\MICROS~2\2022\ENTERP~1\VC\Tools\MSVC\1444~1.352\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\digidoc_java.dir\objects1.rsp /out:digidoc_javad.dll /implib:digidoc_javad.lib /pdb:D:\a\libdigidocpp\libdigidocpp\x64Debug\src\digidoc_javad.pdb /dll /version:0.0 /guard:cf /machine:x64 /debug /INCREMENTAL digidocppd.lib digidocpp_utild.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\digidoc_java.dir/intermediate.manifest CMakeFiles\digidoc_java.dir/manifest.res" failed (exit code 1120) with the following output:
   Creating library digidoc_javad.lib and object digidoc_javad.exp
libdigidocppJAVA_wrap.cxx.obj : error LNK2001: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const digidoc::Signature::POLv1" (?POLv1@Signature@digidoc@@2V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@B)
libdigidocppJAVA_wrap.cxx.obj : error LNK2001: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const digidoc::Signature::POLv2" (?POLv2@Signature@digidoc@@2V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@B)

@lnagel
Copy link
Copy Markdown
Author

lnagel commented Mar 25, 2026

Which command is this from? I see that CI checks are all successful. I have personally no way to replicate it.

@metsma
Copy link
Copy Markdown
Contributor

metsma commented Mar 25, 2026

Seems like powershell hides windows build failures.
I discovered warning in github actions and then looked the windows builds
No files were found with the provided path: ./*.msi. No artifacts will be uploaded.
Maybe we can add one simple static windows build to verify all of this to avoid future breakage?

@lnagel
Copy link
Copy Markdown
Author

lnagel commented Mar 25, 2026

I agree that a static build on GitHub actions would be a good idea. Maybe if you add this on master then I can rebase?

@metsma
Copy link
Copy Markdown
Contributor

metsma commented Mar 25, 2026

We are currently in code freeze

@lnagel
Copy link
Copy Markdown
Author

lnagel commented Mar 25, 2026

What would you suggest then?

@metsma
Copy link
Copy Markdown
Contributor

metsma commented Mar 26, 2026

If you do not mind I can use your branch?

@lnagel
Copy link
Copy Markdown
Author

lnagel commented Mar 26, 2026

Yes, both of my PRs have maintainer edits enabled.

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