소스 검색

Tutorial: Provide a source archive when published on cmake.org

Provide readers following the tutorial on `cmake.org` a direct link to
download the tutorial's source examples.  Previously readers had to
fetch the CMake source tree separately and look for the tutorial source
examples inside it.

Fixes: #22475
Brad King 3 년 전
부모
커밋
4cb616fed6
5개의 변경된 파일54개의 추가작업 그리고 2개의 파일을 삭제
  1. 2 0
      .gitignore
  2. 3 2
      Help/guide/tutorial/index.rst
  3. 3 0
      Help/guide/tutorial/source.txt
  4. 4 0
      Utilities/Sphinx/CMakeLists.txt
  5. 42 0
      Utilities/Sphinx/tutorial_archive.cmake

+ 2 - 0
.gitignore

@@ -4,6 +4,8 @@
 *.user*
 *.user*
 
 
 *.pyc
 *.pyc
+
+Help/_generated
 Testing
 Testing
 CMakeUserPresets.json
 CMakeUserPresets.json
 
 

+ 3 - 2
Help/guide/tutorial/index.rst

@@ -11,8 +11,9 @@ work together in an example project can be very helpful.
 Steps
 Steps
 =====
 =====
 
 
-The tutorial documentation and source code for examples can be found in
-the ``Help/guide/tutorial`` directory of the CMake source code tree.
+.. include:: source.txt
+
+|tutorial_source|
 Each step has its own subdirectory containing code that may be used as a
 Each step has its own subdirectory containing code that may be used as a
 starting point. The tutorial examples are progressive so that each step
 starting point. The tutorial examples are progressive so that each step
 provides the complete solution for the previous step.
 provides the complete solution for the previous step.

+ 3 - 0
Help/guide/tutorial/source.txt

@@ -0,0 +1,3 @@
+.. |tutorial_source| replace::
+  The tutorial documentation and source code examples can be found in
+  the ``Help/guide/tutorial`` directory of the CMake source code tree.

+ 4 - 0
Utilities/Sphinx/CMakeLists.txt

@@ -148,6 +148,10 @@ if(CMake_SPHINX_CMAKE_ORG)
     list(APPEND doc_html_opts -A outdated=1)
     list(APPEND doc_html_opts -A outdated=1)
   endif()
   endif()
 
 
+  list(APPEND html_pre_commands
+    COMMAND ${CMAKE_COMMAND} -Dversion=${CMake_VERSION} -P ${CMAKE_CURRENT_SOURCE_DIR}/tutorial_archive.cmake
+    )
+
   list(APPEND qthelp_post_commands
   list(APPEND qthelp_post_commands
     COMMAND ${CMAKE_COMMAND} -E copy
     COMMAND ${CMAKE_COMMAND} -E copy
       "${CMAKE_CURRENT_BINARY_DIR}/qthelp/CMake.qch"
       "${CMAKE_CURRENT_BINARY_DIR}/qthelp/CMake.qch"

+ 42 - 0
Utilities/Sphinx/tutorial_archive.cmake

@@ -0,0 +1,42 @@
+if(NOT version)
+  message(FATAL_ERROR "Pass -Dversion=")
+endif()
+
+# Name of the archive and its top-level directory.
+set(archive_name "cmake-${version}-tutorial-source")
+
+# Base directory for CMake Documentation.
+set(help_dir "${CMAKE_CURRENT_LIST_DIR}/../../Help")
+cmake_path(ABSOLUTE_PATH help_dir NORMALIZE)
+
+# Collect the non-documentation part of the tutorial directory.
+file(COPY "${help_dir}/guide/tutorial/"
+  DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/${archive_name}"
+  NO_SOURCE_PERMISSIONS
+  PATTERN *.rst EXCLUDE
+  PATTERN source.txt EXCLUDE
+  )
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${archive_name}/README.txt" [[
+This directory contains source code examples for the CMake Tutorial.
+Each step has its own subdirectory containing code that may be used as a
+starting point. The tutorial examples are progressive so that each step
+provides the complete solution for the previous step.
+]])
+
+# Create an archive containing the tutorial source examples.
+file(MAKE_DIRECTORY "${help_dir}/_generated")
+file(ARCHIVE_CREATE
+  OUTPUT "${help_dir}/_generated/${archive_name}.zip"
+  PATHS "${CMAKE_CURRENT_BINARY_DIR}/${archive_name}"
+  FORMAT zip
+  )
+
+# Write a reStructuredText snippet included from the tutorial index.
+file(WRITE "${help_dir}/guide/tutorial/source.txt" "
+.. |tutorial_source| replace::
+  The tutorial source code examples are available in
+  :download:`this archive </_generated/${archive_name}.zip>`.
+")
+
+# Remove temporary directory.
+file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/${archive_name}")