blob: 6bf2f073ad097a29c22ccdbf5d745fa69b051ba6 [file] [log] [blame]
Gyorgy Szing74dae3c2018-09-27 17:00:46 +02001#-------------------------------------------------------------------------------
2# Copyright (c) 2019, Arm Limited. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
8#Sphinx needs all document files to be under a single directory. This script
9#copies all document files to a temporary directory while keeping the original
10#directory tree (relative location of files) except "docs/index.rst" which is
11#moved to the top level of the new tree.
12#
13# i.e.:
14# <DST_DIR>
15# | All documents from <TFM_ROOT_DIR> plus <TFM_ROOT_DIR>/docs/index.rst
16# |
17# +---docs
18# | |
19# \- all documents from <TFM_ROOT_DIR>/docs except index.rst
20# |
21# +---lib
22# | |
23# | \- All document from <TFM_ROOT_DIR>/lib keeping reativle location
24# ...
25# |
26#
27#Usage:
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020028# cmake -DDST_DIR=<path to destination> -DTFM_ROOT_DIR=<path to tf-m root> \
Galanakis, Minos0c1ad782019-11-08 11:28:40 +000029# -DBINARY_DIR=${CMAKE_BINARY_DIR}
30# -DMASTER_IDX=<path to master index.rst> -P SphinxCopyDoc.cmake
Gyorgy Szing74dae3c2018-09-27 17:00:46 +020031
32#Check input parameters
Galanakis, Minos0c1ad782019-11-08 11:28:40 +000033foreach(_PARAM IN ITEMS TFM_ROOT_DIR DST_DIR BINARY_DIR MASTER_IDX)
Gyorgy Szing74dae3c2018-09-27 17:00:46 +020034 if (NOT DEFINED ${_PARAM})
35 message(FATAL_ERROR "Variable ${_PARAM} is undefined. Please add -D${_PARAM}=<...> when calling this script.")
36 endif()
37endforeach()
38
39message(STATUS "Creating document tree for Sphinx under ${DST_DIR}")
40
41#List all document files.
42file(GLOB_RECURSE _COPY_FILES
43 LIST_DIRECTORIES false
44 RELATIVE "${TFM_ROOT_DIR}"
45 "${TFM_ROOT_DIR}/*.md"
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020046 "${TFM_ROOT_DIR}/*.rst"
Antonio de Angelisb9bba1a2019-05-08 10:28:22 +010047 "${TFM_ROOT_DIR}/*.png"
48 "${TFM_ROOT_DIR}/*.jpg"
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020049 "${TFM_ROOT_DIR}/dco.txt")
Gyorgy Szing74dae3c2018-09-27 17:00:46 +020050
Gyorgy Szing5c873232019-05-10 23:28:14 +020051#Remove intermediate and final document build outputs.
52foreach(_PATH IN ITEMS BINARY_DIR DST_DIR)
53 file(RELATIVE_PATH _REL_DIR ${TFM_ROOT_DIR} ${${_PATH}})
54 list(FILTER _COPY_FILES EXCLUDE REGEX "${_REL_DIR}/.*")
55endforeach()
Gyorgy Szing74dae3c2018-09-27 17:00:46 +020056
57#Copy files with directory tree.
58foreach(_FILE ${_COPY_FILES})
59 get_filename_component(_DIR ${_FILE} DIRECTORY)
Galanakis, Minos0c1ad782019-11-08 11:28:40 +000060 if (_FILE STREQUAL MASTER_IDX)
61 file(COPY ${_FILE} DESTINATION "${DST_DIR}")
62 else()
63 file(COPY ${_FILE} DESTINATION "${DST_DIR}/${_DIR}")
64 endif()
Gyorgy Szing74dae3c2018-09-27 17:00:46 +020065endforeach()