How to configure an Xcode build rule with a variable list of output files?

Assembly rules are described in the Xcode Build System Guide

They are well adapted to the general case when one input file is converted to a fixed number (usually one) of output files.

Output files must be described in the "Output Files" area to define a rule, one line for each output file. Usually the output files have the same name as the input file, but have different extensions.

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

Then the output files must be processed later (in this case, the C files must be compiled).

How to configure the assembly rule for this case?

Any suggestion is welcome.

(I asked the same question in the Apple Developers Forum, but I thought it would be nice to ask about this as well).

+6
build-process xcode
source share
3 answers

I dealt with this, instead of generating multiple C files, simply combining them all together into a single file (for example, "AUTOGENERATED.c") and indicating this as the output file.

As long as your output files do not contain anything conflicting (static functions with the same name, conflicting #defines, etc.), this works well.

+2
source share

The best way to find any number of files in my xcode project (and do some processing) is to write a little php script. The script can simply copy the files to the bundle. The hard part is integrating with xcode. It took me a while to find a clean path. (You can use a script language that you like using this method).

First use "Add Script Run" instead of "Add Copy File"

Shell parameter:

/bin/sh 

Command Parameter:

 ${SRCROOT}/your_script.php -s ${SRCROOT} -o ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH} exit $? 

(screenshot in xcode)

$ {SRCROOT} is your project directory.

$ {CONFIGURATION (...) is the package directory. Exactly what you need :)

That way, your script return code can stop the xcode assembly (use die (0) for success and die (1) for crashes), and the script output will appear in the xcode build log.

Your script will look like this: (don't forget chmod + x on it)

 #!/usr/bin/php <?php error_reporting(E_ALL); $options = getopt("s:o:"); $src_dir = $options["s"]."/"; $output_dir = $options["o"]."/"; // process_files (...) die(0); ?> 

BONUS : here is my add_file function.

  • Pay attention to the special PNG handling (use apple png compression).
  • Note the use of file / time to prevent copying copy files every time.

l

 define("COPY_PNG", "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/copypng -compress"); function add_file_to_bundle($output_dir, $filepath) { // split path $path_info = pathinfo($filepath); $output_filepath = $output_dir.$path_info['basename']; // get file dates of input and output $input_date = filemtime($filepath); $output_date = @filemtime($output_filepath); if ($input_date === FALSE) { echo "can't get input file modification date"; die(1); } // skip unchanged files if ($output_date === $input_date) { //message("skip ".$path_info['basename']); return 0; } // special copy for png with apple png compression tool if (strcasecmp($path_info['extension'], "png") == 0) { //message($path_info['basename']." is a png"); passthru(COPY_PNG." ".escapeshellarg($filepath)." ".escapeshellarg($output_filepath), $return_var); if ($return_var != 0) die($return_var); } // classic copy else { //message("copy ".$path_info['basename']); passthru("cp ".escapeshellarg($filepath)." ".escapeshellarg($output_filepath), $return_var); if ($return_var != 0) die($return_var); } // important: set output file date with input file date touch($output_filepath, $input_date, $input_date); return 1; } 
0
source share

See this Cocoa article With love:
http://cocoawithlove.com/2010/02/custom-build-rules-generated-tables-and.html

This is an example of creating custom C code and using it as input to a normal build process. It uses the $ {} variable syntax in the output file.

-one
source share

All Articles