# SPDX-License-Identifier: GPL-3.0-or-later
cmake_minimum_required(VERSION 3.12)
project(wolf2009_spline_codec_checks LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(core "${CMAKE_CURRENT_SOURCE_DIR}/../../src/wolf2009")
add_library(wolf2009_spline_codec STATIC "${core}/SplineTransformCodec.cpp")
target_include_directories(wolf2009_spline_codec PUBLIC "${core}")
if(NOT MSVC)
    target_compile_options(wolf2009_spline_codec PRIVATE -ffp-contract=off -fno-fast-math)
endif()
add_executable(wolf2009-spline-codec SplineTransformCodecTest.cpp)
target_link_libraries(wolf2009-spline-codec PRIVATE wolf2009_spline_codec)
enable_testing()
add_test(NAME wolf2009_spline_codec_synthetic COMMAND wolf2009-spline-codec)
set(WOLF2009_SPLINE_SOURCE_BASE "" CACHE PATH "Optional owner-supplied read-only SP/base")
set(WOLF2009_MINIZ_SOURCE_DIR "" CACHE PATH "Optional pinned miniz source directory")
if(WOLF2009_SPLINE_SOURCE_BASE)
    if(WOLF2009_MINIZ_SOURCE_DIR)
        add_library(spline_source_miniz STATIC "${WOLF2009_MINIZ_SOURCE_DIR}/miniz.c")
        target_include_directories(spline_source_miniz PUBLIC "${WOLF2009_MINIZ_SOURCE_DIR}")
        set(compression spline_source_miniz)
    else()
        find_package(ZLIB REQUIRED)
        set(compression ZLIB::ZLIB)
    endif()
    add_executable(wolf2009-spline-source SourceCompatibility.cpp
        "${core}/Archive.cpp" "${core}/StreamMounts.cpp" "${core}/GreeterAnimation.cpp")
    target_link_libraries(wolf2009-spline-source PRIVATE wolf2009_spline_codec ${compression})
    if(WOLF2009_MINIZ_SOURCE_DIR)
        target_compile_definitions(wolf2009-spline-source PRIVATE WOLF2009_USE_MINIZ)
    endif()
    add_test(NAME wolf2009_spline_codec_source COMMAND wolf2009-spline-source
        --source-base "${WOLF2009_SPLINE_SOURCE_BASE}")
endif()
