summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-07-31 23:43:58 +0800
committerGitHub <[email protected]>2026-07-31 23:43:58 +0800
commitb41ed3acf227011f4904d95a439a30be9580e5cf (patch)
tree0acb0a92e5692fe0cf642162d51b517d1d92c160
parentbafb5d4b802017b8d6c3583fee26574d902abc6b (diff)
parent1c520959e8530c8c4bd5148589db385cb324c08f (diff)
Merge pull request #7679 from 0xb1aded/fix/msvc-pcheader
fix set_pcheader for msvc in c mode
-rw-r--r--xmake/modules/private/action/build/pcheader.lua16
1 files changed, 14 insertions, 2 deletions
diff --git a/xmake/modules/private/action/build/pcheader.lua b/xmake/modules/private/action/build/pcheader.lua
index 4e984f62b..1682ead8c 100644
--- a/xmake/modules/private/action/build/pcheader.lua
+++ b/xmake/modules/private/action/build/pcheader.lua
@@ -38,12 +38,24 @@ function config(target, langkind, opt)
-- https://github.com/xmake-io/xmake/issues/2667
-- https://github.com/xmake-io/xmake/issues/5858
if not os.isfile(headerfile) then
- io.writefile(headerfile, ([[
+ local langcxx = (langkind == "cxx" or langkind == "mxx")
+ local content
+ if langcxx then
+ content = [[
#pragma system_header
#ifdef __cplusplus
#include "%s"
#endif // __cplusplus
- ]]):format(path.absolute(pcheaderfile):gsub("\\", "/")))
+ ]]
+ else
+ content = [[
+#pragma system_header
+#ifndef __cplusplus
+#include "%s"
+#endif
+ ]]
+ end
+ io.writefile(headerfile, content:format(path.absolute(pcheaderfile):gsub("\\", "/")))
end
-- we need only to add a header wrapper in .gch directory
-- @see https://github.com/xmake-io/xmake/issues/5858#issuecomment-2506918167