From cca73b54ae6a25f50b17cf32077ca85020340d92 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 1 Apr 2022 21:47:42 -0400 Subject: Utilities/Sphinx: Add undocumented option to build docs for cmake.org --- .gitlab/os-linux.yml | 3 ++- Utilities/Sphinx/CMakeLists.txt | 33 ++++++++++++++++++++++++++++++--- Utilities/Sphinx/conf.py.in | 1 + Utilities/Sphinx/templates/layout.html | 22 +++++++++++++++++++--- 4 files changed, 52 insertions(+), 7 deletions(-) diff --git a/.gitlab/os-linux.yml b/.gitlab/os-linux.yml index 90c10a2..48d4279 100644 --- a/.gitlab/os-linux.yml +++ b/.gitlab/os-linux.yml @@ -490,5 +490,6 @@ - *before_script_linux - mkdir -p build/ - cd build/ - - cmake ../Utilities/Sphinx -GNinja -DSPHINX_HTML=ON -DSPHINX_FLAGS="-A versionswitch=1" + - cmake ../Utilities/Sphinx -GNinja -DSPHINX_HTML=ON + -DCMake_SPHINX_CMAKE_ORG=ON - ninja diff --git a/Utilities/Sphinx/CMakeLists.txt b/Utilities/Sphinx/CMakeLists.txt index c8a970d..6576036 100644 --- a/Utilities/Sphinx/CMakeLists.txt +++ b/Utilities/Sphinx/CMakeLists.txt @@ -49,6 +49,12 @@ else() set(conf_copyright "Kitware, Inc.") endif() +if(CMake_SPHINX_CMAKE_ORG) + set(conf_baseurl "https://cmake.org/cmake/help/latest") +else() + set(conf_baseurl "") +endif() + set(conf_docs "${CMake_SOURCE_DIR}/Help") set(conf_path "${CMAKE_CURRENT_SOURCE_DIR}") set(conf_version "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}") @@ -129,11 +135,24 @@ if(SPHINX_LATEXPDF) list(APPEND doc_formats latexpdf) endif() +set(doc_html_opts "") +if(CMake_SPHINX_CMAKE_ORG) + list(APPEND doc_html_opts + -A googleanalytics=1 + -A versionswitch=1 + ) +endif() + set(doc_format_outputs "") set(doc_format_last "") foreach(format ${doc_formats}) set(doc_format_output "doc_format_${format}") set(doc_format_log "build-${format}.log") + if(CMake_SPHINX_CMAKE_ORG) + set(doctrees "doctrees/${format}") + else() + set(doctrees "doctrees") + endif() if(format STREQUAL "latexpdf") # This format does not use builder (-b) but make_mode (-M) which expects # arguments in peculiar order @@ -144,8 +163,9 @@ foreach(format ${doc_formats}) ${CMake_SOURCE_DIR}/Help ${CMAKE_CURRENT_BINARY_DIR}/${format} -c ${CMAKE_CURRENT_BINARY_DIR} - -d ${CMAKE_CURRENT_BINARY_DIR}/doctrees + -d ${CMAKE_CURRENT_BINARY_DIR}/${doctrees} ${sphinx_flags} + ${doc_${format}_opts} > ${doc_format_log} # log stdout, pass stderr ${${format}_extra_commands} DEPENDS ${doc_format_last} @@ -158,9 +178,10 @@ foreach(format ${doc_formats}) OUTPUT ${doc_format_output} COMMAND ${SPHINX_EXECUTABLE} -c ${CMAKE_CURRENT_BINARY_DIR} - -d ${CMAKE_CURRENT_BINARY_DIR}/doctrees + -d ${CMAKE_CURRENT_BINARY_DIR}/${doctrees} -b ${format} ${sphinx_flags} + ${doc_${format}_opts} ${CMake_SOURCE_DIR}/Help ${CMAKE_CURRENT_BINARY_DIR}/${format} > ${doc_format_log} # log stdout, pass stderr @@ -172,7 +193,9 @@ foreach(format ${doc_formats}) endif() set_property(SOURCE ${doc_format_output} PROPERTY SYMBOLIC 1) list(APPEND doc_format_outputs ${doc_format_output}) - set(doc_format_last ${doc_format_output}) + if(NOT CMake_SPHINX_CMAKE_ORG) + set(doc_format_last ${doc_format_output}) + endif() endforeach() add_custom_target(documentation ALL DEPENDS ${doc_format_outputs}) @@ -192,6 +215,10 @@ if(CMake_SPHINX_DEPEND_ON_EXECUTABLES) endforeach() endif() +if(CMake_SPHINX_CMAKE_ORG) + return() +endif() + if(SPHINX_INFO) CMake_OPTIONAL_COMPONENT(sphinx-info) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/texinfo/cmake.info diff --git a/Utilities/Sphinx/conf.py.in b/Utilities/Sphinx/conf.py.in index c383828..2b3083b 100644 --- a/Utilities/Sphinx/conf.py.in +++ b/Utilities/Sphinx/conf.py.in @@ -55,6 +55,7 @@ for fpath in cmake_manuals: man_show_urls = False man_make_section_directory = False +html_baseurl = '@conf_baseurl@' html_show_sourcelink = True html_static_path = ['@conf_path@/static'] html_style = 'cmake.css' diff --git a/Utilities/Sphinx/templates/layout.html b/Utilities/Sphinx/templates/layout.html index be2660c..0cc5c26 100644 --- a/Utilities/Sphinx/templates/layout.html +++ b/Utilities/Sphinx/templates/layout.html @@ -18,9 +18,9 @@ {% endblock %} {% block extrahead %} - {% if versionswitch is defined %} - - {% endif %} + {%- if versionswitch is defined %} + + {%- endif %} {{ super() }} {% endblock %} @@ -29,3 +29,19 @@ {% block htmltitle %} {{ title|striptags|e }} {{ "—"|safe }} {{ docstitle|e }} {% endblock %} + +{%- block footer %} +{{ super() }} +{%- if googleanalytics is defined %} + + +{%- endif %} +{%- endblock %} -- cgit v0.12