Premake

警告

此功能是实验性的,可能会发生重大更改。有关更多信息,请参阅 Conan 稳定性 部分。

`Premake` 构建助手是 Premake 命令行调用的一个封装。它将抽象项目配置和构建命令。

此助手旨在用于 *conanfile.py* 的 `build()` 方法中,以便当 Conan 直接构建(创建、安装)包时自动调用 Premake 命令。

使用示例

from conan.tools.premake import Premake

class Pkg(ConanFile):
    settings = "os", "compiler", "build_type", "arch"

    # The PremakeToolchain generator is always needed to use premake helper
    generators = "PremakeToolchain"

    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 "gmake" for other compilers
        # p.configure() will run: premake5 --file=myproject.lua <action> --{key}={value} ...
        p.configure()
        # p.build() will invoke proper compiler depending on action (automatically detected by profile)
        p.build("HelloWorld.sln")

参考

class Premake(conanfile)

此类别在构建包时调用 Premake 命令。请注意,此类别应与 `PremakeToolchain` 生成器一起使用。

此 Premake 生成器仅与 `premake5` 兼容。

参数:

conanfile – `< ConanFile object >` 当前的配方对象。始终使用 `self`。

luafile

根 premake5 lua 文件的路径(默认为 `premake5.lua`)

arguments

键值对。将转换为“–{key}={value}”

configure()

运行 `premake5 <action> [FILE]`,这将根据 `action` 生成相应的构建脚本。

build(workspace, targets=None, msbuild_platform=None)

根据操作,此方法将使用 `N_JOBS` 运行 `msbuild` 或 `make`。您可以通过配置文件 `[conf]` 部分中的配置行 `tools.build:jobs=N_JOBS` 来指定 `N_JOBS`。

参数:
  • workspace – `str` 指定要编译的解决方案(仅由 `MSBuild` 使用)。

  • targets – `List[str]` 声明要构建的项目(None 表示构建所有项目)。

  • msbuild_platform – `str` 为内部 MSBuild 生成器指定平台(仅由 `MSBuild` 使用)。

conf

`Premake` 构建助手受以下 `[conf]` 变量影响

  • `tools.build:verbosity` 接受 `quiet` 或 `verbose` 之一,并在 `Premake.configure()` 中设置 `--quiet` 标志。

  • `tools.compilation:verbosity` 接受 `quiet` 或 `verbose` 之一,并在 `Premake.build()` 中设置 `--verbose` 标志。