Debian Codegraph @

src/cmake/modules/FindSphinx.cmake

raw
1 # Locate sphinx-build. If found, Sphinx_FOUND will be true and
2 # SPHINX_EXECUTABLE will have the path for the executable.
3 #
4 # Adapted from https://www.vortech.nl/en/integrating-sphinx-in-cmake/ .
5
6 INCLUDE(FindPackageHandleStandardArgs)
7
8 UNSET(_SEARCH_PATH)
9
10 # Sphinx may be installed near the Python interpreter.
11 IF(${CMAKE_VERSION} VERSION_LESS "3.12.0")
12 FIND_PACKAGE(PythonInterp)
13 IF(PYTHONINTERP_FOUND)
14 GET_FILENAME_COMPONENT(_PYTHON_DIR "${PYTHON_EXECUTABLE}" DIRECTORY)
15 LIST(
16 APPEND
17 _SEARCH_PATH
18 "${_PYTHON_DIR}"
19 "${_PYTHON_DIR}/bin"
20 "${_PYTHON_DIR}/Scripts"
21 )
22 ENDIF()
23 ELSE()
24 FIND_PACKAGE(Python COMPONENTS Interpreter)
25 IF(Python_FOUND)
26 GET_FILENAME_COMPONENT(_PYTHON_DIR "${Python_EXECUTABLE}" DIRECTORY)
27 LIST(
28 APPEND
29 _SEARCH_PATH
30 "${_PYTHON_DIR}"
31 "${_PYTHON_DIR}/bin"
32 "${_PYTHON_DIR}/Scripts"
33 )
34 ENDIF()
35 ENDIF()
36
37 # Check /usr/share/sphinx/scripts/python{3,2}; Ubuntu uses those.
38 LIST(
39 APPEND
40 _SEARCH_PATH
41 "/usr/share/sphinx/scripts/python3"
42 "/usr/share/sphinx/scripts/python2"
43 )
44
45 FIND_PROGRAM(
46 SPHINX_EXECUTABLE
47 NAMES sphinx-build sphinx-build3 sphinx-build2 sphinx-build.exe
48 HINTS ${_SEARCH_PATH}
49 )
50 MARK_AS_ADVANCED(SPHINX_EXECUTABLE)
51
52 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Sphinx DEFAULT_MSG SPHINX_EXECUTABLE)