diff --git a/cmake/FindSphinx.cmake b/cmake/FindSphinx.cmake index 4607f7806..331598006 100644 --- a/cmake/FindSphinx.cmake +++ b/cmake/FindSphinx.cmake @@ -2,44 +2,36 @@ # Find the Sphinx documentation generator # # This modules defines -# SPHINX_EXECUTABLE -# SPHINX_FOUND - -find_program(SPHINX_EXECUTABLE - NAMES sphinx-build - PATHS - /usr/bin - /usr/local/bin - /opt/local/bin - DOC "Sphinx documentation generator" -) +# Sphinx_EXECUTABLE +# Sphinx_FOUND +# function Sphinx_add_target +# function Sphinx_add_targets +# -if( NOT SPHINX_EXECUTABLE ) - set(_Python_VERSIONS - 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0 1.6 1.5 - ) +include(FindPackageHandleStandardArgs) +include(CMakeParseArguments) - foreach( _version ${_Python_VERSIONS} ) - set( _sphinx_NAMES sphinx-build-${_version} ) +set(_sphinx_names sphinx-build) +foreach(_version 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0 1.6 1.5) + list(APPEND _sphinx_names sphinx-build-${_version}) +endforeach() - find_program( SPHINX_EXECUTABLE - NAMES ${_sphinx_NAMES} - PATHS +find_program(Sphinx_EXECUTABLE + NAMES ${_sphinx_names} + PATHS /usr/bin /usr/local/bin - /opt/loca/bin - DOC "Sphinx documentation generator" - ) - endforeach() -endif() + /opt/local/bin + DOC "Sphinx documentation generator" +) +mark_as_advanced(Sphinx_EXECUTABLE) -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Sphinx DEFAULT_MSG - SPHINX_EXECUTABLE +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Sphinx + FOUND_VAR Sphinx_FOUND + REQUIRED_VARS Sphinx_EXECUTABLE ) - option( SPHINX_HTML_OUTPUT "Build a single HTML with the whole content." ON ) option( SPHINX_DIRHTML_OUTPUT "Build HTML pages, but with a single directory per document." OFF ) option( SPHINX_HTMLHELP_OUTPUT "Build HTML pages with additional information for building a documentation collection in htmlhelp." OFF ) @@ -50,96 +42,43 @@ option( SPHINX_LATEX_OUTPUT "Build LaTeX sources that can be compiled to a PDF d option( SPHINX_MAN_OUTPUT "Build manual pages in groff format for UNIX systems." OFF ) option( SPHINX_TEXT_OUTPUT "Build plain text files." OFF ) - -mark_as_advanced( - SPHINX_EXECUTABLE - SPHINX_HTML_OUTPUT - SPHINX_DIRHTML_OUTPUT - SPHINX_HTMLHELP_OUTPUT - SPHINX_QTHELP_OUTPUT - SPHINX_DEVHELP_OUTPUT - SPHINX_EPUB_OUTPUT - SPHINX_LATEX_OUTPUT - SPHINX_MAN_OUTPUT - SPHINX_TEXT_OUTPUT -) - -function( Sphinx_add_target target_name builder conf source destination ) - add_custom_target( ${target_name} ALL - COMMAND ${SPHINX_EXECUTABLE} -b ${builder} - -c ${conf} - ${source} - ${destination} - COMMENT "Generating sphinx documentation: ${builder}" +function(Sphinx_add_target target_name builder conf source destination) + add_custom_target( ${target_name} ALL + COMMAND ${Sphinx_EXECUTABLE} -b ${builder} -c ${conf} ${source} ${destination} + DEPENDS ${conf}/conf.py + COMMENT "Generating sphinx documentation: ${builder}" ) - set_property( - DIRECTORY APPEND PROPERTY - ADDITIONAL_MAKE_CLEAN_FILES - ${destination} + set_property(DIRECTORY APPEND PROPERTY + ADDITIONAL_MAKE_CLEAN_FILES ${destination} ) endfunction() -# Target dependencies can be optionally listed at the end. -function( Sphinx_add_targets target_base_name conf source base_destination ) - - set( _dependencies ) - - foreach( arg IN LISTS ARGN ) - set( _dependencies ${_dependencies} ${arg} ) - endforeach() - - if( ${SPHINX_HTML_OUTPUT} ) - Sphinx_add_target( ${target_base_name}_html html ${conf} ${source} ${base_destination}/html ) - - add_dependencies( ${target_base_name}_html ${_dependencies} ) - endif() - - if( ${SPHINX_DIRHTML_OUTPUT} ) - Sphinx_add_target( ${target_base_name}_dirhtml dirhtml ${conf} ${source} ${base_destination}/dirhtml ) - - add_dependencies( ${target_base_name}_dirhtml ${_dependencies} ) - endif() - - if( ${SPHINX_QTHELP_OUTPUT} ) - Sphinx_add_target( ${target_base_name}_qthelp qthelp ${conf} ${source} ${base_destination}/qthelp ) - - add_dependencies( ${target_base_name}_qthelp ${_dependencies} ) - endif() - - if( ${SPHINX_DEVHELP_OUTPUT} ) - Sphinx_add_target( ${target_base_name}_devhelp devhelp ${conf} ${source} ${base_destination}/devhelp ) - - add_dependencies( ${target_base_name}_devhelp ${_dependencies} ) - endif() - - if( ${SPHINX_EPUB_OUTPUT} ) - Sphinx_add_target( ${target_base_name}_epub epub ${conf} ${source} ${base_destination}/epub ) - - add_dependencies( ${target_base_name}_epub ${_dependencies} ) - endif() - - if( ${SPHINX_LATEX_OUTPUT} ) - Sphinx_add_target( ${target_base_name}_latex latex ${conf} ${source} ${base_destination}/latex ) - - add_dependencies( ${target_base_name}_latex ${_dependencies} ) - endif() - - if( ${SPHINX_MAN_OUTPUT} ) - Sphinx_add_target( ${target_base_name}_man man ${conf} ${source} ${base_destination}/man ) - - add_dependencies( ${target_base_name}_man ${_dependencies} ) - endif() - - if( ${SPHINX_TEXT_OUTPUT} ) - Sphinx_add_target( ${target_base_name}_text text ${conf} ${source} ${base_destination}/text ) - - add_dependencies( ${target_base_name}_text ${_dependencies} ) - endif() - - if( ${BUILD_TESTING} ) - sphinx_add_target( ${target_base_name}_linkcheck linkcheck ${conf} ${source} ${base_destination}/linkcheck ) - - add_dependencies( ${target_base_name}_linkcheck ${_dependencies} ) - endif() +# Usage: +# +# Sphinx_add_targets(NAME +# SRC_DIR / +# DST_DIR / +# CONFIG_DIR / +# [DEPENDENCIES dep1 dep2 dep3 ...] +# ) +function(Sphinx_add_targets) + set(options ) + set(one_value_keywords NAME SRC_DIR DST_DIR CONFIG_DIR) + set(multi_value_keywords DEPENDENCIES) + CMAKE_PARSE_ARGUMENTS(OPT "${options}" "${one_value_keywords}" "${multi_value_keywords}" ${ARGN}) + + if (NOT OPT_NAME OR NOT OPT_SRC_DIR OR NOT OPT_DST_DIR OR NOT OPT_CONFIG_DIR) + message(FATAL_ERROR "Arguments NAME, SRC_DIR, DST_DIR, CONFIG_DIR are required!") + endif() + + foreach(_generator html dirhtml qthelp devhelp epub latex man text linkcheck) + string(TOUPPER ${_generator} _generator_uc) + if (SPHINX_${_generator_uc}_OUTPUT) + Sphinx_add_target(${OPT_NAME}_${_generator} ${_generator} ${OPT_CONFIG_DIR} ${OPT_SRC_DIR} ${OPT_DST_DIR}/${_generator}/) + if (OPT_DEPENDENCIES) + add_dependencies(${OPT_NAME}_${_generator} ${OPT_DEPENDENCIES}) + endif() + endif() + endforeach() endfunction()