@@ -299,28 +299,6 @@ if(MSVC)
299299 # Disable deprecation warnings about POSIX function names such as setmode (replaced by the ISO C and C++ conformant name _setmode).
300300 # Disable deprecation warnings about unsafe CRT library functions such as fopen (replaced by fopen_s).
301301 target_compile_definitions (avif_enable_warnings INTERFACE _CRT_NONSTDC_NO_WARNINGS _CRT_SECURE_NO_WARNINGS)
302-
303- # clang-cl documentation says:
304- # /execution-charset:<value>
305- # Runtime encoding, supports only UTF-8
306- # ...
307- # /source-charset:<value> Source encoding, supports only UTF-8
308- # So we don't need to pass /source-charset:utf-8 to clang-cl, and we cannot pass /execution-charset:us-ascii to clang-cl.
309- if (CMAKE_C_COMPILER_ID MATCHES "MSVC" )
310- target_compile_options (
311- avif_obj
312- PUBLIC $<BUILD_INTERFACE:
313- # This tells MSVC to read source code as UTF-8 and assume console can only use ASCII (minimal safe).
314- # libavif uses ANSI API to print to console, which is not portable between systems using different
315- # languages and results in mojibake unless we only use codes shared by every code page: ASCII.
316- # A C4556 warning will be generated on violation.
317- # Commonly used /utf-8 flag assumes UTF-8 for both source and console, which is usually not the case.
318- # Warnings can be suppressed but there will still be random characters printed to the console.
319- /source -charset:utf-8
320- /execution-charset:us-ascii
321- >
322- )
323- endif ()
324302elseif (CMAKE_C_COMPILER_ID MATCHES "Clang" )
325303 message (STATUS "libavif: Enabling warnings for Clang" )
326304 target_compile_options (avif_enable_warnings INTERFACE -Wall -Wextra -Wshorten-64-to-32)
@@ -335,6 +313,30 @@ if(AVIF_ENABLE_WERROR)
335313 # Warnings as errors
336314 if (MSVC )
337315 target_compile_options (avif_enable_warnings INTERFACE /WX)
316+
317+ # The MSVC /source-charset:utf-8 /execution-charset:us-ascii options
318+ # validate that the source code contains only characters that can be
319+ # represented in UTF-8, and in addition the string and character
320+ # literals in the source code contain only characters that can be
321+ # represented in ASCII. If a character in a string or character literal
322+ # cannot be represented in ASCII, MSVC substitutes a question mark (?)
323+ # for the character and emits a C4566 warning. Therefore we only use
324+ # these options when warnings are treated as errors. Note that the
325+ # /execution-charset:us-ascii option does NOT prevent the executable
326+ # from receiving UTF-8 input or sending UTF-8 output. It also allows
327+ # string and character literals to contain UTF-8 characters encoded in
328+ # octal or hex escape sequences.
329+ #
330+ # clang-cl documentation says:
331+ # /execution-charset:<value>
332+ # Runtime encoding, supports only UTF-8
333+ # ...
334+ # /source-charset:<value> Source encoding, supports only UTF-8
335+ # So we don't need to pass /source-charset:utf-8 to clang-cl, and we
336+ # cannot pass /execution-charset:us-ascii to clang-cl.
337+ if (CMAKE_C_COMPILER_ID MATCHES "MSVC" )
338+ target_compile_options (avif_enable_warnings INTERFACE /source -charset:utf-8 /execution-charset:us-ascii)
339+ endif ()
338340 elseif (CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "GNU" )
339341 target_compile_options (avif_enable_warnings INTERFACE -Werror)
340342 else ()
0 commit comments