pkg_check_modules(GLIB glib-2.0 REQUIRED)
pkg_check_modules(PROCESS_CPP process-cpp REQUIRED)
pkg_check_modules(UPSTART_APP_LAUNCH upstart-app-launch-2 REQUIRED)

add_definitions(-DQT_PLUGIN)

include_directories(
  ${GLIB_INCLUDE_DIRS}
  ${MIRCOMMON_INCLUDE_DIRS}
  ${MIRSERVER_INCLUDE_DIRS}
  ${PROCESS_CPP_INCLUDE_DIRS}
  ${UBUNTU_PLATFORM_API_INCLUDE_DIRS}
  ${UPSTART_APP_LAUNCH_INCLUDE_DIRS}

  ${CMAKE_SOURCE_DIR}/src/unity-mir
)

add_library(
  unityapplicationplugin SHARED

  application_manager.cpp
  application.cpp
  desktopfilereader.cpp
  plugin.cpp
  applicationscreenshotprovider.cpp
  dbuswindowstack.cpp
  taskcontroller.cpp
  mirsurface.cpp
  mirsurfacemanager.cpp
  inputarea.cpp
  inputfilterarea.cpp
  processcontroller.h
  processcontroller.cpp
  proc_info.cpp
  shellinputarea.cpp
  ubuntukeyboardinfo.cpp

  upstart/applicationcontroller.h
  upstart/applicationcontroller.cpp

  applicationcontroller.h
  application_manager.h
  application.h
  desktopfilereader.h
  applicationscreenshotprovider.h
  dbuswindowstack.h
  taskcontroller.h
  mirsurface.h
  mirsurfacemanager.h
  shellinputarea.h
  inputarea.h
  inputfilterarea.h
  ubuntukeyboardinfo.h
  
  # We need to pull in some external header files
  /usr/include/unity/shell/application/ApplicationManagerInterface.h
  /usr/include/unity/shell/application/ApplicationInfoInterface.h
)

# We should not need this line according to the Qt5/CMake docs.
# However, when removing it, include paths are not set and linking to Qt5 fails.
qt5_use_modules(unityapplicationplugin Core Quick DBus)

target_link_libraries(
  unityapplicationplugin
  
  unity-mir

  ubuntu_application_api_mirserver

  Qt5::Core
  Qt5::Quick
  Qt5::DBus

  ${CMAKE_THREAD_LIBS_INIT}

  ${GLIB_LDFLAGS}
  ${UBUNTU_PLATFORM_API_LDFLAGS}
  ${MIRSERVER_LDFLAGS}
  ${PROCESS_CPP_LDFLAGS}
  ${UPSTART_APP_LAUNCH_LDFLAGS}

  ubuntu_application_api_mirserver
)


execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=plugindir_suffix unity-shell-api OUTPUT_VARIABLE SHELL_PLUGINDIR OUTPUT_STRIP_TRAILING_WHITESPACE)
if(SHELL_PLUGINDIR STREQUAL "")
    set(SHELL_PLUGINDIR ${CMAKE_INSTALL_LIBDIR}/unity8/qml)
endif()

install(
  TARGETS unityapplicationplugin
  ARCHIVE DESTINATION ${SHELL_PLUGINDIR}/Unity/Application
  LIBRARY DESTINATION ${SHELL_PLUGINDIR}/Unity/Application
)

install(
  FILES qmldir OSKController.qml
  DESTINATION ${SHELL_PLUGINDIR}/Unity/Application
)
