75 lines
2.1 KiB
Text
75 lines
2.1 KiB
Text
|
set(DOC_SRC "${PROJECT_SOURCE_DIR}/doc")
|
||
|
set(DOC_DEST "${PROJECT_BINARY_DIR}/doc/${DOC}")
|
||
|
set(DOC_TMP "${PROJECT_BINARY_DIR}/tmp/doc")
|
||
|
|
||
|
if(DOC STREQUAL "html")
|
||
|
set(EXTRA_PYTHON_MODULES "sphinx_rtd_theme")
|
||
|
else()
|
||
|
unset(EXTRA_PYTHON_MODULES)
|
||
|
endif()
|
||
|
|
||
|
find_package(PythonInterp REQUIRED)
|
||
|
include(find_python_module)
|
||
|
|
||
|
# do not change the ENV, doesn't work with add_custom_target
|
||
|
# https://cmake.org/Bug/view.php?id=5145
|
||
|
if(ENV{PYTHONPATH})
|
||
|
set(PYTHONPATH "$ENV{PYTHONPATH}")
|
||
|
else()
|
||
|
# PYTHONPATH disables defaults, manually append them
|
||
|
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
|
||
|
"import sys; sys.stdout.write(':'.join(sys.path))"
|
||
|
OUTPUT_VARIABLE PYTHONPATH)
|
||
|
endif()
|
||
|
|
||
|
foreach(module
|
||
|
sphinx
|
||
|
sphinxcontrib.plantuml
|
||
|
${EXTRA_PYTHON_MODULES})
|
||
|
string(TOUPPER "${module}" module_upper)
|
||
|
find_python_module("${module}" "${module_upper}")
|
||
|
set(PYTHONPATH "${${module_upper}_PATH}:${PYTHONPATH}")
|
||
|
endforeach(module)
|
||
|
|
||
|
if(${WERROR})
|
||
|
set(SPHINX_WERROR "-W")
|
||
|
else()
|
||
|
unset(SPHINX_WERROR)
|
||
|
endif()
|
||
|
|
||
|
include(plantuml)
|
||
|
|
||
|
configure_file(
|
||
|
"${DOC_SRC}/conf.py.in"
|
||
|
"${DOC_TMP}/sphinx/conf.py"
|
||
|
@ONLY)
|
||
|
|
||
|
add_custom_target(doc ALL
|
||
|
COMMAND "${CMAKE_COMMAND}" -E echo
|
||
|
"Generating sphinx ${DOC} documentation"
|
||
|
COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=${PYTHONPATH}"
|
||
|
"${PYTHON_EXECUTABLE}" -m sphinx -b "${DOC}"
|
||
|
-d "${DOC_TMP}/sphinx/doctrees" -j auto
|
||
|
-c "${DOC_TMP}/sphinx" -q ${SPHINX_WERROR}
|
||
|
"${DOC_SRC}" "${DOC_DEST}")
|
||
|
add_custom_command(TARGET doc POST_BUILD
|
||
|
COMMAND ;
|
||
|
COMMENT "Output at ${DOC_DEST}")
|
||
|
|
||
|
add_custom_target(doc_nocache
|
||
|
COMMAND "${CMAKE_COMMAND}" -E echo
|
||
|
"Generating sphinx ${DOC} documentation, no cache"
|
||
|
COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=${PYTHONPATH}"
|
||
|
"${PYTHON_EXECUTABLE}" -m sphinx -b "${DOC}" -E
|
||
|
-d "${DOC_TMP}/sphinx/doctrees" -j auto
|
||
|
-c "${DOC_TMP}/sphinx" -q ${SPHINX_WERROR}
|
||
|
"${DOC_SRC}" "${DOC_DEST}")
|
||
|
add_custom_command(TARGET doc_nocache POST_BUILD
|
||
|
COMMAND ;
|
||
|
COMMENT "Output at ${DOC_DEST}")
|
||
|
|
||
|
add_custom_target(doc_clean
|
||
|
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${DOC_DEST}"
|
||
|
COMMAND "${CMAKE_COMMAND}" -E remove_directory
|
||
|
"${DOC_TMP}/sphinx/doctrees")
|