Salome HOME
Update copyrights
[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-2019  CEA/DEN, EDF R&D, OPEN CASCADE
17 #
18 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
19 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
20 #
21 # This library is free software; you can redistribute it and/or
22 # modify it under the terms of the GNU Lesser General Public
23 # License as published by the Free Software Foundation; either
24 # version 2.1 of the License, or (at your option) any later version.
25 #
26 # This library is distributed in the hope that it will be useful,
27 # but WITHOUT ANY WARRANTY; without even the implied warranty of
28 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
29 # Lesser General Public License for more details.
30 #
31 # You should have received a copy of the GNU Lesser General Public
32 # License along with this library; if not, write to the Free Software
33 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
34 #
35 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
36 #
37
38 FIND_PROGRAM(SPHINX_EXECUTABLE
39              NAMES sphinx-build sphinx-build-${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}
40              PATH_SUFFIXES Scripts)
41 FIND_PROGRAM(SPHINX_APIDOC_EXECUTABLE
42              NAMES sphinx-apidoc sphinx-apidoc-${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}
43              PATH_SUFFIXES Scripts)
44 FIND_PROGRAM(SPHINX_INTL_EXECUTABLE
45              NAMES sphinx-intl sphinx-intl-${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}
46              PATH_SUFFIXES Scripts)
47
48
49 # Get root dir locally, going up two levels from the exec:
50 GET_FILENAME_COMPONENT(_tmp_ROOT_DIR "${SPHINX_EXECUTABLE}" PATH)
51 GET_FILENAME_COMPONENT(_tmp_ROOT_DIR "${_tmp_ROOT_DIR}" PATH)
52 IF(WIN32)
53   SET(SPHINX_PYTHONPATH "${_tmp_ROOT_DIR}/lib/site-packages")
54 ELSE()
55   SET(SPHINX_PYTHONPATH "${_tmp_ROOT_DIR}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages")
56 ENDIF()
57
58 # Handle the standard arguments of the find_package() command:
59 INCLUDE(FindPackageHandleStandardArgs)
60 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Sphinx REQUIRED_VARS SPHINX_EXECUTABLE SPHINX_APIDOC_EXECUTABLE SPHINX_INTL_EXECUTABLE)
61
62 FOREACH(_ext ${Sphinx_EXTENSIONS})
63   EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "import ${_ext}; print('ok')" OUTPUT_VARIABLE _has_ext ERROR_QUIET)
64   IF(_has_ext)
65     MESSAGE(STATUS "Required Sphinx extension '${_ext}' has been found!")
66   ELSE()
67     MESSAGE(WARNING "Required Sphinx extension '${_ext}' is not found!")
68   ENDIF()
69 ENDFOREACH()