Xcode generator: schemes not used for cmake --build, schemes missing from ALL_BUILD
The CMAKE_XCODE_GENERATE_SCHEME
variable can be used to enable scheme generation when using the Xcode generator. That will initialise the XCODE_GENERATE_SCHEME
property of each target. A similar pattern follows for the various CMAKE_XCODE_SCHEME_...
variables and their associated XCODE_SCHEME_...
target properties.
To enable sanitisers, you would typically set the variables to apply them across the whole build. That means you'd set something like the following:
cmake -G Xcode -S . -B build-xcode \
-DCMAKE_XCODE_GENERATE_SCHEME=TRUE \
-DCMAKE_XCODE_SCHEME_ADDRESS_SANITIZER=TRUE \
-DCMAKE_XCODE_SCHEME_UNDEFINED_BEHAVIOR_SANITIZER=TRUE
But if you then build using cmake --build
, it doesn't use the generated schemes and sanitisers are not enabled. As a workaround, you can invoke xcodebuild
directly, asking for a scheme rather than a target to be built. That command line would look something like this:
xcodebuild -project sanitizers.xcodeproj build -scheme SomeTarget -parallelizeTargets -configuration Debug -hideShellScriptEnvironment
This does build SomeTarget
with sanitisers enabled. However, if you want to build the whole project, this workaround fails. The generated ALL_BUILD
target doesn't get the scheme settings applied, meaning it doesn't have any of the sanitisers enabled. If it did, then the following would work:
xcodebuild -project sanitizers.xcodeproj build -scheme ALL_BUILD -parallelizeTargets -configuration Debug -hideShellScriptEnvironment
- BUG PART A:
cmake --build
should prefer to invokexcodebuild -scheme
rather thanxcodebuild -target
if a scheme exists for the requested target (orALL_BUILD
if no target was explicitly requested). - BUG PART B:
XCODE_SCHEME_...
settings should also be applied to theALL_BUILD
scheme (at least, where possible and where the scheme setting could potentially change how things are built).
An alternative change for PART A might be to support cmake --build ... --scheme ...
as an alternative to cmake --build ... --target ...
. At least then the developer can explicitly state that they want the scheme rather than the target. It would probably be better if cmake --build
could work this out for itself though.