# CS-18 inventory management, 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  products and warehouses with strong ids, stock as on hand and
#           reserved, all-or-nothing reservations that commit or release
#           (safe to repeat), low-stock alerts sent outside the lock, and one
#           mutex for the whole inventory
#   step-2  change: transfers between warehouses, and stock held in batches
#           with expiry dates on an injected clock, reserved earliest expiry
#           first
# 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_inv_sources inventory.cpp)
foreach(step IN ITEMS 1 2)
  list(TRANSFORM cs_inv_sources PREPEND step-${step}/ OUTPUT_VARIABLE sources)
  add_library(cs_inv_step${step} STATIC ${sources})
  target_include_directories(cs_inv_step${step} PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/step-${step})
  target_compile_options(cs_inv_step${step} PUBLIC -Wconversion -Wshadow)
  target_link_libraries(cs_inv_step${step} PUBLIC Threads::Threads)
  lld_add_test(cs_inv_step${step}_tests
    SOURCES step-${step}/tests/test_step${step}.cpp LABELS unit concurrency)
  target_link_libraries(cs_inv_step${step}_tests PRIVATE cs_inv_step${step})
  lld_add_example(cs_inv_step${step}_demo SOURCES step-${step}/main.cpp
    EXPECTED_OUTPUT step-${step}/expected_output.txt)
  target_link_libraries(cs_inv_step${step}_demo PRIVATE cs_inv_step${step})
endforeach()
