set(sources
  Geometry.cxx
  Operation.cxx
  Registrar.cxx
  Resource.cxx
  Session.cxx
  operators/Export.cxx
  operators/Import.cxx
  operators/MeshLabel.cxx
  operators/Segment.cxx
  operators/SelectionResponder.cxx
  vtk/vtkMedReader.cxx
)

set(headers
  Geometry.h
  Operation.h
  Registrar.h
  Resource.h
  Session.h
  operators/Export.h
  operators/Import.h
  operators/MeshLabel.h
  operators/Segment.h
  operators/SelectionResponder.h
  vtk/vtkMedReader.h
)

set(sbt
  operators/Export.sbt
  operators/Import.sbt
  operators/MeshLabel.sbt
  operators/Segment.sbt
  operators/SelectionResponder.sbt
)

file(GLOB SESSION_FILES "*.h" "*.cxx")
source_group("session" FILES ${SESSION_FILES})
file(GLOB OPERATIONS_FILES "operators/*.h" "operators/*.cxx" "operators/*.sbt")
source_group("session\\operators" FILES ${OPERATIONS_FILES})
file(GLOB VTK_FILES "vtk/*.h" "vtk/*.cxx")
source_group("session\\vtk" FILES ${VTK_FILES})

find_package(HDF5 REQUIRED)

add_library(smtkAEVASession SHARED ${sources} ${headers} ${sbt})
target_link_libraries(smtkAEVASession
  PUBLIC
    smtkCore
    smtkPVServerExt
    vtkSMTKSourceExt
  PRIVATE
    VTK::CommonCore
    VTK::CommonDataModel
    VTK::IOXML
    VTK::IOGeometry
    VTK::FiltersExtraction
    VTK::FiltersGeometry
    ${ITK_LIBRARIES}
    ${__dependencies}
    ${Boost_LIBRARIES}
    ${HDF5_LIBRARIES}
)
target_include_directories(smtkAEVASession
  PUBLIC
    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
    $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
    $<INSTALL_INTERFACE:include>
    ${Boost_INCLUDE_DIR}
    ${HDF5_INCLUDE_DIRS}
)
target_compile_definitions(smtkAEVASession PRIVATE ${HDF5_DEFINITIONS})

generate_export_header(smtkAEVASession EXPORT_FILE_NAME Exports.h)

# Operators which have XML descriptions in separate files
# need to have it encoded as a string in a header.
# We do not need the path to the generated header (appended
# to aevaOperationXML) since the operators themselves include
# the header in their implementations.
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/Export.sbt" aevaOperationXML)
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/Import.sbt" aevaOperationXML)
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/MeshLabel.sbt" aevaOperationXML)
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/Segment.sbt" aevaOperationXML)
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/SelectionResponder.sbt" aevaOperationXML)

smtk_get_kit_name(name dir_prefix)

# Install the header files
install(
  FILES
    ${headers}
    ${CMAKE_CURRENT_BINARY_DIR}/Exports.h
  DESTINATION
    include/${PROJECT_NAME}/${PROJECT_VERSION}/${dir_prefix})

# Install the library and exports
install(
  TARGETS smtkAEVASession
  EXPORT  AEVASession
  ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
  LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
  RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
  PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${PROJECT_VERSION}/${dir_prefix}"
)

if(SMTK_ENABLE_PARAVIEW_SUPPORT)
  paraview_plugin_scan(
    PLUGIN_FILES "${CMAKE_CURRENT_SOURCE_DIR}/plugin/paraview.plugin"
    PROVIDES_PLUGINS paraview_plugins
    ENABLE_BY_DEFAULT ON
    HIDE_PLUGINS_FROM_CACHE ON
  )
  paraview_plugin_build(
    HEADERS_DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${PROJECT_VERSION}"
    LIBRARY_SUBDIRECTORY "${PROJECT_NAME}-${PROJECT_VERSION}"
    PLUGINS ${paraview_plugins}
    PLUGINS_FILE_NAME "aeva.xml"
    AUTOLOAD ${paraview_plugins}
    INSTALL_EXPORT AEVASessionPlugins
    CMAKE_DESTINATION ${CMAKE_INSTALL_CMAKEDIR}
    ADD_INSTALL_RPATHS ON
    TARGET aeva_session_paraview_plugins
  )
endif()

# if (AEVA_ENABLE_PYTHON)
#   add_subdirectory(pybind11)
# endif()

if (AEVA_ENABLE_TESTING)
  add_subdirectory(testing)
endif()
