# 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(BIN_NAME dtkwmjack)
set(WMJACK_INCLUDE ${CMAKE_SOURCE_DIR}/include/wmjack)

find_package(X11)
find_package(PkgConfig REQUIRED)
find_package(EGL)
pkg_search_module(DBUSGLIB REQUIRED dbus-glib-1)
pkg_search_module(GLIB REQUIRED glib-2.0)

include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${WMJACK_INCLUDE})
include_directories(${DBUSGLIB_INCLUDE_DIRS})
include_directories(${GLIB_INCLUDE_DIRS})
link_directories(${GLIB_LIBRARY_DIRS})
include_directories(${COMMON_PATH})
include_directories(../uace/src/ext/)

set(SCREEN_LIB_SRCS
    dtk_wmjack.c
    dtk_wmjack_x11.c
    dtk_wmjack_wayland.c
    ${WMJACK_INCLUDE}/dtk_wmjack.h
    wayland_client_management.c
    ${WMJACK_INCLUDE}/wayland_client.h
    ${COMMON_PATH}/log.c
    ${COMMON_PATH}/log.h
    ${COMMON_PATH}/dtk_utils.c
    ${COMMON_PATH}/dtk_utils.h
    ${CMAKE_CURRENT_BINARY_DIR}/wayland-client-management-client-protocol.h
    glad/glad.c
    )

set(SCREEN_LIB_HEADERS
    ${WMJACK_INCLUDE}/dtk_wmjack.h
    )

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

add_library(${BIN_NAME} SHARED
    ${SCREEN_LIB_SRCS}
    ${SCREEN_LIB_HEADERS}
)

target_link_libraries(
    ${BIN_NAME}
    PUBLIC
    ${DBUSGLIB_LDFLAGS}
    ${GLIB_LIBRARIES}
    uaceExt
    EGL
    GL
)

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

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 ${SCREEN_LIB_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${BIN_NAME})
install(TARGETS ${BIN_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR})

install(
    FILES
    configures/video-blacklist
    DESTINATION
    "/usr/share/displayjack/wmjack/"
)