@@ -38,19 +38,14 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/depthai-core/cmake")
3838# Constants
3939set (DOCSTRINGS_INCLUDE_PLACEHOLDER_DIR ${CMAKE_CURRENT_BINARY_DIR} /generated /include )
4040set (DOCSTRINGS_INCLUDE_PLACEHOLDER_PATH ${DOCSTRINGS_INCLUDE_PLACEHOLDER_DIR} /docstring.hpp)
41- set (DOCSTRINGS_OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /generated / include /depthai_python_docstring.hpp)
41+ set (DEFAULT_DOCSTRINGS_OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /generated /depthai_python_docstring.hpp)
4242
4343# First specify options
4444option (DEPTHAI_PYTHON_USE_FIND_PACKAGE "Use find_package for depthai-core" OFF )
4545option (DEPTHAI_PYTHON_ENABLE_TESTS "Enable tests" OFF )
4646option (DEPTHAI_PYTHON_ENABLE_EXAMPLES "Enable examples" OFF )
4747option (DEPTHAI_PYTHON_BUILD_DOCS "Build documentation - see docs/requirements.txt for needed dependencies" OFF )
4848option (DEPTHAI_PYTHON_BUILD_DOCSTRINGS "Generate docstrings from header files if module 'pybind11_mkdoc' available" ON )
49- set (DEPTHAI_PYTHON_DOCSTRINGS_INPUT ${DOCSTRINGS_OUTPUT} CACHE FILEPATH "Path to docstring for bindings" )
50- set (DEPTHAI_PYTHON_DOCSTRINGS_OUTPUT ${DOCSTRINGS_OUTPUT} CACHE FILEPATH "Path where docstring file will be generated" )
51- if (DEPTHAI_PYTHON_BUILD_DOCSTRINGS)
52- option (DEPTHAI_PYTHON_FORCE_DOCSTRINGS "Force that docstrings are generated, module 'pybind11_mkdoc' required" OFF )
53- endif ()
5449
5550# Add external dependencies
5651add_subdirectory (external)
@@ -89,22 +84,51 @@ pybind11_add_module(${TARGET_NAME}
8984 src/log /LogBindings.cpp
9085)
9186
87+
88+ # Docstring options
89+ if (DEPTHAI_PYTHON_DOCSTRINGS_INPUT AND DEPTHAI_PYTHON_DOCSTRINGS_OUTPUT)
90+ message (FATAL_ERROR "DEPTHAI_PYTHON_DOCSTRINGS_INPUT and DEPTHAI_PYTHON_DOCSTRINGS_OUTPUT are mutually exclusive" )
91+ endif ()
92+
93+ if (DEPTHAI_PYTHON_DOCSTRINGS_OUTPUT)
94+ # If output is specified set both input and output to same the path
95+ set (docstring_input_path ${DEPTHAI_PYTHON_DOCSTRINGS_OUTPUT} )
96+ set (docstring_output_path ${DEPTHAI_PYTHON_DOCSTRINGS_OUTPUT} )
97+ else ()
98+ # If input docstrings explicitly specified, use those and disable building
99+ if (DEPTHAI_PYTHON_DOCSTRINGS_INPUT)
100+ set (docstring_input_path ${DEPTHAI_PYTHON_DOCSTRINGS_INPUT} )
101+ message (STATUS "Disabled building of docstrings - using docstrings specified by DEPTHAI_PYTHON_DOCSTRINGS_INPUT (${DEPTHAI_PYTHON_DOCSTRINGS_INPUT} )" )
102+ set (DEPTHAI_PYTHON_BUILD_DOCSTRINGS OFF CACHE BOOL "Generate docstrings from header files if module 'pybind11_mkdoc' available" FORCE)
103+ else ()
104+ # Otherwise set default location as input
105+ set (docstring_input_path ${DEFAULT_DOCSTRINGS_OUTPUT} )
106+ endif ()
107+
108+ # Set default output location
109+ set (docstring_output_path ${DEFAULT_DOCSTRINGS_OUTPUT} )
110+ endif ()
111+
112+ if (DEPTHAI_PYTHON_BUILD_DOCSTRINGS)
113+ option (DEPTHAI_PYTHON_FORCE_DOCSTRINGS "Force that docstrings are generated, module 'pybind11_mkdoc' required" OFF )
114+ endif ()
115+
92116# Configure include placeholder with INPUT path
93117configure_file (cmake/docstring.hpp.in ${DOCSTRINGS_INCLUDE_PLACEHOLDER_PATH} )
94118# Add target to generate docstrings
95119if (DEPTHAI_PYTHON_BUILD_DOCSTRINGS)
96120 include (pybind11-mkdoc)
97121
98122 # Check if pybind11_mkdoc available and create target
99- target_pybind11_mkdoc_setup(${DEPTHAI_PYTHON_DOCSTRINGS_OUTPUT } depthai::core ${DEPTHAI_PYTHON_FORCE_DOCSTRINGS} )
123+ target_pybind11_mkdoc_setup(${docstring_output_path } depthai::core ${DEPTHAI_PYTHON_FORCE_DOCSTRINGS} )
100124
101125 if (NOT TARGET pybind11_mkdoc)
102126 # Generate default docstrings to OUTPUT path
103- configure_file (cmake/default_docstring.hpp.in ${DEPTHAI_PYTHON_DOCSTRINGS_OUTPUT } COPYONLY )
127+ configure_file (cmake/default_docstring.hpp.in ${docstring_output_path } COPYONLY )
104128 endif ()
105129else ()
106130 # Generate default docstrings to OUTPUT path
107- configure_file (cmake/default_docstring.hpp.in ${DEPTHAI_PYTHON_DOCSTRINGS_OUTPUT } COPYONLY )
131+ configure_file (cmake/default_docstring.hpp.in ${docstring_output_path } COPYONLY )
108132endif ()
109133
110134# Add include directory
0 commit comments