Skip to content

Draft: refactor to cmake build system

This MR integrates CMake as the primary build tool, uses llwin for ci pipelines and adds some small code fixes required for compiling the project with clang.

With this MR it is possible to cross-compile the project on unix hosts without adding runtime dependencies (such as MingW).

implementation details

The CMakeLists.txt configures the xlln project and uses CPM to fetch and configure the dependencies (currently Opus and DirectX SDK).

CMake is configured to use these toolchains by default:

change generator/compiler

The compiler can be changed by using CC/CXX environment variables and to use a different generator add the -G <generator> option

Windows Unix
Generator Visual Studio Makefile
Compiler MSVC Clang

required code changes for ABI adherence

Since clang enforces ABI adherence more strictly than msvc, some changes to the code base were required to allow clang to succesfully compile. Those changes are found in the superewald/xlivelessness@00b3b174 commit.

compilation warnings with clang

Compiling with clang will currently emit a lot of warnings since the clang compiler enforces code standard compliance more strictly than msvc does. These warnings can be toggled off if desired but I decided to leave them on.

ci scripts

The CI config were adopted to compile on linux shared runners using the superewald/llwin:16-debug container. This drastically decreases the pipeline runtime while preserving compliance with windows targets. See the pipeline of this MR.

caching

CCache combined with the gitlab ci job caches could be used to further decrease the pipeline runtime.

build instructions

build on windows

using Visual Studio

VS project structure

It is possible with CMake to force a specific layout of the project tree view in Visual Studio. I skipped this currently, if wanted leave a comment with the desired structure.

Required tools:

  • Visual Studio 2017+ with these packages:
    • c++
    • Windows 10 SDK
    • cmake

Build steps

  1. clone this branch
  2. open the Visual Studio Developer Powershell and execute:
    cmake -A Win32 -B build -DCMAKE_BUILD_TYPE=<Release|Debug>
  3. open the build/XLLN.sln in VisualStudio
  4. compile either by using Visual Studio or manually with
    cmake --build build to compile

using LLVM

Required tools:

Build steps

  1. clone this branch
  2. open cmd/powershell and execute:
    cmake -A Win32 -B build -DCMAKE_BUILD_TYPE=<Release|Debug>
  3. compile using cmake with
    cmake --build build

build on linux

Required tools

  • CMake 3.12+
  • Make
  • LLVM 18+
  • Windows Sysroot

Windows Sysroot

I recommend using llwin (disclaimer: I'm the author) to setup the sysroot along with some helper scripts which makes cross-compiling windows targets on unix hosts easy. The sysroot can be setup manually but that requires good knowledge about CMake and LLVM internals.

A quick setup with a sufficient sysroot for this project can be acquired like this:

git clone https://gitlab.com/superewald/llwin $HOME/.local/llwin
$HOME/.local/llwin/bin/llwin init --user --wine
llwin install 16 --debug --archs x86

If you don't plan to use the compiled project on the host machine you can also use the llwin container images with docker/podman to build.

Build steps

  1. clone this branch
  2. open shell and execute
    wmake -A Win32 -B build -DCMAKE_BUILD_TYPE=<Release|Debug>
  3. edit sources using your preferred IDE
  4. compile with cmake --build build

use while MR is not merged

If you - like me - want to develop and build this project on linux entirely or need cmake integration for other reasons you can already use the feat/cmake-clang branch of my fork to do that even before this MR is merged.

  1. add the https://gitlab.com/superewald/xlivelessness repository as git remote: git remote add superewald https://gitlab.com/superewald/xlivelessness && git fetch --all
  2. create a new branch based on feat/cmake-clang: git checkout -b feature-xyz superewald/feat/cmake-clang
  3. develop, commit and push as usual but using cmake
  4. before opening a PR, rebase the branch onto the xlivelessness/master branch (this will remove the cmake-clang changes from the branch):
    git fetch origin
    git rebase --onto origin/master superewald/feat/cmake-clang feature-xyz
  5. force push the branch git push --force

Tip

If you rebased your branch to master but need to add more commits that require the cmake build tool, you can simply temporary rebase back onto the feat/cmake-clang branch and continue with 4.

git checkout feature-xyz
git rebase --onto superewald/feat/cmake-clang origin/master

todo

  • verify compilation on windows host
  • discuss DirectX SDK dependency strategy fixed with !10 (4eb0b728)
Edited by Glitchy Scripts

Merge request reports

Loading