cmake_minimum_required(VERSION 3.15)

# Jupyter kernel installation path default values. Assign it before projet() so it override CMake defaults.
# (see https://jupyter-client.readthedocs.io/en/stable/kernels.html#kernel-specs)
if(WIN32)
  set(CMAKE_INSTALL_PREFIX
    "%PROGRAMDATA%/jupyter/kernels" CACHE PATH
    "Install path prefix, prepended onto install directories.")
else()
  set(CMAKE_INSTALL_PREFIX
    "/usr/share/jupyter/kernels" CACHE PATH
    "Install path prefix, prepended onto install directories.")
endif()

project(IParaView)

find_package(ParaView REQUIRED)

option(BUILD_SHARED_LIBS "Build shared libraries" ON)

include(GNUInstallDirs)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}")

# Build jupyter kernel
add_subdirectory("IParaViewKernel")

# Build Qt Client plugin
set("_paraview_plugin_default_PVQtJupyterPlugin" ON)
paraview_plugin_scan(
  PLUGIN_FILES
    "${CMAKE_CURRENT_SOURCE_DIR}/PVQtJupyterPlugin/paraview.plugin"
  PROVIDES_PLUGINS  plugins
  REQUIRES_MODULES  required_modules)

foreach (module IN LISTS required_modules)
  if (NOT TARGET "${module}")
    message(FATAL_ERROR
      "Missing required module for plugins: "
      "${module}")
    return ()
  endif ()
endforeach ()

paraview_plugin_build(
  RUNTIME_DESTINATION "${CMAKE_PROJECT_NAME}"
  LIBRARY_DESTINATION "${CMAKE_PROJECT_NAME}"
  LIBRARY_SUBDIRECTORY ""
  PLUGINS ${plugins})
