add_library(rtt_trace src/ray_batch.cpp src/apply_event.cpp src/sequential.cpp src/sources.cpp
  src/run_control.cpp)
add_library(rtt::trace ALIAS rtt_trace)
target_include_directories(rtt_trace PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
# rtt-paraxial provides pupils and the paraxial chief ray for aiming (ADR 0016).
# rtt-coating: layer type in EventMedia; rtt-polar: interface PRT matrices (ADR 0021).
target_link_libraries(rtt_trace PUBLIC rtt::compile rtt::paraxial rtt::coating rtt::math
  PRIVATE rtt::polar TBB::tbb)
rtt_target_defaults(rtt_trace LIBRARY)

if(RTT_BUILD_TESTS)
  # rtt::io only loads the reference systems in the tests; TBB limits the threads in the
  # determinism test.
  rtt_add_test(rtt_trace_tests
    SOURCES tests/test_ray_batch.cpp tests/test_apply_event.cpp tests/test_sequential.cpp
            tests/test_polygon_aperture.cpp tests/test_obscuration_shapes.cpp
            tests/test_sources.cpp tests/test_interactions.cpp tests/test_ray_paths.cpp
            tests/test_start_plane.cpp
            tests/test_accumulated_q.cpp
            tests/test_run_control.cpp tests/test_parallel_aiming.cpp
            tests/test_diffraction.cpp tests/test_crystal_trace.cpp tests/test_relative_trace.cpp
            tests/test_gauss_pupil.cpp tests/test_ideal_lens_trace.cpp
            tests/test_point_list_pupil.cpp tests/test_ideal_lens_aiming.cpp
            tests/test_obscuration.cpp tests/test_aim_reference.cpp tests/test_object_medium.cpp
            tests/test_object_reference.cpp
            tests/test_aim_continuation.cpp tests/test_surface_stop.cpp tests/test_real_na.cpp
            tests/test_anamorphic_trace.cpp tests/test_anamorphic_aiming.cpp
            tests/test_rotational_trace.cpp tests/test_forbes_trace.cpp tests/test_xy_trace.cpp tests/test_active_trace.cpp
    LIBS rtt::trace rtt::io rtt::polar rtt::coating rtt::model_test_support TBB::tbb)
  # src/: the continuation fallback of real aiming (aim_continuation.hpp, #287) and the start plane
  # at the vertex (start_plane.hpp, ADR 0041, point 6) are tested directly.
  target_include_directories(rtt_trace_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
  target_compile_definitions(rtt_trace_tests PRIVATE
    RTT_CATALOG_DIR="${PROJECT_SOURCE_DIR}/tests/catalogs")
endif()
