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

cmake_minimum_required(VERSION 3.13)

# If do't define version number, specify the version number
set (VERSION "1.0.0" CACHE STRING "define project version")

set(BIN_NAME displayjack)

set(PROTOCOLS_PATH ${CMAKE_SOURCE_DIR}/src/protocols)
set(COMMON_PATH ${CMAKE_SOURCE_DIR}/src/common)

project(${BIN_NAME}
    HOMEPAGE_URL https://github.com/linuxdeepin/dtk-template
    DESCRIPTION "display jack module"
    VERSION ${VERSION}
)
enable_language(C)

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer")
endif ()

if(dtkclipboardace_FOUND)
    set(BUILD_TESTING ON)
endif ()

# specify include modules
include(CheckIncludeFiles)
include(CheckLibraryExists)
include(CheckFunctionExists)
include(FindPkgConfig)
include(FeatureSummary)
include(GNUInstallDirs)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

include(UseDoxygenDoc)

include_directories("include/" ${CMAKE_SOURCE_DIR}/src)
link_directories(${CMAKE_BINARY_DIR})
add_definitions("-Wall -D_GNU_SOURCE")

# ECM setup
find_package(ECM 5.54.0  NO_MODULE)
set_package_properties(ECM PROPERTIES TYPE REQUIRED DESCRIPTION "Extra CMake Modules." URL "https://commits.kde.org/extra-cmake-modules")
feature_summary(WHAT REQUIRED_PACKAGES_NOT_FOUND FATAL_ON_MISSING_REQUIRED_PACKAGES)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/Modules)

# wayland client
find_package(Wayland 1.13 COMPONENTS Client)
set_package_properties(Wayland PROPERTIES TYPE REQUIRED)
find_package(WaylandScanner)

# Install settings
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
    set(CMAKE_INSTALL_PREFIX /usr)
endif ()

add_subdirectory(src)
add_subdirectory(dbus)
add_subdirectory(qt)

set(BUILD_DOCS ON CACHE BOOL "Generate doxygen-based documentation")
find_package(Doxygen)

if (BUILD_DOCS AND DOXYGEN_FOUND)
    add_doxygen_doc(
        BUILD_DIR
            ${CMAKE_CURRENT_BINARY_DIR}/_build
        DOXY_FILE
            ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in
        TARGET_NAME
            docs
        COMMENT
            "HTML documentation"
    )
endif ()

# test
if (BUILD_TESTING)
    add_subdirectory(example)
#    add_subdirectory(tests)
endif()

install(FILES ${PROJECT_SOURCE_DIR}/docs/displayjack_development_manual.pdf DESTINATION "/usr/share/doc/displayjack/")
