Reputation: 10383
We have a Filters
framework that contains many image processing filters (written in Swift and Metal) and the resources they require (like ML models and static images). But not every app we have uses all the filters in Filters
. Rather we want to only build and bundle the required filters and resources that are needed by the app.
The only way we can think of to achieve that is to create different framework targets in Xcode, one for each app. But that would require that the Filters
framework project “knows” all of its consumers (apps) and we would rather like to avoid that. Especially since the filters are in a separate repository.
Is there a way to, for instance, pass some kind of configuration file to the framework that is used at build time to decide which files to build and bundle?
Upvotes: 0
Views: 1143
Reputation: 711
You can use Target Membership to assign files into specific targets. See image below.
Make sure you are on the File Inspector
tab on the right side of Xcode. Select the files you want to limit to a target and in the Target Membership
area, you can select which target the selected file belongs to or don't belong to. For public resources, make sure to select public
for the visibility scope.
For files that don't require compilation, e.g. image files, once you've selected the target membership, the file will be automatically added to the Build Phases
' Copy Bundle Resources
area.
Alternative One
Alternatively, you can use add a Copy Files Phase
in the Build Phases
. With the Copy Files Phase
, you can copy files to subdirectories instead of the root of the framework bundle.
Alternative Two
Yet another way is to add a Run Script Phase
in the Build Phases
. The script can be in any language but usually shell script. You can do whatever you need in the script including compiling code manually but you need to know where the files goes by using environment variables and placed the files in the correct location. I think this will be the most manual and most hassle to use for selecting files based on targets.
Alternative Three
If you really want to go fancy, you can even break down all the components into targets and use Aggregate target
to tie the different components into the target you are building for. I would not recommend this usually and reserve this for very special needs that other methods could not achieve.
Upvotes: 1