Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame^] | 1 | #------------------------------------------------------------------------------- |
| 2 | # SPDX-License-Identifier: BSD-3-Clause |
| 3 | # SPDX-FileCopyrightText: Copyright TF-RMM Contributors. |
| 4 | #------------------------------------------------------------------------------- |
| 5 | |
| 6 | #FindSphinx |
| 7 | #----------- |
| 8 | #Sphinx is a document generation tool written in Python. |
| 9 | #See http://www.sphinx-doc.org/en/master/ |
| 10 | # |
| 11 | #This module checks availability of the Sphinx document generator |
| 12 | #(sphinx-build) and it's dependences (Python). |
| 13 | #Sphinx is distributed as pip package or on Linux as a distribution specific |
| 14 | #package (i.e. python-sphinx for Ubuntu). Independent of the distribution |
| 15 | #method this module expects sphix-build to be either available on the PATH, |
| 16 | #or to be located in a host OS specific standard location. |
| 17 | # |
| 18 | #This modules has the following parameters: |
| 19 | # SPHINX_PATH = variable specifying where sphinx-build can be found. |
| 20 | # If it is not defined the environment variable with |
| 21 | # the same name is used. If that is also undefined, |
| 22 | # then OS specific standard locations will be |
| 23 | # searched. |
| 24 | # |
| 25 | # This modules defines the following variables: |
| 26 | # SPHINX_VERSION = The version reported by "sphinx-build --version" |
| 27 | # SPHINX_FOUND = True is sphinx-build was found and executed fine |
| 28 | # |
| 29 | |
| 30 | Include(CMakeParseArguments) |
| 31 | |
| 32 | #Sphinx needs Python. |
| 33 | find_package(PythonInterp 3) |
| 34 | if (NOT PYTHONINTERP_FOUND) |
| 35 | message(STATUS "Can not find Python3.x interpreter. Pyhton3 must be installed and available on the PATH.") |
| 36 | message(STATUS "Sphinx documentation targets will not be created.") |
| 37 | return() |
| 38 | endif() |
| 39 | |
| 40 | if (NOT DEFINED SPHINX_PATH) |
| 41 | if (DEFINED $ENV{SPHINX_PATH}) |
| 42 | set(SPHINX_PATH $ENV{SPHINX_PATH}) |
| 43 | endif() |
| 44 | endif() |
| 45 | |
| 46 | |
| 47 | if (DEFINED SPHINX_PATH) |
| 48 | #Find the Sphinx executable. Search only at SPHINX_PATH. |
| 49 | find_program(SPHINX_EXECUTABLE |
| 50 | NAMES sphinx-build |
| 51 | DOC "Sphinx Documentation Builder (sphinx-doc.org)" |
| 52 | PATH ${SPHINX_PATH} |
| 53 | NO_DEFAULT_PATH |
| 54 | NO_CMAKE_ENVIRONMENT_PATH |
| 55 | NO_CMAKE_PATH |
| 56 | NO_SYSTEM_ENVIRONMENT_PATH |
| 57 | NO_CMAKE_SYSTEM_PATH |
| 58 | NO_CMAKE_FIND_ROOT_PATH |
| 59 | ) |
| 60 | if (SPHINX_EXECUTABLE-NOTFOUND) |
| 61 | message(STATUS "Failed to find sphinx-build at ${SPHINX_PATH}.") |
| 62 | message(STATUS "Sphinx documentation targets will not be created.") |
| 63 | return() |
| 64 | endif() |
| 65 | else() |
| 66 | #Find the Sphinx executable. Search OS specific default locations. |
| 67 | find_program(SPHINX_EXECUTABLE |
| 68 | NAMES sphinx-build |
| 69 | DOC "Sphinx Documentation Builder (sphinx-doc.org)" |
| 70 | ) |
| 71 | |
| 72 | if (SPHINX_EXECUTABLE-NOTFOUND) |
| 73 | message(STATUS "Failed to find sphinx-build at OS specific default locations.") |
| 74 | message(STATUS "Sphinx documentation targets will not be created.") |
| 75 | return() |
| 76 | endif() |
| 77 | endif() |
| 78 | |
| 79 | #Get Sphinx version |
| 80 | execute_process(COMMAND "${SPHINX_EXECUTABLE}" "--version" OUTPUT_VARIABLE _SPHINX_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) |
| 81 | #Parse output |
| 82 | if(_SPHINX_VERSION) |
| 83 | if(_SPHINX_VERSION MATCHES ".*sphinx-build[^0-9.]*([0-9.]+).*") |
| 84 | string(REGEX REPLACE ".*sphinx-build ([0-9.]+).*" "\\1" SPHINX_VERSION "${_SPHINX_VERSION}") |
| 85 | endif() |
| 86 | endif() |
| 87 | |
| 88 | #Set "standard" find module return values |
| 89 | include(FindPackageHandleStandardArgs) |
| 90 | find_package_handle_standard_args(Sphinx REQUIRED_VARS SPHINX_EXECUTABLE SPHINX_VERSION VERSION_VAR SPHINX_VERSION) |