From 905d20efb6c72cfae9c803acf6b63bec01c61901 Mon Sep 17 00:00:00 2001 From: = <=> Date: Fri, 19 Jan 2024 19:21:26 +0100 Subject: [PATCH] optimizations --- CMakeLists.txt | 13 +++++++++++++ README.md | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ee9682d..96d2659 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,9 @@ project(Pong) set(CMAKE_CXX_STANDARD 17) +# Option for enabling optimizations +option(ENABLE_OPTIMIZATIONS "Enable compiler optimizations" OFF) + # Base SDL2 find_package(SDL2 REQUIRED) include_directories(${SDL2_INCLUDE_DIRS}) @@ -33,3 +36,13 @@ add_executable(Pong src/main.cpp # Now link the libraries to the target target_link_libraries(Pong ${SDL2_LIBRARIES} ${SDL2_GFX_LIBRARY} ${SDL2_TTF_LIBRARY}) + +# Set compiler optimization flags +if(ENABLE_OPTIMIZATIONS) + message(STATUS "Optimizations are enabled") + if(MSVC) + target_compile_options(Pong PRIVATE /O2) + else() + target_compile_options(Pong PRIVATE -O3) + endif() +endif() diff --git a/README.md b/README.md index b102fdf..f31745a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # Pong -A pong implementation in C++. You'll need cmake make, sdl2 sdl2-gfx and sdl2-ttf to compile. \ No newline at end of file +A pong implementation in C++. You'll need cmake make, sdl2 sdl2-gfx and sdl2-ttf to compile. + +To enable compiler optimizations pass `-DENABLE_OPTIMIZATIONS=ON` to cmake. You'll end up with the following command `cmake -DENABLE_OPTIMIZATIONS=ON`. \ No newline at end of file