# SPDX-License-Identifier: GPL-3.0-or-later
cmake_minimum_required(VERSION 3.12)
project(wolf2009_compiled_declarations_checks LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
enable_testing()
set(core "${CMAKE_CURRENT_SOURCE_DIR}/../../src/wolf2009")
if(NOT TARGET wolf2009_compiled_declarations)
    add_library(wolf2009_compiled_declarations STATIC "${core}/CompiledDeclarations.cpp")
    target_include_directories(wolf2009_compiled_declarations PUBLIC "${core}")
    target_compile_features(wolf2009_compiled_declarations PUBLIC cxx_std_11)
endif()
if(NOT TARGET wolf2009-compiled-declarations)
    set(WOLF2009_MINIZ_SOURCE_DIR "" CACHE PATH "Optional existing pinned miniz source directory")
    if(WOLF2009_MINIZ_SOURCE_DIR)
        add_library(compiled_declarations_miniz STATIC "${WOLF2009_MINIZ_SOURCE_DIR}/miniz.c")
        target_include_directories(compiled_declarations_miniz PUBLIC "${WOLF2009_MINIZ_SOURCE_DIR}")
        set(compression compiled_declarations_miniz)
    else()
        find_package(ZLIB REQUIRED)
        set(compression ZLIB::ZLIB)
    endif()
    add_library(compiled_declarations_archive STATIC "${core}/Archive.cpp")
    target_include_directories(compiled_declarations_archive PUBLIC "${core}")
    target_link_libraries(compiled_declarations_archive PUBLIC ${compression})
    if(WOLF2009_MINIZ_SOURCE_DIR)
        target_compile_definitions(compiled_declarations_archive PRIVATE WOLF2009_USE_MINIZ)
    endif()
    add_executable(wolf2009-compiled-declarations CompiledDeclarationsTest.cpp)
    target_link_libraries(wolf2009-compiled-declarations PRIVATE wolf2009_compiled_declarations compiled_declarations_archive)
endif()
add_test(NAME wolf2009_compiled_declarations_synthetic COMMAND wolf2009-compiled-declarations --self-test)
set(WOLF2009_COMPILED_DECL_SOURCE_MAP "" CACHE FILEPATH "Optional owner-supplied selected trainyard MPK")
if(WOLF2009_COMPILED_DECL_SOURCE_MAP)
    add_test(NAME wolf2009_compiled_declarations_original COMMAND wolf2009-compiled-declarations --source-map "${WOLF2009_COMPILED_DECL_SOURCE_MAP}")
endif()
set(WOLF2009_COMPILED_DECL_SOURCE_BASE "" CACHE PATH "Optional owner SP/base for the selected empty DECL and global SPK absence")
if(WOLF2009_COMPILED_DECL_SOURCE_BASE)
    add_test(NAME wolf2009_compiled_declarations_empty COMMAND wolf2009-compiled-declarations --source-package
        "${WOLF2009_COMPILED_DECL_SOURCE_BASE}/maps/game/empty/empty.mpk" "maps/game/empty/empty")
    add_test(NAME wolf2009_compiled_declarations_global_decl_absence COMMAND wolf2009-compiled-declarations --source-decl-absence
        "${WOLF2009_COMPILED_DECL_SOURCE_BASE}/maps/game/global/global.spk")
endif()
