Concurrently building projects with different Xcode versions using CMake

I have multiple Xcode versions installed on my system using the XcodesApp. Whenever I need to work with a specific Xcode version, I have to switch between them using the xcodes select command:

xcodes select 14.3.1 # or 15.3, etc.

After selecting the desired Xcode version, I use CMake to generate Ninja build files for my projects. However, having to switch Xcode versions manually every time is quite tedious and prevents me from concurrently building projects that require different Xcode versions.

Is there an official or recommended way to configure CMake to use the appropriate Xcode toolchain (compilers, linkers, etc.) for each project without having to manually switch between Xcode versions? Ideally, I'd like to be able to specify the desired Xcode version when running CMake, and have it automatically use the corresponding toolchain for that version.

I'm aware that one potential solution could be to create separate toolchain files for each Xcode version, specifying the paths to the compilers and other tools. However, I'm wondering if there's a more official or recommended approach from Apple or the CMake community.

Any guidance or suggestions on how to achieve this would be greatly appreciated.

Replies

I don’t know about anything official, but the way I tell xcrun and friends to temporarily use a specific Xcode version is by setting the DEVELOPER_DIR environment variable.

% xcrun swift --version
… Apple Swift version 5.10 …
…
% DEVELOPER_DIR=~/XcodeZone/Xcode\ 15.0.app/Contents/Developer xcrun swift --version
… Apple Swift version 5.9 …
…

I don’t use CMake, so I’ve never tried it with that.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"