From 1c520959e8530c8c4bd5148589db385cb324c08f Mon Sep 17 00:00:00 2001 From: 0xb1aded Date: Wed, 29 Jul 2026 18:09:27 +0800 Subject: fix set_pcheader for msvc in c mode --- xmake/modules/private/action/build/pcheader.lua | 16 ++++++++++++++-- 1 file 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 -- cgit v1.3.1