-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Factoring out the patches into a separate .lua file
- Loading branch information
Showing
2 changed files
with
116 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
--[[ | ||
This .lua file can be loaded via dofile() from premake4.lua in order to | ||
modify the behavior a bit. | ||
It does the following (in order of appearence below): | ||
- On older premake4 versions it will provide a premake.project.getbasename | ||
function, furthermore two other functions get patched to make use of it | ||
- premake.project.getbasename() gets overridden to insert a marker into the | ||
created file name, based on the chosen action | ||
Example: foobar.vcxproj becomes foobar.vs2022.vcxproj etc ... | ||
The purpose of this exercise is to allow for projects/solutions of several | ||
Visual Studio versions to reside in the same folder | ||
- Options "dotnet" gets removed | ||
- The "platform" option has some allowed values removed | ||
- The "os" option has some allowed values removed | ||
- The actions are trimmed to what we know can work | ||
Consult the premake4.lua in the same folder for more details. | ||
PS: There should be no adverse effects from commenting out the dofile() line | ||
in the main premake4.lua file. | ||
]] | ||
-- SPDX-License-Identifier: Unlicense | ||
|
||
do | ||
-- This is mainly to support older premake4 builds | ||
if not premake.project.getbasename then | ||
print "Magic happens ..." | ||
-- override the function to establish the behavior we'd get after patching Premake to have premake.project.getbasename | ||
premake.project.getbasename = function(prjname, pattern) | ||
return pattern:gsub("%%%%", prjname) | ||
end | ||
-- obviously we also need to overwrite the following to generate functioning VS solution files | ||
premake.vstudio.projectfile = function(prj) | ||
local pattern | ||
if prj.language == "C#" then | ||
pattern = "%%.csproj" | ||
else | ||
pattern = iif(action > "vs2008", "%%.vcxproj", "%%.vcproj") | ||
end | ||
|
||
local fname = premake.project.getbasename(prj.name, pattern) | ||
fname = path.join(prj.location, fname) | ||
return fname | ||
end | ||
-- we simply overwrite the original function on older Premake versions | ||
premake.project.getfilename = function(prj, pattern) | ||
local fname = premake.project.getbasename(prj.name, pattern) | ||
fname = path.join(prj.location, fname) | ||
return path.getrelative(os.getcwd(), fname) | ||
end | ||
end | ||
-- Name the project files after their VS version | ||
local orig_getbasename = premake.project.getbasename | ||
premake.project.getbasename = function(prjname, pattern) | ||
-- The below is used to insert the .vs(2003..2022) into the file names for projects and solutions | ||
if _ACTION and string.find(_ACTION, "vs") ~= nil then | ||
pattern = pattern:gsub("%%%%", "%%%%." .. _ACTION) | ||
end | ||
return orig_getbasename(prjname, pattern) | ||
end | ||
|
||
-- Remove an option altogether or some otherwise accepted values for that option | ||
local function remove_allowed_optionvalues(option, values_toremove) | ||
if premake.option.list[option] ~= nil then | ||
if values_toremove == nil then | ||
premake.option.list[option] = nil | ||
return | ||
end | ||
if premake.option.list.platform["allowed"] ~= nil then | ||
local allowed = premake.option.list[option].allowed | ||
for i = #allowed, 1, -1 do | ||
if values_toremove[allowed[i][1]] then | ||
table.remove(allowed, i) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
local function remove_action(action) | ||
if premake.action.list[action] ~= nil then | ||
premake.action.list[action] = nil | ||
end | ||
end | ||
|
||
-- Remove some unwanted/outdated options | ||
remove_allowed_optionvalues("dotnet") | ||
remove_allowed_optionvalues("platform", { universal = 0, universal32 = 0, universal64 = 0, ps3 = 0, xbox360 = 0, }) | ||
remove_allowed_optionvalues("os", { haiku = 0, solaris = 0, }) | ||
-- ... and actions (mainly because they are untested) | ||
for k,v in pairs({codeblocks = 0, codelite = 0, xcode3 = 0, xcode4 = 0, vs2002 = 0}) do | ||
remove_action(k) | ||
end | ||
end | ||
|
||
_G["transformMN"] = function (input) -- transform the macro names for older Visual Studio versions | ||
local new_map = { vs2002 = 0, vs2003 = 0, vs2005 = 0, vs2008 = 0 } | ||
local replacements = { Platform = "PlatformName", Configuration = "ConfigurationName" } | ||
if new_map[action] ~= nil then | ||
for k,v in pairs(replacements) do | ||
if input:find(k) then | ||
input = input:gsub(k, v) | ||
end | ||
end | ||
end | ||
return input | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters