-->

Can you create custom build rules for XCode based

2020-07-27 04:00发布

问题:

I have a project with a bunch of .png files that I want to convert to PVRTC compressed textures. Right now, I'm using a custom XCode run script phase that looks like this:

TEXTURE_TOOL=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/texturetool

$TEXTURE_TOOL -e PVRTC --bits-per-pixel-2 -o "$SRCROOT/images/select_menu_bgs1.pvr" -f PVR "$SRCROOT/images/select_menu_bgs1.png"
$TEXTURE_TOOL -e PVRTC --bits-per-pixel-2 -o "$SRCROOT/images/select_menu_bgs2.pvr" -f PVR "$SRCROOT/images/select_menu_bgs2.png"

but it's annoying to have to make it explicitly include the exact list of files I need converted. (they also need to be added to the input & output properties of the build step, which is the even more annoying part.)

what I would like to do is something easy with "make": have a rule that says "if there's a .pvr in the project, it's built from the corresponding .png using this command line."

Is anything like this possible in XCode?

回答1:

Double-click a Target.

Choose the Rules pane, simplify it with the popup Rules Specific to target

Click the Plus button at the bottom of the window.

For the Process: popup, choose the last entry - Source files with names matching, which allows you to enter a file glob pattern.

For Using, choose Custom Script and enter your script below.

Use "${INPUT_FILE_BASE}" eg:

$TEXTURE_TOOL -e PVRTC --bits-per-pixel-2 -o "${INPUT_FILE_BASE}.pvr" -f PVR "${INPUT_FILE_BASE}.png"