Skip to content

fix: embed bundled dxflib directly into libgerbv#369

Closed
rampageservices wants to merge 1 commit intogerbv:developfrom
SourceParts:fix/dxflib-libgerbv-bundling
Closed

fix: embed bundled dxflib directly into libgerbv#369
rampageservices wants to merge 1 commit intogerbv:developfrom
SourceParts:fix/dxflib-libgerbv-bundling

Conversation

@rampageservices
Copy link
Copy Markdown
Contributor

@rampageservices rampageservices commented Mar 6, 2026

Summary

When system dxflib is absent, the bundled copy is built as a separate STATIC library (dxflib_bundled) and linked via the compilation-flags INTERFACE target. The gerbv executable links fine, but libgerbv.a never embeds the dxflib object files — they show up as *UND*, breaking downstream consumers like pcb2gcode.

This PR:

  • Replaces the separate dxflib_bundled STATIC library with a DXFLIB_BUNDLED_SOURCES variable
  • Adds the bundled sources directly to the gerbv library target via target_sources(), so symbols are embedded in libgerbv.a
  • Suppresses -Wno-uninitialized on the bundled dxflib files (GCC false positive on DL_HatchEdgeData default construction, tracked in Bundled dxflib: DL_HatchEdgeData triggers -Wuninitialized with -Werror #372)
  • Defines _USE_MATH_DEFINES on MSVC via compilation-flags so M_PI/M_1_PI (used by DEG2RAD/RAD2DEG) are available under strict ANSI conformance — a header-level define in gerbv.h doesn't work because draw.c, draw-gdk.c, and export-isel-drill.c include <math.h> before gerbv.h

Fixes #366

Approach

@eyal0's PR #368 identified the same root cause and proposed an OBJECT library approach. This PR takes a simpler path: compiling the bundled .cpp files directly into libgerbv via target_sources(), avoiding the extra CMake target entirely.

Test plan

  • cmake --build with no system dxflib → bundled sources compile into libgerbv
  • nm libgerbv.a | grep dl_dxf → symbols are defined (T), not undefined (U)
  • cmake --build with system dxflib installed → pkg-config path still works
  • CI passes with CMAKE_COMPILE_WARNING_AS_ERROR ON (no dxflib warnings)
  • MSVC build → M_PI resolves via the compile definition

@eyal0
Copy link
Copy Markdown
Collaborator

eyal0 commented Mar 6, 2026

That math fix isn't working for me yet, don't merge it yet please.

When system dxflib is absent, the bundled copy was built as a separate
STATIC library and linked via the compilation-flags INTERFACE target.
This works for the gerbv executable, but libgerbv.a never embeds the
dxflib object files — they appear as undefined symbols, breaking
downstream consumers like pcb2gcode.

Replace the separate dxflib_bundled STATIC library with a
DXFLIB_BUNDLED_SOURCES list that gets compiled directly into the gerbv
library target via target_sources().  This ensures the dxflib symbols
are part of libgerbv.a itself.

The bundled sources now inherit -Wall from compilation-flags, which
surfaces GCC false-positive -Wuninitialized warnings in
DL_HatchEdgeData.  Suppress these per-file since we don't maintain the
dxflib code (tracked in gerbv#372).

Also define _USE_MATH_DEFINES on MSVC via compilation-flags so that
M_PI/M_1_PI (used by DEG2RAD/RAD2DEG in gerbv.h) are available under
strict ANSI conformance.  A header-level define doesn't work because
several source files include <math.h> before gerbv.h.

Fixes gerbv#366

Co-Authored-By: eyal0 <109809+eyal0@users.noreply.github.com>
@rampageservices
Copy link
Copy Markdown
Contributor Author

Closing in favor of #374 — spe-ciellt is restructuring the thirdparty CMake layout (#373) and it makes sense to land that first.

The bug fixes from this PR (dxflib symbol embedding, warning suppression, MSVC _USE_MATH_DEFINES) are noted on #374 for incorporation. The target_sources() approach for dxflib embedding still applies — #374's current STATIC library won't fix the undefined symbols in libgerbv.a.

@spe-ciellt spe-ciellt added the wontfix This will not be worked on label Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wontfix This will not be worked on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libgerbv is not installing correctly

3 participants