# Does cmake file name or content support Chinese characters

**URL:** <https://discourse.cmake.org/t/does-cmake-file-name-or-content-support-chinese-characters/5122>\
**Category:** Code\
**Tags:** os:windows\
**Created:** [February 26, 2022, 2:24am UTC](https://discourse.cmake.org/t/does-cmake-file-name-or-content-support-chinese-characters/5122 "2022-02-26T02:24:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xuexq](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/x/49beb7/32.png) [@Xuexq](https://discourse.cmake.org/u/Xuexq)\
**Post date:** [February 26, 2022, 2:24am UTC](https://discourse.cmake.org/t/does-cmake-file-name-or-content-support-chinese-characters/5122/1 "2022-02-26T02:24:56Z")

</div>

CMake 3.22.0  
1.If cmake file name contains Chinese characters, such as “中文工程\_files.cmake”, there is error  
Error information:  
CMake Error at cmake/FileUtil.cmake:26 (include):  
include could not find requested file:

```
???????_files.cmake

```

FileUtil.cmake:  
function(ly\_include\_cmake\_file\_list file)

```
set(UNITY_AUTO_EXCLUSIONS)

include(${file}) --line 26

```

1. Other errors  
The target name “Gem::???.Servers” is reserved or not valid for  
certain CMake features, such as generator expressions, and may result in  
undefined behavior.
2. Cmake content with chinese  
Code Example：
# Add the project\_name to global LY\_PROJECTS\_TARGET\_NAME property
file(READ “${CMAKE\_CURRENT\_LIST\_DIR}/project.json” project\_json)  
string(JSON project\_target\_name ERROR\_VARIABLE json\_error GET ${project\_json} “project\_name”)  
set\_property(GLOBAL APPEND PROPERTY LY\_PROJECTS\_TARGET\_NAME ${project\_target\_name})

If “project\_target\_name” contains Chinese characters, there is error, the printed project\_target\_name is ???.

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [February 26, 2022, 2:03pm UTC](https://discourse.cmake.org/t/does-cmake-file-name-or-content-support-chinese-characters/5122/2 "2022-02-26T14:03:35Z")

</div>

What encoding are you using for the file? CMake should support it, but it will need to be in UTF-8, not any of the other encodings usually in use.

---

<div class="post-metadata">

**Author:** ![Xuexq](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/x/49beb7/32.png) [@Xuexq](https://discourse.cmake.org/u/Xuexq)\
**Post date:** [February 28, 2022, 1:47am UTC](https://discourse.cmake.org/t/does-cmake-file-name-or-content-support-chinese-characters/5122/3 "2022-02-28T01:47:49Z")

</div>

> [@ben.boeckel](#):
>
> CMake should support it, but it will need to be in UTF-8,

GBK encoding

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [February 28, 2022, 3:25pm UTC](https://discourse.cmake.org/t/does-cmake-file-name-or-content-support-chinese-characters/5122/4 "2022-02-28T15:25:14Z")

</div>

Yes, CMake won’t support that literally in the file contents of any CMake source. You _can_ hack around it by writing the hex to a file and then reading it into a variable with `file(READ)`. This will allow you to do `include(path/to/${nonutf8bytes}.cmake")`. But this is obviously outside of the normal patterns; I recommend instead just using UTF-8 for your filenames here.

---

<div class="post-metadata">

**Author:** ![Xuexq](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/x/49beb7/32.png) [@Xuexq](https://discourse.cmake.org/u/Xuexq)\
**Post date:** [March 29, 2022, 1:47pm UTC](https://discourse.cmake.org/t/does-cmake-file-name-or-content-support-chinese-characters/5122/5 "2022-03-29T13:47:00Z")

</div>

I have a related question about add\_library.  
CMake file which runs successfully:  
cmake\_minimum\_required(VERSION 3.20)  
project(my)  
add\_library(myproject\_static STATIC MyProject/myproject.cpp)  
add\_executable(my Demo.cpp MyProject/myproject.h MyProject/myproject.cpp)

CMake file which has error:  
cmake\_minimum\_required(VERSION 3.20)  
project(my)  
add\_library(工程\_static STATIC MyProject/myproject.cpp)  
add\_executable(my Demo.cpp MyProject/myproject.h MyProject/myproject.cpp)

error info:  
CMake Error at D:\Code\CMakeLists.txt:3 (add\_library):  
The target name “工程\_static” is reserved or not valid for certain CMake features, such as generator expressions, and may result in undefined behavior.

How to fix the error? Does the first param of add\_library support chinese character?

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [March 29, 2022, 3:28pm UTC](https://discourse.cmake.org/t/does-cmake-file-name-or-content-support-chinese-characters/5122/6 "2022-03-29T15:28:20Z")

</div>

I suspect the name of the target should be ASCII. You can set `OUTPUT_NAME` to rename the resulting library at least.
