premake / premake-core

Premake
https://premake.github.io/
BSD 3-Clause "New" or "Revised" License
3.22k stars 620 forks source link

Supporting Win32 and WinRT platforms for the same project #1653

Open GCourtney27 opened 3 years ago

GCourtney27 commented 3 years ago

I'm using the WinRT platform module found here to support both Win32 and Universal Windows for the same project. To choose between them I filter through them like

filter "platforms:Win64" system "Windows"

and

filter "platforms:XboxOne" system "WindowsUniversal"

The problem is when I run the premake script the platform is permanently set to Universal Windows in Visual Studio until I comment out the filter "platforms:XboxOne" filter. So my question is: Is this a bug in premake or the module? Or is it not possible to switch between these two platforms in Visual Studio? It would be great to be able to simply switch the platforms in the VS editor to compile for the two different platforms instead of possibly having to comment out code or run premake again. If it's not possible, does anyone have any suggestions for handling multiple platforms like this in premake?

Platform: Windows 10 Premake version: 5.0.0-alpha16-windows Visual Studio version: 2019

samsinsane commented 3 years ago

It's been quite a while since I last used the WinRT module. From memory, it's a project level setting not a configuration level setting, so from the VS UI this isn't possible. Rerunning Premake is an option, but you can also generate the project(s) multiple times, it's a bit cumbersome to do testing but if your goal is to just build every combination in a single solution, that is entirely possible.

I used something like this for one of my projects that used the WinRT module:

workspace "wks"
  configurations { "Debug", "Release" }
  platforms { "All" }

  group "Windows"
    projectsuffix = "_Windows"
    dofile "project.lua"
      configmap { All = "x64" }
      system "windows"
  group "XboxOne"
    projectsuffix = "_XboxOne"
    dofile "project.lua"
      configmap { All = "XboxOne" }
      system "WindowsUniversal"

The project.lua file would look like:

project ("ProjectName" .. (projectsuffix or ""))
  -- All the normal settings
  -- objdir, targetdir and debgudir should all be set to unique locations for each system and platforms combination.
  -- links and dependson for other projects need to factor in the projectsuffix too

From memory the project I had was using this for about 10 different system and platform combinations, as convenient as it was to build them all at once it was pretty cumbersome for active development. All I had to do was change the startup project when I wanted to test a different system/platform.

Alternatively, if you're happy to swap between both platforms and change your startup project, you can specify the proper platforms and then for the Windows projects removeplatforms { "XboxOne" } and for the Xbox One projects removeplatforms { "x64" } instead of the configmap lines.