Skip to content

Commit

Permalink
build: set /utf-8 flag when using MSVC (#4975)
Browse files Browse the repository at this point in the history
MSVC by default decodes source files in the current Windows code page if
they don't have a Unicode BOM, and also encodes strings and chars into
the current code page before storing them into the compiled binary. Our
files are always encoded in UTF-8, and our code always assumes runtime
strings are encoded in UTF-8, so we should pass the `/utf-8` flag to
MSVC.

Microsoft Docs:
https://learn.microsoft.com/en-us/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8
  • Loading branch information
fghzxm committed Feb 22, 2023
1 parent 9d1a141 commit e2b6dc4
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Expand Up @@ -181,6 +181,8 @@ if(WIN32)
# Ignore various deprecation and security warnings (at least for now)
set(CMAKE_${L}_FLAGS "${CMAKE_${L}_FLAGS} -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS")
if(MSVC)
# Set source file encoding and execution charset to UTF-8
set(CMAKE_${L}_FLAGS "${CMAKE_${L}_FLAGS} /utf-8")
# Reduce noise (at least for now)
set(CMAKE_${L}_FLAGS "${CMAKE_${L}_FLAGS} /wd4244 /wd4267")
# Make caching-friendly (store debug info inside object files)
Expand Down

0 comments on commit e2b6dc4

Please sign in to comment.