Created
October 27, 2011 20:02
-
-
Save annulen/1320699 to your computer and use it in GitHub Desktop.
QMake integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- qmake.lua | |
-- Runs qmake scripts and get variables from them | |
-- Copyright (c) 2011 Konstantin Tokarev | |
-- | |
qmake = {} | |
local qmake_code = "" | |
local function qmake_requestcode() | |
return [[ | |
isEmpty(PREMAKE_REQUEST_VARS) { | |
error("Error in QMake integration: PREMAKE_REQUEST_VARS not defined") | |
} | |
defineTest(printVariables) { | |
var = $$1 | |
expr = \$\$ | |
expr += $$var | |
eval(value = $$join(expr)) | |
message($$var=\"$$value\") | |
} | |
for(var, PREMAKE_REQUEST_VARS) { | |
printVariables($$var) | |
} | |
]] | |
end | |
-- | |
-- Full path to QMake executable | |
-- | |
qmake.command = "qmake" | |
-- | |
-- Add piece of QMake code into listing | |
-- | |
-- @param code | |
-- QMake code | |
-- | |
function qmake.addcode(code) | |
qmake_code = qmake_code.."\n"..code | |
end | |
function qmake.include(file) | |
qmake.addcode("include("..file..")") | |
end | |
function qmake.set(var, value) | |
qmake.addcode(var.." = "..value) | |
end | |
function qmake.getvariables(variables) | |
qmake.addcode(qmake_requestcode()) | |
local pro_name = os.tmpname() | |
local pro_file = io.open(pro_name, "w") | |
pro_file:write(qmake_code) | |
pro_file:close() | |
local makefile_name = os.tmpname() | |
local cmd = qmake.command.." PREMAKE_REQUEST_VARS=\"" | |
..table.concat(variables, " ").."\" " | |
..pro_name.." -o "..makefile_name.." 2>&1" | |
local output = os.outputof(cmd) | |
os.remove(pro_name) | |
os.remove(makefile_name) | |
local lines = string.explode(output, "\n") | |
local values = {} | |
for i,v in ipairs(lines) do | |
for j = 1,#variables do | |
if string.startswith(v, "Project MESSAGE: "..variables[j].."=\"") then | |
local val = v:match("=\"(.*)\"") | |
values[variables[j]] = val | |
end | |
end | |
end | |
return values | |
end | |
-- | |
-- Discard current QMake listing | |
-- | |
function qmake.reset() | |
qmake_code = "" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment