Skip to content

CMake for thirdparty libraries#374

Merged
spe-ciellt merged 3 commits intodevelopfrom
cmake-for-thirdparty-libraries
Mar 7, 2026
Merged

CMake for thirdparty libraries#374
spe-ciellt merged 3 commits intodevelopfrom
cmake-for-thirdparty-libraries

Conversation

@spe-ciellt
Copy link
Copy Markdown
Contributor

Update for CMake which is more best practices on how to include third party packages in CMake, see my description in #373 .

This will be set in Draft mode until it has been tested and cleaned up a bit. There are probably naming that is broken, commented out code, and pure errors/bugs/omissions in this.

Comments and suggestions are welcome.

Closes #373

@spe-ciellt spe-ciellt self-assigned this Mar 6, 2026
@spe-ciellt spe-ciellt added the buildsystem Updates to the buildsystem (CMake/CTest/CPack) label Mar 6, 2026
@rampageservices
Copy link
Copy Markdown
Contributor

The directory restructuring looks good — centralizing thirdparty build logic into thirdparty/*/CMakeLists.txt is cleaner than having it all in the root CMakeLists.txt.

A few things this PR will need before it can close #366:

dxflib symbol embedding (#366): add_library(dxflib_bundled STATIC) still produces a separate archive — its symbols won't end up in libgerbv.a, which is the original bug. Downstream consumers like pcb2gcode get undefined references. Two options:

  • Compile bundled sources directly into the gerbv target via target_sources() (what fix: embed bundled dxflib directly into libgerbv #369 did)
  • Use an OBJECT library and consume via target_link_libraries(gerbv PRIVATE dxflib_bundled) — CMake 3.12+ propagates object files from OBJECT libraries through normal linking

Warning suppression on bundled dxflib (#372): The bundled sources trigger a GCC false positive (-Wuninitialized on DL_HatchEdgeData default construction). With CMAKE_COMPILE_WARNING_AS_ERROR ON in the CI preset, this becomes a build error. Needs set_source_files_properties or SYSTEM includes to suppress.

tinyscheme _GNU_SOURCE (#370): Building with GCC 15 / -std=c23 on Linux fails because isascii() isn't exposed without _GNU_SOURCE. The tinyscheme target needs:

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
    target_compile_definitions(tinyscheme PRIVATE _GNU_SOURCE)
endif()

MSVC _USE_MATH_DEFINES: M_PI and M_1_PI (used by DEG2RAD/RAD2DEG in gerbv.h) aren't defined under MSVC strict ANSI. This needs a compile definition on compilation-flags:

if(MSVC)
    target_compile_definitions(compilation-flags INTERFACE _USE_MATH_DEFINES)
endif()

I'm closing #369 and #371 in favor of this restructuring — the fixes above cover what those PRs addressed. Happy to help if needed.

@spe-ciellt
Copy link
Copy Markdown
Contributor Author

_GNU_SOURCE: If you configure with --preset linux-gnu-gcc, _GNU_SOURCE is included in all compilations. Linux specific settings and Apple specific settings should preferably go into the respective toolchains files. Also valid for MSVC above.

I quickly looked up the isascii() and there seems to be more generic ways to fix it.

I have added the OBJECT flag now as well.

@spe-ciellt spe-ciellt marked this pull request as ready for review March 7, 2026 09:59
@spe-ciellt spe-ciellt force-pushed the cmake-for-thirdparty-libraries branch from 140e7fd to 237c7e8 Compare March 7, 2026 10:03
@rampageservices
Copy link
Copy Markdown
Contributor

Makes sense — replacing isascii() with a portable equivalent like ((unsigned)(c) <= 0x7f) in scheme.c would be cleaner than relying on _GNU_SOURCE. That patch would go into GERBV_PATCHES alongside the existing vendored dxflib patches.

One small thing: thirdparty/CMakeLists.txt is missing a trailing newline at EOF — some tools (GCC, Git, various linters) will warn about that.

Everything else looks good after the squash. The OBJECT library for dxflib is the right call. Will watch for the HAVE_LIBDXFLIB guard cleanup whenever that lands.

Thanks for pushing this through — the thirdparty restructuring is a big improvement.

Following directories got included from start:
* tinyscheme
* dxflib

Then realized that support files for gettext et al was in several places.
So extracted out the thirdparty of gettext support which is used in gerbv.

Reasoning;
There seems to be some files that usually should be, but isn't, bundled with
the Intl support which is added as copied in from somewhere. It is just two
header files, one which have the generic name of common.h.

Switched to use only the bundled DXF lib. That gives the same path and code
for all platforms.
Root cause: macOS filesystems are case-insensitive by default.
When compiling with -std=c++2b (C++23), system headers like <limits>
include <version> (the C++20 feature-test header). Clang searched
-Ithirdparty/dxflib first and found thirdparty/dxflib/VERSION —
which matched version on the case-insensitive filesystem — instead
of the real <version> standard header. On Linux the case-sensitive
filesystem meant VERSION ≠ version, so it worked fine.

Fix: Renamed thirdparty/dxflib/VERSION → thirdparty/dxflib/GERBV_PATCHES.
Also renamed a similar file in the tinyscheme directory.
@spe-ciellt spe-ciellt force-pushed the cmake-for-thirdparty-libraries branch from 237c7e8 to 6b8a361 Compare March 7, 2026 10:18
@spe-ciellt spe-ciellt merged commit b0a1a6c into develop Mar 7, 2026
3 checks passed
@spe-ciellt spe-ciellt deleted the cmake-for-thirdparty-libraries branch March 7, 2026 10:31
spe-ciellt added a commit that referenced this pull request Mar 7, 2026
… it is compiled in

@rampageservices noticed that when I merged in PR #374 all DXF support disappeared since
I also removed the flag. So this is to remove all the checks if DXF is compiled in or not.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

buildsystem Updates to the buildsystem (CMake/CTest/CPack)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reorganize CMake for third party libraries first

2 participants