Premake

警告

此功能为实验性功能,可能会有破坏性变更。有关更多信息,请参阅Conan 稳定性章节。

Premake 构建助手是 Premake 命令行调用的包装器。它将抽象化项目配置命令。

此助手旨在用于 conanfile.pybuild() 方法中,以便在 Conan 直接构建包时(创建、安装)自动调用 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)
        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}"')