From bee807a5151eb35057d6e9a72f0afd04520d29e4 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Mon, 10 Jul 2023 13:07:11 +0700 Subject: [PATCH] build: modify `target_generate_xml_docs` to `add_xml_docs` function --- .github/workflows/build.yml | 6 ++- error/CMakeLists.txt | 4 +- error/cmake/add_xml_docs.cmake | 30 +++++++++++++++ error/cmake/target_generate_xml_docs.cmake | 45 ---------------------- 4 files changed, 36 insertions(+), 49 deletions(-) create mode 100644 error/cmake/add_xml_docs.cmake delete mode 100644 error/cmake/target_generate_xml_docs.cmake diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 47afced..5223e55 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -105,9 +105,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v3.5.3 - - name: Configure and build documentation + - name: Configure project uses: threeal/cmake-action@v1.2.0 with: source-dir: ${{ matrix.package }} options: BUILD_DOCS=ON - run-build: true + + - name: Build documentation + run: cmake --build ${{ matrix.package }}/build --target docs diff --git a/error/CMakeLists.txt b/error/CMakeLists.txt index 0237331..2269aa9 100644 --- a/error/CMakeLists.txt +++ b/error/CMakeLists.txt @@ -60,7 +60,7 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) # Build XML documentation if(BUILD_DOCS) - include(cmake/target_generate_xml_docs.cmake) - target_generate_xml_docs(error) + include(cmake/add_xml_docs.cmake) + add_xml_docs(docs include/error/error.hpp) endif() endif() diff --git a/error/cmake/add_xml_docs.cmake b/error/cmake/add_xml_docs.cmake new file mode 100644 index 0000000..7d1cebc --- /dev/null +++ b/error/cmake/add_xml_docs.cmake @@ -0,0 +1,30 @@ +# A function that generates XML documentation from the specified source files. +function(add_xml_docs TARGET_NAME) + # Try to install Doxygen if not found + find_program(DOXYGEN_PROGRAM doxygen) + if(NOT DOXYGEN_PROGRAM) + find_program(APT_GET_PROGRAM apt-get) + if(APT_GET_PROGRAM) + message(STATUS "Doxygen could not be found, installing...") + execute_process(COMMAND ${APT_GET_PROGRAM} install -y doxygen) + endif() + + find_program(BREW_PROGRAM brew) + if(BREW_PROGRAM) + message(STATUS "Doxygen could not be found, installing...") + execute_process(COMMAND ${BREW_PROGRAM} install doxygen) + endif() + endif() + + # Try to find Doxygen + find_package(Doxygen) + if(DOXYGEN_FOUND) + # Configure Doxygen to generate XML documentation + set(DOXYGEN_GENERATE_HTML NO) + set(DOXYGEN_GENERATE_XML YES) + set(DOXYGEN_XML_OUTPUT ${TARGET_NAME}) + + # Generate XML documentation for the target + doxygen_add_docs(${TARGET_NAME} ${ARGN} USE_STAMP_FILE) + endif() +endfunction() diff --git a/error/cmake/target_generate_xml_docs.cmake b/error/cmake/target_generate_xml_docs.cmake deleted file mode 100644 index 6229475..0000000 --- a/error/cmake/target_generate_xml_docs.cmake +++ /dev/null @@ -1,45 +0,0 @@ -# A function that generates XML documentation for the specified target. -function(target_generate_xml_docs TARGET) - # Try to install Doxygen if not found - find_program(DOXYGEN_PROGRAM doxygen) - if(NOT DOXYGEN_PROGRAM) - find_program(APT_GET_PROGRAM apt-get) - if(APT_GET_PROGRAM) - message(STATUS "Doxygen could not be found, installing...") - execute_process(COMMAND ${APT_GET_PROGRAM} install -y doxygen) - endif() - - find_program(BREW_PROGRAM brew) - if(BREW_PROGRAM) - message(STATUS "Doxygen could not be found, installing...") - execute_process(COMMAND ${BREW_PROGRAM} install doxygen) - endif() - endif() - - # Try to find Doxygen - find_package(Doxygen) - if(DOXYGEN_FOUND) - # Configure Doxygen to generate XML documentation - set(DOXYGEN_GENERATE_HTML NO) - set(DOXYGEN_GENERATE_XML YES) - - # Get include directories of the target - foreach(PROP INCLUDE_DIRECTORIES INTERFACE_INCLUDE_DIRECTORIES) - get_target_property(TARGET_INCLUDE_DIRS ${TARGET} ${PROP}) - if(NOT "${TARGET_INCLUDE_DIRS}" STREQUAL "TARGET_INCLUDE_DIRS-NOTFOUND") - list(APPEND INCLUDE_DIRS ${TARGET_INCLUDE_DIRS}) - endif() - endforeach() - list(REMOVE_DUPLICATES INCLUDE_DIRS) - - # Get header files from the include directories - foreach(DIR ${TARGET_INCLUDE_DIRS}) - file(GLOB_RECURSE FILES CONFIGURE_DEPENDS "${DIR}/*") - list(APPEND HEADER_FILES ${FILES}) - endforeach() - - # Generate XML documentation for the target - doxygen_add_docs(${TARGET}_docs ${HEADER_FILES} USE_STAMP_FILE) - add_dependencies(${TARGET} ${TARGET}_docs) - endif() -endfunction()