tools/asset/pack now special-cases .ds files: each one is compiled with duskscriptcc to a temp .dsb (no .map, nothing reads one yet) and that gets packed under the same path with the extension swapped - the raw .ds source never ends up in the archive. Every other asset type is unchanged, packed byte for byte as before. CMake passes --duskscriptcc "$<TARGET_FILE:duskscriptcc>" and adds a DEPENDS on it, but only on the linux/knulli host target where duskscriptcc is actually built (see its own gating in src/CMakeLists.txt) - a cross-compiled console target has no host-built compiler to point at, so for now it can only pack an assets/ with no .ds in it; the packer raises a clear error rather than silently skipping or mis-packing one if it finds one anyway. The manifest's cache-skip check also now folds in duskscriptcc's own mtime, so a compiler rebuild invalidates every .ds's cached result even when none of their own source files changed. Verified by hand: a .ds under assets/scripts/ packs as the matching .dsb (confirmed by unzipping the resulting dusk.dsk), an unrelated rebuild correctly skips re-packing, touching duskscriptcc correctly forces a re-pack, and a syntax error in the .ds fails the build loudly with duskscriptcc's own error message rather than silently succeeding. Co-Authored-By: Claude Sonnet 5 <[email protected]>
173 lines
5.4 KiB
CMake
173 lines
5.4 KiB
CMake
# Copyright (c) 2025 Dominic Masters
|
|
#
|
|
# This software is released under the MIT License.
|
|
# https://opensource.org/licenses/MIT
|
|
|
|
# Setup
|
|
cmake_minimum_required(VERSION 3.13)
|
|
|
|
set(CMAKE_C_STANDARD 11)
|
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
|
set(CMAKE_MODULE_PATH
|
|
${CMAKE_MODULE_PATH}
|
|
${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules
|
|
)
|
|
cmake_policy(SET CMP0079 NEW)
|
|
# set(FETCHCONTENT_UPDATES_DISCONNECTED ON)
|
|
|
|
option(DUSK_BUILD_TESTS "Enable tests" OFF)
|
|
option(DUSK_NETWORK "Enable network support" ON)
|
|
|
|
set(DUSK_GAME_NAME "Dusk" CACHE STRING "Game display name")
|
|
set(DUSK_GAME_AUTHOR "YourWishes" CACHE STRING "Game author / coder")
|
|
set(DUSK_GAME_SHORT_DESCRIPTION "Dusk game" CACHE STRING "One-line description")
|
|
set(DUSK_GAME_LONG_DESCRIPTION
|
|
"No description yet." CACHE STRING "Full description"
|
|
)
|
|
|
|
# Prep cache
|
|
set(DUSK_CACHE_TARGET "dusk-target")
|
|
|
|
# Build variables
|
|
set(DUSK_ROOT_DIR "${CMAKE_SOURCE_DIR}")
|
|
set(DUSK_BUILD_DIR "${CMAKE_BINARY_DIR}")
|
|
set(DUSK_SOURCES_DIR "${DUSK_ROOT_DIR}/src")
|
|
set(DUSK_TEST_DIR "${DUSK_ROOT_DIR}/test")
|
|
set(DUSK_TEMP_DIR "${DUSK_BUILD_DIR}/temp")
|
|
set(DUSK_TOOLS_DIR "${DUSK_ROOT_DIR}/tools")
|
|
set(DUSK_DATA_DIR "${DUSK_ROOT_DIR}/data")
|
|
set(DUSK_ASSETS_DIR "${DUSK_ROOT_DIR}/assets")
|
|
set(DUSK_BUILT_ASSETS_DIR "${DUSK_BUILD_DIR}/built_assets"
|
|
CACHE INTERNAL ${DUSK_CACHE_TARGET}
|
|
)
|
|
set(DUSK_GENERATED_HEADERS_DIR "${DUSK_BUILD_DIR}/generated")
|
|
set(DUSK_BUILD_BINARY ${DUSK_BUILD_DIR}/Dusk
|
|
CACHE INTERNAL ${DUSK_CACHE_TARGET}
|
|
)
|
|
set(DUSK_ASSETS "" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
|
set(DUSK_LIBRARY_TARGET_NAME "DuskCore" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
|
set(DUSK_BINARY_TARGET_NAME "Dusk" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
|
set(DUSK_ASSETS_ZIP "${DUSK_BUILD_DIR}/dusk.dsk"
|
|
CACHE INTERNAL ${DUSK_CACHE_TARGET}
|
|
)
|
|
|
|
if(NOT DEFINED DUSK_TARGET_SYSTEM)
|
|
set(DUSK_TARGET_SYSTEM "linux")
|
|
endif()
|
|
|
|
# Create directories
|
|
file(MAKE_DIRECTORY ${DUSK_GENERATED_HEADERS_DIR})
|
|
file(MAKE_DIRECTORY ${DUSK_TEMP_DIR})
|
|
file(MAKE_DIRECTORY ${DUSK_BUILT_ASSETS_DIR})
|
|
|
|
# Required build packages
|
|
find_package(Python3 COMPONENTS Interpreter REQUIRED)
|
|
|
|
# Init Project.
|
|
project(${DUSK_LIBRARY_TARGET_NAME}
|
|
VERSION 1.0.0
|
|
LANGUAGES C
|
|
)
|
|
|
|
# Either, create library and binary separately (used for tests), or make them
|
|
# one in the same so all code is in the binary only.
|
|
# Binary Executable
|
|
add_executable(${DUSK_BINARY_TARGET_NAME} ${DUSK_SOURCES_DIR}/dusk/null.c)
|
|
|
|
if(DUSK_BUILD_TESTS)
|
|
# MainLibrary
|
|
add_library(${DUSK_LIBRARY_TARGET_NAME} STATIC)
|
|
|
|
# Link library to binary
|
|
target_link_libraries(${DUSK_BINARY_TARGET_NAME}
|
|
PUBLIC
|
|
${DUSK_LIBRARY_TARGET_NAME}
|
|
)
|
|
else()
|
|
set(DUSK_LIBRARY_TARGET_NAME "${DUSK_BINARY_TARGET_NAME}"
|
|
CACHE INTERNAL ${DUSK_CACHE_TARGET}
|
|
)
|
|
endif()
|
|
|
|
if(NOT DEFINED DUSK_VERSION)
|
|
string(TIMESTAMP DUSK_VERSION "debug-%y%m%d%H%M%S")
|
|
endif()
|
|
|
|
# Definitions
|
|
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME}
|
|
PUBLIC
|
|
DUSK_TARGET_SYSTEM="${DUSK_TARGET_SYSTEM}"
|
|
DUSK_GAME_NAME="${DUSK_GAME_NAME}"
|
|
DUSK_GAME_AUTHOR="${DUSK_GAME_AUTHOR}"
|
|
DUSK_GAME_SHORT_DESCRIPTION="${DUSK_GAME_SHORT_DESCRIPTION}"
|
|
DUSK_GAME_LONG_DESCRIPTION="${DUSK_GAME_LONG_DESCRIPTION}"
|
|
DUSK_VERSION="${DUSK_VERSION}"
|
|
)
|
|
|
|
if(DUSK_NETWORK)
|
|
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
|
DUSK_NETWORK
|
|
)
|
|
endif()
|
|
|
|
# Toolchains
|
|
include(cmake/targets/${DUSK_TARGET_SYSTEM}.cmake)
|
|
|
|
# Add tools
|
|
add_subdirectory(tools)
|
|
|
|
# Include generated headers from tools.
|
|
target_include_directories(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
|
${DUSK_GENERATED_HEADERS_DIR}
|
|
)
|
|
|
|
# Add main code
|
|
add_subdirectory(${DUSK_SOURCES_DIR})
|
|
|
|
# Include generated headers
|
|
target_include_directories(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
|
${DUSK_GENERATED_HEADERS_DIR}
|
|
)
|
|
|
|
# Handle tests
|
|
if(DUSK_BUILD_TESTS)
|
|
enable_testing()
|
|
add_subdirectory(test)
|
|
endif()
|
|
|
|
# Build assets. Runs unconditionally on every build (rather than being
|
|
# gated behind a custom_command's file-level DEPENDS list) because
|
|
# CONFIGURE_DEPENDS globs only pick up added/removed files on the next
|
|
# CMake configure, so that approach could miss/lag a rebuild behind an
|
|
# asset edit. tools.asset.pack itself decides whether anything actually
|
|
# changed (see its manifest check) and no-ops quickly when nothing did,
|
|
# so this stays cheap on a build where assets are untouched.
|
|
#
|
|
# A .ds script under assets/ is compiled to .dsb by duskscriptcc as part of
|
|
# packing, so dusk.dsk only ever carries bytecode. duskscriptcc is a host
|
|
# tool, only built when target_system is the build host (linux/knulli, see
|
|
# src/CMakeLists.txt) - a cross-compiled console target has no duskscriptcc
|
|
# of its own to depend on or pass down, so it can only pack assets with no
|
|
# .ds in them until something sets up a host-built duskscriptcc for it too.
|
|
if(DUSK_TARGET_SYSTEM STREQUAL "linux" OR DUSK_TARGET_SYSTEM STREQUAL "knulli")
|
|
set(DUSK_ASSET_PACK_DUSKSCRIPTCC_ARGS --duskscriptcc "$<TARGET_FILE:duskscriptcc>")
|
|
set(DUSK_ASSET_PACK_DEPENDS duskscriptcc)
|
|
else()
|
|
set(DUSK_ASSET_PACK_DUSKSCRIPTCC_ARGS "")
|
|
set(DUSK_ASSET_PACK_DEPENDS "")
|
|
endif()
|
|
|
|
add_custom_target(DUSK_ASSETS_BUILT ALL
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory "${DUSK_ASSETS_DIR}"
|
|
COMMAND ${Python3_EXECUTABLE} -m tools.asset.pack
|
|
--input "${DUSK_ASSETS_DIR}"
|
|
--output "${DUSK_ASSETS_ZIP}"
|
|
${DUSK_ASSET_PACK_DUSKSCRIPTCC_ARGS}
|
|
WORKING_DIRECTORY "${DUSK_ROOT_DIR}"
|
|
BYPRODUCTS "${DUSK_ASSETS_ZIP}"
|
|
DEPENDS ${DUSK_ASSET_PACK_DEPENDS}
|
|
COMMENT "Packing assets into dusk.dsk"
|
|
VERBATIM
|
|
)
|
|
add_dependencies(${DUSK_LIBRARY_TARGET_NAME} DUSK_ASSETS_BUILT)
|