cmake_minimum_required(VERSION 3.15)

project(pfe)

set(VTK_COMPONENTS
  VTK::CommonCore
  VTK::IOCore
  VTK::FiltersCore
  VTK::CommonColor
  VTK::CommonDataModel
  VTK::IOLegacy
  VTK::IOGeometry
  VTK::IOXML
  VTK::FiltersModeling
  VTK::FiltersGeometry
  VTK::vtksys)
set(ENABLE_VIEWER OFF CACHE BOOL "Enable the 3D viewer, depends on Qt.")
if(ENABLE_VIEWER)
  list(APPEND VTK_COMPONENTS
	VTK::RenderingCore
	VTK::ViewsCore
	VTK::GUISupportQt
	VTK::RenderingQt
	VTK::ViewsQt
	VTK::RenderingVolume
	VTK::RenderingVolumeOpenGL2)
endif()

set(USE_SYSTEM_VTK NO CACHE BOOL
  "Use the version of vtk installed in the system instead of downloading and compiling it ourselves.")
if(USE_SYSTEM_VTK)
  list(TRANSFORM VTK_COMPONENTS REPLACE "VTK::" ""
	OUTPUT_VARIABLE VTK_PACKAGE_COMPONENTS)
  message("VTK_COMPONENTS: ${VTK_COMPONENTS}")
  message("VTK_PACKAGE_COMPONENTS: ${VTK_PACKAGE_COMPONENTS}")
  find_package(VTK COMPONENTS ${VTK_PACKAGE_COMPONENTS})
else()
  add_subdirectory(external/vtk)
endif()

add_executable(pfe)

target_compile_features(pfe PRIVATE cxx_std_17)

target_sources(pfe PRIVATE
  src/main.cc
  src/angles_filter.cc
  src/angles_filter.h
  src/aspect_ratio_filter.cc
  src/aspect_ratio_filter.h
  src/dihedral_angles_filter.cc
  src/dihedral_angles_filter.h
  src/surface_points_filter.cc
  src/surface_points_filter.h
  src/kd_tree.cc
  src/kd_tree.h
  src/mesh_fit_filter.cc
  src/mesh_fit_filter.h
  src/point_tris_dist.cc
  src/point_tris_dist.h
  src/project_surface_points_on_poly.cc
  src/project_surface_points_on_poly.h
  src/remove_external_cells_filter.cc
  src/remove_external_cells_filter.h
  src/relaxation_filter.cc
  src/relaxation_filter.h
  src/max_distance_filter.cc
  src/max_distance_filter.h
  src/closest_polymesh_point.cc
  src/closest_polymesh_point.h)

target_link_libraries(pfe PRIVATE ${VTK_COMPONENTS})

if(ENABLE_VIEWER)
  target_compile_definitions(pfe PRIVATE ENABLE_VIEWER)
endif()
