Skip to content

Commit e27f6fe

Browse files
committed
Use vcpkg for all platform presets
1 parent e68f270 commit e27f6fe

File tree

6 files changed

+138
-43
lines changed

6 files changed

+138
-43
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,25 @@ jobs:
6666
run: |
6767
sudo apt update
6868
sudo apt install -y --no-install-recommends \
69-
ninja-build cmake g++ libgtest-dev libsdl2-dev zlib1g-dev libspdlog-dev
69+
ninja-build cmake g++ libspdlog-dev
7070
7171
- name: Install Windows dependencies
7272
if: ${{ matrix.os.runner == 'windows-latest' }}
7373
run: choco install ninja
74-
74+
7575
- uses: ilammy/msvc-dev-cmd@v1
7676
if: ${{ matrix.os.runner == 'windows-latest' }}
7777
with:
7878
arch: win64
7979

80+
- uses: lukka/run-vcpkg@v11
81+
with:
82+
vcpkgJsonGlob: vcpkg.json
83+
8084
- name: Configure CMake
8185
env:
8286
CC: ${{ matrix.os.cc }}
8387
CXX: ${{ matrix.os.cxx }}
84-
VCPKG_ROOT: C:/vcpkg
8588
run: cmake --preset ${{ matrix.os.preset }} -DBUILD_TESTING=ON -DENABLE_LOGGER=ON -DFORCE_PORTABLE_INSTALL=ON -DBUILD_EDITOR=ON
8689

8790
- name: Build ${{ matrix.build_type }}

Brewfile

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
# Homebrew dependencies to build Descent3
22

3-
# SDL
4-
brew "sdl2"
5-
63
brew "cmake"
7-
brew "googletest"
84
brew "ninja"
9-
10-
# zlib
11-
brew "zlib"

CMakeLists.txt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
cmake_minimum_required(VERSION 3.20) # For using CMAKE_<LANG>_BYTE_ORDER
22

3+
if(NOT DEFINED USE_VCPKG OR USE_VCPKG)
4+
message("NOT DEFINED USE_VCPKG OR USE_VCPKG")
5+
if(DEFINED ENV{VCPKG_ROOT})
6+
message("DEFINED ENV{VCPKG_ROOT}")
7+
if (CMAKE_TOOLCHAIN_FILE)
8+
cmake_path(ABSOLUTE_PATH CMAKE_TOOLCHAIN_FILE NORMALIZE OUTPUT_VARIABLE VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
9+
endif()
10+
11+
set(VCPKG_TOOLCHAIN_FILE "scripts/buildsystems/vcpkg.cmake")
12+
cmake_path(ABSOLUTE_PATH VCPKG_TOOLCHAIN_FILE BASE_DIRECTORY $ENV{VCPKG_ROOT} NORMALIZE OUTPUT_VARIABLE CMAKE_TOOLCHAIN_FILE)
13+
14+
if(CMAKE_TOOLCHAIN_FILE STREQUAL VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
15+
# prevent endless recursion
16+
unset(VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
17+
endif()
18+
elseif(USE_VCPKG)
19+
message(WARNING "USE_VCPKG=${USE_VCPKG} but ENV{VCPKG_ROOT} not set; will use system-provided libraries. Did you forget to set VCPKG_ROOT in your environment?")
20+
endif()
21+
endif()
22+
323
# set default cmake build type to Debug (None Debug Release RelWithDebInfo MinSizeRel)
424
if(NOT CMAKE_BUILD_TYPE AND NOT DEFINED ENV{CMAKE_BUILD_TYPE})
525
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "default build type")
@@ -10,7 +30,7 @@ project(Descent3
1030
VERSION 1.5.0
1131
)
1232

13-
option(FORCE_COLORED_OUTPUT "Always produce ANSI-colored compiler warnings/errors (GCC/Clang only; esp. useful with ninja)." OFF)
33+
option(FORCE_COLORED_OUTPUT "Always produce ANSI-colored compiler warnings/errors (GCC/Clang only; esp. useful with Ninja)." OFF)
1434
option(FORCE_PORTABLE_INSTALL "Install all files into local directory defined by CMAKE_INSTALL_PREFIX" ON)
1535
option(ENABLE_LOGGER "Enable logging to the terminal" OFF)
1636
option(ENABLE_MEM_RTL "Enable Real-time library memory management functions (disable to verbose memory allocations)" ON)

CMakePresets.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
"architecture": {
2222
"strategy": "external",
2323
"value": "x64"
24-
},
25-
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
24+
}
2625
},
2726
{
2827
"name": "mac",

README.md

Lines changed: 102 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,24 @@ The milestone needs testing on all platforms. Please report issues when found.
9292
- D3 Open Source compiles level scripts in their own hogfiles. Make sure you copy and overwrite `d3-{platform}.hog`.
9393

9494
## Building
95+
#### Dependencies
96+
The build process uses [**CMake**](https://cmake.org/) and, by default, [**Ninja**](https://ninja-build.org/). You must install these; the project cannot locate them for you. The source code depends on [**SDL2**](https://github.com/libsdl-org/SDL) and [**zlib**](https://github.com/madler/zlib). You can supply these dependencies yourself via your system's library management tools, or the build system can locate the dependencies for you using [**vcpkg**](https://github.com/microsoft/vcpkg), a cross-platform dependency-management system developed by Microsoft. The official builds source their dependencies from **vcpkg**.
97+
98+
#### Installing and using **vcpkg**
99+
* When building for Windows, **vcpkg** is already installed and configured when using the Developer Tools Command Prompt.
100+
* For Android, Linux or Mac (or non-standard-Windows) configurations, you will need to install **vcpkg** locally by cloning https://github.com/microsoft/vcpkg and setting your `VCPKG_ROOT` env var to the repository location. With this environment variable set, the build will automatically locate its dependencies.
101+
95102
#### Building - Windows
96-
1. Make sure that you have Git and Visual Studio 2022 with the “Desktop development with C++” workload and the “C++ MFC for latest v143 build tools (x86 & x64)” component. If you don’t already have those installed or you aren’t sure, then open an elevated Command Prompt and run:
103+
1. Install the prerequisite build tools.
97104

105+
Make sure that you have Git and Visual Studio 2022 with the “Desktop development with C++” workload and the “C++ MFC for latest v143 build tools (x86 & x64)” component. If you don’t already have those installed or you aren’t sure, then open an elevated Command Prompt and run:
98106
<!--
99107
The following code block specifies the full path to the Visual Studio Installer because the Visual Studio Installer doesn’t add itself to the user’s Path. The installer is guaranteed to be in a specific location on 64-bit systems [1]. The installer will be in a different location on 32-bit systems [2], but Visual Studio 2022 doesn’t support 32-bit systems [3] so we can ignore that detail.
100108
101109
[1]: <https://learn.microsoft.com/en-us/visualstudio/install/use-command-line-parameters-to-install-visual-studio?view=vs-2022>
102110
[2]: <https://github.com/microsoft/vswhere/wiki#installing>
103111
[3]: <https://learn.microsoft.com/en-us/answers/questions/1689898/does-visual-studio-build-tools-2022-support-32-bit>
104112
-->
105-
106113
```batch
107114
winget install Git.Git Microsoft.VisualStudio.2022.Community
108115
@@ -114,61 +121,127 @@ The milestone needs testing on all platforms. Please report issues when found.
114121
--add Microsoft.VisualStudio.Component.VC.ATLMFC
115122
```
116123
117-
2. Open a “x64 Native Tools Command Prompt” and run:
124+
2. Clone the Descent3 source code.
118125
126+
Open a “**x64 Native Tools Command Prompt**” and run:
119127
```batch
120128
git clone https://github.com/DescentDevelopers/Descent3
129+
```
130+
131+
3. Acquire the library dependencies.
132+
133+
The **Native Tools** prompts will already have **vcpkg** installed and configured for use, so no dependency management is needed.
134+
135+
4. Build Descent3.
136+
137+
Open a “**x64 Native Tools Command Prompt**” and run:
138+
```batch
121139
cd Descent3
122-
cmake --preset win -D ENABLE_LOGGER=[ON|OFF] -D BUILD_EDITOR=[ON|OFF]
140+
cmake --preset win
123141
cmake --build --preset win --config [Debug|Release]
124142
```
143+
See "Build Options" below for more information on `Debug` vs `Release`.
125144
126145
Once CMake finishes, the built files will be put in `builds\win\Descent3\Debug` or `builds\win\Descent3\Release`.
127146
128147
#### Building - macOS
129-
1. Make sure that [Xcode](https://developer.apple.com/xcode) is installed.
148+
1. Install the prerequisite build tools.
130149
131-
2. Make sure that [Homebrew](https://brew.sh) is installed.
150+
* Make sure that [Xcode](https://developer.apple.com/xcode) is installed.
151+
* Make sure that [Homebrew](https://brew.sh) is installed.
132152
133-
3. Run these commands:
153+
2. Clone the Descent3 source code.
134154
155+
Open a Terminal and run:
135156
```sh
136157
git clone https://github.com/DescentDevelopers/Descent3
158+
```
159+
160+
3. Acquire the library dependencies.
161+
162+
* If you would like to use **vcpkg**:
163+
```sh
164+
git clone https://github.com/microsoft/vcpkg
165+
cd vcpkg
166+
export VCPKG_ROOT=$(pwd)
167+
# IMPORTANT: You will need $VCPKG_ROOT defined for all build runs. It is a good idea to set this in your .bashrc or equivalent.
168+
```
169+
* If you would like to manage the code dependencies yourself:
170+
```sh
171+
brew install sdl2 zlib googletest
172+
```
173+
174+
3. Build Descent3.
175+
176+
```sh
137177
cd Descent3
138178
brew bundle install
139-
cmake --preset mac -D ENABLE_LOGGER=[ON|OFF]
179+
cmake --preset mac
140180
cmake --build --preset mac --config [Debug|Release]
141181
```
182+
See "Build Options" below for more information on `Debug` vs `Release`.
142183
143184
Once CMake finishes, the built files will be put in `builds/mac/Descent3/Debug` or `builds/mac/Descent3/Release`.
144185
145-
#### Building - Linux (Ubuntu)
146-
Run these commands:
186+
#### Building - Linux
187+
1. Install the prerequisite build tools.
147188
148-
```sh
149-
sudo apt update
150-
sudo apt install -y --no-install-recommends git ninja-build cmake g++ libsdl2-dev zlib1g-dev
151-
git clone https://github.com/DescentDevelopers/Descent3
152-
cd Descent3
153-
cmake --preset linux -D ENABLE_LOGGER=[ON|OFF]
154-
cmake --build --preset linux --config [Debug|Release]
155-
```
189+
* Apt users (Debian, Ubuntu)
190+
```sh
191+
sudo apt update
192+
sudo apt install -y --no-install-recommends git ninja-build cmake g++
193+
```
194+
* Dnf users (Red Hat, Fedora)
195+
```sh
196+
sudo dnf update --refresh
197+
sudo dnf install -y git ninja-build cmake gcc-c++
198+
```
156199
157-
Once CMake finishes, the built files will be put in `builds/linux/Descent3/Debug` or `builds/linux/Descent3/Release`.
200+
2. Clone the Descent3 source code.
201+
202+
Open a Terminal and run:
203+
```sh
204+
git clone https://github.com/DescentDevelopers/Descent3
205+
```
158206
159-
#### Building - Linux (Fedora)
160-
Run these commands:
207+
3. Acquire the library dependencies.
208+
209+
* If you would like to use **vcpkg**:
210+
```sh
211+
git clone https://github.com/microsoft/vcpkg
212+
cd vcpkg
213+
export VCPKG_ROOT=$(pwd)
214+
# IMPORTANT: You will need $VCPKG_ROOT defined for all build runs. It is a good idea to set this in your .bashrc or equivalent.
215+
```
216+
* If you would like to manage the code dependencies yourself:
217+
* Apt users
218+
```sh
219+
sudo apt install -y --no-install-recommends libsdl2-dev zlib1g-dev libgtest-dev
220+
* Dnf users
221+
```sh
222+
sudo dnf install sdl2-devel zlib-devel gtest
223+
```
224+
225+
3. Build Descent3.
161226
162-
```sh
163-
sudo dnf update --refresh
164-
sudo dnf install -y git ninja-build cmake gcc-c++ SDL2-devel zlib-devel
165-
git clone https://github.com/DescentDevelopers/Descent3
166-
cd Descent3
167-
cmake --preset linux -D ENABLE_LOGGER=[ON|OFF]
168-
cmake --build --preset linux --config [Debug|Release]
169-
```
227+
```sh
228+
cd Descent3
229+
cmake --preset linux
230+
cmake --build --preset linux --config [Debug|Release]
231+
```
232+
See "Build Options" below for more information on `Debug` vs `Release`.
170233
171234
Once CMake finishes, the built files will be put in `builds/linux/Descent3/Debug` or `builds/linux/Descent3/Release`.
172235
236+
#### Build Options
237+
* `Debug` vs `Release` TODO
238+
* `BUILD_EDITOR` - Build internal editor. Default OFF.
239+
* `BUILD_TESTING` - Enable testing. Requires GTest. Default OFF.
240+
* `ENABLE_LOGGER` - Enable logging to the terminal. Default OFF.
241+
* `ENABLE_MEM_RTL` - Enable Real-time library memory management functions (disable to verbose memory allocations). Default ON.
242+
* `FORCE_COLORED_OUTPUT` - Always produce ANSI-colored compiler warnings/errors (GCC/Clang only; esp. useful with Ninja). Default OFF.
243+
* `FORCE_PORTABLE_INSTALL` - Install all files into local directory defined by `CMAKE_INSTALL_PREFIX`. Default ON.
244+
* `USE_VCPKG` - Explicitly control whether or not to use **vcpkg** for dependency resolution. ON requires `VCPKG_ROOT` environment variable set. Default behavior is determined by the existence of `VCPKG_ROOT` in the environment: If it exists, **vcpkg** is used.
245+
173246
## Contributing
174247
Anyone can contribute! We have an active Discord presence at [Descent Developer Network](https://discord.gg/GNy5CUQ). If you are interested in maintaining the project on a regular basis, please contact Kevin Bentley.

vcpkg.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@
55
"zlib",
66
{
77
"name": "sdl2",
8-
"version>=": "2.30.3"
8+
"version>=": "2.30.3",
9+
"features": ["x11","wayland"],
10+
"platform": "linux"
11+
},
12+
{
13+
"name": "sdl2",
14+
"version>=": "2.30.3",
15+
"platform": "!linux"
916
}
1017
],
1118
"overrides": [

0 commit comments

Comments
 (0)