From ce0345854c5f2751b72c8e51153b41f3954f2ce7 Mon Sep 17 00:00:00 2001 From: Jammyjamjamman Date: Mon, 14 Jun 2021 01:39:03 +0100 Subject: [PATCH] New windows build helper scripts * build-mg-vs-cmake.ps1 to build mg. * clean-all.ps1 to clean mg. * install-deps-vcpkg.ps1 * .gitignore ignores build and vcpkg folders. --- mk/windoze/.gitignore | 2 + mk/windoze/build-mg-vs-cmake.ps1 | 118 ++++++++++++++++++++++++++++++ mk/windoze/clean-all.ps1 | 4 + mk/windoze/install-deps-vcpkg.ps1 | 2 + mk/windoze/vcpkg_deps.ps1 | 1 - 5 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 mk/windoze/build-mg-vs-cmake.ps1 create mode 100644 mk/windoze/clean-all.ps1 create mode 100644 mk/windoze/install-deps-vcpkg.ps1 delete mode 100644 mk/windoze/vcpkg_deps.ps1 diff --git a/mk/windoze/.gitignore b/mk/windoze/.gitignore index 53bf9b3c..59f846ba 100644 --- a/mk/windoze/.gitignore +++ b/mk/windoze/.gitignore @@ -2,6 +2,8 @@ /*/Release/ /x64/ /*/x64/ +/vcpkg/ +/build/ # Windows_build *.dll diff --git a/mk/windoze/build-mg-vs-cmake.ps1 b/mk/windoze/build-mg-vs-cmake.ps1 new file mode 100644 index 00000000..aff20146 --- /dev/null +++ b/mk/windoze/build-mg-vs-cmake.ps1 @@ -0,0 +1,118 @@ +# Build MegaGlest on Windows. +# Author: James Sherratt. +param(${vcpkg-location}) + +$sword = [char]::ConvertFromUtf32(0x2694) +Write-Output "=====$sword Mega Glest $sword=====" +"" +<# +.SYNOPSIS +# + +.DESCRIPTION +Test if a command exists. + +.PARAMETER cmdName +Comamnd to test + +.PARAMETER errorAdvice +Error advice to give user if command fails + +.PARAMETER errorAction +(optional) Etion after error + +.EXAMPLE +Test-Command "7z" "7z not found. Please install from 7zip.org" 'Write-Warning "7zip will not be used."' + +.NOTES +General notes +#> +function Test-Command { + param( + $cmdName, + $errorAdvice, + $errorAction + ) + + if (Get-Command $cmdName -errorAction SilentlyContinue) { + "Found $cmdName." + "" + } + else { + "The command '$cmdName' does not exist." + "$errorAdvice" + "" + + if ( !$errorAction ) { + Exit + } + else { + Invoke-Expression $errorAction + } + } +} + +function Write-Title { + param ( + $titleText + ) + $titleText + "-" * $titleText.Length +} + +Write-Title "Updating git source" + +Test-Command "git" "Please download and install git-scm https://git-scm.com/" +git pull +"" + +Write-Title "Setup vcpkg" +Test-Command "cmake" "Please download and install CMake: https://cmake.org/download/. (For 64 bit windows, select 'cmake-x.y.z-windows-x86_64.msi'.)" + +${vcpkg-location} = $(Resolve-Path ${vcpkg-location}).ToString() +"path is ${vcpkg-location}" + +if ( !${vcpkg-location} ) { + ${vcpkg-location} = Join-Path $PSScriptRoot \vcpkg + "Vcpkg location not set. Setting it to ${vcpkg-location}." +} + +if ( Test-Path ${vcpkg-location} ) { + "Found vcpkg." +} +else { + "Vcpkg not found. Cloning. https://github.com/microsoft/vcpkg.git." + git clone "https://github.com/microsoft/vcpkg.git" ${vcpkg-location} + "Installing vcpkg." + & "$(Join-Path ${vcpkg-location} bootstrap-vcpkg.bat)" +} + +"Installing vcpkg and Mega Glest dependencies." +Set-Location ${vcpkg-location} +& "$(Join-Path $PSScriptRoot install-deps-vcpkg.ps1)" +if (!$?) { + "Installing deps with vcpkg failed. Please check your vcpkg git repo is configured correctly." + Set-Location $PSScriptRoot + Exit +} +Set-Location $PSScriptRoot +"" + +Write-Title "Build Mega Glest" + +$toolchainPath = $(Join-Path ${vcpkg-location} \scripts\buildsystems\vcpkg.cmake) +$buildFolder = $(Join-Path $PSScriptRoot build) +$topLevelTargetDir = $(Resolve-Path $(Join-Path $PSScriptRoot ../../)).ToString() + +cmake --no-warn-unused-cli -DCMAKE_TOOLCHAIN_FILE:STRING=$toolchainPath -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE "-H$topLevelTargetDir" "-B$buildFolder" -G "Visual Studio 16 2019" -T host=x64 -A x64 +cmake --build $buildFolder --config Release --target ALL_BUILD -j 18 +"" + +if ($?) { + "Build succeeded. megaglest.exe, megaglest_editor.exe and megaglest_g3dviewer.exe can be found in mk/windoze/." +} +else { + "Build failed. Please make sure you have installed VS C++ tools: https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019" + "If you have installed all the relevant tools and you still can't build Mega Glest, try running '.\clean-build.ps1'. Then run this script again." + "If Mega Glest still fails to build, please consider submitting a bug report at https://github.com/MegaGlest/megaglest-source/issues." +} diff --git a/mk/windoze/clean-all.ps1 b/mk/windoze/clean-all.ps1 new file mode 100644 index 00000000..597ed15a --- /dev/null +++ b/mk/windoze/clean-all.ps1 @@ -0,0 +1,4 @@ +"Cleaning build files." +Remove-Item $(Join-Path $PSScriptRoot *.exe) +Remove-Item -Recurse $(Join-Path $PSScriptRoot build\) +"Cleaning build files completed." diff --git a/mk/windoze/install-deps-vcpkg.ps1 b/mk/windoze/install-deps-vcpkg.ps1 new file mode 100644 index 00000000..36fee871 --- /dev/null +++ b/mk/windoze/install-deps-vcpkg.ps1 @@ -0,0 +1,2 @@ +"Installing MegaGlest deps." +.\vcpkg.exe install --disable-metrics brotli:x64-windows-static bzip2:x64-windows-static curl:x64-windows-static expat:x64-windows-static freetype:x64-windows-static fribidi:x64-windows-static ftgl:x64-windows-static glew:x64-windows-static libiconv:x64-windows-static libjpeg-turbo:x64-windows-static liblzma:x64-windows-static libogg:x64-windows-static libpng:x64-windows-static libvorbis:x64-windows-static libxml2:x64-windows-static lua:x64-windows-static openal-soft:x64-windows-static opengl:x64-windows-static miniupnpc:x64-windows-static sdl2:x64-windows-static sqlite3:x64-windows-static tiff:x64-windows-static tool-meson:x64-windows-static wxwidgets:x64-windows-static xerces-c:x64-windows-static zlib:x64-windows-static diff --git a/mk/windoze/vcpkg_deps.ps1 b/mk/windoze/vcpkg_deps.ps1 deleted file mode 100644 index 874a9e77..00000000 --- a/mk/windoze/vcpkg_deps.ps1 +++ /dev/null @@ -1 +0,0 @@ -.\vcpkg.exe install brotli:x64-windows-static bzip2:x64-windows-static curl:x64-windows-static expat:x64-windows-static freetype:x64-windows-static fribidi:x64-windows-static ftgl:x64-windows-static glew:x64-windows-static libiconv:x64-windows-static libjpeg-turbo:x64-windows-static liblzma:x64-windows-static libogg:x64-windows-static libpng:x64-windows-static libvorbis:x64-windows-static libxml2:x64-windows-static lua:x64-windows-static openal-soft:x64-windows-static opengl:x64-windows-static miniupnpc:x64-windows-static sdl2:x64-windows-static sqlite3:x64-windows-static tiff:x64-windows-static tool-meson:x64-windows-static wxwidgets:x64-windows-static xerces-c:x64-windows-static zlib:x64-windows-static