XcodeToolchainο
The XcodeToolchain is the toolchain generator for Xcode. It will generate .xcconfig
configuration files that can be added to Xcode projects. This generator translates the
current package configuration, settings, and options, into Xcode .xcconfig files syntax.
The XcodeToolchain generator can be used by name in conanfiles:
class Pkg(ConanFile):
generators = "XcodeToolchain"
[generators]
XcodeToolchain
And it can also be fully instantiated in the conanfile generate() method:
from conan import ConanFile
from conan.tools.apple import XcodeToolchain
class App(ConanFile):
settings = "os", "arch", "compiler", "build_type"
def generate(self):
tc = XcodeToolchain(self)
tc.generate()
The XcodeToolchain will generate three files after a conan install command. As
explained above for the XcodeDeps generator, each different configuration will create a
set of files with different names. For example, running conan install for Release
first and then Debug configuration:
$ conan install conanfile.py # default is Release
$ conan install conanfile.py -s build_type=Debug
Will create these files:
.
βββ conan_config.xcconfig
βββ conantoolchain_release_x86_64.xcconfig
βββ conantoolchain_debug_x86_64.xcconfig
βββ conantoolchain.xcconfig
βββ conan_global_flags.xcconfig
Those files are:
The main conan_config.xcconfig file, to be added to the project. Includes both the files from this generator and the generated by the XcodeDeps in case it was also set.
conantoolchain_<debug/release>_x86_64.xcconfig: declares
CLANG_CXX_LIBRARY,CLANG_CXX_LANGUAGE_STANDARDandMACOSX_DEPLOYMENT_TARGET(whenosis set toMacos) variables with conditional logic depending on the build configuration, architecture and sdk set.conantoolchain.xcconfig: aggregates all the conantoolchain_<config>_<arch>.xcconfig files for the different installed configurations.
conan_global_flags_<config>_<arch>.xcconfig: declares
GCC_PREPROCESSOR_DEFINITIONS,OTHER_CFLAGS,OTHER_CPLUSPLUSFLAGSandOTHER_LDFLAGSvariables with conditional logic depending on the build configuration, architecture and sdk set. This file will only be generated in case any configuration variables related to compiler or linker flags are set. Check the configuration section below for more details.conan_global_flags.xcconfig: aggregates all the conan_global_flags_<config>_<arch>.xcconfig files for the different installed configurations (since Conan 2.32).
Every invocation to conan install with different configuration will create a new
conantoolchain_<config>_<arch>.xcconfig and, if any compiler or linker flags are set, a new
conan_global_flags_<config>_<arch>.xcconfig file. Both are aggregated in
conantoolchain.xcconfig and conan_global_flags.xcconfig respectively, so you can have
different configurations included in your Xcode project.
The XcodeToolchain files can declare the following Xcode build settings based on Conan settings values:
*_DEPLOYMENT_TARGETis based on the value of theos+os.versionsettings and will make the build system pass respective flag (e.g.MACOSX_DEPLOYMENT_TARGETtranslates to-mmacosx-version-minfor macOS) with that value (if set). It defines the minimum operating system version the binary should run on.CLANG_CXX_LANGUAGE_STANDARDis based on the value of thecompiler.cppstdsetting that sets the C++ language standard.CLANG_CXX_LIBRARYis based on the value of the compiler.libcxx setting and sets the version of the C++ standard library to use.
One of the advantages of using toolchains is that they can help to achieve the exact same build with local development flows, than when the package is created in the cache.
confο
This toolchain is also affected by these [conf] variables:
tools.build:cxxflagslist of C++ flags.tools.build:cflagslist of pure C flags.tools.build:sharedlinkflagslist of flags that will be used by the linker when creating a shared library.tools.build:exelinkflagslist of flags that will be used by the linker when creating an executable.tools.build:defineslist of preprocessor definitions.
If you set any of these variables, the toolchain will use them to generate the
conan_global_flags.xcconfig file that will be included from the conan_config.xcconfig
file.
build_settingsο
The build_settings attribute lets a recipe set any Xcode build setting
directly. Settings already covered by a [conf] variable, such as
OTHER_CFLAGS, OTHER_CPLUSPLUSFLAGS, OTHER_LDFLAGS and
GCC_PREPROCESSOR_DEFINITIONS, should instead be set with the
tools.build:* variables from the conf section
above:
def generate(self):
tc = XcodeToolchain(self)
tc.build_settings["OTHER_SWIFT_FLAGS"] = "$(inherited) -cxx-interoperability-mode=default"
tc.build_settings["GCC_WARN_UNUSED_VARIABLE"] = "YES"
tc.generate()