cmake: small updates to sphinx build target

Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Mihai Tudor Panu 2015-05-18 11:08:19 -07:00
parent bfbbb04065
commit 1079cb7cdd
2 changed files with 28 additions and 24 deletions

View File

@ -70,31 +70,35 @@ if (BUILDDOC)
COMMENT "Generating API documentation with Doxygen" VERBATIM COMMENT "Generating API documentation with Doxygen" VERBATIM
) )
endif (DOXYGEN_FOUND) endif (DOXYGEN_FOUND)
# check if sphinx is installed # check if Sphinx is installed and add target to generate API documentation
find_package (Sphinx) find_package (Sphinx)
if(SPHINX_FOUND) if(SPHINX_FOUND)
# python required for sphinx build # python required for Sphinx build
find_package (PythonLibs) find_package (PythonLibs)
string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING}) string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
list (GET PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR) list (GET PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR)
list (GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR) list (GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR)
# check if site-packages exists, might need a more robust way on adding make install dependency and paths set (SITE_PACKAGES ${CMAKE_INSTALL_LIBDIR}/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages)
if (EXISTS ${CMAKE_INSTALL_LIBDIR}/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages/)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/conf.py.in ${CMAKE_CURRENT_BINARY_DIR}/pydoc/conf.py @ONLY) # throw a warning if site-packages doesn't exist, might need a more robust way on adding make install dependency and paths
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/index.rst ${CMAKE_CURRENT_BINARY_DIR}/pydoc/index.rst) if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${SITE_PACKAGES})
add_custom_target (pydoc message( WARNING " - Sphinx documentation 'pydoc' target depends on python libs generated by 'install' target. Run that first!")
${SPHINX_API_EXECUTABLE} -f -o pydoc ${CMAKE_INSTALL_LIBDIR}/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages/ endif()
#use a separate cmake FILE module for string replacement instead
COMMAND sed -i.bak s|site-packages|sensor-drivers|g pydoc/modules.rst configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/conf.py.in ${CMAKE_CURRENT_BINARY_DIR}/pydoc/conf.py @ONLY)
COMMAND ${SPHINX_EXECUTABLE} -b html pydoc html/python configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/index.rst ${CMAKE_CURRENT_BINARY_DIR}/pydoc/index.rst)
COMMAND sed -i.bak s|\">pyupm_|\">|g html/python/index.html html/python/modules.html add_custom_target (pydoc
COMMAND sed -i.bak s|\\smodule</a>|</a>|g html/python/index.html html/python/modules.html ${SPHINX_API_EXECUTABLE} -f -o pydoc ${SITE_PACKAGES}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} # todo: use a separate cmake FILE module for string replacement instead
COMMENT "Generating API documentation with Sphinx" VERBATIM COMMAND sed -i.bak s|site-packages|sensor-drivers|g pydoc/modules.rst
) COMMAND ${SPHINX_EXECUTABLE} -b html pydoc html/python
else() COMMAND sed -i.bak s|\">pyupm_|\">|g html/python/index.html html/python/modules.html
message( WARNING " - Sphinx documentation depends on python libs generated by 'install' target. Run cmake again after installation to create 'pydoc' target!") COMMAND sed -i.bak s|[[:space:]]module</a>|</a>|g html/python/index.html html/python/modules.html
endif() # cleanup .pyc files
COMMAND find ${SITE_PACKAGES} -name *.pyc -exec rm {} \;
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Sphinx" VERBATIM
)
endif() endif()
endif() endif()

View File

@ -22,7 +22,7 @@ import shlex
# documentation root, use os.path.abspath to make it absolute, like shown here. # 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@/python@PYTHON_VERSION_MAJOR@.@PYTHON_VERSION_MINOR@/site-packages/")
sys.path.insert(0, "@CMAKE_INSTALL_LIBDIR@") sys.path.insert(0, "@CMAKE_INSTALL_LIBDIR@")
sys.path.insert(0, "@MRAA_LIBDIR@") sys.path.insert(0, "@MRAA_LIBDIR@@LIB_SUFFIX@")
# -- General configuration ------------------------------------------------ # -- General configuration ------------------------------------------------