# SPDX-License-Identifier: GPL-3.0-or-later
cmake_minimum_required(VERSION 3.12)
project(wolf2009_compiled_catalog_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_catalog)
    add_library(wolf2009_compiled_catalog STATIC "${core}/CompiledDeclarationCatalog.cpp")
    target_include_directories(wolf2009_compiled_catalog PUBLIC "${core}")
    target_compile_features(wolf2009_compiled_catalog PUBLIC cxx_std_11)
    target_link_libraries(wolf2009_compiled_catalog PUBLIC wolf2009_compiled_declarations)
endif()
if(NOT TARGET wolf2009-compiled-catalog)
    set(WOLF2009_MINIZ_SOURCE_DIR "" CACHE PATH "Optional existing pinned miniz source directory")
    if(WOLF2009_MINIZ_SOURCE_DIR)
        add_library(compiled_catalog_miniz STATIC "${WOLF2009_MINIZ_SOURCE_DIR}/miniz.c")
        target_include_directories(compiled_catalog_miniz PUBLIC "${WOLF2009_MINIZ_SOURCE_DIR}")
        set(compression compiled_catalog_miniz)
    else()
        find_package(ZLIB REQUIRED)
        set(compression ZLIB::ZLIB)
    endif()
    add_library(compiled_catalog_archive STATIC "${core}/Archive.cpp")
    target_include_directories(compiled_catalog_archive PUBLIC "${core}")
    target_link_libraries(compiled_catalog_archive PUBLIC ${compression})
    if(WOLF2009_MINIZ_SOURCE_DIR)
        target_compile_definitions(compiled_catalog_archive PRIVATE WOLF2009_USE_MINIZ)
    endif()
    add_executable(wolf2009-compiled-catalog CompiledCatalogTest.cpp)
    target_link_libraries(wolf2009-compiled-catalog PRIVATE wolf2009_compiled_catalog compiled_catalog_archive)
endif()
add_test(NAME wolf2009_compiled_catalog_synthetic COMMAND wolf2009-compiled-catalog --self-test)
set(WOLF2009_COMPILED_CATALOG_SOURCE_MAP "" CACHE FILEPATH "Optional owner-supplied selected trainyard MPK")
if(WOLF2009_COMPILED_CATALOG_SOURCE_MAP)
    add_test(NAME wolf2009_compiled_catalog_original COMMAND wolf2009-compiled-catalog --source-map "${WOLF2009_COMPILED_CATALOG_SOURCE_MAP}")
endif()
