Skip to content

Compiling for MacOS for distribution purposes

Colin Matthews edited this page Mar 7, 2024 · 31 revisions

This page details how to compile CorsixTH on MacOS so that the resulting .app can be distributed for use by others which involves the process of manually downloading, compiling and installing all dependencies from the command line using Terminal.

Do not use Homebrew as doing so will result in a CorsixTH.app that will not run on other machines that do not have the dependencies installed.

Dependencies

Downloading Dependencies

Xcode and Cmake can just be downloaded and the command line activated.

  • Xcode - installed from the App Store
  • Xcode command line - installed from the terminal by running
xcode-select --install
  • CMake
  • Cmake command line - installed from terminal by running
sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install

The source code must be downloaded for the below dependencies. Do not download any pre-compiled binaries intended to be part of a release for MacOS

All downloads can be performed via the command line using Curl or via the GUI using a web browser. Extraction can be performed using tar zxf <name of archive> or via the GUI. Please note that certain types of archives may require an extractor such as The Unarchiver to be downloaded from the App Store.

The below are downloaded and installed using Luarocks once that dependency has been installed

  • LuaFileSystem
  • LPeg
  • LuaSocket

Compiling and Installing Dependencies

Once all dependencies are downloaded and extracted, the source code for each will need to be configured, compiled and installed. In most cases, this is a simple process via the command line using the following commands:

  1. Move into the extracted directory:
cd /path/to/dependency/directory/
  1. Configure the source code so it is ready to compile:
./configure
  1. Compile the source code. Note - the -j4 flag is used to specify how many CPU cores/thread will be utilised for compiling:
make -j4
  1. Install the compiled code.
sudo make install

In order for certain dependencies to configure, compile and install correctly, the following amendments to the above steps need to be made:

ogg & vorbis
Use the following command instead of ./configure:

cmake .

OpenSSL
Use the following command instead of ./configure:

./Configure darwin64-x86_64-cc no-shared -mmacosx-version-min=10.13

or for Apple Silicon

./Configure darwin64-arm64-cc no-shared -mmacosx-version-min=10.13

Lua
Do not use the ./configure command and instead of make -j4, use the command:

MACOSX_DEPLOYMENT_TARGET=10.10 make -j4 macosx test

wxWidgets
Use the following command instead of ./configure:

CXXFLAGS="-stdlib=libc++ -std=c++11" OBJCXXFLAGS="-stdlib=libc++ -std=c++11" LDFLAGS="-stdlib=libc++" ./configure

FFmpeg
Use the following command instead of ./configure:

./configure --disable-everything --enable-asm --enable-x86asm --disable-doc --enable-debug --disable-ffmpeg --enable-decoder=smacker --enable-decoder=smackaud --enable-demuxer=smacker --enable-protocol=file --enable-protocol=cache --enable-protocol=pipe --enable-runtime-cpudetect --enable-shared

or for Apple Silicon

./configure --arch=arm64 --disable-everything --enable-asm --disable-doc --enable-debug --disable-ffmpeg --enable-decoder=smacker --enable-decoder=smackaud --enable-demuxer=smacker --enable-protocol=file --enable-protocol=cache --enable-protocol=pipe --enable-runtime-cpudetect --enable-shared

LuaFileSystem, Lpeg and LuaSocket
After installing Luarocks run the following to install all 4 Lua dependencies, adjusting the lua install path if necessary.

sudo -H luarocks install luafilesystem
sudo -H luarocks install lpeg
sudo -H luarocks install luasocket
sudo -H luarocks install luasec

To make universal binary builds in luarocks, enter the following.

luarocks config variables.CC "MACOSX_DEPLOYMENT_TARGET=11.0 SDKROOT=$(xcrun --show-sdk-path) clang -arch x86_64 -arch arm64"
luarocks config variables.LD "MACOSX_DEPLOYMENT_TARGET=11.0 clang -arch x86_64 -arch arm64"

Building CorsixTH

Download

Download and extract the latest version of the source code from from https://github.com/CorsixTH/CorsixTH/releases

or

Get the most up to date source code by running:

git clone https://github.com/CorsixTH/CorsixTH

Configure using Cmake

  1. Open Cmake.
  2. Click Browse Source to set the source code directory. This is the directory that was created when the source code was extracted or git-cloned.
  3. Click Browse Build to set the build directory. This should be an empty or non-existent folder that will be created in the next step.
  4. Click Configure. If a non-existent directory was specified in the previous step, click Yes in the warning prompt to create it.
  5. In the window that appears, select Xcode as the generator and leave Use default native compilers selected and click Done.
  6. A check will then be performed to ensure all dependencies are met. Once this has completed, change the option for CMAKE_INSTALL_PREFIX from /usr/local to /Applications.
  7. Add to the option CMAKE_OSX_DEPLOYMENT_TARGET the value 10.13.
  8. Tick the option WITH_LUAROCKS.
  9. OPTIONAL: Tick the box for BUILD_ANIMVIEW if a build of Animview build is also desired.
  10. Click Configure again so all the values become populated and are valid.
  11. Click Generate and then click Open Project.

Build and Install using Xcode

  1. In the menu bar, select Product > Scheme > ALL_BUILD
  2. Click the Play button in the top left of the Xcode window to build CorsixTH
  3. If no errors are generated (warnings are fine), in the menu bar, select Product > Scheme > install
  4. Click the Play button again in the top left of the Xcode window to install CorsixTH (and Animview if selected in Cmake)
  5. CorsixTH.app should now be located in /Applications.

NOTE: To force a code signature to make CorxixTH run, you may need to run

codesign --force --deep --sign - /Applications/CorsixTH.app