
include(wmtk_data)

list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/components/cmake")

option(WMTK_COMPONENT_TESTS "Generate component unit tests." ON)

include (jse)

include(add_component)
include(add_component_test)

#clear autogenerated the files
set(WMTK_AUTOGEN_COMMENT "// This file was auto-generated with CMake\n")
file(WRITE "${CMAKE_SOURCE_DIR}/app/components_include.hpp" ${WMTK_AUTOGEN_COMMENT})
file(WRITE "${CMAKE_SOURCE_DIR}/app/components_map.hpp" ${WMTK_AUTOGEN_COMMENT})
file(WRITE "${CMAKE_SOURCE_DIR}/app/components_memory_map.hpp" ${WMTK_AUTOGEN_COMMENT})
file(WRITE "${CMAKE_SOURCE_DIR}/app/components_python.hpp" ${WMTK_AUTOGEN_COMMENT})
file(WRITE "${CMAKE_SOURCE_DIR}/app/components_spec_include.hpp" ${WMTK_AUTOGEN_COMMENT})
file(WRITE "${CMAKE_SOURCE_DIR}/app/components_spec_map.hpp" ${WMTK_AUTOGEN_COMMENT})
if(WMTK_BUILD_INTEGRATION_TESTS)
    target_include_directories(wmtk_integration_tests PUBLIC  "${CMAKE_SOURCE_DIR}/app")
endif()

# list of all components
add_subdirectory("shortest_edge_collapse/wmtk/components/shortest_edge_collapse")
add_subdirectory("isotropic_remeshing/wmtk/components/isotropic_remeshing")
add_subdirectory("qslim/wmtk/components/qslim")
add_subdirectory("tetwild/wmtk/components/tetwild")
add_subdirectory("triwild/wmtk/components/triwild")
add_subdirectory("simwild/wmtk/components/simwild")
add_subdirectory("c1_simplification/wmtk/components/c1_simplification")
add_subdirectory("manifold_extraction/wmtk/components/manifold_extraction")
add_subdirectory("topological_offset/wmtk/components/topological_offset")
add_subdirectory("prismatic_mesh/wmtk/components/prismatic_mesh")
add_subdirectory("tracking/wmtk/components/tracking")

if(BUILD_TESTING AND WMTK_COMPONENT_TESTS)
    include(wmtk_data)
    add_executable(wmtk_component_io_tests "${PROJECT_SOURCE_DIR}/tests/test_component_io.cpp")
    target_link_libraries(wmtk_component_io_tests PRIVATE wmtk::toolkit wmtk::data Catch2::Catch2WithMain)
    # Every enabled component (add_component records them), so a new one is tested here too.
    get_property(WMTK_IO_TEST_COMPONENTS GLOBAL PROPERTY WMTK_COMPONENTS)
    foreach(component IN LISTS WMTK_IO_TEST_COMPONENTS)
        if(TARGET wmtk_${component})
            target_link_libraries(wmtk_component_io_tests PRIVATE wmtk_${component})
            target_compile_definitions(wmtk_component_io_tests PRIVATE WMTK_TEST_${component})
        endif()
    endforeach()
    wmtk_copy_dll(wmtk_component_io_tests)
    catch_discover_tests(wmtk_component_io_tests)
endif()
