diff --git a/build/BuildWindowsTask.cs b/build/BuildWindowsTask.cs index 9d59c0c..f70e576 100644 --- a/build/BuildWindowsTask.cs +++ b/build/BuildWindowsTask.cs @@ -1,3 +1,4 @@ +using Cake.Common.Tools.VSWhere.Latest; namespace BuildScripts; @@ -10,12 +11,23 @@ public sealed class BuildWindowsTask : FrostingTask public override void Run(BuildContext context) { + var vswhere = new VSWhereLatest(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); + + string cmake = "cmake"; + string msbuild = "msbuild"; + + // If processes are not on PATH, we want to retrieve the Visual Studio installation + if (!IsOnPATH(cmake)) + cmake = vswhere.Latest(new VSWhereLatestSettings()).FullPath + @"\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe"; + if (!IsOnPATH(msbuild)) + msbuild = vswhere.Latest(new VSWhereLatestSettings()).FullPath + @"\MSBuild\Current\Bin\MSBuild.exe"; + // Build var buildDir = "sdl/build_x64"; context.CreateDirectory(buildDir); context.CreateDirectory($"{context.ArtifactsDir}/win-x64"); - context.StartProcess("cmake", new ProcessSettings { WorkingDirectory = buildDir, Arguments = "-A x64 -D CMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded ../" }); - context.StartProcess("msbuild", new ProcessSettings { WorkingDirectory = buildDir, Arguments = "SDL2.sln /p:Configuration=Release" }); + context.StartProcess(cmake, new ProcessSettings { WorkingDirectory = buildDir, Arguments = "-A x64 -D CMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded ../" }); + context.StartProcess(msbuild, new ProcessSettings { WorkingDirectory = buildDir, Arguments = "SDL2.sln /p:Configuration=Release" }); // Copy artifact context.CreateDirectory(context.ArtifactsDir); @@ -24,11 +36,35 @@ public override void Run(BuildContext context) buildDir = "sdl/build_arm64"; context.CreateDirectory(buildDir); context.CreateDirectory($"{context.ArtifactsDir}/win-arm64"); - context.StartProcess("cmake", new ProcessSettings { WorkingDirectory = buildDir, Arguments = "-A ARM64 -D CMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded ../" }); - context.StartProcess("msbuild", new ProcessSettings { WorkingDirectory = buildDir, Arguments = "SDL2.sln /p:Configuration=Release" }); + context.StartProcess(cmake, new ProcessSettings { WorkingDirectory = buildDir, Arguments = "-A ARM64 -D CMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded ../" }); + context.StartProcess(msbuild, new ProcessSettings { WorkingDirectory = buildDir, Arguments = "SDL2.sln /p:Configuration=Release" }); // Copy artifact context.CreateDirectory(context.ArtifactsDir); context.CopyFile("sdl/build_arm64/Release/SDL2.dll", $"{context.ArtifactsDir}/win-arm64/SDL2.dll"); } + + private bool IsOnPATH(string process) + { + if (string.IsNullOrEmpty(process)) + return false; + + if (!process.EndsWith(".exe")) + process += ".exe"; + + // Check if process exist on PATH env + + var split = Environment.GetEnvironmentVariable("PATH")?.Split(';'); + if (split != null) + { + foreach (var path in split) + { + string processPath = System.IO.Path.Combine(path, process); + if (File.Exists(processPath)) + return true; + } + } + + return false; + } } diff --git a/sdl b/sdl index 98d1f3a..5d24957 160000 --- a/sdl +++ b/sdl @@ -1 +1 @@ -Subproject commit 98d1f3a45aae568ccd6ed5fec179330f47d4d356 +Subproject commit 5d249570393f7a37e037abf22cd6012a4cc56a71