# Passing UTF-16 strings from CPack to NSIS

**URL:** https://discourse.cmake.org/t/passing-utf-16-strings-from-cpack-to-nsis/2646
**Category:** Usage
**Created:** [January 28, 2021, 7:46am UTC](https://discourse.cmake.org/t/passing-utf-16-strings-from-cpack-to-nsis/2646 "2021-01-28T07:46:26Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![baleboy](https://discourse.cmake.org/user_avatar/discourse.cmake.org/baleboy/32/1148_2.png) [@baleboy](https://discourse.cmake.org/u/baleboy)
#### Post date: [January 28, 2021, 7:46am UTC](https://discourse.cmake.org/t/passing-utf-16-strings-from-cpack-to-nsis/2646/1 "2021-01-28T07:46:26Z")

</div>

Hello,

I’m working with a project that uses the CPack NSIS generator. I would like to display the “registered trademark” (®) symbol in the installer text, but I haven’t been able to make it work. I added the character directly to CPACK\_NSIS\_PACKAGE\_NAME but it appears garbled in the installer text.

AFAICT the symbol is UTF-16 and NSIS would accept it, but since CMake requires UTF-8 files I can’t use UTF-16 characters in CPACK\_NSIS\_PACKAGE\_NAME

Any help would be appreciated, thanks!

Francesco

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [January 28, 2021, 8:40am UTC](https://discourse.cmake.org/t/passing-utf-16-strings-from-cpack-to-nsis/2646/2 "2021-01-28T08:40:21Z")

</div>

> [@baleboy](#):
>
> AFAICT the symbol is UTF-16 and NSIS would accept it, but since CMake requires UTF-8 files I can’t use UTF-16 characters in CPACK\_NSIS\_PACKAGE\_NAME

Symbols aren’t “UTF-8” or “UTF-16”. UTF-8 and UTF-16 are just different encodings of Unicode. Any Unicode character can be expressed in both UTF-8 and UTF-16.

> [@baleboy](#):
>
> I added the character directly to CPACK\_NSIS\_PACKAGE\_NAME but it appears garbled in the installer text.

How exactly have you added the character? Can you verify in a hex editor that the file which includes it represents it as the two bytes `0xC2 0xAE` (which is the UTF-8 encoding of “®”)?

---

<div class="post-metadata">

### Author: ![baleboy](https://discourse.cmake.org/user_avatar/discourse.cmake.org/baleboy/32/1148_2.png) [@baleboy](https://discourse.cmake.org/u/baleboy)
#### Post date: [January 28, 2021, 9:28am UTC](https://discourse.cmake.org/t/passing-utf-16-strings-from-cpack-to-nsis/2646/3 "2021-01-28T09:28:58Z")

</div>

Thanks for the reply!

I inserted the character using the Sublime Text Unicode Insert addon, it shows up as “bla ®”

In the installer the ® is shown after an additional character, see attached screenshot below.

![registered](https://discourse.cmake.org/uploads/default/original/2X/b/b8783dd798642d4be2b139e677fcf8332e855c54.png)

Using a Hex viewer, it does seem that the character is saved as 0xC2 0xAE and the same seems to be true for the produced project.nsi. So maybe this is a NSIS issue after all?

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [January 28, 2021, 10:10am UTC](https://discourse.cmake.org/t/passing-utf-16-strings-from-cpack-to-nsis/2646/4 "2021-01-28T10:10:03Z")

</div>

> [@baleboy](#):
>
> So maybe this is a NSIS issue after all?

Could be. Unfortunately, I have zero experience with NSIS, so I can’t comment further. Hopefully someone else can chime in.

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [January 28, 2021, 10:46am UTC](https://discourse.cmake.org/t/passing-utf-16-strings-from-cpack-to-nsis/2646/5 "2021-01-28T10:46:29Z")

</div>

How do you output this string? Which version of NSIS are you using?

---

<div class="post-metadata">

### Author: ![baleboy](https://discourse.cmake.org/user_avatar/discourse.cmake.org/baleboy/32/1148_2.png) [@baleboy](https://discourse.cmake.org/u/baleboy)
#### Post date: [January 28, 2021, 10:52am UTC](https://discourse.cmake.org/t/passing-utf-16-strings-from-cpack-to-nsis/2646/6 "2021-01-28T10:52:17Z")

</div>

> Which version of NSIS are you using?

NSIS v3.06.1

> How do you output this string?

I enter the string in the CMake file (CMakeLists.txt), then run cmake which I understand will generate the NSIS file and run NSIS to create the package.

I saved the project.nsi produced by CPack (?) as UTF-16 LE with BOM and ran NSIS manually, and the character was shown correctly. It would seem that the issue is that CPack produces an UTF-8 encoded file but NSIS would need UTF-16 at least for this kind of special characters.

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [January 28, 2021, 1:22pm UTC](https://discourse.cmake.org/t/passing-utf-16-strings-from-cpack-to-nsis/2646/7 "2021-01-28T13:22:39Z")

</div>

Keep the file as UTF-8 and add “Unicode true”, see  
[https://nsis.sourceforge.io/Reference/Unicode](https://nsis.sourceforge.io/Reference/Unicode) or add UTF-BOM or upgrade to latest CMake as the latest change on the NSIS.template.in file looks like being supposed to handle this, see [https://gitlab.kitware.com/cmake/cmake/-/issues/21318](https://gitlab.kitware.com/cmake/cmake/-/issues/21318)

---

<div class="post-metadata">

### Author: ![baleboy](https://discourse.cmake.org/user_avatar/discourse.cmake.org/baleboy/32/1148_2.png) [@baleboy](https://discourse.cmake.org/u/baleboy)
#### Post date: [January 28, 2021, 2:00pm UTC](https://discourse.cmake.org/t/passing-utf-16-strings-from-cpack-to-nsis/2646/8 "2021-01-28T14:00:21Z")

</div>

> [@hsattler](#):
>
> Keep the file as UTF-8 and add “Unicode true”

Thanks for the suggestion! If I’m reading the tags correctly, the Unicode fix will be in Cmake 3.20 which is not yet released, and because of constraints in the environment I work with I can’t update to that version. What would be the way to add “Unicode true” to CMakeLists.txt so that it propagates to the .nis file?

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [January 28, 2021, 4:48pm UTC](https://discourse.cmake.org/t/passing-utf-16-strings-from-cpack-to-nsis/2646/9 "2021-01-28T16:48:17Z")

</div>

The CPACK\_NSIS\_DEFINES looks promising. Probably only via CPackConfig.cmake file, though

---

<div class="post-metadata">

### Author: ![baleboy](https://discourse.cmake.org/user_avatar/discourse.cmake.org/baleboy/32/1148_2.png) [@baleboy](https://discourse.cmake.org/u/baleboy)
#### Post date: [January 28, 2021, 7:19pm UTC](https://discourse.cmake.org/t/passing-utf-16-strings-from-cpack-to-nsis/2646/10 "2021-01-28T19:19:19Z")

</div>

I tried adding “Unicode true” and “!define Unicode true” at the beginning of NSIS.template.in but the result was the same.

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [January 28, 2021, 10:25pm UTC](https://discourse.cmake.org/t/passing-utf-16-strings-from-cpack-to-nsis/2646/11 "2021-01-28T22:25:31Z")

</div>

Hmm, then the documentation of NSIS is misleading. Could be. Not the first time. 😅

You could just convert the template to UTF-8 with BOM after CMake installation until a version with the change is available…

---

<div class="post-metadata">

### Author: ![baleboy](https://discourse.cmake.org/user_avatar/discourse.cmake.org/baleboy/32/1148_2.png) [@baleboy](https://discourse.cmake.org/u/baleboy)
#### Post date: [January 29, 2021, 4:06am UTC](https://discourse.cmake.org/t/passing-utf-16-strings-from-cpack-to-nsis/2646/12 "2021-01-29T04:06:21Z")

</div>

> [@hsattler](#):
>
> You could just convert the template to UTF-8 with BOM

Yes, that worked, thank you very much for your help!
