Search code examples
iosxcodeapplescript

Is it possible to script adding a directory of source files into an Xcode project for compile?


As part of our Unity build process we drag and drop a directory of C source files which are generated by the Unity IDE into our iOS Xcode project. We want Xcode to "Create groups" for the files because the header files don't seem to be recognized by the compiler when using "Create folder references".

I'm wondering if there's a way to script this so we don't have to manually drag the directories into Xcode each time. Adding a "Copy Files" build phase only seems to work if I choose "Create folder references". When I choose "Create groups", the "Copy Files" section remains empty. Is this a bug in Xcode or am I doing something wrong? I'm using Xcode 9.1.

I know Apple recommends creating a framework rather than copying in a directory of source files. The reason we can't do that is because we're relying on the Unity build process which gives us a bunch of C source files.


Solution

  • Xcode makes it possible to script adding resource files such as images to the project file using the "Build Phases" tab however this does not work for source code files that need to be recognized at compile time. Luckily I managed to come across a nice community-developed Python script which does allow us to do this.

    https://github.com/kronenthaler/mod-pbxproj

    With this script we can make all sorts of modifications to the project file including adding or deleting files.

    See this link for a full list of available operations:

    https://github.com/kronenthaler/mod-pbxproj/wiki