cmake_minimum_required(VERSION 3.10)
project(Maelstrom68K CXX)

# MAEL_LOG writes "Maelstrom Log" next to the app (harness runs).
# MAEL_AUTOPILOT plays the game by itself (harness runs).
option(MAEL_LOG "Write a log file" OFF)
option(MAEL_AUTOPILOT "Self-playing build for the Snow harness" OFF)

set(ASSET_RSRC ${CMAKE_SOURCE_DIR}/assets/Maelstrom.rsrc.bin)
if(NOT EXISTS ${ASSET_RSRC})
    message(FATAL_ERROR "missing ${ASSET_RSRC}; run tools/mkassets.py")
endif()

add_application(Maelstrom
    CREATOR "MAEL"
    TYPE "APPL"
    src/main.cpp
    src/gfx.cpp
    src/sys.cpp
    src/sound.cpp
    src/init.cpp
    src/game.cpp
    src/blit.cpp
    src/make.cpp
    src/object.cpp
    src/objects.cpp
    src/player.cpp
    src/fastrand.cpp
    src/scores.cpp
    src/autopilot.cpp
    src/Maelstrom.r
    ${ASSET_RSRC}
)

# 68000 baseline: Mac 512Ke, Plus, SE, Classic.
target_compile_options(Maelstrom PRIVATE
    -Os -ffunction-sections -fno-exceptions -fno-rtti
    -Wall -Wno-unused-variable -Wno-unused-but-set-variable
)
if(MAEL_LOG)
    target_compile_definitions(Maelstrom PRIVATE MAEL_LOG)
endif()
if(MAEL_AUTOPILOT)
    target_compile_definitions(Maelstrom PRIVATE MAEL_AUTOPILOT MAEL_LOG)
endif()
target_include_directories(Maelstrom PRIVATE src)
set_target_properties(Maelstrom PROPERTIES
    LINK_FLAGS "-Wl,-gc-sections -Wl,--mac-strip-macsbug"
)

# The blitters and the per-frame logic want speed over size.
set_source_files_properties(src/gfx.cpp src/sound.cpp src/blit.cpp src/object.cpp src/init.cpp
    src/player.cpp PROPERTIES COMPILE_OPTIONS "-O2")
