Difference between revisions of "CompilingWesnothOnMacOSX"

From The Battle for Wesnoth Wiki
(Compiling with the terminal)
m (OS X -> macOS)
 
(27 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{Compiling Wesnoth}}
 
{{Compiling Wesnoth}}
==  Introduction: Compiling Wesnoth on Mac OS X ==
+
==  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]],
 
Other than the generic Unix information on how to build at [[CompilingWesnoth]],
Line 8: Line 10:
 
[http://www.wesnoth.org/forum/viewtopic.php?t=287 How To Compile On A Mac]
 
[http://www.wesnoth.org/forum/viewtopic.php?t=287 How To Compile On A Mac]
 
and
 
and
[http://www.wesnoth.org/forum/viewtopic.php?t=4591 Help with using BfW for Mac OS X with command-line arguments].
+
[http://www.wesnoth.org/forum/viewtopic.php?t=4591 Help with using BfW for macOS with command-line arguments].
  
==  Compiling with the terminal  ==
+
==  Compiling with the terminal, Xcode tools, homebrew & scons ==
NOTE: Building with autotools has been removed as of 1.9.4. See below for compiling with XCode.
 
  
It is possible to compile with scons. Follow the the Fink related instructions, but replace ./configure, and make with appropriate scons commands (same as for other platforms).
+
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 Assumptions:
Line 19: Line 20:
 
* That you understand what compiliation is:  http://en.wikipedia.org/wiki/Compiling
 
* That you understand what compiliation is:  http://en.wikipedia.org/wiki/Compiling
 
* That you understand some of the basics of how to use a mac command line, especially the cd or chdir commands.  The following articles will help if you don't:  http://www.macobserver.com/tips/macosxcl101/index.html
 
* That you understand some of the basics of how to use a mac command line, especially the cd or chdir commands.  The following articles will help if you don't:  http://www.macobserver.com/tips/macosxcl101/index.html
* That you have downloaded a copy of the files in our Subversion Repository - all of the source code and data files needed to build the game.
+
* That you have downloaded a copy of the files in our version-control repository - all of the source code and data files needed to build the game.
  
 
=== Basic Ideas ===
 
=== 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 http://www.apple.com/developer/ .
 
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 http://www.apple.com/developer/ .
  
<tt>make</tt> and <tt>make install</tt> are traditional unix commands that compile a program for you from source.  <tt>make</tt> compiles the program, <tt>make install</tt> puts all of the non-code and code parts in the correct places - on a Unix system, this means that it puts the code in your executable search path. When you type a command in the command line, the system looks in a certain set of directories/folders to find any executable file, that is, any file of machine code, which matches the name.  <tt>make install</tt> takes care of doing that for you.
+
<tt>homebrew</tt> 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" https://github.com/mistydemeo/tigerbrew .
 
 
* http://en.wikipedia.org/wiki/Make
 
* http://en.wikipedia.org/wiki/Automake
 
 
 
Many of the headaches that <tt>make</tt>, and other programs like <tt>automake</tt> alleviate are things like dependencies, which are the other programs and libraries that the programs you are attempting to compile build off of.
 
 
 
The process involves first setting a configuration file, which tells make where you want the files to end up (for example, where your executable search path is).  You do this by entering the command <tt>./configure</tt> with a bunch of options following it.  If my name is John Doe, and that was also the name of my user account, I might enter the following:
 
 
 
<tt>./configure --bindir=/sw/bin --datadir=/Users/johndoe/wesnoth_data/ --with-libintl-prefix=/sw --with-libiconv-prefix=/sw</tt>
 
 
 
Some of these names, like <tt>wesnoth_data</tt> are whatever you choose them to be.  Namely, the <tt>--bindir</tt> and <tt>--datadir</tt> choose where your executable file goes, and where the images and game data files for Wesnoth go (don't confuse these with the preference files - these get created by Wesnoth when it runs, and go in a hidden folder called <tt>.wesnoth</tt> in your home directory).
 
 
 
 
 
However, you probably don't have any of these programs like <tt>make</tt> on your computer right now. What you will do is use a program known as [http://fink.sourceforge.net/ Fink] to download and install these Unix programs.  Unix command-line programs are made portable by being distributed as the source code they were made from - anyone can (theoretically) compile them on their own computer platform, and make them work, for free.  Unfortunately, this is generally a very difficult process that is prone to esoteric and difficult problems.  Fortunately, you don't have to solve them, because someone else already has - Fink is a master list of Unix programs for which all the headaches of getting them to compile on the Mac have been sorted out in advance. All you do is type a command (or click a button), and they will be downloaded, compiled, and installed into the correct spots on your machine!  FinkCommander, by the way, is the gui program that you use to drive the rest of what makes Fink work - as far as you're concerned, it's Fink, and it's all you have to download to run Fink.
 
 
 
Once you have Fink, you will download <tt>make</tt> and some other files needed to compile Wesnoth.  One of the most important of these is a set of libraries called SDL (Simple Direct media Layer), which allow programmers to write graphics (and other) code that will run on any platform SDL runs on (which is almost anything, these days).
 
  
With all of these downloaded, you will then run <tt>make</tt> and <tt>make install</tt>. After that, you can start Wesnoth from the command line by typing in the command <tt>wesnoth</tt>.  Some of the advantages of doing this are that you can see debug information, such as missing images, being dumped to the terminal window from which you typed the <tt>wesnoth</tt> command, and you can also specify certain command line options, like what bit depth the game graphics should run in. There is a way to get a double-clickable application (see below), but this really isn't anything remotely like Sithrandel's builds, and you may as well stick to the command line if you are, like most, using these builds to help create graphics or code for the game.
+
<tt>scons</tt> 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 ===
 
=== Outline of Steps ===
*  Get OS X 10.3 or 10.4
 
 
*  Install XCode
 
*  Install XCode
*  Download Fink
+
*  Download and install homebrew: http://brew.sh/
*  Download a copy of the SVN repository
+
* Install wesnoth dependencies (includes scons)
 
+
* Download a copy of the source-code repository (see [[WesnothRepository]]).
Use Fink to install the latest versions of the following:
+
* Use scons to compile
* Automake
 
* SDL
 
* SDL-mixer
 
* SDL-image
 
* SDL-net
 
* freetype2
 
* freetype2-dev
 
 
 
Then, these are the steps you repeat every time you want to compile wesnoth:
 
* Get an up-to-date copy of the game source and resources - usually by running <tt>svn update</tt>.
 
* change the working directory (using the <tt>cd</tt> command) to the bottom/"root" folder of those game files
 
* execute the command <tt>./autogen.sh</tt>
 
* execute the command <tt>./configure --bindir=</tt>'''/sw/bin''' <tt>--datadir=</tt>'''datadir''' <tt>--with-libintl-prefix=/sw --with-libiconv-prefix=/sw</tt>
 
** add <tt>--enable-editor</tt> to the end of this line to compile the map editor
 
* execute the command <tt>make</tt>
 
* execute the command <tt>sudo make install</tt>
 
 
 
At this point, you can run wesnoth by typing <tt>wesnoth</tt> in the command line.
 
* <tt>wesnoth_editor</tt> will run the map editor
 
 
 
=== Advanced/Specific Instructions for each step ===
 
 
 
Since 0.8.11+cvs the code compiles just fine on Mac OS X with gcc-3.3 (as shipped with Xcode 1.2 and 1.5) and gcc-4 (as shipped with Xcode 2.0), using the normal GNU autotools <tt>./configure; make; make install</tt> build process.
 
 
 
You do need a set of SDL libraries that have <tt>sdl-config</tt> installed -- the ones from Fink's unstable tree work well. The .pkg files from http://www.libsdl.org/ do not include <tt>sdl-config</tt> and are not designed for command-line building, so they are best avoided for now.
 
  
Fink is a program available from the [http://fink.sourceforge.net/ Fink homepage] that automates the installation of common Unix/Linux software.  The SDL, SDL-mixer, and SDL-image files are available as normal Fink packages.  SDL-net is unstable, so Fink does not list it by default (for your protection, presumably).  [http://fink.sourceforge.net/faq/usage-fink.php#unstable This page] describes how to activate unstable packages, after which you can install SDL-net normally.
+
=== Using homebrew ===
fink install SDL SDL-mixer SDL-image SDL-net
 
  
Also note that you need gettext-dev and libiconv-dev or equivalent, for instance, from Fink.  If you use Fink, you probably want libgettext3-dev and not gettext-dev, since the latter is currently based on an ancient 0.10 version of gettext and may result in warnings like
+
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:
  ld: Undefined symbols:
 
  _libintl_bind_textdomain_codeset
 
  _libintl_dgettext
 
  _libintl_gettext
 
  _libintl_bindtextdomain
 
when trying to link.
 
  
If you still have problems, you may need to change the normal config command to look like this:
+
  ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
./configure --with-libintl-prefix=/sw --with-libiconv-prefix=/sw
 
This is because fink installs everything into your /sw directory.  In fact, it is possible to have multiple copies of a single program on your system in various locations: one where you installed it and another in /sw.
 
  
ALSO note that fink installs freetype1 by default, but the game wants you to have freetype2.  Using the same fink installation process, install freetype2. I uninstalled freetype1 to avoid confusing 'make', but that may have been unnecessary.  The commands are:
+
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.
fink install freetype2 freetype2-dev
 
fink remove freetype freetype-dev
 
  
Building using the autotools configure/make process creates an application that has to be started from the commandline, but otherwise functions the same as on every other platform.  Since 0.9.2, you can also do
+
  brew tap homebrew/games
   make wesnoth_bundle
+
   brew install cairo --without-x11
   make wesnoth_editor_bundle
+
   brew install pango --without-x11
to create application bundles for the game and the map editor.  These are at present quite minimalist, with no icon or Finder information, but they can at least be launched from the Finder.  Note that these apps both look for the game data in <tt>${prefix}/share/wesnoth/</tt> which is usually <tt>/usr/local/share/wesnoth/</tt> unless you specified a different --prefix argument to <tt>configure</tt> when you built it.
+
  brew install wesnoth
  
Summary:
+
More detail is given on the wesnoth forums here: http://forums.wesnoth.org/viewtopic.php?f=5&t=41140#p577235
# Install Apple developer tools from the OS X install DVD (so you have gcc)
 
# Install Fink
 
# Activate unstable packages in Fink
 
# Install the SDL libraries using Fink
 
# Install libgettext3-dev using Fink
 
# Install freetype2 using Fink
 
# Run the <tt>./configure; make; make install</tt> sequence (either as-is or modified as described above or elsewhere)
 
  
 +
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:
  
=== Tuning the build ===
+
  brew install wesnoth --only-dependencies
  
One of the reason you may want to compile the game by yourself is to build an optimized version for your computer. For this, you just have to know which CPU you have (G3, G4, G5; etc.) By default, Wesnoth will compile with level 2 optimzation (-O2); to enable level 3 (the highest) on a G4 CPU (for example), run the following command instead of the usual <tt>./configure</tt>:
+
In this case you will end up running scons yourself with appropriate options.
  
  CXXFLAGS="-mtune=G4 -O3" ./configure
+
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.
  
For '''csh'''-like shell, such as '''tcsh''', the syntax is
+
=== Compiling ===
  
  setenv CXXFLAGS "-mtune=G4 -O3"  
+
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".
  ./configure
 
  
If you already built a Wesnoth binary with the current sources, clean your build with
+
Now execute scons:
  
   make clean
+
   scons jobs=3 gettextdir=`brew --prefix gettext`
  
then type
+
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:
  
   make && sudo make install
+
   scons jobs=3 nls=false
  
Note that <tt>-O3</tt> is not recomanded for all programs and hosts, as it may require more memory to run the program. On some host, you may try <tt>-Os</tt> which will optimize for size and may use less memory.
+
When it is finished, run wesnoth by typing
  
You may also get a bit more optimization using <tt>-mcpu=G4</tt> instead of <tt>-mtune=G4</tt>. This will cause the compiler to use instructions only available to the specified CPU, which could make it not work on any other CPU.  Use with care.
+
  ./wesnoth
  
This optimizations are only about the game by itself.  You may also want to build optimized versions of required libraries (SDL, gettext, etc.). If you built them yourself, rebuild them with the optimization arguments you want.  For tools written in C, as most are, use <tt>CFLAGS</tt> instead of <tt>CXXFLAGS</tt> for C++.  If the tool uses a <tt>configure</tt> script, just type
+
=== Tuning the Build ===
  
  CFLAGS="-mcpu=G4 -O3" ./configure ...
+
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
  
This should work with Fink too (<tt>CFLAGS="..." fink ...</tt>)
+
  scons extra_flags_release="-O3"
Don't forget to read the install documentation and requirements of each tool.
 
  
Note that, if you used Fink, the compiler will look for tools in <tt>/sw/bin</tt> before <tt>/usr/local/bin</tt>.
+
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 ==
 
== Build using XCode ==
This method is currently rather disjointed as some required parts have not been integrated for a while. The most up to date versions of each of the components are listed here, but building versions of Wesnoth older than 1.9 will not work using these instructions.
 
 
The Xcode project can be found in the svn tree and is usually up to date. The forum contains a link to a copy of the headers and frameworks needed for early 1.9, but Boost is out of date and the included copy of SDL does not support full screen in Lion. You will need to install your own version of Boost, and get a recent snapshot of SDL from the hg repository to support Lion.
 
  
Here are some basic steps to compile with XCode, most of which are taken from the [http://www.wesnoth.org/forum/viewtopic.php?t=287 thread discussion on the same topic].
+
=== Building Wesnoth 1.13 with Xcode ===
  
Summary:
+
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.
  
# Install XCode tools from the OS X install DVD. You currently need XCode 3.0 or later to use the project file.
+
==== macOS 10.9 and later ====
# Download and extract the source code to a folder; here we assume '''~/wesnoth'''
 
# Download additional compilation material from http://sourceforge.net/projects/wesnoth/files/unofficial/Mac%20Compile%20Stuff/
 
: -> Copy its contents into ~/wesnoth/projectfiles/Xcode/
 
# Install Boost and replace the copy included with the Mac Compile Stuff download
 
# Download a recent official BFW OS X package
 
: -> The more recent it is, the less likely you are to have problems with the build.
 
# In the recent package, locate SDL.framework and replace the one included in the download
 
# Open '''BattleForWesnoth.xcodeproj'''
 
# Make sure the target you want is selected in the pop-up menu (usually '''Battle For Wesnoth''')
 
# Click '''Build'''
 
  
=== Troubleshooting the Build Step ===
+
* Install Xcode.
 +
* Download and extract the [[WesnothRepository|Wesnoth Repository]] to a folder on your computer.
 +
* Download the [http://sourceforge.net/projects/wesnoth/files/unofficial/Mac%20Compile%20Stuff/ Xcode compilation material.] For master, you need wesnoth_compile_mac_1.13.zip.  [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.
  
At this point, you may run into an error that causes the build to failHere are ways to deal with some of them:
+
That is all that should be requiredOpen projectfiles/Xcode/Wesnoth.xcodeproj and compile.
  
==== Can't find '''SDL.h''' (or similar) ====
+
==== macOS 10.8 ====
  
This is usually the first error of manyThe XCode project file assumes you installed the SDL frameworks in '''/Library/Frameworks'''.  If you decide to install them somewhere else (for example, '''~/Library/Frameworks'''), you need to tell the project file where to look.
+
None of the Wesnoth macOS developers currently has access to macOS 10.8, so we are not sure which method will workTry 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.
  
# Expand '''Targets''' in the project window, and double-click on '''Battle for Wesnoth'''.
+
==== macOS 10.6 and 10.7 ====
# Click the '''Build''' tab, and make sure '''Collection''' is set to '''Customized Settings''' .
 
# Click '''Header Search Paths''', and then click '''Edit'''.
 
# Click the '''+''' to add a new search path, and type in the path to the '''Headers''' directory inside the SDL framework.
 
# Repeat the previous step for each of the other SDL frameworks, then click '''OK''' and close the Info window.
 
# Locate '''SDL.framework''' in the right-hand pane of the project window (it should appear in red), click on it, and then click '''Info'''.
 
# Click '''Choose...''', locate '''SDL.framework''' on your system, and close the Info window.
 
# Repeat the previous two steps for each of the other SDL frameworks.
 
  
==== Undefined symbols ====
+
* 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 <code>sudo port selfupdate</code>.
 +
* The script is called setup_Xcode_10_6.sh 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 <code>chmod +x setup_Xcode_10_6.sh</code>.
 +
* 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 <code>sudo ./setup_Xcode_10_6.sh</code> 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.
  
The project file contains a list of the files in the '''src''' folder.  If new files were added to the '''src''' folder since the last release, your old XCode project file won't know about them.  This is less likely to happen when the project file is from the latest release.
+
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.
  
# Expand the '''Wesnoth''' group in the project window.
+
'''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.
# In the Finder, select any files in the '''src''' folder that are not listed in the project window.
 
# Drag them into the '''src''' group, and click '''OK'''.
 
  
==== Warnings ====
+
==== macOS 10.5 and earlier ====
  
Warnings tend to be very likely to occur when building any large projectThey will not cause the build to fail, and can generally be ignored, unless they seem particularly ominous.
+
Unfortunately, the changes from macOS 10.5 to 10.6 are too significant to support compiling on versions before 10.6 any moreIt 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.
  
=== More About XCode Builds ===
+
=== Building Wesnoth 1.12 with Xcode ===
  
This build uses a more "Mac-like" set of defaults, for instance putting all the information that is usually in the '''~/.wesnoth/''' directory into the '''~/Library/Application Support/Wesnoth 1.x/''' folder, and placing the system-wide game files (which are usually in '''/usr/local/share/wesnoth/''') inside the '''Battle For Wesnoth.app''' folder of the application itself. If you want to use both, just make a symbolic link between the directories:
+
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 wesnoth_compile_mac_1.11.zip from [http://sourceforge.net/projects/wesnoth/files/unofficial/Mac%20Compile%20Stuff/ Xcode compilation material.]
ln -s Library/Preferences/Wesnoth ~/.wesnoth
 
Before running this command, make sure '''~/.wesnoth''' does not exist.  If necessary, merge the information within it and delete it.
 
  
The commandline and Cocoa-app approaches are hopefully going to be merged at some stage in the future, but some additional scripts still need to be written to keep the project file in sync.
+
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 ==
 
== See Also ==

Latest revision as of 22:31, 13 May 2017

[edit]Compiling Wesnoth

Platforms
Tools

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 http://www.apple.com/developer/ .

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" https://github.com/mistydemeo/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: http://brew.sh/
  • 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 https://raw.githubusercontent.com/Homebrew/install/master/install)”

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: http://forums.wesnoth.org/viewtopic.php?f=5&t=41140#p577235

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.

Compiling

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

 ./wesnoth

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 wesnoth_compile_mac_1.13.zip. [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 setup_Xcode_10_6.sh 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 setup_Xcode_10_6.sh.
  • 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 ./setup_Xcode_10_6.sh 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 wesnoth_compile_mac_1.11.zip 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.