summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-07-28 22:35:12 +0800
committerruki <[email protected]>2023-07-28 22:35:12 +0800
commit3ce4679ace52d987ca028a57e6f3e265b6e6e914 (patch)
tree178b9d99b25fd9c78d6c914ff925e3cf05afc9ea
parente14f298f88acfa8417eaa1c26e43ac8f345fd763 (diff)
add set_encodings
-rw-r--r--xmake/core/project/target.lua1
-rw-r--r--xmake/languages/c++/xmake.lua1
-rw-r--r--xmake/languages/objc++/xmake.lua2
-rw-r--r--xmake/modules/core/tools/cl.lua39
-rw-r--r--xmake/modules/core/tools/gcc.lua35
5 files changed, 78 insertions, 0 deletions
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index e0b2ebdd2..0a1c68a4a 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -2496,6 +2496,7 @@ function target.apis()
, "target.set_toolchains"
, "target.set_runargs"
, "target.set_exceptions"
+ , "target.set_encodings"
-- target.add_xxx
, "target.add_deps"
, "target.add_rules"
diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua
index 4109ab50b..2df4ba6c9 100644
--- a/xmake/languages/c++/xmake.lua
+++ b/xmake/languages/c++/xmake.lua
@@ -48,6 +48,7 @@ language("c++")
, "target.frameworkdirs"
, "target.frameworks"
, "target.exceptions"
+ , "target.encodings"
, "target.pcheader"
, "target.pcxxheader"
, "toolchain.includedirs"
diff --git a/xmake/languages/objc++/xmake.lua b/xmake/languages/objc++/xmake.lua
index b40ab52e6..edea6c5bd 100644
--- a/xmake/languages/objc++/xmake.lua
+++ b/xmake/languages/objc++/xmake.lua
@@ -66,6 +66,8 @@ language("objc++")
, "target.undefines"
, "target.frameworkdirs"
, "target.frameworks"
+ , "target.exceptions"
+ , "target.encodings"
, "target.pmheader"
, "target.pmxxheader"
, "toolchain.includedirs"
diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua
index aa8c9aba1..b043370d1 100644
--- a/xmake/modules/core/tools/cl.lua
+++ b/xmake/modules/core/tools/cl.lua
@@ -315,6 +315,45 @@ function nf_exception(self, exp)
return maps[exp]
end
+-- make the encoding flag
+-- @see https://github.com/xmake-io/xmake/issues/2471
+--
+-- e.g.
+-- set_encodings("utf-8")
+-- set_encodings("source:utf-8", "target:utf-8")
+function nf_encoding(self, encoding)
+ local kind
+ local charset
+ local splitinfo = encoding:split(":")
+ if #splitinfo > 1 then
+ kind = splitinfo[1]
+ charset = splitinfo[2]
+ else
+ charset = encoding
+ end
+ local charsets = {
+ ["utf-8"] = "utf-8",
+ utf8 = "utf-8"
+ }
+ local flags = {}
+ charset = charsets[charset:lower()]
+ if charset then
+ if not kind and charset == "utf-8" then
+ table.insert(flags, "/utf-8")
+ else
+ if kind == "source" or not kind then
+ table.insert(flags, "-source-charset=" .. charset)
+ end
+ if kind == "target" or not kind then
+ table.insert(flags, "-execution-charset=" .. charset)
+ end
+ end
+ end
+ if #flags > 0 then
+ return flags
+ end
+end
+
-- make the c precompiled header flag
function nf_pcheader(self, pcheaderfile, target)
if self:kind() == "cc" then
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index b45c04119..60bfc8e5e 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -337,6 +337,41 @@ function nf_exception(self, exp)
return exp:startswith("no-") and "-fno-exceptions" or "-fexceptions"
end
+-- make the encoding flag
+-- @see https://github.com/xmake-io/xmake/issues/2471
+--
+-- e.g.
+-- set_encodings("utf-8")
+-- set_encodings("source:utf-8", "target:utf-8")
+function nf_encoding(self, encoding)
+ local kind
+ local charset
+ local splitinfo = encoding:split(":")
+ if #splitinfo > 1 then
+ kind = splitinfo[1]
+ charset = splitinfo[2]
+ else
+ charset = encoding
+ end
+ local charsets = {
+ ["utf-8"] = "UTF-8",
+ utf8 = "UTF-8"
+ }
+ local flags = {}
+ charset = charsets[charset:lower()]
+ if charset then
+ if kind == "source" or not kind then
+ table.insert(flags, "-finput-charset=" .. charset)
+ end
+ if kind == "target" or not kind then
+ table.insert(flags, "-fexec-charset=" .. charset)
+ end
+ end
+ if #flags > 0 then
+ return flags
+ end
+end
+
-- make the c precompiled header flag
function nf_pcheader(self, pcheaderfile, target)
if self:kind() == "cc" then