Skip to content

fix: Include header files to fix compile errors.#368

Draft
eyal0 wants to merge 9 commits intogerbv:developfrom
eyal0:iwyu
Draft

fix: Include header files to fix compile errors.#368
eyal0 wants to merge 9 commits intogerbv:developfrom
eyal0:iwyu

Conversation

@eyal0
Copy link
Copy Markdown
Collaborator

@eyal0 eyal0 commented Mar 6, 2026

The windows compilation seems more sensitive to missing header files than linux compilation.

If dxf is not found on the system, include it in libgerbv.a.

This fixes gerbv#366.
@eyal0 eyal0 marked this pull request as draft March 6, 2026 00:52
@eyal0
Copy link
Copy Markdown
Collaborator Author

eyal0 commented Mar 6, 2026

This is a draft until the underlying PR #367 is in.

Copy link
Copy Markdown
Contributor

@rampageservices rampageservices left a comment

Choose a reason for hiding this comment

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

The math.h/_USE_MATH_DEFINES fix (commit 2) looks good.

A few notes on the dxflib bundling (commit 1):

COMPILE_WARNING_AS_ERROR OFF is a no-op. The project doesn't set -Werror or COMPILE_WARNING_AS_ERROR anywhere, so there's nothing to turn off. This can be dropped.

PUBLIC include dir on the OBJECT library is dead. OBJECT library usage requirements don't propagate through $<TARGET_OBJECTS:>, which is why you had to add the explicit target_include_directories(gerbv PRIVATE ...) in src/CMakeLists.txt. The PUBLIC on dxflib_bundled no longer does anything.

Inconsistent path style. The root CMakeLists.txt changed ${CMAKE_SOURCE_DIR}/thirdparty to the relative thirdparty, but src/CMakeLists.txt uses ${CMAKE_SOURCE_DIR}/thirdparty. Both work, but the inconsistency is unnecessary.

Simpler alternative: skip the OBJECT library entirely. Since the only goal is embedding dxflib symbols into libgerbv.a, you can just add the sources directly to the gerbv target:

# Root CMakeLists.txt — replace the add_library block:
if(NOT DXF_FOUND)
    set(DXFLIB_BUNDLED_SOURCES
        ${CMAKE_SOURCE_DIR}/thirdparty/dxflib/dl_dxf.cpp
        ${CMAKE_SOURCE_DIR}/thirdparty/dxflib/dl_writer_ascii.cpp)
    set(DXF_FOUND TRUE)
    set(DXFLIB_BUNDLED TRUE)
endif()

# src/CMakeLists.txt — in the DXF_FOUND block:
if(DXFLIB_BUNDLED)
    target_sources(gerbv PRIVATE ${DXFLIB_BUNDLED_SOURCES})
    target_include_directories(gerbv PRIVATE ${CMAKE_SOURCE_DIR}/thirdparty)
endif()

This eliminates the dxflib_bundled target, the OBJECT library, the dead PUBLIC include propagation, and the unnecessary COMPILE_WARNING_AS_ERROR OFF — while achieving the same result.

rampageservices

This comment was marked as duplicate.

@rampageservices
Copy link
Copy Markdown
Contributor

Thanks for identifying the root cause here @eyal0 — I've put up #369 as a simplified alternative that compiles the bundled dxflib sources directly into the gerbv library target via target_sources() instead of using an intermediate OBJECT library. This avoids the extra CMake target while achieving the same result (symbols embedded in libgerbv.a).

I've credited you as co-author on both commits.

@eyal0
Copy link
Copy Markdown
Collaborator Author

eyal0 commented Mar 6, 2026

COMPILE_WARNING_AS_ERROR OFF is a no-op. The project doesn't set -Werror or COMPILE_WARNING_AS_ERROR anywhere, so there's nothing to turn off. This can be dropped.

I think that this is not true.

ci.yml uses a preset for cmake: https://github.com/gerbv/gerbv/blob/develop/.github/workflows/ci.yaml#L65

That preset is here: https://github.com/gerbv/gerbv/blob/develop/CMakePresets.json#L4

It loads this: https://github.com/gerbv/gerbv/blob/develop/cmake/preset/linux-gnu-gcc.json#L3

Which loads the base.json: https://github.com/gerbv/gerbv/blob/develop/cmake/preset/base.json#L10

@eyal0
Copy link
Copy Markdown
Collaborator Author

eyal0 commented Mar 6, 2026

I do prefer your simple alternative. Go for it!

On some systems, like MVC++ and strict ANSI/C standards, M_PI and
others are not defined.
@rampageservices
Copy link
Copy Markdown
Contributor

You were right about COMPILE_WARNING_AS_ERROR — the preset chain sets it in base.json. I missed that during the initial review, apologies.

Updated #369 to handle it: the bundled dxflib sources now get -Wno-uninitialized / -Wno-maybe-uninitialized via set_source_files_properties so they don't trip -Werror while keeping it enforced for gerbv's own code.

Also moved the _USE_MATH_DEFINES fix from gerbv.h to a CMake-level compile definition on MSVC — the header approach doesn't work because draw.c, draw-gdk.c, and export-isel-drill.c include <math.h> before gerbv.h, so the define arrives too late.

@rampageservices
Copy link
Copy Markdown
Contributor

Heads up — spe-ciellt opened #374 to restructure all thirdparty library handling into thirdparty/*/CMakeLists.txt (tracking issue #373). He'd prefer that restructuring lands first, with other CMake PRs rebasing on top.

I've closed #369 in favor of that approach and left review comments on #374 noting the fixes that still need to go in (dxflib embedding, warning suppression, _GNU_SOURCE, MSVC _USE_MATH_DEFINES).

You may want to close this one too and coordinate with #374 directly, since the OBJECT library approach here would conflict with the new directory layout.

@eyal0
Copy link
Copy Markdown
Collaborator Author

eyal0 commented Mar 7, 2026

Leaving this here for reference: This branch of gerbv successfully compiles on both ubuntu and mingw32 windows. Also, the libgerbv.a created on both platforms works successfully in pcb2gcode.

The necessary changes are:

It might be possible to get M_PI et al in another way but _USE_MATH_DEFINES didn't work for me. Maybe WIN32 is sufficient? I didn't try that. G_PI and G_PI_2 exist but I think that it is less accurate: https://docs.gtk.org/glib/const.PI.html . Mine are copy-pasted from math.h.

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