Create a CXX package without duplicate headers

How would one create a C/C++/Objc SPM package without duplicating the public header files? You're supposed to put them in the include folder, but is there a way to use a module map file to simply reference the public headers instead?

I realize I can just move the headers there, but if I have public and private headers now I have header files in two different places. And for the sake of discussion, I just want to know if this is possible without actually putting any headers in the include folder.

you can create a soft link in your include folder

That doesn't seem like a good idea :/

@NeoNacho can you offer any guidance?

Symlinks into include is really all we have today.

That is unfortunate :confused: Would it be a ton of work to get relative parent-folder paths working?

And to be clear, you mean putting the headers in include and adding symlinks outside the folder? Or the other way around?

I think he means the other way around. Your Swift package include directory would have soft-links to the required headers you need.

1 Like

Not entirely sure, tbh, but I think it would ideally go along with new manifest APIs so that it would work for both generated module maps as well as manually created ones.

Either way should work, but for your case, it would probably be better to keep your headers where they are and just symlink all the public ones in include so that you don't have to reorganize your headers. This would also makes it easiest if SwiftPM ever does support a different model for public headers because you could just delete the include directory instead of having to move headers around again.

Gotcha, gotcha. Thanks for the help, all of you!