Building Qt 5.15 for Mac M1 - bobwolff68/fritzing-app GitHub Wiki

The following came almost word for word from a Reddit post by /u/nezticle ... I followed the directions, made a couple of mods for success and ultimately wound up with what seems to be a fully functional Qt 5 build for the ARM-based Mac M1. The original post URL: https://www.reddit.com/r/QtFramework/comments/ll58wg/how_to_build_qt_creator_for_macos_arm64_a_guide/

This guide for building Qt is a prerequisite to building Fritzing under M1 compilation fully.

-- bob

How to Build Qt Creator for macOS ARM64 (a guide)

Since this topic keeps coming up, and maybe my previous instructions were not enough for people to reproduce my build, I've written a whole guide on how I was able to build Qt Creator for macOS ARM64. This is an "unofficial guide" since there is not "official" support for Qt Creator or Qt for that matter on macOS ARM64. Also it uses unreleased (potentially unstable) code, but it does assume using the publicly available code for 5.15 and Qt Creator (not some hidden magic that doesn't exist yet in a private repo). And just so we are clear there is not even a version that is available for commercial customers of Qt. I'm publishing this guide because it is possible to do now with unreleased code, and it makes tasks like debugging from Qt Creator on the M1 Macs possible.

Get Qt build dependencies (using homebrew)

brew install pcre2 harfbuzz freetype

Get Qt Creator dependencies (using homebrew)

brew install cmake ninja python

brew install --build-from-source llvm

The LLVM install is optional, but is necessary for the extra clang code model in Qt Creator. Also using the homebrew version is the easiest because there are outstanding issues with building LLVM for macOS ARM64 that requires an unreleased version of LLVM to overcome, which isn't even supported by Qt Creator. The homebrew source has the patches necessary to build a working LLVM.

Not so sure about the pcre2, harfbuzz, and freetype dependencies, because if you didn't have them we would just build them anyway, and by using the brew version it likely makes the build unmovable from the development machine. I include them because I already have them in my environment, and we recommend them in some of our cmake build documentation for Qt 6 (even though we're building for Qt 5 in this case).

Building Qt 5.15.x (unreleased/opensource)

First get all the source code for Qt 5.15. We need some unreleased code so you need to get it using git. This will basically give you the last bit of opensource code before the 5.15 repo went private.

git clone git://code.qt.io/qt/qt5.git

cd qt5

git checkout 5.15

This step takes forever because it needs to pull down every module, and for Qt 5.15 there are ALOT. WebEngine takes like half the time because it contains Chromium which is larger than Qt. It's possible to skip downloading some modules, and Qt Creator certainly doesn't use all of them. But since people seem to miss these modules in Qt 6, why not take a moment(or hour) to reflect on the largess of Qt 5 by downloading everything?

./init-repository

Ok now that that is done we can build things. Create a build folder outside of your Qt source directory.

cd ..

mkdir qt5-5.15-macOS-release

cd qt5-5.15-macOS-release

../qt5/configure -release -prefix ./qtbase -nomake examples -nomake tests QMAKE_APPLE_DEVICE_ARCHS=arm64 -opensource -confirm-license -skip qt3d -skip qtwebengine

This should configure Qt without errors and you should confirm that it says this at the top of the configuration output:

Build type: macx-clang (arm64, CPU features: neon crc32)

Compiler: clang (Apple) 12.0.0

If that is correct, then all the rituals have been performed, and you can move on to building Qt which again will take quite awhile, but maybe not as long as to download Qt because the M1 Macs are crazy fast to build stuff.

make -j15

When that completes, there is no need to run make install. By setting the -prefix value to "./qtbase" you essentially say that you are installing to the place where it already was. This is a pretty common pattern we use for Qt development (its also one of the nice things that the -developer-build configure flag does, but we don't do that here because we want a release build). Also notice the skipping of qt3d and qtwebengine, do not mistake this for mercy, they in fact do not build with macOS ARM64 currently.

Building Qt Creator 4.14.x

cd ..

git clone git://code.qt.io/qt-creator/qt-creator.git

cd qt-creator

git checkout 4.14

git submodule update --init --recursive

cd ..

mkdir qt-creator-4.14-build

cd qt-creator-4.14-build

Note: My python3 was not located in /opt/homebrew/bin per the original docs. I'd suggest using `which python3` or your own location in the subsequent build steps.

With LLVM (Clang code model):

cmake -DCMAKE_BUILD_TYPE=Release -G Ninja "-DCMAKE_PREFIX_PATH=../qt5-5.15-macOS-release/qtbase/;/opt/homebrew/opt/llvm" -DPYTHON_EXECUTABLE=/opt/homebrew/bin/python3 ../qt-creator

Or Without LLVM:

cmake -DCMAKE_OSX_ARCHITECTURES="arm64" -DCMAKE_BUILD_TYPE=Release -G Ninja "-DCMAKE_PREFIX_PATH=../qt5-5.15-macOS-release/qtbase/" -DPYTHON_EXECUTABLE=/opt/homebrew/bin/python3 ../qt-creator

Then to build:

ninja

Now you should have "Qt Creator.app" which is an ARM64 version of Qt Creator.

And if you want to get real fancy (and still might not work as intended) you can try:

../qt5-5.15-macOS-release/qtbase/bin/macdeployqt Qt\ Creator.app

Which should copy the necessary files from Qt into the App bundle necessary for relocation, but no clue if that actually works given that we used homebrew for some of the dependencies (and I don't have a second M1 to test with).