# src/sign/CMakeLists.txt
#
# libplugin-sign — DSO signing and verification library
#
# OpenSSL is required for Ed25519 operations and SHA-256.
# If OpenSSL is not found the sign/ module is silently skipped.

cmake_minimum_required(VERSION 3.20)

find_package(OpenSSL QUIET)

if(NOT OpenSSL_FOUND)
    message(STATUS "sign: OpenSSL not found — signing module disabled")
    return()
endif()

set(SIGN_MODULE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "")

add_library(plugin-sign STATIC
    Manifest.cpp
    Verifier.cpp
)
target_include_directories(plugin-sign
    PUBLIC  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../..>
            $<INSTALL_INTERFACE:include>
)
target_link_libraries(plugin-sign
    PUBLIC  OpenSSL::SSL
            OpenSSL::Crypto
)
set_target_properties(plugin-sign PROPERTIES
    POSITION_INDEPENDENT_CODE ON
    CXX_STANDARD 23
)
target_compile_options(plugin-sign PRIVATE
    $<$<CXX_COMPILER_ID:GNU,Clang>:-Wall -Wextra -Wpedantic>)

# Make plugin-sign available to dso/ (for DSOLoader signed variants)
set(PLUGIN_SIGN_AVAILABLE TRUE CACHE INTERNAL "")

install(FILES Manifest.hh Verifier.hh TrustLevel.hh
    COMPONENT plugin_development
    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sign)

install(TARGETS plugin-sign
    ARCHIVE COMPONENT plugin_development
    DESTINATION ${CMAKE_INSTALL_LIBDIR})
