57 KiB
Scripting Reference
Table of Contents
- Predefined Variables
- Script Functions
- buildaction
- buildoptions
- configuration
- configurations
- custombuildtask
- debugargs
- debugdir
- defines
- dependency
- deploymentoptions
- excludes
- files
- flags
- framework
- iif
- imageoptions
- imagepath
- implibdir
- implibextension
- implibname
- implibprefix
- implibsuffix
- include
- includedirs
- kind
- language
- libdirs
- linkoptions
- links
- location
- newaction
- newoption
- objdir
- os.chdir
- os.copyfile
- os.findlib
- os.get
- os.getcwd
- os.getversion
- os.is
- os.is64bit
- os.isdir
- os.isfile
- os.matchdirs
- os.matchfiles
- os.mkdir
- os.outputof
- os.pathsearch
- os.rmdir
- os.stat
- os.uuid
- path.getabsolute
- path.getbasename
- path.getdirectory
- path.getdrive
- path.getextension
- path.getname
- path.getrelative
- path.isabsolute
- path.iscfile
- path.iscppfile
- path.isresourcefile
- path.join
- path.rebase
- path.translate
- pchheader
- pchsource
- platforms
- postbuildcommands
- postcompiletasks
- prebuildcommands
- prelinkcommands
- printf
- project
- resdefines
- resincludedirs
- resoptions
- solution
- string.endswith
- string.explode
- string.findlast
- string.startswith
- table.contains
- table.implode
- targetdir
- targetextension
- targetname
- targetprefix
- targetsuffix
- uuid
- vpaths
- Additional Information
Predefined Variables
Each of the following variables is available for use in any GENie script.
_ACTION
Name of the action to be performed on this execution run.
$ genie vs2005
produces
_ACTION: "vs2005"
_ARGS
Any arguments to the current action.
$ genie vs2015 alpha beta
produces
_ARGS[0]: "alpha"
_ARGS[1]: "beta"
_OPTIONS
Current set of command line options and their values, if any.
$ genie vs2015 --gfxapi=directx
produces
_OPTIONS['gfxapi']: "directx"
Note: Options may be registered with newoption to fully integrate them into the CLI.
_PREMAKE_COMMAND
Full path to the GENie (Premake) executable.
_PREMAKE_VERSION
GENie (Premake) version.
_SCRIPT
Full path to the currently executing script.
_WORKING_DIR
Current working directory.
Script Functions
buildaction(action)
Specifies what action should be performed on a set of files during compilation. Usually paired with a configuration filter to select a file set. If no build action is specified for a file, a default action will be used (chosen based on the file's extension).
Scope: solutions, projects, configurations
Note: only supported for .NET projects, and not for C or C++.
Arguments
action - the action to be performed. One of:
- "Compile" - treat the file as source code: compile and run it
- "Embed" - embed the file into the target binary as a resource
- "Copy" - copy the file to the target directory
- "None" - do nothing with this file
Examples
Embed all PNGs into the target binary
configuration "**.png"
buildaction "Embed"
buildoptions({options...})
Passes arguments direction to the compiler command line. Multiple calls in a project will be concatenated in order.
Scope: solutions, projects, configurations
Arguments
options - list of compiler flags
Examples
Add some GCC-specific options
configuration {"linux", "gmake"}
buildoptions {"-ansi", "-pedantic"}
configuration({keywords...})
Limits subsequent build settings to a particular environment. Acts as a filter, only applying settings that appear after this function if the environment matches the keywords.
Arguments
keywords - list of identifiers to compare to the current runtime environment
Possible values:
- Configuration names - configuration names passed to configurations
- Action names - "vs2015", "gmake", etc.
- Operating system names - "windows", "macosx", etc.
- Platform names - "ps3", "xbox360", etc.
- Command-line options - either built-in or custom
- File names - very limited, but some settings can be applied to specific files
You may also use "*" and "**" wildcards, as well as "not" and "or".
Return
Current configuration object with the following fields:
- buildaction - build action.
- buildoptions - list of compiler options.
- defines - list of compiler symbols.
- excludes - list of excluded files.
- files - list of files.
- flags - list of build flags.
- implibdir - import library directory.
- implibextension - import library file extension.
- implibname - import library base file name.
- implibprefix - import library file name prefix.
- implibsuffix - import library file name suffix.
- includedirs - list of include file search directories.
- keywords - list of keywords associated with the block.
- kind - target kind.
- libdirs - list of library search directories.
- linkoptions - list of linker options.
- links - list of libraries or assemblies to link against.
- objdir - objects and intermediate files directory.
- pchheader - target file name for precompiled header support.
- pchsource - target source file name for precompiled header support.
- prebuildcommands - list of pre-build commands.
- prelinkcommands - list of pre-link commands.
- postbuildcommands - list of post-build commands.
- resdefines - list of symbols for the resource compiler.
- resincludedirs - list of include file search paths for the resource compiler.
- resoptions - list of resource compiler options.
- targetdir - target output directory.
- targetextension - target file extension.
- targetname - target base file name.
- targetprefix - target file name prefix.
- targetsuffix - target file name suffix.
- terms - filter terms passed to the configuration function to create the block (i.e. "Debug").
Examples
Define debug symbol for debug configurations
configuration "Debug"
defines { "DEBUG" }
Define a symbol based on a wildcard
configuration "vs*"
defines { "VISUAL_STUDIO_2005" }
Define a symbol based on an "or"
configuration "linux or macosx"
defines { "LINUX_OR_MACOSX" }
Define a symbol based on a "not"
configuration "not windows"
defines { "NOT_WINDOWS" }
Reset the configuration filter
configuration {}
configurations({names...})
Defines a set of build configurations, such as "Debug" and "Release". Must be specified before any projects are defined, so can't be called after a project has been defined.
Scope: solutions
Arguments
names - list of configuration names
Return Value
When called with no arguments - list of current configuration names
Examples
Specify configurations for a solution
solution "MySolution"
configurations { "Debug", "Release" }
Add additional configurations
configurations{ "Debug", "Release", "DebugDLL", "ReleaseDLL" }
Retrieve current list of configurations
local cfgs = configurations()
custombuildtask({input_file, output_file, {dependency,...},{command,...}},...)
Defines custom build task for specific input file, that generates output file, there can be additional dependencies, and for rule listed commands are executed.
Scope: solutions, projects, configurations
Arguments
input_file - source file that should be "compiled" with custom task output_file - generated file name dependency - additional dependencies, that can be used as parameters to commands command - command list, special functions in commands are : $(<) - input file $(@) - output file $(1) - $(9) - additional dependencies
Examples
custombuildtask {
{ ROOT_DIR .. "version.txt" , GEN_DIR .. "src/version.inc", { ROOT_DIR .. "version.py" }, {"@echo Generating version.inc file...", "python $(1) $(<) > $(@)" }},
}
debugargs({args...})
Specifies a list of arguments to pas to the application when run under the debugger.
Note: Not implemented for Xcode 3, where it must be configured in a per-user config file.
Note: In Visual Studio, this can be overridden by a per-user config file (e.g. ProjectName.vcxproj.MYDOMAIN-MYUSERNAME.user). Removing this file (genie clean
) will restore the default settings.
Scope: solutions, projects, configurations
Arguments
args - list of arguments to pas to the executable while debugging
Examples
configuration "Debug"
debugargs { "--append", "somefile.txt" }
debugdir(path)
Sets the working directory for the integrated debugger.
Note: Not implemented for Xcode 3, where it must be configured in a per-user config file.
Note: In Visual Studio, this can be overridden by a per-user config file (e.g. ProjectName.vcxproj.MYDOMAIN-MYUSERNAME.user). Removing this file (genie clean
) will restore the default settings.
Scope: solutions, projects, configurations
Arguments
path - path to the working directory, relative to the currently-executing script file
Examples
configuration "Debug"
debugdir "bin/debug"
defines({symbols...})
Adds preprocessor or compiler symbols to the project. Multiple calls are concatenated.
Scope: solutions, projects, configurations
Arguments
symbols - list of symbols
Examples
Define two new symbols
defines { "DEBUG", "TRACE" }
Assign a symbol value
defines { "CALLSPEC=__dllexport" }
dependency({_main_file, depending_of}...)
GMAKE specific adds dependency between source file and any other file.
Scope: solutions, projects, configurations
Arguments
_main_file - name of source file that depends of other file depending_of - name of dependency file
Examples
dependency { { ROOT_DIR .. "src/test.c", ROOT_DIR .. "verion.txt" } }
deploymentoptions({options...})
Passes arguments directly to the deployment tool command line. Multiple calls are concatenated.
Note: Currently only supported for Xbox 360 targets.
Scope: solutions, projects, configurations
Arguments
options - list of arguments
excludes({files...})
Removes files added with the files
function. Multiple calls are concatenated.
Note: May be set on the solution, project, or configuration, but only project-level file lists are currently supported.
Scope: solutions, projects, configurations
Arguments
files - List of files to exclude. Paths should be relative to the currently-executing script file and may contain wildcards.
Examples
Add all c files in a directory, then exclude a specific file
files { "*.c" }
excludes { "a_file.c" }
Add an entire directory of C files, then exclude one directory
files { "*.c" }
excludes { "tests/*.c" }
files({files...})
Adds files to a project. Multiple calls are concatenated.
Note: May be set on the solution, project, or configuration, but only project-level file lists are currently supported.
Scope: solutions, projects, configurations
Arguments
files - List of files to include. Paths should be relative to the currently-executing script file and may contain wildcards.
Examples
Add two files to the current project
files { "hello.cpp", "goodbye.cpp" }
Add all C++ files from the "src/" directory to the project
files { "src/*.cpp" }
Add all C++ files from the "src/" directory and any subdirectories
files { "src/**.cpp" }
flags({flags...})
Specifies build flags to modify the compiling or linking process. Multiple calls are concatenated.
Scope: solutions, projects, configurations
Arguments
flags - List of flag names from list below. Names are case-insensitive and ignored if not supported on a platform.
- EnableSSE, EnableSSE2 - Enable SSE instruction sets
- ExtraWarnings - Sets compiler's max warning level.
- FatalWarnings - Treat warnings as errors.
- FloatFast - Enable floating point optimizations at the expense of accuracy.
- FloatStrict - Improve floating point consistency at the expense of performance.
- Managed - Enable Managed C++ (.NET).
- MFC - Enable support for Microsoft Foundation Classes.
- NativeWChar, NoNativeWChar - Toggle support for the wchar data type.
- No64BitChecks - Disable 64-bit portability warnings.
- NoEditAndContinue - Disable support for Visual Studio's Edit-and-Continue feature.
- NoExceptions - Disable C++ exception support.
- NoFramePointer - Disable the generation of stack frame pointers.
- NoIncrementalLink - Disable support for Visual Studio's incremental linking feature.
- NoImportLib - Prevent the generation of an import library for a Windows DLL.
- NoManifest - Prevent the generation of a manifest for Windows executables and shared libraries.
- NoMinimalRebuild - Disable Visual Studio's minimal rebuild feature.
- NoPCH - Disable precompiled headers.
- NoRTTI - Disable C++ runtime type information.
- Optimize - Perform a balanced set of optimizations.
- OptimizeSize - Optimize for the smallest file size.
- OptimizeSpeed - Optimize for the best performance.
- SEH - Enable structured exception handling.
- StaticRuntime - Perform a static link against the standard runtime libraries.
- Symbols - Generate debugging information.
- Unicode - Enable Unicode strings. If not specified, the default toolset behavior is used.
- Unsafe - Enable the use of unsafe code in .NET applications.
- WinMain - Use WinMain() as the entry point for Windows applications, rather than main().
Note: When not set, options will default to the tool default.
Additional tool-specific arguments can be passed with buildoptions
or linkoptions
Examples
Enable debugging symbols in the Debug configuration and optimize the Release configuration
configuration "Debug"
flags { "Symbols" }
configuration "Release"
flags { "OptimizeSpeed", "No64BitChecks" }
framework(version)
Specifies a .NET framework version.
Note: Currently only applied to Visual Studio 2005+ and GNU Makefiles using Mono.
Scope: solutions, projects
Arguments
version - one of the following:
- 1.0
- 1.1
- 2.0
- 3.0
- 3.5
- 4.0
Examples
Use the .NET 3.0 framework
framework "3.0"
iif(condition, trueval, falseval)
Implements an immediate if
clause, returning one of two possible values.
Arguments
condition - logical condition to test
trueval - value to return if condition evaluates to true
falseval - value to return if condition evaluates to false
Examples
result = iif(os.is("windows"), "is windows", "is not windows")
Note that all expressions are evaluated before the condition is checked. The following expression cannot be implemented with an iif
because it may try to concatenate a string value.
result = iif(x -= nil, "x is " .. x, "x is nil")
imageoptions({options...})
Passes arguments directly to the image tool command line without translation. Multiple calls are concatenated.
Scope: solutions, project, configurations
Arguments
options - list of image tools flags and options
imagepath(path)
Sets the file name of the deployment image produced by the build
Scope: solutions, projects, configurations
Arguments
path - the full path for the image file, relative to the currently-executing script
implibdir(path)
Specifies the import library output directory. Import libraries are generated for Windows DLL projects. By default, the generated files will place the import library in the same directory as the compiled binary.
Scope: solutions, projects, configurations
Arguments
path - the output directory for the library, relative to the currently-executing script file
Examples
implibdir "../Libraries"
implibextension(extension)
Specifies the import library file extension. Import libraries are generated for Windows DLL projects. By default, the toolset static library file extension will be used (.lib
with Windows tools, .a
with GNU tools).
Scope: solutions, projects, configurations
Arguments
extension - the extension, including the leading dot
implibname(name)
Specifies the import library base file name. Import libraries are generated for Windows DLL projects. By default the target name will be used as the import library file name.
Scope: solutions, projects, configurations
Arguments
name - new base file name
implibprefix(prefix)
Specifies the import library file name prefix. Import libraries are generated for Windows DLL projects. By default the system naming convention will be used (no prefix on Windows, lib
prefix on other systems).
Scope: solutions, projects, configurations
Arguments
prefix - new file name prefix
Examples
implibprefix "plugin"
The prefix may also be set to an empty string for no prefix
implibprefix ""
implibsuffix(suffix)
Specifies the file name suffix for the import library base file name. Import libraries are generated for Windows DLL projects.
Scope: solutions, projects, configurations
Arguments
suffix - the new filename suffix
Examples
-- Add "-d" to debug versions of files
configuration "Debug"
implibsuffix "-d"
include(directory)
Includes a file named premake4.lua
from the specified directory. This allows you to specify each project in its own file, and easily include them into a solution.
Arguments
directory - path to the included directory, relative to the currently-executing script file.
Return Value
Any values returned by the script are passed through to the caller
Examples
-- runs "src/MyApplication/premake4.lua"
include "src/MyApplication"
-- runs "src/MyLibrary/premake4.lua"
include "src/MyLibrary"
includedirs({paths...})
Specifies include file search paths. Multiple calls are concatenated.
Scope: solutions, projects, configurations
Arguments
paths - list of include file search directories, relative to the currently-executing script file.
Examples
Define two include file search paths
includedirs { "../lua/include", "../zlib" }
You can also use wildcards to match multiple directories.
includedirs { "../includes/**" }
kind(kind)
Sets the kind of binary object being created by the project, such as a console or windowed application.
Scope: solutions, projects, configurations
Arguments
kind - project kind identifier. One of:
- ConsoleApp - console executable
- WindowedApp - application that runs in a desktop window. Does not apply on Linux.
- SharedLib - shared library or DLL
- StaticLib - static library
Examples
kind "ConsoleApp"
You can also set different kinds for each configuration. Not supported by XCode.
solution "MySolution"
configurations { "DebugLib", "ReleaseLib", "DebugDLL", "ReleaseDLL" }
project "MyProject"
configuration "*Lib"
kind "StaticLib"
configuration "*DLL"
kind "SharedLib"
language(lang)
Sets the programming language used by a project. GENie currently supports C, C++, and C#. Not all languages are supported by all of the generators. For instance, SharpDevelop does not currently support C or C++ development, and Code::Blocks does not support the .NET languages (C#, managed C++).
Scope: solutions, projects
Arguments
lang - language identifier string ("C", "C++", or "C#"). Case insensitive.
Examples
language "C++"
libdirs({paths...})
Specifies the library search paths. Library search directories are not well supported by the .NET tools. Visual Studio will change relative paths to absolute, making it difficult to share the generated project. MonoDevelop and SharpDevelop do not support search directories at all, using only the GAC. In general, it is better to include the full (relative) path to the assembly in links instead. C/C++ projects do not have this limitation.
Multiple calls are concatenated.
Scope: solutions, projects, configurations
Arguments
paths - list of library search directories, relative to the currently-executing script file
Examples
libdirs { "../lua/libs", "../zlib" }
You can also use wildcards to match multiple directories.
libdirs { "../libs/**" }
linkoptions({options...})
Passes arguments to the linker command line. Multiple calls are concatenated.
Scope: solutions, projects, configurations
Arguments
options - list of flags and options to pass
Examples
Use pkg-config
-style configuration when building on Linux with GCC.
configuration { "linux", "gmake" }
linkoptions { "`wx-config --libs`"}
links({references...})
Specifies a list of libraries and projects to link against. Multiple calls are concatenated.
Scope: solutions, projects, configurations
Arguments
references - list of library and project names
When linking against another project in the same solution, specify the project name here, rather than the library name. GENie will figure out the correct library to link against for the current configuration and will also create a dependency between the projects to ensure proper build order.
When linking against system libraries, do not include any prefix or file extension. GENie will use the appropriate naming conventions for the current platform.
Examples
Link against some system libraries
configuration "windows"
links { "user32", "gdi32" }
configuration "linux"
links { "m", "png" }
configuration "macosx"
--- OS X frameworks need the extension to be handled properly
links { "Cocoa.framework", "png" }
In a solution with two projects, link the library into the executable. Note that the project name is used to specify the link. GENie will automatically figure out the correect library file name and directory and create a project dependency.
solution "MySolution"
configurations { "Debug", "Release" }
language "C++"
project "MyExecutable"
kind "ConsoleApp"
files "**.cpp"
links { "MyLibrary" }
project "MyLibrary"
kind "SharedLib"
files "**.cpp"
You may also create links between non-library projects. In this case, GENie will generate a build dependency (the linked project will build first) but not an actual link. In this example, MyProject uses a build dependency to ensure that MyTool gets built first. It then uses MyTool as part of its build process
solution "MySolution"
configurations { "Debug", "Release" }
language "C++"
project "MyProject"
kind "ConsoleApp"
files "**.cpp"
links { "MyTool" }
prebuildcommands { "MyTool --dosomething" }
project "MyTool"
kind "ConsoleApp"
files "**.cpp"
location(path)
Sets the destination directory for a generated solution or project file. By default, project files are generated into the same directory as the script that defines them.
Note: Does not automatically propagate to the contained projects. Projects will use their default location unless explicitly overridden.
Scope: solutions, projects
Arguments
path - directory into which files should be generated, relative to the currently-executing script file.
Examples
solution "MySolution"
location "../build"
If you plan to build with multiple tools from the same source tree, you might want to split up the project files by toolset. The _ACTION global variable contains the current toolset identifier, as specified on the command line. Note that Lua sytax requires parentheses around the function parameters in this case.
location ("../build/" .. _ACTION)
newaction(description)
Registers a new command-line action argument.
Arguments
description - a table describing the new action with the following fields:
- trigger - string identifier of the action; what the user would type on the command line
- description - short description of the action, to be displayed in the help text
- execute - Function to be executed when the action is fired
Examples
newaction {
trigger = "install",
description = "Install the software",
execute = function()
os.copyfile("bin/debug/myprogram", "/usr/local/bin/myprogram")
end
}
newoption(description)
Registers a new command-line option argument.
Scope: solutions, projects, configurations
Arguments
description - a table describing the new option with the following fields:
- trigger - string identifier of the option; what the user would type on the command line
- description - short description of the option, to be displayed in the help text
- value - (optional) provides a hint to the user as to what type of data is expected
- allowed - (optional) list of key-value pairs listing the allowed values for the option
Examples
newoption {
trigger = "gfxapi",
value = "API",
description = "Choose a particular 3D API for rendering",
allowed = {
{ "opengl", "OpenGL" },
{ "direct3d", "Direct3D (Windows only)"},
{ "software", "Software Renderer" }
}
}
objdir(path)
Sets an object and intermediate file directory for a project. By default, object and intermediate files are stored in a directory named "obj" in the same directory as the project.
Scope: solutions, projects, configurations
Arguments
path - directory where the object and intermediate files should be stored, relative to the currently-executing script file.
Examples
project "MyProject"
objdir "objects"
Set object directories per configuration
configuration "Debug"
objdir "../obj_debug"
configuration "Release"
objdir "../obj_release"
os.chdir(path)
Changes the working directory
Arguments
path - path to the new working directory
Return Value
true
if successful, otherwise nil
and an error message
os.copyfile(source, destination)
Copies a file from one location to another.
Arguments
source - file system path to the file to be copied destination - path to the copy location
Return Value
true
if successful, otherwise nil
and an error message
os.findlib(libname)
Scans the well-known system locations looking for a binary file.
Arguments
libname - name of the library to locate. May be specified with (libX11.so) or without (X11) system-specified decorations.
Return Value
The path containing the library file, if found. Otherwise, nil
.
os.get()
Identifies the currently-targeted operating system.
Return Value
One of "bsd", "linux", "macosx", "solaris", or "windows"
Note: This function returns the OS being targeted, which is not necessarily the same as the OS on which GENie is being run.
Example
if os.get() == "windows" then
-- do something windows-specific
end
os.getcwd()
Gets the current working directory.
Return Value
The current working directory
os.getversion()
Retrieves version information for the host operating system
Note: Not implemented for all platforms. On unimplemented platforms, will return 0
for all version numbers, and the platform name as the description.
Return Value
Table containing the following key-value pairs:
Key | Value |
---|---|
majorversion | major version number |
minorversion | minor version number |
revision | bug fix release or service pack number |
description | human-readable description of the OS version |
Examples
local ver = os.getversion()
print(string.format(" %d.%d.%d (%s)",
ver.majorversion, ver.minorversion, ver.revision,
ver.description))
-- On Windows XP: "5.1.3 (Windows XP)"
-- On OSX: "10.6.6 (Mac OS X Snow Leopard)"
os.is(id)
Checks the current operating system identifier against a particular value
Arguments
id - one of "bsd", "linux", "macosx", "solaris", or "windows"
Note: This function returns the OS being targeted, which is not necessarily the same as the OS on which GENie is being run.
Return Value
true
if the supplied id matches the current operating system identifer, false
otherwise.
os.is64bit()
Determines if the host is using a 64-bit processor.
Return Value
true
if the host system has a 64-bit processor
false
otherwise
Examples
if os.is64bit() then
print("This is a 64-bit system")
else
print("This is NOT a 64-bit system")
end
os.isdir(path)
Checks for the existence of a directory.
Arguments
path - the file system path to check
Return Value
true
if a matching directory is found
false
if there is no such file system path, or if the path points to a file
os.isfile(path)
Checks for the existence of a file.
Arguments
path - the file system path to check
Return Value
true
if a matching file is found
false
if there is no such file system path or if the path points to a directory instead of a file
Back to top
os.matchdirs(pattern)
Performs a wildcard match to locate one or more directories.
Arguments
pattern - file system path to search. May wildcard patterns.
Return Value
List of directories which match the specified pattern. May be empty.
Examples
matches = os.matchdirs("src/*") -- non-recursive match
matches = os.matchdirs("src/**") -- recursive match
matches = os.matchdirs("src/test*") -- may also match partial name
os.matchfiles(patterns)
Performs a wildcard match to locate one or more directories.
Arguments
pattern - file system path to search. May contain wildcard patterns.
Return Value
List of files which match the specified pattern. May be empty.
Examples
matches = os.matchfiles("src/*.c") -- non-recursive match
matches = os.matchfiles("src/**.c") -- recursive match
os.mkdir(path)
Creates a new directory.
Arguments
path - path to be created
Return Value
true
if successful
nil
and an error message otherwise
os.outputof(command)
Runs a shell command and returns the output.
Arguments
command - shell command to run
Return Value
The output of the command
Examples
-- Get the ID for the host processor architecture
local proc = os.outputof("uname -p")
os.pathsearch(fname, paths...)
description
Scope: solutions, projects, configurations
Arguments
fname - name of the file being searched, followed by one or more path sets to be searched
paths - the match format of the PATH environment variable: a colon-delimited list of path. On Windows, you may use a semicolon-delimited list if drive letters might be included
Return Value
Path to the directory which contains the file, if found
nil
otherwise
Examples
local p = os.pathsearch("mysystem.config", "./config:/usr/local/etc:/etc")
os.rmdir(path)
Removes an existing directory as well as any files or subdirectories it contains.
Arguments
path - file system path to be removed
Return Value
true
if successful
nil
and an error message otherwise
os.stat(path)
Retrieves information about a file.
Arguments
path - path to file for which to retrieve information
Return Value
Table of values:
Key | Value |
---|---|
mtime | Last modified timestamp |
size | File size in bytes |
os.uuid()
Returns a Universally Unique Identifier
Return Value
A new UUID, a string value with the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
path.getabsolute(path)
Converts relative path to absolute path
Arguments
path - the relative path to be converted
Return Value
new absolute path, calculated from the current working directory
path.getbasename(path)
Extracts base file portion of a path, with the directory and extension removed.
Arguments
path - path to be split
Return Value
Base name portion of the path
path.getdirectory(path)
Extracts directory portion of a path, with file name removed
Arguments
path - path to be split
Return Value
Directory portion of the path
path.getdrive(path)
Returns drive letter portion of a path
Arguments
path - path to be split
Return Value
Drive letter portion of the path, or nil
path.getextension(path)
Returns file extension portion of a path
Arguments
path - path to be split
Return Value
File extension portion of the path, or an empty string
path.getname(path)
Returns file name and extension, removes directory information.
Arguments
path - path to be split
Return Value
File name and extension without directory information
path.getrelative(src, dest)
Computes relative path from one directory to another.
Arguments
src - originating directory dest - target directory
Return Value
Relative path from src to dest
path.isabsolute(path)
Returns whether or not a path is absolute.
Arguments
path - path to check
Return Value
true
if path is absolute
false
otherwise
path.iscfile(path)
Determines whether file is a C source code file, based on extension.
Arguments
path - path to check
Return Value
true
if path uses a C file extension
false
otherwise
path.iscppfile(path)
Determines whether a file is a C++ source code file, based on extension.
Arguments
path - path to check
Return Value
true
if path uses a C++ file extension
false
otherwise
path.isresourcefile(path)
Determines whether a path represends a Windows resource file, based on extension.
Arguments
path - path to check
Return Value
true
if path uses a well-known Windows resource file extension
false
otherwise
path.join(leading, trailing)
Joins two path portions together into a single path.
Note: if trailing is an absolute path, then leading is ignored and the absolute path is returned.
Arguments
leading - beginning portion of the path trailing - ending portion of the path
Return Value
Merged path
Examples
-- returns "MySolution/MyProject"
p = path.join("MySolution", "MyProject")
-- returns "/usr/bin", because the trailing path is absolute
p = path.join("MySolution", "/usr/bin")
-- tokens are assumed to be absolute. This returns `${ProjectDir}`
p = path.join("MySolution", "$(ProjectDir)")
path.rebase(path, oldbase, newbase)
Takes a relative path and makes it relative to a different location.
Arguments
path - path to be modified oldbase - original base directory, from which path is relative newbase - the new base directory, from where the resulting path should be relative
Return Value
Rebased path
path.translate(path, newsep)
Converts the separators in a path.
Arguments
path - path to modify newsep - new path separator. Defaults to current environment default.
Return Value
Modified path Back to top
pchheader(file)
Sets the main header file for precompiled header support.
Scope: projects
Arguments
file - name of the header file, as it is specified in your #include
statements
Examples
pchheader "afxwin.h"
pchsource "afxwin.cpp"
pchsource(file)
Sets the main source file for precompiled header support. Only used by Visual Studio.
Scope: projects
Arguments
file - name of the source file, relative to the currently-executing script file
Examples
pchheader "afxwin.h"
pchsource "afxwin.cpp"
platforms({identifiers...})
Specifies a set of target hardware platforms for a solution.
Platform support is a new, experimental feature. The syntax and behavior described here might change as we sort out the details
Scope: solutions
Arguments
identifiers - list of hardware platform specifiers from this list:
- Native - general build not targeting any particular platform. If your project can be built in a generic fashion, you should include this as the first platform option
- x32 - 32-bit environment
- x64 - 64-bit environment
- Universal - OS X universal binary, target both 32- and 64-bit versions of x86 and PPC. Automated dependency generation must be turned off, and always do a clean build. Not supported by Visual Studio.
- Universal32 - like Universal above, but targeting only 32-bit platforms
- Universal64 - like Universal above, but targeting only 64-bit platforms
- PS3 - Playstation 3
- Xbox360 - Xbox 360 compiler and linker under Visual Studio
Return Value
Current list of target platforms for the active solution
Examples
Generic build, as well as OS X Universal build
solution "MySolution"
configurations { "Debug", "Release" }
platforms { "native", "universal" }
Prove 32- and 64-bit specific build targets. No generic build is provided so one of these two platforms must always be used. Do this only if your software requires knowledge of the underlying architecture at build time; otherwise, include native to provide a generic build.
solution "MySolution"
configurations { "Debug", "Release" }
platforms { "x32", "x64" }
You can retrieve the current list of platforms by calling the function with no parameters
local p = platforms()
Once you have defined a list of platforms, you may use those identifiers to set up configuration filters and apply platform-specific settings.
configuration "x64"
defines "IS_64BIT"
-- You can also mix platforms with other configuration selectors
configuration { "Debug", "x64" }
defines "IS_64BIT_DEBUG"
postbuildcommands({commands...})
Specifies shell commands to run after build is finished
Scope: solutions, projects, configurations
Arguments
commands - one or more shell commands
Examples
configuration "windows"
postbuildcommands { "copy default.config bin\\project.config" }
configuration "not windows"
postbuildcommands { "cp default.config bin/project.config" }
postcompiletasks({commands...})
Specifies shell commands to run after compile of file is finished (GMAKE specific)
Scope: solutions, projects, configurations
Arguments
commands - one or more shell commands
Examples
postcompiletasks { "rm $(@:%.o=%.d)" }
prebuildcommands({commands...})
Specifies shell commands to run before each build
Scope: solutions, projects, configurations
Arguments
commands - one or more shell commands
Examples
configuration "windows"
prebuildcommands { "copy default.config bin\\project.config" }
configuration "not windows"
prebuildcommands { "cp default.config bin/project.config" }
prelinkcommands({commands...})
Specifies shell commands to run after source files have been compiled, but before the link step
Scope: solutions, projects, configurations
Arguments
commands - one or more shell commands
Examples
configuration "windows"
prelinkcommands { "copy default.config bin\\project.config" }
configuration "not windows"
prelinkcommands { "cp default.config bin/project.config" }
printf(format, args...)
Prints a formatted string
Arguments
format - formatting string, containing C printf()
formatting codes
args - arguments to be substituted into the format string
project(name)
Creates a new project and makes it active. Projects contain all of the settings necessary to build a single binary target, and are synonymous with a Visual Studio Project. These settings include the list of source code files, the programming language used by those files, compiler flags, include directories, and which libraries to link against.
Every project belongs to a solution.
Arguments
name - a unique name for the project. If a project with the given name already exists, it is made active and returned. The project name will be used as the file name of the generated solution file.
Return Value
The active project object.
The project
Object
Every project is represented in Lua as a table of key-value pairs. You should treat this object as read-only and use the GENie API to make any changes.
- basedir - directory where the project was originally defined. Root for relative paths.
- blocks - list of configuration blocks
- language - project language, if set
- location - output directory for generated project file
- name - name of the project
- solution - solution which contains the project
- uuid - unique identifier
Examples
Create a new project named "MyProject". Note that a solution must exist to contain the project. The indentation is for readability and is optional.
solution "MySolution"
configurations { "Debug", "Release" }
project "MyProject"
You can retrieve the currently active project by calling project
with no parameters.
local prj = project()
You can retrieve the list of projects associated with a solution using the projects
field of the solution object, which may then be iterated over.
local prjs = solution().projects
for i, prj in ipairs(prjs) do
print(prj.name)
end
resdefines({symbols...})
Specifies preprocessor symbols for the resource compiler. Multiple calls are concatenated.
Scope: solutions, projects, configurations
Arguments
symbols - list of symbols to be defined
Examples
resdefines { "DEBUG", "TRACE" }
resdefines { "CALLSPEC=__dllexport" }
resincludedirs({paths...})
Specifies the include file search paths for the resource compiler. Multiple calls are concatenated.
Scope: solutions, projects, configurations
Arguments
paths - list of include file search directories, relative to the currently executing script file
Examples
resincludedirs { "../lua/include", "../zlib" }
May use wildcards
resincludedirs { "../includes/**" }
resoptions({options...})
Passes arguments directly to the resource compiler. Multiple calls are concatenated.
Scope: solutions, projects, configurations
Arguments
options - list of resource compiler flags and options
Examples
configuration { "linux", "gmake" }
resoptions { "`wx-config --cxxflags`", "-ansi", "-pedantic" }
solution(name)
Creates a new solution and makes it active. Solutions are the top-level opjects in a GENie build script, and are synonymous with a Visual Studio solution. Each solution contains one or more projects, which in turn contain the settings to generate a single binary target.
Arguments
name - unique name for the solution. If a solution with the given name already exists, it is made active and returned. This value will be used as the file name of the generated solution file.
Return Value
The active solution
object.
The solution
Object
Represented as a Lua table key-value pairs, containing the following values. You should treat this object as read-only and use the GENie API to make any changes.
- basedir - directory where the original project was defined; acts as a root for relative paths
- configurations - list of valid configuration names
- blocks - list of configuration blocks
- language - solution language, if set
- location - output directory for the generated solution file
- name - name of the solution
- platforms - list of target platforms
- projects - list of projects contained by the solution
Examples
solution "MySolution"
You can retrieve the currently active solution object by calling solution
with no parameters.
local sln = solution()
You can use the global variable _SOLUTIONS
to list out all of the currently defined solutions.
for i, sln in ipairs(_SOLUTIONS) do
print(sln.name)
end
string.endswith(haystack, needle)
Checks if the given haystack string ends with needle.
Arguments
haystack - string to search within needle - string to check ending of haystack against
Return Value
true
- haystack ends with needle
false
- haystack does not end with needle
string.explode(str, pattern)
Breaks a string into an array of strings, formed by splitting str on pattern.
Arguments
str - string to be split pattern - separator pattern at which to split; may use Lua's pattern matching syntax
Return Value
List of substrings
string.findlast(str, pattern, plain)
Finds the last instance of a pattern within a string.
Arguments
str - string to be searched pattern - pattern to search for; may use Lua's pattern matching syntax plain - whether or not plain string comparison should be used (rather than pattern-matching)
Return Value
The matching pattern, if found, or nil
string.startswith(haystack, needle)
Checks if the given haystack starts with needle.
Arguments
haystack - string to search within needle - string to check start of haystack against
Return Value
true
- haystack starts with needle
false
- haystack does not start with needle
table.contains(array, value)
Determines if a array contains value.
Arguments
array - table to test for value value - value being tested for
Return Value
true
- array contains value
false
- array does not contain value
table.implode(array, before, after, between)
Merges an array of items into a single formatted string.
Arguments
array - table to be converted into a string before - string to be inserted before each item after - string to be inserted after each item between - string to be inserted between each item
Return Value
Formatted string
targetdir(path)
Sets the destination directory for the compiled binary target. By default, generated project files will place their compiled output in the same directory as the script.
Scope: solutions, projects, configurations
Arguments
path - file system path to the directory where the compiled target file should be stored, relative to the currently executing script file.
Examples
project "MyProject"
configuration "Debug"
targetdir "bin/debug"
configuration "Release"
targetdir "bin/release"
targetextension(ext)
Specifies the file extension for the compiled binary target. By default, the project will use the system's normal naming conventions: ".exe" for Windows executables, ".so" for Linux shared libraries, etc.
Scope: solutions, projects, configurations
Arguments
ext - new file extension, including leading dot
Examples
targetextension ".zmf"
targetname(name)
Specifies the base file name for the compiled binary target. By default, the project name will be used as the file name of the compiled binary target.
Scope: solutions, projects, configurations
Arguments
name - new base file name
Examples
targetname "mytarget"
targetprefix(prefix)
Specifies the file name prefix for the compiled binary target. By default, system naming conventions will be used: "lib" for POSIX libraries (e.g. "libMyProject.so") and no prefix elsewhere.
Scope: solutions, projects, configurations
Arguments
prefix - new file name prefix
Examples
targetprefix "plugin"
The prefix may also be set to an empty string for no prefix
targetprefix ""
targetsuffix(suffix)
Specifies a file name suffix for the compiled binary target.
Scope: solutions, projects, configurations
Arguments
suffix - new filename suffix
Examples
--- Add "-d" to debug versions of files
configuration "Debug"
targetsuffix "-d"
uuid(projectuuid)
Sets the UUID for a project. GENie automatically assigns a UUID to each project, which is used by the Visual Studio generators to identify the project within a solution. This UUID is essentially random and will change each time the project file is generated. If you are storing the generated Visual Studio project files in a version control system, this will create a lot of unnecessary deltas. Using the uuid
function, you can assign a fixed UUID to each project which never changes.
Scope: projects
Arguments
projectuuid - UUID for the current project
Return Value
Current project UUID or nil
if no UUID has been set
Examples
uuid "XXXXXXXX-XXXX-XXXX-XXXXXXXXXXXX"
vpaths({[group] = {pattern...}})
Places files into groups for "virtual paths", rather than mirroring the filesystem. This allows you to, for instance, put all header files in a group called "Headers", no matter where they appeared in the source tree.
Note: May be set on the solution, project, or configuration, but only project-level file lists are currently supported.
Scope: solutions, projects, configurations
Arguments
Table of values, where keys (groups) are strings and values (pattern) are lists of file system patterns.
group - name for the new group pattern - file system pattern for matching file names
Examples
Place all header files into a virtual path called "Headers". Any directory information is removed, "src/lua/lua.h" will appear in the IDE as "Headers/lua.h"
vpaths { ["Headers"] = "**.h" }
You may specify multiple file patterns using table syntax
vpaths {
["Headers"] = { "**.h", "**.hxx", "**.hpp" }
}
It is also possible to include the file's path in the virtual group. Using this rule, "src/lua/lua.h" will appear in the IDE as "Headers/src/lua/lua.h".
vpaths { ["Headers/*"] = "**.h" }
Any directory information explicitly provided in the pattern will be remvoed from the replacement. Using this rule, "src/lua/lua.h" will appear in the IDE as "Headers/lua/lua.h".
vpaths { ["Headers/*"] = "src/**.h" }
You can also use virtual paths to remove extra directories from the IDE. Using this rule, "src/lua/lua.h" will appear in the IDE as "lua/lua.h".
vpaths { ["*"] = "src" }
You may specify more than one rule at a time
vpaths {
["Headers"] = "**.h",
["Sources/*"] = {"**.c", "**.cpp"},
["Docs"] = "**.txt"
}
Additional Information
Wildcards
In some places, wildcards may be used in string values passed to a function. Usually, these strings represent paths. There are two types of wildcards:
*
- matches files within a single directory**
- matches files recursively in any child directory