diff options
| author | ruki <[email protected]> | 2019-08-29 00:29:16 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-08-28 20:55:38 +0800 |
| commit | 6f8d4b91cf019662a58f822c700d894d82a2c76d (patch) | |
| tree | 3ed6d85592e4a64427f195f6098a070dbdb48d7b | |
| parent | 57d0b3900a27add2dbd81e186c7aa496ea9d369f (diff) | |
cpprules
| -rw-r--r-- | xmake/actions/build/kinds/object.lua | 22 | ||||
| -rw-r--r-- | xmake/languages/c++/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/languages/objc++/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/rules/c++/cache/xmake.lua | 46 | ||||
| -rw-r--r-- | xmake/rules/c++/pcheader/build.lua | 24 | ||||
| -rw-r--r-- | xmake/rules/c++/xmake.lua | 30 |
6 files changed, 118 insertions, 10 deletions
diff --git a/xmake/actions/build/kinds/object.lua b/xmake/actions/build/kinds/object.lua index 8f859054e..31f1d8cc0 100644 --- a/xmake/actions/build/kinds/object.lua +++ b/xmake/actions/build/kinds/object.lua @@ -28,7 +28,6 @@ import("core.project.config") import("core.project.depend") import("core.project.project") import("core.language.language") -import("detect.tools.find_ccache") -- build the object from the *.[o|obj] source file function _build_from_object(target, sourcefile, objectfile, progress) @@ -118,12 +117,16 @@ function _do_build_file(target, sourcefile, opt) -- is verbose? local verbose = option.get("verbose") + -- get build prefix + local build_prefix = target:data("build.object.prefix") + build_prefix = build_prefix and (build_prefix .. " ") or "" + -- trace progress info cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", progress) if verbose then - cprint("${dim color.build.object}%scompiling.$(mode) %s", buildinfo.ccache and "ccache " or "", sourcefile) + cprint("${dim color.build.object}%scompiling.$(mode) %s", build_prefix, sourcefile) else - cprint("${color.build.object}%scompiling.$(mode) %s", buildinfo.ccache and "ccache " or "", sourcefile) + cprint("${color.build.object}%scompiling.$(mode) %s", build_prefix, sourcefile) end -- trace verbose info @@ -211,6 +214,10 @@ function _build_files_for_single(target, sourcebatch, jobs) local dependfiles = sourcebatch.dependfiles local sourcekind = sourcebatch.sourcekind + -- get build prefix + local build_prefix = target:data("build.object.prefix") + build_prefix = build_prefix and (build_prefix .. " ") or "" + -- trace progress info local buildinfo = _g.buildinfo for index, sourcefile in ipairs(sourcefiles) do @@ -221,9 +228,9 @@ function _build_files_for_single(target, sourcebatch, jobs) -- trace progress info cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", progress) if verbose then - cprint("${dim color.build.object}%scompiling.$(mode) %s", buildinfo.ccache and "ccache " or "", sourcefile) + cprint("${dim color.build.object}%scompiling.$(mode) %s", build_prefix, sourcefile) else - cprint("${color.build.object}%scompiling.$(mode) %s", buildinfo.ccache and "ccache " or "", sourcefile) + cprint("${color.build.object}%scompiling.$(mode) %s", build_prefix, sourcefile) end end @@ -397,11 +404,6 @@ function build(target, buildinfo) buildinfo.sourceindex = 0 buildinfo.sourcecount = target:sourcecount() - -- init ccache - if config.get("ccache") and buildinfo.ccache == nil then - buildinfo.ccache = find_ccache() - end - -- build precompiled headers _build_pcheaderfiles(target, buildinfo) diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua index cae820768..93f0eb528 100644 --- a/xmake/languages/c++/xmake.lua +++ b/xmake/languages/c++/xmake.lua @@ -39,6 +39,9 @@ language("c++") -- set mixing kinds set_mixingkinds("cc", "cxx", "as", "mrc") + -- add rules + add_rules("cpp") + -- on load on_load("load") diff --git a/xmake/languages/objc++/xmake.lua b/xmake/languages/objc++/xmake.lua index 2b6276124..86a5cb0e8 100644 --- a/xmake/languages/objc++/xmake.lua +++ b/xmake/languages/objc++/xmake.lua @@ -39,6 +39,9 @@ language("objc++") -- set mixing kinds set_mixingkinds("mm", "mxx", "cc", "cxx", "as") + -- add rules + add_rules("cpp.pcheader") + -- on load on_load("load") diff --git a/xmake/rules/c++/cache/xmake.lua b/xmake/rules/c++/cache/xmake.lua new file mode 100644 index 000000000..38cf390d3 --- /dev/null +++ b/xmake/rules/c++/cache/xmake.lua @@ -0,0 +1,46 @@ +--!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 - 2019, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define rule: cpp.cache +rule("cpp.cache") + + -- we attempt to use ccache now + -- maybe we will implement cross-platform cache in the future + before_load(function (target) + + -- imports + import("lib.detect.find_tool") + + -- find ccache + local ccache = target:data("cpp.ccache") + if not ccache and config.get("ccache") then + ccache = find_tool("ccache") + target:data_set("cpp.ccache", ccache) + end + + -- add the prefix information of building object + -- + -- e.g. + -- [ 0%]: ccache compiling.release src/xxx.c + -- + if ccache then + target:data_set("build.object.prefix", "ccache") + end + end) diff --git a/xmake/rules/c++/pcheader/build.lua b/xmake/rules/c++/pcheader/build.lua new file mode 100644 index 000000000..cd6929681 --- /dev/null +++ b/xmake/rules/c++/pcheader/build.lua @@ -0,0 +1,24 @@ +--!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 - 2019, TBOOX Open Source Group. +-- +-- @author ruki +-- @file build.lua +-- + +-- build the precompiled header +function (target) + -- TODO +end diff --git a/xmake/rules/c++/xmake.lua b/xmake/rules/c++/xmake.lua new file mode 100644 index 000000000..3105d69dc --- /dev/null +++ b/xmake/rules/c++/xmake.lua @@ -0,0 +1,30 @@ +--!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 - 2019, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define rule: cpp.pcheader +rule("cpp.pcheader") + add_deps("cpp.cache") + before_build(function (target, opt) + import("pcheader.build")(target, opt) + end) + +-- define rule: cpp +rule("cpp") + add_deps("cpp.pcheader", "cpp.cache") |
