# 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/>.

set(TARGET_NAME "prohibitscreenshotDbus")
set(DBUS_NAME "com.deepin.prohibitscreenshotDbus")

include_directories(${CMAKE_CURRENT_BINARY_DIR})

set(SOURCES_DBUS_SERVER_FILES
    ../config/screenshotconfig.cpp
    ../utils/paths.cpp
    ../utils/string.cpp
    dbus.cpp
    dbusadaptor.cpp
    prohibitscreenshot.cpp
    window-system/x11.cpp
    prohibitedwindowdecision.cpp
)

find_package(X11)
find_package(Threads REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5DBus REQUIRED)
find_package(Qt5Xml REQUIRED)
find_package(PolkitQt5-1)
find_package(PkgConfig REQUIRED)
pkg_search_module(DBUSGLIB REQUIRED dbus-glib-1)

add_executable(
    ${TARGET_NAME}
    ${SOURCES_DBUS_SERVER_FILES}
)
target_link_libraries(
    ${TARGET_NAME}
    PUBLIC
    stdc++fs # std::filesystem
    Threads::Threads # std::thread
    Qt5::DBus
    Qt5::Xml
    KF5::WaylandClient
    PolkitQt5-1::Agent
    -lX11
    -lxcb
    -ldl
    -lwayland-client
)

install(TARGETS ${TARGET_NAME} DESTINATION "/usr/bin/")
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/installation/${DBUS_NAME}.policy DESTINATION "/usr/share/polkit-1/actions/" PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/installation/${DBUS_NAME}.service DESTINATION "/usr/share/dbus-1/services/" PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/installation/${DBUS_NAME}.conf DESTINATION "/etc/dbus-1/system.d/" PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)