set(sources
  aevaAboutDialogReaction.cxx
  aevaAboutDialogReaction.h
  mbMainWindow.cxx
  mbMainWindow.h
  mbMenuBuilder.cxx
  mbMenuBuilder.h
  mbObjectFactory.cxx
  mbObjectFactory.h
  mbReaderFactory.cxx
  mbReaderFactory.h
  mbTestEventPlayer.cxx
  mbTestEventPlayer.h
  mbTestEventTranslator.cxx
  mbTestEventTranslator.h
  ${CMAKE_CURRENT_BINARY_DIR}/mbTestData.h
  ${CMAKE_CURRENT_BINARY_DIR}/mbVersion.h
)

set(ui_files
  ui/mbFileMenu.ui
  ui/mbMainWindow.ui
)

set(rc_files
  resource/mbResource.qrc
)
list(APPEND sources ${rc_files})

set(CMAKE_AUTOMOC 1)
set(CMAKE_AUTOUIC 1)
set(CMAKE_AUTORCC 1)
set(CMAKE_AUTOUIC_SEARCH_PATHS
  "${CMAKE_CURRENT_SOURCE_DIR}/ui")

configure_file(
  ${PROJECT_SOURCE_DIR}/cmake/Version.h.in
  ${CMAKE_CURRENT_BINARY_DIR}/mbVersion.h
)

configure_file(
  mbTestData.h.in
  ${CMAKE_CURRENT_BINARY_DIR}/mbTestData.h
)

set (gui_xml_files
 "${CMAKE_CURRENT_SOURCE_DIR}/postprocessing-filters.xml"
 "${CMAKE_CURRENT_SOURCE_DIR}/postprocessing-sources.xml"
)

# A list of "plugin targets" generated by ParaView's plugin infrastructure.
# They are added as available. ParaView's client infrastructure makes use of
# these to allow them to be automatically loaded at runtime.
set(smtk_plugins_targets)
set(required_plugins
  aevaPostProcessingModePlugin)
if (TARGET smtk_paraview_plugins)
  list(APPEND smtk_plugins_targets
    smtk_paraview_plugins)
  list(APPEND required_plugins
    smtkPVServerExtPlugin)
endif ()
if (TARGET smtk_paraview_extension_plugin)
  list(APPEND smtk_plugins_targets
    smtk_paraview_extension_plugin)
endif ()
foreach (plugin_dependency IN LISTS AEVA_EXTRA_SMTK_PLUGINS)
  string(REPLACE "-" "_" plugin_dependency "${plugin_dependency}")
  list(APPEND smtk_plugins_targets
    "${plugin_dependency}_paraview_plugins")
endforeach ()

set(title "aeva ${aeva_version} ${aeva_build_architecture}-bit")
#------------------------------------------------------------------------------
# Build the client
paraview_client_add(
  NAME "aeva"
  APPLICATION_NAME "aeva"
  TITLE "${title}"
  ORGANIZATION  "aeva"
  VERSION ${aeva_version_major}.${aeva_version_minor}.${aeva_version_patch}
  MAIN_WINDOW_CLASS mbMainWindow
  MAIN_WINDOW_INCLUDE mbMainWindow.h
  BUNDLE_ICON   "${CMAKE_CURRENT_SOURCE_DIR}/aeva.icns"
  BUNDLE_PLIST  "${CMAKE_CURRENT_SOURCE_DIR}/resource/MacOSXBundleInfo.plist.in"
  APPLICATION_ICON  "${CMAKE_CURRENT_SOURCE_DIR}/aeva.ico"
  APPLICATION_XMLS ${application_gui_xmls}
  SOURCES ${sources}
  PLUGINS_TARGETS aeva_paraview_plugins ${smtk_plugins_targets} ParaView::paraview_plugins
  REQUIRED_PLUGINS ${required_plugins}
  APPLICATION_XMLS ${ParaView_CLIENT_XML_FILES}
  SPLASH_IMAGE "${CMAKE_CURRENT_SOURCE_DIR}/resource/splash.png"
)

target_link_libraries(aeva
  LINK_PRIVATE
    ${qt_targets}
    aevaPostProcessingModePlugin
)
target_include_directories(aeva
  PUBLIC
    $<BUILD_INTERFACE:${aeva_SOURCE_DIR}>
    $<BUILD_INTERFACE:${aeva_BINARY_DIR}>
)

#if (PARAVIEW_ENABLE_EMBEDDED_DOCUMENTATION)
#  # Link against the documentation module.
#  target_link_libraries(aeva
#    LINK_PRIVATE vtkParaViewDocumentation)
#endif()

# link enabled plugins if not building in shared library mode and
# add dependecies to linked python modules These are non-empty only when
# building statically.
if(TARGET VTK::UtilitiesPythonInitializer)
  target_link_libraries(aeva
    LINK_PRIVATE
      VTK::UtilitiesPythonInitializer
  )
endif()

if (aeva_enable_testing)
  add_subdirectory(testing)
endif ()

#------------------------------------------------------------------------------
if (UNIX AND NOT APPLE)
  configure_file(
    aeva.desktop.in
    "${CMAKE_CURRENT_BINARY_DIR}/aeva.desktop"
    @ONLY)
  install(
    FILES       "${CMAKE_CURRENT_BINARY_DIR}/aeva.desktop"
    DESTINATION share/applications
    COMPONENT   runtime)
  foreach (iconsize 22x22 32x32 96x96)
    install(
      FILES       "resource/aeva-${iconsize}.png"
      DESTINATION "share/icons/hicolor/${iconsize}/apps"
      RENAME      aeva.png
      COMPONENT   runtime)
  endforeach ()
  install(
    FILES       resource/aeva.appdata.xml
    DESTINATION share/appdata
    COMPONENT   runtime)
endif()
