Premake4 snippet to create solution names depending on target Visual Studio version

I prefer to name my solutions and projects something like projectname.vsX.sln and projectname.vsX.vcproj respectively. However, by default Premake4 generates the names as they are passed to the builtin solution and project functions respectively. Not cool enough for me. By the power of Graysk…uh uhm…Lua:

do
    function myoverride(orig_func)
        local func = orig_func
        return function(name)
            if _ACTION == "vs2003" then
                name = name .. ".vs7"
            elseif _ACTION == "vs2005" then
                name = name .. ".vs8"
            elseif _ACTION == "vs2008" then
                name = name .. ".vs9"
            elseif _ACTION == "vs2010" then
                name = name .. ".vs10"
            end
            elseif _ACTION == "vs2012" then
                name = name .. ".vs11"
            end
            return func(name)
        end
    end
    solution = myoverride(solution)
    project = myoverride(project)
end

… this way the names fit my taste much better.

// Oliver

PS: somewhat more concise but achieving a similar effect:

do
    function myoverride(orig_func)
        local func = orig_func
        return function(name)
            if _ACTION:sub(1,2) == "vs" then
                name = name .. "." .. _ACTION
            end
            return func(name)
        end
    end
    solution = myoverride(solution)
    project = myoverride(project)
end
This entry was posted in EN, Lua, Programming, Software and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *