From 0041da795a3e3d45b8d6971a6caa73a8d687fdbe Mon Sep 17 00:00:00 2001 From: Raymonf Date: Fri, 21 Aug 2020 01:18:19 -0400 Subject: [PATCH] Build multiple packet versions on AppVeyor for Windows (#14) * Move to PowerShell script for Windows build * Allow CMake to override struct version * PACKET_VERSION option * Rename CNPROTO_CUSTOM to CNPROTO_OVERRIDE Co-authored-by: Raymonf --- CMakeLists.txt | 9 ++++++++- appveyor.yml | 38 +++++++++++++++++++++++++++++++++----- src/CNStructs.hpp | 19 ++++++++++++------- 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fc5fcda..dada585 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,13 @@ project(OpenFusion) set(CMAKE_CXX_STANDARD 17) +# OpenFusion supports multiple packet/struct versions +# 0104 is the default version to build which can be changed +# For example: cmake -B build -DPACKET_VERSION=0728 +OPTION(PACKET_VERSION "The packet version to build" "0104") + +ADD_DEFINITIONS(-DCNPROTO_OVERRIDE -DCNPROTO_VERSION_${PACKET_VERSION}) + # Disallow in-source builds if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) message(FATAL_ERROR "In-source builds not allowed. Please refer to the wiki for more information. Please remove the CMakeFiles folder and the CMakeCache.txt file.") @@ -38,4 +45,4 @@ set_target_properties(openfusion PROPERTIES OUTPUT_NAME ${BIN_NAME}) if (NOT CMAKE_GENERATOR MATCHES "Visual Studio" AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND NOT CMAKE_GENERATOR MATCHES "MinGW Makefiles") find_package(Threads REQUIRED) target_link_libraries(openfusion pthread) -endif() \ No newline at end of file +endif() diff --git a/appveyor.yml b/appveyor.yml index e681892..acad59a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -25,12 +25,40 @@ for: type: zip - matrix: - only: - - image: Visual Studio 2019 - before_build: - - cmake -B build + only: + - image: Visual Studio 2019 build_script: - - msbuild build/OpenFusion.sln /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" + - ps: | + $versions = "0104", "0728" + $configurations = "Release", "Debug" + + # AppVeyor uses VS2019 Community + $vsPath = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community" + + Import-Module "$vsPath\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" + Enter-VsDevShell -VsInstallPath $vsPath -SkipAutomaticLocation + + foreach ($version in $versions) { + if (Test-Path -LiteralPath "build") { + Remove-Item "build" -Recurse + Write-Output "Deleted existing build folder" + } + Invoke-Expression "cmake -B build -DPACKET_VERSION=$version" + if ($LASTEXITCODE -ne "0") { + Write-Error "cmake generation failed for version $version" -ErrorAction Stop + } + Write-Output "Generated build files for version $version" + + foreach ($configuration in $configurations) { + Write-Output "Building version $version $configuration" + Invoke-Expression "msbuild build\OpenFusion.sln /p:Configuration=$configuration" + if ($LASTEXITCODE -ne "0") { + Write-Error "msbuild build failed for version $version" -ErrorAction Stop + } + Rename-Item -Path "bin/$configuration" -newName "$version-$configuration" + Write-Output "Built version $version $configuration" + } + } artifacts: - path: bin name: windows-vs2019-bin-x64 diff --git a/src/CNStructs.hpp b/src/CNStructs.hpp index 4007758..9df5f31 100644 --- a/src/CNStructs.hpp +++ b/src/CNStructs.hpp @@ -6,19 +6,19 @@ #define _CNS_HPP #ifdef _MSC_VER -// codecvt_* is deprecated in C++17 and MSVC will throw an annoying warning because of that. -// Defining this before anything else to silence it. -#define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING + // codecvt_* is deprecated in C++17 and MSVC will throw an annoying warning because of that. + // Defining this before anything else to silence it. + #define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING #endif #include #include #include #ifndef _MSC_VER -#include + #include #else // Can't use this in MSVC. -#include + #include #endif #include #include @@ -31,8 +31,13 @@ std::string U16toU8(char16_t* src); int U8toU16(std::string src, char16_t* des); // returns number of char16_t that was written at des uint64_t getTime(); -//#define CNPROTO_VERSION_0728 -#define CNPROTO_VERSION_0104 +// The CNPROTO_OVERRIDE definition is defined by cmake if you use it. +// If you don't use cmake, feel free to comment this out and change it around. +// Otherwise, use the PACKET_VERSION option (e.g. -DPACKET_VERSION=0104 in the cmake command) to change it. +#if !defined(CNPROTO_OVERRIDE) + //#define CNPROTO_VERSION_0728 + #define CNPROTO_VERSION_0104 +#endif #if defined(CNPROTO_VERSION_0104) #include "structs/0104.hpp"