cmake_minimum_required(VERSION 3.19)

# ---------------------------------------------------------------------------
# Version — SINGLE SOURCE OF TRUTH. Edit REASAMPLER_VERSION here and nowhere else: it flows
# to the binary constant, the ext-state writing-version stamp, and the "show version" action
# through the configured header below. The string is authoritative verbatim, leading zeros
# included — padded and unpadded versions are BOTH legitimate ("0.9.8" and "0.9.80" are
# different versions), so nothing may force zero-padding.
#
# *** INVARIANT — DO NOT COLLAPSE OR DERIVE ***
# The set(REASAMPLER_VERSION ...) line below MUST stay a verbatim string literal, even when
# it is textually identical to the project(VERSION ...) line. It must NEVER become
#   set(REASAMPLER_VERSION "${PROJECT_VERSION}")
#   set(REASAMPLER_VERSION "${CMAKE_PROJECT_VERSION}")
# or any other form derived from project(): CMake normalizes numeric patch fields, so a
# padded "0.9.01" would silently round-trip to "0.9.1" and break the displayed version.
# project(VERSION ...) is kept for CMake hygiene and downstream numeric use, but it is NOT
# the rendered source of truth.
#
# The padding canary in src/core/version/CMakeLists.txt guards the other half of this
# invariant (reconstruct-from-components inside app_version.cpp) via a permanent synthetic
# "0.9.01" fixture there that must NEVER be bumped on release. It cannot see this line
# becoming a CMake derivation — that is this comment's job.
set(REASAMPLER_VERSION "1.4.0")

project(reaper_reasampler VERSION 1.4.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# ---------------------------------------------------------------------------
# Channel — SINGLE SOURCE OF TRUTH for beta-in-isolation. One flag forks the whole channel
# identity from one build tree: absent (or `stable`) is today's build with byte-identical
# identity; `beta` is a fully isolated artifact that coexists with stable in one REAPER. The
# flag reduces to ONE bit threaded through the SAME generated header as the version string,
# so app_version derives every channel-qualified identity from it and no #ifdefs scatter.
# An unrecognized non-empty value hard-errors at configure time: a misspelled
# -DREASAMPLER_CHANNEL=betaa must not silently ship stable identity under a beta intent.
set(REASAMPLER_CHANNEL "stable" CACHE STRING "Build channel: stable (default) or beta")
if(REASAMPLER_CHANNEL STREQUAL "beta")
    set(REASAMPLER_CHANNEL_IS_BETA 1)
    set(REASAMPLER_OUTPUT_NAME "reaper_reasampler_beta")
    # Must match app_version::vstOutputName() so the artifact name and the in-binary
    # self-id agree.
    set(REASAMPLER_VST_OUTPUT_NAME "reasampler_9000_beta")
elseif(REASAMPLER_CHANNEL STREQUAL "stable")
    set(REASAMPLER_CHANNEL_IS_BETA 0)
    set(REASAMPLER_OUTPUT_NAME "reaper_reasampler")
    set(REASAMPLER_VST_OUTPUT_NAME "reasampler_9000")
else()
    message(FATAL_ERROR
        "REASAMPLER_CHANNEL must be 'stable' or 'beta' (got '${REASAMPLER_CHANNEL}')")
endif()

# Regenerated at configure time whenever the version string or the channel bit changes; the
# string is substituted verbatim.
configure_file(
    ${CMAKE_CURRENT_SOURCE_DIR}/src/core/version/version_generated.h.in
    ${CMAKE_CURRENT_BINARY_DIR}/generated/version_generated.h
    @ONLY)

# ---------------------------------------------------------------------------
# Vendored dependencies (git submodules — see CLAUDE.md for the one-time init).
set(SDK_INC  ${CMAKE_CURRENT_SOURCE_DIR}/vendor/reaper-sdk/sdk)
set(WDL_INC  ${CMAKE_CURRENT_SOURCE_DIR}/vendor/WDL/WDL)
set(SWELL    ${WDL_INC}/swell)
set(VST3_SDK ${CMAKE_CURRENT_SOURCE_DIR}/vendor/vst3sdk)

# The LICE TUs both loadable modules draw with. lice_line.cpp's bezier helpers call
# LICE_FillCircle from lice_arc.cpp, so that TU is required to link. NOTE the "new" text
# variant: lice_textnew.cpp is the TU implementing the LICE_CachedFont CLASS the draw kit
# uses — lice_text.cpp is the legacy bitmap-font renderer with no class and would leave the
# symbols unresolved. LICE routes GDI through native Win32 or, on mac/linux, the host SWELL.
# draw_kit.cpp is compiled directly into each module rather than being a static library:
# it is the only kit TU that touches LICE, so it needs these LICE_SRC TUs linked into the
# same artifact, and both modules draw with it.
set(LICE_SRC
    ${WDL_INC}/lice/lice.cpp
    ${WDL_INC}/lice/lice_line.cpp
    ${WDL_INC}/lice/lice_arc.cpp
    ${WDL_INC}/lice/lice_textnew.cpp
)

# ---------------------------------------------------------------------------
set(REASAMPLER_SRC_DIR   ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(REASAMPLER_TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/reasampler_targets.cmake)

enable_testing()

add_subdirectory(src/core)
add_subdirectory(src/app)
add_subdirectory(src/shell/instrument)
