# Keyleds -- Gaming keyboard tool
# Copyright (C) 2017 Julien Hartmann, juli1.hartmann@gmail.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
# (at your option) 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.0)

##############################################################################
# Options

option(NO_DBUS "Do not compile DBus support" OFF)

##############################################################################
# Sources

# Look for header files in build directory (for config.h) and include dir
include_directories("${CMAKE_CURRENT_BINARY_DIR}")

# List of sources
set(service_SRCS
    src/device/Logitech.cxx
    src/effect/EffectService.cxx
    src/effect/StaticModuleRegistry.cxx
    src/tools/DeviceWatcher.cxx
    src/tools/Event.cxx
    src/tools/FileWatcher.cxx
    src/tools/XContextWatcher.cxx
    src/tools/XInputWatcher.cxx
    src/DeviceManager.cxx
    src/DisplayManager.cxx
    src/Service.cxx
    src/main.cxx
)

IF(NOT NO_DBUS)
    set(service_SRCS ${service_SRCS}
        src/dbus/DeviceManager.cxx
        src/dbus/Service.cxx
    )
ENDIF()

##############################################################################
# Dependencies

find_library(LIBUDEV udev)
IF(NOT LIBUDEV)
    MESSAGE(SEND_ERROR "libudev is required for keyledsd")
ENDIF(NOT LIBUDEV)
set(service_DEPS ${service_DEPS} ${LIBUDEV})

find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBUV REQUIRED libuv)
include_directories(${LIBUV_INCLUDE_DIRS})
set(service_DEPS ${service_DEPS} ${LIBUV_LIBRARIES})

IF(NOT NO_DBUS)
    pkg_check_modules(LIBSYSTEMD REQUIRED libsystemd)
    include_directories(${LIBSYSTEMD_INCLUDE_DIRS})
    set(service_DEPS ${service_DEPS} ${LIBSYSTEMD_LIBRARIES})
ENDIF()

configure_file("include/config.h.in" "config.h")

##############################################################################
# Targets

# Binary
add_executable(${PROJECT_NAME} ${service_SRCS})
target_compile_definitions(${PROJECT_NAME} PRIVATE KEYLEDSD_MODULES_STATIC=1)
target_include_directories(${PROJECT_NAME} PRIVATE include)
target_link_libraries(${PROJECT_NAME} common core libkeyleds ${service_DEPS})

##############################################################################
# Installing stuff
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
