Fix #12197: Force set /utf-8 for msvc compilers (#12198)

The MSVC compiler determines the encoding of the source code based on
the BOM of the source code when reading it. If there is no BOM, it
defaults to the local encoding, which is gb2312, codepage 936, on
Simplified Chinese Windows. This can cause errors such as newline
characters in strings.
This commit is contained in:
Quan Zhuo
2025-02-07 01:34:41 +08:00
committed by GitHub
parent 8397e1fcc0
commit c9341489cc
35 changed files with 188 additions and 0 deletions

View File

@@ -13,6 +13,12 @@ else()
set(SDL3_MAINPROJECT OFF)
endif()
# Add UTF-8 encoding support for MSVC compiler.
# This ensures that the MSVC compiler interprets source files as UTF-8 encoded,
# which is useful for projects containing non-ASCII characters in source files.
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
# By default, configure SDL3 in RelWithDebInfo configuration
if(SDL3_MAINPROJECT)
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)