FindSphinx.cmake 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # Ceres Solver - A fast non-linear least squares minimizer
  2. # Copyright 2023 Google Inc. All rights reserved.
  3. # http://ceres-solver.org/
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions are met:
  7. #
  8. # * Redistributions of source code must retain the above copyright notice,
  9. # this list of conditions and the following disclaimer.
  10. # * Redistributions in binary form must reproduce the above copyright notice,
  11. # this list of conditions and the following disclaimer in the documentation
  12. # and/or other materials provided with the distribution.
  13. # * Neither the name of Google Inc. nor the names of its contributors may be
  14. # used to endorse or promote products derived from this software without
  15. # specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  18. # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  21. # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23. # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  24. # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  25. # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  27. # POSSIBILITY OF SUCH DAMAGE.
  28. #
  29. # Author: pablo.speciale@gmail.com (Pablo Speciale)
  30. #
  31. #[=======================================================================[.rst:
  32. FindSphinx
  33. ==========
  34. Module for locating Sphinx and its components.
  35. This modules defines the following variables:
  36. ``Sphinx_FOUND``
  37. ``TRUE`` iff Sphinx and all of its components have been found.
  38. ``Sphinx_BUILD_EXECUTABLE``
  39. Path to the ``sphinx-build`` tool.
  40. ]=======================================================================]
  41. include (FindPackageHandleStandardArgs)
  42. find_program (Sphinx_BUILD_EXECUTABLE
  43. NAMES sphinx-build
  44. PATHS /opt/local/bin
  45. DOC "Sphinx documentation generator"
  46. )
  47. mark_as_advanced (Sphinx_BUILD_EXECUTABLE)
  48. if (Sphinx_BUILD_EXECUTABLE)
  49. execute_process (
  50. COMMAND ${Sphinx_BUILD_EXECUTABLE} --version
  51. ERROR_STRIP_TRAILING_WHITESPACE
  52. ERROR_VARIABLE _Sphinx_BUILD_ERROR
  53. OUTPUT_STRIP_TRAILING_WHITESPACE
  54. OUTPUT_VARIABLE _Sphinx_VERSION_STRING
  55. RESULT_VARIABLE _Sphinx_BUILD_RESULT
  56. )
  57. if (_Sphinx_BUILD_RESULT EQUAL 0)
  58. string (REGEX REPLACE "^sphinx-build[ \t]+([^ \t]+)$" "\\1" Sphinx_VERSION
  59. "${_Sphinx_VERSION_STRING}")
  60. if (Sphinx_VERSION MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+")
  61. set (Sphinx_VERSION_COMPONENTS 3)
  62. set (Sphinx_VERSION_MAJOR ${CMAKE_MATCH_1})
  63. set (Sphinx_VERSION_MINOR ${CMAKE_MATCH_2})
  64. set (Sphinx_VERSION_PATCH ${CMAKE_MATCH_3})
  65. endif (Sphinx_VERSION MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+")
  66. else (_Sphinx_BUILD_RESULT EQUAL 0)
  67. message (WARNING "Could not determine sphinx-build version: ${_Sphinx_BUILD_ERROR}")
  68. endif (_Sphinx_BUILD_RESULT EQUAL 0)
  69. unset (_Sphinx_BUILD_ERROR)
  70. unset (_Sphinx_BUILD_RESULT)
  71. unset (_Sphinx_VERSION_STRING)
  72. find_package (Python COMPONENTS Interpreter)
  73. set (_Sphinx_BUILD_RESULT FALSE)
  74. if (Python_Interpreter_FOUND)
  75. # Check for Sphinx theme dependency for documentation
  76. foreach (component IN LISTS Sphinx_FIND_COMPONENTS)
  77. string (REGEX MATCH "^(.+_theme)$" theme_component "${component}")
  78. if (NOT theme_component STREQUAL component)
  79. continue ()
  80. endif (NOT theme_component STREQUAL component)
  81. execute_process (
  82. COMMAND ${Python_EXECUTABLE} -c "import ${theme_component}"
  83. ERROR_STRIP_TRAILING_WHITESPACE
  84. ERROR_VARIABLE _Sphinx_BUILD_ERROR
  85. OUTPUT_QUIET
  86. RESULT_VARIABLE _Sphinx_BUILD_RESULT
  87. )
  88. if (_Sphinx_BUILD_RESULT EQUAL 0)
  89. set (Sphinx_${component}_FOUND TRUE)
  90. elseif (_Sphinx_BUILD_RESULT EQUAL 0)
  91. message (WARNING "Could not determine whether Sphinx component '${theme_component}' is available: ${_Sphinx_BUILD_ERROR}")
  92. set (Sphinx_${component}_FOUND FALSE)
  93. endif (_Sphinx_BUILD_RESULT EQUAL 0)
  94. unset (_Sphinx_BUILD_ERROR)
  95. unset (_Sphinx_BUILD_RESULT)
  96. endforeach (component)
  97. unset (theme_component)
  98. endif (Python_Interpreter_FOUND)
  99. endif (Sphinx_BUILD_EXECUTABLE)
  100. find_package_handle_standard_args (Sphinx
  101. REQUIRED_VARS Sphinx_BUILD_EXECUTABLE
  102. VERSION_VAR Sphinx_VERSION
  103. HANDLE_COMPONENTS
  104. )