Visual Studio Generator: Setting Unicode character-set is inconsistent
I am using the Visual Studio (2022) Generator and noticed that in the generated *.vcxproj
files the tag CharacterSet
has value MultiByte
, although I wanted it to have Unicode
.
I know that MSVC respects the macros _UNICODE
and UNICODE
and I was already setting these via add_compile_definitions
:
add_compile_definitions(_UNICODE=1 UNICODE=1)
By some googling, I found the following CMake issue: #12189 (closed)
From that I learned, that settings _UNICODE
via add_definitions
should result in the tag CharacterSet
in the generated *.vcxproj
files to contain the value Unicode
.
And indeed, using add_definitions(-D_UNICODE)
results in the generated *.vcxproj
file to set Unicode as character-set.
However, using add_compile_definitions(-D_UNICODE)
or add_compile_definitions(_UNICODE=1)
does not have the same effect. Interestingly add_compile_definitions(_UNICODE)
works again.
I would suggest to unify the behavior so that it does not matter if _UNICODE
is set with or without value, with or without -D
prefix and with add_compile_definitions
or add_definitions
.