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.

Tokens
79.5K
Snippets
538
Records
718
Agent score
75%

What's inside Premake

  1. Overview of Premake Actions and Custom Action Creation

    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.
  2. 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.
  3. 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"
  4. Configure the preferred Visual Studio toolchain architecture

    Use the preferredtoolarchitecture setting 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"
  5. Identify the host operating system architecture using os.hostarch()

    Use os.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 the architecture() documentation.
    if os.hostarch() == "x86_64" then
       -- do something x64-specific
    end
  6. Planned 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.
  7. 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.
  8. Premake 5 new and modified API calls

    Premake 5 introduces a wide array of new API calls for project configuration, including architecture, buildcommands, builddependencies, clr, dotnetframework, externalproject, nuget, and workspace. Additionally, the solution call has been renamed to workspace.
  9. Specify supported ISA extensions using isaextensions

    The isaextensions configuration 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"
    }
  10. Supported values for the architecture parameter

    The architecture parameter accepts the following values:

    ValueDescription
    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$ AARCH64
    • amd64 $\rightarrow$ x86_64
    • i386 $\rightarrow$ x86
    • x32 $\rightarrow$ x86
    • x64 $\rightarrow$ x86_64
  11. 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 nil for backwards compatibility unless a target architecture has been explicitly specified. The target architecture is determined by the following priority (highest to lowest):

    1. The --arch command line option.
    2. The _TARGET_ARCH global variable.

    Available in Premake 5.0.0 beta 3 or later.

    -- Example: Print the target architecture
    print(os.targetarch())
    -- Output: "x86_64"
  12. 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 --arch command-line flag.
    # Override the target architecture to x86 when generating a gmake file
    premake5 --arch=x86 gmake