Premake Documentation
website·Indexed 29 days ago
https://premake.github.io/Documentation for Premake, featuring API references for the os, path, and table modules, as well as project configuration options such as optimize, pic, openmp, and precompiled headers. Covers version 5.0 and later.
What's inside Premake
- In Premake, 'actions' are components that process project script information to perform a specific task. Standard exporters (such as Visual Studio and Makefile) are examples of actions that output project files for specific toolsets. Premake allows developers to create custom actions for various purposes, ranging from simple one-time operations (like preparing a source code working copy) to complex support for entirely new toolsets.
Overview of Premake build configuration
Premake is a build configuration tool that allows developers to describe a software project once using a simple, Lua-based syntax. It then generates native project files for multiple IDEs and build systems across different operating systems, including Windows, Mac OS X, and Linux. Supported targets include Visual Studio, GNU Make, Xcode, and CodeLite.Overview of Premake project generation
Premake is a command-line utility that reads a scripted definition of a software project (written in Lua) and generates project files for various toolsets. This allows developers to maintain a single project definition and generate compatible files for different platforms and IDEs on demand, ensuring builds remain in sync across different environments.workspace "MyWorkspace" configurations { "Debug", "Release" } project "MyProject" kind "ConsoleApp" language "C++" files { "**.h", "**.cpp" } filter { "configurations:Debug" } defines { "DEBUG" } symbols "On" filter { "configurations:Release" } defines { "NDEBUG" } optimize "On"Configure the preferred Visual Studio toolchain architecture
Use the
preferredtoolarchitecturesetting in your workspace configuration to specify which architecture the Visual Studio toolchain should use. This is available for Visual Studio projects using Premake 5.0.0-alpha12 or later.Available values:
Default: Uses the preferred tool architecture.x86: Forces the use of x86 tooling.x86_64: Forces the use of x86_64 tooling.
preferredtoolarchitecture "x86_64"Identify the host operating system architecture using os.hostarch()
Useos.hostarch()to retrieve the architecture identifier of the currently executing operating system. This function takes no parameters and returns a string identifier. For a complete list of possible architecture identifiers, refer to thearchitecture()documentation.if os.hostarch() == "x86_64" then -- do something x64-specific endPlanned improvements for Premake 5.0 extensions and toolsets
The Premake team is reviewing the mechanisms used to extend toolsets and exporters to reduce the complexity of extending core functionality. Users should be aware that this may result in breaking changes for external modules using existing extension mechanisms. Documentation and a transition period will be provided as these changes occur.Use Premake system scripts for global project support
Premake system scripts are executed immediately after startup, before any actions, arguments, or project scripts are processed. They are primarily used to load modules and support code that should be available to all Premake-enabled projects. System scripts can contain any valid Premake code, including workspace and project configurations.Premake 5 new and modified API calls
Premake 5 introduces a wide array of new API calls for project configuration, includingarchitecture,buildcommands,builddependencies,clr,dotnetframework,externalproject,nuget, andworkspace. Additionally, thesolutioncall has been renamed toworkspace.Specify supported ISA extensions using isaextensions
Theisaextensionsconfiguration option allows you to specify a list of supported instruction set architecture (ISA) extensions for a project. This is available in Premake 5.0.0-alpha14 or later and applies to project configurations.isaextensions { "POPCNT", "BMI2" }Supported values for the architecture parameter
The
architectureparameter accepts the following values:Value Description universalUniversal binaries supported by iOS and macOS x86x86 Architecture x86_64x86_64 Architecture ARM32-bit ARM Architecture AARCH6464-bit ARM Architecture RISCV6464-bit RISCV Architecture loongarch6464-bit LoongArch Architecture ppc32-bit PowerPC Architecture ppc6464-bit PowerPC Architecture wasm3232-bit WASM Architecture wasm6464-bit WASM Architecture e2kElbrus-2000 Architecture mips64el64-bit MIPS (Little Endian) Architecture Aliases:
ARM64$\rightarrow$AARCH64amd64$\rightarrow$x86_64i386$\rightarrow$x86x32$\rightarrow$x86x64$\rightarrow$x86_64
Get the target architecture using os.targetarch()
The
os.targetarch()function returns the identifier of the architecture for the OS that Premake is generating files for. This may differ from the architecture of the system currently running Premake.By default, this function returns
nilfor backwards compatibility unless a target architecture has been explicitly specified. The target architecture is determined by the following priority (highest to lowest):- The
--archcommand line option. - The
_TARGET_ARCHglobal variable.
Available in Premake 5.0.0 beta 3 or later.
-- Example: Print the target architecture print(os.targetarch()) -- Output: "x86_64"- The
Use _TARGET_ARCH to identify the target architecture
_TARGET_ARCH is a global variable that stores the name of the architecture currently being targeted. To see a complete list of supported architecture identifiers, refer to the architecture() function. The target architecture can be overridden at runtime using the--archcommand-line flag.# Override the target architecture to x86 when generating a gmake file premake5 --arch=x86 gmake