function(add_lightests)
  foreach(LIGHTEST ${ARGN})
    file(RELATIVE_PATH LIGHTEST_PATH ${CMAKE_SOURCE_DIR}/test ${CMAKE_CURRENT_SOURCE_DIR}/${LIGHTEST})
    list(APPEND LIGHTESTS ${LIGHTEST_PATH})
  endforeach()
  set_property(GLOBAL APPEND PROPERTY LIGHTESTS_PROPERTY ${LIGHTESTS})
endfunction()

enable_testing()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

function(lightest LIBRARY)
  add_subdirectory(test)
  get_property(LIGHTESTS GLOBAL PROPERTY LIGHTESTS_PROPERTY)
  foreach(LIGHTEST ${LIGHTESTS})
    string(REPLACE / _ LIGHTEST_ID ${LIGHTEST})
    add_executable(${LIGHTEST_ID} test/${LIGHTEST}_test.cc)
    target_link_libraries(${LIGHTEST_ID} ${LIBRARY} lightest)
    set_target_properties(${LIGHTEST_ID} PROPERTIES FOLDER test)
    add_test(${LIGHTEST} ${LIGHTEST_ID})
  endforeach()
endfunction()
