1 ############################################################################## 2 # @file FindSphinx.cmake 3 # @brief Find Sphinx documentation build tools. 5 # @par Input variables: 8 # @tp @b Sphinx_DIR @endtp 9 # <td>Installation directory of Sphinx tools. Can also be set as environment variable.</td> 12 # @tp @b SPHINX_DIR @endtp 13 # <td>Alternative environment variable for @c Sphinx_DIR.</td> 16 # @tp @b Sphinx_FIND_COMPONENTS @endtp 17 # <td>Sphinx build tools to look for, i.e., 'apidoc' and/or 'build'.</td> 21 # @par Output variables: 24 # @tp @b Sphinx_FOUND @endtp 25 # <td>Whether all or only the requested Sphinx build tools were found.</td> 28 # @tp @b SPHINX_FOUND @endtp 29 # <td>Alias for @c Sphinx_FOUND.<td> 32 # @tp @b SPHINX_EXECUTABLE @endtp 33 # <td>Non-cached alias for @c Sphinx-build_EXECUTABLE.</td> 36 # @tp @b Sphinx_PYTHON_EXECUTABLE @endtp 37 # <td>Python executable used to run sphinx-build. This is either the 38 # by default found Python interpreter or a specific version as 39 # specified by the shebang (#!) of the sphinx-build script.</td> 42 # @tp @b Sphinx_PYTHON_OPTIONS @endtp 43 # <td>A list of Python options extracted from the shebang (#!) of the 44 # sphinx-build script. The -E option is added by this module 45 # if the Python executable is not the system default to avoid 46 # problems with a differing setting of the @c PYTHONHOME.</td> 49 # @tp @b Sphinx-build_EXECUTABLE @endtp 50 # <td>Absolute path of the found sphinx-build tool.</td> 53 # @tp @b Sphinx-apidoc_EXECUTABLE @endtp 54 # <td>Absolute path of the found sphinx-apidoc tool.</td> 57 # @tp @b Sphinx_VERSION_STRING @endtp 58 # <td>Sphinx version found e.g. 1.1.2.</td> 61 # @tp @b Sphinx_VERSION_MAJOR @endtp 62 # <td>Sphinx major version found e.g. 1.</td> 65 # @tp @b Sphinx_VERSION_MINOR @endtp 66 # <td>Sphinx minor version found e.g. 1.</td> 69 # @tp @b Sphinx_VERSION_PATCH @endtp 70 # <td>Sphinx patch version found e.g. 2.</td> 74 # @ingroup CMakeFindModules 75 ############################################################################## 77 #============================================================================= 78 # Copyright 2011-2012 University of Pennsylvania 79 # Copyright 2013-2016 Andreas Schuh <andreas.schuh.84@gmail.com> 81 # Distributed under the OSI-approved BSD License (the "License"); 82 # see accompanying file Copyright.txt for details. 84 # This software is distributed WITHOUT ANY WARRANTY; without even the 85 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 86 # See the License for more information. 87 #============================================================================= 88 # (To distribute this file outside of CMake, substitute the full 89 # License text for the above reference.) 91 set (_Sphinx_REQUIRED_VARS)
93 # ----------------------------------------------------------------------------
96 if (NOT $ENV{Sphinx_DIR} STREQUAL
"")
97 set (Sphinx_DIR
"$ENV{Sphinx_DIR}")
99 set (Sphinx_DIR
"$ENV{SPHINX_DIR}")
103 # ---------------------------------------------------------------------------- 104 # default components to look for 106 set (Sphinx_FIND_COMPONENTS
"build" "apidoc")
107 elseif (NOT Sphinx_FIND_COMPONENTS MATCHES
"^(build|apidoc)$")
108 message (FATAL_ERROR
"Invalid Sphinx component in: ${Sphinx_FIND_COMPONENTS}")
111 # ---------------------------------------------------------------------------- 112 # find components, i.e., build tools 113 foreach (_Sphinx_TOOL IN LISTS Sphinx_FIND_COMPONENTS)
116 Sphinx-${_Sphinx_TOOL}_EXECUTABLE
117 NAMES sphinx-${_Sphinx_TOOL} sphinx-${_Sphinx_TOOL}.py
118 HINTS
"${Sphinx_DIR}" 120 DOC
"The sphinx-${_Sphinx_TOOL} Python script." 125 Sphinx-${_Sphinx_TOOL}_EXECUTABLE
126 NAMES sphinx-${_Sphinx_TOOL} sphinx-${_Sphinx_TOOL}.py
127 DOC
"The sphinx-${_Sphinx_TOOL} Python script." 130 mark_as_advanced (Sphinx-${_Sphinx_TOOL}_EXECUTABLE)
131 list (APPEND _Sphinx_REQUIRED_VARS Sphinx-${_Sphinx_TOOL}_EXECUTABLE)
134 # set main Sphinx_EXECUTABLE so basis_find_package can derive DEPENDS_Sphinx_DIR 135 if (Sphinx-build_EXECUTABLE)
141 # ---------------------------------------------------------------------------- 142 # determine Python executable used by Sphinx 143 if (Sphinx-build_EXECUTABLE)
144 # extract python executable from shebang of sphinx-build 147 set (Sphinx_PYTHON_OPTIONS) 148 file (STRINGS "${Sphinx-build_EXECUTABLE}
" FIRST_LINE LIMIT_COUNT 1) 149 if (FIRST_LINE MATCHES "^#!(.*/python.*)
") # does not match "#!/usr/bin/env python
" ! 150 string (REGEX REPLACE "^ +| +$
" "" Sphinx_PYTHON_EXECUTABLE "${CMAKE_MATCH_1}
") 151 if (Sphinx_PYTHON_EXECUTABLE MATCHES "([^ ]+) (.*)
") 152 set (Sphinx_PYTHON_EXECUTABLE "${CMAKE_MATCH_1}
") 153 string (REGEX REPLACE " +
" ";
" Sphinx_PYTHON_OPTIONS "${CMAKE_MATCH_2}
") 156 # this is done to avoid problems with multiple Python versions being installed 157 # remember: CMake command if(STR EQUAL STR) is bad and may cause many troubles ! 158 string (REGEX REPLACE "([.+*?^$])
" "\\\\\\1
" _Sphinx_PYTHON_EXECUTABLE_RE "${PYTHON_EXECUTABLE}
") 159 list (FIND Sphinx_PYTHON_OPTIONS -E IDX) 160 if (IDX EQUAL -1 AND NOT Sphinx_PYTHON_EXECUTABLE MATCHES "^${_Sphinx_PYTHON_EXECUTABLE_RE}$
") 161 list (INSERT Sphinx_PYTHON_OPTIONS 0 -E) 163 unset (_Sphinx_PYTHON_EXECUTABLE_RE) 166 # ---------------------------------------------------------------------------- 167 # determine Sphinx version 168 if (Sphinx-build_EXECUTABLE) 169 # intentionally use invalid -h option here as the help that is shown then 170 # will include the Sphinx version information 171 if (Sphinx_PYTHON_EXECUTABLE) 174 OUTPUT_VARIABLE _Sphinx_VERSION 175 ERROR_VARIABLE _Sphinx_VERSION 179 COMMAND "${Sphinx-build_EXECUTABLE}
" -h 180 OUTPUT_VARIABLE _Sphinx_VERSION 181 ERROR_VARIABLE _Sphinx_VERSION 184 if (_Sphinx_VERSION MATCHES "Sphinx v([0-9]+\\.[0-9]+\\.[0-9]+)
") 185 set (Sphinx_VERSION_STRING "${CMAKE_MATCH_1}
") 187 list(GET _Sphinx_VERSION 0 Sphinx_VERSION_MAJOR) 188 list(GET _Sphinx_VERSION 1 Sphinx_VERSION_MINOR) 189 list(GET _Sphinx_VERSION 2 Sphinx_VERSION_PATCH) 190 if (Sphinx_VERSION_PATCH EQUAL 0) 196 # ---------------------------------------------------------------------------- 197 # compatibility with FindPythonInterp.cmake and FindPerl.cmake 198 set (SPHINX_EXECUTABLE "${Sphinx-build_EXECUTABLE}
") 200 # ---------------------------------------------------------------------------- 201 # handle the QUIETLY and REQUIRED arguments and set SPHINX_FOUND to TRUE if 202 # all listed variables are TRUE 203 include (FindPackageHandleStandardArgs) 204 FIND_PACKAGE_HANDLE_STANDARD_ARGS ( 207 ${_Sphinx_REQUIRED_VARS} 209 Sphinx_VERSION_STRING 212 unset (_Sphinx_VERSION) 213 unset (_Sphinx_REQUIRED_VARS)
cmake Sphinx_PYTHON_EXECUTABLE
cmake Sphinx_VERSION_STRING
macro find_package()
Overloaded find_package() command.
cmake Sphinx_FIND_COMPONENTS