From The Battle for Wesnoth Wiki

[edit]Compiling Wesnoth


Introduction: Compiling Wesnoth on macOS

Note: A lot of the information on this page is rather outdated and many of the steps listed below or not necessary when using a recent version of macOS and Xcode. See below for the Xcode-specific instructions.

Other than the generic Unix information on how to build at CompilingWesnoth, there are some Mac OS X specific issues. These issues are dealt with here.

See also forum topics How To Compile On A Mac and Help with using BfW for macOS with command-line arguments.

Compiling with the terminal, Xcode tools, homebrew & scons

It is possible to compile with scons, following instructions which are very similar to what is done on a Linux platform. On macOS, the simplest way to acquire dependencies is either to download those provided by our macOS packager and put them in the appropriate directory, or to acquire them from a package manager like homebrew.

Basic Assumptions:

Basic Ideas

First, make sure you have installed the full XCode package, this includes the GCC compilers which do the actual compilation of wesnoth, and this is the easiest way to get them. XCode comes with all copies of OS X, though it's not installed by default (it's actually in a separate install program, and in 10.3/Panther, was on a separate CD). If you don't have it at all, you can get a cd image at .

homebrew is a free package manager which makes it easy to obtain open source software on a mac. (It is an alternative to Macports and Fink.) It is based on automatically downloading the sources and compiling them on your machine (it has some precompiled versions too). This way, you are sure to get recent versions of all of the libraries that will work on your machine. It is used and supported by many people, so if you have problems there will be someone who can help. It only officially supports macOS 10.6 and later. For macOS 10.4 and 10.5, you might attempt to use a fork of homebrew called "tigerbrew" .

scons is a build tool. After all the prerequisite libraries have been obtained and the source code has been downloaded, compilation may begin. To compile wesnoth, the compiler and linker must be invoked many times. scons orchestrates this part of the process.

Outline of Steps

  • Install XCode
  • Download and install homebrew:
  • Install wesnoth dependencies (includes scons)
  • Download a copy of the source-code repository (see WesnothRepository).
  • Use scons to compile

Using homebrew

Once you have installed the XCode command line tools and homebrew (described on their webpage), you can use homebrew to install packages, by referring to them by name. This line installs homebrew:

 ruby -e "$(curl -fsSL”

Homebrew actually has a wesnoth package, so you can use it to download all the sources and deps and compile the whole game for you if you like, by running the following commands.

 brew tap homebrew/games
 brew install cairo --without-x11
 brew install pango --without-x11
 brew install wesnoth

More detail is given on the wesnoth forums here:

If you want to edit the wesnoth source code, or tweak the build by giving different compile options, then instead of `brew install wesnoth` you should tell homebrew only to give you the dependencies:

 brew install wesnoth --only-dependencies

In this case you will end up running scons yourself with appropriate options.

If your machine has multiple cores, you can build much faster by typing `brew install wesnoth -j3` or `brew install wesnoth --only-dependencies -j3` where 3 is the number of cores that you have.


After you have used git or another method to get the source code from the WesnothRepository, navigate your terminal to that directory. This is the directory containing folders "data" and "src".

Now execute scons:

 scons jobs=3 gettextdir=`brew --prefix gettext`

The "jobs=3" tells scons to use 3 cores. The "gettextdir=..." line tells wesnoth to use homebrew's gettext rather than the OS X provided gettext, which will cause problems. If you only want to have english available in the game, you could skip the translations by using:

 scons jobs=3 nls=false

When it is finished, run wesnoth by typing


Tuning the Build

To compile with different compiler options, for example "-O3" which turns on level 3 optimizations, or "-Os" which optimizes the build for executable size, compile again with the options

 scons extra_flags_release="-O3"

for example. scons remembers all of these settings so you don't have to type them each time. You can look at other options for scons on its wikipage.

Build using XCode

Building Wesnoth 1.13 with Xcode

Due to changes in the system libraries between different versions of OS X, the Xcode project provided with Wesnoth only works for the latest versions. For previous versions (back to OS X 10.6), a script can be used to get compiling to work in a semi-automated way.

macOS 10.9 and later

  • Install Xcode.
  • Download and extract the Wesnoth Repository to a folder on your computer.
  • Download the Xcode compilation material. For master, you need [The versions with a date in the file name are only needed if you want to compile a previous version of Wesnoth from before the respective date.]
  • Unzip the compilation material. Copy folders lib/ Headers/ and Wesnoth.dmgCanvas/ into projectfiles/Xcode/ in your local Wesnoth repository folder.

That is all that should be required. Open projectfiles/Xcode/Wesnoth.xcodeproj and compile.

macOS 10.8

None of the Wesnoth macOS developers currently has access to macOS 10.8, so we are not sure which method will work. Try the method described for 10.9 and later above. If it does not work, try the method for 10.6 and 10.7 described below. Then, please let us know which method worked, so that we can update this page accordingly.

macOS 10.6 and 10.7

  • Follow the instructions given above for OS X 10.9 and later.
    • This sets up most of what is needed, but because of changes in the OS X system libraries, some of the libraries provided will not work and need to be compiled locally on your computer and copied to the Wesnoth Xcode project folder. If you want, you can do this yourself in any way you choose, but we also provide a script that will do it automatically. This script uses MacPorts and is used as follows.
  • Install MacPorts.
    • If this is a new install, or if you installed MacPorts more than a couple weeks ago, you probably want to do a selfupdate by running sudo port selfupdate.
  • The script is called and is included in the Xcode compilation material zip archive you downloaded earlier.
    • Open the script in a text editor and convince yourself that we are not doing anything evil. You do need to run this script with superuser privileges, as MacPorts needs this for building and installing libraries.
    • Depending on how you copied/moved the script, you might also have to set execute permissions for the file with chmod +x
  • Edit the two path names at the beginning of the script:
    • Change WESNOTH_PATH to point to your Wesnoth repository folder.
    • Change TMP_DIR to point to any directory of your choice to store the existing libraries temporarily. The folder does not have to exist, the script will create it.
  • Run the script by typing sudo ./ in a terminal.
    • Depending on which libraries need to be build, this can take a little while (minutes to tens of minutes).
  • If the script finishes without error messages, you ou should now be able to open projectfiles/Xcode/Wesnoth.xcodeproj in the Wesnoth repository and compile.
    • After you confirmed that this works, you can delete the temporary directory with the old library files.

If any of this does not work, or if you need to modify any of the steps described above, please let us know so that we can adjust the instructions and/or the script accordingly.

Note: The Wesnoth executable built in this way depends on some of the MacPorts libraries in /opt/local, so those cannot be removed. The script contains a commented-out code block that switches the links inside the libraries to local (as in, within Wesnoth) links. However, depending on your version of OS X, pango and other libraries, it might be necessary to replace some of the other Wesnoth libraries with MacPorts-built versions also, if you want to do that.

macOS 10.5 and earlier

Unfortunately, the changes from macOS 10.5 to 10.6 are too significant to support compiling on versions before 10.6 any more. It is probably possible to get it to work if you replace all the libraries and headers in the Xcode compilation material archives with versions that work on your system and update the Xcode project file as needed. You can also try to follow the instructions for compiling with homebrew that are given above.

Building Wesnoth 1.12 with Xcode

The instructions given above for Wesnoth 1.13 and macOS 10.9 and later should work with 1.12 on most versions of OS X (in principle back to 10.4). The only difference is that you need to get file from Xcode compilation material.

Compiling a debug build should work out of the box. If you want to compile a release build, you need to make sure that Xcode has the macOS 10.4 SDKs available (file MacOSX10.4u.sdk).

See Also

This page was last edited on 13 May 2017, at 22:31.