diff --git a/Documentation/Cookbook/CMake/RunApplicationsRstGenerator.sh.cmake.in b/Documentation/Cookbook/CMake/RunApplicationsRstGenerator.sh.cmake.in index 1db3cde6aab86c666b516b5c7cde100f4ddada27..cf902c1eb10149d74def84663547781abf0dbee4 100644 --- a/Documentation/Cookbook/CMake/RunApplicationsRstGenerator.sh.cmake.in +++ b/Documentation/Cookbook/CMake/RunApplicationsRstGenerator.sh.cmake.in @@ -2,7 +2,7 @@ #cmake builds with rpath in the binary dir, so we don't need to set LD_LIBRARY_PATH here #export LD_LIBRARY_PATH=@CMAKE_BINARY_DIR@/lib:$LD_LIBRARY_PATH -export PYTHONPATH=@PYTHONPATH_COOKBOOK@:$PYTHONPATH +export PYTHONPATH=@CMAKE_BINARY_DIR@/lib/otb/python:$PYTHONPATH export OTB_APPLICATION_PATH=@CMAKE_BINARY_DIR@/lib/otb/applications python3 @CMAKE_CURRENT_SOURCE_DIR@/Scripts/otbGenerateWrappersRstDoc.py "$1" diff --git a/Documentation/Cookbook/CMakeLists.txt b/Documentation/Cookbook/CMakeLists.txt index cee9b6269ceeae37f27a13504916ff8b6e3d4101..4cda32d6e10e4e9c2f09325f3c28795094bb968c 100644 --- a/Documentation/Cookbook/CMakeLists.txt +++ b/Documentation/Cookbook/CMakeLists.txt @@ -30,22 +30,27 @@ endif() message(STATUS "") message(STATUS "Configuring Cookbook...") -# here we could add -# find_package (Python3 COMPONENTS Interpreter) -# but it requires cmake 3.12+ +# Check we have python bindings with python 3+ +if (NOT OTB_WRAP_PYTHON OR ${PYTHONLIBS_VERSION_STRING} STRLESS "3.0.0") + message(FATAL_ERROR "CookBook build requires Python 3 wrappers. Try setting OTB_WRAP_PYTHON=ON in the CMake configuration, or disable the CookBook with BUILD_COOKBOOK=OFF.") +endif() find_program(SH_INTERP sh) mark_as_advanced(SH_INTERP) +# Note: we do not use either: +# - find_program(SPHINX_BUILD NAMES sphinx-build) +# - find_packages(PythonInterp) +# because they don't work with python virtualenv (in CMake < 3.13.0), +# so in calls to add_custom_target() below, we call them directly. +# See CMake bug: https://gitlab.kitware.com/cmake/cmake/issues/18302 + find_program(LATEX_COMMAND NAMES latex) mark_as_advanced(LATEX_COMMAND) find_program(TAR_COMMAND NAMES tar) mark_as_advanced(TAR_COMMAND) -find_program(SPHINX_BUILD NAMES sphinx-build) -mark_as_advanced(SPHINX_BUILD) - find_program(PDFLATEX_COMMAND NAMES pdflatex ) mark_as_advanced(PDFLATEX_COMMAND) @@ -58,26 +63,12 @@ foreach(cmd TAR_COMMAND PDFLATEX_COMMAND MAKEINDEX_COMMAND - SPHINX_BUILD SH_INTERP) if(NOT ${cmd}) message(FATAL_ERROR "Error while configuring Cookbook, ${cmd} not set. Cannot continue") endif() endforeach() -# We need to set PYTHONPATH for the script otbGenerateWrappersRstDoc.py, depending on how the Python3 module was built -if (OTB_WRAP_PYTHON) - set(PYTHONPATH_COOKBOOK "${CMAKE_BINARY_DIR}/lib/otb/python") -else() - # Cookbook only supports Python3 - # But OTB_WRAP_PYTHON can wrap both python2 and python3 - if (${PYTHONLIBS_VERSION_STRING} STRGREATER "3.0.0") - set(PYTHONPATH_COOKBOOK "${CMAKE_BINARY_DIR}/lib/otb/python") - else() - message(FATAL_ERROR "Must wrap OTB with python lib 3+ to build the cookbook, but found version ${PYTHONLIBS_VERSION_STRING}") - endif() -endif() - set(RST_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/rst) set(RST_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/rst) set(LATEX_DIR ${CMAKE_CURRENT_BINARY_DIR}/latex) @@ -88,7 +79,6 @@ message(STATUS "RST_SOURCE_DIR = ${RST_SOURCE_DIR}") message(STATUS "RST_BINARY_DIR = ${RST_BINARY_DIR}") message(STATUS "LATEX_DIR = ${LATEX_DIR}") message(STATUS "HTML_DIR = ${HTML_DIR}") -message(STATUS "PYTHONPATH_COOKBOOK = ${PYTHONPATH_COOKBOOK}") # Clean any existing build macro(remove_and_make_directories) @@ -140,7 +130,7 @@ add_custom_target(generate_otbapps_rst ) add_custom_target(generate_examples_rst - COMMAND "python3" ${CMAKE_CURRENT_SOURCE_DIR}/Scripts/otbGenerateExamplesRstDoc.py + COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/Scripts/otbGenerateExamplesRstDoc.py ${RST_BINARY_DIR} ${CMAKE_SOURCE_DIR} WORKING_DIRECTORY ${RST_BINARY_DIR} @@ -157,7 +147,7 @@ foreach(app_name ${app_names}) endforeach() add_custom_target(CookBookHTML - COMMAND ${SPHINX_BUILD} + COMMAND sphinx-build -b html ${RST_BINARY_DIR} ${HTML_DIR} @@ -178,7 +168,7 @@ add_custom_target(CookBookArchive COMMENT "Creating archive for html CookBook") add_custom_target(CookBookTexFromRST - COMMAND ${SPHINX_BUILD} + COMMAND sphinx-build -b latex ${RST_BINARY_DIR} ${LATEX_DIR} diff --git a/Documentation/Cookbook/rst/CompilingOTBFromSource.rst b/Documentation/Cookbook/rst/CompilingOTBFromSource.rst index d5fa3737f2c4b82f31c83c6f4d4df01847afca8d..7961cc02b4c01a66b884a02cc678759f70bc5a34 100644 --- a/Documentation/Cookbook/rst/CompilingOTBFromSource.rst +++ b/Documentation/Cookbook/rst/CompilingOTBFromSource.rst @@ -376,3 +376,32 @@ directory where you built OTB and run ``ctest -N`` to have a list of all the tests. Just using ``ctest`` will run all the tests. To select a subset, you can do ``ctest -R Kml`` to run all tests related to kml files or ``ctest -I 1,10`` to run tests from 1 to 10. + +Compiling documentation +----------------------- + +To build the CookBook documentation, the following python packages are required: +``numpy, sphinx, sphinx_rtd_theme``. They are available on pip: + +:: + + pip install numpy sphinx sphinx_rtd_theme + +A working installation of ``latex`` is +required for building the PDF version. + +Enable Python bindings and set ``BUILD_COOKBOOK``: + +:: + + cmake -DOTB_WRAP_PYTHON=ON -DBUILD_COOKBOOK=ON . + +Then, build the target: + +:: + + make CookbookHTML + +:: + + make CookBookPDF