Migrating an existing Xcode library to SPM

I'm trying to migrate an existing mixed (C++, C, Swift) library to SPM without breaking the existing Xcode-based setup. I managed to get pretty far by splitting the C, C++ and Swift code into modules, but I still have one problem. You'd have to actually import those modules before using them. Since Xcode is using the bridging header, it doesn't require any imports and symbols are available top level. Which means that for SPM, I need the imports and for Xcode, I don't, which breaks my initial plan of not breaking the Xcode setup.

Now, I might have found a couple of solutions:

  1. Create targets in the Xcode proj for C and C++ source code, essentially splitting the code per language like SPM does it. This is a bit hard to do because it fundamentally changes the way things are build.
  2. Use @_exported import MyCorCppModule in a file used only by SPM. This feels like a hack and there's a lot of controversy around it.

But, do I have any other options? If not, what's the better approach?

The package manager identifies its builds (including in its generated Xcode projects) with the SWIFT_PACKAGE compilation condition. You should be able to accomplish what you want with this:

#if SWIFT_PACKAGE
import CModule
#endif

Thanks for the reply. I'd say this is better than adding all those targets, it still forces me to edit all the files and add a bit of extra compilation conditional logic, but that's fine I guess.