summaryrefslogtreecommitdiff
path: root/xmake/modules/core/tools/gcc.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2017-07-28 13:52:22 +0800
committerruki <[email protected]>2017-07-28 13:52:22 +0800
commitf09e86f3f7986a71d6b376c754df3e9209ca2900 (patch)
treef7820a78ca048ea978c4423c32ef38705a7bd86a /xmake/modules/core/tools/gcc.lua
parenteb2d597f3d8ca3b9795d02c3a1ee46e2956f0276 (diff)
add precompiled source
Diffstat (limited to 'xmake/modules/core/tools/gcc.lua')
-rw-r--r--xmake/modules/core/tools/gcc.lua33
1 files changed, 29 insertions, 4 deletions
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index 4f53cc19c..254f3301a 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -252,10 +252,13 @@ end
-- make the precompiled header flag
function nf_precompiled_header(self, headerfile, target)
- if self:name() == "clang" then
- return "-include " .. headerfile .. " -include-pch " .. target:pcheaderfile()
- else
- return "-include " .. headerfile
+ local extension = path.extension(headerfile)
+ if extension == ".h" or extension == ".hpp" then
+ if self:name() == "clang" then
+ return "-include " .. headerfile .. " -include-pch " .. target:pcheaderfile()
+ else
+ return "-include " .. headerfile
+ end
end
end
@@ -280,6 +283,15 @@ function _include_deps(self, sourcefile, flags)
-- the temporary file
local tmpfile = os.tmpfile()
+ -- uses pchflags for precompiled header
+ if _g._PCHFLAGS then
+ local key = sourcefile .. tostring(flags)
+ local pchflags = _g._PCHFLAGS[key]
+ if pchflags then
+ flags = pchflags
+ end
+ end
+
-- generate it
os.runv(self:program(), table.join("-c", "-E", "-MM", flags or {}, "-o", tmpfile, sourcefile))
@@ -304,6 +316,10 @@ end
-- make the complie arguments list for the precompiled header
function _compargv1_pch(self, headerfile, objectfile, flags)
+ -- init key and cache
+ local key = headerfile .. tostring(flags)
+ _g._PCHFLAGS = _g._PCHFLAGS or {}
+
-- remove "-include xxx.h" and "-include-pch xxx.pch"
local pchflags = {}
local include = false
@@ -316,6 +332,15 @@ function _compargv1_pch(self, headerfile, objectfile, flags)
end
end
+ -- compile header.h as c++?
+ if self:kind() == "cxx" and headerfile:endswith(".h") then
+ table.insert(pchflags, "-x")
+ table.insert(pchflags, "c++-header")
+ end
+
+ -- save pchflags to cache
+ _g._PCHFLAGS[key] = pchflags
+
-- make complie arguments list
return self:program(), table.join("-c", pchflags, "-o", objectfile, headerfile)
end