if(NOT DEFINED DOCDIR)
    set(DOCDIR "usr/share/doc/${CMAKE_PROJECT_NAME}-${APPLICATION_VERSION}")
    set(DOC_FILES_TO_INSTALL README AUTHORS License ChangeLog TODO)
    set(DOC_DIRS_TO_INSTALL examples)

    function(INSTALL_DOC_FILE_IF_EXISTS ${filename})
        if(EXISTS ${CMAKE_SOURCE_DIR}/${filename})
            message(STATUS "Found document: ${filename}")
            INSTALL(FILES ${filename} DESTINATION ${DOCDIR})
        else()
            message(STATUS "Document Not found: ${filename}")
        endif()
    endfunction(INSTALL_DOC_FILE_IF_EXISTS)

    function(INSTALL_DOC_DIR_IF_EXISTS ${dirname})
        if(EXISTS ${CMAKE_SOURCE_DIR}/${dirname})
            message(STATUS "Found documentation dir: ${dirname}")
            INSTALL(DIRECTORY ${dirname} DESTINATION ${DOCDIR})
        else()
            message(STATUS "Document directory Not found: ${dirname}")
        endif()
    endfunction(INSTALL_DOC_DIR_IF_EXISTS)

    function(INSTALL_DOC_FILES)
        foreach(filename ${DOC_FILES_TO_INSTALL})
            INSTALL_DOC_FILE_IF_EXISTS(${filename})
        endforeach(filename)
    endfunction(INSTALL_DOC_FILES)

    function(INSTALL_DOC_DIRS)
        foreach(dirname ${DOC_DIRS_TO_INSTALL})
            INSTALL_DOC_DIR_IF_EXISTS(${dirname})
        endforeach(dirname)
    endfunction(INSTALL_DOC_DIRS)

    message(STATUS "Documentation directory: ${DOCDIR}")
    INSTALL_DOC_FILES()
    INSTALL_DOC_DIRS()
endif(NOT DEFINED DOCDIR)
