IF(POLICY CMP0017)
   CMAKE_POLICY(SET CMP0017 NEW)
ENDIF(POLICY CMP0017)

IF(POLICY CMP0022)
   CMAKE_POLICY(SET CMP0022 NEW)
ENDIF(POLICY CMP0022)

IF(POLICY CMP0063)
   CMAKE_POLICY(SET CMP0063 NEW)
ENDIF(POLICY CMP0063)

SET(QT_MIN_VERSION  "5.2.0")

IF(${CMAKE_SYSTEM_NAME} MATCHES "Android")
    SET(OS_ANDROID 1)
ENDIF()

OPTION(ENABLE_NOTIFICATIONS ON)

IF(DEFINED OS_ANDROID)
    SET(ENABLE_NOTIFICATIONS OFF)
    SET(ENABLE_SINGLE_INSTANCE OFF)
ENDIF()


# It doesn't work in sandboxes
IF (NOT ENABLE_SINGLE_INSTANCE)
   ADD_DEFINITIONS(-DDISABLE_KDBUS_SERVICE=1)
ENDIF()


SET(CMAKE_CXX_STANDARD 14)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

#Make sure it can access DBUS autogenerated files
INCLUDE_DIRECTORIES(SYSTEM ${ringqt_INCLUDE_DIR})

INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src)

IF(${CMAKE_BUILD_TYPE} MATCHES Release)
    MESSAGE("NO DEBUG OUTPUT")
    ADD_DEFINITIONS( -DQT_NO_DEBUG_OUTPUT)
ENDIF(${CMAKE_BUILD_TYPE} MATCHES Release)

IF(NOT ENABLE_NOTIFICATIONS)
    ADD_DEFINITIONS(-DDISABLE_NOTIFICATION=1)
ENDIF()

SET(
   ring_kde_SRCS
   main.cpp
   cmd.cpp
   ringapplication.cpp
)

QT5_ADD_RESOURCES(ring_kde_SRCS appicon.qrc)

# add_subdirectory( test   ) #Enable again some day, it cause compile problems for some users

IF(NOT (${ENABLE_VIDEO} MATCHES false))
   SET(ENABLE_VIDEO 1 CACHE BOOLEAN "Enable video")
   ADD_DEFINITIONS( -DENABLE_VIDEO=true )
ENDIF(NOT (${ENABLE_VIDEO} MATCHES false))

IF(${DISABLE_UNIQUE_APPLICATION} MATCHES true)
   MESSAGE("KUniqueApplication disabled")
   SET(DISABLE_UNIQUE_APPLICATION 1 CACHE BOOLEAN "Disable KUniqueApplication")
   ADD_DEFINITIONS( -DDISABLE_UNIQUE_APPLICATION=true )
ENDIF(${DISABLE_UNIQUE_APPLICATION} MATCHES true)

IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  ADD_EXECUTABLE(ring-kde MACOSX_BUNDLE ${ring_kde_SRCS})

  set_source_files_properties( ../data/ring-kdeui.rc PROPERTIES MACOSX_PACKAGE_LOCATION Resources )
  file( COPY ../data/ring-kdeui.rc DESTINATION "ring-kde.app/Contents/Resources/" )
ELSE()
  ADD_EXECUTABLE(ring-kde ${ring_kde_SRCS})
ENDIF()

IF(NOT ${ENABLE_STATIC} MATCHES false)
  FIND_PACKAGE(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED DBus)
  INCLUDE_DIRECTORIES(SYSTEM ${Qt5DBus_INCLUDE_DIRS} )
  LINK_DIRECTORIES(${Qt5DBus_LIBRARY_DIRS} )
  ADD_DEFINITIONS(${Qt5DBus_CFLAGS})

  IF(NOT DEFINED OS_ANDROID)
    TARGET_LINK_LIBRARIES(ring-kde
      -lpthread
    )
  ENDIF()

  TARGET_LINK_LIBRARIES(ring-kde
    ${ringqt_LIBRARY_STATIC}
  )

  IF(NOT ${ENABLE_LIBWRAP})
    TARGET_LINK_LIBRARIES(ring-kde
        ${Qt5DBus_LIBRARIES}
    )
  ENDIF()

ELSE()
   TARGET_LINK_LIBRARIES(ring-kde ${ringqt_LIBRARY_DYNAMIC})
ENDIF()

QT5_ADD_DBUS_ADAPTOR(ring_kde_SRCS ../data/org.kde.kuiserver.xml cmd.h Cmd )

TARGET_LINK_LIBRARIES(ring-kde
  jamiwizard
  jamicallview
  jamidialview
  jamitimelineview
  jamiphotoselector
  jamicanvasindicator
  desktopview
  jamicontactview
  jamiaccountview
  genericutils
  kquickitemviews
  jamikdeintegration
  jamivideoview
  jamitroubleshooting
  jamihistoryview
  jamichatview
  jamitimelinebase
  jamiaudioplayer

  # RingQt
  ringqtquick

  # Qt5
  Qt5::Widgets
  Qt5::Core
  Qt5::Gui
  Qt5::Svg
  Qt5::PrintSupport

  # KF5
  KF5::I18n
  KF5::WidgetsAddons
  KF5::ConfigCore
  KF5::ConfigGui
  KF5::DBusAddons
  KF5::XmlGui
  KF5::IconThemes
  KF5::Crash
  KF5::GlobalAccel
  KF5::Declarative
  KF5::Kirigami2
)

IF(ENABLE_NOTIFICATIONS)
    TARGET_LINK_LIBRARIES(ring-kde
        jaminotification

        # KF5
        KF5::Notifications
        KF5::NotifyConfig
    )
ENDIF()

IF (Qt5TextToSpeech_FOUND)
   TARGET_LINK_LIBRARIES(ring-kde
      Qt5::TextToSpeech
   )
ENDIF()

########### install files ###############

INSTALL( TARGETS ring-kde DESTINATION ${BIN_INSTALL_DIR})
