diff options
| author | ruki <[email protected]> | 2024-08-05 22:53:42 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-08-05 22:53:42 +0800 |
| commit | c3ce0d90e7ee0aec14d4bed9e91bcfa40ca7d56c (patch) | |
| tree | 4b61b8b6fc947f7403de396f2f3b7ca8723857de | |
| parent | 0c1486f23f87c6fca5b77938c8f524a0306430e6 (diff) | |
improve pch filename for msvc #5413
| -rw-r--r-- | xmake/core/project/target.lua | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index e19ea07c5..c8c6606fc 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -2322,14 +2322,17 @@ function _instance:pcoutputfile(langkind) -- get the precompiled header file in the object directory local pcheaderfile = self:pcheaderfile(langkind) if pcheaderfile then - - -- is gcc? local is_gcc = false + local is_msvc = false local sourcekinds = {c = "cc", cxx = "cxx", m = "mm", mxx = "mxx"} local sourcekind = assert(sourcekinds[langkind], "unknown language kind: " .. langkind) local _, toolname = self:tool(sourcekind) - if toolname and (toolname == "gcc" or toolname == "gxx") then - is_gcc = true + if toolname then + if toolname == "gcc" or toolname == "gxx" then + is_gcc = true + elseif toolname == "cl" then + is_msvc = true + end end -- make precompiled output file @@ -2337,7 +2340,27 @@ function _instance:pcoutputfile(langkind) -- @note gcc has not -include-pch option to set the pch file path -- pcoutputfile = self:objectfile(pcheaderfile) - pcoutputfile = path.join(path.directory(pcoutputfile), sourcekind, path.basename(pcoutputfile) .. (is_gcc and ".gch" or ".pch")) + local pcoutputfilename = path.basename(pcoutputfile) + if is_gcc then + pcoutputfilename = pcoutputfilename .. ".gch" + else + -- different vs versions of pch files are not backward compatible, + -- so we need to distinguish between them. + -- + -- @see https://github.com/xmake-io/xmake/issues/5413 + local msvc = self:toolchain("msvc") + if is_msvc and msvc then + local vs_toolset = msvc:config("vs_toolset") + if vs_toolset then + vs_toolset = sandbox_module.import("private.utils.toolchain", {anonymous = true}).get_vs_toolset_ver(vs_toolset) + end + if vs_toolset then + pcoutputfilename = pcoutputfilename .. "_" .. vs_toolset + end + end + pcoutputfilename = pcoutputfilename .. ".pch" + end + pcoutputfile = path.join(path.directory(pcoutputfile), sourcekind, pcoutputfilename) self._PCOUTPUTFILES[langkind] = pcoutputfile return pcoutputfile end |
