summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2017-08-04 15:37:44 +0800
committerruki <[email protected]>2017-08-04 15:37:44 +0800
commitfada840909bf5e61e3d5c8bed84722166f5adda0 (patch)
tree2872417ab3ef455ae7fa746b8188ea1df83f1596 /xmake/modules
parentb9f40db69152c3458b2a0dcd1b99eb094e578a0d (diff)
improve precompiled header
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/core/tools/cl.lua78
-rw-r--r--xmake/modules/core/tools/gcc.lua30
2 files changed, 51 insertions, 57 deletions
diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua
index d02982d12..bf5bc786f 100644
--- a/xmake/modules/core/tools/cl.lua
+++ b/xmake/modules/core/tools/cl.lua
@@ -202,41 +202,37 @@ function nf_includedir(self, dir)
return "-I" .. dir
end
--- make the precompiled header flag
-function nf_precompiled_header(self, headerfile, target)
+-- make the c precompiled header flag
+function nf_pcheader(self, pcheaderfile, target)
- -- cache precompiled source file
- local _, sourcefile = target:pcsourcefile()
- if sourcefile then
+ -- for c source file
+ if self:kind() == "cc" then
- -- parse headerfile from sourcefile
- if os.isfile(sourcefile) then
- local sourcedata = io.readfile(sourcefile)
- if sourcedata then
- local includefile = sourcedata:match("#include%s+[<\"](.+)[>\"]")
- if includefile then
- headerfile = includefile
- end
- end
+ -- patch objectfile
+ local objectfiles = target:objectfiles()
+ if objectfiles then
+ table.insert(objectfiles, target:pcoutputfile("c") .. ".obj")
end
- -- cache sourcefile
- _g._PCHSOURCEFILES = _g._PCHSOURCEFILES or {}
- _g._PCHSOURCEFILES[target:pcheaderfile()] = sourcefile
- else
- headerfile = path.filename(headerfile)
+ -- make flag
+ return "-Yu" .. path.filename(pcheaderfile) .. " -Fp" .. target:pcoutputfile("c")
end
+end
- -- patch objectfile
- local objectfiles = target:objectfiles()
- if objectfiles then
- table.insert(objectfiles, target:pcheaderfile() .. ".obj")
- end
+-- make the c++ precompiled header flag
+function nf_pcxxheader(self, pcheaderfile, target)
- -- make flag
- local extension = path.extension(headerfile)
- if (extension:startswith(".h") or extension == ".inl") then
- return "-Yu" .. headerfile .. " -Fp" .. target:pcheaderfile()
+ -- for c++ source file
+ if self:kind() == "cxx" then
+
+ -- patch objectfile
+ local objectfiles = target:objectfiles()
+ if objectfiles then
+ table.insert(objectfiles, target:pcoutputfile("cxx") .. ".obj")
+ end
+
+ -- make flag
+ return "-Yu" .. path.filename(pcheaderfile) .. " -Fp" .. target:pcoutputfile("cxx")
end
end
@@ -268,7 +264,7 @@ function _include_deps(self, outdata)
end
-- make the complie arguments list for the precompiled header
-function _compargv1_pch(self, headerfile, objectfile, flags)
+function _compargv1_pch(self, pcheaderfile, pcoutputfile, flags)
-- remove "-Yuxxx.h" and "-Fpxxx.pch"
local pchflags = {}
@@ -278,27 +274,15 @@ function _compargv1_pch(self, headerfile, objectfile, flags)
end
end
- -- get pcheaderfile
- local pcheaderfile = objectfile
-
- -- get sourcefile from the *.pch file
- local sourcefile = nil
- if _g._PCHSOURCEFILES then
- sourcefile = _g._PCHSOURCEFILES[pcheaderfile]
- end
-
- -- make it if no sourcefile
- if not sourcefile then
- sourcefile = os.tmpfile() .. language.extension_of(self:kind())
- io.writefile(sourcefile, format("#include \"%s\"", path.filename(headerfile)))
- table.insert(pchflags, "-I" .. path.directory(headerfile))
+ -- compile as c/c++ source file
+ if self:kind() == "cc" then
+ table.insert(pchflags, "-TC")
+ elseif self:kind() == "cxx" then
+ table.insert(pchflags, "-TP")
end
- -- make objectfile
- objectfile = pcheaderfile .. ".obj"
-
-- make complie arguments list
- return self:program(), table.join("-c", "-Yc", pchflags, "-Fp" .. pcheaderfile, "-Fo" .. objectfile, sourcefile)
+ return self:program(), table.join("-c", "-Yc", pchflags, "-Fp" .. pcoutputfile, "-Fo" .. pcoutputfile .. ".obj", pcheaderfile)
end
-- make the complie arguments list
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index b8f34942f..96413b718 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -250,14 +250,24 @@ function nf_frameworkdir(self, frameworkdir)
return "-F " .. frameworkdir
end
--- make the precompiled header flag
-function nf_precompiled_header(self, headerfile, target)
- local extension = path.extension(headerfile)
- if (extension:startswith(".h") or extension == ".inl") then
+-- make the c precompiled header flag
+function nf_pcheader(self, pcheaderfile, target)
+ if self:kind() == "cc" then
+ if self:name() == "clang" then
+ return "-include " .. pcheaderfile .. " -include-pch " .. target:pcoutputfile("c")
+ else
+ return "-include " .. pcheaderfile
+ end
+ end
+end
+
+-- make the c++ precompiled header flag
+function nf_pcxxheader(self, pcheaderfile, target)
+ if self:kind() == "cxx" then
if self:name() == "clang" then
- return "-include " .. headerfile .. " -include-pch " .. target:pcheaderfile()
+ return "-include " .. pcheaderfile .. " -include-pch " .. target:pcoutputfile("cxx")
else
- return "-include " .. headerfile
+ return "-include " .. pcheaderfile
end
end
end
@@ -314,10 +324,10 @@ function _include_deps(self, sourcefile, flags)
end
-- make the complie arguments list for the precompiled header
-function _compargv1_pch(self, headerfile, objectfile, flags)
+function _compargv1_pch(self, pcheaderfile, pcoutputfile, flags)
-- init key and cache
- local key = headerfile .. tostring(flags)
+ local key = pcheaderfile .. tostring(flags)
_g._PCHFLAGS = _g._PCHFLAGS or {}
-- remove "-include xxx.h" and "-include-pch xxx.pch"
@@ -333,7 +343,7 @@ function _compargv1_pch(self, headerfile, objectfile, flags)
end
-- compile header.h as c++?
- if self:kind() == "cxx" and headerfile:endswith(".h") then
+ if self:kind() == "cxx" then
table.insert(pchflags, "-x")
table.insert(pchflags, "c++-header")
end
@@ -342,7 +352,7 @@ function _compargv1_pch(self, headerfile, objectfile, flags)
_g._PCHFLAGS[key] = pchflags
-- make complie arguments list
- return self:program(), table.join("-c", pchflags, "-o", objectfile, headerfile)
+ return self:program(), table.join("-c", pchflags, "-o", pcoutputfile, pcheaderfile)
end
-- make the complie arguments list