Xcode 4 custom build step before compilation

I am trying to integrate a tool in Xcode 4 that generates a C header from a descriptor file. In Xcode 3, he worked on adding a custom build step for files with a specific extension. These files are then compiled before the .m / .mm / .cpp files into which they were included. When I try to do this with Xcode 4, it seems like it launches my custom step after compiling another source. Of course, this does not work. Is there any way to tell Xcode to run this step earlier?

Here's a simple playback setup:

enter image description here

My main.m contains a:

#include <mytest.h> 

and I added ${DERIVED_FILE_DIR} to the header search path. When I compile this project, I get the following:

enter image description here

If I remove the inclusion and build it again, I get the following:

enter image description here

So, the rule really works, but it's too late. Is there any way to change this behavior?

+6
source share
3 answers

I already have my Revival badge, but here it goes :)

I just ran into this problem and the answer is simple (now I spent half a day looking at it).

The assembly rule responds to the source file (.abc), and the source file is processed in the order in which it was specified at the source compilation stage of the assembly. Just go to the build rule and drag .abc to the top of the list.

One small step to the icon of the archaeologist, I hope.

+6
source

Instead of adding an assembly rule: on the "Phase Assembly" tab, using the "Add Assembly Stage" button, select "Add Launch" Script. A script launch phase will be added in which you can implement your Script requirements. A new Script phase can be dragged to the Compilation Sources phase when you want your functions to execute.

+3
source

You need to add an explicit dependency between the generated file and your target.

Open the DerivedData directory in Finder, select the mytest.h file and drag it into Xcode inside your project. Usually I create a new group called Derived Files and place such files under it.

To easily find the DerivedData directory, I change the project settings so that it is relative to the catalog project (see File → Project Settings, Creation tab).

After the file is referenced in the project, you need to add it to the main Compile Sources rule. Select the main goal of the project, expand the compilation sources, if it is not already expanded, and drag the newly added derived file to the list of files for compilation.

Finally, since you really want to compile this file, you can rename it to .m or .c instead of .h.

Update: Actually looks like the one shown above, does not work all the time. The most reliable way is to use the build phase instead of the build rule.

0
source

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


All Articles