在 premake 中处理非源代码文件
handling non-sourcecode files in premake
我的项目是一个游戏,由几个源文件和几个资源组成,例如图像,地图,模型等。其中一些需要由程序处理,例如我想转换所有图片来自 png to dds。由于我的构建是源外构建,我希望将所有资源构建到构建文件夹中,以便在发布时只需要打包构建文件夹。
我该怎么做?
如果您使用的是 4.x 版本的 Premake,恐怕没有简单的解决方案。您可以嵌入数据(将它们复制到输出目录)
configuration "**.png"
buildaction "Copy"
如果你想构建它们,我会做的是复制它们,然后使用 "post-build" 命令来负责转换文件和清理。例如:
configuration ""
postbuildcommands { "premake --file=build_resources.lua build" }
当然,您在 build_resources.lua
中输入的内容由您决定,您甚至可以使用与创建项目相同的脚本。您只需要定义 build
操作及其作用(基本上解析输出文件夹,并将每个 png 编译为 dds,然后清理 png。
您可能还必须添加选项以指定构建脚本的平台/配置。
现在,如果您使用最新版本的 premake(可在此处找到:http://sourceforge.net/projects/premake/files/Premake/nightlies/),您可以更轻松地实现这一目标:
-- filter is the equivalent of 'configuration' in Premake 5.
-- configuration is still supported for backward compatibility, but it
-- will be removed eventually, so better start using 'filter' :)
filter "files:**.png"
-- this is simply a message shown in the Visual Studio output
buildmessage "converting %{file.relpath} to dds ..."
-- this is the actual custom compilation command
buildcommands {
"ddsconverter --input=%{file.abspath} --output=%{cfg.linktarget.directory}"
}
有关详细信息,请参阅此处:
https://bitbucket.org/premake/premake-dev/wiki/buildcommands
以及有关令牌的信息(%{xxx}
允许您使用已知的预制路径而无需编写它们的东西):
https://bitbucket.org/premake/premake-dev/wiki/Tokens
我的项目是一个游戏,由几个源文件和几个资源组成,例如图像,地图,模型等。其中一些需要由程序处理,例如我想转换所有图片来自 png to dds。由于我的构建是源外构建,我希望将所有资源构建到构建文件夹中,以便在发布时只需要打包构建文件夹。
我该怎么做?
如果您使用的是 4.x 版本的 Premake,恐怕没有简单的解决方案。您可以嵌入数据(将它们复制到输出目录)
configuration "**.png"
buildaction "Copy"
如果你想构建它们,我会做的是复制它们,然后使用 "post-build" 命令来负责转换文件和清理。例如:
configuration ""
postbuildcommands { "premake --file=build_resources.lua build" }
当然,您在 build_resources.lua
中输入的内容由您决定,您甚至可以使用与创建项目相同的脚本。您只需要定义 build
操作及其作用(基本上解析输出文件夹,并将每个 png 编译为 dds,然后清理 png。
您可能还必须添加选项以指定构建脚本的平台/配置。
现在,如果您使用最新版本的 premake(可在此处找到:http://sourceforge.net/projects/premake/files/Premake/nightlies/),您可以更轻松地实现这一目标:
-- filter is the equivalent of 'configuration' in Premake 5.
-- configuration is still supported for backward compatibility, but it
-- will be removed eventually, so better start using 'filter' :)
filter "files:**.png"
-- this is simply a message shown in the Visual Studio output
buildmessage "converting %{file.relpath} to dds ..."
-- this is the actual custom compilation command
buildcommands {
"ddsconverter --input=%{file.abspath} --output=%{cfg.linktarget.directory}"
}
有关详细信息,请参阅此处: https://bitbucket.org/premake/premake-dev/wiki/buildcommands
以及有关令牌的信息(%{xxx}
允许您使用已知的预制路径而无需编写它们的东西):
https://bitbucket.org/premake/premake-dev/wiki/Tokens