reasampler_pure_library(app_version SOURCES app_version.cpp)
# version_generated.h, configured at the root from the one REASAMPLER_VERSION string.
# PUBLIC so every consumer of the channel bit sees it.
target_include_directories(app_version PUBLIC ${PROJECT_BINARY_DIR}/generated)
reasampler_test(app_version LINK app_version)

# Anti-normalization padding canary (rationale in tests/test_app_version_padding.cpp). The
# live-version assertions in app_version_tests are version-shape-blind — relative checks
# such as appVersion() == stampVersion() hold whether the string was threaded verbatim or
# reconstructed from numeric components — so that suite cannot detect a
# reconstruct-from-components regression at all. So: run the SAME template through
# configure_file a second time with a SYNTHETIC padded version, and compile the SAME
# app_version.cpp against it.
#
# "0.9.01" is a permanent test fixture, NOT the shipped version. It must match the literals
# in test_app_version_padding.cpp and must NEVER be bumped on release.
#
# Coverage boundary: this catches reconstruct-from-components inside app_version.cpp. It
# cannot see the live source-of-truth line becoming a CMake variable derivation — the
# comment block at the top of the root CMakeLists.txt guards that half.
function(_configure_padding_canary)
    # set() inside a function is function-scoped, so this clobber cannot leak to the parent
    # scope — no save/restore dance needed. REASAMPLER_CHANNEL_IS_BETA and the directory
    # variables are inherited read-only.
    set(REASAMPLER_VERSION "0.9.01")
    configure_file(
        ${CMAKE_CURRENT_SOURCE_DIR}/version_generated.h.in
        ${PROJECT_BINARY_DIR}/generated_padding_canary/version_generated.h
        @ONLY)
endfunction()
_configure_padding_canary()

# Longhand rather than reasampler_test: the canary RECOMPILES app_version.cpp instead of
# linking the library, which is what lets the include-dir substitution work — it must see
# generated_padding_canary/ in place of the live generated/ dir. If app_version ever gains
# a link dependency, mirror it here.
add_executable(app_version_padding_tests
    ${REASAMPLER_TESTS_DIR}/test_app_version_padding.cpp
    app_version.cpp)
target_include_directories(app_version_padding_tests PRIVATE
    ${PROJECT_BINARY_DIR}/generated_padding_canary ${REASAMPLER_SRC_DIR})
add_test(NAME app_version_padding_tests COMMAND app_version_padding_tests)
