107 lines
3.8 KiB
CMake
107 lines
3.8 KiB
CMake
# Copyright (c) 2026 Dominic Masters
|
|
#
|
|
# This software is released under the MIT License.
|
|
# https://opensource.org/licenses/MIT
|
|
|
|
# Resolve YAUL_INSTALL_ROOT (already set by the toolchain file, but guard
|
|
# in case cmake/targets/ is loaded standalone for IDE tooling).
|
|
if(NOT DEFINED YAUL_INSTALL_ROOT)
|
|
if(DEFINED ENV{YAUL_INSTALL_ROOT})
|
|
set(YAUL_INSTALL_ROOT "$ENV{YAUL_INSTALL_ROOT}")
|
|
else()
|
|
set(YAUL_INSTALL_ROOT "/opt/yaul")
|
|
endif()
|
|
endif()
|
|
|
|
# Yaul installs headers/libs under the arch-prefix sysroot subdirectory:
|
|
# ${YAUL_INSTALL_ROOT}/sh2eb-elf/include/
|
|
# ${YAUL_INSTALL_ROOT}/sh2eb-elf/lib/
|
|
# Cross-compiled zlib and libzip are installed to the same sysroot.
|
|
set(_YAUL_SYSROOT "${YAUL_INSTALL_ROOT}/sh2eb-elf")
|
|
set(_YAUL_BIN "${YAUL_INSTALL_ROOT}/bin")
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Bypass system find_package calls for libraries we cross-compile into the
|
|
# sh2eb-elf sysroot and install into ${_YAUL_SYSROOT}.
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# zlib
|
|
if(NOT TARGET ZLIB::ZLIB)
|
|
add_library(ZLIB::ZLIB INTERFACE IMPORTED GLOBAL)
|
|
set_target_properties(ZLIB::ZLIB PROPERTIES
|
|
INTERFACE_INCLUDE_DIRECTORIES "${_YAUL_SYSROOT}/include"
|
|
INTERFACE_LINK_LIBRARIES "${_YAUL_SYSROOT}/lib/libz.a"
|
|
)
|
|
endif()
|
|
set(ZLIB_FOUND TRUE CACHE BOOL "" FORCE)
|
|
set(ZLIB_INCLUDE_DIR "${_YAUL_SYSROOT}/include" CACHE PATH "" FORCE)
|
|
set(ZLIB_LIBRARY "${_YAUL_SYSROOT}/lib/libz.a" CACHE FILEPATH "" FORCE)
|
|
|
|
# libzip — pre-installed into the sh2eb-elf sysroot; skip Findlibzip.cmake.
|
|
set(libzip_FOUND TRUE CACHE BOOL "libzip found (Saturn sysroot)" FORCE)
|
|
find_path(_sat_zip_inc NAMES zip.h
|
|
PATHS "${_YAUL_SYSROOT}/include"
|
|
NO_DEFAULT_PATH
|
|
)
|
|
if(_sat_zip_inc)
|
|
target_include_directories(${DUSK_LIBRARY_TARGET_NAME} PRIVATE "${_sat_zip_inc}")
|
|
endif()
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Compile definitions
|
|
# ---------------------------------------------------------------------------
|
|
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
|
DUSK_SATURN
|
|
DUSK_INPUT_GAMEPAD
|
|
DUSK_PLATFORM_ENDIAN_BIG
|
|
DUSK_DISPLAY_WIDTH=320
|
|
DUSK_DISPLAY_HEIGHT=224
|
|
DUSK_THREAD_NONE
|
|
)
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Compile options
|
|
# ---------------------------------------------------------------------------
|
|
target_compile_options(${DUSK_LIBRARY_TARGET_NAME} PRIVATE
|
|
-m2 -mb
|
|
-fno-builtin
|
|
-fomit-frame-pointer
|
|
-w
|
|
)
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Include paths
|
|
# ---------------------------------------------------------------------------
|
|
target_include_directories(${DUSK_LIBRARY_TARGET_NAME} PRIVATE
|
|
"${_YAUL_SYSROOT}/include"
|
|
"${_YAUL_SYSROOT}/include/yaul"
|
|
)
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Link libraries
|
|
# ---------------------------------------------------------------------------
|
|
target_link_directories(${DUSK_LIBRARY_TARGET_NAME} PRIVATE
|
|
"${_YAUL_SYSROOT}/lib"
|
|
)
|
|
|
|
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PRIVATE
|
|
"${_YAUL_SYSROOT}/lib/libyaul.a"
|
|
"${_YAUL_SYSROOT}/lib/libzip.a"
|
|
"${_YAUL_SYSROOT}/lib/libz.a"
|
|
m
|
|
)
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Post-build: ELF → binary image
|
|
# sh2eb-elf-objcopy converts the ELF to a flat binary that IP.BIN loads
|
|
# into Saturn Work RAM.
|
|
# ---------------------------------------------------------------------------
|
|
set(DUSK_SAT_BIN "${CMAKE_BINARY_DIR}/Dusk.bin")
|
|
add_custom_command(TARGET ${DUSK_BINARY_TARGET_NAME} POST_BUILD
|
|
COMMAND "${_YAUL_BIN}/sh2eb-elf-objcopy"
|
|
-O binary
|
|
"$<TARGET_FILE:${DUSK_BINARY_TARGET_NAME}>"
|
|
"${DUSK_SAT_BIN}"
|
|
COMMENT "Converting ${DUSK_BINARY_TARGET_NAME} ELF → ${DUSK_SAT_BIN}"
|
|
)
|