如何在 CMake 中使用非 ascii 字符 add_executable

How to use non ascii characters in CMake add_executable

例如,在CmakeLists.txt中:

add_executable( ❤ test.cpp )

将导致:

CMake Error at CMakeLists.txt:37 (add_executable):
  The target name "❤" is reserved or not valid for certain CMake features,
  such as generator expressions, and may result in undefined behavior.

我认为今天使用非 ascii 字符非常简单,如何让 CMake 支持它?

您的选项仅限于可以用作目标名称的内容,但使用 OUTPUT_NAME 属性.

可以提供更大的灵活性

工作示例:

add_executable(heart test.cpp)
set_target_properties(heart PROPERTIES
    OUTPUT_NAME ❤
)

输出:

$ make
[ 50%] Building CXX object CMakeFiles/heart.dir/test.cpp.o
[100%] Linking CXX executable ❤
[100%] Built target heart