mirror of
https://github.com/lov3b/Pong.git
synced 2025-09-13 00:00:21 +02:00
65 lines
1.9 KiB
CMake
65 lines
1.9 KiB
CMake
cmake_minimum_required(VERSION 3.25)
|
|
project(Pong)
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
|
|
# Option for enabling optimizations
|
|
option(ENABLE_OPTIMIZATIONS "Enable compiler optimizations" OFF)
|
|
|
|
# Use pkg-config
|
|
find_package(PkgConfig REQUIRED)
|
|
|
|
pkg_check_modules(SDL2 REQUIRED sdl2)
|
|
include_directories(${SDL2_INCLUDE_DIRS})
|
|
link_directories(${SDL2_LIBRARY_DIRS})
|
|
|
|
pkg_check_modules(SDL2_GFX REQUIRED SDL2_gfx)
|
|
include_directories(${SDL2_GFX_INCLUDE_DIRS})
|
|
link_directories(${SDL2_GFX_LIBRARY_DIRS})
|
|
|
|
pkg_check_modules(SDL2_TTF REQUIRED SDL2_ttf)
|
|
include_directories(${SDL2_TTF_INCLUDE_DIRS})
|
|
link_directories(${SDL2_TTF_LIBRARY_DIRS})
|
|
|
|
add_executable(Pong src/main.cpp
|
|
src/SdlWrapper.cpp
|
|
src/Game.cpp
|
|
src/VisibleObjects/Ball.cpp
|
|
src/Vec2d/Vec2d.cpp
|
|
src/VisibleObjects/PlayerPaddle.cpp
|
|
src/text/TextScreen.cpp
|
|
src/defaultfont.cpp
|
|
src/icon.cpp
|
|
src/text/OptionScreen.cpp
|
|
src/text/Score.cpp
|
|
src/text/ScrollOptionScreen.cpp
|
|
)
|
|
|
|
target_link_libraries(Pong ${SDL2_LIBRARIES} ${SDL2_GFX_LIBRARIES} ${SDL2_TTF_LIBRARIES})
|
|
|
|
# Set compiler optimization flags
|
|
if (ENABLE_OPTIMIZATIONS)
|
|
message(STATUS "Optimizations are enabled")
|
|
set_target_properties(Pong PROPERTIES LINK_SEARCH_START_STATIC 1)
|
|
set_target_properties(Pong PROPERTIES LINK_SEARCH_END_STATIC 1)
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
|
|
|
# Apply static linking options only for GCC
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
|
|
endif()
|
|
|
|
# Make sure that a terminal window doesn't launch under Windows.
|
|
# We will still launch the terminal if we haven't compiled with optimizations.
|
|
# This is useful for debugging
|
|
if (WIN32)
|
|
set_target_properties(Pong PROPERTIES WIN32_EXECUTABLE TRUE)
|
|
endif ()
|
|
|
|
if (MSVC)
|
|
target_compile_options(Pong PRIVATE /O2)
|
|
else ()
|
|
target_compile_options(Pong PRIVATE -O3)
|
|
endif ()
|
|
endif ()
|