我想将两个条件属性添加到我的项目配置中,以非默认的vcpkg三元组为目标:https://github.com/microsoft/vcpkg/blob/master/docs/users/integration.md#with-msbuild
我的项目文件是由premake生成的。我将如何处理?
最佳答案
您可以尝试从Visual Studio生成器中覆盖全局功能,例如:...未经测试...
local vs2010 = premake.vstudio.vs2010
function vcPkgOverride(prj)
-- go trough the configs and platforms and figure out which conditions to put
for _, cfg in pairs(prj.cfgs) do
local condition = vs2010.condition(cfg)
if cfg.platform == "Win32" then
vs2010.vc2010.element("VcpkgTriplet ", condition, "x86-windows-static")
else if cfg.platform == "x64" then
vs2010.vc2010.element("VcpkgTriplet ", condition, "x64-windows-static")
end
end
end
premake.override(vc2010.elements, "globals", function (oldfn, prj)
local elements = oldfn(prj)
elements = table.join(elements, {
vcPkgOverride
})
end
return elements
end)
更新
上面的代码似乎不适用于premake5.0.0-alpha14,因此我根据the docs对其进行了调整,在这里您有一个不太通用但可以使用的版本:
require('vstudio')
local vs = premake.vstudio.vc2010
local function premakeVersionComment(prj)
premake.w('<!-- Generated by Premake ' .. _PREMAKE_VERSION .. ' -->')
end
local function vcpkg(prj)
premake.w('<VcpkgTriplet>x64-windows-static</VcpkgTriplet>')
premake.w('<VcpkgEnabled>true</VcpkgEnabled>')
end
premake.override(premake.vstudio.vc2010.elements, "project", function(base, prj)
local calls = base(prj)
table.insertafter(calls, vs.xmlDeclaration, premakeVersionComment)
return calls
end)
premake.override(premake.vstudio.vc2010.elements, "globals", function(base, prj)
local calls = base(prj)
table.insertafter(calls, vs.globals, vcpkg)
return calls
end)
在主要premake5.lua脚本的开头添加此代码,或者找到从其他位置包含它的方法(我对lua或premake不太了解,我只需要修复此问题并想向社区展示)