diff options
| author | ruki <[email protected]> | 2026-01-27 00:46:04 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-01-27 00:46:04 +0800 |
| commit | d0fa1e1927c4085921bddfbfda64c767f052098e (patch) | |
| tree | dd74ef8734030b84b999e70cab6092d2191ced35 | |
| parent | 8ba2870f97ce1213f4a95f95cee1e6b1369916c2 (diff) | |
fix pch for cl
| -rw-r--r-- | xmake/modules/core/tools/cl.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 21 | ||||
| -rw-r--r-- | xmake/modules/private/utils/toolchain.lua | 19 |
3 files changed, 24 insertions, 21 deletions
diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index 34be37513..a28d049c3 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -26,6 +26,7 @@ import("core.cache.memcache") import("core.project.project") import("core.project.policy") import("core.language.language") +import("private.utils.toolchain", {alias = "toolchain_utils"}) import("private.tools.vstool") import("core.tools.cl.parse_include") import("private.cache.build_cache") @@ -557,7 +558,7 @@ function _preprocess(program, argv, opt) flag:startswith("-external:") or flag:startswith("/external:") then skipped = 1 -- @note we cannot ignore precompiled flags when compiling pch, @see https://github.com/xmake-io/xmake/issues/2885 - elseif not extension:startswith(".h") and ( + elseif not toolchain_utils.is_cxx_headerext(extension) and ( flag:startswith("-Yu") or flag:startswith("/Yu") or flag:startswith("-FI") or flag:startswith("/FI") or flag:startswith("-Fp") or flag:startswith("/Fp")) then @@ -671,7 +672,7 @@ function compargv(self, sourcefile, objectfile, flags, opt) -- precompiled header? local extension = path.extension(sourcefile) - if (extension:startswith(".h") or extension == ".inl") then + if toolchain_utils.is_cxx_headerext(extension) then return _compargv_pch(self, sourcefile, objectfile, flags) end diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index 9cc46e9f2..d390d8884 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -23,10 +23,10 @@ import("core.base.option") import("core.base.tty") import("core.base.colors") import("core.base.global") -import("core.base.hashset") import("core.cache.memcache") import("core.project.config") import("core.project.policy") +import("private.utils.toolchain", {alias = "toolchain_utils"}) import("core.project.project") import("core.language.language") import("utils.progress") @@ -981,30 +981,13 @@ function link(self, objectfiles, targetkind, targetfile, flags, opt) end end --- check if the file is a header file -function _is_header_file(extension) - if extension:startswith(".h") then - return true - end - - local headerexts = _g.headerexts - if not headerexts then - local other_header_extensions = { - ".inl", ".ipp", ".tcc", ".tpl", ".inc" - } - headerexts = hashset.from(other_header_extensions) - _g.headerexts = headerexts - end - return headerexts:has(extension) or false -end - -- make the compile arguments list function compargv(self, sourcefile, objectfile, flags, opt) opt = opt or {} -- is precompiled header or module files? remove the force includes. local extension = path.extension(sourcefile) - if _is_header_file(extension) then + if toolchain_utils.is_cxx_headerext(extension) then flags = _translate_flags_for_pch(self, flags) elseif support.has_module_extension(sourcefile, {extension = extension}) then flags = _translate_flags_for_mpp(self, flags) diff --git a/xmake/modules/private/utils/toolchain.lua b/xmake/modules/private/utils/toolchain.lua index 263137300..b1a26b8da 100644 --- a/xmake/modules/private/utils/toolchain.lua +++ b/xmake/modules/private/utils/toolchain.lua @@ -22,6 +22,7 @@ import("core.base.option") import("core.project.config") import("core.base.semver") +import("core.base.hashset") import("core.tool.linker") import("core.tool.compiler") import("core.language.language") @@ -555,3 +556,21 @@ function get_sanitizer_flags(target, opt) end return result end + +-- check if the file is a c++ header file extension +function is_cxx_headerext(extension) + -- prioritize .h* extensions to filter out most cases quickly + if extension:startswith(".h") then + return true + end + + local headerexts = _g.headerexts + if not headerexts then + local other_header_extensions = { + ".inl", ".ipp", ".tcc", ".tpl", ".inc" + } + headerexts = hashset.from(other_header_extensions) + _g.headerexts = headerexts + end + return headerexts:has(extension) or false +end |
