Make forcing UTF-8 codepage optional

This commit is contained in:
Martchus 2016-12-24 16:08:09 +01:00
parent 28d2063d33
commit 737f73e71a
2 changed files with 9 additions and 1 deletions

View File

@ -128,6 +128,12 @@ if(USE_NATIVE_FILE_BUFFER)
list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_USE_NATIVE_FILE_BUFFER)
endif()
# configure forcing UTF-8 code page under Windows
option(FORCE_UTF8_CODEPAGE "forces use of UTF-8 code page under Windows" OFF)
if(FORCE_UTF8_CODEPAGE)
list(APPEND META_PRIVATE_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_FORCE_UTF8_CODEPAGE)
endif()
# include modules to apply configuration
include(BasicConfig)
include(WindowsResources)

View File

@ -38,7 +38,7 @@ bool confirmPrompt(const char *message, Response defaultResponse)
#ifdef PLATFORM_WINDOWS
/*!
* \brief Starts the console and sets the console output code page to UTF-8.
* \brief Starts the console and sets the console output code page to UTF-8 if this is configured.
* \remarks This method is only available on Windows and used to start a console from a GUI application.
*/
void startConsole()
@ -67,9 +67,11 @@ void startConsole()
fp = _fdopen(conHandle, "w");
*stderr = *fp;
setvbuf(stderr, NULL, _IONBF, 0);
#ifdef CPP_UTILITIES_FORCE_UTF8_CODEPAGE
// set console to handle UTF-8 IO correctly
SetConsoleCP(CP_UTF8);
SetConsoleOutputCP(CP_UTF8);
#endif
// sync
ios::sync_with_stdio(true);
}