Salome HOME
8a3551606a1aafe923513f590b4f7dbfbb93b557
[tools/configuration.git] / cmake / FindSphinx.cmake
1 # - Sphinx detection
2 #
3 # Output variables:
4 #   SPHINX_EXECUTABLE - path to the Sphinx executable
5 #   SPHINX_PYTHONPATH - path to the Sphinx Python modules
6 #
7 # Additional features:
8 #   Sphinx_EXTENSIONS - optional variable which can be used to specify
9 #                       a list of required Sphinx extensions; not found
10 #                       extensions will be reported during the detection
11 #                       procedure; by default this variable is empty.
12 #                       Example:
13 #                           set(Sphinx_EXTENSIONS sphinxcontrib.napoleon)
14 #
15 ###########################################################################
16 # Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
17 #
18 # This library is free software; you can redistribute it and/or
19 # modify it under the terms of the GNU Lesser General Public
20 # License as published by the Free Software Foundation; either
21 # version 2.1 of the License, or (at your option) any later version.
22 #
23 # This library is distributed in the hope that it will be useful,
24 # but WITHOUT ANY WARRANTY; without even the implied warranty of
25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26 # Lesser General Public License for more details.
27 #
28 # You should have received a copy of the GNU Lesser General Public
29 # License along with this library; if not, write to the Free Software
30 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
31 #
32 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
33 #
34
35 FIND_PROGRAM(SPHINX_EXECUTABLE
36              NAMES sphinx-build sphinx-build-${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}
37              PATH_SUFFIXES Scripts)
38 FIND_PROGRAM(SPHINX_APIDOC_EXECUTABLE
39              NAMES sphinx-apidoc sphinx-apidoc-${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}
40              PATH_SUFFIXES Scripts)
41 FIND_PROGRAM(SPHINX_INTL_EXECUTABLE
42              NAMES sphinx-intl sphinx-intl-${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}
43              PATH_SUFFIXES Scripts)
44
45
46 # Get root dir locally, going up two levels from the exec:
47 GET_FILENAME_COMPONENT(_tmp_ROOT_DIR "${SPHINX_EXECUTABLE}" PATH)
48 GET_FILENAME_COMPONENT(_tmp_ROOT_DIR "${_tmp_ROOT_DIR}" PATH)
49 IF(WIN32)
50   SET(SPHINX_PYTHONPATH "${_tmp_ROOT_DIR}/lib/site-packages")
51 ELSE()
52   SET(SPHINX_PYTHONPATH "${_tmp_ROOT_DIR}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages")
53 ENDIF()
54
55 # Handle the standard arguments of the find_package() command:
56 INCLUDE(FindPackageHandleStandardArgs)
57 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Sphinx REQUIRED_VARS SPHINX_EXECUTABLE SPHINX_APIDOC_EXECUTABLE SPHINX_INTL_EXECUTABLE)
58
59 EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "import sphinx; print(sphinx.__version__)" OUTPUT_VARIABLE SPHINX_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
60 IF(SPHINX_VERSION)
61   MESSAGE(STATUS "Found Sphinx version ${SPHINX_VERSION}")
62 ELSE()
63   MESSAGE(STATUS "Found Sphinx (unknown version)")
64 ENDIF()