How to build WSJT-X on the Apple M1

 

First you need to grab the experimental gcc-darwin-arm64. It is located here:

git@github.com:iains/gcc-darwin-arm64.git

You need to make sure that you have the Xcode development tools and brew are both installed. I have Xcode installed and therefore my --with-sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk which may be different than yours if you use the command line tools instead.

First step:

cd ~

git clone git@github.com:iains/gcc-darwin-arm64.git

 

cd gcc-darwin-arm64

mkdir build

cd build

../configure --build=aarch64-apple-darwin21 --disable-nls --enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-10 --with-gmp=/opt/homebrew/opt/gmp --with-mpfr=/opt/homebrew/opt/mpfr --with-mpc=/opt/homebrew/opt/libmpc --with-isl=/opt/homebrew/opt/isl --with-system-zlib --disable-multilib --with-native-system-header-dir=/usr/include --disable-darwin-at-rpath --with-sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk

make

sudo make install

 

Update gfortran symlink:

While you can most likely configure CMake with gfortran's path, I found this to be easier and more permanent.

You will need to change the symlink on your system for gfortran to point to the gfortran-10 build you just built.

It gets installed into /usr/local/bin, so I had to change my symlink in /opt/homebrew/bin to point to my version of gfortran.

/opt/homebrew/bin/gfortran -> /usr/local/bin/aarch64-apple-darwin21-gfortran-10

You may have a newer version of gfortran at this point. That is ok. I left everything else alone in the sense that I did not overwrite any other symlinks, this means that only the gfortran compiler is being replaced in your toolchain. If you use macports, your package binaries will be in a different directory than using brew.

My example above is from using brew.

 

Next you need to download the WSJT-X tarball and build it.

To build WSJT-X you will probably need to install the following brew packages:

brew install qt@5

brew install cmake

brew install gfortran

brew install boost

brew install fftw

brew install libomp

brew install libusb

brew install portaudio

# for man pages:

brew install asciidoctor

brew install asciidoc

brew install docbook-xsl

 

Configure CMake for Apple M1-

Just launch CMake 3.28.1 or later and make sure that the "Where is the source code" points to ~/wsjtx (the tarball you downloaded) and that the "Where to build binaries" directory points to ~/wsjtx-release (which will be created for you by CMake).

Make sure that CMAKE_BUILD_TYPE is set to "Release" (without quotes).

Make sure that CMAKE_INSTALL_PREFIX is set to ~/wsjtx. (This is where wsjt-x will be installed with make install, you can drag it to the application folder later if you like. These instructions assume the code is in ~/wsjtx.)

Make sure that CMAKE_OSX_SYSROOT points to the Xcode SDK directory (same as --with-sysroot option above).

Make sure that CMAKE_OSX_DEPLOYMENT_TARGET = 11.0 and not the default 10.12 otherwise you will get a link error for void __chkstk_darwin()

You need the following environment variables, they can be added to your shell (if so, then launch CMake from that shell) or can be added to CMake's environment variables.

export Qt5Test_DIR="/opt/homebrew/Cellar/qt@5/5.15.12"

export Qt5_DIR="/opt/homebrew/Cellar/qt@5/5.15.12"

export XML_CATALOG_FILES="/opt/homebrew/etc/xml/catalog"

 

In CMake GUI, select Configure (and if asked to create new build directory, say yes), choose Unix makefiles. When that is complete, press the Generate button.

Now you need to kick off a build- if you intend to point to the latest source code, you will need to start the build (which will unpack all the source from the tarball). Then you need to replace the WSJTX source with the git repo source files and build again.

cd ~/wsjtx-release

make -j8

 

You can now replace the ~/wsjtx-release/wsjtx-prefix/src/wsjtx directory with the git repo (this section is optional):

cd ~/wsjtx-release/wsjtx-prefix/src

rm -rf ./wsjtx

git clone https://git.code.sf.net/p/wsjt/wsjtx ./wsjtx

If you pointed to the git repo, it will help if you remove the build-stamp, otherwise the make system will fail to see that anything has changed and it will not rebuild the new source code you just cloned... [You can skip this step if building the tarball source files]

cd ~/wsjtx-release/wsjtx-prefix/src/wsjtx-stamp

rm wsjtx-build

 

Next execute the build:

cd ~/wsjtx-release

cmake --build . -j8

make install

Note: you can leave off the -j8 part for a single threaded build. You can also use make -j8 instead.

 

At this point, the following steps are total hacks and should go away in the future:

 

So if you get a link error with wsprd then you might need brute force:

The easiest way to fix this is to go into wsjtx-prefix/src/wsjtx-build/CMakeFiles/wsprd.dir/link.txt and change all instances of 10.12 to 11.0, save the file, and then rebuild!

-- or --

add void __chkstk_darwin() {} to line 49 of wsjtx-prefix/src/wsjtx/lib/wsprd/wsprd.c

I'm not sure why CMake has a different setting for the wsprd project with respect to CMAKE_OSX_DEPLOYMENT_TARGET = 11.0. Actually this is caused by the way the tarball is setup and I'm too lazy to resolve and patch the issue.

 

If you get an error during the 'make install' phase related to libwebp or libsharpyuv then you will need to modify the bundle_fixup CMakeLists.txt file.

cd ~/wsjtx-release/wsjtx-prefix/src/bundle_fixup.

Modify CMakeLists.txt file to add this line right below 'list (APPEND fixup_library_dirs ${QtCore_location})' on line 4.

list (APPEND fixup_library_dirs "/opt/homebrew/Cellar/webp/1.3.2/lib")

You might have a different webp version or directory on your system so be sure to check the path yourself.

 

- open up the WSJT-X bundle and go into the Frameworks directory. WSJT-X is located in ~/wsjtx

- replace libgcc_s.1.1.dylib with libgcc_s.1.1.dylib from ~/gcc-darwin-arm64/build/aarch64-apple-darwin21/libgcc… This is necessary otherwise ___addtf3 is an unresolved import and causes WSJT-X to crash on launch.

 

After you run make install you will need to sign the bundle. You will need an Apple Developer Account to create a Developer ID certificate. I believe you can also run the app unsigned by right-clicking it and selecting Open... but I have not tested this.

Go to: http://developer.apple.com and click the Account button.

You need to create an AppID for wsjtx, it should be org.k1jt.wsjtx but I have taken that- so you will need to create your own ID and modify the Info.plist file to match before signing.

Be sure to add your development device to your device list, then also create a Developer ID Application certificate.

Then create a MacOS Development Profile and select the AppID for WSJT-X that you just created and then select your certificate and device(s).

Once you have your developer ID profile downloaded and installed (you can double-click the provision to install it), run these two commands:

security unlock-keychain login.keychain

codesign -s "Developer ID Application: xxx" --deep -f ~/wsjtx/wsjtx.app/

Replace xxx above with your Developer ID profile name.

 

 

That should do it! You will find the built app inside ~/wsjtx. Good luck