I've been trying to add SPM support to an existing Objective-C project that supports 2 platforms: macOS and iOS.
The platform support is achieved by providing some source files that should only be compiled on iOS (they are dependent on UIKit) and some source files that should only be compiled in macOS (they are dependent on AppKit).
In the Xcode project it's done by specifying two targets. In the Podfile it's done via two patterns sources: spec.ios.source_files and spec.osx.source_files.
Does anybody know of the way to express this in Package.swift?
There's an ability to exclude the files (or provide the list of the sources) in the target, but there's no place to express that is should differ based on the platform I'm compiling package for.
Things that I've tried so far are:
#if os(...)in Package.swift (it always reports macOS, which makes sense since the Package.swift file is targeted for either macOS or Linux platforms)
- using the
.when(platforms: [.macOS])(but I've not found a clang flag that would tell the compiler to skip compilation for a file of particular name or matching some pattern)
- creating a separate target for the macOS and iOS (but then the package fails to compile on either platform because UIKit is unavailable on macOS and AppKit is unavailable on iOS)
- creating two packages in Package.swift (only one was taken into consideration, the other one was ignored)
If anyone has ever been struggling with similar issue, please share