| 1 |
# Distributed under the original FontForge BSD 3-clause license |
| 2 |
|
| 3 |
#[=======================================================================[.rst: |
| 4 |
FindSphinx |
| 5 |
---------- |
| 6 |
|
| 7 |
Finds Sphinx. |
| 8 |
|
| 9 |
Options |
| 10 |
^^^^^^^ |
| 11 |
|
| 12 |
``SPHINX_DIR`` |
| 13 |
Set to a directory to search for sphinx-build. |
| 14 |
``SPHINX_USE_VIRTUALENV`` |
| 15 |
If set to true and Sphinx is not found, will try to install it into |
| 16 |
a virtualenv. |
| 17 |
|
| 18 |
Result Variables |
| 19 |
^^^^^^^^^^^^^^^^ |
| 20 |
|
| 21 |
This module will set the following variables in your project: |
| 22 |
|
| 23 |
``Sphinx_FOUND`` |
| 24 |
true if a usable Sphinx installation has been found |
| 25 |
``Sphinx_BUILD_BINARY`` |
| 26 |
path to the sphinx-build binary |
| 27 |
``Sphinx_VERSION`` |
| 28 |
the version of sphinx being used |
| 29 |
|
| 30 |
#]=======================================================================] |
| 31 |
|
| 32 |
function(_find_sphinx) |
| 33 |
find_program(Sphinx_BUILD_BINARY NAMES sphinx-build |
| 34 |
HINTS |
| 35 |
$ENV{SPHINX_DIR} |
| 36 |
${PROJECT_BINARY_DIR}/sphinx-venv/Scripts |
| 37 |
${PROJECT_BINARY_DIR}/sphinx-venv/bin |
| 38 |
PATH_SUFFIXES bin |
| 39 |
DOC "Sphinx documentation generator" |
| 40 |
) |
| 41 |
endfunction() |
| 42 |
|
| 43 |
function(_sphinx_from_venv) |
| 44 |
find_package(Python3 3.3 COMPONENTS Interpreter) |
| 45 |
if(NOT Python3_Interpreter_FOUND) |
| 46 |
message(STATUS "Python3 not found, skipping") |
| 47 |
return() |
| 48 |
endif() |
| 49 |
execute_process(COMMAND "${Python3_EXECUTABLE}" -m venv "${PROJECT_BINARY_DIR}/sphinx-venv") |
| 50 |
|
| 51 |
find_program(_venv_bin NAMES python |
| 52 |
NO_DEFAULT_PATH |
| 53 |
HINTS |
| 54 |
"${PROJECT_BINARY_DIR}/sphinx-venv/Scripts" |
| 55 |
"${PROJECT_BINARY_DIR}/sphinx-venv/bin" |
| 56 |
) |
| 57 |
if(NOT _venv_bin) |
| 58 |
message(WARNING "could not make venv") |
| 59 |
return() |
| 60 |
endif() |
| 61 |
|
| 62 |
execute_process(COMMAND "${_venv_bin}" -m pip install sphinx RESULT_VARIABLE _pip_result) |
| 63 |
if(_pip_result) |
| 64 |
message(WARNING "could not install sphinx") |
| 65 |
return() |
| 66 |
endif() |
| 67 |
|
| 68 |
_find_sphinx() |
| 69 |
endfunction() |
| 70 |
|
| 71 |
|
| 72 |
_find_sphinx() |
| 73 |
|
| 74 |
if(NOT Sphinx_BUILD_BINARY AND SPHINX_USE_VENV AND NOT EXISTS "${PROJECT_BINARY_DIR}/sphinx-venv") |
| 75 |
message(STATUS "sphinx-build not found, attempting to install it into a venv...") |
| 76 |
_sphinx_from_venv() |
| 77 |
endif() |
| 78 |
|
| 79 |
if(Sphinx_BUILD_BINARY) |
| 80 |
execute_process(COMMAND "${Sphinx_BUILD_BINARY}" --version |
| 81 |
OUTPUT_VARIABLE Sphinx_VERSION_STRING |
| 82 |
ERROR_QUIET |
| 83 |
OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 84 |
string(REGEX REPLACE "^.* ([0-9\.]+)$" "\\1" Sphinx_VERSION "${Sphinx_VERSION_STRING}") |
| 85 |
endif() |
| 86 |
|
| 87 |
include(FindPackageHandleStandardArgs) |
| 88 |
find_package_handle_standard_args( |
| 89 |
Sphinx |
| 90 |
REQUIRED_VARS |
| 91 |
Sphinx_BUILD_BINARY |
| 92 |
VERSION_VAR |
| 93 |
Sphinx_VERSION |
| 94 |
) |