diff options
| author | ruki <[email protected]> | 2018-04-18 22:40:05 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-04-18 10:00:35 +0800 |
| commit | e751e95930ca8dabb61169eb2c695f70f8f907a0 (patch) | |
| tree | ad27ab7fd9c5af3600d6a0f0d0451def222a2351 | |
| parent | 383f44f85f2fd209a65d3bc58b28558ce5028051 (diff) | |
compile qt moc header
| -rw-r--r-- | tests/projects/qt_widgetapp/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/rules/qt/xmake.lua | 61 |
2 files changed, 63 insertions, 1 deletions
diff --git a/tests/projects/qt_widgetapp/xmake.lua b/tests/projects/qt_widgetapp/xmake.lua index d0b8f1b4a..1d1a3ba3a 100644 --- a/tests/projects/qt_widgetapp/xmake.lua +++ b/tests/projects/qt_widgetapp/xmake.lua @@ -15,5 +15,8 @@ target("qt_demo") add_files("src/*.cpp") add_files("src/mainwindow.ui") + -- add files with Q_OBJECT meta (only for qt.moc) + add_files("src/mainwindow.h") + -- add frameworks add_frameworks("QtWidgets") diff --git a/xmake/rules/qt/xmake.lua b/xmake/rules/qt/xmake.lua index d27259d03..a2df08cac 100644 --- a/xmake/rules/qt/xmake.lua +++ b/xmake/rules/qt/xmake.lua @@ -112,6 +112,65 @@ rule("qt.ui") target:data_add("qt.cleanfiles", headerfile_ui) end) +-- define rule: moc +rule("qt.moc") + + -- add rule: qt environment + add_deps("qt.env") + + -- set extensions + set_extensions(".h") + + -- on load + on_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) + + -- on build file + on_build_file(function (target, headerfile_moc) + + -- imports + 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}) + + -- get object file + local objectfile = target:objectfile(sourcefile_moc) + + -- trace + if option.get("verbose") then + print(compiler.compcmd(sourcefile_moc, objectfile, {target = target})) + end + + -- compile c++ source file for moc + compiler.compile(sourcefile_moc, objectfile, {target = target}) + + -- add objectfile + table.insert(target:objectfiles(), objectfile) + + -- add clean files + target:data_add("qt.cleanfiles", {sourcefile_moc, objectfile}) + end) + -- define rule: *.qrc rule("qt.qrc") @@ -175,7 +234,7 @@ rule("qt.qrc") rule("qt.application") -- add rules - add_deps("qt.qrc", "qt.ui") + add_deps("qt.qrc", "qt.ui", "qt.moc") -- on load on_load(function (target) |
