Pong/CMakeLists.txt

49 lines
1.2 KiB
CMake
Raw Normal View History

2024-01-19 15:06:48 +01:00
cmake_minimum_required(VERSION 3.27)
project(Pong)
set(CMAKE_CXX_STANDARD 17)
2024-01-19 19:21:26 +01:00
# Option for enabling optimizations
option(ENABLE_OPTIMIZATIONS "Enable compiler optimizations" OFF)
2024-01-19 15:06:48 +01:00
# Base SDL2
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})
# SDL2 Gfx
find_library(SDL2_GFX_LIBRARY NAMES SDL2_gfx SDL2_gfxd)
if (NOT SDL2_GFX_LIBRARY)
message(FATAL_ERROR "SDL2_gfx not found")
endif ()
2024-01-19 18:41:26 +01:00
find_library(SDL2_TTF_LIBRARY NAMES SDL2_ttf SDL2_TTF SDL2TTF)
if (NOT SDL2_TTF_LIBRARY)
message(FATAL_ERROR "SDL2_TTF not found")
endif ()
2024-01-19 15:06:48 +01:00
# Define the executable target before linking libraries
2024-01-19 19:11:22 +01:00
add_executable(Pong src/main.cpp
src/SdlWrapper.h
src/Game.h
src/VisibleObjects/Ball.h
src/Vec2d/Vec2d.h
src/Vec2d/Bump.h
src/VisibleObjects/PlayerPaddle.h
src/VisibleObjects/Side.h
src/VisibleObjects/Score.h)
2024-01-19 15:06:48 +01:00
# Now link the libraries to the target
2024-01-19 18:41:26 +01:00
target_link_libraries(Pong ${SDL2_LIBRARIES} ${SDL2_GFX_LIBRARY} ${SDL2_TTF_LIBRARY})
2024-01-19 19:21:26 +01:00
# 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()