include_guard(GLOBAL) function(myx_cmake_doc_breathe) set(BREATHE_FOUND AUTO CACHE STRING "Enable Breathe documentation generator") set_property(CACHE BREATHE_FOUND PROPERTY STRINGS ON OFF AUTO) find_package(Doxygen) find_package(Perl) set(Python_ADDITIONAL_VERSIONS 3.11;3.10;3.9;3.8;3.7;3.6;3.5;3.4;3.3;3.2) find_package(PythonInterp) if(PYTHONINTERP_FOUND) find_package(Sphinx) include(FindPythonModule) find_python_module(breathe) find_python_module(recommonmark) if(DOXYGEN_FOUND AND PERL_FOUND AND PYTHONINTERP_FOUND AND SPHINX_EXECUTABLE AND breathe AND recommonmark) set(BREATHE_FOUND ON CACHE STRING "Breathe documentation generator enabled" FORCE) else() set(BREATHE_FOUND OFF CACHE STRING "Breathe documentation generator disabled" FORCE) endif() else() set(BREATHE_FOUND OFF CACHE STRING "Breathe documentation generator disabled" FORCE) endif() set(_target "myx-cmake-doc-breathe-${CMAKE_PROJECT_NAME}") if(NOT BREATHE_FOUND) message(STATUS "MyxCMake:") add_custom_target(${_target} VERBATIM COMMENT " Breathe is not found. Skipping target ${_target} build") return() endif() if(NOT TARGET ${_target}) set(options) set(oneValueArgs COMMENT) set(multiValueArgs) cmake_parse_arguments(_arg "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) set(BREATHE_DIR ${CMAKE_BINARY_DIR}/doc/breathe) set(BREATHE_CONF_DIR ${BREATHE_DIR}/conf) set(BREATHE_DOXYGEN_DIR ${BREATHE_DIR}/doxygen) set(GENERATE_XML YES) set(GENERATE_HTML NO) set(GENERATE_LATEX NO) set(CONF_FILE ${MYX_CMAKE_FUNCTIONS_DIR}/doc/breathe-conf.py.in) set(DOXY_FILE ${MYX_CMAKE_FUNCTIONS_DIR}/doc/Doxyfile.in) configure_file(${CONF_FILE} ${BREATHE_CONF_DIR}/conf.py @ONLY) configure_file(${DOXY_FILE} ${BREATHE_DOXYGEN_DIR}/Doxyfile @ONLY) add_custom_target(${_target} VERBATIM DEPENDS ${DOXY_FILE} DEPENDS ${CONF_FILE} COMMAND "${CMAKE_COMMAND}" -E make_directory ${BREATHE_CONF_DIR} COMMAND ${SPHINX_EXECUTABLE} -q -b html -c ${BREATHE_CONF_DIR} -d ${BREATHE_DIR}/cache ${BREATHE_DOXYGEN_DIR} ${BREATHE_DIR}/html COMMENT "Building ${CMAKE_PROJECT_NAME} documentation with Breathe") set(INDEX_MD_FILE ${CMAKE_HOME_DIRECTORY}/doc/breathe/index.md.in) if(EXISTS ${INDEX_MD_FILE}) configure_file(${INDEX_MD_FILE} ${BREATHE_DOXYGEN_DIR}/index.md @ONLY) file(GLOB MD_FILES ${CMAKE_HOME_DIRECTORY}/doc/breathe/*.md) if(MD_FILES) add_custom_command(TARGET ${_target} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${MD_FILES} ${BREATHE_DOXYGEN_DIR}) endif() endif() set(INDEX_RST_FILE ${CMAKE_HOME_DIRECTORY}/doc/breathe/index.rst.in) if(EXISTS ${INDEX_RST_FILE}) configure_file(${INDEX_RST_FILE} ${BREATHE_DOXYGEN_DIR}/index.rst @ONLY) file(GLOB RST_FILES ${CMAKE_SOURCE_DIR}/doc/breathe/*.rst) if(RST_FILES) add_custom_command(TARGET ${target} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${RST_FILES} ${BREATHE_DOXYGEN_DIR}) endif() endif() if(NOT TARGET myx-cmake-doc-breathe) add_custom_target(myx-cmake-doc-breathe) endif() add_dependencies(myx-cmake-doc-breathe ${_target}) install(DIRECTORY ${CMAKE_BINARY_DIR}/doc/breathe/html COMPONENT doc OPTIONAL DESTINATION ${CMAKE_INSTALL_DATADIR}/doc/breathe) else() message(STATUS "MyxCMake:") add_custom_target(${target} VERBATIM COMMENT " Breathe is not found. Skipping target ${target} build") endif() endfunction()