find_path(MALLOC_DIR NAMES malloc/malloc.h )
if(NOT "${MALLOC_DIR}" MATCHES "MALLOC_DIR-NOTFOUND")
  try_run(MALLOCSIZE_CHECK MALLOCSIZE_CHECK_BUILD
    ${LEAN_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
    ${LEAN_SOURCE_DIR}/cmake/Modules/CheckMallocSize.cc
    CMAKE_FLAGS -DINCLUDE_DIRECTORIES=${MALLOC_DIR}
    RUN_OUTPUT_VARIABLE MALLOCSIZE_TRY_OUT)
  
  if("${MALLOCSIZE_CHECK_BUILD}" MATCHES "TRUE" AND "${MALLOCSIZE_CHECK}" MATCHES "0")
    message(STATUS "Found malloc_size " "${MALLOCSIZE_UNTESTED}")
    set(MALLOCSIZE_FOUND TRUE)
  else()
    message(STATUS "Usable malloc_size was not detected")
    set(MALLOCSIZE_FOUND FALSE)
  endif()
else()
  set(MALLOCSIZE_FOUND FALSE)
endif()
