summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-08-21 22:49:59 +0800
committerGitHub <[email protected]>2023-08-21 22:49:59 +0800
commitd5598c616c00829a488dc1ff9fb9958866589c9f (patch)
treec5c9daee7717465c8cad1a1f799af4f7c6a96d19
parentbba45b29a174e83ff6aff784e7aaec27bccb9ac0 (diff)
parent960c7ab7c59e6bb5c9578f5fb4c7b0182399becd (diff)
Merge pull request #4103 from xmake-io/includes
add force includes #4101
-rw-r--r--CHANGELOG.md2
-rw-r--r--xmake/languages/c++/load.lua1
-rw-r--r--xmake/languages/c++/xmake.lua1
-rw-r--r--xmake/languages/objc++/load.lua1
-rw-r--r--xmake/languages/objc++/xmake.lua1
-rw-r--r--xmake/modules/core/tools/cl.lua8
-rw-r--r--xmake/modules/core/tools/gcc.lua8
7 files changed, 22 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 926165584..1aebcb1c4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@
* [#1613](https://github.com/xmake-io/xmake/issues/1613): Add avx512 and sse4.2 for add_vectorexts
* [#2471](https://github.com/xmake-io/xmake/issues/2471): Add set_encodings to set source/target encodings
* [#4071](https://github.com/xmake-io/xmake/pull/4071): Support the stm8 assembler on the sdcc toolchain.
+* [#4101](https://github.com/xmake-io/xmake/issues/4101): Add force includes for c/c++
### Changes
@@ -1634,6 +1635,7 @@
* [#1613](https://github.com/xmake-io/xmake/issues/1613): 为 add_vectorexts 增加 avx512 和 sse4.2 支持
* [#2471](https://github.com/xmake-io/xmake/issues/2471): 添加 set_encodings API 去设置源文件和目标文件的编码
* [#4071](https://github.com/xmake-io/xmake/pull/4071): 支持 sdcc 的 stm8 汇编器
+* [#4101](https://github.com/xmake-io/xmake/issues/4101): 为 c/c++ 添加 force includes
### 改进
diff --git a/xmake/languages/c++/load.lua b/xmake/languages/c++/load.lua
index 828385f6f..ff251e778 100644
--- a/xmake/languages/c++/load.lua
+++ b/xmake/languages/c++/load.lua
@@ -35,6 +35,7 @@ function _get_apis()
, "target.add_undefines"
, "target.add_frameworks"
, "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path
+ , "target.add_forceincludes"
-- option.add_xxx
, "option.add_cincludes"
, "option.add_cxxincludes"
diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua
index 2df4ba6c9..e07b9e294 100644
--- a/xmake/languages/c++/xmake.lua
+++ b/xmake/languages/c++/xmake.lua
@@ -51,6 +51,7 @@ language("c++")
, "target.encodings"
, "target.pcheader"
, "target.pcxxheader"
+ , "target.forceincludes"
, "toolchain.includedirs"
, "toolchain.defines"
, "toolchain.undefines"
diff --git a/xmake/languages/objc++/load.lua b/xmake/languages/objc++/load.lua
index 2b12871b3..b41ef77f3 100644
--- a/xmake/languages/objc++/load.lua
+++ b/xmake/languages/objc++/load.lua
@@ -34,6 +34,7 @@ function _get_apis()
, "target.add_undefines"
, "target.add_frameworks"
, "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path
+ , "target.add_forceincludes"
-- option.add_xxx
, "option.add_cincludes"
, "option.add_cxxincludes"
diff --git a/xmake/languages/objc++/xmake.lua b/xmake/languages/objc++/xmake.lua
index edea6c5bd..00fae204b 100644
--- a/xmake/languages/objc++/xmake.lua
+++ b/xmake/languages/objc++/xmake.lua
@@ -70,6 +70,7 @@ language("objc++")
, "target.encodings"
, "target.pmheader"
, "target.pmxxheader"
+ , "target.forceincludes"
, "toolchain.includedirs"
, "toolchain.defines"
, "toolchain.undefines"
diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua
index b043370d1..069c96d86 100644
--- a/xmake/modules/core/tools/cl.lua
+++ b/xmake/modules/core/tools/cl.lua
@@ -281,6 +281,14 @@ function nf_includedir(self, dir)
return {"-I" .. path.translate(dir)}
end
+-- make the force include flag
+function nf_forceinclude(self, headerfile, target)
+ local sourcekinds = target and target:extraconf("forceincludes", headerfile, "sourcekinds")
+ if not sourcekinds or table.contains(table.wrap(sourcekinds), self:kind()) then
+ return {"-FI", headerfile}
+ end
+end
+
-- make the sysincludedir flag
function nf_sysincludedir(self, dir)
local has_external_includedir = _g._HAS_EXTERNAL_INCLUDEDIR
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index 60bfc8e5e..84b0aca4a 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -278,6 +278,14 @@ function nf_sysincludedir(self, dir)
return {"-isystem", path.translate(dir)}
end
+-- make the force include flag
+function nf_forceinclude(self, headerfile, target)
+ local sourcekinds = target and target:extraconf("forceincludes", headerfile, "sourcekinds")
+ if not sourcekinds or table.contains(table.wrap(sourcekinds), self:kind()) then
+ return {"-include", headerfile}
+ end
+end
+
-- make the link flag
function nf_link(self, lib)
if lib:endswith(".a") or lib:endswith(".so") or lib:endswith(".dylib") or lib:endswith(".lib") then