Is it possible for a script to add a source directory to an Xcode project for compilation?

As part of the Unity build process, we drag and drop the directory of C source files that are generated by the Unity IDE in our iOS Xcode project. We want Xcode to "create groups" for files, because header files do not seem to be recognized by the compiler when using Create Folder Links.

I am wondering if there is a script way, so we don’t need to manually drag and drop directories into Xcode every time. Adding the Copy Files build phase seems to work if I select Create Folder Links. When I select Create Groups, the Copy Files section remains empty. Is this an error in Xcode or am I doing something wrong? I am using Xcode 9.1.

I know that Apple recommends creating a framework instead of copying to the source files directory. The reason we cannot do this is because we rely on the Unity build process, which gives us a bunch of C source files. Thanks!

+5
source share
3 answers

Xcode allows the script to add resource files, such as images, to the project file using the Phase Assemblies tab, however this does not work for source code files that need to be recognized at compile time. Fortunately, I was able to find a good community-developed Python script that allows us to do this.

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

With this script, we can make all kinds of changes to the project file, including adding or deleting files.

See this link for a complete list of available operations:

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

0
source

In Xcode, you can control the build process on the Build Phases tab when you select the target application. These tasks are performed each time you build your application, unless otherwise indicated at some stages (for example: you can select a phase only when the application is installed for the first time).

Click the + button, and you can add the “Copy files” phase, which will copy the selected files to the application. When adding files, you can choose whether the added folders will create groups or links to folders.

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

+1
source

xcode-> Assembling phases-> button (+) → New copy files Phase / New start Script Phase

enter image description here

enter image description here

+1
source

Source: https://habr.com/ru/post/1273677/


All Articles