find_program(DOT_EXE "dot")
if (DOT_EXE)
    message(STATUS "dot found: ${DOT_EXE}")
else ()
    message(STATUS "dot not found!")
endif ()

set(DOT_OUTPUT_TYPE "" CACHE STRING "Build a dependency graph. Options are dot output type: ps, png, pdf...")

if ()
    add_custom_target(
            dependency-graph
            COMMAND ${CMAKE_COMMAND} ${CMAKE_SOURCE_DIR} --graphviz=${CMAKE_BINARY_DIR}/graphviz/${PROJECT_NAME}.dot
            COMMAND ${DOT_EXE} -T${DOT_OUTPUT_TYPE} ${CMAKE_BINARY_DIR}/graphviz/${PROJECT_NAME}.dot -o ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.${DOT_OUTPUT_TYPE}
    )

    add_custom_command(
            TARGET dependency-graph POST_BUILD
            COMMAND ;
            COMMENT "Dependency graph generated and located at ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.${DOT_OUTPUT_TYPE}"
    )
endif ()
