Skip to content

Fix macOS CMake build: emit INTERFACE libraries for header-only support targets#1444

Draft
KHicketts wants to merge 1 commit into
google:mainfrom
KHicketts:interface
Draft

Fix macOS CMake build: emit INTERFACE libraries for header-only support targets#1444
KHicketts wants to merge 1 commit into
google:mainfrom
KHicketts:interface

Conversation

@KHicketts

@KHicketts KHicketts commented Jul 15, 2026

Copy link
Copy Markdown

Hello! I'm new to crubit!

I suspect, since these CMake files are generated this is not the PR that want to go in but perhaps a generation script needs changing instead? Would it be possible to amend this so I can build on Mac?

Problem

The CMake build fails on macOS for the header-only support libraries. They're declared as STATIC archives, but they have no .cc sources only headers. Apple's ar refuses to create an empty archive:

ar: no archive members specified

Fix Proposal

Someone else would need to update the script that generates these CMake files.

If header only targets use CMake INTERFACE instead of STATIC
https://cmake.org/cmake/help/latest/command/add_library.html#interface-libraries
Then the archive step is skipped but includes and link dependencies are still propagated.

@@ -4,12 +4,9 @@

# Automatically @generated CMakeLists.txt.

@KHicketts KHicketts Jul 15, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'm guessing since these are autogenerated, the fix is actually in some generation script that I don't have access to?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You have guessed correctly! Originally I wanted to open source our generation script but it's relatively entangled with our internal tooling atm and I don't have a good fix for it. But I can certainly reflect this change upstream and post here once the CMake is updated.

If you could help me out with understanding this fix that would be appreciated. My CMake knowledge is relatively limited. My understanding was PUBLIC was a superset of functionality of INTERFACE. Is that correct? And if so, why does swapping to INTERFACE fix the CMake build on mac?

Thank you for the PR!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

:) thanks for the fast response!

That's a very fair question. It took me a while to understand it as well.

add_library(blah INTERFACE) [instead of STATIC] is the bit that actually fixes the build. [stops the empty archive creation]

You are correct about PUBLIC ----> PUBLIC = PRIVATE (let's .cc files see path) + INTERFACE (exposes path to consumers)

The PUBLIC -> INTERFACE changes are required because we changed the library to INTERFACE - we get a configuration error otherwise. CMake won't let you keep it as public.

In reality the PRIVATE part wasn't doing anything. It only applies to compiling the libraries own cc files and there weren't any so it's safe to drop it. PUBLIC - PRIVATE = INTERFACE.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation I was missing the change in behavior from swapping STATIC -> INTERFACE. I've updated our CMakeLists.txt and they should now use INTERFACE everywhere in place of STATIC/PUBLIC.

It's exciting to hear you're trying out Crubit on mac. As you can see we have not done extensive testing for it yet. Is mac the host platform or the target platform?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks very much Ethan :). Mac is just my dev box. I wanted to look into getting this working with gcc as an experiment. Would be great to chat about it if you have bandwidth. 👀 It's easy to find a Hicketts on LinkedIn.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would be happy to do that! I'll reach out on LinkedIn. We also recently started a discord server, so it's easier for us to talk to OSS users: https://discord.gg/SpBTWJrH

@KHicketts KHicketts changed the title question about interfaces Fix macOS CMake build: emit INTERFACE libraries for header-only support targets Jul 15, 2026
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