Skip to content

fix(build): guard CG type redefinitions against libs-base CFCGTypes.h#15

Open
DTW-Thalion wants to merge 1 commit into
gnustep:masterfrom
DTW-Thalion:fix/cg-types-redefinition-guards
Open

fix(build): guard CG type redefinitions against libs-base CFCGTypes.h#15
DTW-Thalion wants to merge 1 commit into
gnustep:masterfrom
DTW-Thalion:fix/cg-types-redefinition-guards

Conversation

@DTW-Thalion
Copy link
Copy Markdown

Problem

Building libs-opal on Linux against a modern libs-base install fails with:

../../Headers/CoreGraphics/CGGeometry.h:44:3: error: redefinition of enumerator 'CGRectMinXEdge'
../../Headers/CoreGraphics/CGGeometry.h:332:22: error: redefinition of 'NSRectToCGRect'
../../Headers/CoreGraphics/CGAffineTransform.h:37:16: error: redefinition of 'CGAffineTransform'
... (12 errors total)

Root cause: libs-base/Headers/CoreFoundation/CFCGTypes.h (transitively included via <Foundation/NSGeometry.h>) already declares CGPoint, CGSize, CGRect, the CGRectMinXEdge..CGRectMaxYEdge anonymous enum, and struct CGAffineTransform. libs-opal's own headers then redeclare the same types unconditionally, which is a hard error under clang and gcc.

The NSRect/NSPoint/NSSize ↔ CG conversion helpers (NSRectToCGRect, NSRectFromCGRect, NSPointToCGPoint, NSPointFromCGPoint, NSSizeToCGSize, NSSizeFromCGSize) are also provided by NSGeometry.h when CFCGTypes.h is present, and collide for the same reason.

Fix

Detect libs-base's CFCGTypes.h via its own include guard _CFCGTypes_h_GNUSTEP_BASE_INCLUDE and skip the duplicate declarations in CGGeometry.h and CGAffineTransform.h.

CGRectEdge itself is not provided by CFCGTypes.h (only the enum values are), so the typedef int CGRectEdge; is always emitted — otherwise CGGeometry.h line 140 would reference an undeclared type.

Environment

  • Ubuntu 24.04, clang 18.1.3
  • libs-base HEAD installed to /usr/local
  • libs-opal built via make CC=clang CXX=clang++

Platform impact

  • Linux/clang: now builds cleanly (0 errors, all existing warnings unchanged).
  • macOS: untouched — __APPLE__ path defines its own CG types and doesn't include CFCGTypes.h.
  • Windows/MSYS2: untouched — current MSYS2 clang builds don't expose CFCGTypes.h through this path either. No-op on that environment.

Test plan

  • Clean build of libs-opal against installed libs-base on Ubuntu 24.04 + clang 18.1.3
  • libs-quartzcore (downstream consumer) still builds against the patched libs-opal
  • macOS spot-check (I don't have a Mac to verify locally; the change is conditional on _CFCGTypes_h_GNUSTEP_BASE_INCLUDE which isn't defined under Apple's CoreGraphics)

libs-base's Headers/CoreFoundation/CFCGTypes.h (pulled in transitively
via Foundation/NSGeometry.h) already declares CGPoint, CGSize, CGRect,
the CGRectMinXEdge..CGRectMaxYEdge anonymous enum, and struct
CGAffineTransform. Redefining them a second time in libs-opal's
CGGeometry.h / CGAffineTransform.h is a hard error on clang 18 and
gcc-objc.

Detect libs-base's CFCGTypes.h via its own include guard
(_CFCGTypes_h_GNUSTEP_BASE_INCLUDE) and skip the duplicates. CGRectEdge
itself is NOT provided by CFCGTypes.h, so that typedef is always
emitted. The NSRect/NSPoint/NSSize conversion helpers (NSRectToCGRect
etc.) are also provided by NSGeometry.h when CFCGTypes.h is present,
so they are skipped in the same block.

No functional change on Windows / MSYS2 where CFCGTypes.h is not in
the include path — those builds see the existing definitions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@pkgdemon
Copy link
Copy Markdown
Contributor

I believe this is fixed now with #16 @DTW-Thalion can you let me know if I missed anything?

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants