Начало работы с Breathe

This commit is contained in:
Andrei Astafev 2021-12-12 22:37:50 +03:00
parent 4b92732a3b
commit 20d372a25c
6 changed files with 88 additions and 67 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
project(myx-cmake VERSION 0.2.6 LANGUAGES) project(myx-cmake VERSION 0.3.0 LANGUAGES)
include(GNUInstallDirs) include(GNUInstallDirs)
file(WRITE ${CMAKE_SOURCE_DIR}/MyxCMake/MyxCMakeConfigVersion.cmake file(WRITE ${CMAKE_SOURCE_DIR}/MyxCMake/MyxCMakeConfigVersion.cmake

View File

@ -1,11 +1,12 @@
set(BREATHE_FOUND AUTO CACHE STRING "Enable Breathe documentation generator") function(myx_cmake_doc_breathe)
set_property(CACHE BREATHE_FOUND PROPERTY STRINGS ON OFF AUTO) 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(Doxygen)
find_package(Perl) find_package(Perl)
set(Python_ADDITIONAL_VERSIONS 3.9;3.8;3.7;3.6;3.5;3.4;3.3;3.2) 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) find_package(PythonInterp)
if(PYTHONINTERP_FOUND) if(PYTHONINTERP_FOUND)
find_package(Sphinx) find_package(Sphinx)
include(FindPythonModule) include(FindPythonModule)
find_python_module(breathe) find_python_module(breathe)
@ -20,55 +21,65 @@ if(PYTHONINTERP_FOUND)
else() else()
set(BREATHE_FOUND OFF CACHE STRING "Breathe documentation generator disabled" FORCE) set(BREATHE_FOUND OFF CACHE STRING "Breathe documentation generator disabled" FORCE)
endif() endif()
else() else()
set(BREATHE_FOUND OFF CACHE STRING "Breathe documentation generator disabled" FORCE) set(BREATHE_FOUND OFF CACHE STRING "Breathe documentation generator disabled" FORCE)
endif() endif()
function(myx_cmake_add_breathe_target target) 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(options)
set(oneValueArgs COMMENT) set(oneValueArgs COMMENT)
set(multiValueArgs) set(multiValueArgs)
cmake_parse_arguments(_arg "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
cmake_parse_arguments(_BREATHE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) set(BREATHE_DIR ${CMAKE_BINARY_DIR}/doc/breathe)
if(BREATHE_FOUND) set(BREATHE_CONF_DIR ${BREATHE_DIR}/conf)
set(WORK_DIR ${CMAKE_BINARY_DIR}/_breathe) set(BREATHE_DOXYGEN_DIR ${BREATHE_DIR}/doxygen)
set(BREATHE_DOCS_BUILD_DIR ${WORK_DIR})
set(GENERATE_XML YES) set(GENERATE_XML YES)
set(GENERATE_HTML NO) set(GENERATE_HTML NO)
set(GENERATE_LATEX NO) set(GENERATE_LATEX NO)
set(CONF_FILE ${CMLIB_MODULE_DIR}/doxygen/breathe-conf.py.in) set(CONF_FILE ${MYX_CMAKE_FUNCTIONS_DIR}/doc/breathe-conf.py.in)
set(DOXY_FILE ${CMLIB_MODULE_DIR}/doxygen/Doxyfile.in) set(DOXY_FILE ${MYX_CMAKE_FUNCTIONS_DIR}/doc/Doxyfile.in)
configure_file(${CONF_FILE} ${WORK_DIR}/conf.py @ONLY) configure_file(${CONF_FILE} ${BREATHE_CONF_DIR}/conf.py @ONLY)
configure_file(${DOXY_FILE} ${WORK_DIR}/Doxyfile @ONLY) configure_file(${DOXY_FILE} ${BREATHE_DOXYGEN_DIR}/Doxyfile @ONLY)
add_custom_target( add_custom_target(${_target}
${target}
VERBATIM VERBATIM
COMMAND ${SPHINX_EXECUTABLE} -q -b html -c ${WORK_DIR} -d ${WORK_DIR}/cache ${WORK_DIR} DEPENDS ${DOXY_FILE}
${CMAKE_BINARY_DIR}/doc/breathe DEPENDS ${CONF_FILE}
COMMENT "Building ${target} documentation with Breathe") 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_SOURCE_DIR}/doc/breathe/index.md.in) set(INDEX_MD_FILE ${CMAKE_HOME_DIRECTORY}/doc/breathe/index.md.in)
if(EXISTS ${INDEX_MD_FILE}) if(EXISTS ${INDEX_MD_FILE})
configure_file(${INDEX_MD_FILE} ${WORK_DIR}/index.md @ONLY) configure_file(${INDEX_MD_FILE} ${BREATHE_DOXYGEN_DIR}/index.md @ONLY)
file(GLOB MD_FILES ${CMAKE_SOURCE_DIR}/doc/breathe/*.md) file(GLOB MD_FILES ${CMAKE_HOME_DIRECTORY}/doc/breathe/*.md)
if(MD_FILES) if(MD_FILES)
add_custom_command(TARGET ${target} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different add_custom_command(TARGET ${_target} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different
${MD_FILES} ${WORK_DIR}) ${MD_FILES} ${BREATHE_DOXYGEN_DIR})
endif() endif()
endif() endif()
set(INDEX_RST_FILE ${CMAKE_SOURCE_DIR}/doc/breathe/index.rst.in) set(INDEX_RST_FILE ${CMAKE_HOME_DIRECTORY}/doc/breathe/index.rst.in)
if(EXISTS ${INDEX_RST_FILE}) if(EXISTS ${INDEX_RST_FILE})
configure_file(${INDEX_RST_FILE} ${WORK_DIR}/index.rst @ONLY) configure_file(${INDEX_RST_FILE} ${BREATHE_DOXYGEN_DIR}/index.rst @ONLY)
file(GLOB RST_FILES ${CMAKE_SOURCE_DIR}/doc/breathe/*.rst) file(GLOB RST_FILES ${CMAKE_SOURCE_DIR}/doc/breathe/*.rst)
if(RST_FILES) if(RST_FILES)
add_custom_command(TARGET ${target} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different add_custom_command(TARGET ${target} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different
${RST_FILES} ${WORK_DIR}) ${RST_FILES} ${BREATHE_DOXYGEN_DIR})
endif() endif()
endif() endif()
install(DIRECTORY ${CMAKE_BINARY_DIR}/doc/breathe/
install(DIRECTORY ${CMAKE_BINARY_DIR}/doc/breathe/html
COMPONENT doc OPTIONAL COMPONENT doc OPTIONAL
DESTINATION ${CMAKE_INSTALL_DATADIR}/doc/breathe) DESTINATION ${CMAKE_INSTALL_DATADIR}/doc/breathe)
else() else()

View File

@ -49,8 +49,8 @@ master_doc = 'index'
# General information about the project. # General information about the project.
project = '@DOXYGEN_PROJECT_TITLE@' project = '@DOXYGEN_PROJECT_TITLE@'
author = '@AUTHOR_NAME@' author = '@MYX_CMAKE_AUTHOR_NAME@'
copyright = '@CMLIB_YEAR@, ' + author copyright = '© @MYX_CMAKE_YEAR@, ' + author
# The version info for the project you're documenting, acts as replacement for # The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the # |version| and |release|, also used in various other places throughout the
@ -112,7 +112,7 @@ html_sidebars = {
# -- Options for HTMLHelp output ------------------------------------------ # -- Options for HTMLHelp output ------------------------------------------
# Output file base name for HTML help builder. # Output file base name for HTML help builder.
htmlhelp_basename = '@PROJECT_NAME@doc' htmlhelp_basename = '@CMAKE_PROJECT_NAME@doc'
# -- Options for LaTeX output --------------------------------------------- # -- Options for LaTeX output ---------------------------------------------
@ -138,7 +138,7 @@ latex_elements = {
# (source start file, target name, title, # (source start file, target name, title,
# author, documentclass [howto, manual, or own class]). # author, documentclass [howto, manual, or own class]).
latex_documents = [ latex_documents = [
(master_doc, '@PROJECT_NAME@.tex', '@PROJECT_NAME@ Documentation', (master_doc, '@CMAKE_PROJECT_NAME@.tex', '@CMAKE_PROJECT_NAME@ Documentation',
author, 'manual'), author, 'manual'),
] ]
@ -146,7 +146,7 @@ latex_documents = [
# One entry per manual page. List of tuples # One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section). # (source start file, name, description, authors, manual section).
man_pages = [(master_doc, '@PROJECT_NAME@', '@PROJECT_NAME@ Documentation', [author], 1)] man_pages = [(master_doc, '@CMAKE_PROJECT_NAME@', '@CMAKE_PROJECT_NAME@ Documentation', [author], 1)]
# -- Options for Texinfo output ------------------------------------------- # -- Options for Texinfo output -------------------------------------------
@ -154,11 +154,11 @@ man_pages = [(master_doc, '@PROJECT_NAME@', '@PROJECT_NAME@ Documentation', [aut
# (source start file, target name, title, author, # (source start file, target name, title, author,
# dir menu entry, description, category) # dir menu entry, description, category)
texinfo_documents = [ texinfo_documents = [
(master_doc, '@PROJECT_NAME@', '@PROJECT_NAME@ Documentation', author, '@PROJECT_NAME@', (master_doc, '@CMAKE_PROJECT_NAME@', '@CMAKE_PROJECT_NAME@ Documentation', author, '@CMAKE_PROJECT_NAME@',
'One line description of project.', 'Miscellaneous'), 'One line description of project.', 'Miscellaneous'),
] ]
breathe_projects = {'@PROJECT_NAME@': '@BREATHE_DOCS_BUILD_DIR@/xml'} breathe_projects = {'@CMAKE_PROJECT_NAME@': '@BREATHE_DOXYGEN_DIR@/xml'}
def run_doxygen(folder): def run_doxygen(folder):
@ -174,7 +174,7 @@ def run_doxygen(folder):
def setup(app): def setup(app):
run_doxygen('@BREATHE_DOCS_BUILD_DIR@') run_doxygen('@BREATHE_DOXYGEN_DIR@')
app.add_config_value('recommonmark_config', { app.add_config_value('recommonmark_config', {
'enable_auto_toc_tree': True, 'enable_auto_toc_tree': True,
'enable_eval_rst': True, 'enable_eval_rst': True,

View File

@ -12,7 +12,7 @@ include(MyxCMakeProjectVersion)
include(MyxCMakeRequiredVariables) include(MyxCMakeRequiredVariables)
include(MyxCMakeGlobalFunctions) include(MyxCMakeGlobalFunctions)
include(MyxCMakeGlobalVariables) include(MyxCMakeGlobalVariables)
include(MyxCMakeToday) include(MyxCMakeDates)
include(MyxCMakeLSBInfo) include(MyxCMakeLSBInfo)
include(MyxCMakeCompiler) include(MyxCMakeCompiler)
include(MyxCMakeCompilerFlags) include(MyxCMakeCompilerFlags)
@ -33,8 +33,8 @@ include(MyxCMakeAddSharedLibrary)
include(MyxCMakeAddStaticLibrary) include(MyxCMakeAddStaticLibrary)
include(MyxCMakePkgConfig) include(MyxCMakePkgConfig)
include(MyxCMakeNinjaGeneratorHelper) include(MyxCMakeNinjaGeneratorHelper)
include(CMLibDocDoxygen) include(MyxCMakeDocDoxygen)
include(CMLibDocBreathe) include(MyxCMakeDocBreathe)
include(MyxCMakeExternalProject) include(MyxCMakeExternalProject)
include(MyxCMakeCPack) include(MyxCMakeCPack)
include(MyxCMakeUninstall) include(MyxCMakeUninstall)

View File

@ -0,0 +1,18 @@
if(NOT MYX_CMAKE_TODAY)
if(WIN32)
execute_process(COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE MYX_CMAKE_TODAY)
else()
execute_process(COMMAND "date" "+%d/%m/%Y" OUTPUT_VARIABLE MYX_CMAKE_TODAY)
endif()
string(REGEX REPLACE "(..)/(..)/(....).*" "\\3-\\2-\\1" MYX_CMAKE_TODAY ${MYX_CMAKE_TODAY})
endif()
if(NOT MYX_CMAKE_YEAR)
if(WIN32)
execute_process(COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE MYX_CMAKE_YEAR)
else()
execute_process(COMMAND "date" "+%d/%m/%Y" OUTPUT_VARIABLE MYX_CMAKE_YEAR)
endif()
string(REGEX REPLACE "(..)/(..)/(....).*" "\\3" MYX_CMAKE_YEAR ${MYX_CMAKE_YEAR})
endif()

View File

@ -1,8 +0,0 @@
if(NOT TODAY)
if(WIN32)
execute_process(COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE TODAY)
else()
execute_process(COMMAND "date" "+%d/%m/%Y" OUTPUT_VARIABLE TODAY)
endif()
string(REGEX REPLACE "(..)/(..)/(....).*" "\\3-\\2-\\1" TODAY ${TODAY})
endif()