Skip to content

Enable UTF-8 Source Encoding for MSVC via CMake #1226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

xiaobing318
Copy link
Contributor

Add conditional CMake compiler options so that when building with MSVC, both C and C++ sources are compiled with UTF-8 encoding (/utf-8). By default, MSVC uses the system code page and will warn (C4819) or fail when encountering non-ASCII characters in source files. This change eliminates those encoding warnings without requiring BOMs or pragmas in the code, ensures consistent UTF-8 handling across platforms, and keeps existing build processes for other toolchains unchanged.

CMakeLists.txt Outdated
Comment on lines 46 to 49
if (MSVC)
add_compile_options("$<$<COMPILE_LANGUAGE:C>:/utf-8>")
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/utf-8>")
endif()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a if (MSVC) block at the bottom of this file, move this there to keep all the MSVC-specific settings together.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, I will modify it according to your suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a if (MSVC) block at the bottom of this file, move this there to keep all the MSVC-specific settings together.

Move /utf-8 and /bigobj into the existing if(MSVC) block before add_subdirectory(src) so that every ggml target inherits the flags automatically. This keeps all MSVC-specific settings together while still ensuring ggml-base and ggml see the flags during their creation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants