Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. Thanks!

like image 720
Mike Onorato Avatar asked Oct 28 '22 22:10

Mike Onorato


2 Answers

In Xcode, you can manage your build process under the "Build Phases" tab when you select your app target. These tasks are executed on each build of your app, unless specified otherwise by some phases (for example: you can choose to run a phase only when the app installs for the first time).

Click the + button and you can add a "Copy files phase" that will copy your selected files into the app. When adding the files you'll be able to select if added folders will create groups or folder references.

You can also add a custom "Run script phase" and write some bash code to do whatever you like, or even run an external script that will do more complex work.

like image 175
Artal Avatar answered Nov 15 '22 05:11

Artal


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

like image 30
Mike Onorato Avatar answered Nov 15 '22 06:11

Mike Onorato