Building Spring on MacOSX: Difference between revisions

From Spring
Jump to navigationJump to search
Abma (talk | contribs)
Af (talk | contribs)
No edit summary
 
(46 intermediate revisions by 7 users not shown)
Line 1: Line 1:
[[Engine_Development|Development]] < [[Building_spring|Building Spring]] < {{FULLPAGENAME}}
[[Engine_Development|Development]] < [[Building_spring|Building Spring]] < {{FULLPAGENAME}}


If you want only to play a spring game, follow the [[Spring_on_MacOSX]] Tutorial.
This is a guide to the requirements for building the Spring RTS engine on MacOS. If you want only to play a spring game, follow the [[Spring_on_MacOSX]] Tutorial.




=Build from source on MacOSX=


'''Guide is for x86/Intel based OSX installs'''
=Building Spring on MacOS=


I am hoping that with our efforts on the forum that we can have an .app bundle released everytime spring is updated and that will save most people needing to go through the headache of compiling from source code. But if you must try, then here's the steps to help!
'''This guide is for x86/Intel based MacOS installs'''


I cannot stress enough that this will most likely only work on Intel based systems at this stage. With my understanding of how unitsync works, it seems like online play will not be possible between PPC and x86 architecture.
Even though it will not run, Spring should successfully compile on Mac for both 104.0 and the latest develop version.


=Obtaining the Source=
NOTE: Only official spring versions 99.0-103.1 will compile and run on MacOS. 104+ will compile, but uses an incompatible OpenGL version. When 105.0 is released, a MacOS - compatible OpenGL version will be used, however at this point in time '''there are other blocking issues'''.
{{Obtaining_The_Source_Code}}


=Get Dependencies=
Questions about this process should be asked [https://springrts.com/phpbb/viewforum.php?f=65 here].


You will need to install some development packages Spring depends on. Most of these are available using [http://www.macports.org/ Macports] (similar to portage / apt-get etc available on various linux distro's)


You will also need to install the [http://developer.apple.com/TOOLS/Xcode/ Xcode developers package] (this requires a free membership to apple's ADC website)


==Full list==
=Requirements=
 
==Command Line Tools==
 
Install the [http://developer.apple.com/TOOLS/Xcode/ Xcode developers package] (this requires a free membership to apple's ADC website).
 
==Package Manager==
 
Either  [http://brew.sh Homebrew] or [http://www.macports.org/install.php MacPorts] may be used to fetch dependencies. The MacOS Buildbot (run by Turboss) uses Homebrew. The writer uses Macports.
 
 
== Compiler==
 
Compiler: GCC must be used, and dependencies must be compiled with GCC
 
=== MacPorts ===
 
For MacPorts:
<pre>
port install
sudo port select --set gcc mp-gcc8
hash -r # Reload the terminal
</pre>
 
To check for installed gcc:
<code>
port select --list gcc
</code>
 
===HomeBrew===
 
<pre>
brew install gcc@8
</pre>
 
 
==Dependencies==
 
===MacPorts===
 
Necessary dependencies for the develop branch are below (as called by Macports):
 
<pre>
port install sudo port install cmake libsdl2 p7zip libdevil libvorbis minizip openal-soft glew freetype binutils libXcursor +gcc8
</pre>
 
(This list has not been tested for errors; please message MasterBel if they do not work for you.)
 
Compiling Spring 104.0 (current master) or older will also require Boost. [https://sourceforge.net/projects/boost/ Retreive source] and compile with gcc. '''TODO: Instructions?'''
 
===HomeBrew===
 
Note that this list is incomplete:
 
<pre>
brew install cmake minizip freetype glew openal-soft p7zip clang-format libvorbis jsoncpp PkgConfig devil sdl2
</pre>
 
You will also need to install XQuartz for the X11 dependency, however it will install the headers in a non-standard location. Use this command to symlink it to the standard location:
 
<pre>
ln -s /opt/X11/include/X11 /usr/local/include/X11
</pre>
 
==Obtaining Source==
 
<code>
git clone --recursive git://github.com/spring/spring.git -b <branch>
</code>
 
The “master” branch is the latest stable release. “develop” branch is the latest development release. (Note: The recursive argument is important for submodules.)<br />
Update with: <code>git pull --rebase</code>
 
=Compiling Source=
 
<pre>
cmake . -DCMAKE_CXX_COMPILER=/path/to/bin/g++-mp-8 -DCMAKE_C_COMPILER=/path/to/bin/gcc-mp-8
make spring
</pre>
 
Other common Cmake flags are:
<pre>
-DGLEW_INCLUDE_DIR=/path/to/include
-DGLEW_LIBRARIES=/path/to/lib/libGLEW.a
-DOPENAL_INCLUDE_DIR=/path/to/include/AL
-DCMAKE_INSTALL_PREFIX:PATH=/path/to/output/directory
-DCMAKE_PREFIX_PATH=/path/
</pre>
 
If boost is used:
<code>
-DBoost_Root=/path/to/boost
</code>
 
Number of simultaneous jobs may be specified by: <code>make spring -j<n></code> Where n is number of jobs. It is common for n to be number of cores + 1
 
Other targets may be made also/instead, e.g.
 
<pre>
make prdownloader -j<n>
make install-spring -j<n>
</pre>
 
=Additional Notes=


*Programs necessary to build
**Xcode
**cmake
**zip
**The usual build toolchain
***gcc ''(comes with Xcode tools)''
***make ''(comes with Xcode tools)''
*Libraries
**SDL
**boost (version 1.35 or later recommended)
***threads
***regex
***signals
***system
**DeviL (IL, ILU)
**OpenAL ''Please check the OpenAL section for MacOSX specific info''
**OpenGL headers (mesa, glew, etc.) ''(comes with Xcode tools)''
**zlib
**freetype
**ogg,vorbis and vorbisfile
*Optional, for bindings and Ais
**Python (2.5)
**Java-SDK ''(pre-installed on OSX)''


==Using Macports==
==Using Macports==
As hint: set "buildmakejobs" to cpu-core count + 1 in /opt/local/etc/macports/macports.conf. For example:
As hint: set "buildmakejobs" to cpu-core count + 1 in /opt/local/etc/macports/macports.conf. For example:
<code><pre>
<code>
buildmakejobs 5
buildmakejobs 5
</pre></code>
</code>
 
 
==Using Homebrew==
 
Hombrew can install boost, but it must be recompiled  with gcc <version>:
<code>
brew install boost --build-from-source --cc=gcc<version>
</code>
 
These flags were recommended by a previous editor:
<pre>
cmake . -DAPPLE=1 -DCMAKE_CXX_COMPILER=/usr/local/Cellar/gcc48/4.8.3/bin/g++-4.8 \
-DCMAKE_C_COMPILER=/usr/local/Cellar/gcc48/4.8.3/bin/gcc-4.8 \
-DIL_INCLUDE_DIR=/usr/local/include \
-DGLEW_INCLUDE_DIR=/usr/local/include \
-DOPENAL_DIR=/usr/local/include/AL \
-DNO_SOUND=1
</pre>
 
 
=Examples=
 
==Macports==
 
<pre>
# Example setup script (for MacOS Catalina)
 
# Macports must be installed prior to running this script. Macports requires XCode to be installed.
# Boost sources must be located in
 
# Requires the following directory format:
# $DIR (customisable; set on line 16)
# /setup.sh
# /build.sh
# /Sources
# /boost_1_68_0
# /Builds
# /Bunldes
 
DIR=~/Spring # The root directory; to be set manually
 
SCRIPTDIR=~/Documents/Spring/ # The directory the build script is located in


Once you have downloaded and configured Macports use these commands to download /  
SOURCES=$DIR/Sources
compile and install the required dependencies:
SPRING=$SOURCES/spring
BOOST=$SOURCES/boost_1_66_0/boost


cd $DIR


<code><pre>
# Install the necessary compiler. Version gcc5 is oldest compatible with High Sierra; gcc48 is the oldest I know works
sudo port install cmake libsdl libsdl-framework boost boost-jam libpng jpeg \
sudo port install gcc9
                  tiff libogg libvorbis python27 libdevil git-core binutils \
                  p7zip glew gcc47
</pre></code>
libpng might not be needed, but may save you some headaches
binutils are required because of "addr2line", this allows finding bugs.


<code><pre>
# Set compiler as default
sudo port select --set gcc mp-gcc47
sudo port select --set gcc mp-gcc9
hash -r
hash -r
</pre></code>


if you don't know the installed gcc, type:
sudo port install cmake libsdl2 p7zip libdevil libvorbis minizip openal-soft glew freetype binutils dylibbundler xorg-libXcursor +gcc9
<code><pre>
#dylibbundler is for the bundling stage, not actual dependency
port select --list gcc
 
</pre></code>
cd $SOURCES
 
# Clone from git (creates the directory $SPRING for us)
git clone --recursive git://github.com/spring/spring.git
cd $SPRING
git fetch --all --tags --prune
git checkout tags/103.0 -b master
 
# Install Boost
 
cd $BOOST
 
./bootstrap.sh --with-toolset=gcc --with-libraries=all # Not sure which libaries.
./b2 # install
 
# Try compiling spring
 
cd $SCRIPTDIR
 
sh build.sh
 
</pre>
 
<pre>
 
# Example buildscript (for MacOS Catalina)
 
# This script assumes that setup.sh (the above example) has been run.


As of October 12th 2009, the Macports install of ''libdevil'' (''1.6.8-rc2_0'') is broken for some people.
# Build Configuration
If you get errors like:
<code>/opt/local/include/IL/il.h:505: error: ‘<anonymous>’ has incomplete type</code>
while building spring, you will probably need to install it from source.


If all was successful, you are very close to being able to compile Spring naively!
BRANCH=<branch name> # The source branch to checkout and build.
REPOSITORY=spring # The name of the folder containing the git repository.
WIPE=0 # Wipes previous build on WIPE = 1 (flag -w)


==Installing ''libdevil'' from source==
for arg in "$@"
do
if [ "$arg" == "-w" ]; then
echo "Initiating clean build."
WIPE=1
else
echo "Unknown flag ${arg}"
fi
done


Make sure that all the other port packages are installed first!
echo "Building sources at/to ${REPOSITORY}"
Download the source.  Right now ''1.6.8-rc2_0'' has the bug we are trying to work around, so do not use that one, or earlier versions.


Extract the source code.
# Directory Setup


Configure with this command:
DIR=~/Spring # Where everything is/will be
<code><pre>
SOURCES=$DIR/Sources
./configure --enable-png --enable-ILU --enable-ILUT --enable-x86_64 CPPFLAGS="-I/opt/local/include/ -L/opt/local/lib/" LDFLAGS=-L/opt/local/lib/
SPRING=$SOURCES/$REPOSITORY
</pre></code>
BUILD=$DIR/Builds/$REPOSITORY
BOOST=$SOURCES/boost_1_55_0 # Where boost can be found. Must be prepared as per the setup script (above).


Make sure you have support for png, jpg, dds, and tga
MACPORTS=/opt/local # The install directory of MACPORTS


Build it with:
if [ -d $BUILD ]; then
<code><pre>
if [ $WIPE != 0 ]; then
make
echo "Wiping previous build…"
</pre></code>
rm -r $BUILD # Wipe preivous build


echo "Making new build directory…"
mkdir $BUILD # The others should have already been made
fi
else
echo "Making new build directory…"
mkdir $BUILD # The others should have already been made
fi


Part way through you'll get an error about ''malloc.h'' not being found.  To fix it, replace ''<malloc.h>'' with ''<sys/malloc.h>''
if [ -e $DIR/log.txt ]; then
echo "Removing outdated log…"
rm $DIR/log.txt
fi


install with:
# Source setup
<code><pre>
sudo make install
</pre></code>


==OpenAL==
if [ -d $SPRING ]; then
cd $SPRING
else
echo "Cloning remote…"
    cd $SOURCES
    git clone --recursive git://github.com/spring/spring.git $REPOSITORY


After having mountains of problems myself with the OpenAL pre-installed with the Xcode tools, I discovered that it is version 1.0 of OpenAL (not the correct version we want).
cd $SPRING
fi


Head to your ''/System/Library/Framework/'' folder and delete any trace of OpenAL framework / folders that are there.
# Update repository


[http://kcat.strangesoft.net/openal-releases/openal-soft-1.8.466.tar.bz2 Now download this copy of OpenAL]
CURRENTBRANCH=$(git rev-parse --abbrev-ref HEAD)


Using the terminal, go into the folder where you downloaded openal-soft and pass these commands:
if [ "$CURRENTBRANCH" != "$BRANCH" ]; then
git fetch --all
echo "Switching branch from ${CURRENTBRANCH} to ${BRANCH}"
git checkout $BRANCH
fi


<code><pre>
echo "Updating to latest…"
bzip2 -d openal-soft-xxxx.tar.bz2 | tar xvf -
git pull # Update to latest
cd openal-soft-xxxx
echo "Updating submodules"
cmake .
git submodule update
make
make install
</pre></code>


All done, now you will have no problems compiling the ''Sound.cpp'' file in spring!
# Metadata


=Build And Install=
REV=$(git describe --tags)
VERSION=`echo "${REV}" | tr '<>:\"/\\|?*' -`


The build will spew out warnings like the following, which you can safely ignore:<br>
# Compile
warning: division by zero<br>
warning: 'q' may be used uninitialized in this function<br>


==Removing duplicate libraries==
echo "Compiling Spring ${VERSION}"


Make sure that you remove all extra libraries before the first time you call ''cmake''.  If not, ''cmake'' will make your life a living hell.  Check in ''/usr'', ''/usr/local'', ''/opt/local'' and ''/Library/Frameworks''.  Also, do not change the location of the source directory, librarys, or includes after calling ''cmake''.  If you do change any of the locations you can not just call ''cmake'' again.  The only way I know to tell it to recompute everything from scratch is this:
cd $BUILD


* rm CMakeCache.txt
cmake . $SPRING -DCMAKE_PREFIX_PATH=$MACPORTS -DCMAKE_CXX_COMPILER=$MACPORTS/bin/g++-mp-9 -DCMAKE_C_COMPILER=$MACPORTS/bin/gcc-mp-9 -DGLEW_INCLUDE_DIR=$MACPORTS/include -DGLEW_LIBRARIES=$MACPORTS/lib/libGLEW.a -DOPENAL_INCLUDE_DIR=$MACPORTS/include/AL -DBOOST_ROOT=$BOOST -DBoost_USE_STATIC_LIBS=YES -DCMAKE_CXX_FLAGS="${FLAGS}" -DCMAKE_C_FLAGS="${FLAGS}"
* if that's not enough, you can cleanup the git dir with <code>git clean -d -x -n</code> (replace -n with -f to really remove the displayed files)
* Run <code>git reset --hard</code>


==Using CMake (2.6 or newer) (Adso's method)==
make spring -j5 # >>$DIR/log.txt 2>&1
This is the only way I have compiled spring successfully so far:


(could someone please add a better way? As I cannot workout how to get xcodebuild to run the "install portion of the make file")
make pr-downloader # -j5 >>$DIR/log.txt 2>&1


<code><pre>cmake .
make install-spring DESTDIR=$BUILD/temp #>>$DIR/log.txt 2>&1
make spring
make install-spring</pre></code>


This will install spring in all the right places to be run from a command line (but don't yet, it compiles an unusable executable, we just needed to get the makefile to install everything to the right place)
# Bundling spring


Now pass these commands
BUNDLES=$DIR/Bundles
BUNDLE=$BUNDLES/Spring_${VERSION}.app


<code><pre>cmake -G Xcode
mkdir $BUNDLES
xcodebuild</pre></code>
mkdir $BUNDLE
mkdir $BUNDLE/Contents
mkdir $BUNDLE/Contents/MacOS
mkdir $BUNDLE/Contents/Resources
mkdir $BUNDLE/Contents/lib


This will have made a folder called "Debug" and will contain a command line program Spring, and ''Libunitsync.dylib''
cp $BUILD/spring $BUNDLE/Contents/MacOS/spring #>>$DIR/log.txt 2>&1
cp $SPRING/installer/Mac/spring.icns $BUNDLE/Contents/Resources/spring.icns #>>$DIR/log.txt 2>&1
cp -R $BUILD/temp/usr/local/share $BUNDLE/Contents/share #>>$DIR/log.txt 2>&1


now to make sure the correct copy of spring runs when you are using the terminal pass the following command
cat $SPRING/installer/Mac/Info.plist | sed s/###VERSION###/${VERSION}/ > $BUNDLE/Contents/Info.plist


<code><pre>sudo cp spring /usr/local/bin</pre></code>
cp $BUILD/tools/pr-downloader/src/pr-downloader $BUNDLE/Contents/MacOS #>>$DIR/log.txt 2>&1


Now you are ready to ready to play Spring on your MacOSX system!
dylibbundler -cd -b -x $BUILD/temp/usr/local/lib/libunitsync.dylib -d $BUNDLE/Contents/MacOS -p @loader_path/../MacOS #>>$DIR/log.txt 2>&1
Enjoy!


==Using CMake (2.6 or newer) (patmo98's method)==
dylibbundler -of -cd -b -x $BUNDLE/Contents/MacOS/spring -d $BUNDLE/Contents/lib -p @executable_path/../lib #>>$DIR/log.txt 2>&1
The worst problem I ran into while trying to use Adso's method was getting the include and library paths to work.
'''This probably won't be needed unless you you been installing libraries from source or using fink.'''


Make sure before you start that you don't have any extra copies of libraries laying around.
install_name_tool -change $MACPORTS/lib/libX11.6.dylib @executable_path/../lib/libX11.6.dylib $BUNDLE/Contents/lib/libXcursor.1.dylib #>>$DIR/log.txt 2>&1


Get the dependencies and source code.
dylibbundler -of -cd -b -x $BUNDLE/Contents/MacOS/pr-downloader -d $BUNDLE/Contents/lib -p @executable_path/../lib #>>$DIR/log.txt 2>&1


<code><pre>ccmake .
dylibbundler -cd -b -x $BUNDLE/Contents/share/games/spring/AI/Interfaces/C/0.1/libAIInterface.dylib -d $BUNDLE/Contents/share/games/spring/AI/Interfaces/C/0.1 -p @loader_path/../0.1 #>>$DIR/log.txt 2>&1
</pre></code>


If you see a list of options here, you've already run (''c'')''cmake'' before and that may cause you trouble. Press ''c'' to have it auto configure. Press ''t'' to switch to advanced mode. Manually add the following includes and librarys. Yes, this is an ugly hack that should be instead fixed in the build system, but I don't know enough about ''cmake'' to fix it.
dylibbundler -cd -b -x $BUNDLE/Contents/share/games/spring/AI/Interfaces/Java/0.1/libAIInterface.dylib -d $BUNDLE/Contents/share/games/spring/AI/Interfaces/Java/0.1 -p @loader_path/../0.1 #>>$DIR/log.txt 2>&1


<code><pre>
dylibbundler -cd -b -x $BUNDLE/Contents/share/games/spring/AI/Skirmish/AAI/0.9/libSkirmishAI.dylib -d $BUNDLE/Contents/share/games/spring/AI/Skirmish/AAI/0.9 -p @loader_path/../0.9 #>>$DIR/log.txt 2>&1
CMAKE_CXX_FLAGS                  -I/usr/local/include -I/opt/local/include
CMAKE_C_FLAGS                    -I/usr/local/include -I/opt/local/include
CMAKE_EXE_LINKER_FLAGS          -L/usr/local/lib -L/opt/local/lib
</pre></code>


You may need to add more directories.
dylibbundler -cd -b -x $BUNDLE/Contents/share/games/spring/AI/Skirmish/CppTestAI/0.1/libSkirmishAI.dylib -d $BUNDLE/Contents/share/games/spring/AI/Skirmish/CppTestAI/0.1 -p @loader_path/../0.1 #>>$DIR/log.txt 2>&1


Now you can compile:
dylibbundler -cd -b -x $BUNDLE/Contents/share/games/spring/AI/Skirmish/E323AI/3.25.0/libSkirmishAI.dylib -d $BUILD/Spring.app/Contents/share/games/spring/AI/Skirmish/E323AI/3.25.0 -p @loader_path/../3.25.0 #>>$DIR/log.txt 2>&1
<code><pre>make spring
</pre></code>


If the build finishes successfully, you will now have the ''spring'' executable, ''unitsync.dylib'', and some other assorted things.
dylibbundler -cd -b -x $BUILD/Spring.app/Contents/share/games/spring/AI/Skirmish/KAIK/0.13/libSkirmishAI.dylib -d $BUILD/Spring.app/Contents/share/games/spring/AI/Skirmish/KAIK/0.13 -p @loader_path/../0.13 #>>$DIR/log.txt 2>&1


Spring will search for ''Libunitsync.dylib'' in the same directory as the executable (and possibly other places), and search for the data files in ''~/.spring/''.
dylibbundler -cd -b -x $BUNDLE/Contents/share/games/spring/AI/Skirmish/NullAI/0.1/libSkirmishAI.dylib -d $BUNDLE/Contents/share/games/spring/AI/Skirmish/NullAI/0.1 -p @loader_path/../0.1 #>>$DIR/log.txt 2>&1
If you have access to a working windows install, just copy the windows install to ''~/.spring/'' and run the executable from where ever you like.


dylibbundler -cd -b -x $BUNDLE/Contents/share/games/spring/AI/Skirmish/RAI/0.601/libSkirmishAI.dylib -d $BUNDLE/Contents/share/games/spring/AI/Skirmish/RAI/0.601 -p @loader_path/../0.601 #>>$DIR/log.txt 2>&1


Now you are ready to play Spring on your Mac OS X system!
dylibbundler -cd -b -x $BUNDLE/Contents/share/games/spring/AI/Skirmish/Shard/dev/libSkirmishAI.dylib -d $BUILD/Spring.app/Contents/share/games/spring/AI/Skirmish/Shard/dev -p @loader_path/../dev #>>$DIR/log.txt 2>&1
Enjoy!


=Finalizing installation=
if [ ! -e $BUNDLE/Contents/MacOS/spring ];then
echo "Error: App did not build correctly. Check log for details"
ERRORBUILD=1
fi


Will update later once I update the Springlobby wiki with all my OSX information!
if [ "$ERRORBUILD" = "1" ]; then
echo "Build Failed."
fi


If you need to contact me, send a PM to '''adso''' on the forums, or catch me in #sy or #springlobby in the lobby chat :)
echo "Done!"
exit 0


--[[User:Adso|Adso]] 06:23, 29 August 2009 (UTC)
</pre>


[[Category:Compiling]]
[[Category:Compiling]]

Latest revision as of 18:44, 4 March 2020

Development < Building Spring < Building Spring on MacOSX

This is a guide to the requirements for building the Spring RTS engine on MacOS. If you want only to play a spring game, follow the Spring_on_MacOSX Tutorial.


Building Spring on MacOS

This guide is for x86/Intel based MacOS installs

Even though it will not run, Spring should successfully compile on Mac for both 104.0 and the latest develop version.

NOTE: Only official spring versions 99.0-103.1 will compile and run on MacOS. 104+ will compile, but uses an incompatible OpenGL version. When 105.0 is released, a MacOS - compatible OpenGL version will be used, however at this point in time there are other blocking issues.

Questions about this process should be asked here.


Requirements

Command Line Tools

Install the Xcode developers package (this requires a free membership to apple's ADC website).

Package Manager

Either Homebrew or MacPorts may be used to fetch dependencies. The MacOS Buildbot (run by Turboss) uses Homebrew. The writer uses Macports.


Compiler

Compiler: GCC must be used, and dependencies must be compiled with GCC

MacPorts

For MacPorts:

port install
sudo port select --set gcc mp-gcc8
hash -r # Reload the terminal

To check for installed gcc: port select --list gcc

HomeBrew

brew install gcc@8


Dependencies

MacPorts

Necessary dependencies for the develop branch are below (as called by Macports):

port install sudo port install cmake libsdl2 p7zip libdevil libvorbis minizip openal-soft glew freetype binutils libXcursor +gcc8

(This list has not been tested for errors; please message MasterBel if they do not work for you.)

Compiling Spring 104.0 (current master) or older will also require Boost. Retreive source and compile with gcc. TODO: Instructions?

HomeBrew

Note that this list is incomplete:

brew install cmake minizip freetype glew openal-soft p7zip clang-format libvorbis jsoncpp PkgConfig devil sdl2

You will also need to install XQuartz for the X11 dependency, however it will install the headers in a non-standard location. Use this command to symlink it to the standard location:

ln -s /opt/X11/include/X11 /usr/local/include/X11

Obtaining Source

git clone --recursive git://github.com/spring/spring.git -b <branch>

The “master” branch is the latest stable release. “develop” branch is the latest development release. (Note: The recursive argument is important for submodules.)
Update with: git pull --rebase

Compiling Source

cmake . -DCMAKE_CXX_COMPILER=/path/to/bin/g++-mp-8 -DCMAKE_C_COMPILER=/path/to/bin/gcc-mp-8
make spring

Other common Cmake flags are:

-DGLEW_INCLUDE_DIR=/path/to/include 
-DGLEW_LIBRARIES=/path/to/lib/libGLEW.a 
-DOPENAL_INCLUDE_DIR=/path/to/include/AL 
-DCMAKE_INSTALL_PREFIX:PATH=/path/to/output/directory 
-DCMAKE_PREFIX_PATH=/path/

If boost is used: -DBoost_Root=/path/to/boost

Number of simultaneous jobs may be specified by: make spring -j<n> Where n is number of jobs. It is common for n to be number of cores + 1

Other targets may be made also/instead, e.g.

make prdownloader -j<n>
make install-spring -j<n>

Additional Notes

Using Macports

As hint: set "buildmakejobs" to cpu-core count + 1 in /opt/local/etc/macports/macports.conf. For example: buildmakejobs 5


Using Homebrew

Hombrew can install boost, but it must be recompiled with gcc <version>: brew install boost --build-from-source --cc=gcc<version>

These flags were recommended by a previous editor:

cmake . -DAPPLE=1 -DCMAKE_CXX_COMPILER=/usr/local/Cellar/gcc48/4.8.3/bin/g++-4.8 \
-DCMAKE_C_COMPILER=/usr/local/Cellar/gcc48/4.8.3/bin/gcc-4.8 \
-DIL_INCLUDE_DIR=/usr/local/include \
-DGLEW_INCLUDE_DIR=/usr/local/include \
-DOPENAL_DIR=/usr/local/include/AL \
-DNO_SOUND=1


Examples

Macports

# Example setup script (for MacOS Catalina)

# Macports must be installed prior to running this script. Macports requires XCode to be installed.
# Boost sources must be located in

# Requires the following directory format:
# $DIR (customisable; set on line 16)
#	/setup.sh
#	/build.sh
# 	/Sources
#		/boost_1_68_0
#	/Builds
#	/Bunldes

DIR=~/Spring # The root directory; to be set manually

SCRIPTDIR=~/Documents/Spring/ # The directory the build script is located in

SOURCES=$DIR/Sources
SPRING=$SOURCES/spring
BOOST=$SOURCES/boost_1_66_0/boost

cd $DIR

# Install the necessary compiler. Version gcc5 is oldest compatible with High Sierra; gcc48 is the oldest I know works
sudo port install gcc9

# Set compiler as default
sudo port select --set gcc mp-gcc9
hash -r

sudo port install cmake libsdl2 p7zip libdevil libvorbis minizip openal-soft glew freetype binutils dylibbundler xorg-libXcursor +gcc9
#dylibbundler is for the bundling stage, not actual dependency

cd $SOURCES

# Clone from git (creates the directory $SPRING for us)
git clone --recursive git://github.com/spring/spring.git
cd $SPRING
git fetch --all --tags --prune
git checkout tags/103.0 -b master

# Install Boost

cd $BOOST

./bootstrap.sh --with-toolset=gcc --with-libraries=all # Not sure which libaries.
./b2 # install

# Try compiling spring

cd $SCRIPTDIR

sh build.sh


# Example buildscript (for MacOS Catalina)

# This script assumes that setup.sh (the above example) has been run.

# Build Configuration

BRANCH=<branch name> # The source branch to checkout and build.
REPOSITORY=spring # The name of the folder containing the git repository.
WIPE=0 # Wipes previous build on WIPE = 1 (flag -w)

for arg in "$@"
do
if [ "$arg" == "-w" ]; then
echo "Initiating clean build."
WIPE=1
else
echo "Unknown flag ${arg}"
fi
done

echo "Building sources at/to ${REPOSITORY}"

# Directory Setup

DIR=~/Spring # Where everything is/will be
SOURCES=$DIR/Sources
SPRING=$SOURCES/$REPOSITORY
BUILD=$DIR/Builds/$REPOSITORY
BOOST=$SOURCES/boost_1_55_0 # Where boost can be found. Must be prepared as per the setup script (above).

MACPORTS=/opt/local # The install directory of MACPORTS

if [ -d $BUILD ]; then
	if [ $WIPE != 0 ]; then
		echo "Wiping previous build…"
		rm -r $BUILD # Wipe preivous build

		echo "Making new build directory…"
		mkdir $BUILD # The others should have already been made
	fi
else
	echo "Making new build directory…"
	mkdir $BUILD # The others should have already been made
fi

if [ -e $DIR/log.txt ]; then
	echo "Removing outdated log…"
	rm $DIR/log.txt
fi

# Source setup

if [ -d $SPRING ]; then
	cd $SPRING
else
	echo "Cloning remote…"
    cd $SOURCES
    git clone --recursive git://github.com/spring/spring.git $REPOSITORY

	cd $SPRING
fi

# Update repository

CURRENTBRANCH=$(git rev-parse --abbrev-ref HEAD)

if [ "$CURRENTBRANCH" != "$BRANCH" ]; then
git fetch --all
echo "Switching branch from ${CURRENTBRANCH} to ${BRANCH}"
git checkout $BRANCH
fi

echo "Updating to latest…"
git pull # Update to latest
echo "Updating submodules"
git submodule update

# Metadata

REV=$(git describe --tags)
VERSION=`echo "${REV}" | tr '<>:\"/\\|?*' -`

# Compile

echo "Compiling Spring ${VERSION}"

cd $BUILD

cmake . $SPRING -DCMAKE_PREFIX_PATH=$MACPORTS -DCMAKE_CXX_COMPILER=$MACPORTS/bin/g++-mp-9 -DCMAKE_C_COMPILER=$MACPORTS/bin/gcc-mp-9 -DGLEW_INCLUDE_DIR=$MACPORTS/include -DGLEW_LIBRARIES=$MACPORTS/lib/libGLEW.a -DOPENAL_INCLUDE_DIR=$MACPORTS/include/AL -DBOOST_ROOT=$BOOST -DBoost_USE_STATIC_LIBS=YES -DCMAKE_CXX_FLAGS="${FLAGS}" -DCMAKE_C_FLAGS="${FLAGS}"

make spring -j5 # >>$DIR/log.txt 2>&1

make pr-downloader # -j5 >>$DIR/log.txt 2>&1

make install-spring DESTDIR=$BUILD/temp #>>$DIR/log.txt 2>&1

# Bundling spring

BUNDLES=$DIR/Bundles
BUNDLE=$BUNDLES/Spring_${VERSION}.app

mkdir $BUNDLES
mkdir $BUNDLE
mkdir $BUNDLE/Contents
mkdir $BUNDLE/Contents/MacOS
mkdir $BUNDLE/Contents/Resources
mkdir $BUNDLE/Contents/lib

cp $BUILD/spring $BUNDLE/Contents/MacOS/spring #>>$DIR/log.txt 2>&1
cp $SPRING/installer/Mac/spring.icns $BUNDLE/Contents/Resources/spring.icns #>>$DIR/log.txt 2>&1
cp -R $BUILD/temp/usr/local/share $BUNDLE/Contents/share #>>$DIR/log.txt 2>&1

cat $SPRING/installer/Mac/Info.plist | sed s/###VERSION###/${VERSION}/ > $BUNDLE/Contents/Info.plist

cp $BUILD/tools/pr-downloader/src/pr-downloader $BUNDLE/Contents/MacOS #>>$DIR/log.txt 2>&1

dylibbundler -cd -b -x $BUILD/temp/usr/local/lib/libunitsync.dylib -d $BUNDLE/Contents/MacOS -p @loader_path/../MacOS #>>$DIR/log.txt 2>&1

dylibbundler -of -cd -b -x $BUNDLE/Contents/MacOS/spring -d $BUNDLE/Contents/lib -p @executable_path/../lib #>>$DIR/log.txt 2>&1

install_name_tool -change $MACPORTS/lib/libX11.6.dylib @executable_path/../lib/libX11.6.dylib $BUNDLE/Contents/lib/libXcursor.1.dylib #>>$DIR/log.txt 2>&1

dylibbundler -of -cd -b -x $BUNDLE/Contents/MacOS/pr-downloader -d $BUNDLE/Contents/lib -p @executable_path/../lib #>>$DIR/log.txt 2>&1

dylibbundler -cd -b -x $BUNDLE/Contents/share/games/spring/AI/Interfaces/C/0.1/libAIInterface.dylib -d $BUNDLE/Contents/share/games/spring/AI/Interfaces/C/0.1 -p @loader_path/../0.1 #>>$DIR/log.txt 2>&1

dylibbundler -cd -b -x $BUNDLE/Contents/share/games/spring/AI/Interfaces/Java/0.1/libAIInterface.dylib -d $BUNDLE/Contents/share/games/spring/AI/Interfaces/Java/0.1 -p @loader_path/../0.1 #>>$DIR/log.txt 2>&1

dylibbundler -cd -b -x $BUNDLE/Contents/share/games/spring/AI/Skirmish/AAI/0.9/libSkirmishAI.dylib -d $BUNDLE/Contents/share/games/spring/AI/Skirmish/AAI/0.9 -p @loader_path/../0.9 #>>$DIR/log.txt 2>&1

dylibbundler -cd -b -x $BUNDLE/Contents/share/games/spring/AI/Skirmish/CppTestAI/0.1/libSkirmishAI.dylib -d $BUNDLE/Contents/share/games/spring/AI/Skirmish/CppTestAI/0.1 -p @loader_path/../0.1 #>>$DIR/log.txt 2>&1

dylibbundler -cd -b -x $BUNDLE/Contents/share/games/spring/AI/Skirmish/E323AI/3.25.0/libSkirmishAI.dylib -d $BUILD/Spring.app/Contents/share/games/spring/AI/Skirmish/E323AI/3.25.0 -p @loader_path/../3.25.0 #>>$DIR/log.txt 2>&1

dylibbundler -cd -b -x $BUILD/Spring.app/Contents/share/games/spring/AI/Skirmish/KAIK/0.13/libSkirmishAI.dylib -d $BUILD/Spring.app/Contents/share/games/spring/AI/Skirmish/KAIK/0.13 -p @loader_path/../0.13 #>>$DIR/log.txt 2>&1

dylibbundler -cd -b -x $BUNDLE/Contents/share/games/spring/AI/Skirmish/NullAI/0.1/libSkirmishAI.dylib -d $BUNDLE/Contents/share/games/spring/AI/Skirmish/NullAI/0.1 -p @loader_path/../0.1 #>>$DIR/log.txt 2>&1

dylibbundler -cd -b -x $BUNDLE/Contents/share/games/spring/AI/Skirmish/RAI/0.601/libSkirmishAI.dylib -d $BUNDLE/Contents/share/games/spring/AI/Skirmish/RAI/0.601 -p @loader_path/../0.601 #>>$DIR/log.txt 2>&1

dylibbundler -cd -b -x $BUNDLE/Contents/share/games/spring/AI/Skirmish/Shard/dev/libSkirmishAI.dylib -d $BUILD/Spring.app/Contents/share/games/spring/AI/Skirmish/Shard/dev -p @loader_path/../dev #>>$DIR/log.txt 2>&1

if [ ! -e $BUNDLE/Contents/MacOS/spring ];then
echo "Error: App did not build correctly. Check log for details"
ERRORBUILD=1
fi

if [ "$ERRORBUILD" = "1" ]; then
	echo "Build Failed."
fi

echo "Done!"
exit 0