# Copyright (c) 2025 The YAC Authors
#
# SPDX-License-Identifier: BSD-3-Clause

if(NOT YAC_ENABLE_NETCDF)
  message(
    FATAL_ERROR
      "NetCDF is needed to build the tools. Enable it with -DYAC_ENABLE_NETCDF=ON."
  )
endif()

add_executable(debug_grid2vtk.x debug_grid2vtk.c)
target_link_libraries(debug_grid2vtk.x yac_core yac_utils NetCDF::NetCDF_C)
set_target_properties(
  debug_grid2vtk.x PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE
)

add_executable(weights2vtk.x weights2vtk.c)
target_link_libraries(weights2vtk.x yac_core yac_utils NetCDF::NetCDF_C)
set_target_properties(weights2vtk.x PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)

add_executable(yac_compute_weights.x yac_compute_weights.c)
target_link_libraries(
  yac_compute_weights.x yac_utils yac_mci yaxt::yaxt_c NetCDF::NetCDF_C
)
set_target_properties(
  yac_compute_weights.x PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE
)

# Install tools
if(DEFINED SKBUILD)
  # When built via pip/scikit-build-core, install to Python package directory
  install(
    TARGETS debug_grid2vtk.x weights2vtk.x yac_compute_weights.x
    RUNTIME DESTINATION ${SKBUILD_SCRIPTS_DIR}
  )

  install(
    FILES yac_plot_weights.py
          yac_plot_grids.py
          yac_plot_coupling_config.py
          yac_generate_weights.py
          yac_record.py
          yac_replay.py
    DESTINATION ${SKBUILD_SCRIPTS_DIR}
  )
else()
  # Standard CMake install
  install(
    TARGETS debug_grid2vtk.x weights2vtk.x yac_compute_weights.x
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  )
endif()
