# SPDX-License-Identifier: GPL-3.0-or-later
cmake_minimum_required(VERSION 3.12)
project(wolf2009_compiled_namespace_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")
add_library(namespace_core STATIC "${core}/CompiledDeclarations.cpp" "${core}/CompiledDeclarationCatalog.cpp"
    "${core}/CompiledDeclarationNamespace.cpp" "${core}/SourceDefinitions.cpp")
target_include_directories(namespace_core PUBLIC "${core}")
set(WOLF2009_MINIZ_SOURCE_DIR "" CACHE PATH "Optional pinned miniz directory")
if(WOLF2009_MINIZ_SOURCE_DIR)
    add_library(namespace_compression STATIC "${WOLF2009_MINIZ_SOURCE_DIR}/miniz.c")
    target_include_directories(namespace_compression PUBLIC "${WOLF2009_MINIZ_SOURCE_DIR}")
    target_compile_definitions(namespace_compression PUBLIC WOLF2009_USE_MINIZ)
else()
    find_package(ZLIB REQUIRED)
    add_library(namespace_compression INTERFACE)
    target_link_libraries(namespace_compression INTERFACE ZLIB::ZLIB)
endif()
add_library(namespace_archives STATIC "${core}/Archive.cpp" "${core}/ZipArchive.cpp")
target_include_directories(namespace_archives PUBLIC "${core}")
target_link_libraries(namespace_archives PUBLIC namespace_compression)
add_executable(wolf2009-compiled-namespace CompiledNamespaceTest.cpp)
target_link_libraries(wolf2009-compiled-namespace PRIVATE namespace_core namespace_archives)
add_test(NAME wolf2009_compiled_namespace_synthetic COMMAND wolf2009-compiled-namespace --self-test)
set(WOLF2009_COMPILED_NAMESPACE_SP_BASE "" CACHE PATH "Owner-supplied SP/base directory")
if(WOLF2009_COMPILED_NAMESPACE_SP_BASE)
    add_test(NAME wolf2009_compiled_namespace_original COMMAND wolf2009-compiled-namespace
        --source-base "${WOLF2009_COMPILED_NAMESPACE_SP_BASE}")
endif()
