Possible to force CMake/MSVC to use UTF-8 encoding for source files without a BOM? C4819
问题 All our source code is valid UTF-8, however some users on Windows cannot build them because their system is configured for a different encoding. Without adding a BOM to source files, is it possible to tell MSVC to treat all source as UTF-8, irrespective of the users system encoding? See MSDN's link regarding this topic (requires adding BOM header). 回答1: You can try: add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>") add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>") By default,