From e27f6fe36fa7d427d835c76acf4702790f7dfa2c Mon Sep 17 00:00:00 2001 From: Chris Sarbora Date: Tue, 25 Jun 2024 23:06:02 -0500 Subject: [PATCH] Use vcpkg for all platform presets --- .github/workflows/build.yml | 9 ++- Brewfile | 7 -- CMakeLists.txt | 22 +++++- CMakePresets.json | 3 +- README.md | 131 ++++++++++++++++++++++++++++-------- vcpkg.json | 9 ++- 6 files changed, 138 insertions(+), 43 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 633b70729..33b46b63d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -66,22 +66,25 @@ jobs: run: | sudo apt update sudo apt install -y --no-install-recommends \ - ninja-build cmake g++ libgtest-dev libsdl2-dev zlib1g-dev libspdlog-dev + ninja-build cmake g++ libspdlog-dev - name: Install Windows dependencies if: ${{ matrix.os.runner == 'windows-latest' }} run: choco install ninja - + - uses: ilammy/msvc-dev-cmd@v1 if: ${{ matrix.os.runner == 'windows-latest' }} with: arch: win64 + - uses: lukka/run-vcpkg@v11 + with: + vcpkgJsonGlob: vcpkg.json + - name: Configure CMake env: CC: ${{ matrix.os.cc }} CXX: ${{ matrix.os.cxx }} - VCPKG_ROOT: C:/vcpkg run: cmake --preset ${{ matrix.os.preset }} -DBUILD_TESTING=ON -DENABLE_LOGGER=ON -DFORCE_PORTABLE_INSTALL=ON -DBUILD_EDITOR=ON - name: Build ${{ matrix.build_type }} diff --git a/Brewfile b/Brewfile index ffd96d258..7df945a3b 100644 --- a/Brewfile +++ b/Brewfile @@ -1,11 +1,4 @@ # Homebrew dependencies to build Descent3 -# SDL -brew "sdl2" - brew "cmake" -brew "googletest" brew "ninja" - -# zlib -brew "zlib" diff --git a/CMakeLists.txt b/CMakeLists.txt index 529a76051..d99813f38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,25 @@ cmake_minimum_required(VERSION 3.20) # For using CMAKE__BYTE_ORDER +if(NOT DEFINED USE_VCPKG OR USE_VCPKG) + message("NOT DEFINED USE_VCPKG OR USE_VCPKG") + if(DEFINED ENV{VCPKG_ROOT}) + message("DEFINED ENV{VCPKG_ROOT}") + if (CMAKE_TOOLCHAIN_FILE) + cmake_path(ABSOLUTE_PATH CMAKE_TOOLCHAIN_FILE NORMALIZE OUTPUT_VARIABLE VCPKG_CHAINLOAD_TOOLCHAIN_FILE) + endif() + + set(VCPKG_TOOLCHAIN_FILE "scripts/buildsystems/vcpkg.cmake") + cmake_path(ABSOLUTE_PATH VCPKG_TOOLCHAIN_FILE BASE_DIRECTORY $ENV{VCPKG_ROOT} NORMALIZE OUTPUT_VARIABLE CMAKE_TOOLCHAIN_FILE) + + if(CMAKE_TOOLCHAIN_FILE STREQUAL VCPKG_CHAINLOAD_TOOLCHAIN_FILE) + # prevent endless recursion + unset(VCPKG_CHAINLOAD_TOOLCHAIN_FILE) + endif() + elseif(USE_VCPKG) + 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?") + endif() +endif() + # set default cmake build type to Debug (None Debug Release RelWithDebInfo MinSizeRel) if(NOT CMAKE_BUILD_TYPE AND NOT DEFINED ENV{CMAKE_BUILD_TYPE}) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "default build type") @@ -10,7 +30,7 @@ project(Descent3 VERSION 1.5.0 ) -option(FORCE_COLORED_OUTPUT "Always produce ANSI-colored compiler warnings/errors (GCC/Clang only; esp. useful with ninja)." OFF) +option(FORCE_COLORED_OUTPUT "Always produce ANSI-colored compiler warnings/errors (GCC/Clang only; esp. useful with Ninja)." OFF) option(FORCE_PORTABLE_INSTALL "Install all files into local directory defined by CMAKE_INSTALL_PREFIX" ON) option(ENABLE_LOGGER "Enable logging to the terminal" OFF) option(ENABLE_MEM_RTL "Enable Real-time library memory management functions (disable to verbose memory allocations)" ON) diff --git a/CMakePresets.json b/CMakePresets.json index 0b5f90e51..23e5c4a11 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -21,8 +21,7 @@ "architecture": { "strategy": "external", "value": "x64" - }, - "toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" + } }, { "name": "mac", diff --git a/README.md b/README.md index 080de55d9..9cc40cc5f 100644 --- a/README.md +++ b/README.md @@ -92,9 +92,17 @@ The milestone needs testing on all platforms. Please report issues when found. - D3 Open Source compiles level scripts in their own hogfiles. Make sure you copy and overwrite `d3-{platform}.hog`. ## Building +#### Dependencies +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**. + +#### Installing and using **vcpkg** +* When building for Windows, **vcpkg** is already installed and configured when using the Developer Tools Command Prompt. +* 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. + #### Building - Windows -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: +1. Install the prerequisite build tools. + 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: - ```batch winget install Git.Git Microsoft.VisualStudio.2022.Community @@ -114,61 +121,127 @@ The milestone needs testing on all platforms. Please report issues when found. --add Microsoft.VisualStudio.Component.VC.ATLMFC ``` -2. Open a “x64 Native Tools Command Prompt” and run: +2. Clone the Descent3 source code. + Open a “**x64 Native Tools Command Prompt**” and run: ```batch git clone https://github.com/DescentDevelopers/Descent3 + ``` + +3. Acquire the library dependencies. + + The **Native Tools** prompts will already have **vcpkg** installed and configured for use, so no dependency management is needed. + +4. Build Descent3. + + Open a “**x64 Native Tools Command Prompt**” and run: + ```batch cd Descent3 - cmake --preset win -D ENABLE_LOGGER=[ON|OFF] -D BUILD_EDITOR=[ON|OFF] + cmake --preset win cmake --build --preset win --config [Debug|Release] ``` + See "Build Options" below for more information on `Debug` vs `Release`. Once CMake finishes, the built files will be put in `builds\win\Descent3\Debug` or `builds\win\Descent3\Release`. #### Building - macOS -1. Make sure that [Xcode](https://developer.apple.com/xcode) is installed. +1. Install the prerequisite build tools. -2. Make sure that [Homebrew](https://brew.sh) is installed. + * Make sure that [Xcode](https://developer.apple.com/xcode) is installed. + * Make sure that [Homebrew](https://brew.sh) is installed. -3. Run these commands: +2. Clone the Descent3 source code. + Open a Terminal and run: ```sh git clone https://github.com/DescentDevelopers/Descent3 + ``` + +3. Acquire the library dependencies. + + * If you would like to use **vcpkg**: + ```sh + git clone https://github.com/microsoft/vcpkg + cd vcpkg + export VCPKG_ROOT=$(pwd) + # IMPORTANT: You will need $VCPKG_ROOT defined for all build runs. It is a good idea to set this in your .bashrc or equivalent. + ``` + * If you would like to manage the code dependencies yourself: + ```sh + brew install sdl2 zlib googletest + ``` + +3. Build Descent3. + + ```sh cd Descent3 brew bundle install - cmake --preset mac -D ENABLE_LOGGER=[ON|OFF] + cmake --preset mac cmake --build --preset mac --config [Debug|Release] ``` + See "Build Options" below for more information on `Debug` vs `Release`. Once CMake finishes, the built files will be put in `builds/mac/Descent3/Debug` or `builds/mac/Descent3/Release`. -#### Building - Linux (Ubuntu) -Run these commands: +#### Building - Linux +1. Install the prerequisite build tools. -```sh -sudo apt update -sudo apt install -y --no-install-recommends git ninja-build cmake g++ libsdl2-dev zlib1g-dev -git clone https://github.com/DescentDevelopers/Descent3 -cd Descent3 -cmake --preset linux -D ENABLE_LOGGER=[ON|OFF] -cmake --build --preset linux --config [Debug|Release] -``` + * Apt users (Debian, Ubuntu) + ```sh + sudo apt update + sudo apt install -y --no-install-recommends git ninja-build cmake g++ + ``` + * Dnf users (Red Hat, Fedora) + ```sh + sudo dnf update --refresh + sudo dnf install -y git ninja-build cmake gcc-c++ + ``` -Once CMake finishes, the built files will be put in `builds/linux/Descent3/Debug` or `builds/linux/Descent3/Release`. +2. Clone the Descent3 source code. + + Open a Terminal and run: + ```sh + git clone https://github.com/DescentDevelopers/Descent3 + ``` -#### Building - Linux (Fedora) -Run these commands: +3. Acquire the library dependencies. + + * If you would like to use **vcpkg**: + ```sh + git clone https://github.com/microsoft/vcpkg + cd vcpkg + export VCPKG_ROOT=$(pwd) + # IMPORTANT: You will need $VCPKG_ROOT defined for all build runs. It is a good idea to set this in your .bashrc or equivalent. + ``` + * If you would like to manage the code dependencies yourself: + * Apt users + ```sh + sudo apt install -y --no-install-recommends libsdl2-dev zlib1g-dev libgtest-dev + * Dnf users + ```sh + sudo dnf install sdl2-devel zlib-devel gtest + ``` + +3. Build Descent3. -```sh -sudo dnf update --refresh -sudo dnf install -y git ninja-build cmake gcc-c++ SDL2-devel zlib-devel -git clone https://github.com/DescentDevelopers/Descent3 -cd Descent3 -cmake --preset linux -D ENABLE_LOGGER=[ON|OFF] -cmake --build --preset linux --config [Debug|Release] -``` + ```sh + cd Descent3 + cmake --preset linux + cmake --build --preset linux --config [Debug|Release] + ``` + See "Build Options" below for more information on `Debug` vs `Release`. Once CMake finishes, the built files will be put in `builds/linux/Descent3/Debug` or `builds/linux/Descent3/Release`. +#### Build Options +* `Debug` vs `Release` TODO +* `BUILD_EDITOR` - Build internal editor. Default OFF. +* `BUILD_TESTING` - Enable testing. Requires GTest. Default OFF. +* `ENABLE_LOGGER` - Enable logging to the terminal. Default OFF. +* `ENABLE_MEM_RTL` - Enable Real-time library memory management functions (disable to verbose memory allocations). Default ON. +* `FORCE_COLORED_OUTPUT` - Always produce ANSI-colored compiler warnings/errors (GCC/Clang only; esp. useful with Ninja). Default OFF. +* `FORCE_PORTABLE_INSTALL` - Install all files into local directory defined by `CMAKE_INSTALL_PREFIX`. Default ON. +* `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. + ## Contributing 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. diff --git a/vcpkg.json b/vcpkg.json index 56db60f8a..0f09d7022 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -5,7 +5,14 @@ "zlib", { "name": "sdl2", - "version>=": "2.30.3" + "version>=": "2.30.3", + "features": ["x11","wayland"], + "platform": "linux" + }, + { + "name": "sdl2", + "version>=": "2.30.3", + "platform": "!linux" } ], "overrides": [