YURIX


Building XTRKCAD on Apple Silicon

November 2023

xtrkcad is probably one of the best free model railroad planners that run on macOS. However, they only provide downloads for older intel-cpu based macs. (the switch to arm by apple was around 2020). You can run xtrkcad in rosetta, a translation layer allowing older intel apps to run on Apple Silicon, but I prefer native builds.

Building for apple silicon natively turned out to be a bit more difficult than anticipated. The documentation is rather sparse. Additionally, I'm using homebrew and not macports.

Installing Homebrew

This guide heavily uses homebrew. You should therefore go and install it if you haven't already.

Building from source

To build from source, obviously the source code is required. It is stored on the mercurial version control system, not git, like most software is today. Get the source like this:

   brew install mercurial
                                                mkdir xtrackcad
                                                cd xtrackcad
                                                hg clone http://hg.code.sf.net/p/xtrkcad-fork/xtrkcad src/  

Next is installing all dependencies. The first install command are common libraries that are found on the main brew index. The second line is for a library called Mini-XML. Mini-XML is on brew, but only for a newer, incompatible version. I've created a brew tap(repo) that provides the dependency. here is a link to the source code of the tap and here of the Mini-XML website.

    brew install cmake gtk+ inkscape libzip freeimage
                                                brew install recursivetree/xtrkcad/libmxml@3    

Finally build the software:

   cmake -S src -B build
                                                make -j4 -C build
                                                make -j4 -C build install

I've had it happen that the svg to png conversion fails. In that case, remove the build directory and build again. For me, that has always helped.

It is also possible that you will run into linking issues about missing libraries. Since homebrew doesn't install libraries in the typical places, some tools have trouble finding them. The easies fix I've found is to open src/CMakeLists.txt and add the following line: link_directories(/opt/homebrew/lib).

If everything worked, you should now be able to launch the app using the command xtrkcad.

Bonus - Generating .app Files

   make -j4 -C build package   

A .dmg file will be generated in the build folder that contains the .app file. However, I haven't figured out how to include the required dynamic libraries, so it will most likely crash when running it on different computers.

Using my Homebrew tap

Alternatively, I've built a homebrew formula that automates the above build steps. Due to how homebrew works, it was not possible to specify a dependency on inkscape. Therefore, it has to be installed manually beforehand.

   brew install inkscape
                                                brew install recursivetree/xtrkcad/xtrkcad

If everything worked, you should now be able to launch the app using the command xtrkcad.

The source for the xtrkcad formula can be found here. It performs the same steps as described above, except it applies a patch that allows xtrkcad to find its share directory, since again, due to homebrew's design it is located in non-standard places.

Closing Words

I know this guide does not have the highest quality. It is more of a note sheet for myself. If you run into any issues or have something to comment, contact me at blog@ycloud.yurix.ch.