From 5c9344d02b2ed44be6f0dbddfb31fc8212de1ee4 Mon Sep 17 00:00:00 2001 From: Xiake Sun Date: Mon, 6 Jan 2025 20:03:22 +0800 Subject: [PATCH 1/3] Fix chinese character to UTF-8 garbled code on windows for chat sample --- samples/cpp/chat_sample/CMakeLists.txt | 5 +++++ samples/cpp/chat_sample/chat_sample.cpp | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/samples/cpp/chat_sample/CMakeLists.txt b/samples/cpp/chat_sample/CMakeLists.txt index 69578dc86c..e48c322d97 100644 --- a/samples/cpp/chat_sample/CMakeLists.txt +++ b/samples/cpp/chat_sample/CMakeLists.txt @@ -8,6 +8,11 @@ find_package(OpenVINOGenAI REQUIRED NO_CMAKE_FIND_ROOT_PATH ) +if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + # Specifies both the source character set and the execution character set as UTF-8. + # For details, refer to link: https://learn.microsoft.com/en-us/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8?view=msvc-170 + add_compile_options("$<$:/utf-8>") + add_executable(chat_sample chat_sample.cpp) target_link_libraries(chat_sample PRIVATE openvino::genai) set_target_properties(chat_sample PROPERTIES diff --git a/samples/cpp/chat_sample/chat_sample.cpp b/samples/cpp/chat_sample/chat_sample.cpp index 41d63fc0f1..dc6e44521c 100644 --- a/samples/cpp/chat_sample/chat_sample.cpp +++ b/samples/cpp/chat_sample/chat_sample.cpp @@ -2,8 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 #include "openvino/genai/llm_pipeline.hpp" +#ifdef _WIN32 +#include +#endif int main(int argc, char* argv[]) try { + #ifdef _WIN32 + SetConsoleOutputCP(CP_UTF8); + system("chcp 65001"); //Using UTF-8 Encoding + #endif if (2 != argc) { throw std::runtime_error(std::string{"Usage: "} + argv[0] + " "); } From 8df94f44257c140454b8e0786669b8c46c52a567 Mon Sep 17 00:00:00 2001 From: Xiake Sun Date: Mon, 6 Jan 2025 23:24:14 +0800 Subject: [PATCH 2/3] Fix compile error --- samples/cpp/chat_sample/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/cpp/chat_sample/CMakeLists.txt b/samples/cpp/chat_sample/CMakeLists.txt index e48c322d97..7ed748ee11 100644 --- a/samples/cpp/chat_sample/CMakeLists.txt +++ b/samples/cpp/chat_sample/CMakeLists.txt @@ -12,6 +12,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") # Specifies both the source character set and the execution character set as UTF-8. # For details, refer to link: https://learn.microsoft.com/en-us/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8?view=msvc-170 add_compile_options("$<$:/utf-8>") +endif() add_executable(chat_sample chat_sample.cpp) target_link_libraries(chat_sample PRIVATE openvino::genai) From 7603007ce1e2a4c108e680a19dfc7caf57e3a4a5 Mon Sep 17 00:00:00 2001 From: Xiake Sun Date: Fri, 10 Jan 2025 13:18:54 +0800 Subject: [PATCH 3/3] Remove /utf-8 since latest openvino base package already add MSVC UTF-8 support --- samples/cpp/chat_sample/CMakeLists.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/samples/cpp/chat_sample/CMakeLists.txt b/samples/cpp/chat_sample/CMakeLists.txt index 7ed748ee11..69578dc86c 100644 --- a/samples/cpp/chat_sample/CMakeLists.txt +++ b/samples/cpp/chat_sample/CMakeLists.txt @@ -8,12 +8,6 @@ find_package(OpenVINOGenAI REQUIRED NO_CMAKE_FIND_ROOT_PATH ) -if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - # Specifies both the source character set and the execution character set as UTF-8. - # For details, refer to link: https://learn.microsoft.com/en-us/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8?view=msvc-170 - add_compile_options("$<$:/utf-8>") -endif() - add_executable(chat_sample chat_sample.cpp) target_link_libraries(chat_sample PRIVATE openvino::genai) set_target_properties(chat_sample PROPERTIES