-
Notifications
You must be signed in to change notification settings - Fork 21
Using Platforms
Home > [Scripting With Premake](Scripting With Premake) > Using Platforms
Platform support is a new, experimental feature introduced in Premake 4.1. This is a potentially large area of development and it may take a few releases to get it just right. The syntax and behavior described here might change along the way.
An important caveat: I don't target multiple platforms in my own day to day work. I am relying on those of you that do, and the community at large, to help me shape this feature.
One more disclaimer: I think this page is confusing. If you've got any ideas on how I might explain it better please leave a comment. Thanks!
In addition to [configurations](Using Configurations), you can also target multiple hardware platforms, such as a 32-bit build and a 64-bit build. This is also known as cross compiling. These platforms can be quickly switched between from within your IDE, or with a command-line parameter on the generated makefile.
In addition to 32- and 64-bit builds, Premake also supports Mac OS X universal binaries, the Playstation 3, and the Xbox 360. See the platforms function documentation for a full list of supported platforms.
Unlike configurations, platforms are optional. If you don't need them, just don't call the platforms function at all, in which case the toolset's default behavior will be used.
The easiest way to target a particular platform is to supply the --platform argument to Premake. If you have a solution that builds on Windows, and you want to a binary for the Xbox 360, you would call:
premake4 --platform=xbox360 vs2005
The files generated by this call will include the default Win32 build normally present in Visual Studio solutions, plus a new set of configurations which target the Xbox 360. Assuming that you have the proper development tools installed and your software is portable enough, you can now build an Xbox 360 binary.
If you frequently target several different platforms, and want to switch between them without regenerating your project files, you can add them directly to your script. Target platforms are part of the solution, just like configurations:
#!lua
solution "MySolution"
configurations { "Debug", "Release" }
platforms { "Native", "Universal" }
Not all tools will support all of the possible targets (currently only Visual Studio supports the Xbox 360 platform). Unsupported platforms are silently ignored; they simply will not appear in the generated build scripts.
Most toolsets require extra configuration to target multiple platforms. Premake will generate a build script with the right instructions for a 64-bit or an Xbox build, but that build will only succeed if the corresponding tools and libraries have been installed on the developer machine. GCC users may need to install the GCC multilib packages.
In addition to the cross-compiling platform targets listed above, there is a special target called native which preserves the default compiler behavior. Taking GCC as an example, Premake's x32 flag adds -m32 to the GCC command line, and the x64 flag adds -m64. The native platform, in contrast, does not add any flags to the command line and lets GCC use its default behavior to target the current platform.
Normally you would include the native platform, and list it first to make it the default.
#!lua
platforms { "native", "x32", "x64" }
So if you wanted your code to "just build" on Windows or Unix, 32- or 64-bit systems, and you also wanted to allow folks to cross-compile for the Xbox 360 or Mac OS X universal binaries, you could do:
#!lua
platforms { "native", "xbox360", "universal" }
Sometimes it is important to know which platform you are targeting; you might need to define specific symbols or link to different libraries. In this case, the native platform would not be included in the list.
#!lua
platforms { "x32", "x64" }
Like any other configuration-specific value, platform-specific settings are set with [configuration filters](Using Configurations). If no platform is specified to the filter, the subsequent settings will apply to all platforms.
#!lua
configuration { "debug" }
defines "_DEBUG" -- this symbol will appear in settings for ALL platforms
If a specific platform identifier is listed, the settings will be applied only when that platform is specifically selected by the user.
#!lua
configuration { "xbox360" }
defines "IS_XBOX360_BUILD" -- this will only get applied when user chooses the Xbox 360 build
The platform is just another configuration axis, which you can mix and match with any other selectors. See the configuration function for more details.
#!lua
configuration { "Debug", "x64" }
defines "USE_64BIT_DEBUG_LIBRARY"
I am still working out how the target platforms should be represented in Premake-generated makefiles. Below is my best take so far; feedback and suggestions for improvement are very much appreciated.
In the generated makefiles, platforms and build configurations are paired up. If you defined a solution like this:
#!lua
platforms { "native", "x64", "universal" }
There would be six possible configurations: debug, release, debug64, release64, debuguniv, and releaseuniv. I tried to truncate the platforms to something easy to type.
You target a specific configuration using the config argument.
make config=debug64
If the makefile is executed without any arguments, the first build configuration (in the example above, **debug) will be used. For this reason, it is recommended that you put native first in the list.