I'm trying to use the Address Sanitizer in Xcode, but I'm also using ccache to accelerate my builds. To do this, I've set the CC
flag at the Xcode-project-level to point to a script I'm storing at ~/projects/support/cmake/ccache-clang
. The script reads
#!/bin/sh
if type -p /usr/local/bin/ccache >/dev/null 2>&1; then
export CCACHE_CPP2=true
exec /usr/local/bin/ccache "${DEVELOPER_DIR}/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" "$@"
else
exec "${DEVELOPER_DIR}/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" "$@"
fi
so the desired effect is achieved (ccache is used if installed on the dev's system). This is working well.
Now the problem comes when we turn on the Address Sanitizer for a given scheme. The build completes successfully, but then we finally see this error when we try to run:
Error: Check dependencies
Could not determine version of clang to find its Address Sanitizer library: ~/projects/support/cmake/ccache-clang
Perhaps this is due to some hacky implementation in Xcode where it tries to parse the compiler's path to determine the version?
Wondering how I can modify my script to allow Address Sanitizer to work. The current work around is to remove the overridden CC
flag when we need to do sanitizer work.
Using Xcode 8.3.1
I was able to make it work. Tested with Xcode 14.2
ccache-clang
must be renamed toclang
andclang++
(i.e.clang++
is copy ofclang
). It seems that Xcode first of all tries to detect compiler's name: clang, gcc, etc., so naming the script like this makes Xcode to decide that this is clang. Also I useCMAKE_XCODE_ATTRIBUTE_
properties to setCC
,CXX
, etc.:After this I was able to enable sanitisers from Xcode, compile and run the app.