Premake¶
Warning
This feature is experimental and subject to breaking changes. See the Conan stability section for more information.
The Premake build helper is a wrapper around the command line invocation of Premake. It will abstract the
project configuration and build command.
The helper is intended to be used in the conanfile.py build() method, to call Premake commands automatically
when a package is being built directly by Conan (create, install)
Usage Example:
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")
Reference¶
- class Premake(conanfile)¶
This class calls Premake commands when a package is being built. Notice that this one should be used together with the
PremakeToolchaingenerator.This premake generator is only compatible with
premake5.- Parameters:
conanfile –
< ConanFile object >The current recipe object. Always useself.
- luafile¶
Path to the root premake5 lua file (default is
premake5.lua)
- arguments¶
Key value pairs. Will translate to “–{key}={value}”
- configure()¶
Runs
premake5 <action> [FILE]which will generate respective build scripts depending on theaction.
- build(workspace, targets=None, configuration=None, msbuild_platform=None)¶
Depending on the action, this method will run either
msbuildormakewithN_JOBS. You can specifyN_JOBSthrough the configuration linetools.build:jobs=N_JOBSin your profile[conf]section.- Parameters:
workspace –
strSpecifies the solution to be compiled (only used byMSBuild).targets –
List[str]Declare the projects to be built (None to build all projects).configuration –
strSpecify the configuration build type, default to build_type (“Release” or “Debug”), but this allow setting custom configuration type.msbuild_platform –
strSpecify the platform for the internal MSBuild generator (only used byMSBuild).
conf¶
The Premake build helper is affected by these [conf] variables:
tools.build:verbositywhich accepts one ofquietorverboseand sets the--quietflag inPremake.configure()tools.compilation:verbositywhich accepts one ofquietorverboseand sets the--verboseflag inPremake.build()
Extra configuration¶
By default, typical Premake configurations are Release and Debug.
This configurations could vary depending on the used Premake script.
For example,
workspace "MyProject"
configurations { "Debug", "Release", "DebugDLL", "ReleaseDLL" }
If you wish to use a different configuration than Release or Debug, you can override the configuration from the Premake generator.
If the project also have dependencies, you will also need to override the
configuration property of the PremakeDeps generator accordingly, with the same value.
class MyRecipe(Conanfile):
...
def _premake_configuration(self):
return str(self.settings.build_type) + ("DLL" if self.options.shared else "")
def generate(self):
deps = PremakeDeps(self)
deps.configuration = self._premake_configuration
deps.generate()
tc = PremakeToolchain(self)
tc.generate()
def build(self):
premake = Premake(self)
premake.configure()
premake.build(workspace="MyProject", configuration=self._premake_configuration)