-
Notifications
You must be signed in to change notification settings - Fork 382
How To Compile
This page outlines how to compile the very latest version of CorsixTH. The following steps should be done
In order to compile CorsixTH, the following applications need to be installed:
| Application | Status | Windows Example | Linux Example | macOS Example | Notes |
|---|---|---|---|---|---|
| CMake | Required | CMake Win32 installer | CMake Unix/Linux source | CMake macOS | Version 3.10 or later is required. |
| C++ compiler | Required | Visual Studio or MinGW | g++ | Xcode | The compiler must support C++ 17. |
| Git client | Recommended | GitHub Desktop | git | GitHub Desktop | Necessary for vcpkg |
| vcpkg | Recommended | vcpkg | vcpkg | vcpkg | Necessary for the CMake presets. |
Before compiling, the following development libraries need to be installed. Each Library will have its own instructions on how to install or use them. Some libraries are optional but come with caveats if not used.
If you are using vcpkg all of these libraries will be installed automatically when you run cmake later in the guide
| Library | Minimum version | Windows | Linux | macOS | Notes |
|---|---|---|---|---|---|
| SDL | 2.0 | Required | Required | Required | |
| Lua | 5.2-5.3, 5.4.3+ | Required | Required | Required | Lua 5.1 and LuaJIT are no longer recommended. Lua 5.4.0 and 5.4.1 are not supported. |
| SDL_mixer | 2.0 | Required | Required | Required | |
| FluidSynth | 2.0.0 | Optional | Optional | OptionalA | If not present then background MIDIs may not be played or may not be played correctly. |
| FluidR3 | N/A | Optional | Optional | Optional | The recommended soundFont for MIDI playback if fluidsynth is used (and custom SoundFont file not configured) |
| wxWidgets | 2.8 | Optional | Optional | Optional | Required to build the AnimView tool, but not the game itself. |
| FreeType2 | 2.5.3 | Required | Required | Required | Provides font support beyond the original game's bitmap Latin fonts. Hence required for translations like Russian and Chinese. |
| Timidity | Any | N/A | Optional | N/A | Note: Timdity is now DEPRECATED for CorsixTH, use FluidSynth instead. If not present on Linux, then background MIDIs may not be played. |
| FFmpeg | 4-7+ | Optional | Optional | Optional | FFmpeg is required for movie support. LivAV is no longer supported. |
| libcurl | ? | Optional | Optional | Optional | Curl is used for upgrade checks. |
| Doxygen | 1.8 | Optional | Optional | Optional | Only required for building documentationB |
| LuaFileSystem | 1.5 | Required | Required | Required | Required at runtime. Can be obtained through vcpkg or luarocks |
| LPeg | 0.9 | Required | Required | Required | Required at runtime. Can be obtained through vcpkg or luarocks |
- Note A - On macOS, SDL_mixer may be compiled with native MIDI instead of fluidsynth, and internal "dr_" support for other media types instead of other external libraries. Native midi is not available in sdl2_mixer built by vcpkg, and fluidsynth should be used instead.
- Note B - Even if you do not intend to build the documentation you may have CMake warnings about the missing doxygen executable, which can be safely ignored.
The latest source code can be cloned from the main Git repository. With a command line Git client, the required command is:
git clone https://github.com/CorsixTH/CorsixTH
If using a graphical Git client (for example, GitHub Desktop), then instruct it to fork https://github.com/CorsixTH/CorsixTH.
If you do not have a Git client, then the source code of the most recent release is available as a tarball from the releases page, or a zip of the git repository is also available.
| Option | Default | Description |
|---|---|---|
| BUILD_CORSIXTH | ON | Build the game itself |
| WITH_MOVIES | ON | Activate in game movies |
| BUILD_ANIMVIEW | OFF | Build the animation viewer as part of the build process. |
| USE_SOURCE_DATADIRS | OFF | Build the game to use Lua and other resources from the source directory instead of the install directory. This is highly recommended for developers, but should be off for packagers. |
| WITH_LUAJIT | OFF | Use LuaJIT instead of Lua |
| WITH_LUAROCKS | OFF | Include luarocks - Lpeg and luafilesystem - only on macOS |
Compiling on the common operating systems is explained in more detail below:
The following commands may be suitable for installing the prerequisites; consult your distribution's package manager for full details, or alternatively, build the prerequisites from source.
For Ubuntu/Debian-based distributions:
sudo apt-get install build-essential cmake git libsdl2-dev libsdl2-mixer-dev fluidsynth libfreetype6-dev lua-filesystem lua-lpeg doxygen liblua5.3-0 liblua5.3-0-dbg liblua5.3-dev
In addition, if you would like in game movies you can install FFmpeg:
sudo apt-get install ffmpeg libavcodec-dev libavformat-dev libavresample-dev libavdevice-dev libavutil-dev libavfilter-dev libswscale-dev libpostproc-dev libswresample-dev
For Arch Linux:
sudo pacman -Sy base-devel cmake lua53 lua53-filesystem lua53-lpeg sdl2 sdl2_mixer fluidsynth ffmpeg
This includes the FFmpeg movie library.
For Fedora:
sudo dnf install cmake freetype-devel git gcc gcc-c++ lua lua-filesystem lua-lpeg lua-socket lua-sec make SDL2 SDL2-devel SDL2_mixer SDL2_mixer-devel fluidsynth
In addition, if you would like in game movies, you will need FFMPEG from RPMFusion:
sudo dnf install ffmpeg ffmpeg-devel
Assuming that you have the prerequisites, and <checkout-path> is the top-level directory of CorsixTH source code (which should contain a file called CMakeLists.txt, and subdirectories called AnimView, CorsixTH, LFS, etc.), then the following commands should compile and run corsix-th:
cd <checkout-path>
mkdir build
cd build
cmake -DUSE_SOURCE_DATADIRS=ON .. # <-- Note the dots at the end!Note the -D_USE_SOURCE_DATADIRS=ON, this flag makes CorsixTH use the Lua and other binary resources from the source directory; which is useful for development. If you are building for distribution instead, or plan to install, then leave out that flag. CorsixTH will instead expect these resources to be in ${CMAKE_INSTALL_PREFIX}/share/corsix-th which is handled automatically by make install.
If you have multiple versions of lua installed, sometimes cmake gets confused about which one to use. You can fix this by being explicit:
cmake -DUSE_SOURCE_DATADIRS=ON -DLUA_INCLUDE_DIR=/usr/include/lua5.3 -DLUA_LIBRARY=/usr/lib/i386-linux-gnu/liblua5.3.so ..
# Note that if you had already run CMake you should rm CMakeCache.txt firstFor Debian9:
cmake -DUSE_SOURCE_DATADIRS=ON -DLUA_INCLUDE_DIR=/usr/include/lua5.3 -DLUA_LIBRARY=/usr/lib/x86_64-linux-gnu/liblua5.3.so ..If you do not have FFMpeg installed, you can disable building this feature by adding options to CMake like
cmake -D -D WITH_MOVIES=OFF .. # <-- Note the dot at the end!Specific cmake for Raspberry Pi (tested on 4B)
cmake -DUSE_SOURCE_DATADIRS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Ofast -DNDEBUG -mcpu=cortex-a72" ..If running CMake did not give any error, and USE_SOURCE_DATADIRS was set then the program can be built with a simple:
makeand run:
cd CorsixTH
./corsix-thIf you opted not to use -DUSE_SOURCE_DATADIRS=ON then build with:
make
make installAssuming ${CMAKE_INSTALL_PREFIX}/bin is in your $PATH run with:
corsix-thThe below provides a simple-to-use instruction set for compiling CorsixTH in Windows with Visual Studio 2022. You do not need to download any of prerequesites unless mentioned below.
Before starting you may wish to familiarise yourself with the Example Reference of directory structure for Windows instructions at the bottom of this section. Command line instructions can also be found there too.
Setup
-
Download Visual Studio's installer (C++ compiler in prerequisite applications)
- When installing:
- Choose the workload from
Desktop & Mobile > Desktop development with C++. This by default includes ability to operate localised vcpkg and cmake. - On the Optional section on Desktop development with C++ also select
C++ MFC for latest vXXX build tools (x86 & x64)[1] - On Individual Components search for "git" and choose
Code tools > Git for Windows
- Choose the workload from
- When installing:
-
Once installed, close the program for now.
-
Download the FluidR3 soundfont file (FluidR3 in prerequisite libraries) and keep it for later.
-
Create yourself a folder you want to work on this project in (e.g. C:\dev).
- You should make this in File Explorer to get the correct permissions easily.
- With
vcpkg, using spacesor+in your directory structure is highly discouraged. Use-or_instead.
-
Using git make a copy of the CorsixTH source files.
- In Command Prompt or Powershell run:
cd <path-to-your-project>. - Run
git clone https://github.com/CorsixTH/CorsixTH.git. This creates a folder called CorsixTH (the repository)[2].
Caution
When we open this project in Visual Studio it will automatically try to configure potentially under the incorrect preset. If you want to avoid that:
- Open Visual Studio and use the "Continue without code" option so we can modify settings.
- Go to
Tools > Options > CMake > When cache is out of date: "Never run configure step automatically". - Note that doing this means you must use
Project > Configure cacheto run the configure process manaully.
CMake Configure
-
Open the project in Visual Studio:
- Go to
File > Open > CMake. Navigate to your CorsixTH repository folder and selectCMakeLists.txt.- The CMake has finished loading once "CMake Overview Pages" tab loads.
- Go to
-
On the toolbar you will see a "Local machine" dropdown and another dropdown to the right of it potentially saying "linux-dev". On this second dropdown change this to "win-dev" (for development builds, recommended) or "win-x64-rel" (for release builds).
- If the preset is on "linux-dev" you may wish to stop the automatic Configure action. Click the chat bubble in the bottom left. Click the red stop button, then the following X to cancel configure.
-
Once you select the preset desired it will automatically begin configuring (unless you disabled automatic configure, see above).
- If this is your first run of configure for this preset it will take some time while it downloads and compiles all dependencies.
-
When CMake is completed a folder called
build\<preset>will be made. This contains the build scripts. If you now openCorsixTH_Top_Level.slnyou can make your build.
Compiling
-
On the toolbar you will see two dropdowns, the second potentially saying
x64. On the first dropdown choose your build type (Release, Debug, or RelWithDebInfo).[3] -
On the Solution Explorer on the right hand side you will see an options called
ALL_BUILD(for all modules) andCorsixTH(for just the program). Right click the option desired and select "Build". ACorsixTH\<build_type>folder will now be created inCorsixTH\<preset>containing the program.
-
CorsixTH.exemay attempt to automatically launch from Visual Studio. You can closeCorsixTH.exesafely. - If you chose ALL_BUILD on
win-devanAnimview\<build_type>also exists at the same hierarchy level. AnimView lets you view animations from the original Theme Hospital files.
-
-
Now prepare to complete the built artifact:
- You should now place the soundfont downloaded earlier as below:
- For
win-devin the CorsixTH sourceCorsixTH\CorsixTH - For
win-x64-relandwin-x86-relin theCorsixTH\build\<preset>\CorsixTH\<build_type>folder.
- For
- In
win-devpreset, this program will launch as is without additional actions because it calls missing files from the CorsixTH source folder.[4] - In other presets, from the CorsixTH source, Lua files and other folders should be copied over. This includes:
- CorsixTH.lua
- Bitmap
- Campaigns
- Graphics
- Levels
- Lua
- You should now place the soundfont downloaded earlier as below:
Footnotes
[1] The version number of this component can change over time. So use the newer version if presented. (at time of writing,
this was v143).
[2] If you are modifying C++ files for a test build, you would do those here.
[3] Due to an known issue in SDL2_mixer debug currently does not work. Use Release or RelWithDebInfo instead.
[4] win-dev builds can't be moved to other machines unless you change "USE_SOURCE_DATADIRS" in CMakePresets.json to OFF. You will then need to also add all other files mentioned in the artifact directory.
Example Reference of directory structure for Windows instructions ([ ] denotes comments)
C:\dev
├─ CorsixTH [repository]
│ ├─ CMakePresents.json
│ ├─ CMakeLists.txt
│ ├─ build [cmake configure folder]
│ │ ├─ dev [named after cmake configure preset]
│ │ │ ├─ CorsixTH
│ │ │ │ ├─ Release [Built program named after build type]
│ │ │ ├─ AnimView [if built]
│ │ │ │ ├─ Release
│ ├─ CorsixTH [source for Lua etc.]
│ │ ├─ CorsixTH.lua
│ │ ├─ Bitmap
│ │ ├─ Campaigns
│ │ ├─ Graphics
│ │ ├─ Levels
│ │ ├─ Lua
Basic instructions to compile fully via command line (without using Visual Studio IDE)
You can still compile using the command line, if you prefer and know how (and can manage prerequisites as necessary).
Note: You'll still need Visual Studio or the Build Tools for Visual Studio installed for this to work.
Basic example command line instructions (adjust according to your needs)
cmake --preset win-dev
cd build/dev
cmake --build . --config RelWithDebInfoSome packaging notes in the Visual Studio instructions (Compling, step 3) may still be relevant depending on your build.
It is recommended to use the CMake presets with CMake cli in Terminal. This uses vcpkg to build the libraries required by the build settings (eg -DWITH_MOVIES=off). The instructions below the following section are for a manual install of these libraries, or building CorsixTH in GUI programs. It is not currently possible to use CMake presets with Xcode.
The two macOS presets are macos-arm64-rel for Apple Silicon, and macos-x64-rel for Intel. Swap arm64 for x86 in these instructions if the build is for the Intel platform.
Download vcpkg to a path we will use next.
git clone https://github.com/microsoft/vcpkg.git $HOME/vcpkgConfigure CMake in the CorsixTH folder. This will build dependencies if they do not exist, so this step can take several minutes.
VCPKG_ROOT=$HOME/vcpkg cmake --preset macos-arm64-rel -DCMAKE_INSTALL_PREFIX=/ApplicationsThen build these makefiles through CMake (or navigate to the folder and use make).
cmake --build --preset macos-arm64-relA successful build can be installed to the Applications folder.
cmake --build --preset macos-arm64-rel -- installIf you plan to share the resulting CorsixTH.app you should not use Homebrew to generate your dependencies, or use other prebuilt binaries; they should be built with attention paid to the compile flags and targets (eg the same as for CorsixTH).
For personal use, the libraries can be installed more simply using a package manager such as Homebrew. Note that this will build SDL2_mixer with fluidsynth, therefore a soundfont is needed to listen to MIDI files.
A list of the required libraries and the minimum versions required can be found at the top of this page.
Download the source code of the dependencies you are using to a folder. 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.
- SDL2
- MikMod - must be installed before SDL2 mixer
- ogg - must be installed before Vorbis
- vorbis - must be installed before SDL2 mixer
- flac - must be installed before SDL2 mixer
- mpg123 - must be installed before SDL2 mixer
- SDL2 mixer
- Lua
- LuaRocks
- wxWidgets - only for Animview
- FreeType2
- yasm - Intel only, must be installed before ffmpeg
- nasm - Apple Silicon only, must be installed before ffmpeg
- ffmpeg
Alternatively, a safe use of homebrew is to unpack the source.
mkdir -p build_files
cd build_files
brew unpack lua luarocks sdl2 libxmp libgme wavpack fluidsynth sdl2_mixer freetype ffmpeg curlIf you wish to compile all dependencies with certain settings, some can be set in advance, eg CFLAGS=-O2 -pipe -mmacos-version-min=11.3. If you wish to not install globally, follow the configure line with a prefix setting, eg --prefix=$PWD/../. This will then need to be fed into CMake later with the build flag "-DCMAKE_PREFIX_PATH=$PWD/build_files". If you have not installed globally before, you may need to take ownership of the /usr/local/ folder with sudo mkdir -p /usr/local/; sudo chown -R "$(id -u):$(id -g)" /usr/local/.
For each dependency we will cd into its directory, configure the build, make the build, and install it globally.
cd directory
./configure
make -j
make install
cd ..In order for certain dependencies to configure, compile and install correctly, the following amendments to the above steps need to be made:
ogg & vorbis
Replace configure with cmake .
Lua
Skip configure, and use the make command: MACOSX_DEPLOYMENT_TARGET=10.13 make -j macosx test
wxWidgets (for AnimView) 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 commands instead of configure and make:
./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
make -j CFLAGS="$CFLAGS -DHAVE_UNISTD_H=0" LDFLAGS="-Wl,-ld_classic,-headerpad_max_install_names"
Now to install the luarocks libraries. 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"Install the two required libraries, alternatively, use scripts/macos_luarocks.
luarocks install lpeg
luarocks install luafilesystemNow you need to open CMake which you installed earlier. Once you have done this follow the steps below to generate an Xcode project which we will use to compile CorsixTH.
-
From the main window of CMake click Browse Source... and navigate to the directory that you cloned the Git repository to.
-
Now click Browse Build... and select a directory where you want the project to be generated, eg build.
-
Click Configure and allow CMake to create any directories if needed. When prompted select Xcode as the generator for the project and Use default native compilers.
-
The main page will now show a large number of red lines, this is normal. Check the log at the bottom and you can see a number of red lines stating:
Building CorsixTH SDL found Lua found SDL_mixer found FFmpeg found FreeType2 found -
(Optional) Now scroll to the CMAKE_INSTALL_PREFIX option. Set this to the directory where you want the compiled applications to be installed (e.g. /Applications). To avoid Xcode asking for a signing identity, either disable it in Xcode or add the field CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED with value "NO".
-
Now click Configure again to apply the changes.
-
At this stage you may be presented with an error popup stating Error in the configuration process, project files may be invalid. This is perfectly normal and nothing to worry about. Simply click 'OK' to proceed.
-
Click Configure again to apply the changes.
-
Now you should find you have no red lines in the main window. Click Generate to create the Xcode project.
This stage is relatively straight forward. Navigate to the folder you selected in Step 2 above and open the CorsixTX_Top_Level.xcodeproj file. Now follow the steps below:
-
In Xcode you will likely find you have an alert showing in the top bar. Click this, it will expand the drop down menu to the left. Click on Validate Project Settings. In the pop up window simply click Perform Changes. (If you are prompted to enable project snapshots, select Enable.) If you get a popup to install additional components allow these to install by selecting Install. Disable project signing if necessary.
-
In the menu bar select Product and then Build. The applications will now compile. During this process you will likely see many yellow alerts appear, these are nothing to worry about and the applications will still compile.
-
Assuming everything went well you can now find the compiled applications in the directory you set in CMake step 5. If you did not set one it will be inside the Release or Debug folder.
-
Finally run the install target to create a full app, or run the app with the run-corsix-th.sh file in the same folder.
- Open Terminal in the folder created by cloning the repository and create a makefile project. Run the following command, adjusting the CMake.app folder if necessary. CMake can be installed with
brew install cmake.
/Applications/CMake.app/Contents/bin/cmake . -G"Unix Makefiles" -Bbuild -DCMAKE_INSTALL_PREFIX=/Applications -DWITH_LUAROCKS=onNote: If there are multiple versions of lua then specify which should be used by adding the following (adjust for lua install path) -DLUA_LIBRARY=/usr/local/lib/liblua.5.4.dylib.
-
Navigate to the Corsixth folder in the given build folder above, eg
cd build. -
Check the options available to you with
make help. If you used the Data Sources Dirs option in CMake then install will not be on this list. -
Build CorsixTH with
make CorsixTH -
Finally run the install target, with
make install, to create a full app, or run the app with the run-corsix-th.sh file in the same folder.
If you're having difficulty please come to the Matrix room or Discord server. If you suspect there is an issue please create an issue on GitHub.