How To Create the Xcode Configuration Settings File

The Xcode project configuration is saved in the project file (*.xcodeproj). It is enough for normal-scale application development, but if you develop a middle or large-scale application, you may need more. Moreover, you would like to have more flexible control.

For example,

  • You would like to define the common macro across multiple projects.
  • You would like to change the search path of headers and libraries on each build machine.
  • You would like not to save the code signing configuration into the project file.
  • You would like to change the build configuration without Xcode.

You can overwrite the project’s configurations by writing them into the configuration setting file. This article explains how to create the Xcode configuration settings file.

目次

Creating the configuration settings file

The configuration settings file is a text file. You can create this using a text editor, but you must set it to the project file. Hence, I suggest making it with Xcode.

STEP
Select the “New…” in the “New” of the “File” menu.
STEP
Select the “Configuration Settings File” in the template table and click “Next”.
Select the "Configuration Settings File" in the table
Select the “Configuration Settings File” in the table
STEP
Uncheck all items in “Targets”, select the destination, enter the file name and click “Create”.

The build configuration files are not targeted to a specific build target, even if the configuration is for a particular target.

Select the save destination and enter the file name
Select the save destination and enter the file name

The syntax of the configuration settings file

The syntax of the configuration settings file is simple. Write the configuration in each line.

Configuration = Value

For example, write the following line if you want to set the ONLY_ACTIVE_ARCH to be YES.

ONLY_ACTIVE_ARCH = YES

Comments

As with Swift code, everything after // until the end of the line is treated as a comment.

Types of the value

The value type differs for each configuration. For example, if you look at the build settings on Xcode, it could be a string or a number. It corresponds to that. The following types are defined.

  • Boolean (YES or NO)
  • String
  • Enumeration (The predefined text)
  • Space-separated string list. If a string contains space, surround it with '.
  • Path. The file path and the directory path are in the POSIX form.
  • Space-separated path list. If a path contains space, surround it with '.

Reference to other configuration

If you want to use the value of the other configuration setting, write in the following form.

$(Other configuration)

Inherited value

If you don’t specify the target level configuration value, the project level configuration value will be used. The default value will also be used if the project-level configuration value is not defined. Like this, the inherited value may be used.

To use the inherited value, write the following as a value.

$(inherited)

Use it for the configuration supporting multiple values, such as the string list or the path list. You can add the element to the inherited value.

FLAGS = $(inherited) --no-timestamp

Platform-specific configurations

If you want to define the platform-specific configurations, write the configuration in [platform=value]. The two platforms are defined.

  • sdk: The cross-platform SDK, such as macos10.12, iphoneos10.2, and so on. You can specify * as a version for hitting any version.
  • arch: The CPU architecture. x86_64 or arm64.

Both values can be specified simultaneously in the form configuration[sdk=macos10.12][arch=x86_64] = value.

Import other configuration files

If you want to import other configuration files, use the #include statement.

#include "Common.xcconfig"

In this case, the Common.xcconfig file is imported. If the file is missing, Xcode will say the warning. However, if you write #include? statement, Xcode will not display the warning even if the file is missing.

#include? "Option.xcconfig"

Assign the configuration settings file to the build target

To use the configuration settings file, assign it to the build target with the Xcode.

STEP
Open the project settings.
STEP
Open the disclosure button (with triangle icon) of the “Configurations”
Open the disclosure button
Open the disclosure button
STEP
Click “None” and select the configuration settings file.

For example, if you want to assign the Debug.xcconfig file to the Debug configuration, click the None at the line “Example” project in the Debug configuration.

Assign the "Debug" to the debug configuration
Assign the “Debug” to the debug configuration

Configurations List

The configurations list is available on the Apple Developer Site.

著書紹介

Authored Books

よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!

この記事を書いた人

Akira Hayashi (林 晃)のアバター Akira Hayashi (林 晃) Representative(代表), Software Engineer(ソフトウェアエンジニア)

アールケー開発代表。Appleプラットフォーム向けの開発を専門としているソフトウェアエンジニア。ソフトウェアの受託開発、技術書執筆、技術指導・セミナー講師。note, Medium, LinkedIn
-
Representative of RK Kaihatsu. Software Engineer Specializing in Development for the Apple Platform. Specializing in contract software development, technical writing, and serving as a tech workshop lecturer. note, Medium, LinkedIn

目次