cmake_minimum_required(VERSION 3.12...4.4)
project(Mesh_smoothing_3_Examples)

message(STATUS "CGAL_DIR: ${CGAL_DIR}")

find_package(CGAL REQUIRED)
find_package(Eigen3 QUIET)
include(CGAL_Eigen3_support)

if (NOT TARGET CGAL::Eigen3_support)
  message("NOTICE: This project requires the Eigen library, and will not be compiled.")
  return()
endif()

create_single_source_cgal_program("c3t3_smooth.cpp")
create_single_source_cgal_program("hybrid_domain_feature_recovery.cpp")
create_single_source_cgal_program("implicit_domain_feature_recovery.cpp")
target_link_libraries(c3t3_smooth PRIVATE CGAL::Eigen3_support)
target_link_libraries(hybrid_domain_feature_recovery PRIVATE CGAL::Eigen3_support)
target_link_libraries(implicit_domain_feature_recovery PRIVATE CGAL::Eigen3_support)

option(USE_ONLY_OPENMP_FOR_PARALLELISM OFF "Use OpenMP instead of TBB for parallelism")

if (NOT USE_ONLY_OPENMP_FOR_PARALLELISM)
    find_package(TBB QUIET)
    include (CGAL_TBB_support)
    if(TARGET CGAL::TBB_support)
    target_link_libraries(c3t3_smooth PRIVATE CGAL::TBB_support)
    target_link_libraries(hybrid_domain_feature_recovery PRIVATE CGAL::TBB_support)
    target_link_libraries(implicit_domain_feature_recovery PRIVATE CGAL::TBB_support)
    endif()
endif()

find_package(OpenMP COMPONENTS CXX)
if(OpenMP_CXX_FOUND)
    message(STATUS "OpenMP found")
    if(MSVC)
        # Override the compile options for the imported OpenMP target
        set_target_properties(OpenMP::OpenMP_CXX PROPERTIES
                            INTERFACE_COMPILE_OPTIONS "/openmp:llvm")
    endif()
    # target_link_libraries(alpha_wrap_improvement PRIVATE OpenMP::OpenMP_CXX)
    target_link_libraries(c3t3_smooth PRIVATE OpenMP::OpenMP_CXX)
    target_link_libraries(hybrid_domain_feature_recovery PRIVATE OpenMP::OpenMP_CXX)
    target_link_libraries(implicit_domain_feature_recovery PRIVATE OpenMP::OpenMP_CXX)
else()
    message(STATUS "OpenMP was not found.")
endif()
