# Copyright (C) 2020 Uniontech Technology Co., Ltd.
#
# Author:     xinbo wang <wangxinbo@uniontech.com>
#
# Maintainer: xinbo wang <wangxinbo@uniontech.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

find_package(PkgConfig REQUIRED)
pkg_check_modules(DBUS REQUIRED dbus-1)
set(BIN_NAME dtkclipboardace)
set(SECURITY_INCLUDE ${CMAKE_SOURCE_DIR}/include/clipboard-ace)

include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${SECURITY_INCLUDE})
include_directories(${COMMON_PATH})
include_directories(../uace/src/ext/)
include_directories(${DBUS_INCLUDE_DIRS})

set(DNDS_LIB_SRCS
    dnd_security.c
    ${COMMON_PATH}/dtk_utils.c
    wayland_dnd.c
    ${SECURITY_INCLUDE}/wayland_dnd.h
    x11_dnd.c
    ${SECURITY_INCLUDE}/x11_dnd.h
    ${COMMON_PATH}/log.c
    ${COMMON_PATH}/log.h
    dde_security_interface.c
    ${SECURITY_INCLUDE}/dde_security_interface.h
    ${CMAKE_CURRENT_BINARY_DIR}/wayland-dde-security-client-protocol.h
    ${CMAKE_CURRENT_BINARY_DIR}/wayland-client-management-client-protocol.h
    )

ecm_add_wayland_client_protocol(DNDS_LIB_SRCS
    PROTOCOL ${PROTOCOLS_PATH}/dde-security.xml
    BASENAME dde-security
)

ecm_add_wayland_client_protocol(DNDS_LIB_SRCS
    PROTOCOL ${PROTOCOLS_PATH}/client-management.xml
    BASENAME client-management
)

set(DNDS_LIB_HEADERS
    ${COMMON_PATH}/dtk_utils.h
    ${SECURITY_INCLUDE}/dnd_security.h
    )

add_library(${BIN_NAME} SHARED
    ${DNDS_LIB_SRCS}
    ${DNDS_LIB_HEADERS}
)

install(
    FILES
    ace-config/entity/clipboard.json
    DESTINATION
    "/usr/share/uos/usec/entity.d"
)

install(
    FILES
    ace-config/mode/clipboard.json
    DESTINATION
    "/usr/share/uos/usec/mode.d"
)

target_link_libraries(${BIN_NAME} PRIVATE Wayland::Client uaceExt)

target_link_libraries(${BIN_NAME} PRIVATE  ${DBUS_LIBRARIES})

set_target_properties(${BIN_NAME} PROPERTIES
    VERSION ${CMAKE_PROJECT_VERSION}
    SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR})

target_compile_definitions(${BIN_NAME} PRIVATE VERSION="${CMAKE_PROJECT_VERSION}")

install(FILES ${DNDS_LIB_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${BIN_NAME})
install(TARGETS ${BIN_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR})

# for pc file config
set(PC_REQ_PRIVATE)
set(PC_REQ_PUBLIC)

# config pkgconfig file
configure_file(pkg/${BIN_NAME}.pc.in ${BIN_NAME}.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${BIN_NAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
# config cmake file
configure_file(pkg/${BIN_NAME}Config.cmake.in ${BIN_NAME}Config.cmake @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${BIN_NAME}Config.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${BIN_NAME})

# config qmake moudule file
set(DTK_MODULE ${BIN_NAME})
