Skip to content

Commit

Permalink
Fix cmake exe unicode bug
Browse files Browse the repository at this point in the history
  • Loading branch information
eric15342335 committed Jun 17, 2024
1 parent 7e261ac commit b989915
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ else()
set(OUTPUT_NAME "stocksim")
endif()

add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:-utf-8>")

add_executable(${OUTPUT_NAME}
src/main.cpp
src/random_price.cpp
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ OUTPUT = stocksim-msvc.exe
endif
endif

# -GL can further reduce size, but more likely to flag as malicious
msvc: src/*.cpp include/*.h clean
cl -std:c++17 -EHsc -utf-8 -Iinclude -W1 -WX -O1 -guard:cf -MP \
src/*.cpp -Fe:$(OUTPUT)
Expand Down
23 changes: 18 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,25 @@ void enableWindowsVTProcessing(void) {
// Enable virtual terminal processing
consoleMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), consoleMode);
std::cout << "Experimental Windows VT processing enabled." << std::endl;
// Enable Data Execution Prevention (DEP) for the process
SetProcessDEPPolicy(PROCESS_DEP_ENABLE);
std::cout << "Experimental Windows VT processing enabled.\n";
}
void maximizeTerminalScreen_win10(void) {
#ifdef _MSC_VER
#pragma comment(lib, "user32.lib")
#endif
/** @note Windows 11 needs to set the default terminal application to Conhost
* to maximize the terminal screen.
* Terminal -> Settings -> Default Terminal Application -> Conhost
*/
ShowWindow(GetConsoleWindow(), SW_MAXIMIZE);
std::cout << "Terminal screen maximized.\n";
}
void windowsRoutines(void) {
enableWindowsVTProcessing();
maximizeTerminalScreen_win10();
}
#else
#define enableWindowsVTProcessing() // Do nothing
#define windowsRoutines() // Do nothing
#endif

/**
Expand Down Expand Up @@ -320,7 +333,7 @@ void initializePlayerSaves(
}

int main(void) {
enableWindowsVTProcessing();
windowsRoutines();
std::cout << "The game was compiled on " << __DATE__ << " at " << __TIME__
<< std::endl;

Expand Down

0 comments on commit b989915

Please sign in to comment.