diff options
| author | ruki <[email protected]> | 2022-08-11 00:53:18 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-08-11 00:53:18 +0800 |
| commit | ae1521c83b8d19b832b1fb1636ae2c22c299cac8 (patch) | |
| tree | ec3db9772f4bd9428f2fb91b166a1968e2120cd2 /xmake/modules | |
| parent | eb348d65c260d13a47bea41ee461fff95b9dfb60 (diff) | |
fix pcheader for msvc
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/private/action/build/pcheader.lua | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/xmake/modules/private/action/build/pcheader.lua b/xmake/modules/private/action/build/pcheader.lua index 91dcfb172..bc16bd29f 100644 --- a/xmake/modules/private/action/build/pcheader.lua +++ b/xmake/modules/private/action/build/pcheader.lua @@ -22,8 +22,29 @@ import("core.language.language") import("object") +function config(target, langkind, opt) + local pcheaderfile = target:pcheaderfile(langkind) + if pcheaderfile then + local headerfile = target:autogenfile(pcheaderfile) + if target:is_plat("windows") and + target:has_tool(langkind == "cxx" and "cxx" or "cc", "cl") then + -- fix `#pragma once` for msvc + -- https://github.com/xmake-io/xmake/issues/2667 + if not os.isfile(headerfile) then + io.writefile(headerfile, ([[ +#pragma system_header +#ifdef __cplusplus +#include "%s" +#endif // __cplusplus + ]]):format(path.absolute(pcheaderfile):gsub("\\", "/"))) + end + target:pcheaderfile_set(langkind, headerfile) + end + end +end + -- add batch jobs to build the precompiled header file -function main(target, langkind, opt) +function build(target, langkind, opt) local pcheaderfile = target:pcheaderfile(langkind) if pcheaderfile then local sourcefile = pcheaderfile |
