# hash_codegen.cmake — generate overlay_codegen_hash.h with a content hash of the # recompiler's codegen sources, so the overlay cache path (gcc//cg_/) # changes automatically whenever the emitter changes. This closes the gap where a # pure-emitter change within the same manual PSX_OVERLAY_CODEGEN_VER produced a # different DLL the cache happily reused (a stale-but-cgN load — the v0.3.0 black # screen). Both the runtime loader (via overlay_api.h) and compile_overlays.py read # the generated PSX_OVERLAY_CODEGEN_HASH, so the two sides never drift. # # Invoked as: cmake -DOUT=
"-DSRCS=;;..." -P hash_codegen.cmake # Re-runs whenever a listed source changes (it's an add_custom_command DEPENDS). # # Or, outside any build, with the canonical list resolved here: # cmake -DOUT=
-DPSXRECOMP_CODEGEN_HASH_ROOT= -P hash_codegen.cmake # tools/aot_overlay_pipeline.py `static` does this: a static overlay shard is # generated before the runtime is ever built, and compile_overlays' stale- # recompiler guard needs this header to exist. if(NOT DEFINED SRCS) if(NOT DEFINED PSXRECOMP_CODEGEN_HASH_ROOT) message(FATAL_ERROR "hash_codegen.cmake: pass -DSRCS= or " "-DPSXRECOMP_CODEGEN_HASH_ROOT=") endif() include("${CMAKE_CURRENT_LIST_DIR}/codegen_hash_sources.cmake") set(SRCS ${PSXRECOMP_CODEGEN_HASH_SRCS}) endif() set(_cat "") foreach(f IN LISTS SRCS) if(EXISTS "${f}") file(READ "${f}" _c) string(APPEND _cat "${_c}") endif() endforeach() string(SHA256 _h "${_cat}") string(SUBSTRING "${_h}" 0 8 _h8) set(_content "/* AUTO-GENERATED by hash_codegen.cmake — do not edit, do not commit. * Content hash of the recompiler codegen sources; folded into the overlay cache * path so an emitter change never reuses a stale DLL. */ #pragma once #define PSX_OVERLAY_CODEGEN_HASH 0x${_h8}u ") # Only rewrite when the value actually changes, so dependents don't rebuild on # every invocation. if(EXISTS "${OUT}") file(READ "${OUT}" _old) if(_old STREQUAL _content) return() endif() endif() file(WRITE "${OUT}" "${_content}") message(STATUS "overlay codegen hash: 0x${_h8}")