if (BUILD_DOC_HTML)
    set(DOXYGEN_GENERATE_HTML YES)
endif()
if (BUILD_DOC_MAN)
    set(DOXYGEN_GENERATE_MAN YES)
endif()
if (BUILD_DOC_XML)
    set(DOXYGEN_GENERATE_XML YES)
endif()

if (BUILD_DOXYGEN_AWESOME)
    include(ExternalProject)
    ExternalProject_Add(doxygen-awesome-css
    GIT_REPOSITORY https://github.com/jothepro/doxygen-awesome-css.git
    GIT_TAG "v2.2.1"
    CONFIGURE_COMMAND ""
    BUILD_COMMAND make
    BUILD_IN_SOURCE TRUE
    INSTALL_COMMAND make PREFIX=${CMAKE_CURRENT_BINARY_DIR}/doxygen-awesome-css install
    )
    set (DOXYGEN_GENERATE_TREEVIEW YES)
    set (DOXYGEN_DISABLE_INDEX NO)
    set (DOXYGEN_FULL_SIDEBAR NO)
    set (DOXYGEN_HTML_EXTRA_STYLESHEET
        ${CMAKE_CURRENT_BINARY_DIR}/doxygen-awesome-css/share/doxygen-awesome-css/doxygen-awesome.css
        ${CMAKE_CURRENT_BINARY_DIR}/doxygen-awesome-css/share/doxygen-awesome-css/doxygen-awesome-sidebar-only.css
        ${CMAKE_CURRENT_BINARY_DIR}/doxygen-awesome-css/share/doxygen-awesome-css/doxygen-awesome-sidebar-only-darkmode-toggle.css
        custom.css
    )
    set (DOXYGEN_HTML_EXTRA_FILES
        ${CMAKE_CURRENT_BINARY_DIR}/doxygen-awesome-css/share/doxygen-awesome-css/doxygen-awesome-darkmode-toggle.js
    )
    set (DOXYGEN_FULL_SIDEBAR NO)
    set (DOXYGEN_HTML_COLORSTYLE "LIGHT")
    set (DOXYGEN_HTML_HEADER header.html)
endif()

doxygen_add_docs(
    documentation
    ${PROJECT_SOURCE_DIR}/src
    mainpage.dox
    ALL
    COMMENT "Generate man and html pages"
)
if (BUILD_DOC_MAN)
    install(DIRECTORY
    ${CMAKE_CURRENT_BINARY_DIR}/man
    TYPE DOC
)
endif()
if (BUILD_DOC_HTML)
install(DIRECTORY
    ${CMAKE_CURRENT_BINARY_DIR}/html
    TYPE DOC
)
endif()
if (BUILD_DOC_XML)
install(DIRECTORY
    ${CMAKE_CURRENT_BINARY_DIR}/xml
    TYPE DOC
)
endif()

if (BUILD_DOXYGEN_AWESOME)
    add_dependencies(documentation doxygen-awesome-css)
endif()