Fix macOS CMake build: emit INTERFACE libraries for header-only support targets#1444
Fix macOS CMake build: emit INTERFACE libraries for header-only support targets#1444KHicketts wants to merge 1 commit into
Conversation
| @@ -4,12 +4,9 @@ | |||
|
|
|||
| # Automatically @generated CMakeLists.txt. | |||
There was a problem hiding this comment.
I'm guessing since these are autogenerated, the fix is actually in some generation script that I don't have access to?
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
:) 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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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.