summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchooyy <[email protected]>2026-06-04 15:52:38 +0800
committerchooyy <[email protected]>2026-06-04 15:52:38 +0800
commitea2d5d2454167ee9fe293427df729ff60baee22f (patch)
tree62fa242264cbe84584917414fb0760602e669869
parentc2dd4195391125636743b9ebb70a794349a6f7ce (diff)
support set_encodings with nvcc
-rw-r--r--xmake/languages/cuda/xmake.lua1
-rw-r--r--xmake/modules/core/tools/nvcc.lua52
2 files changed, 53 insertions, 0 deletions
diff --git a/xmake/languages/cuda/xmake.lua b/xmake/languages/cuda/xmake.lua
index ae43f7fc0..2ae6e26a0 100644
--- a/xmake/languages/cuda/xmake.lua
+++ b/xmake/languages/cuda/xmake.lua
@@ -40,6 +40,7 @@ language("cuda")
, "target.vectorexts:check"
, "target.includedirs"
, "target.languages"
+ , "target.encodings"
, "target.defines"
, "target.undefines"
, "toolchain.includedirs"
diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua
index 41ae28274..2b9eea319 100644
--- a/xmake/modules/core/tools/nvcc.lua
+++ b/xmake/modules/core/tools/nvcc.lua
@@ -227,6 +227,58 @@ function nf_language(self, stdname)
return result
end
+-- make the encoding flag
+--
+-- 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 self:is_plat("windows") then
+ if not kind and charset == "utf-8" then
+ table.insert(flags, "-Xcompiler")
+ table.insert(flags, "/utf-8")
+ else
+ if kind == "source" or not kind then
+ table.insert(flags, "-Xcompiler")
+ table.insert(flags, "-source-charset:" .. charset)
+ end
+ if kind == "target" or not kind then
+ table.insert(flags, "-Xcompiler")
+ table.insert(flags, "-execution-charset:" .. charset)
+ end
+ end
+ else
+ if kind == "source" or not kind then
+ table.insert(flags, "-Xcompiler")
+ table.insert(flags, "-finput-charset=" .. charset:upper())
+ end
+ if kind == "target" or not kind then
+ table.insert(flags, "-Xcompiler")
+ table.insert(flags, "-fexec-charset=" .. charset:upper())
+ end
+ end
+ end
+ if #flags > 0 then
+ return flags
+ end
+end
+
-- make the define flag
function nf_define(self, macro)
return {"-D" .. macro}