Living with Premake

When you are working with cross-platform code, ensuring that your build-system is cross-platform too simplifies things quite a bit.

While there are more sophisticated build systems, I love premake for its simplicity. Though getting some things done can be quite a challenge. In this post I will briefly talk about some tricks and hacks that I have used.

There might be better ways of doing these things and I would be more than happy to learn about them.

Project Sub-modules

This is with premake 4.4. For a project that requires the ability to selectively choose what went into the build – include sources and components that have to be removed/added according to what has to be deployed – we wrote wrappers to our premake scripts that used these methods:

This could be extended to copy source files to a global destination, magic for selecting sources to be included in the build etc. Now, the module implementation would look like this:

And you would put together the build by doing something like this in our top-level scripts:

Building with modules like this is also very convenient for hiding away code and blobs you don’t want to distribute or want others to know that exist. There might be simpler ways to do something like this using filters, defines etc but this was something straightforward that I liked to use.

VS2012 to VS2013

Premake 4.4 only had VS2012 support – no VS2013. In case you want to go from 2012 to 2013 – upgrade to premake5 (and that happens to be a solution for a lot of problems). If you can’t, here’s a non-premake hack:

Now, if you simply change all references to the older version of Visual Studio in the .vcxproj file, you will have something that works:

I used the windows build of gsar.exe.

Moving to the awesome premake5 + VS2015

So upgrading to premake5 isn’t going to require much effort… and when you are upgrading, might as well upgrade the toolchain. While upgrading, this is all I had to take care:

– premake configures the entrypoint function to int main(), even for UNICODE projects. So fix that.

– link to legacy_stdio_definitions for a whole bunch of CRT linker issues.

AND… thats about it. Everything else was a breeze.

Author: Chaitanya Vasantarao

Multimedia and Systems developer. Working as a Senior Technical Architect at PathPartner Technology. Live in Bangalore with my wife Nidhi and little tyke Sid. Enjoy travelling, books, photography

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s