diff options
| author | ruki <[email protected]> | 2017-07-28 11:47:05 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-07-28 11:47:05 +0800 |
| commit | 68a1ab8714d5243f85f09d53942ae4d2fdd78a47 (patch) | |
| tree | dcb61a9cdd7f8775f1d5fb40f6bb65d717fc9dae | |
| parent | 222d8bbce334904d1a7cb3514d2655fe10b9fd35 (diff) | |
support pch for gcc
| -rw-r--r-- | xmake/actions/clean/main.lua | 3 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 33 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 6 |
3 files changed, 39 insertions, 3 deletions
diff --git a/xmake/actions/clean/main.lua b/xmake/actions/clean/main.lua index eef366444..4fed90d02 100644 --- a/xmake/actions/clean/main.lua +++ b/xmake/actions/clean/main.lua @@ -65,6 +65,9 @@ function _on_clean_target(target) -- remove the symbol file _remove(target:symbolfile()) + -- remove the precompiled header file + _remove(target:pcheaderfile()) + -- remove the object files _remove(target:objectfiles()) diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index add079dd7..ee033a892 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -33,6 +33,7 @@ local table = require("base/table") local deprecated = require("base/deprecated") local option = require("project/option") local config = require("project/config") +local tool = require("tool/tool") local linker = require("tool/linker") local compiler = require("tool/compiler") local platform = require("platform/platform") @@ -716,8 +717,36 @@ function target:pcheaderfile() -- get the precompiled header file in the object directory local precompiled_header = self:get("precompiled_header") if precompiled_header then - local headerdir = path.directory(precompiled_header):gsub("%.%.", "__") - return string.format("%s/%s/%s/%s", self:objectdir(), self:name(), headerdir, path.filename(precompiled_header) .. ".pch") + + -- get it from the cache first + if self._PCHEADERFILE then + return self._PCHEADERFILE + end + + -- init sourcekinds + local sourcekinds = {[".h"] = "cc", [".hpp"] = "cxx"} + + -- get source kind + local sourcekind = sourcekinds[path.extension(precompiled_header)] or "cc" + + -- load tool instance + local toolinstance = tool.load(sourcekind) + + -- make precompiled header file + -- + -- @note gcc has not -include-pch option to set the pch file path + -- + local pcheaderfile = nil + if toolinstance and toolinstance:name() == "gcc" then + pcheaderfile = precompiled_header .. ".gch" + else + local headerdir = path.directory(precompiled_header):gsub("%.%.", "__") + pcheaderfile = string.format("%s/%s/%s/%s", self:objectdir(), self:name(), headerdir, path.filename(precompiled_header) .. ".pch") + end + + -- save to cache + self._PCHEADERFILE = pcheaderfile + return pcheaderfile end end diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index 7b249cd66..4f53cc19c 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -252,7 +252,11 @@ end -- make the precompiled header flag function nf_precompiled_header(self, headerfile, target) - return "-include " .. headerfile .. " -include-pch " .. target:pcheaderfile() + if self:name() == "clang" then + return "-include " .. headerfile .. " -include-pch " .. target:pcheaderfile() + else + return "-include " .. headerfile + end end -- make the link arguments list |
