diff options
| author | OpportunityLiu <[email protected]> | 2019-07-17 17:12:49 +0800 |
|---|---|---|
| committer | OpportunityLiu <[email protected]> | 2019-07-17 17:12:49 +0800 |
| commit | a6396622cdb3af334c1ec044d5a699affa0dccc2 (patch) | |
| tree | 48e64bd811c233542d8e696efe53e16b4d74dbd5 | |
| parent | 509f75e87676bf3d95bc5dc8ccd3b731fdc055e4 (diff) | |
use single pdb file for compile
| -rw-r--r-- | xmake/modules/core/tools/cl.lua | 92 | ||||
| -rw-r--r-- | xmake/modules/core/tools/nvcc.lua | 72 |
2 files changed, 80 insertions, 84 deletions
diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index 7d4fda764..8e3c0bd1b 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -11,7 +11,7 @@ -- 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 @@ -20,13 +20,12 @@ -- imports import("core.base.option") -import("core.base.hashset") import("core.project.project") import("core.language.language") -- init it function init(self) - + -- init cxflags self:set("cxflags", "-nologo") @@ -88,21 +87,41 @@ end -- make the symbol flag function nf_symbol(self, level, target) - -- the maps - local maps = - { - debug = "-Zi" - } + -- debug? generate *.pdb file + local flags = nil + if level == "debug" then + local symbolfile = nil + if target and target.symbolfile then + symbolfile = target:symbolfile() + end + if symbolfile then - return maps[level] + -- ensure the object directory + local symboldir = path.directory(symbolfile) + if not os.isdir(symboldir) then + os.mkdir(symboldir) + end + + -- check and add symbol output file + flags = "-Zi -Fd" .. path.join(symboldir, "compile." .. path.filename(symbolfile)) + if self:has_flags({"-Zi", "-FS", "-Fd" .. os.tmpfile() .. ".pdb"}, "cxflags") then + flags = "-FS " .. flags + end + else + flags = "-Zi" + end + end + + -- none + return flags end -- make the warning flag function nf_warning(self, level) -- the maps - local maps = - { + local maps = + { none = "-W0" , less = "-W1" , more = "-W3" @@ -112,15 +131,15 @@ function nf_warning(self, level) } -- make it - return maps[level] + return maps[level] end -- make the optimize flag function nf_optimize(self, level) -- the maps - local maps = - { + local maps = + { none = "-Od" , faster = "-O2" , fastest = "-Ox -fp:fast" @@ -137,7 +156,7 @@ function nf_vectorext(self, extension) -- the maps local maps = - { + { sse = "-arch:SSE" , sse2 = "-arch:SSE2" , avx = "-arch:AVX" @@ -156,7 +175,7 @@ function nf_language(self, stdname) -- the stdc maps if _g.cmaps == nil then - _g.cmaps = + _g.cmaps = { -- stdc c99 = "-TP" -- compile as c++ files because msvc only support c89 @@ -168,7 +187,7 @@ function nf_language(self, stdname) -- the stdc++ maps if _g.cxxmaps == nil then - _g.cxxmaps = + _g.cxxmaps = { cxx11 = "-std:c++11" , gnuxx11 = "-std:c++11" @@ -197,7 +216,7 @@ function nf_language(self, stdname) -- not support it? if flag and flag:find("std:c++", 1, true) and not self:has_flags(flag, "cxflags") then - return + return end -- ok @@ -319,42 +338,11 @@ function _include_deps(self, outdata) return results end --- add if we need -Fd flags -function _patch_pdbflags(objectfile, flags) - - local compflags = flags - - local _pdbflags = _g._pdbflags or hashset.of("-ZI", "-Zi", "/ZI", "/Zi") - _g._pdbflags = _pdbflags - - -- check if we need -Fd flags - local need_pdb = false - local has_pdb = false - for _, flag in ipairs(flags) do - if _pdbflags:has(flag) then - need_pdb = true - end - if flag:find("-Fd", 1, true) or flag:find("/Fd", 1, true) then - has_pdb = true - end - if need_pdb and has_pdb then - break - end - end - - -- add pdb output - if need_pdb and not has_pdb then - compflags = table.join(flags, "-Fd" .. objectfile .. ".pdb") - end - - return compflags -end - -- make the complie arguments list for the precompiled header function _compargv1_pch(self, pcheaderfile, pcoutputfile, flags) - local pchflags = {} -- remove "-Yuxxx.h" and "-Fpxxx.pch" + local pchflags = {} for _, flag in ipairs(flags) do if not flag:find("-Yu", 1, true) and not flag:find("-Fp", 1, true) then table.insert(pchflags, flag) @@ -375,8 +363,6 @@ end -- make the complie arguments list function _compargv1(self, sourcefile, objectfile, flags) - flags = _patch_pdbflags(objectfile, flags) - -- precompiled header? local extension = path.extension(sourcefile) if (extension:startswith(".h") or extension == ".inl") then @@ -428,7 +414,7 @@ function _compile1(self, sourcefile, objectfile, dependinfo, flags) local results = "" for _, line in ipairs(tostring(errors):split("\n", {plain = true})) do line = line:rtrim() - if not _include_note(self, line) then + if not _include_note(self, line) then results = results .. line .. "\r\n" end end diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index 856e5c47c..35318f37b 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -11,7 +11,7 @@ -- 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 @@ -60,21 +60,46 @@ end -- make the symbol flag function nf_symbol(self, level, target) - -- the maps - local maps = - { - debug = "-g -G" - } + -- debug? generate *.pdb file + local flags = nil + if level == "debug" then + flags = "-g -G" + if is_plat("windows") then + local host_flags = nil + local symbolfile = nil + if target and target.symbolfile then + symbolfile = target:symbolfile() + end + if symbolfile then - return maps[level] + -- ensure the object directory + local symboldir = path.directory(symbolfile) + if not os.isdir(symboldir) then + os.mkdir(symboldir) + end + + -- check and add symbol output file + host_flags = "-Zi -Fd" .. path.join(symboldir, "compile." .. path.filename(symbolfile)) + if self:has_flags({'-Xcompiler "-Zi -FS -Fd' .. os.tmpfile() .. '.pdb"'}, "cuflags") then + host_flags = "-FS " .. host_flags + end + else + host_flags = "-Zi" + end + flags = flags .. ' -Xcompiler "' .. host_flags .. '"' + end + end + + -- none + return flags end -- make the warning flag function nf_warning(self, level) -- the maps - local maps = - { + local maps = + { none = "-w" , everything = "-Wreorder" , error = "-Werror" @@ -82,7 +107,7 @@ function nf_warning(self, level) -- for cl.exe on windows local cl_maps = - { + { none = "-W0" , less = "-W1" , more = "-W3" @@ -90,19 +115,19 @@ function nf_warning(self, level) , everything = "-Wall" , error = "-WX" } - + -- for gcc & clang on linux, may be work for other gnu compatible compilers such as icc -- -- gcc dosen't support `-Weverything`, use `-Wall -Wextra -Weffc++` for it -- no warning will emit for unsupoorted `-W` flags by clang/gcc -- local gcc_clang_maps = - { + { none = "-w" , less = "-Wall" , more = "-Wall" - , all = "-Wall" - , everything = "-Weverything -Wall -Wextra -Weffc++" + , all = "-Wall" + , everything = "-Weverything -Wall -Wextra -Weffc++" , error = "-Werror" } @@ -150,7 +175,7 @@ function nf_language(self, stdname) -- the stdc++ maps if _g.cxxmaps == nil then - _g.cxxmaps = + _g.cxxmaps = { cxx03 = "--std c++03" , cxx11 = "--std c++11" @@ -261,21 +286,6 @@ function _compargv1(self, sourcefile, objectfile, flags) -- make argv local argv = table.join("-c", flags, "-o", objectfile, sourcefile) - -- insert -Fd flags - if is_plat("windows") then - local need_pdb = false - for _, flag in ipairs(flags) do - if flag:find("-g", 1, true) then - need_pdb = true - break - end - end - if need_pdb then - table.insert(argv, "-Xcompiler") - table.insert(argv, "-Fd" .. objectfile .. ".pdb") - end - end - -- uses cache? local program = self:program() if ccache then @@ -304,7 +314,7 @@ function _compile1(self, sourcefile, objectfile, dependinfo, flags) try { function () - -- support `-M -MF depfile.d`? + -- support `-M -MF depfile.d`? if depfile and _g._HAS_M_MF == nil then _g._HAS_M_MF = self:has_flags({"-M", "-MF", os.nuldev()}, "cuflags") or false end |
