Blang/doc/CMakeLists.txt

59 lines
1.7 KiB
CMake

project(BlangDoc NONE)
option(SPHINX_MAN "Build man pages with Sphinx" OFF)
option(SPHINX_HTML "Build html pages with Sphinx" OFF)
find_program(SPHINX_EXECUTABLE
NAMES sphinx-build
DOC "Sphinx Documentation Builder (sphinx-doc.org)"
)
if(NOT SPHINX_MAN AND NOT SPHINX_HTML)
return()
elseif(NOT SPHINX_EXECUTABLE)
message(FATAL_ERROR "SPHINX_EXECUTABLE (sphinx-build) is not found!")
endif()
set(conf_path "${CMAKE_CURRENT_SOURCE_DIR}")
configure_file(conf.py.in conf.py @ONLY)
set(doc_formats "")
if(SPHINX_HTML)
list(APPEND doc_formats html)
endif()
if(SPHINX_MAN)
list(APPEND doc_formats man)
endif()
set(doc_format_outputs "")
set(doc_format_last "")
foreach(format ${doc_formats})
set(doc_format_output "doc_format_${format}")
set(doc_format_log "build-${format}.log")
add_custom_command(
OUTPUT ${doc_format_output}
COMMAND ${SPHINX_EXECUTABLE}
-c ${CMAKE_CURRENT_BINARY_DIR}
-d ${CMAKE_CURRENT_BINARY_DIR}/doctrees
-b ${format}
${g1m_assembler_SOURCE_DIR}/doc/
${CMAKE_CURRENT_BINARY_DIR}/${format}
> ${doc_format_log} # log stdout, pass stderr
DEPENDS ${doc_format_last}
COMMENT "sphinx-build ${format}: see doc/${doc_format_log}"
VERBATIM
)
set_property(SOURCE ${doc_format_output} PROPERTY SYMBOLIC 1)
list(APPEND doc_format_outputs ${doc_format_output})
set(doc_format_last ${doc_format_output})
endforeach()
add_custom_target(documentation ALL DEPENDS ${doc_format_outputs})
if(SPHINX_HTML)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html
DESTINATION ${INSTALL_DOC_DIR}
PATTERN .buildinfo EXCLUDE
PATTERN objects.inv EXCLUDE
)
endif()