Recently, I was working with a larger iOS project than I usually do. This project involved creating a library and using it in other applications as well as testing it. In order to make this as painless as possible I started using bash script to make my builds as efficient as possible. In doing this I discovered many many Xcode build tokens which are underused. Lots of these made my build scripts a lot easier to create as I didn’t need to work with lots of relative paths, and helped ignore lots of redundant builds and build steps.
One of the biggest issues that I had with these tokens was the lack of documentation by Apple on these. A good chunk of these are based on my observations of how they change with various project settings. Some of them may not be quite right and if that is the case, feel free to let me know on this one and I’ll be glad to update it. I’m taking the unusual step on this post and adding in a comment system to see how well received this is (as well as test the suitablity of a comment system for this site), so please let me know through there.
Anyway, here are some of the more useful tokens that I found:
- BUILD_DIR: The location of the build directory. This is normally somewhere deep in the derived data folder, but can be configured in Xcode.
- BUILD_ROOT: This doesn't seem to be mentioned anywhere in Apple's documentation(just like lots of flags here), but seems to be set to the same thing as BUILD_DIR.
- BUILT_PRODUCTS_DIR: The location where the final products are placed after building.
- COMPRESS_PNG_FILES: A boolean value which specifies whether to compress PNG files whenthey are copied into the application bundle on iOS.
- CONFIGURATION: The current build configuration. This is usually Debug or Release,but can be a custom configuration.
- CONFIGURATION_BUILD_DIR: The build directory for the current configuration. This seems togenerally be the same as the BUILD_PRODUCTS_DIR.
- CURRENT_ARCH: Identifies the architecture on which the build is being *performed*.
- DEBUGGING_SYMBOLS: A boolean which specifies if debug symbols should be included in thecurrent build.
- DEVELOPMENT_LANGUAGE: Specifies the language that the project was developed in. Note thatthis means English/Spanish/etc. and *not* Objective-C/C++/etc.
- EFFECTIVE_PLATFORM_NAME: The platform which the build is being performed for, prefixed with a- usually. This can be combined with CONFIGURATION to get builddirectories usually.
- INSTALL_OWNER: The user who owns the final built product. This can be used to getappropriate permissions, etc.
- IPHONEOS_DEPLOYMENT_TARGET: This one is simply the iOS deployment target. If you are developingfor iOS 7.0 then set it to 7.0.
- ONLY_ACTIVE_ARCH: A boolean flag which states if the build will be performed for theactive architecture only.
- OPTIMIZATION_LEVEL: The optimisation level which is used by GCC compatible compilers.
- PATH: The PATH variable which is the same as you would see in a regularBash environment.
- PLATFORM_NAME: The name of the current platform. This time there is no - unlike theEFFECTIVE_PLATFORM_NAME.
- PRODUCT_NAME: The current products name. This is usually the same name as the currentbuild target.
- PROJECT: The name of the project.
- PROJECT_DIR: The location of the .xcodeproj directory.
- PROJECT_FILE_PATH: Similar to PROJECT_DIR, but this one places the .xcodeproj directoryon the end.
- PROJECT_NAME: Seems to be identical to PROJECT.
- SDK_NAME: The current SDK being used.
- SOURCE_ROOT: The location of the source code for this project.
- SRCROOT: An alias for SOURCE_ROOT
- TARGETNAME: The name of the current target.
- TARGET_BUILD_DIR: The build directory of the current target.
- TARGET_NAME: An alias for TARGETNAME.
- USER: The current system user.