summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2026-01-27 11:47:53 +0800
committerGitHub <[email protected]>2026-01-27 11:47:53 +0800
commitefe8fc122c04fb05a80488e39ddb19d802e6a409 (patch)
tree3ad925a1a0f31771e7ce20c8c94524f21527445d /xmake/modules
parentb55dade1f55c21c498faa39463c5122b1a3bac22 (diff)
parentb41e1092c8b309d76ad093ebb519fcdf0a79d7fb (diff)
Merge pull request #7266 from xmake-io/pch
fix pch header extension
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/core/tools/cl.lua5
-rw-r--r--xmake/modules/core/tools/gcc.lua3
-rw-r--r--xmake/modules/private/utils/toolchain.lua19
3 files changed, 24 insertions, 3 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 6fc7a641b..d390d8884 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -26,6 +26,7 @@ import("core.base.global")
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")
@@ -986,7 +987,7 @@ function compargv(self, sourcefile, objectfile, flags, opt)
-- is precompiled header or module files? remove the force includes.
local extension = path.extension(sourcefile)
- if (extension:startswith(".h") or extension == ".inl") 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