tutorial_archive.cmake 1.5 KB

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