#
# Check if doxygen is installed
find_package(Doxygen)

#
# Only build if found
if (DOXYGEN_FOUND)
    # Set variables
    set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
    set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
    set(DOXYGEN_LOG ${CMAKE_CURRENT_BINARY_DIR}/doxygen_out.log)

    # Configure doygen file for correct pathes
    configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
    message("doxygen found: Creating code documentation")

    # Actually make the doxygen call
    add_custom_target(doc_doxygen ALL
        COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} > ${DOXYGEN_LOG}
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
        COMMENT "Generating code documentation"
        VERBATIM)

    # Install the documentation
    install(DIRECTORY html DESTINATION share/doc/${CMAKE_PROJECT_NAME})
else (DOXYGEN_FOUND)
    message("doxygen not installed: Not creating code documentation")
endif (DOXYGEN_FOUND)
