# CS-11 task scheduler, 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  run-once and periodic tasks on an injected clock, a queue ordered
#           by (due time, sequence number), a fixed pool of worker threads,
#           cancellation, and shutdown with a drain or discard policy
#   step-2  change: retries with backoff, and dependencies between tasks
# The tests start real threads, so they carry the concurrency label and the
# tsan preset runs them. This example is also built with -Wconversion and
# -Wshadow (PUBLIC, so its tests and demos are too).
find_package(Threads REQUIRED)

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