From 76c601b22d49872eb3c2ad67590d15834468d440 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Wed, 27 Dec 2023 19:14:15 +0700 Subject: [PATCH 1/2] build: build docs using CMake --- .github/workflows/build.yaml | 15 +++++++++------ .github/workflows/deploy.yaml | 15 +++++++++------ CMakeLists.txt | 4 ++++ docs/CMakeLists.txt | 23 +++++++++++++++++++++++ 4 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 docs/CMakeLists.txt diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 1146abb..3ab799a 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -48,15 +48,18 @@ jobs: - name: Checkout uses: actions/checkout@v4.1.1 - - name: Install Dependencies - run: | - sudo apt-get install -y doxygen - pip3 install -r docs/requirements.txt + - name: Install Doxygen + run: sudo apt-get install -y doxygen + + - name: Configure Project + uses: threeal/cmake-action@v1.3.0 + with: + options: BUILD_DOCS=ON - name: Build Documentation - run: sphinx-build -b html docs build/docs -W --keep-going + run: cmake --build build --target docs - name: Upload Documentation uses: actions/upload-pages-artifact@v3.0.0 with: - path: build/docs + path: build/docs/html diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 0fbd1d2..52aa253 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -23,18 +23,21 @@ jobs: - name: Checkout uses: actions/checkout@v4.1.1 - - name: Install Dependencies - run: | - sudo apt-get install -y doxygen - pip3 install -r docs/requirements.txt + - name: Install Doxygen + run: sudo apt-get install -y doxygen + + - name: Configure Project + uses: threeal/cmake-action@v1.3.0 + with: + options: BUILD_DOCS=ON - name: Build Documentation - run: sphinx-build -b html docs docs/build -W --keep-going + run: cmake --build build --target docs - name: Upload Documentation uses: actions/upload-pages-artifact@v3.0.0 with: - path: docs/build + path: build/docs/html - name: Deploy Pages id: deploy-pages diff --git a/CMakeLists.txt b/CMakeLists.txt index d3d8cb4..e83844b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,3 +82,7 @@ if(NOT_SUBPROJECT) endif() add_subdirectory(components) + +if(NOT_SUBPROJECT AND BUILD_DOCS) + add_subdirectory(docs) +endif() diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt new file mode 100644 index 0000000..0eb09b7 --- /dev/null +++ b/docs/CMakeLists.txt @@ -0,0 +1,23 @@ +find_package(Python REQUIRED) + +message(STATUS "Installing Python dependencies") +execute_process( + COMMAND ${Python_EXECUTABLE} -m pip install -r ${CMAKE_CURRENT_SOURCE_DIR}/requirements.txt + RESULT_VARIABLE RES + ERROR_VARIABLE ERR + OUTPUT_QUIET +) +if(NOT RES EQUAL 0 ) + message(FATAL_ERROR "Failed to install Python dependencies:\n${ERR}") +endif() + +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/html/index.html + COMMAND ${Python_EXECUTABLE} -m sphinx -b html ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/html -W --keep-going + DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/conf.py + ${CMAKE_CURRENT_SOURCE_DIR}/index.rst +) + +add_custom_target(docs ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/html/index.html) +add_dependencies(docs errors_docs errors_format_docs) From 2dd0a139e5f6d162574bf38a80a1bfe38cd62d4d Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Wed, 27 Dec 2023 07:58:15 +0700 Subject: [PATCH 2/2] build(docs): add file stamp depends --- docs/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 0eb09b7..82a4ebb 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -11,12 +11,17 @@ if(NOT RES EQUAL 0 ) message(FATAL_ERROR "Failed to install Python dependencies:\n${ERR}") endif() +get_target_property(errors_docs_BINARY_DIR errors_docs BINARY_DIR) +get_target_property(errors_format_docs_BINARY_DIR errors_format_docs BINARY_DIR) + add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/html/index.html COMMAND ${Python_EXECUTABLE} -m sphinx -b html ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/html -W --keep-going DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/conf.py ${CMAKE_CURRENT_SOURCE_DIR}/index.rst + ${errors_docs_BINARY_DIR}/errors_docs.stamp + ${errors_format_docs_BINARY_DIR}/errors_format_docs.stamp ) add_custom_target(docs ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/html/index.html)