Premake指令将静态库嵌入到静态库中

时间:2015-09-03 17:56:18

标签: visual-studio-2013 premake

首先,我使用了premake5和VisualStudio 2013.请不要跳过那个(因为premake5仍然是alpha)。我已经搜索过,无法找到答案,而不是真正有效的答案。

我需要使用premake将静态库嵌入到自定义静态库中。我在更新库后转换了一些旧代码,只想将自定义库与应用程序链接起来。我不想将自定义库和它处理的所有其他库链接到应用程序配置。使用premake5的其他任何东西都在游泳。

我可以使用link指令将其链接到应用程序,例如:     链接{" SDL2"," SDL2main"," SDL2_image" }

这适用于正常包含静态库但我需要一种方法来嵌入这些示例库到自定义静态库中。

我可以将premake创建的结果项目文件带到visual studio中,并手动修改项目以按照我需要的方式添加库,但我不想每次需要重新生成时都这样做该项目。

我需要的结果是premake在项目xml文件中生成以下XML的方法:

    <ItemGroup>
    <Library Include="..\deps\SDL2\lib\x86\SDL2.lib">
      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Win64|x64'">true</ExcludedFromBuild>
    </Library>
    <Library Include="..\deps\SDL2\lib\x86\SDL2main.lib">
        <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Win64|x64'">true</ExcludedFromBuild>
    </Library>
    <Library Include="..\deps\SDL2_image\lib\x86\SDL2_image.lib" />
        <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Win64|x64'">true</ExcludedFromBuild>
    </Library>
  </ItemGroup>

这是在visual studio中手动编辑项目的结果。我在x64版本中添加了库的排除,因为最终我还必须使用这些库的x64版本。如果我严重忽视某些事情会很好,但我需要能够让它发挥作用。

我在这里忽略了一些非常简单的事情吗?

1 个答案:

答案 0 :(得分:0)

Premake不支持将静态库链接到开箱即用,因为该行为不可移植到其他工具集。但是,您可以在项目脚本中安装一个小扩展,以使其工作:

---
-- Allow static library projects to link in their dependencies. Visual Studio
-- doesn't support this out of the box, so I need to manually add items to
-- the list of additional dependencies.
---

local p = premake

function myAdditionalStaticDependencies(cfg)
    local links = p.config.getlinks(cfg, "siblings", "fullpath")
    if #links > 0 then
        links = path.translate(table.concat(links, ";"))
        p.x('<AdditionalDependencies>%s;%%(AdditionalDependencies)</AdditionalDependencies>', links)
    end
end

p.override(p.vstudio.vc2010.elements, "lib", function(base, cfg, explicit)
    local calls = base(cfg, explicit)
    if cfg.kind == p.STATICLIB then
        table.insert(calls, myAdditionalStaticDependencies)
    end
    return calls
end)