How to change sysroot in macOS?
-
I'm trying to set up a custom toolchain for compiling Qt 6.2 in Qt Creator, with a custom build of LLVM / clang and a custom sysroot. However, I can't figure out how to do it.
The first thing I did was the obvious thing: I set up my compiler in Qt Creator's Kits preferences, and then created a new kit that uses my custom compiler and has a custom value for its
sysrootfield. That didn't work at all. Both the compiler and thesysrootvalue are completely ignored!The next thing I tried to do is create my own mkspec. I did so by first copying the macx-clang mkspec, adjusting the paths to its calls to
include, and then explicitly set the values ofQMAKE_CCandQMAKE_CXX, which did finally have an effect: now it's using my compiler.But I can't figure out how to change the value for
isysrootthat gets passed to the compilers. There's no obvious variable anywhere in any of the various mkspec files that defines it.The only thing I was able to find at all after
greping through the whole Qt 6.2 mkspec directory is this bit inmkspecs/features/mac/default_post.prf, starting at line 224:sysroot_path = $$xcodeSDKInfo(Path, $$device.sdk) ... version_min_flag = -m$${version_identifier}-version-min=$$deployment_target QMAKE_CFLAGS += -isysroot $$sysroot_path $$version_min_flag QMAKE_CXXFLAGS += -isysroot $$sysroot_path $$version_min_flagIt looks like this always gets executed no matter the mac mkspec I use, meaning it will always add the wrong
isysrootargument to all compiler calls!Surely there's some way I can change the value of
isysroot? Can anyone help? I've been bashing my head against this for hours now. :-( -
I figured it out! I guess if you bash your head against something long enough, sometimes you break through before your head cracks.
Here is the
qmake.conffile in my mkspec that works, with file paths replaced with generic paths for readability:include(/path/to/qt/6.2.3/macos/mkspecs/macx-clang/qmake.conf) QMAKE_CC = /path/to/llvm/usr/bin/clang QMAKE_CXX = /path/to/llvm/usr/bin/clang++ QMAKE_LINK = /path/to/llvm/usr/bin/usr/bin/clang++ QMAKE_MAC_SDK.macosx.Path = /path/to/sysroot QMAKE_MAC_SDK.macosx.SDKVersion = 12The last line setting the macOS SDK version may not be needed, but is useful if the compiler and sysroot support a newer macOS SDK than the current installed version of Xcode. I found that in order for compilation to work, I also needed to set the environment variable
QT_MAC_SDK_NO_VERSION_CHECK=1.That all said, this would have been A LOT easier and saved me hours of tough debugging if the kit settings for compiler and sysroot in Qt Creator actually did anything! I'll probably file a bug report.