From 7de561e8e822fc56258736e77ae3c91378da2883 Mon Sep 17 00:00:00 2001 From: Sumit Dey Date: Sat, 19 Jun 2021 03:09:09 +0200 Subject: [PATCH] Fix dependency check for building documentation Build with documentation fails if the required 'sphinx rtd theme' is not available. Check if dependency is installed before building with documentation. Add Python3 as requirement for building documentation. Change-Id: I5edc5d7374864990e625a5efb358f5a23b3c50fe --- CMakeLists.txt | 4 ++-- cmake/FindSphinx.cmake | 32 +++++++++++++++++++------------- docs/source/CMakeLists.txt | 5 ++++- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 203c5d22b..055bd0e12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -640,9 +640,9 @@ if (BUILD_DOCUMENTATION) set(CERES_DOCS_INSTALL_DIR "share/doc/ceres" CACHE STRING "Ceres docs install path relative to CMAKE_INSTALL_PREFIX") - find_package(Sphinx QUIET) + find_package(Sphinx) if (NOT SPHINX_FOUND) - message("-- Failed to find Sphinx, disabling build of documentation.") + message("-- Failed to find Sphinx and/or its dependencies, disabling build of documentation.") update_cache_variable(BUILD_DOCUMENTATION OFF) else() # Generate the User's Guide (html). diff --git a/cmake/FindSphinx.cmake b/cmake/FindSphinx.cmake index 220108dab..2ba3c81bd 100644 --- a/cmake/FindSphinx.cmake +++ b/cmake/FindSphinx.cmake @@ -43,24 +43,30 @@ find_program(SPHINX_EXECUTABLE /opt/local/bin DOC "Sphinx documentation generator") -if (NOT SPHINX_EXECUTABLE) - set(_Python_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0 1.6 1.5) +if (SPHINX_EXECUTABLE) - foreach (_version ${_Python_VERSIONS}) - set(_sphinx_NAMES sphinx-build-${_version}) + find_package(PythonInterp 3) + + if(PYTHONINTERP_FOUND) + # Check for sphinx theme dependency for documentation + execute_process( + COMMAND ${PYTHON_EXECUTABLE} -m pip show sphinx-rtd-theme + RESULT_VARIABLE SPHINX_RTD_THEME + OUTPUT_QUIET + ERROR_QUIET + ) + endif () + + if (${SPHINX_RTD_THEME} EQUAL 0) + set(SPHINX_RTD_THEME TRUE) + else () + set(SPHINX_RTD_THEME FALSE) + endif () - find_program(SPHINX_EXECUTABLE - NAMES ${_sphinx_NAMES} - PATHS - /usr/bin - /usr/local/bin - /opt/local/bin - DOC "Sphinx documentation generator") - endforeach () endif () include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Sphinx DEFAULT_MSG SPHINX_EXECUTABLE) +find_package_handle_standard_args(Sphinx DEFAULT_MSG SPHINX_EXECUTABLE SPHINX_RTD_THEME) mark_as_advanced(SPHINX_EXECUTABLE) diff --git a/docs/source/CMakeLists.txt b/docs/source/CMakeLists.txt index 70bf9985c..217a5194e 100644 --- a/docs/source/CMakeLists.txt +++ b/docs/source/CMakeLists.txt @@ -9,9 +9,12 @@ install(DIRECTORY ${SPHINX_HTML_DIR} COMPONENT Doc PATTERN "${SPHINX_HTML_DIR}/*") +# Find python 3 +find_package(PythonInterp 3 REQUIRED) + # Building using 'make_docs.py' python script add_custom_target(ceres_docs ALL - python + ${PYTHON_EXECUTABLE} "${Ceres_SOURCE_DIR}/scripts/make_docs.py" "${Ceres_SOURCE_DIR}" "${Ceres_BINARY_DIR}/docs"