Hpp and better imports

This commit is contained in:
2025-08-12 17:36:08 +02:00
parent 2f401e8d32
commit 378e2d74cf
26 changed files with 63 additions and 82 deletions

View File

@@ -6,52 +6,36 @@ set(CMAKE_CXX_STANDARD 17)
# Option for enabling optimizations
option(ENABLE_OPTIMIZATIONS "Enable compiler optimizations" OFF)
# Base SDL2
find_package(SDL2 REQUIRED)
# Use pkg-config
find_package(PkgConfig REQUIRED)
pkg_check_modules(SDL2 REQUIRED sdl2)
include_directories(${SDL2_INCLUDE_DIRS})
link_directories(${SDL2_LIBRARY_DIRS})
# SDL2 Gfx
find_library(SDL2_GFX_LIBRARY NAMES SDL2_gfx SDL2_gfxd libSDL2_gfx)
if (NOT SDL2_GFX_LIBRARY)
message(FATAL_ERROR "SDL2_gfx not found")
endif ()
pkg_check_modules(SDL2_GFX REQUIRED SDL2_gfx)
include_directories(${SDL2_GFX_INCLUDE_DIRS})
link_directories(${SDL2_GFX_LIBRARY_DIRS})
find_library(SDL2_TTF_LIBRARY NAMES SDL2_ttf SDL2_TTF SDL2TTF)
if (NOT SDL2_TTF_LIBRARY)
message(FATAL_ERROR "SDL2_TTF not found")
endif ()
pkg_check_modules(SDL2_TTF REQUIRED SDL2_ttf)
include_directories(${SDL2_TTF_INCLUDE_DIRS})
link_directories(${SDL2_TTF_LIBRARY_DIRS})
# Define the executable target before linking libraries
add_executable(Pong src/main.cpp
src/SdlWrapper.h
src/SdlWrapper.cpp
src/Game.h
src/Game.cpp
src/VisibleObjects/Ball.h
src/VisibleObjects/Ball.cpp
src/Vec2d/Vec2d.h
src/Vec2d/Vec2d.cpp
src/Vec2d/Bump.h
src/VisibleObjects/PlayerPaddle.h
src/VisibleObjects/PlayerPaddle.cpp
src/VisibleObjects/Side.h
src/text/TextScreen.h
src/text/TextScreen.cpp
src/defaultfont.h
src/defaultfont.cpp
src/icon.h
src/icon.cpp
src/text/OptionScreen.h
src/text/OptionScreen.cpp
src/text/Score.h
src/text/Score.cpp
src/text/ScrollOptionScreen.cpp
src/text/ScrollOptionScreen.h
)
# Now link the libraries to the target
target_link_libraries(Pong ${SDL2_LIBRARIES} ${SDL2_GFX_LIBRARY} ${SDL2_TTF_LIBRARY})
target_link_libraries(Pong ${SDL2_LIBRARIES} ${SDL2_GFX_LIBRARIES} ${SDL2_TTF_LIBRARIES})
# Set compiler optimization flags
if (ENABLE_OPTIMIZATIONS)
@@ -59,7 +43,11 @@ if (ENABLE_OPTIMIZATIONS)
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")
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
# 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.