Appending to buildcommands in premake

532 views Asked by At

I'm using a premake makefile project with the configurations: {"VulkanDebug", "VulkanRelease", "OpenGLDebug", "OpenGLRelease"} and want to pass DEBUG / RELEASE and VULKAN / OPENGL tokens to the script in buildCommands.

For example, when the configuration is VulkanRelease, the buildcommand is script.bat VULKAN RELEASE and the script is responsible for deciding what to do with those tokens.

My ideal solution is (using invalid logic):

    buildcommands { "script.bat" }

    filter "configurations:*Vulkan*"
        buildcommands.append(" VULKAN")
        rebuildcommands.append(" VULKAN")

    filter "configurations:*OpenGL*"
        buildcommands.append(" OPENGL")
        rebuildcommands.append(" OPENGL")

    filter "configurations:*Debug*"
        buildcommands.append(" DEBUG")
        rebuildcommands.append(" DEBUG")

    filter "configurations:*Release*"
        buildcommands.append(" RELEASE")
        rebuildcommands.append(" RELEASE")

If I use buildcommands the normal way, visual studio will consider it as three separate commands to execute: script.bat, VULKAN, and RELEASE.

I have a few workarounds but they all feel ugly to me. First is to pass the entire configuration name as an argument to the script and parse it there. Not really a fan of clumping arguments together like that. The second is to create command line arguments to the premake script for VULKAN or OPENGL and only have DEBUG and RELEASE as the configurations. As far as I know this will generate separate project files for Vulkan and OpenGL, which seems like overkill. Finally, I could supply the full build command for each configuration. This third option seems the best but it will make the script longer once I add more configurations (and all possible permutations).

So if premake has append support and I don't know about it, then non-issue! Otherwise there might be a cleaner way of doing this that I don't know about. Thanks for reading.

1

There are 1 answers

0
J. Perkins On BEST ANSWER

Probably the cleanest approach that you can use right now today is to provide a helper function in your project script, which you then call from an inline token. Maybe something like:

-- Helper function to assemble the arguments
function buildArguments(cfg)
    local args = {}

    if cfg.name:find("VULKAN") then
        table.insert(args, "VULKAN")
    end

    if cfg.name:find("OpenGL") then
        table.insert(args, "OPENGL")
    end

    if cfg.name:find("Debug") then
        table.insert(args, "DEBUG")
    end

    if cfg.name:find("Release") then
        table.insert(args, "RELEASE")
    end

    return table.concat(args, " ")
end

-- Use it like this
buildcommands "SomeCmd.exe %{buildArguments(cfg)}"