# CS-10 booking / ticket reservation, built in steps. Each step is the whole
# program at that point in the study, and is built and tested on its own.
#   step-1  seats as a state machine, holds that expire on an injected
#           clock, one mutex per show, idempotent confirmation, and a stubbed
#           payment called with no lock held
#   step-2  change: group bookings (N seats, optionally side by side)
# The tests start real threads, so they carry the concurrency label and the
# tsan preset runs them.
find_package(Threads REQUIRED)

set(cs_ticket_sources show.cpp booking_service.cpp)
foreach(step IN ITEMS 1 2)
  list(TRANSFORM cs_ticket_sources PREPEND step-${step}/ OUTPUT_VARIABLE sources)
  add_library(cs_ticket_step${step} STATIC ${sources})
  target_include_directories(cs_ticket_step${step} PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/step-${step})
  target_link_libraries(cs_ticket_step${step} PUBLIC Threads::Threads)
  lld_add_test(cs_ticket_step${step}_tests
    SOURCES step-${step}/tests/test_step${step}.cpp LABELS unit concurrency)
  target_link_libraries(cs_ticket_step${step}_tests PRIVATE cs_ticket_step${step})
  lld_add_example(cs_ticket_step${step}_demo SOURCES step-${step}/main.cpp
    EXPECTED_OUTPUT step-${step}/expected_output.txt)
  target_link_libraries(cs_ticket_step${step}_demo PRIVATE cs_ticket_step${step})
endforeach()
