project( desq-session )
cmake_minimum_required( VERSION 3.8 )
set( CMAKE_CXX_STANDARD 17 )

set( CMAKE_INCLUDE_CURRENT_DIR ON )
set( CMAKE_AUTOMOC ON )
set( CMAKE_BUILD_TYPE Release )

set( PROJECT_VERSION 1.0.0 )
set( PROJECT_VERSION_MAJOR 1 )
set( PROJECT_VERSION_MINOR 0 )
set( PROJECT_VERSION_PATCH 0 )

set( PROJECT_VERSION_MAJOR_MINOR ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} )

add_definitions ( -Wall )
if ( CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT )
    set( CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Location for installing the project" FORCE )
endif()

if ( NOT DEFINED PKGCONFPATH )
    message( "-- PKGCONFPATH not set. Trying pkg-config" )
    find_package( PkgConfig REQUIRED )
    pkg_get_variable( PKGCONFPATH desq-core pkgconfpath )

    if ( PKGCONFPATH STREQUAL "" OR NOT DEFINED PKGCONFPATH )
        message( "-- Unable to retrieve the value of PKGCONFPATH." )
        set( PKGCONFPATH "/etc/xdg/desq" )
        message( "-- Using default value: /etc/xdg/desq" )
    endif()
endif()

cmake_policy( SET CMP0071 NEW )

set( CMAKE_AUTOMOC ON )
set( CMAKE_AUTORCC ON )
set( CMAKE_AUTOUIC ON )

find_package ( Qt5Core REQUIRED )
find_package ( Qt5DBus REQUIRED )

find_package( PkgConfig REQUIRED )
pkg_check_modules( DESQ_CORE REQUIRED desq-core )

include_directories(
    ${DESQ_CORE_INCLUDE_DIRS}
)

set ( SOURCES
	DesQSession.cpp
    DesQSession.hpp
	DesQSessionAdaptor.cpp
    DesQSessionAdaptor.hpp
	Main.cpp
)

add_executable ( desq-session ${SOURCES} )
target_link_libraries ( desq-session  Qt5::Core Qt5::DBus ${DESQ_CORE_LIBRARIES} )

configure_file( resources/wayfire.ini.in wayfire.ini @ONLY )

# Main Executable
install( TARGETS desq-session DESTINATION bin )

# Wayland and X11 Sessions
install( FILES resources/desqsession.desktop DESTINATION share/wayland-sessions )

# Configs
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/wayfire.ini DESTINATION share/desq/ )

# Configs
install( FILES resources/Session.conf DESTINATION ${PKGCONFPATH} )