1、简介
Premake是一个命令行实用程序,它读取软件项目的脚本定义,最常见的是使用它为Visual Studio,Xcode或GNU Make等工具集生成项目文件。
2、使用
2.1 支持的工程文件Project Files
Action | Description |
---|---|
vs2022 | Generate Visual Studio 2022 project files |
vs2019 | Generate Visual Studio 2019 project files |
vs2017 | Generate Visual Studio 2017 project files |
vs2015 | Generate Visual Studio 2015 project files |
vs2013 | Generate Visual Studio 2013 project files |
vs2012 | Generate Visual Studio 2012 project files |
vs2010 | Generate Visual Studio 2010 project files |
vs2008 | Generate Visual Studio 2008 project files |
vs2005 | Generate Visual Studio 2005 project files |
gmake | Generate GNU Makefiles (This generator is deprecated by gmake2) |
gmake2 | Generate GNU Makefiles (including Cygwin and MinGW) |
xcode4 | XCode projects |
codelite | CodeLite projects |
若要生成 Visual Studio 2013 项目文件,请使用以下命令:
premake5 vs2013
2.2 构建设置Build Settings
设置名称 | 设置标志 |
---|---|
指定二进制类型(可执行文件、库) | kind |
指定源代码文件 | files, removefiles |
定义编译器或预处理器符号 | defines |
找到包含文件 | includedirs |
设置预编译标头 | pchheader, pchsource |
链接库、框架或其他项目 | links, libdirs |
启用调试信息 | symbols |
针对尺寸或速度进行优化 | optimize |
添加任意构建标志 | buildoptions, linkoptions |
设置已编译目标的名称或位置 | targetname, targetdir |
defines { "DEBUG", "TRACE" }
defines { "CALLSPEC=__dllexport" }
includedirs { "../lua/include", "../zlib" }
includedirs { "../includes/**" }
pchheader "myproject.h"
optimize "Speed"
filter { "system:linux", "action:gmake" }
buildoptions { "`wx-config --cxxflags`", "-ansi", "-pedantic" }
targetname "mytarget"
2.3 链接Linking
(1)链接到外部库是通过links 功能完成的。
links { "png", "zlib" }
(2)links 指令的位置在project 下面设置。
workspace "MyWorkspace"
project "MyLibraryProject"
-- ...project settings here...
project "MyExecutableProject"
-- ...project settings here...
links { "MyLibraryProject" }
(3)而查找库,则使用如下指令。
libdirs { "libs", "../mylibs" }
# or
libdirs { os.findlib("X11") }
2.4 配置Configurations
配置是要应用于构建的设置集合,包括标志和开关、头文件和库搜索目录等。每个工作区定义自己的配置名称列表;大多数 IDE 提供的默认值是“调试”和“发布”。
workspace "MyWorkspace"
configurations { "Debug", "Release" }
workspace "MyWorkspace"
configurations { "Debug", "DebugDLL", "Release", "ReleaseDLL" }
workspace "MyWorkspace"
configurations { "Froobniz", "Fozbat", "Cthulhu" }
workspace "HelloWorld"
configurations { "Debug", "Release" }
filter "configurations:Debug"
defines { "DEBUG" }
flags { "Symbols" }
filter "configurations:Release"
defines { "NDEBUG" }
optimize "On"
2.5 平台Platforms
“平台”在这里有点用词不当;我再次遵循Visual Studio命名法。实际上,平台只是另一组构建配置名称,提供了另一个方向用于配置项目。
configurations { "Debug", "Release" }
platforms { "Win32", "Win64", "Xbox360" }
configurations { "Debug", "Release" }
platforms { "Win32", "Win64", "Xbox360" }
filter { "platforms:Win32" }
system "Windows"
architecture "x86"
filter { "platforms:Win64" }
system "Windows"
architecture "x86_64"
filter { "platforms:Xbox360" }
system "Xbox360"
configurations { "Debug", "Release" }
platforms { "Static", "DLL" }
filter { "platforms:Static" }
kind "StaticLib"
filter { "platforms:DLL" }
kind "SharedLib"
defines { "DLL_EXPORTS" }
2.6 过滤Filters
project "MyProject"
filter { "configurations:Debug" }
targetdir "bin/debug"
filter { "configurations:Release" }
targetdir "bin/release"
2.7 预设值Tokens
wks.name
wks.location -- (location where the workspace/solution is written, not the premake-wks.lua file)
prj.name
prj.location -- (location where the project is written, not the premake-prj.lua file)
prj.language
prj.group
cfg.longname
cfg.shortname
cfg.kind
cfg.architecture
cfg.platform
cfg.system
cfg.buildcfg
cfg.buildtarget -- (see [target], below)
cfg.linktarget -- (see [target], below)
cfg.objdir
file.path
file.abspath
file.relpath
file.directory
file.reldirectory
file.name
file.basename -- (file part without extension)
file.extension -- (including '.'; eg ".cpp")
-- These values are available on build and link targets
-- Replace [target] with one of "cfg.buildtarget" or "cfg.linktarget"
-- Eg: %{cfg.buildtarget.abspath}
[target].abspath
[target].relpath
[target].directory
[target].name
[target].basename -- (file part without extension)
[target].extension -- (including '.'; eg ".cpp")
[target].bundlename
[target].bundlepath
[target].prefix
[target].suffix
结语
如果您觉得该方法或代码有一点点用处,可以给作者点个赞,或打赏杯咖啡;
╮( ̄▽ ̄)╭
如果您感觉方法或代码不咋地
//(ㄒoㄒ)//,就在评论处留言,作者继续改进;
o_O???
如果您需要相关功能的代码定制化开发,可以留言私信作者;
(✿◡‿◡)
感谢各位大佬童鞋们的支持!
( ´ ▽´ )ノ ( ´ ▽´)っ!!!