Enable code coverage in the build settings of a particular target

We got an app that uses DriverKit. So we have the main target of the app and another target for DriverKit.

We would like to turn on code coverage for testing. To do so we enable it in the scheme settings.

Unfortunately this doesn't work because DriverKit doesn't support code coverage option. This happens because all settings set in the scheme settings get carry out for all the targets. So this the error you get:

File cannot be open)ed, errno=2 path=/Applications/code.app/Contents/Developer/Toolchains/XcodeDefault.ctoolchain/usr/lib/clang/15.0.0/ lib/darwin/libclang_rt.profile_driverkit.a in '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/
15.0.0/lib/darwin/libclang_rt.profile_driverkit.a'

After talking with a couple of Apple engineers ( thanks for your help btw :) ) about a similar problem related with Address Sanitiser, they helped me adding a custom setting in build settings for the main target so address sanitiser can be enabled only for the main target.

Unfortunately we didn't have enough time to cover the code coverage problem and they suggested to post a question in this forum to find out the KEY to set up code coverage in build settings

Thanks

For current Xcodes the build setting for enabling or disabling code coverage is ENABLE_CODE_COVERAGE.

A target should be able to set ENABLE_CODE_COVERAGE=NO in the build settings to opt-out of building with instrumentation, even when it is enabled for the overall build operation for the active test plan.

Enable code coverage in the build settings of a particular target
 
 
Q