Imported Upstream version 3.23.2
[platform/upstream/cmake.git] / Utilities / Sphinx / tutorial_archive.cmake
1 if(NOT version)
2   message(FATAL_ERROR "Pass -Dversion=")
3 endif()
4
5 # Name of the archive and its top-level directory.
6 set(archive_name "cmake-${version}-tutorial-source")
7
8 # Base directory for CMake Documentation.
9 set(help_dir "${CMAKE_CURRENT_LIST_DIR}/../../Help")
10 cmake_path(ABSOLUTE_PATH help_dir NORMALIZE)
11
12 # Collect the non-documentation part of the tutorial directory.
13 file(COPY "${help_dir}/guide/tutorial/"
14   DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/${archive_name}"
15   NO_SOURCE_PERMISSIONS
16   PATTERN *.rst EXCLUDE
17   PATTERN source.txt EXCLUDE
18   )
19 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${archive_name}/README.txt" [[
20 This directory contains source code examples for the CMake Tutorial.
21 Each step has its own subdirectory containing code that may be used as a
22 starting point. The tutorial examples are progressive so that each step
23 provides the complete solution for the previous step.
24 ]])
25
26 # Create an archive containing the tutorial source examples.
27 file(MAKE_DIRECTORY "${help_dir}/_generated")
28 file(ARCHIVE_CREATE
29   OUTPUT "${help_dir}/_generated/${archive_name}.zip"
30   PATHS "${CMAKE_CURRENT_BINARY_DIR}/${archive_name}"
31   FORMAT zip
32   )
33
34 # Write a reStructuredText snippet included from the tutorial index.
35 file(WRITE "${help_dir}/guide/tutorial/source.txt" "
36 .. |tutorial_source| replace::
37   The tutorial source code examples are available in
38   :download:`this archive </_generated/${archive_name}.zip>`.
39 ")
40
41 # Remove temporary directory.
42 file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/${archive_name}")