diff options
| author | ruki <[email protected]> | 2018-04-19 00:48:55 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-04-18 22:53:30 +0800 |
| commit | f55f8a81c6743cccfcc0b76d440ebe997088f3a5 (patch) | |
| tree | 92756c45f208567551e2d23d3d4ca8d6eae99ed9 | |
| parent | e751e95930ca8dabb61169eb2c695f70f8f907a0 (diff) | |
add moc flags
| -rw-r--r-- | xmake/rules/qt/moc.lua | 79 | ||||
| -rw-r--r-- | xmake/rules/qt/xmake.lua | 10 |
2 files changed, 81 insertions, 8 deletions
diff --git a/xmake/rules/qt/moc.lua b/xmake/rules/qt/moc.lua new file mode 100644 index 000000000..3c408c0d9 --- /dev/null +++ b/xmake/rules/qt/moc.lua @@ -0,0 +1,79 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you 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 - 2018, 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 + local argv = _make_flags(target) + table.insert(argv, headerfile_moc) + table.insert(argv, "-o") + table.insert(argv, sourcefile_moc) + os.vrunv(moc, argv) +end diff --git a/xmake/rules/qt/xmake.lua b/xmake/rules/qt/xmake.lua index a2df08cac..f5d33ba67 100644 --- a/xmake/rules/qt/xmake.lua +++ b/xmake/rules/qt/xmake.lua @@ -136,22 +136,16 @@ rule("qt.moc") on_build_file(function (target, headerfile_moc) -- imports + import("moc") import("core.base.option") import("core.project.config") import("core.tool.compiler") - -- get moc - local moc = target:data("qt.moc") - -- get c++ source file for moc local sourcefile_moc = path.join(config.buildir(), ".qt", "moc", target:name(), "moc_" .. path.basename(headerfile_moc) .. ".cpp") - 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, {headerfile_moc, "-o", sourcefile_moc}) + moc.generate(target, headerfile_moc, sourcefile_moc) -- get object file local objectfile = target:objectfile(sourcefile_moc) |
