Skip to content

Commit

Permalink
Fix cmake exe unicode bug (#145)
Browse files Browse the repository at this point in the history
Makefile and main.cpp was unrelated changes.

Makefile flags cleanup
  • Loading branch information
eric15342335 committed Jun 18, 2024
1 parent 7e261ac commit 15a04ab
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 27 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
27 changes: 11 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,27 @@ CXX = g++
INCLUDES = -Iinclude
OUTPUT = stocksim
CXXFLAGS += -Wall -Wextra -pedantic -std=c++17 -Werror -g \
-Wcast-qual -Wundef -Wswitch -Wshadow -Wold-style-cast
-Wcast-qual -Wundef -Wswitch -Wshadow
# -Wconversion -Wfloat-equal
# -fsanitize=address -fsanitize=undefined

# MinGW does not support -static-pie
ifeq ($(OS),Windows_NT)
# -pthread needed for clang++ on Windows
ifeq ($(CXX),clang++)
CXXFLAGS += -pthread
endif
CXXFLAGS += -static
else ifeq ($(CXX),g++)
ifeq ($(shell uname),Linux)
CXXFLAGS += -static-pie -fPIE
CXXFLAGS += -pthread
endif
CXXFLAGS += -static
endif

# Security flags for Linux
ifeq ($(shell uname),Linux)
ifneq ($(CXX),cosmoc++)
CXXFLAGS += -z noexecstack -z relro -z now
CXXFLAGS += -z relro -z now -static-pie -fPIE
endif
endif

# Clang will warn about unused command line arguments.
ifeq ($(CXX),clang++)
CXXFLAGS += -Wno-error=unused-command-line-argument
CXXFLAGS += -Wno-error=unused-command-line-argument
endif

default: stocksim
Expand Down Expand Up @@ -137,15 +131,16 @@ 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 \
cl -std:c++17 -EHsc -utf-8 $(INCLUDES) -W1 -WX -O1 -guard:cf -MP \
src/*.cpp -Fe:$(OUTPUT)
rm *.obj || true

format-check:
clang-format --dry-run --Werror src/*.cpp include/*.h
clang-tidy src/*.cpp --checks=performance-*,-performance-avoid-endl,readability-*,bugprone-*,portability-*,cert-* \
--fix-errors --fix-notes --format-style=file -- -Iinclude
--fix-errors --fix-notes --format-style=file -- $(INCLUDES)

input-check:
echo -e "1\ntest\nX\nY\n" | ./$(OUTPUT)
Expand All @@ -156,11 +151,11 @@ input-check:
# cosmopolitan c++ compiler does not support -flto and stack protector
ifeq ($(MAKECMDGOALS),release)
ifneq ($(CXX),cosmoc++)
CXXFLAGS += -fstack-protector-strong
CXXFLAGS += -fstack-protector-strong
ifneq ($(CXX),clang++)
CXXFLAGS += -flto
CXXFLAGS += -flto
else ifneq ($(OS),Windows_NT)
CXXFLAGS += -flto
CXXFLAGS += -flto
endif
endif
endif
Expand Down
12 changes: 1 addition & 11 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,10 @@ program. If not, see <https://www.gnu.org/licenses/>.
#include "file_io.h"
#include "format.h"
#include "graph.h"
#include "nonstdlibs/VariadicTable.h"
#include "random_price.h"
#include "stock.h"

#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
#include "nonstdlibs/VariadicTable.h"
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif

#include <cmath>
#include <fstream>
#include <numeric>
Expand All @@ -53,8 +45,6 @@ void enableWindowsVTProcessing(void) {
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);
}
#else
#define enableWindowsVTProcessing() // Do nothing
Expand Down

0 comments on commit 15a04ab

Please sign in to comment.