cmake_minimum_required(VERSION 3.25) project(tbg LANGUAGES CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug) endif() add_compile_options(-Wall -Wextra -Wpedantic -Wconversion -Wshadow) # Game rules: no SDL, no I/O. Everything that defines "how Tetris Battle Gaiden plays" lives here. add_library(tbg_core STATIC src/core/piece.cpp src/core/board.cpp src/core/queue.cpp src/core/player.cpp src/core/board_ops.cpp src/core/power.cpp src/core/character.cpp src/core/match.cpp src/core/ai.cpp src/core/rom_ai.cpp src/core/campaign.cpp src/core/replay.cpp ) target_include_directories(tbg_core PUBLIC src) # toml++ v3.4.0 (MIT, header-only) for mod files. target_include_directories(tbg_core SYSTEM PRIVATE external/tomlplusplus) # Original graphics decoded from the user's ROM at runtime (no SDL). add_library(tbg_gfx STATIC src/gfx/rom_gfx.cpp src/gfx/asset_source.cpp src/gfx/pause_text.cpp) target_include_directories(tbg_gfx PUBLIC src) # stb_image v2.30 (public domain / MIT, header-only) for override PNGs. target_include_directories(tbg_gfx SYSTEM PRIVATE external/stb) # Override-folder asset tests; the ROM comparisons need TBG_ROM. add_executable(tbg_gfx_tests tests/gfx_tests.cpp) target_link_libraries(tbg_gfx_tests PRIVATE tbg_gfx) add_executable(gfx_dump tools/gfx_dump.cpp) target_link_libraries(gfx_dump PRIVATE tbg_gfx) # blargg's snes_spc 0.9.0 (LGPL-2.1): its own shared library so it stays separately replaceable. add_library(snes_spc SHARED external/snes_spc/snes_spc/SNES_SPC.cpp external/snes_spc/snes_spc/SNES_SPC_misc.cpp external/snes_spc/snes_spc/SNES_SPC_state.cpp external/snes_spc/snes_spc/SPC_DSP.cpp external/snes_spc/snes_spc/SPC_Filter.cpp ) target_include_directories(snes_spc SYSTEM PUBLIC external/snes_spc) target_compile_options(snes_spc PRIVATE -w) # vendored, unmodified # The original music/SFX: the game's sound code run in a 65816 interpreter, fed to snes_spc (no SDL). add_library(tbg_audio STATIC src/audio/cpu65816.cpp src/audio/sound_ops.cpp src/audio/sound.cpp) target_include_directories(tbg_audio PUBLIC src) target_link_libraries(tbg_audio PUBLIC snes_spc) # Dumps the ROM-derived assets the game reads (local use only): tbg_extract ROM OUTDIR add_executable(tbg_extract tools/tbg_extract.cpp) target_link_libraries(tbg_extract PRIVATE tbg_gfx tbg_audio) add_executable(snd_validate tools/snd_validate.cpp) target_link_libraries(snd_validate PRIVATE tbg_audio) # Needs the user's ROM: TBG_ROM=rom/tbg_jp.sfc ./build/tbg_audio_tests (passes trivially without it). add_executable(tbg_audio_tests tests/audio_tests.cpp) target_link_libraries(tbg_audio_tests PRIVATE tbg_audio) # The game's own non-battle screens: 65816 + PPU model running the ROM's scene code (no SDL). add_library(tbg_screens STATIC src/screens/snes.cpp src/screens/ppu.cpp src/screens/flow.cpp) target_include_directories(tbg_screens PUBLIC src) target_link_libraries(tbg_screens PUBLIC tbg_audio) # Needs the user's ROM: TBG_ROM=rom/tbg_jp.sfc ./build/tbg_screens_tests (passes trivially without it). add_executable(tbg_screens_tests tests/screens_tests.cpp) target_link_libraries(tbg_screens_tests PRIVATE tbg_screens) # Dev tool: scr_validate ROM re/runs/scr/main --frames 200,400,1000 (frames vs Mesen screenshots; needs zlib). find_package(ZLIB) if(ZLIB_FOUND) add_executable(scr_validate tools/scr_validate.cpp) target_link_libraries(scr_validate PRIVATE tbg_screens ZLIB::ZLIB) endif() find_package(SDL3 REQUIRED CONFIG) add_executable(tbg src/app/main.cpp src/app/draw.cpp src/app/controls.cpp src/app/settings.cpp src/app/art_draw.cpp src/app/game_sound.cpp src/app/audio_out.cpp src/app/pause_screen.cpp) target_include_directories(tbg PRIVATE src) target_link_libraries(tbg PRIVATE tbg_core tbg_gfx tbg_audio tbg_screens SDL3::SDL3) set_target_properties(tbg PROPERTIES INSTALL_RPATH "$ORIGIN/../lib") # Dev tool: replays Mesen captures (re/runs/ai2) through the RomAi port. add_executable(ai_validate tools/ai_validate.cpp) target_link_libraries(ai_validate PRIVATE tbg_core) enable_testing() add_executable(tbg_tests tests/core_tests.cpp tests/match_tests.cpp tests/modern_tests.cpp tests/modern_cpu_tests.cpp) target_link_libraries(tbg_tests PRIVATE tbg_core) add_test(NAME core COMMAND tbg_tests) add_test(NAME gfx COMMAND tbg_gfx_tests) # `cmake --install build --prefix ~/.local` installs the game, its docs and the example mod. install(TARGETS tbg RUNTIME DESTINATION bin) install(TARGETS snes_spc LIBRARY DESTINATION lib) install(FILES external/snes_spc/license.txt DESTINATION share/doc/tbg RENAME snes_spc-LICENSE.txt) install(FILES README.md DESTINATION share/doc/tbg) install(FILES data/README.md DESTINATION share/doc/tbg RENAME MODDING.md) install(FILES data/mods/example.toml DESTINATION share/tbg/mods-examples)