cmake: make sphinx use a python-staging folder instead of site-packages

This means that you no longer need to install UPM in oder to be able to use
`make pydoc`. The target pydoc now depends on target doc which with SWIG will
cause python modules to be built, making parralel builds work as expected. We
wipe the python-staging directory on each make pydoc as it's a custom_target
and will rerun at every time anyways, copy is cheap and in case a module gets
deleted it avoids the doc still getting built

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Brendan Le Foll 2015-05-27 15:04:46 +01:00 committed by Mihai Tudor Panu
parent 54c2c8db76
commit f537a5cd4c
2 changed files with 8 additions and 8 deletions

View File

@ -79,7 +79,7 @@ if (BUILDDOC)
string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
list (GET PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR)
list (GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR)
set (SITE_PACKAGES ${CMAKE_INSTALL_LIBDIR}/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages)
set (SITE_PACKAGES ${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages)
# throw a warning if site-packages doesn't exist, might need a more robust way on adding make install dependency and paths
if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${SITE_PACKAGES})
@ -89,18 +89,19 @@ if (BUILDDOC)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/conf.py.in ${CMAKE_CURRENT_BINARY_DIR}/pydoc/conf.py @ONLY)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/index.rst ${CMAKE_CURRENT_BINARY_DIR}/pydoc/index.rst COPYONLY)
add_custom_target (pydoc
${SPHINX_API_EXECUTABLE} -f -o pydoc ${SITE_PACKAGES}
COMMAND rm -r ${CMAKE_BINARY_DIR}/python-staging && mkdir -p ${CMAKE_BINARY_DIR}/python-staging
COMMAND find ${CMAKE_BINARY_DIR}/src -name "_pyupm_*.so" -exec cp {} ${CMAKE_BINARY_DIR}/python-staging \;
COMMAND find ${CMAKE_BINARY_DIR}/src -name "pyupm_*.py" -exec cp {} ${CMAKE_BINARY_DIR}/python-staging \;
COMMAND ${SPHINX_API_EXECUTABLE} -f -o pydoc ${CMAKE_BINARY_DIR}/python-staging
# todo: use a separate cmake FILE module for string replacement instead
COMMAND sed -i.bak s|site-packages|sensor-drivers|g pydoc/modules.rst
COMMAND ${SPHINX_EXECUTABLE} -b html pydoc html/python
COMMAND sed -i.bak s|\">pyupm_|\">|g html/python/index.html html/python/modules.html
COMMAND sed -i.bak s|[[:space:]]module</a>|</a>|g html/python/index.html html/python/modules.html
# cleanup .pyc files
COMMAND find ${SITE_PACKAGES} -name *.pyc -exec rm {} \;
DEPENDS doc
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Sphinx" VERBATIM
)
endif()
endif ()
# check if Yuidoc is installed and add target for API documentation
find_package(Yuidoc)
if(YUIDOC_FOUND)

View File

@ -20,8 +20,7 @@ import shlex
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, "@CMAKE_INSTALL_LIBDIR@/python@PYTHON_VERSION_MAJOR@.@PYTHON_VERSION_MINOR@/site-packages/")
sys.path.insert(0, "@CMAKE_INSTALL_LIBDIR@")
sys.path.insert(0, "@CMAKE_CURRENT_BINARY_DIR@/python-staging/")
sys.path.insert(0, "@MRAA_LIBDIR@@LIB_SUFFIX@")
# -- General configuration ------------------------------------------------