Premake¶
警告
此功能为实验性功能,可能会有破坏性变更。有关更多信息,请参阅 Conan 稳定性 章节。
Premake
构建助手是 Premake 命令行调用的封装。它将抽象化项目配置命令。
该助手旨在用于 conanfile.py 的 build()
方法中,以便在 Conan 直接构建包时(create, install)自动调用 Premake 命令
使用示例
from conan.tools.premake import Premake
from conan.tools.microsoft import MSBuild
class Pkg(ConanFile):
settings = "os", "compiler", "build_type", "arch"
# The VCVars generator might be needed in Windows-MSVC
generators = "VCVars"
def build(self):
p = Premake(self)
# Set the main Lua configuration file (default: premake5.lua)
p.luafile = "myproject.lua"
# Pass custom arguments to Premake (translates to --{key}={value})
p.arguments["myarg"] = "myvalue"
# Automatically determines the correct action:
# - For MSVC, selects vs<version> based on the compiler version
# - Defaults to "gmake2" for other compilers
# p.configure() will run: premake5 --file=myproject.lua <action> --{key}={value} ...
p.configure()
# At the moment Premake does not contain .build() method
# report in Github issues your use cases and feedback to request it
build_type = str(self.settings.build_type)
if self.settings.os == "Windows":
msbuild = MSBuild(self)
msbuild.build("HelloWorld.sln")
else:
self.run(f"make config={build_type.lower()}_x86_64")
p = os.path.join(self.build_folder, "bin", build_type, "HelloWorld")
self.run(f'"{p}"')