blob: 7acab08f74304b12dbc807bc7259ee165664cdf4 [file] [log] [blame]
Soby Mathewb4c6df42022-11-09 11:13:29 +00001#-------------------------------------------------------------------------------
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
30Include(CMakeParseArguments)
31
32#Sphinx needs Python.
33find_package(PythonInterp 3)
34if (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()
38endif()
39
40if (NOT DEFINED SPHINX_PATH)
41 if (DEFINED $ENV{SPHINX_PATH})
42 set(SPHINX_PATH $ENV{SPHINX_PATH})
43 endif()
44endif()
45
46
47if (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()
65else()
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()
77endif()
78
79#Get Sphinx version
80execute_process(COMMAND "${SPHINX_EXECUTABLE}" "--version" OUTPUT_VARIABLE _SPHINX_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
81#Parse output
82if(_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()
86endif()
87
88#Set "standard" find module return values
89include(FindPackageHandleStandardArgs)
90find_package_handle_standard_args(Sphinx REQUIRED_VARS SPHINX_EXECUTABLE SPHINX_VERSION VERSION_VAR SPHINX_VERSION)