CMake selecting wrong version of `strip` on macOS, no `--strip-all`

Viewed 17

I've been noticing a problem the last few times I've tried to build a CMake-based project on macOS 12 (M1 Mac Mini). Right now it's with DevilutionX but it's happened with various other CMake-based projects before.

The problem is that it attempts to use the --strip-all flag to the strip binary that ships with Xcode (at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip), as evidenced by the error log from running cmake on the aforementioned DevilutionX source tree:

[ 95%] Linking CXX executable ../stores_test
[ 95%] Built target path_test
[ 95%] Built target scrollrt_test
[ 95%] Built target stores_test
[ 95%] Built target player_test
[ 95%] Linking CXX executable ../utf8_test
[ 95%] Built target utf8_test
[ 95%] Linking CXX executable ../timedemo_test
[ 95%] Built target timedemo_test
[ 96%] Linking CXX executable ../writehero_test
[ 96%] Built target writehero_test
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip: unrecognized option: --strip-all
Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip [-AnuSXx] [-] [-d filename] [-s filename] [-R filename] [-o output] file [...]
make[2]: *** [devilutionx.app/Contents/MacOS/devilutionx] Error 1
make[2]: *** Deleting file `devilutionx.app/Contents/MacOS/devilutionx'
make[1]: *** [CMakeFiles/devilutionx.dir/all] Error 2
make: *** [all] Error 2

But this is some old, Apple-specific strip that has never had a --strip-all flag. I believe that CMake thinks it's invoking LLVM's strip binary (which I also have on my machine at /opt/homebrew/opt/llvm/bin/llvm-strip) which does have that flag. But that's not the strip it actually selected.

This is causing CMake-based builds to just break unless I hack around it by, e.g., temporarily symlinking Apple's strip to llvm-strip. Is there a better solution/workaround? Is there something in the CMake config files I can set to tell it to use llvm-strip?

0 Answers
Related