From 118e41401190ebd0dc831ff27967197201431789 Mon Sep 17 00:00:00 2001 From: Danil Sidoruk Date: Fri, 22 Mar 2024 21:40:45 +0300 Subject: [PATCH] Reimplement doxygen target & workflow --- .github/workflows/build_docs.yml | 19 ---------------- .github/workflows/documentation.yml | 34 +++++++++++++++++++++++++++++ CMakeLists.txt | 23 +++---------------- cmake/Doxygen.cmake | 17 +++++++++++++++ 4 files changed, 54 insertions(+), 39 deletions(-) delete mode 100644 .github/workflows/build_docs.yml create mode 100644 .github/workflows/documentation.yml create mode 100644 cmake/Doxygen.cmake diff --git a/.github/workflows/build_docs.yml b/.github/workflows/build_docs.yml deleted file mode 100644 index 04e2068..0000000 --- a/.github/workflows/build_docs.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Build and deploy documentation - -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Build and deploy documentation - uses: DenverCoder1/doxygen-github-pages-action@v1.3.0 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml new file mode 100644 index 0000000..48abfeb --- /dev/null +++ b/.github/workflows/documentation.yml @@ -0,0 +1,34 @@ +name: Documentation + +on: + push: + branches: + - master + paths-ignore: + - ".github/**" + - "cmake/**" + - "examples/**" + - "tests/**" + +jobs: + build: + name: Build and publish documentation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Install dependencies + run: | + sudo apt install doxygen + sudo apt install graphviz + + - name: Generate docs + run: | + cmake -S . -B building_docs + cmake --build building_docs --target docs + + - name: Publish + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./docs/html \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 513d2b6..5ae8af9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ project(tftp_common ) include(cmake/ClangFormat.cmake) +include(cmake/Doxygen.cmake) set(ALL_SOURCES tftp_common/details/packets.hpp @@ -71,25 +72,6 @@ if (MAIN_PROJECT) install(DIRECTORY ${PROJECT_SOURCE_DIR}/tftp_common/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}) endif() -option(BUILD_DOC "Build documentation" OFF) - -if (BUILD_DOCS) - find_package(Doxygen) - - if (DOXYGEN_FOUND) - set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile) - set(DOXYGEN_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/docs) - add_custom_target(doc_doxygen ALL - COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_IN} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Generating API documentation with Doxygen" - VERBATIM - ) - else (DOXYGEN_FOUND) - message("Doxygen need to be installed to generate the doxygen documentation") - endif (DOXYGEN_FOUND) -endif (BUILD_DOCS) - option(BUILD_TESTS "Build tests" OFF) if (BUILD_TESTS) @@ -106,4 +88,5 @@ endif (BUILD_EXAMPLES) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(Packing) -add_clang_format_target() \ No newline at end of file +add_clang_format_target() +add_docs_target() \ No newline at end of file diff --git a/cmake/Doxygen.cmake b/cmake/Doxygen.cmake new file mode 100644 index 0000000..e65c937 --- /dev/null +++ b/cmake/Doxygen.cmake @@ -0,0 +1,17 @@ +# +# Add a target for generating docs for the project using `doxygen` (i.e: cmake --build build --target docs) +# + +function(add_docs_target) + find_package(Doxygen COMPONENTS dot) + + if(Doxygen_FOUND) + set(DOXYGEN_CALLER_GRAPH YES) + set(DOXYGEN_CALL_GRAPH YES) + set(DOXYGEN_EXTRACT_ALL YES) + set(DOXYGEN_USE_MDFILE_AS_MAINPAGE ${CMAKE_CURRENT_SOURCE_DIR}/README.md) + set(DOXYGEN_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/docs) + doxygen_add_docs(docs ${PROJECT_SOURCE_DIR}) + message(STATUS "Doxygen has been setup and docs target is now available.") + endif() +endfunction() \ No newline at end of file