Xcode Configuration Settings file (xcConfig)

An Xcode configuration Settings file (which is a file with the.xcconfig file extension), also known as a build configuration file or xcConfig file, is a plain text file that defines and overwrites a specific build configuration for a project or target. This type of file can be edited outside of Xcode and is easy to version control. Build profiles follow specific formatting rules and generate build warnings if they do not.

Note: To add a configuration Settings file to your project, see Adding a Build Configuration (XCConfig) file.

annotation

Use single-line comments to contain comments or other information that should be ignored by the build system. Each comment begins with two forward slashes (//) and continues to the end of the line. Such as:

// // configuration. xcconfig // My iOS app // // was created by Johnny Appleseed on November 15, 2016. // Copyright © 2018 Apple. All rights Reserved. //Copy the code

Comments can reside on a single line or follow the build setting value. Such as:

ASSETCATALOG_COMPILER_APPICON_NAME = MyAppIcon this is a comment.Copy the code

Specifying build Settings Values The build profile does not need to list all possible build Settings. It only needs to include the ones you want to customize. Each build setting value is defined on a single line in the following format:

BUILD_SETTING_DECLARATION_NAME = BUILD_SETTING_VALUE_DEFINITION
Copy the code

Such as:

ONLY_ACTIVE_ARCH = Yes
Copy the code

There are many value types, but the following are the most common:

type instructions
Boolean A value of YES or NO.
string A specified text value.
enumeration (string) A predefined text value.
string list A space-separated list of string values. If a string within a string list contains spaces, then the string must be surrounded by quotes.
path A file or directory path, in POSIX form.
path list A space-separated list of path values. If a path within a path list contains spaces, then the path must be surrounded by quotes.

Pay attention to

The Build Setting can display the title as well as the Key. Select a setting, then click the question mark in the upper right corner to see the actual setting Key.

Prevents values from being overwritten

To keep the existing project or target build setting values as part of the newly defined values, use the $(inherited) variable in the following format:

BUILD_SETTING_DECLARATION_NAME = $(inherited)ADDITIONAL_VALUE
Copy the code

Such as:

OTHER_SWIFT_FLAGS = $(inherited) -v
Copy the code

References the value of another build setting

To reference the value of another build set, reference the other build set name in the following format:

BUILD_SETTING_DECLARATION_NAME = $(OTHER_BUILD_SETTING_DECLARATION_NAME)
Copy the code

Such as:

OBJROOT = $(SYMROOT)
Copy the code

Other build setting values can be referenced inline, as shown below:

DSTROOT = /tmp/$(PROJECT_NAME).dst
Copy the code

Or:

CONFIGURATION_BUILD_DIR = $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
Copy the code

Add a platform condition to a value

A project may need to build differently when targeting one platform versus another. To allow for this, the build system supports the following conditionals:

Conditional Condition value
sdk An SDK, such as macos10.12 or iphoneos10.2. To match any SDK of a given platform, provide An asterisk) instead of a version. For example, a condition value of macos matches any macOS SDK.
arch An architecture, such as x86_64 or arm64.

Conditions appear after the build setting name and are enclosed within brackets. For example:

BUILD_SETTING_DECLARATION_NAME[CONDITIONAL=CONDITION_VALUE] = VALUE_DEFINITION
Copy the code

For example, the following line sets the value of the OTHER_LDFLAGS build setting to -lncurses when building with any macOS SDK:

OTHER_LDFLAGS[sdk=macosx*] = -lncurses
Copy the code

Multiple conditions can also be specified using the format:

BUILD_SETTING_DECLARATION_NAME[CONDITIONAL1=CONDITION_VALUE1][CONDITIONAL2=CONDITION_VALUE2] = VALUE_DEFINITION
Copy the code

For example, the following line sets the value of the OTHER_LDFLAGS build setting to -lncurses whenever the SDK matches a value of macosx* and the architecture matches a value of x86_64:

OTHER_LDFLAGS[sdk=macosx*][arch=x86_64] = -lncurses
Copy the code

Include Settings from Other Build Configuration Files

A build configuration file can import build settings from other build configuration files. To import settings from another file, use the prefix #include, followed a reference to the file in quotes. For example:

#include "MyOtherConfigFile.xcconfig"
Copy the code

If the specified file isn’t found at build time, build warnings are produced. To suppress warnings for missing build configuration files, place a question mark (?) after the #include prefix. For example:

#include? "MyOtherConfigFile.xcconfig"
Copy the code

You can refer to other build configuration files using file names, relative paths, and absolute paths.

Reference type Description Example
File name The name of a build configuration file in the same folder as the current build configuration file. #include “MyOtherConfigFile.xcconfig”
Relative path The path to a build configuration file relative to the location of the current build configuration file. #include “.. /MyOtherConfigFile.xcconfig”
Absolute path An absolute path to a build configuration file on disk. #include “/Users/MyUserName/Desktop/MyOtherConfigFile.xcconfig”

Note: References to other build configuration files are processed before interpreting any build settings.

Original: help.apple.com