-
Notifications
You must be signed in to change notification settings - Fork 1
/
msvc_utf8_encoding.cmake
37 lines (35 loc) · 1.12 KB
/
msvc_utf8_encoding.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Author: Zhuo Zhang <[email protected]>
# Homepage: https://github.com/zchrissirhcz/rocbuild
# Last update: 2024-06-11 23:48:00
cmake_minimum_required(VERSION 3.15)
include_guard()
# Set source file utf-8 encoding
# This solves Visual Studio warning C4819
add_compile_options(
"$<$<COMPILE_LANG_AND_ID:C,MSVC>:/source-charset:utf-8>"
"$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/source-charset:utf-8>"
)
# Set executable run with utf-8 encoding
if(WIN32)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
cmake_host_system_information(
RESULT CodePage
QUERY WINDOWS_REGISTRY "HKLM/SYSTEM/CurrentControlSet/Control/Nls/CodePage"
VALUE "ACP"
)
else()
include(FindPythonInterp)
execute_process(
COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_SOURCE_DIR}/cmake/QueryCodePage.py"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE ReturnCode
OUTPUT_VARIABLE CodePage
)
endif()
if("${CodePage}" STREQUAL "936")
add_compile_options(
"$<$<COMPILE_LANG_AND_ID:C,MSVC>:/execution-charset:gbk>"
"$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/execution-charset:gbk>"
)
endif()
endif()