# SPDX-FileCopyrightText: 2019 Casper Meijn <casper@meijn.net>
# SPDX-License-Identifier: GPL-3.0-or-later
#

cmake_minimum_required(VERSION 3.7)

set(GLOBAL_KSWSDL2CPP_OPTION)
get_filename_component(KDWSDL_IMPORT_PATH ../wsdl/ ABSOLUTE)
set(GLOBAL_KSWSDL2CPP_OPTION -import-path ${KDWSDL_IMPORT_PATH} -use-local-files-only)

set(KSWSDL2CPP_OPTION -namespace WSDiscovery200901 ${GLOBAL_KSWSDL2CPP_OPTION})
KDSOAP_GENERATE_WSDL(KDSoapWSDiscoveryClient_WSDL ${KDWSDL_IMPORT_PATH}/docs.oasis-open.org/ws-dd/discovery/1.1/os/wsdd-discovery-1.1-wsdl-os.wsdl)
set(KSWSDL2CPP_OPTION -namespace WSDiscovery200504 ${GLOBAL_KSWSDL2CPP_OPTION})
KDSOAP_GENERATE_WSDL(KDSoapWSDiscoveryClient_WSDL ${KDWSDL_IMPORT_PATH}/schemas.xmlsoap.org/ws/2005/04/discovery/ws-discovery.wsdl)

set(KDSoapWSDiscoveryClient_SRCS
    "wsdiscoveryclient.cpp"
    "wsdiscoveryprobejob.cpp"
    "wsdiscoverytargetservice.cpp"
    "wsdiscoveryserviceaggregator.cpp"
)

ecm_qt_declare_logging_category(KDSoapWSDiscoveryClient_SRCS
    HEADER loggingcategory.h
    IDENTIFIER KDSoapWSDiscoveryClient
    CATEGORY_NAME kdsoap.wsdiscoveryclient
    DEFAULT_SEVERITY Warning
)

add_library(KDSoapWSDiscoveryClient ${KDSoapWSDiscoveryClient_SRCS} ${KDSoapWSDiscoveryClient_WSDL})
generate_export_header(KDSoapWSDiscoveryClient BASE_NAME WSDiscoveryClient)
add_library(KDSoap::WSDiscoveryClient ALIAS KDSoapWSDiscoveryClient)

target_include_directories(KDSoapWSDiscoveryClient
    INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTALL_INCLUDEDIR}/KDSoapWSDiscoveryClient>"
)

target_link_libraries(KDSoapWSDiscoveryClient
    PUBLIC
        Qt${QT_MAJOR_VERSION}::Core
        KDSoap::kdsoap
    PRIVATE
)

set_target_properties(KDSoapWSDiscoveryClient PROPERTIES
    VERSION     ${WSDISCOVERY_VERSION_STRING}
    SOVERSION   ${WSDISCOVERY_SOVERSION}
    EXPORT_NAME "WSDiscoveryClient"
)

ecm_generate_headers(KDSoapWSDiscoveryClient_HEADERS
    HEADER_NAMES
    WSDiscoveryClient
    WSDiscoveryProbeJob
    WSDiscoveryTargetService
    WSDiscoveryServiceAggregator

    REQUIRED_HEADERS KDSoapWSDiscoveryClient_HEADERS
)

install(TARGETS KDSoapWSDiscoveryClient
        EXPORT KDSoapWSDiscoveryClientTargets
        ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})

install(FILES
            ${CMAKE_CURRENT_BINARY_DIR}/wsdiscoveryclient_export.h
            ${KDSoapWSDiscoveryClient_HEADERS}
        DESTINATION ${KDE_INSTALL_INCLUDEDIR}/KDSoapWSDiscoveryClient
        COMPONENT Devel)

if(BUILD_QCH)
    ecm_add_qch(
        KDSoapWSDiscoveryClient_QCH
        NAME KDSoapWSDiscoveryClient
        BASE_NAME KDSoapWSDiscoveryClient
        VERSION ${WSDISCOVERY_VERSION}
        ORG_DOMAIN net.meijn
        SOURCES # using only public headers, to cover only public API
            ${KDSoapWSDiscoveryClient_HEADERS}
        MD_MAINPAGE "${CMAKE_SOURCE_DIR}/README.md"
        LINK_QCHS
            Qt${QT_MAJOR_VERSION}Core_QCH
            KDSoap_QCH
        BLANK_MACROS
            KARCHIVE_EXPORT
            KARCHIVE_DEPRECATED
        TAGFILE_INSTALL_DESTINATION ${KDE_INSTALL_QTQCHDIR}
        QCH_INSTALL_DESTINATION ${KDE_INSTALL_QTQCHDIR}
        COMPONENT Devel
    )
endif()
