Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set up an Xcode build rule with a variable output file list?

Build Rules are documented in the Xcode Build System Guide

They are well adapted to the common case where one input file is transformed into a fixed number (usually one) of output files.

The output files must be described in the "Output Files" area of the build rule definition; one line per output file. Typically the output files have the same name as the input file but have different extensions.

In my case, one single input file is transformed into a variable number of files with the same extensions. The number and the names of the output files depend on the content of the input file and are not known in advance.

The output files will have to be further processed later on (they are in this case C files to be compiled).

How can I set up a build rule for such a case?

Any suggestions welcome.

(I asked the same question on the Apple developer forum, but I figured it'd be a good idea to ask here too).

like image 224
Jean-Denis Muys Avatar asked Feb 23 '11 23:02

Jean-Denis Muys


People also ask

How do I add a user defined variable in Xcode?

Select your project or target from the left side of the editor. Click the Build Settings button at the top of the editor. Click the Add Build Setting button at the bottom of the editor and choose Add User-Defined Setting.

How do I change the build settings in Xcode?

Choose the project in the Project Navigator on the left. Select the Configurations target from the Targets section and click the Build Settings tab at the top. The Build Settings tab shows the build settings for the Configurations target. It's possible to expand this list with build settings that you define.

What is Srcroot?

$(SRCROOT) (aka $(SOURCE_ROOT) ) is a path to your location where a .

What is Built_products_dir?

BUILT_PRODUCTS_DIR. Description: Directory path. Identifies the directory under which all the product's files can be found. This directory contains either product files or symbolic links to them.


1 Answers

I dealt with this by, instead of generating multiple C files, just concatenating them all together into one file (e.g. "AUTOGENERATED.c"), and specifying that as the output file.

So long as your output files don't contain anything that will conflict (static functions with the same name, conflicting #defines etc.) this works well.

like image 156
th_in_gs Avatar answered Nov 06 '22 14:11

th_in_gs