# Copyright (C) 2024 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/>.
# Qt对cmake版本的最小要求
cmake_minimum_required(VERSION 3.13.0)
# set(TARGET_PATH "${CMAKE_INSTALL_PREFIX}/lib")
set(BIN_NAME displayjack_kvm)
set(KVM_INCLUDE ${CMAKE_SOURCE_DIR}/include/input/kvm)
# 有些项目会动态生成头文件,项目中需要引入它,因此需要将output目录也include进来
# 等同于INCLUDE_DIRECTORY(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Qt5 对C++版本推荐至少11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(X11)
# 当前模块的头文件肯定要include进来
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${KVM_INCLUDE})
# 当前模块下的cpp跟CMakeList.txt在同级目录
# aux_source_directory(./ SRC_LIST)
set(KVM_LIB_SRCS
    displayjack_kvm.cpp
    ${CMAKE_CURRENT_BINARY_DIR}/wayland-dde-kvm-client-protocol.h
)
set(KVM_LIB_HEADERS
    ${KVM_INCLUDE}/displayjack_kvm.h
)
set(LIBS
    Wayland::Client
)

ecm_add_wayland_client_protocol(WAYLAND_PROTOCOLS
    PROTOCOL ${PROTOCOLS_PATH}/dde-kvm.xml
    BASENAME dde-kvm
)

add_library(${BIN_NAME} SHARED
    ${WAYLAND_PROTOCOLS}
    ${KVM_LIB_SRCS}
    ${KVM_LIB_HEADERS}
)
if(${CMAKE_BUILD_TYPE} MATCHES "Debug")
    string(REPLACE "-fsanitize=address" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()
# 链接所有其他模块到当前模块
target_link_libraries(${BIN_NAME} PRIVATE ${LIBS})
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 ${KVM_LIB_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${BIN_NAME})
install(TARGETS ${BIN_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR})