Why i moved to Premake?!

Hello, this is me Moustapha Saad a C++ guy and this is my story with Premake.

At first i stumbled upon Premake when i found an interesting open source project that used Premake to generate it’s project file and for my surprise the process was as easy as typing “premake5 vs2012”, and just like that VS2012 project files was generated flawlessly and the thing that amazed me everything in the solution was created and linked without one single error, as if someone created the project himself, At the time i was using CMake and i’ll let you imagine the pain.

So, after this flawless process i forgot about the project and was interested in the tool itself … Premake.

Baby Steps

Creating a simple C++ project is as simple as this.

First you define your solution and populate it with projects a projects.

Projects has some simple properties:

  • Kind: specifies project kind either “ConsoleApp”, “SharedLib”, or “StaticLib”
  • Language: as the name implies, this option specifies project’s language
  • Files: specifies a list of files that this project contains
  • Filters: a filter allows you to target build settings with an exact configurations, let’s say you need a different configuration for debug build then you use a filter for debug build as the example above shows.

Next Steps

Now that you got familiar with Premake let’s build a shared lib and then link it to a console app.

Don’t panic, this is just the simple version with some few things added.

  • Location: specifies the location of the solution.
  • startproject: specifies which project is the start project to run in VS
  • targetdir: specifies the output directory for a project
  • %{variable}: variable in premake is written in this form so simple %{cfg.buildcfg} is just variable that hold the current build configuration
  • includedirs: specifies the include directories that include header files that you will use in your project
  • configuration {“linux, “gmake”}: specifies a set of options that will be activated in the case of this configuration that is “linux”, “gmake” and simply this line tells the compiler to use c++11 and pthread for multi-threading
  • buildoptions: also as the name implies it specifies a build option that will be passed to the compiler
  • defines: add a preprocessor defines to the project and in case of shared library project i used it to check whether i’m compiling dll or not.
  • links: this feature is just a bless, you can link a project to another project simply by typing it’s name and everything magically works.

Useful Stuff

Premake is Lua so you can use Lua inside your solution definition

  • os.get(): return current OS that runs the script, so you can use it to check for the user OS example: if os.get() == “windows” then …
  • libdirs: specifies the directories that’s will be searched in to find the used libraries in case you use external libraries in your project
  • _ACTION: this is a predefined variable that hold the user argument to premake, example: “premake5 vs2012” then _ACTION will be equal to “vs2012”

That’s all, good luck with your projects.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.