From 0ebd4f5ddb5f2efa909237df9e3b508d3ada1bc3 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Wed, 11 Sep 2024 21:33:07 -0600 Subject: [PATCH] Make CMake Doc build docenv optional --- cmake/Modules/Documentation.cmake | 48 +++++++++++++++++++------------ cmake/Modules/FindSphinx.cmake | 29 +++++++++++++++++++ 2 files changed, 59 insertions(+), 18 deletions(-) create mode 100644 cmake/Modules/FindSphinx.cmake diff --git a/cmake/Modules/Documentation.cmake b/cmake/Modules/Documentation.cmake index 400109067ff..7b8f4a5ba06 100644 --- a/cmake/Modules/Documentation.cmake +++ b/cmake/Modules/Documentation.cmake @@ -4,6 +4,8 @@ option(BUILD_DOC "Build LAMMPS HTML documentation" OFF) if(BUILD_DOC) + option(BUILD_DOC_VENV "Build LAMMPS documentation virtual environment" ON) + mark_as_advanced(BUILD_DOC_VENV) # Current Sphinx versions require at least Python 3.8 # use default (or custom) Python executable, if version is sufficient if(Python_VERSION VERSION_GREATER_EQUAL 3.8) @@ -18,14 +20,6 @@ if(BUILD_DOC) find_package(Doxygen 1.8.10 REQUIRED) file(GLOB DOC_SOURCES CONFIGURE_DEPENDS ${LAMMPS_DOC_DIR}/src/[^.]*.rst) - add_custom_command( - OUTPUT docenv - COMMAND ${VIRTUALENV} docenv - ) - - set(DOCENV_BINARY_DIR ${CMAKE_BINARY_DIR}/docenv/bin) - set(DOCENV_REQUIREMENTS_FILE ${LAMMPS_DOC_DIR}/utils/requirements.txt) - set(SPHINX_CONFIG_DIR ${LAMMPS_DOC_DIR}/utils/sphinx-config) set(SPHINX_CONFIG_FILE_TEMPLATE ${SPHINX_CONFIG_DIR}/conf.py.in) set(SPHINX_STATIC_DIR ${SPHINX_CONFIG_DIR}/_static) @@ -44,14 +38,32 @@ if(BUILD_DOC) # configure paths in conf.py, since relative paths change when file is copied configure_file(${SPHINX_CONFIG_FILE_TEMPLATE} ${DOC_BUILD_CONFIG_FILE}) - add_custom_command( - OUTPUT ${DOC_BUILD_DIR}/requirements.txt - DEPENDS docenv ${DOCENV_REQUIREMENTS_FILE} - COMMAND ${CMAKE_COMMAND} -E copy ${DOCENV_REQUIREMENTS_FILE} ${DOC_BUILD_DIR}/requirements.txt - COMMAND ${DOCENV_BINARY_DIR}/pip $ENV{PIP_OPTIONS} install --upgrade pip - COMMAND ${DOCENV_BINARY_DIR}/pip $ENV{PIP_OPTIONS} install --upgrade ${LAMMPS_DOC_DIR}/utils/converters - COMMAND ${DOCENV_BINARY_DIR}/pip $ENV{PIP_OPTIONS} install -r ${DOC_BUILD_DIR}/requirements.txt --upgrade - ) + if(BUILD_DOC_VENV) + add_custom_command( + OUTPUT docenv + COMMAND ${VIRTUALENV} docenv + ) + + set(DOCENV_BINARY_DIR ${CMAKE_BINARY_DIR}/docenv/bin) + set(DOCENV_REQUIREMENTS_FILE ${LAMMPS_DOC_DIR}/utils/requirements.txt) + + add_custom_command( + OUTPUT ${DOC_BUILD_DIR}/requirements.txt + DEPENDS docenv ${DOCENV_REQUIREMENTS_FILE} + COMMAND ${CMAKE_COMMAND} -E copy ${DOCENV_REQUIREMENTS_FILE} ${DOC_BUILD_DIR}/requirements.txt + COMMAND ${DOCENV_BINARY_DIR}/pip $ENV{PIP_OPTIONS} install --upgrade pip + COMMAND ${DOCENV_BINARY_DIR}/pip $ENV{PIP_OPTIONS} install --upgrade ${LAMMPS_DOC_DIR}/utils/converters + COMMAND ${DOCENV_BINARY_DIR}/pip $ENV{PIP_OPTIONS} install -r ${DOC_BUILD_DIR}/requirements.txt --upgrade + ) + + set(DOCENV_DEPS docenv ${DOC_BUILD_DIR}/requirements.txt) + if(NOT TARGET Sphinx::sphinx-build) + add_executable(Sphinx::sphinx-build IMPORTED GLOBAL) + set_target_properties(Sphinx::sphinx-build PROPERTIES IMPORTED_LOCATION "${DOCENV_BINARY_DIR}/sphinx-build") + endif() + else() + find_package(Sphinx) + endif() set(MATHJAX_URL "https://github.com/mathjax/MathJax/archive/3.1.3.tar.gz" CACHE STRING "URL for MathJax tarball") set(MATHJAX_MD5 "b81661c6e6ba06278e6ae37b30b0c492" CACHE STRING "MD5 checksum of MathJax tarball") @@ -97,8 +109,8 @@ if(BUILD_DOC) endif() add_custom_command( OUTPUT html - DEPENDS ${DOC_SOURCES} docenv ${DOC_BUILD_DIR}/requirements.txt ${DOXYGEN_XML_DIR}/index.xml ${BUILD_DOC_CONFIG_FILE} - COMMAND ${DOCENV_BINARY_DIR}/sphinx-build ${SPHINX_EXTRA_OPTS} -b html -c ${DOC_BUILD_DIR} -d ${DOC_BUILD_DIR}/doctrees ${LAMMPS_DOC_DIR}/src ${DOC_BUILD_DIR}/html + DEPENDS ${DOC_SOURCES} ${DOCENV_DEPS} ${DOXYGEN_XML_DIR}/index.xml ${BUILD_DOC_CONFIG_FILE} + COMMAND Sphinx::sphinx-build ${SPHINX_EXTRA_OPTS} -b html -c ${DOC_BUILD_DIR} -d ${DOC_BUILD_DIR}/doctrees ${LAMMPS_DOC_DIR}/src ${DOC_BUILD_DIR}/html COMMAND ${CMAKE_COMMAND} -E create_symlink Manual.html ${DOC_BUILD_DIR}/html/index.html COMMAND ${CMAKE_COMMAND} -E copy_directory ${LAMMPS_DOC_DIR}/src/PDF ${DOC_BUILD_DIR}/html/PDF COMMAND ${CMAKE_COMMAND} -E remove -f ${DOXYGEN_XML_DIR}/run.stamp diff --git a/cmake/Modules/FindSphinx.cmake b/cmake/Modules/FindSphinx.cmake new file mode 100644 index 00000000000..3718ecc5434 --- /dev/null +++ b/cmake/Modules/FindSphinx.cmake @@ -0,0 +1,29 @@ +# Find sphinx-build +find_program(Sphinx_EXECUTABLE NAMES sphinx-build + PATH_SUFFIXES bin + DOC "Sphinx documenation build executable") +mark_as_advanced(Sphinx_EXECUTABLE) + +if(Sphinx_EXECUTABLE) + execute_process(COMMAND ${Sphinx_EXECUTABLE} --version + OUTPUT_VARIABLE sphinx_version + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE _sphinx_version_result) + + if(_sphinx_version_result) + message(WARNING "Unable to determine sphinx-build verison: ${_sphinx_version_result}") + else() + string(REGEX REPLACE "sphinx-build ([0-9.]+).*" + "\\1" + Sphinx_VERSION + "${sphinx_version}") + endif() + + if(NOT TARGET Sphinx::sphinx-build) + add_executable(Sphinx::sphinx-build IMPORTED GLOBAL) + set_target_properties(Sphinx::sphinx-build PROPERTIES IMPORTED_LOCATION "${Sphinx_EXECUTABLE}") + endif() +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Sphinx REQUIRED_VARS Sphinx_EXECUTABLE VERSION_VAR Sphinx_VERSION)