cmlib/CMLibDocBreathe.cmake

81 lines
2.9 KiB
CMake
Raw Normal View History

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.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()
function(add_breathe_target target)
set(options)
set(oneValueArgs COMMENT)
set(multiValueArgs)
2019-02-20 20:25:23 +00:00
2020-04-01 18:42:59 +00:00
cmake_parse_arguments(_BREATHE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(BREATHE_FOUND)
set(WORK_DIR ${CMAKE_BINARY_DIR}/_breathe)
set(BREATHE_DOCS_BUILD_DIR ${WORK_DIR})
set(GENERATE_XML YES)
set(GENERATE_HTML NO)
set(GENERATE_LATEX NO)
set(CONF_FILE ${CMLIB_MODULE_DIR}/doxygen/breathe-conf.py.in)
set(DOXY_FILE ${CMLIB_MODULE_DIR}/doxygen/Doxyfile.in)
2019-02-20 20:25:23 +00:00
configure_file(${CONF_FILE} ${WORK_DIR}/conf.py @ONLY)
configure_file(${DOXY_FILE} ${WORK_DIR}/Doxyfile @ONLY)
2019-02-20 20:25:23 +00:00
add_custom_target(
${target}
2020-03-29 05:44:48 +00:00
VERBATIM
2020-04-01 18:42:59 +00:00
COMMAND ${SPHINX_EXECUTABLE} -q -b html -c ${WORK_DIR} -d ${WORK_DIR}/cache ${WORK_DIR}
${CMAKE_BINARY_DIR}/doc/breathe
COMMENT "Building ${target} documentation with Breathe")
set(INDEX_MD_FILE ${CMAKE_SOURCE_DIR}/doc/breathe/index.md.in)
if(EXISTS ${INDEX_MD_FILE})
configure_file(${INDEX_MD_FILE} ${WORK_DIR}/index.md @ONLY)
file(GLOB MD_FILES ${CMAKE_SOURCE_DIR}/doc/breathe/*.md)
if(MD_FILES)
2020-04-14 09:20:01 +00:00
add_custom_command(TARGET ${target} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different
${MD_FILES} ${WORK_DIR})
endif()
endif()
set(INDEX_RST_FILE ${CMAKE_SOURCE_DIR}/doc/breathe/index.rst.in)
if(EXISTS ${INDEX_RST_FILE})
configure_file(${INDEX_RST_FILE} ${WORK_DIR}/index.rst @ONLY)
file(GLOB RST_FILES ${CMAKE_SOURCE_DIR}/doc/breathe/*.rst)
if(RST_FILES)
2020-04-14 09:20:01 +00:00
add_custom_command(TARGET ${target} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different
${RST_FILES} ${WORK_DIR})
endif()
endif()
2021-06-24 07:39:06 +00:00
install(
DIRECTORY ${CMAKE_BINARY_DIR}/doc/breathe/
COMPONENT doc
OPTIONAL
DESTINATION ${CMAKE_INSTALL_DATADIR}/doc/breathe)
else()
message(STATUS "CMLIB warning:")
2020-04-14 09:20:01 +00:00
add_custom_target(${target} VERBATIM COMMENT " Breathe is not found. Skipping target ${target} build")
endif()
2019-02-20 20:25:23 +00:00
endfunction()