2018-07-09 14:12:17 +02:00
|
|
|
cmake_minimum_required(VERSION 3.8.2)
|
|
|
|
project(Zephyr-Kernel-Doc VERSION ${PROJECT_VERSION} LANGUAGES)
|
|
|
|
|
|
|
|
set(ZEPHYR_BASE $ENV{ZEPHYR_BASE})
|
|
|
|
|
|
|
|
message(STATUS "Zephyr base: ${ZEPHYR_BASE}")
|
|
|
|
|
2018-09-28 13:10:57 +02:00
|
|
|
include(${ZEPHYR_BASE}/cmake/version.cmake)
|
|
|
|
|
2018-07-09 14:12:17 +02:00
|
|
|
find_package(PythonInterp 3.4)
|
|
|
|
set(DOXYGEN_SKIP_DOT True)
|
|
|
|
find_package(Doxygen REQUIRED)
|
2018-10-02 10:30:39 +02:00
|
|
|
find_package(LATEX)
|
2018-07-09 14:12:17 +02:00
|
|
|
|
|
|
|
find_program(
|
|
|
|
SPHINXBUILD
|
|
|
|
sphinx-build
|
|
|
|
)
|
|
|
|
if(${SPHINXBUILD} STREQUAL SPHINXBUILD-NOTFOUND)
|
|
|
|
message(FATAL_ERROR "The 'sphinx-build' command was not found. Make sure you have Sphinx installed.")
|
|
|
|
endif()
|
|
|
|
|
2018-08-23 20:11:11 +02:00
|
|
|
# Note that this won't force fatal error if latexmk is not found.
|
|
|
|
# Not having LaTeX tools should not prevent people from generating HTML docs.
|
|
|
|
find_program(
|
|
|
|
LATEXMK
|
|
|
|
latexmk
|
|
|
|
)
|
|
|
|
if(${LATEXMK} STREQUAL LATEXMK-NOTFOUND)
|
|
|
|
message(WARNING "The 'latexmk' command was not found. Targets to build PDF will not be available.")
|
|
|
|
endif()
|
|
|
|
|
2018-07-09 14:12:17 +02:00
|
|
|
if(NOT DEFINED SPHINXOPTS)
|
|
|
|
set(SPHINXOPTS -q)
|
2018-07-13 12:37:13 +02:00
|
|
|
else()
|
|
|
|
separate_arguments(SPHINXOPTS)
|
2018-07-09 14:12:17 +02:00
|
|
|
endif()
|
|
|
|
|
2018-08-16 13:45:59 +02:00
|
|
|
if(NOT DEFINED SPHINX_OUTPUT_DIR)
|
2018-08-23 20:11:11 +02:00
|
|
|
set(SPHINX_OUTPUT_DIR_HTML ${CMAKE_CURRENT_BINARY_DIR}/html)
|
|
|
|
set(SPHINX_OUTPUT_DIR_LATEX ${CMAKE_CURRENT_BINARY_DIR}/latex)
|
|
|
|
set(SPHINX_OUTPUT_DIR_PDF ${CMAKE_CURRENT_BINARY_DIR}/pdf)
|
|
|
|
else()
|
2018-10-09 21:28:41 +02:00
|
|
|
# SPHINX_OUTPUT_DIR is used to specify exactly where HTML (or other
|
|
|
|
# outputs) are placed, so no /html, /latex, /pdf suffixes are needed.
|
2018-08-23 20:11:11 +02:00
|
|
|
set(SPHINX_OUTPUT_DIR_HTML ${SPHINX_OUTPUT_DIR})
|
|
|
|
set(SPHINX_OUTPUT_DIR_LATEX ${SPHINX_OUTPUT_DIR})
|
|
|
|
set(SPHINX_OUTPUT_DIR_PDF ${SPHINX_OUTPUT_DIR})
|
2018-08-16 13:45:59 +02:00
|
|
|
endif()
|
|
|
|
|
2018-07-09 14:12:17 +02:00
|
|
|
if(NOT DEFINED DOC_TAG)
|
|
|
|
set(DOC_TAG development)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Internal variables.
|
2018-07-13 15:32:36 +02:00
|
|
|
set(ALLSPHINXOPTS -d ${CMAKE_CURRENT_BINARY_DIR}/doctrees ${SPHINXOPTS})
|
2018-07-15 18:57:01 +02:00
|
|
|
if("-q" IN_LIST ALLSPHINXOPTS)
|
|
|
|
set(SPHINX_USES_TERMINAL )
|
|
|
|
else()
|
|
|
|
set(SPHINX_USES_TERMINAL USES_TERMINAL)
|
|
|
|
endif()
|
|
|
|
|
2018-07-09 14:12:17 +02:00
|
|
|
# the i18n builder cannot share the environment and doctrees with the others
|
2018-07-13 12:37:13 +02:00
|
|
|
set(I18NSPHINXOPTS ${SPHINXOPTS})
|
2018-07-09 14:12:17 +02:00
|
|
|
|
2018-07-16 19:05:05 +02:00
|
|
|
set(DOXYFILE_IN ${CMAKE_CURRENT_LIST_DIR}/zephyr.doxyfile.in)
|
|
|
|
set(DOXYFILE_OUT ${CMAKE_CURRENT_BINARY_DIR}/zephyr.doxyfile)
|
|
|
|
set(RST_OUT ${CMAKE_CURRENT_BINARY_DIR}/rst)
|
|
|
|
set(DOC_LOG ${CMAKE_CURRENT_BINARY_DIR}/doc.log)
|
|
|
|
set(DOXY_LOG ${CMAKE_CURRENT_BINARY_DIR}/doxy.log)
|
|
|
|
set(SPHINX_LOG ${CMAKE_CURRENT_BINARY_DIR}/sphinx.log)
|
|
|
|
set(DOC_WARN ${CMAKE_CURRENT_BINARY_DIR}/doc.warnings)
|
2018-10-09 20:42:03 +02:00
|
|
|
set(CONTENT_OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/extracted-content.txt)
|
2018-07-09 14:12:17 +02:00
|
|
|
|
2018-07-16 19:05:05 +02:00
|
|
|
configure_file(${DOXYFILE_IN} ${DOXYFILE_OUT} @ONLY)
|
2018-07-09 14:12:17 +02:00
|
|
|
|
2018-10-09 20:42:03 +02:00
|
|
|
# This command is used to copy all documentation source files into the
|
|
|
|
# build directory. Sphinx requires a single documentation root, but
|
|
|
|
# Zephyr's documentation is scattered around the tree in samples/,
|
|
|
|
# boards/, and doc/, so we need to copy those files into a single
|
|
|
|
# place in the build directory.
|
|
|
|
set(EXTRACT_CONTENT_COMMAND
|
|
|
|
${CMAKE_COMMAND} -E env
|
|
|
|
${PYTHON_EXECUTABLE} scripts/extract_content.py
|
|
|
|
# Save the outputs for processing by this list file.
|
|
|
|
--outputs ${CONTENT_OUTPUTS}
|
|
|
|
# Ignore any files in the output directory.
|
|
|
|
--ignore ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
# Copy all files in doc to the rst folder.
|
|
|
|
"*:doc:${RST_OUT}"
|
|
|
|
# Copy the .rst files in samples/ and boards/ to the rst folder, and
|
|
|
|
# also the doc folder inside rst.
|
|
|
|
#
|
|
|
|
# Some files refer to items in samples/ and boards/ relative to
|
|
|
|
# their actual position in the Zephyr tree. For example, in
|
|
|
|
# subsystems/sensor.rst:
|
|
|
|
#
|
|
|
|
# .. literalinclude:: ../../samples/sensor/mcp9808/src/main.c
|
|
|
|
#
|
|
|
|
# We make an additional copy as a hackaround so these references
|
|
|
|
# work.
|
|
|
|
"*.rst:samples:${RST_OUT}" "*.rst:boards:${RST_OUT}"
|
|
|
|
"*.rst:samples:${RST_OUT}/doc" "*.rst:boards:${RST_OUT}/doc")
|
|
|
|
|
|
|
|
# Run the content extraction command at configure time in order to
|
|
|
|
# produce lists of input and output files, which are respectively its
|
|
|
|
# dependencies and outputs. This also causes the content files
|
|
|
|
# to be copied for the first time.
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${EXTRACT_CONTENT_COMMAND}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
|
|
|
RESULT_VARIABLE RET)
|
|
|
|
|
|
|
|
if (NOT RET EQUAL 0)
|
|
|
|
message(FATAL_ERROR "Cannot prepare documentation content extraction")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Load the outputs listing from extract_content.py. This is a file
|
|
|
|
# where each pair of lines is a source file in the Zephyr tree and a
|
|
|
|
# destination file in the build directory.
|
|
|
|
file(STRINGS ${CONTENT_OUTPUTS} EXTRACT_CONTENT_RAW)
|
|
|
|
|
|
|
|
# Build up a list of output files for later use in target/command
|
|
|
|
# DEPENDS. Make sure each output file gets updated if the
|
|
|
|
# corresponding input file changes.
|
|
|
|
set(EXTRACT_CONTENT_OUTPUTS)
|
|
|
|
while(EXTRACT_CONTENT_RAW)
|
|
|
|
list(GET EXTRACT_CONTENT_RAW 0 SRC)
|
|
|
|
list(GET EXTRACT_CONTENT_RAW 1 DST)
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${SRC} ${DST}
|
|
|
|
DEPENDS ${SRC}
|
|
|
|
OUTPUT ${DST}
|
|
|
|
)
|
|
|
|
|
|
|
|
list(REMOVE_AT EXTRACT_CONTENT_RAW 0 1)
|
|
|
|
list(APPEND EXTRACT_CONTENT_OUTPUTS ${DST})
|
|
|
|
endwhile()
|
|
|
|
|
|
|
|
add_custom_target(content DEPENDS ${EXTRACT_CONTENT_OUTPUTS})
|
|
|
|
|
2018-07-16 19:05:05 +02:00
|
|
|
set(ARGS ${DOXYFILE_OUT})
|
2018-07-09 14:12:17 +02:00
|
|
|
|
|
|
|
add_custom_target(
|
|
|
|
doxy
|
|
|
|
COMMAND ${CMAKE_COMMAND}
|
|
|
|
-DCOMMAND=${DOXYGEN_EXECUTABLE}
|
|
|
|
-DARGS="${ARGS}"
|
|
|
|
-DOUTPUT_FILE=${DOXY_LOG}
|
|
|
|
-DERROR_FILE=${DOXY_LOG}
|
2018-07-13 15:32:36 +02:00
|
|
|
-DWORKING_DIRECTORY=${CMAKE_CURRENT_LIST_DIR}
|
2018-07-12 17:34:29 +02:00
|
|
|
-P ${ZEPHYR_BASE}/cmake/util/execute_process.cmake
|
2018-07-09 14:12:17 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_target(
|
|
|
|
pristine
|
|
|
|
COMMAND ${CMAKE_COMMAND} -P ${ZEPHYR_BASE}/cmake/pristine.cmake
|
|
|
|
)
|
|
|
|
|
|
|
|
if(WIN32)
|
|
|
|
set(SEP ;)
|
|
|
|
else()
|
|
|
|
set(SEP :)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_custom_target(
|
|
|
|
kconfig
|
2018-07-16 19:05:05 +02:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${RST_OUT}/doc/reference/kconfig
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E env
|
2018-07-09 14:12:17 +02:00
|
|
|
PYTHONPATH="${ZEPHYR_BASE}/scripts/kconfig${SEP}$ENV{PYTHONPATH}"
|
|
|
|
srctree=${ZEPHYR_BASE}
|
2018-09-28 13:10:57 +02:00
|
|
|
KERNELVERSION=${KERNELVERSION}
|
2018-09-05 12:58:05 +02:00
|
|
|
BOARD_DIR=boards/*/*/
|
|
|
|
ARCH=*
|
2018-09-04 21:34:06 +02:00
|
|
|
SOC_DIR=soc/
|
2018-07-09 14:12:17 +02:00
|
|
|
SRCARCH=x86
|
2018-08-17 22:27:01 +02:00
|
|
|
${PYTHON_EXECUTABLE} scripts/genrest.py Kconfig ${RST_OUT}/doc/reference/kconfig/
|
2018-07-13 15:32:36 +02:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
2018-07-09 14:12:17 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
set(KI_SCRIPT ${ZEPHYR_BASE}/scripts/filter-known-issues.py)
|
2018-08-23 20:11:11 +02:00
|
|
|
set(FIX_TEX_SCRIPT ${ZEPHYR_BASE}/doc/scripts/fix_tex.py)
|
2018-07-09 14:12:17 +02:00
|
|
|
set(CONFIG_DIR ${ZEPHYR_BASE}/.known-issues/doc)
|
|
|
|
|
2018-08-23 20:11:11 +02:00
|
|
|
#
|
|
|
|
# HTML section
|
|
|
|
#
|
2018-07-09 14:12:17 +02:00
|
|
|
add_custom_target(
|
|
|
|
html
|
2018-07-16 19:05:05 +02:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E env
|
|
|
|
ZEPHYR_BUILD=${CMAKE_CURRENT_BINARY_DIR}
|
2018-08-23 20:11:11 +02:00
|
|
|
${SPHINXBUILD} -w ${SPHINX_LOG} -N -t ${DOC_TAG} -b html ${ALLSPHINXOPTS} ${RST_OUT}/doc ${SPHINX_OUTPUT_DIR_HTML}
|
|
|
|
# Merge the Doxygen and Sphinx logs into a single file
|
|
|
|
COMMAND ${CMAKE_COMMAND} -P ${ZEPHYR_BASE}/cmake/util/fmerge.cmake ${DOC_LOG} ${DOXY_LOG} ${SPHINX_LOG}
|
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${KI_SCRIPT} --config-dir ${CONFIG_DIR} --errors ${DOC_WARN} --warnings ${DOC_WARN} ${DOC_LOG}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
|
|
|
${SPHINX_USES_TERMINAL}
|
|
|
|
)
|
|
|
|
|
|
|
|
#
|
|
|
|
# LaTEX section
|
|
|
|
#
|
2018-09-11 02:29:20 +02:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${SPHINX_OUTPUT_DIR_LATEX}/zephyr.tex
|
2018-08-23 20:11:11 +02:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E env
|
|
|
|
ZEPHYR_BUILD=${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
${SPHINXBUILD} -w ${SPHINX_LOG} -N -t ${DOC_TAG} -b latex -t svgconvert ${ALLSPHINXOPTS} ${RST_OUT}/doc ${SPHINX_OUTPUT_DIR_LATEX}
|
2018-07-09 14:12:17 +02:00
|
|
|
# Merge the Doxygen and Sphinx logs into a single file
|
|
|
|
COMMAND ${CMAKE_COMMAND} -P ${ZEPHYR_BASE}/cmake/util/fmerge.cmake ${DOC_LOG} ${DOXY_LOG} ${SPHINX_LOG}
|
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${KI_SCRIPT} --config-dir ${CONFIG_DIR} --errors ${DOC_WARN} --warnings ${DOC_WARN} ${DOC_LOG}
|
2018-08-23 20:11:11 +02:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${FIX_TEX_SCRIPT} ${SPHINX_OUTPUT_DIR_LATEX}/zephyr.tex
|
2018-07-13 15:32:36 +02:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
2018-09-26 11:22:32 +02:00
|
|
|
${SPHINX_USES_TERMINAL}
|
2018-09-11 02:29:20 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_target(
|
|
|
|
latex
|
|
|
|
DEPENDS ${SPHINX_OUTPUT_DIR_LATEX}/zephyr.tex
|
2018-07-09 14:12:17 +02:00
|
|
|
)
|
2018-07-15 18:49:37 +02:00
|
|
|
|
2018-08-23 20:11:11 +02:00
|
|
|
#
|
|
|
|
# PDF section
|
|
|
|
#
|
|
|
|
if(NOT ${LATEXMK} STREQUAL LATEXMK-NOTFOUND)
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${SPHINX_OUTPUT_DIR_LATEX}/zephyr.pdf
|
|
|
|
DEPENDS latexdocs ${SPHINX_OUTPUT_DIR_LATEX}/zephyr.tex
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E env
|
2018-10-02 10:30:39 +02:00
|
|
|
LATEXOPTS="-halt-on-error -no-shell-escape"
|
2018-08-23 20:11:11 +02:00
|
|
|
${LATEXMK} -quiet -pdf -dvi- -ps-
|
|
|
|
WORKING_DIRECTORY ${SPHINX_OUTPUT_DIR_LATEX}
|
|
|
|
)
|
|
|
|
|
|
|
|
if(NOT DEFINED SPHINX_OUTPUT_DIR)
|
|
|
|
# Although latexmk allows specifying output directory,
|
|
|
|
# makeindex fails if one is specified.
|
|
|
|
# Hence the need of this to copy the PDF file over.
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${SPHINX_OUTPUT_DIR_PDF}/zephyr.pdf
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${SPHINX_OUTPUT_DIR_PDF}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${SPHINX_OUTPUT_DIR_LATEX}/zephyr.pdf ${SPHINX_OUTPUT_DIR_PDF}/zephyr.pdf
|
|
|
|
DEPENDS ${SPHINX_OUTPUT_DIR_LATEX}/zephyr.pdf
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_custom_target(
|
|
|
|
pdf
|
|
|
|
DEPENDS ${SPHINX_OUTPUT_DIR_PDF}/zephyr.pdf
|
|
|
|
)
|
|
|
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
#
|
|
|
|
# Dependencies and final targets
|
|
|
|
#
|
2018-07-15 18:49:37 +02:00
|
|
|
add_dependencies(html content doxy kconfig)
|
|
|
|
|
|
|
|
add_custom_target(
|
|
|
|
htmldocs
|
|
|
|
)
|
|
|
|
add_dependencies(htmldocs html)
|
|
|
|
|
2018-08-23 20:11:11 +02:00
|
|
|
add_dependencies(latex content doxy kconfig)
|
|
|
|
|
|
|
|
add_custom_target(
|
|
|
|
latexdocs
|
|
|
|
)
|
|
|
|
add_dependencies(latexdocs latex)
|
|
|
|
|
|
|
|
if(NOT ${LATEXMK} STREQUAL LATEXMK-NOTFOUND)
|
|
|
|
|
|
|
|
add_custom_target(
|
|
|
|
pdfdocs
|
2018-09-11 02:29:20 +02:00
|
|
|
DEPENDS latexdocs pdf
|
2018-08-23 20:11:11 +02:00
|
|
|
)
|
|
|
|
add_dependencies(pdfdocs pdf)
|
|
|
|
|
|
|
|
endif()
|