diff options
| author | ruki <[email protected]> | 2021-02-21 12:55:55 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-02-21 12:55:55 +0800 |
| commit | 923489f49a9a83a5f1325ef84b48bb6e15d9972f (patch) | |
| tree | b43d765f64552b227fa0439f994655329e587460 | |
| parent | a97490be14d8b4122460437aab881016eee34f40 (diff) | |
improve qt moc rule
| -rw-r--r-- | xmake/rules/qt/moc/moc.lua | 71 | ||||
| -rw-r--r-- | xmake/rules/qt/moc/xmake.lua | 71 |
2 files changed, 20 insertions, 122 deletions
diff --git a/xmake/rules/qt/moc/moc.lua b/xmake/rules/qt/moc/moc.lua deleted file mode 100644 index a6631b436..000000000 --- a/xmake/rules/qt/moc/moc.lua +++ /dev/null @@ -1,71 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file moc.lua --- - --- make flags from target -function _make_flags_from_target(target) - local flags = {} - for _, define in ipairs(target:get("defines")) do - table.insert(flags, "-D" .. define) - end - for _, includedir in ipairs(target:get("includedirs")) do - table.insert(flags, "-I" .. os.args(includedir)) - end - for _, frameworkdir in ipairs(target:get("frameworkdirs")) do - table.insert(flags, "-F" .. os.args(frameworkdir)) - end - return flags -end - --- make flags -function _make_flags(target) - - -- attempt to get flags from cache first - local key = target:name() - local cache = _g._FLAGS or {} - if cache[key] then - return cache[key] - end - - -- make flags - local flags = _make_flags_from_target(target) - - -- save flags to cache - cache[key] = flags - _g._FLAGS = cache - - -- done - return flags -end - --- generate c++ source file from header file with Q_OBJECT -function generate(target, headerfile_moc, sourcefile_moc) - - -- get moc - local moc = assert(target:data("qt.moc"), "moc not found!") - - -- ensure the parent directory of source file - local sourcefile_dir = path.directory(sourcefile_moc) - if not os.isdir(sourcefile_dir) then - os.mkdir(sourcefile_dir) - end - - -- generate c++ source file for moc - os.vrunv(moc, table.join(_make_flags(target), headerfile_moc, "-o", sourcefile_moc)) -end diff --git a/xmake/rules/qt/moc/xmake.lua b/xmake/rules/qt/moc/xmake.lua index a8754a642..2ad3d969c 100644 --- a/xmake/rules/qt/moc/xmake.lua +++ b/xmake/rules/qt/moc/xmake.lua @@ -27,28 +27,15 @@ rule("qt.moc") -- set extensions set_extensions(".h", ".hpp") - -- before load - before_load(function (target) - - -- get moc - local moc = path.join(target:data("qt").bindir, is_host("windows") and "moc.exe" or "moc") - assert(moc and os.isexec(moc), "moc not found!") - - -- save moc - target:data_set("qt.moc", moc) - end) - -- before build file (we need compile it first if exists Q_PRIVATE_SLOT) - before_build_file(function (target, sourcefile, opt) + before_buildcmd_file(function (target, batchcmds, sourcefile, opt) -- imports - import("moc") - import("core.base.option") - import("core.theme.theme") - import("core.project.config") import("core.tool.compiler") - import("core.project.depend") - import("private.utils.progress") + + -- get moc + local moc = path.join(target:data("qt").bindir, is_host("windows") and "moc.exe" or "moc") + assert(moc and os.isexec(moc), "moc not found!") -- get c++ source file for moc -- @@ -62,36 +49,23 @@ rule("qt.moc") end local sourcefile_moc = path.join(target:autogendir(), "rules", "qt", "moc", filename_moc) - -- get object file - local objectfile = target:objectfile(sourcefile_moc) - - -- load compiler - local compinst = compiler.load("cxx", {target = target}) - - -- get compile flags - local compflags = compinst:compflags({target = target, sourcefile = sourcefile_moc}) - -- add objectfile + local objectfile = target:objectfile(sourcefile_moc) table.insert(target:objectfiles(), objectfile) - -- load dependent info - local dependfile = target:dependfile(objectfile) - local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) - - -- need build this object? - local depvalues = {compinst:program(), compflags} - if not depend.is_changed(dependinfo, {lastmtime = os.mtime(objectfile), values = depvalues}) then - return - end - - -- trace progress info - progress.show(opt.progress, "${color.build.object}compiling.qt.moc %s", sourcefile) + -- add commands + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.qt.moc %s", sourcefile) -- generate c++ source file for moc - moc.generate(target, sourcefile, sourcefile_moc) + local flags = {} + table.join2(flags, compiler.map_flags("cxx", "define", target:get("defines"))) + table.join2(flags, compiler.map_flags("cxx", "includedir", target:get("includedirs"))) + table.join2(flags, compiler.map_flags("cxx", "sysincludedir", target:get("sysincludedirs"))) + table.join2(flags, compiler.map_flags("cxx", "frameworkdir", target:get("frameworkdirs"))) + batchcmds:mkdir(path.directory(sourcefile_moc)) + batchcmds:vrunv(moc, table.join(flags, sourcefile, "-o", sourcefile_moc)) -- we need compile this moc_xxx.cpp file if exists Q_PRIVATE_SLOT, @see https://github.com/xmake-io/xmake/issues/750 - dependinfo.files = {} local mocdata = io.readfile(sourcefile) if mocdata and mocdata:find("Q_PRIVATE_SLOT") or sourcefile_moc:endswith(".moc") then -- add includedirs of sourcefile_moc @@ -106,17 +80,12 @@ rule("qt.moc") end end else - -- trace - if option.get("verbose") then - print(compinst:compcmd(sourcefile_moc, objectfile, {compflags = compflags})) - end - -- compile c++ source file for moc - assert(compinst:compile(sourcefile_moc, objectfile, {dependinfo = dependinfo, compflags = compflags})) + batchcmds:compile(sourcefile_moc, objectfile) end - -- update files and values to the dependent file - dependinfo.values = depvalues - table.insert(dependinfo.files, sourcefile) - depend.save(dependinfo, dependfile) + -- add deps + batchcmds:add_depfiles(sourcefile) + batchcmds:set_depmtime(os.mtime(objectfile)) + batchcmds:set_depcache(target:dependfile(objectfile)) end) |
