# SPDX-License-Identifier: GPL-3.0-or-later
cmake_minimum_required(VERSION 3.12)
project(wolf2009_source_definitions_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_source_definitions)
    add_library(wolf2009_source_definitions STATIC "${core}/SourceDefinitions.cpp")
    target_compile_features(wolf2009_source_definitions PUBLIC cxx_std_11)
    target_include_directories(wolf2009_source_definitions PUBLIC "${core}")
endif()
if(NOT TARGET wolf2009-source-definitions)
    # Compile only this profile's input readers. Importing the entire core
    # project also registers unrelated tests whose binaries are not built by
    # this standalone target.
    set(WOLF2009_MINIZ_SOURCE_DIR "" CACHE PATH "Optional pinned miniz source directory")
    if(WOLF2009_MINIZ_SOURCE_DIR)
        add_library(source_definitions_miniz STATIC "${WOLF2009_MINIZ_SOURCE_DIR}/miniz.c")
        target_include_directories(source_definitions_miniz PUBLIC "${WOLF2009_MINIZ_SOURCE_DIR}")
        set(compression source_definitions_miniz)
    else()
        find_package(ZLIB REQUIRED)
        set(compression ZLIB::ZLIB)
    endif()
    add_library(source_definitions_inputs STATIC
        "${core}/Archive.cpp" "${core}/ZipArchive.cpp" "${core}/Entities.cpp")
    target_include_directories(source_definitions_inputs PUBLIC "${core}")
    target_link_libraries(source_definitions_inputs PUBLIC ${compression})
    if(WOLF2009_MINIZ_SOURCE_DIR)
        target_compile_definitions(source_definitions_inputs PRIVATE WOLF2009_USE_MINIZ)
    endif()
    add_executable(wolf2009-source-definitions SourceDefinitionsTest.cpp)
    target_link_libraries(wolf2009-source-definitions PRIVATE wolf2009_source_definitions source_definitions_inputs)
endif()
add_test(NAME wolf2009_source_definitions_synthetic COMMAND wolf2009-source-definitions --self-test)
set(WOLF2009_DEFINITION_SOURCE_CATALOG "" CACHE FILEPATH "Optional owner-supplied assets PK4 for selected read-only source declarations")
set(WOLF2009_DEFINITION_SOURCE_MAP "" CACHE FILEPATH "Optional owner-supplied MPK providing explicit worldspawn mapSpecificDef context")
if(WOLF2009_DEFINITION_SOURCE_CATALOG)
    set(source_args --source-catalog "${WOLF2009_DEFINITION_SOURCE_CATALOG}")
    if(WOLF2009_DEFINITION_SOURCE_MAP)
        list(APPEND source_args --source-map "${WOLF2009_DEFINITION_SOURCE_MAP}")
    endif()
    add_test(NAME wolf2009_source_definitions_original COMMAND wolf2009-source-definitions
             ${source_args})
endif()
