Skip to content

Commit e7a4a50

Browse files
authored
Add CMake builds for server projects (#657)
* Implemented basic CMake build config (builds on Windows/MSVC). * Removed use of `_CRT_SECURE_NO_WARNINGS` macro (fixing related use cases). * Fixed 64-bit related warnings (as the default build for MSVC is 64-bit). * Updated for Clang (Linux) builds (fixing new warnings, any unsupported code). * Fixed numerous minor warnings (mostly unreferenced or uninitialized vars/parameters). * Added `strcpy_safe()` to replace `strcpy_s()` usage which mostly mimics `strlcpy` -- it's just a little bit nicer, supporting `std::string_view`. * Fixed djb2 support. * Replaced module usage (as used by db-modules) with a standard header/source implementation. Support is technically possible, but it's extremely challenging and will likely be even worse with gcc. It didn't even behave that great in VS, so it's probably for the best it just goes. It should hopefully be more standardized by C++26, so we may reintroduce it eventually. * Renamed db-modules -> db-models (they're still models but no longer modules). * Updated for gcc (Linux) builds (new warning fixes, any unsupported code). * Replaced standard deprecated memcalls (`memcpy(this, ...)`, `memset(this, ...)` - replaced instances these in the client as well for future-proofing. * Restored regular include guards. gcc choked on at least one case with pure `#pragma once`; presumably the header being included in different ways. Better to just be safe than sorry and use both. * Replaced unions in `db-modules` (`field1`, `field2`, `field3` & `field[3]`) with just arrays. It's not technically allowed by the standard for non-trivial types (i.e. `std::optional<>` in this case), though gcc is the only one that's strict about this. * Added consistent default initialization to the various types (mostly math-related) in My_3DStruct.h. Rather than just override the constructor to do nothing (causing initialization like `= {}` to do nothing, we default initialize it instead. That way it still does nothing by default, but if we explicitly value initialize it like `= {}`, it will initialize each field accordingly (typically zeroed). This is needed to replace various standard deprecated memcalls on class/struct instances - instead of these being initialized with memset(), we can just use `{}` to initialize them. * Restored VS debugger working dir for consistency and simplicity when building it for MSVC. * Tidied up generated VS solution to continue grouping projects (the grouping naturally applies to all IDEs that support it, like CLion). * Added GitHub workflow for running CMake jobs (Windows - Win32, x64, Linux - gcc [current - 13], clang [current - 18] & clang 20 [bleeding edge]). * Implemented dependency management through CMake itself to avoid relying on or dealing with submodules (better for seamlessly keeping things up-to-date from a user perspective, though a little more tedious to keep the submodules and CMake config synced for maintainers). * Tweaked `ByteBuffer` to - firstly - build in gcc/clang and additionally just shift implementation (and template) code into a source file to improve compilation times. * Added `sync-submodules` project to our regular Visual Studio solutions to ensure submodules are updated correctly on rename/URL change (as was the case with db-modules etc.). * Fixed some accidentally incorrect log refs (referencing `AiServerInstance` instead of `AujardApp` in Aujard). * Removed `AIServerApp::TestCode()`. This is useless; it looked like it was causing the random number generator to not start on something consistent, but it's called before `srand()` and logic which does this already. Resolves #644
1 parent e69dbb7 commit e7a4a50

File tree

208 files changed

+3086
-2096
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

208 files changed

+3086
-2096
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
name: "Build server (CMake)"
7+
8+
on:
9+
push:
10+
branches:
11+
- master
12+
13+
paths:
14+
- '.github/workflows/build_cmake_server.yml'
15+
- 'CMakeLists.txt'
16+
- 'deps/asio-cmake/CMakeLists.txt'
17+
- 'deps/boost-cmake/CMakeLists.txt'
18+
- 'deps/db-library-cmake/CMakeLists.txt'
19+
- 'deps/db-models-cmake/CMakeLists.txt'
20+
- 'deps/djb2-cmake/CMakeLists.txt'
21+
- 'deps/FTXUI-cmake/CMakeLists.txt'
22+
- 'deps/nanodbc-cmake/CMakeLists.txt'
23+
- 'deps/spdlog-cmake/CMakeLists.txt'
24+
- 'Server/**/*'
25+
- 'shared/**/*'
26+
27+
pull_request:
28+
branches:
29+
- master
30+
31+
paths:
32+
- '.github/workflows/build_cmake_server.yml'
33+
- 'CMakeLists.txt'
34+
- 'deps/asio-cmake/CMakeLists.txt'
35+
- 'deps/boost-cmake/CMakeLists.txt'
36+
- 'deps/db-library-cmake/CMakeLists.txt'
37+
- 'deps/db-models-cmake/CMakeLists.txt'
38+
- 'deps/djb2-cmake/CMakeLists.txt'
39+
- 'deps/FTXUI-cmake/CMakeLists.txt'
40+
- 'deps/nanodbc-cmake/CMakeLists.txt'
41+
- 'deps/spdlog-cmake/CMakeLists.txt'
42+
- 'Server/**/*'
43+
- 'shared/**/*'
44+
45+
workflow_dispatch:
46+
47+
jobs:
48+
build_windows:
49+
runs-on: windows-latest
50+
51+
strategy:
52+
matrix:
53+
BUILD_CONFIGURATION: [Debug, Release]
54+
BUILD_PLATFORM: [Win32, x64]
55+
56+
name: "Server: ${{ matrix.BUILD_CONFIGURATION }} - ${{ matrix.BUILD_PLATFORM }} (Windows)"
57+
58+
steps:
59+
- uses: actions/checkout@v4
60+
with:
61+
submodules: 'false'
62+
63+
- uses: lukka/get-cmake@latest
64+
65+
- name: Configure CMake
66+
shell: bash
67+
run: |
68+
cmake -S . \
69+
-B build-windows-${{ matrix.BUILD_CONFIGURATION }}-${{ matrix.BUILD_PLATFORM }} \
70+
-G "Visual Studio 17 2022" \
71+
-A ${{ matrix.BUILD_PLATFORM }} \
72+
-DCMAKE_BUILD_TYPE=${{ matrix.BUILD_CONFIGURATION }}
73+
74+
- name: Build server
75+
shell: bash
76+
run: |
77+
cmake \
78+
--build build-windows-${{ matrix.BUILD_CONFIGURATION }}-${{ matrix.BUILD_PLATFORM }} \
79+
--config ${{ matrix.BUILD_CONFIGURATION }}
80+
81+
build_linux:
82+
runs-on: ubuntu-latest
83+
84+
strategy:
85+
matrix:
86+
BUILD_CONFIGURATION: [Debug, Release]
87+
COMPILER: [gcc, clang, clang-20]
88+
89+
env:
90+
clang-latest-version: 20
91+
92+
name: "Server: ${{ matrix.BUILD_CONFIGURATION }} - ${{ matrix.COMPILER }} (Linux)"
93+
94+
steps:
95+
- uses: actions/checkout@v4
96+
with:
97+
submodules: 'false'
98+
99+
- name: Install unixODBC
100+
run: sudo apt-get install unixodbc-dev -y
101+
102+
- uses: lukka/get-cmake@latest
103+
104+
- name: Setup compiler
105+
run: |
106+
if [ "${{ matrix.COMPILER }}" = "gcc" ]; then
107+
export CC=gcc
108+
export CXX=g++
109+
elif [ "${{ matrix.COMPILER }}" = "clang" ]; then
110+
export CC=clang
111+
export CXX=clang++
112+
else
113+
wget https://apt.llvm.org/llvm.sh
114+
chmod +x llvm.sh
115+
sudo ./llvm.sh ${{ env.clang-latest-version }}
116+
sudo apt-get update
117+
export CC=clang-${{ env.clang-latest-version }}
118+
export CXX=clang++-${{ env.clang-latest-version }}
119+
fi
120+
echo "CC=$CC" >> $GITHUB_ENV
121+
echo "CXX=$CXX" >> $GITHUB_ENV
122+
123+
- name: Configure CMake
124+
run: |
125+
cmake -S . \
126+
-B build-${{ matrix.COMPILER }}-${{ matrix.BUILD_CONFIGURATION }} \
127+
-G "Ninja" \
128+
-DCMAKE_BUILD_TYPE=${{ matrix.BUILD_CONFIGURATION }}
129+
130+
- name: Build server
131+
run: |
132+
cmake \
133+
--build build-${{ matrix.COMPILER }}-${{ matrix.BUILD_CONFIGURATION }} \
134+
--config ${{ matrix.BUILD_CONFIGURATION }}
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# separate terms of service, privacy policy, and support
44
# documentation.
55

6-
name: Build all
6+
name: "Build all (MSBuild)"
77

88
on:
99
push:
@@ -13,12 +13,11 @@ on:
1313
# This specifically builds when anything relating to a build changes.
1414
# Everything else can be ignored.
1515
paths:
16-
- '.github/workflows/build_all.yml'
16+
- '.github/workflows/build_msbuild_all.yml'
1717
- '**/*.props'
1818
- '**/*.cpp'
1919
- '**/*.h'
2020
- '**/*.hpp'
21-
- '**/*.ixx'
2221
- '**/*.vcxproj'
2322
- 'deps/**'
2423
- 'All.sln'
@@ -31,12 +30,11 @@ on:
3130
# This specifically builds when anything relating to a build changes.
3231
# Everything else can be ignored.
3332
paths:
34-
- '.github/workflows/build_all.yml'
33+
- '.github/workflows/build_msbuild_all.yml'
3534
- '**/*.props'
3635
- '**/*.cpp'
3736
- '**/*.h'
3837
- '**/*.hpp'
39-
- '**/*.ixx'
4038
- '**/*.vcxproj'
4139
- 'deps/**'
4240
- 'All.sln'

.github/workflows/build_client.yml renamed to .github/workflows/build_msbuild_client.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
# separate terms of service, privacy policy, and support
44
# documentation.
55

6-
name: Build client
6+
name: "Build client (MSBuild)"
77

88
on:
99
push:
1010
branches:
1111
- master
1212

1313
paths:
14-
- '.github/workflows/build_client.yml'
14+
- '.github/workflows/build_msbuild_client.yml'
1515

1616
pull_request:
1717
branches:
1818
- master
1919

2020
paths:
21-
- '.github/workflows/build_client.yml'
21+
- '.github/workflows/build_msbuild_client.yml'
2222

2323
workflow_dispatch:
2424

.github/workflows/build_client_tools.yml renamed to .github/workflows/build_msbuild_client_tools.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
# separate terms of service, privacy policy, and support
44
# documentation.
55

6-
name: Build client tools
6+
name: "Build client tools (MSBuild)"
77

88
on:
99
push:
1010
branches:
1111
- master
1212

1313
paths:
14-
- '.github/workflows/build_client_tools.yml'
14+
- '.github/workflows/build_msbuild_client_tools.yml'
1515

1616
pull_request:
1717
branches:
1818
- master
1919

2020
paths:
21-
- '.github/workflows/build_client_tools.yml'
21+
- '.github/workflows/build_msbuild_client_tools.yml'
2222

2323
workflow_dispatch:
2424

.github/workflows/build_server.yml renamed to .github/workflows/build_msbuild_server.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
# separate terms of service, privacy policy, and support
44
# documentation.
55

6-
name: Build server
6+
name: "Build server (MSBuild)"
77

88
on:
99
push:
1010
branches:
1111
- master
1212

1313
paths:
14-
- '.github/workflows/build_server.yml'
14+
- '.github/workflows/build_msbuild_server.yml'
1515

1616
pull_request:
1717
branches:
1818
- master
1919

2020
paths:
21-
- '.github/workflows/build_server.yml'
21+
- '.github/workflows/build_msbuild_server.yml'
2222

2323
workflow_dispatch:
2424

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
# separate terms of service, privacy policy, and support
44
# documentation.
55

6-
name: Build tools
6+
name: "Build tools (MSBuild)"
77

88
on:
99
push:
1010
branches:
1111
- master
1212

1313
paths:
14-
- '.github/workflows/build_tools.yml'
14+
- '.github/workflows/build_msbuild_tools.yml'
1515

1616
pull_request:
1717
branches:
1818
- master
1919

2020
paths:
21-
- '.github/workflows/build_tools.yml'
21+
- '.github/workflows/build_msbuild_tools.yml'
2222

2323
workflow_dispatch:
2424

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,7 @@ All.sln.DotSettings.user
5858
last-build-states/
5959
module-output/
6060
.env
61+
build/
62+
63+
# Do not ignore CMakeLists.txt
64+
!CMakeLists.txt

.gitmodules

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
path = deps/libjpeg-turbo
1414
url = https://github.com/libjpeg-turbo/libjpeg-turbo
1515
branch = main
16-
[submodule "deps/db-modules"]
17-
path = deps/db-modules
18-
url = https://github.com/Open-KO/OpenKO-db-modules
16+
[submodule "deps/db-models"]
17+
path = deps/db-models
18+
url = https://github.com/Open-KO/OpenKO-db-models
1919
branch = main
2020
[submodule "deps/nanodbc"]
2121
path = deps/nanodbc
@@ -27,15 +27,15 @@
2727
branch = main
2828
[submodule "deps/spdlog"]
2929
path = deps/spdlog
30-
url = https://github.com/gabime/spdlog.git
30+
url = https://github.com/Open-KO/spdlog.git
3131
branch = v1.x
3232
[submodule "deps/mpg123"]
3333
path = deps/mpg123
3434
url = https://github.com/madebr/mpg123.git
3535
branch = master-with-github-ci
3636
[submodule "deps/djb2"]
3737
path = deps/djb2
38-
url = https://github.com/ymmfty0/djb2
38+
url = https://github.com/Open-KO/djb2
3939
[submodule "deps/asio"]
4040
path = deps/asio
4141
url = https://github.com/chriskohlhoff/asio

0 commit comments

Comments
 (0)