在预制

时间:2015-05-07 22:11:06

标签: premake

我在Visual Studio 2013中使用premake5并尝试将第三方库链接到我的项目。该库的调试版本具有通常的“d”后缀。这是示例脚本。

solution "MySln"
    language "C++"
    configurations { "debug", "release" }

    d = ""

    configuration "debug"
        d = "d"

    configuration "release"
        d = ""

    libicu = { "icuin%{d}", "icuuc%{d}" }

project "core"
    kind "SharedLib"
    location "core"
    links(libicu)
    files { "core/**.h", "core/**.cpp" }

但是这个脚本链接了两个配置(调试和发布)icuin.lib和icuuc.lib。如果我删除配置“发布”块中的 d =“”分配,则两个配置都会链接icuind.lib和icuucd.lib库。看起来premake在解析%{d}占位符时使用了最新的变量定义。如何更改脚本以获取正确的行为?谢谢!

1 个答案:

答案 0 :(得分:0)

您不能混合变量赋值(在脚本评估时评估)和Premake配置(在所有项目脚本运行后汇编)。

一种解决方案可能是:

solution "MySln"
   language "C++"
   configurations { "debug", "release" }

   filter "configurations:debug"
      targetextension "d"

project "core"
   kind "SharedLib"
   location "core"
   files { "core/**.h", "core/**.cpp" }

   filter "configurations:debug"
      links { "icuind", "icuucd" }
   filter "configurations:release"
      links { "icuin", "icuuc" }

如果您有很多库或经常这样做,您可以使用它的功能:

project "core"
   links_d { "icuin", "icuuc" }

function links_d(value)
   filter("configurations:debug")
   for i = 1, #value do
       links (value[i] .. "d")
   end
   filter("configurations:release")
   links (value)
   filter("*")
end