diff options
| author | ruki <[email protected]> | 2023-07-28 22:35:12 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-07-28 22:35:12 +0800 |
| commit | 3ce4679ace52d987ca028a57e6f3e265b6e6e914 (patch) | |
| tree | 178b9d99b25fd9c78d6c914ff925e3cf05afc9ea /xmake/modules | |
| parent | e14f298f88acfa8417eaa1c26e43ac8f345fd763 (diff) | |
add set_encodings
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/core/tools/cl.lua | 39 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 35 |
2 files changed, 74 insertions, 0 deletions
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 |
