# One library per layer. Each layer's headers are visible only to the
# layers allowed to use it; a forbidden #include fails to compile.
add_library(arch_layered_domain STATIC domain/course.cpp)
target_include_directories(arch_layered_domain PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/domain)

add_library(arch_layered_infrastructure STATIC
  infrastructure/memory_store.cpp infrastructure/mail_outbox.cpp)
target_include_directories(arch_layered_infrastructure PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/infrastructure)
target_link_libraries(arch_layered_infrastructure PUBLIC arch_layered_domain)

# PRIVATE: the application's header exposes neither layer below it.
add_library(arch_layered_application STATIC application/enrollment_service.cpp)
target_include_directories(arch_layered_application PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/application)
target_link_libraries(arch_layered_application PRIVATE arch_layered_domain arch_layered_infrastructure)

add_library(arch_layered_presentation STATIC presentation/console.cpp)
target_include_directories(arch_layered_presentation PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/presentation)
target_link_libraries(arch_layered_presentation PUBLIC arch_layered_application)

# main is the composition root, so it links every layer it creates.
lld_add_example(arch_enrollment_layered SOURCES main.cpp EXPECTED_OUTPUT expected_output.txt)
target_link_libraries(arch_enrollment_layered PRIVATE
  arch_layered_presentation arch_layered_application arch_layered_infrastructure)

lld_add_test(arch_layered_domain_tests SOURCES test_domain.cpp)
target_link_libraries(arch_layered_domain_tests PRIVATE arch_layered_domain)

lld_add_test(arch_layered_application_tests SOURCES test_application.cpp)
target_link_libraries(arch_layered_application_tests PRIVATE
  arch_layered_application arch_layered_infrastructure)

lld_add_test(arch_layered_console_tests SOURCES test_console.cpp)
target_link_libraries(arch_layered_console_tests PRIVATE
  arch_layered_presentation arch_layered_application arch_layered_infrastructure)

add_library(arch_layered_anemic STATIC anemic/anemic_course.cpp)
target_include_directories(arch_layered_anemic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/anemic)
lld_add_test(arch_layered_anemic_tests SOURCES test_anemic.cpp)
target_link_libraries(arch_layered_anemic_tests PRIVATE arch_layered_anemic arch_layered_domain)
