Author Topic: HOWTO: Compiling and cross-compiling OXCE  (Read 25150 times)

Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9113
    • View Profile
HOWTO: Compiling and cross-compiling OXCE
« on: March 24, 2019, 07:56:15 pm »
Applies to all builds and all platforms:
- don't use yaml-cpp 0.7.x, it's broken
- if you can, use yaml-cpp 0.6.3




1. Building on Windows using Visual Studio 2022 (Win32 build only)

1. Download, install and update Visual Studio 2022 Community Edition: https://visualstudio.microsoft.com/downloads/
2. Clone OXCE repo: https://github.com/MeridianOXC/OpenXcom.git
3. Download and extract the pre-compiled dependencies (into repo's root): openxcom-deps-win-vc2017-newest.zip
4. Open solution "src/OpenXcom.2010.sln"
5. Click "Build" from menu or toolbar
« Last Edit: January 09, 2024, 10:50:32 am by Meridian »

Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9113
    • View Profile
Re: [4] Compiling and cross-compiling OXCE
« Reply #1 on: March 28, 2019, 03:50:14 pm »
2. Building on Linux (tested on Kubuntu 18.04)

2.1 First, you need git, cmake, build essentials (compiler, etc.) and SDL libraries.

Code: [Select]
apt install git cmake build-essential libsdl1.2-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-gfx1.2-dev zlib1g-dev

And also a recent version of yaml-cpp library:

Code: [Select]
git clone https://github.com/jbeder/yaml-cpp
cd yaml-cpp
mkdir yaml-build
cd yaml-build
cmake .. -DCMAKE_BUILD_TYPE=Release -DYAML_CPP_BUILD_CONTRIB=OFF -DYAML_CPP_BUILD_TESTS=OFF -DYAML_CPP_BUILD_TOOLS=OFF
sudo make install

This will install it into /usr/local, so you'll need privileges for that.

2.2 Now OXCE itself

Code: [Select]
git clone https://github.com/MeridianOXC/OpenXcom.git
cd OpenXcom
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DDEV_BUILD=OFF -DBUILD_PACKAGE=OFF
make -j4

You will end up with build/bin directory with the executable and the resources.
« Last Edit: September 01, 2019, 03:04:36 pm by Meridian »

Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9113
    • View Profile
Re: [4] Compiling and cross-compiling OXCE
« Reply #2 on: March 28, 2019, 03:50:35 pm »
3a. Building OXCE from source on Mac (tested on macOS 10.15 Catalina)

Install brew, see: https://brew.sh/

3.1 Install tools and dependencies via brew:

For recent versions (macOS 10.13+)

Code: [Select]
brew install git cmake zip yaml-cpp --with-static-lib sdl sdl_gfx sdl_image sdl_mixer --with-flac --with-libmikmod --with-libvorbis --with-static-lib

For older versions (e.g. macOS 10.9), you may need a simpler command:

Code: [Select]
brew install git cmake zip sdl sdl_gfx sdl_image sdl_mixer yaml-cpp

3.2 Now OXCE itself

On macOS 10.13 or earlier:

Code: [Select]
git clone https://github.com/MeridianOXC/OpenXcom.git
cd OpenXcom
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE="Release"
make -j4

Starting with macOS 10.14 (Mojave), there are issues with OpenGL, which is not supported by Apple anymore.
The compilation works, but the game doesn't.
Therefore, you will need an earlier version of the SDK and instruct cmake to lower the deployment target.
You can download SDK for macOS 10.9 here: MacOSX10.9.sdk.zip
I recommend placing it into /Developer/SDKs/MacOSX10.9.sdk
EDIT: macOS 10.15 (Catalina) will probably not allow you to place the SDK there... just put it anywhere it allows you and change the cmake command accordingly

Updated cmake command:

Code: [Select]
cmake .. -DCMAKE_BUILD_TYPE="Release" -DCMAKE_OSX_SYSROOT=/Developer/SDKs/MacOSX10.9.sdk -DCMAKE_OSX_DEPLOYMENT_TARGET=10.9

You will end up with build/openxcom.app bundle.
A .dmg is made out of it using:

Code: [Select]
make package

Spoiler:
Community Update (not tested by me)

3b. Resolving zlib Path Issues and Building OpenXcom (tested externally on macOS 14.6.1 Sonoma)

Quote
I encountered compilation errors on macOS Sonoma 14.6.1 due to missing zlib library paths. After following outdated instructions, I found a solution that successfully built the project. Here are the steps I took:

Prerequisites:
xcode-select --install
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew update
brew upgrade
brew install git cmake zip yaml-cpp sdl sdl_gfx sdl_image sdl_mixer zlib python
export LDFLAGS="-L/opt/homebrew/opt/zlib/lib"
export CPPFLAGS="-I/opt/homebrew/opt/zlib/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/zlib/lib/pkgconfig"

Cloning and Building OpenXcom:

Choose a version:
MeridianOXC: git clone https://github.com/MeridianOXC/OpenXcom.git
OpenXcom: git clone https://github.com/OpenXcom/OpenXcom.git

Build:

cd openxcom
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE="Release"
make -j4

Find the executable: The compiled application will be located in openxcom/build/openxcom.app


I used Google-Gemini For English Translation

Kind Regards From the Baltic Sea in Germany
« Last Edit: September 22, 2024, 12:39:12 pm by Meridian »

Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9113
    • View Profile
Re: [4] Compiling and cross-compiling OXCE
« Reply #3 on: March 28, 2019, 03:51:13 pm »
4. Cross-compiling OXCE for Windows 7 32/64bit on Linux (tested on Kubuntu 18.04)

Windows Vista support was dropped on 3rd April 2022, mxe commit: https://github.com/mxe/mxe/commit/8bb4b52ee0e7cf97f10e6bd760c4397b561bf255

Windows XP support was dropped on 26th May 2021, mxe commit: https://github.com/mxe/mxe/commit/87a9b83dcf7d1650149e1d24f490d70405ddba1f


4.1 First you need git, zip and mxe.

Code: [Select]
apt install git zip

Clone the mxe environment somewhere, for example in /opt/mxe:

Code: [Select]
cd /opt
sudo git clone https://github.com/mxe/mxe.git
sudo chown -R `whoami`: mxe

Check/install the mxe requirements: https://mxe.cc/#requirements

Set up mxe:

Code: [Select]
cd /opt/mxe
make MXE_TARGETS=x86_64-w64-mingw32.static JOBS=8 gcc cmake sdl sdl_gfx sdl_mixer sdl_image yaml-cpp

4.2 Clone the OpenXcom repo (for example in your home dir), make a build dir and build.

Code: [Select]
git clone https://github.com/MeridianOXC/OpenXcom.git
cd OpenXcom
mkdir build
cd build
export PATH=/opt/mxe/usr/bin:$PATH
/opt/mxe/usr/bin/x86_64-w64-mingw32.static-cmake -DCMAKE_BUILD_TYPE=Release -DDEV_BUILD=OFF -DBUILD_PACKAGE=OFF ..
make -j4

You will end up with build/bin directory with the executable ("libopenxcom.dll.a" can be safely ignored) and the resources.
Optionally you can make the exe smaller by running:

Code: [Select]
cd bin
/opt/mxe/usr/bin/x86_64-w64-mingw32.static-strip -d openxcom.exe

PS: to make a 32bit build use "i686-w64-mingw32" instead of "x86_64-w64-mingw32"
« Last Edit: August 31, 2024, 08:59:08 pm by Meridian »

Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9113
    • View Profile
Re: [4] Compiling and cross-compiling OXCE
« Reply #4 on: March 28, 2019, 03:51:27 pm »
5. Compilation for Android

See readme at: https://github.com/MeridianOXC/openxcom-android

Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9113
    • View Profile
Re: [4] Compiling and cross-compiling OXCE
« Reply #5 on: March 28, 2019, 03:51:41 pm »
6. Compilation for iOS

See readme at: https://github.com/MeridianOXC/openxcom-ios