Premake 4 short introduction

Have you ever maintain cross platform project?

Having different build tools to maintain each platforms is troublesome, because naturally we need to synch each other manually. The case can be even worse when we need to upgrade the compiler of one platforms, in most case it means we need to add new build configuration.

With Premake all case above can be handled much easier, virtually premake could generate project for almost all major available build tools, like :

It even has cross compiling support, but it’s still experimental.

With single project configuration, Premake will generate project for any platform you want

So how to use premake ?

I’m not good with premake, actually I never compose my own project using it. Premake is not far different with other meta build tools like cmake and qmake, except it uses Lua as configuration language. In this article I will not introduce you to lua, you could check this page to learn more about lua.

In this article we will create simple solution, it just like creating project via wizard with normal IDE.

First create text premake4.lua , premake would find this file as configuration by default. Then create our first solution by invoking solution function, anything after this function goes to solution scope.

solution "myFirstSolution"
   configurations { "Debug", "Release" }

Look, I create solution called myFirstSolution with two configuration. A solution is nothing without project, right? Then we should create it.

project "mainProject"
 language "C++"
 files { "**.h", "**.cpp" }

Above is our first project which include all .h and .cpp files from our working directory. Then lets advance a little bit by specifying each available configuration for this project. we will add macro definition for all available configuration.

configuration "Debug"
 defines { "DEBUG" }
configuration "Release"
 defines { "NDEBUG" }

Ok this much is alright, now you can generate your project for any supported build tools using premake command.

premake4 --target vs2013

This command will generate visual studio 2013 vsproj file.

Ok, what was that?

In this state you may wonder what was that? Is configuration premake keyword, and what about defines?

If you familiar with lua, you may already know that lua allow function to be called without parentheses if it only has one argument. That’s right, just like I told before that configuration is just normal lua function; but lua makes it looks like normal file configuration rather than mini programs.

Let’s meet again on part two 😀


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s