Skip to content

configuration

starkos edited this page Feb 5, 2013 · 12 revisions

The configuration function limits the subsequent build settings to a particular environment.

#!lua
configuration { "keywords" }

The configuration function acts as a filter. Any settings that appear after this function in the script will be applied only to those contexts that match all of the listed keywords. See below for some usage examples.

Parameters

keywords is a list of identifiers (see below). When all of the keywords in this list match Premake's current context, the settings that follow the configuration statement will be applied. If any of the identifiers are not in the current context the settings will be ignored.

The available sources for keywords. Keywords are not case-sensitive.

  • Configuration names. Any of the configuration names supplied to the configurations or platforms functions.

  • Action names such as vs2010 or gmake. See the Quick Start for a complete list.

  • System names such as windows, macosx, or xbox360.

  • Architectures such as x32 or x64.

  • ** Toolsets** such as gcc.

  • Target kinds like ConsoleApp or SharedLib.

  • File names can be used to apply settings to a specific set of source code files; this feature is currently very limited.

In addition to the terms listed above, you may use the * and ** wildcards to match more than one term or file. You may also use the modifiers not and or to build more complex conditions. See the examples below for more information.

Examples

Define a new symbol which applies only to debug builds; assumes a configuration named "Debug" was defined as part of the solution.

#!lua
configuration "Debug"
  defines { "_DEBUG" }

Define a symbol only when targeting Visual Studio 2010.

#!lua
configuration "vs2010"
  defines { "VISUAL_STUDIO_2005" }

Wildcards can be used to match multiple terms. Define a symbol for all versions of Visual Studio.

#!lua
configuration "vs*"
  defines { "VISUAL_STUDIO" }

Add a suffix to the debug versions of libraries.

#!lua
configuration { "Debug", "SharedLib or StaticLib" }
  targetsuffix "_d"

-- ...or...
configuration { "Debug", "*Lib" }
  targetsuffix "_d"

Although support is currently quite limited, you may also apply settings to a particular file or set of files. This example sets the build action for all PNG image files.

#!lua
configuration "*.png"
  buildaction "Embed"

In the case of files you may also use the ** wildcard, which will recurse into subdirectories.

#!lua
configuration "**.png"
  buildaction "Embed"

If multiple keywords are specified, they will be treated as a logical AND. All terms must be present for the block to be applied. This example will apply the symbol only for debug builds on Mac OS X.

#!lua
configuration { "debug", "macosx" }
  defines { "DEBUG_MACOSX" }

Multiple terms must use Lua's curly bracket list syntax.

You can use the or modifier to match against multiple, specific terms.

#!lua
configuration "linux or macosx"
  defines { "LINUX_OR_MACOSX" }

You can also use not to apply the settings to all environments where the identifier is not set.

#!lua
configuration "not windows"
  defines { "NOT_WINDOWS" }

Finally, you can reset the configuration filter and remove all active keywords by passing the function an empty table.

#!lua
configuration {}
Clone this wiki locally