# Three ways to hold shapes that share no base class: Drawable (owning,
# copyable, one heap allocation per shape), SmallDrawable (owning, with a
# buffer for small shapes), and DrawableRef (a non-owning view).
add_library(adv_drawable STATIC shapes.cpp scene.cpp)
target_include_directories(adv_drawable PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

lld_add_test(adv_drawable_tests SOURCES tests/test_drawable.cpp)
target_link_libraries(adv_drawable_tests PRIVATE adv_drawable)

# These replace the global operator new to count allocations. With Clang,
# which the tsan preset uses, the ThreadSanitizer runtime is linked
# statically and defines operator new too, and the linker refuses two;
# both programs run one thread, so TSan has nothing to check in them.
if(NOT CMAKE_CXX_FLAGS MATCHES "-fsanitize=thread")
  lld_add_example(adv_drawable_demo SOURCES main.cpp counting_new.cpp
    EXPECTED_OUTPUT expected_output.txt)
  target_link_libraries(adv_drawable_demo PRIVATE adv_drawable)

  lld_add_test(adv_drawable_allocation_tests SOURCES tests/test_allocations.cpp
    counting_new.cpp)
  target_link_libraries(adv_drawable_allocation_tests PRIVATE adv_drawable)
endif()
