How I Use Premake

Build systems are the bain of C and C++ developers, but I find those same developers look down on build systems, and are how these systems are maintained is usually to a lesser quality than the main code.

To quote Roy

“i’ve seen things you people wouldn’t believe”.

I quite like Premake, I wish it had more generators, but I like it. However most people write Lua code like shit (because they just dont care), and very quickly you end up with some sorta hell-scape.

This is the way I do my personal projects with Premake.

Describe the exe/lib as data.

{
        "projects" : [
                {
                        "name" : "lib_name",
                        "kind" : "StaticLib",
                        "language" : "C",

                        "files" : [
                                "foo.h",
                                "foo.c"
                        ],

                        "include_dirs" : [
                                "./"
                        ]
                }
        ]
}

Premake provides a json decode function that turns the json into a Lua table. So we can collect all the json files, decode them and process them.

local project_files = os.matchfiles("./**premake.json")

for i, file in ipairs(project_files) do

    local json_str = io.readfile(file)
    local file_table, err = json.decode(json_str)

    -- Call Premake API --
end

My full impl can be found here my solution isn’t meant to be a generic one size fits all solution. Its meant to service my narrow needs.