Files
spacetris/CMakeLists.txt

167 lines
5.8 KiB
CMake

cmake_minimum_required(VERSION 3.20)
# Integrate vcpkg toolchain if available
if(DEFINED ENV{VCPKG_ROOT})
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
elseif(EXISTS "${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
elseif(EXISTS "C:/Users/Gregor Klevže/vcpkg/scripts/buildsystems/vcpkg.cmake")
set(CMAKE_TOOLCHAIN_FILE "C:/Users/Gregor Klevže/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
endif()
# The toolchain file must be set before calling project()
if(DEFINED CMAKE_TOOLCHAIN_FILE)
message(STATUS "Using vcpkg toolchain: ${CMAKE_TOOLCHAIN_FILE}")
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_FILE}" CACHE STRING "" FORCE)
endif()
project(tetris_sdl3 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Find SDL3 (via package manager or a local build)
# vcpkg example: vcpkg install sdl3
# Homebrew: brew install sdl3
find_package(SDL3 CONFIG REQUIRED)
find_package(SDL3_ttf CONFIG REQUIRED)
add_executable(tetris
src/main.cpp
src/gameplay/Game.cpp
src/core/GravityManager.cpp
src/core/StateManager.cpp
# New core architecture classes
src/core/ApplicationManager.cpp
src/core/InputManager.cpp
src/graphics/RenderManager.cpp
src/persistence/Scores.cpp
src/graphics/Starfield.cpp
src/graphics/Starfield3D.cpp
src/graphics/Font.cpp
src/audio/Audio.cpp
src/gameplay/LineEffect.cpp
src/audio/SoundEffect.cpp
# State implementations (new)
src/states/LoadingState.cpp
src/states/MenuState.cpp
src/states/LevelSelectorState.cpp
src/states/PlayingState.cpp
)
if (WIN32)
# Embed the application icon into the executable
set_source_files_properties(src/app_icon.rc PROPERTIES LANGUAGE RC)
target_sources(tetris PRIVATE src/app_icon.rc)
endif()
if (WIN32)
# Ensure favicon.ico is available in the build directory for the resource compiler
set(FAVICON_SRC "${CMAKE_SOURCE_DIR}/assets/favicon/favicon.ico")
set(FAVICON_DEST "${CMAKE_BINARY_DIR}/favicon.ico")
if(EXISTS ${FAVICON_SRC})
add_custom_command(
OUTPUT ${FAVICON_DEST}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${FAVICON_SRC} ${FAVICON_DEST}
DEPENDS ${FAVICON_SRC}
COMMENT "Copy favicon.ico to build dir for resource compilation"
)
add_custom_target(copy_favicon ALL DEPENDS ${FAVICON_DEST})
add_dependencies(tetris copy_favicon)
else()
message(WARNING "Favicon not found at ${FAVICON_SRC}; app icon may not compile")
endif()
# Also copy favicon into the runtime output folder (same dir as exe)
add_custom_command(TARGET tetris POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${FAVICON_SRC} $<TARGET_FILE_DIR:tetris>/favicon.ico
COMMENT "Copy favicon.ico next to executable"
)
endif()
target_link_libraries(tetris PRIVATE SDL3::SDL3 SDL3_ttf::SDL3_ttf)
if (WIN32)
target_link_libraries(tetris PRIVATE mfplat mfreadwrite mfuuid)
endif()
# Include production build configuration
include(cmake/ProductionBuild.cmake)
# Enable CTest so `add_test` registers tests for `ctest`
enable_testing()
# Unit tests (simple runner)
find_package(Catch2 CONFIG REQUIRED)
add_executable(tetris_tests
tests/GravityTests.cpp
src/core/GravityManager.cpp
)
target_include_directories(tetris_tests PRIVATE ${CMAKE_SOURCE_DIR}/src)
target_link_libraries(tetris_tests PRIVATE Catch2::Catch2WithMain)
add_test(NAME GravityTests COMMAND tetris_tests)
if(EXISTS "${CMAKE_SOURCE_DIR}/vcpkg_installed/x64-windows/include")
target_include_directories(tetris_tests PRIVATE "${CMAKE_SOURCE_DIR}/vcpkg_installed/x64-windows/include")
endif()
# Add new src subfolders to include path so old #includes continue to work
target_include_directories(tetris PRIVATE
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/src/audio
${CMAKE_SOURCE_DIR}/src/gameplay
${CMAKE_SOURCE_DIR}/src/graphics
${CMAKE_SOURCE_DIR}/src/persistence
${CMAKE_SOURCE_DIR}/src/core
${CMAKE_SOURCE_DIR}/src/states
)
# Experimental refactored version (for testing new architecture)
add_executable(tetris_refactored
src/main_new.cpp
src/gameplay/Game.cpp
src/core/GravityManager.cpp
src/core/StateManager.cpp
# New core architecture classes
src/core/ApplicationManager.cpp
src/core/InputManager.cpp
src/graphics/RenderManager.cpp
src/persistence/Scores.cpp
src/graphics/Starfield.cpp
src/graphics/Starfield3D.cpp
src/graphics/Font.cpp
src/audio/Audio.cpp
src/gameplay/LineEffect.cpp
src/audio/SoundEffect.cpp
# State implementations (temporarily excluded - depend on main.cpp functions)
# src/states/LoadingState.cpp
# src/states/MenuState.cpp
# src/states/LevelSelectorState.cpp
# src/states/PlayingState.cpp
)
if (WIN32)
# Embed the application icon into the refactored executable too
target_sources(tetris_refactored PRIVATE src/app_icon.rc)
add_dependencies(tetris_refactored copy_favicon)
add_custom_command(TARGET tetris_refactored POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${FAVICON_SRC} $<TARGET_FILE_DIR:tetris_refactored>/favicon.ico
COMMENT "Copy favicon.ico next to refactored executable"
)
endif()
target_link_libraries(tetris_refactored PRIVATE SDL3::SDL3 SDL3_ttf::SDL3_ttf)
if (WIN32)
target_link_libraries(tetris_refactored PRIVATE mfplat mfreadwrite mfuuid)
endif()
target_include_directories(tetris_refactored PRIVATE
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/src/audio
${CMAKE_SOURCE_DIR}/src/gameplay
${CMAKE_SOURCE_DIR}/src/graphics
${CMAKE_SOURCE_DIR}/src/persistence
${CMAKE_SOURCE_DIR}/src/core
${CMAKE_SOURCE_DIR}/src/states
)