FindSphinx.cmake 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. #
  2. # PART B. DOWNLOADING AGREEMENT - LICENSE FROM SBIA WITH RIGHT TO SUBLICENSE ("SOFTWARE LICENSE").
  3. # ------------------------------------------------------------------------------------------------
  4. #
  5. # 1. As used in this Software License, "you" means the individual downloading and/or
  6. # using, reproducing, modifying, displaying and/or distributing the Software and
  7. # the institution or entity which employs or is otherwise affiliated with such
  8. # individual in connection therewith. The Section of Biomedical Image Analysis,
  9. # Department of Radiology at the Universiy of Pennsylvania ("SBIA") hereby grants
  10. # you, with right to sublicense, with respect to SBIA's rights in the software,
  11. # and data, if any, which is the subject of this Software License (collectively,
  12. # the "Software"), a royalty-free, non-exclusive license to use, reproduce, make
  13. # derivative works of, display and distribute the Software, provided that:
  14. # (a) you accept and adhere to all of the terms and conditions of this Software
  15. # License; (b) in connection with any copy of or sublicense of all or any portion
  16. # of the Software, all of the terms and conditions in this Software License shall
  17. # appear in and shall apply to such copy and such sublicense, including without
  18. # limitation all source and executable forms and on any user documentation,
  19. # prefaced with the following words: "All or portions of this licensed product
  20. # (such portions are the "Software") have been obtained under license from the
  21. # Section of Biomedical Image Analysis, Department of Radiology at the University
  22. # of Pennsylvania and are subject to the following terms and conditions:"
  23. # (c) you preserve and maintain all applicable attributions, copyright notices
  24. # and licenses included in or applicable to the Software; (d) modified versions
  25. # of the Software must be clearly identified and marked as such, and must not
  26. # be misrepresented as being the original Software; and (e) you consider making,
  27. # but are under no obligation to make, the source code of any of your modifications
  28. # to the Software freely available to others on an open source basis.
  29. #
  30. # 2. The license granted in this Software License includes without limitation the
  31. # right to (i) incorporate the Software into proprietary programs (subject to
  32. # any restrictions applicable to such programs), (ii) add your own copyright
  33. # statement to your modifications of the Software, and (iii) provide additional
  34. # or different license terms and conditions in your sublicenses of modifications
  35. # of the Software; provided that in each case your use, reproduction or
  36. # distribution of such modifications otherwise complies with the conditions
  37. # stated in this Software License.
  38. #
  39. # 3. This Software License does not grant any rights with respect to third party
  40. # software, except those rights that SBIA has been authorized by a third
  41. # party to grant to you, and accordingly you are solely responsible for
  42. # (i) obtaining any permissions from third parties that you need to use,
  43. # reproduce, make derivative works of, display and distribute the Software,
  44. # and (ii) informing your sublicensees, including without limitation your
  45. # end-users, of their obligations to secure any such required permissions.
  46. #
  47. # 4. The Software has been designed for research purposes only and has not been
  48. # reviewed or approved by the Food and Drug Administration or by any other
  49. # agency. YOU ACKNOWLEDGE AND AGREE THAT CLINICAL APPLICATIONS ARE NEITHER
  50. # RECOMMENDED NOR ADVISED. Any commercialization of the Software is at the
  51. # sole risk of the party or parties engaged in such commercialization.
  52. # You further agree to use, reproduce, make derivative works of, display
  53. # and distribute the Software in compliance with all applicable governmental
  54. # laws, regulations and orders, including without limitation those relating
  55. # to export and import control.
  56. #
  57. # 5. The Software is provided "AS IS" and neither SBIA nor any contributor to
  58. # the software (each a "Contributor") shall have any obligation to provide
  59. # maintenance, support, updates, enhancements or modifications thereto.
  60. # SBIA AND ALL CONTRIBUTORS SPECIFICALLY DISCLAIM ALL EXPRESS AND IMPLIED
  61. # WARRANTIES OF ANY KIND INCLUDING, BUT NOT LIMITED TO, ANY WARRANTIES OF
  62. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  63. # IN NO EVENT SHALL SBIA OR ANY CONTRIBUTOR BE LIABLE TO ANY PARTY FOR
  64. # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES
  65. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY ARISING IN ANY WAY RELATED
  66. # TO THE SOFTWARE, EVEN IF SBIA OR ANY CONTRIBUTOR HAS BEEN ADVISED OF THE
  67. # POSSIBILITY OF SUCH DAMAGES. TO THE MAXIMUM EXTENT NOT PROHIBITED BY LAW OR
  68. # REGULATION, YOU FURTHER ASSUME ALL LIABILITY FOR YOUR USE, REPRODUCTION,
  69. # MAKING OF DERIVATIVE WORKS, DISPLAY, LICENSE OR DISTRIBUTION OF THE SOFTWARE
  70. # AND AGREE TO INDEMNIFY AND HOLD HARMLESS SBIA AND ALL CONTRIBUTORS FROM
  71. # AND AGAINST ANY AND ALL CLAIMS, SUITS, ACTIONS, DEMANDS AND JUDGMENTS ARISING
  72. # THEREFROM.
  73. #
  74. # 6. None of the names, logos or trademarks of SBIA or any of SBIA's affiliates
  75. # or any of the Contributors, or any funding agency, may be used to endorse
  76. # or promote products produced in whole or in part by operation of the Software
  77. # or derived from or based on the Software without specific prior written
  78. # permission from the applicable party.
  79. #
  80. # 7. Any use, reproduction or distribution of the Software which is not in accordance
  81. # with this Software License shall automatically revoke all rights granted to you
  82. # under this Software License and render Paragraphs 1 and 2 of this Software
  83. # License null and void.
  84. #
  85. # 8. This Software License does not grant any rights in or to any intellectual
  86. # property owned by SBIA or any Contributor except those rights expressly
  87. # granted hereunder.
  88. #
  89. #
  90. # PART C. MISCELLANEOUS
  91. # ---------------------
  92. #
  93. # This Agreement shall be governed by and construed in accordance with the laws
  94. # of The Commonwealth of Pennsylvania without regard to principles of conflicts
  95. # of law. This Agreement shall supercede and replace any license terms that you
  96. # may have agreed to previously with respect to Software from SBIA.
  97. #
  98. ##############################################################################
  99. # @file FindSphinx.cmake
  100. # @brief Find Sphinx documentation build tools.
  101. #
  102. # @par Input variables:
  103. # <table border="0">
  104. # <tr>
  105. # @tp @b Sphinx_DIR @endtp
  106. # <td>Installation directory of Sphinx tools. Can also be set as environment variable.</td>
  107. # </tr>
  108. # <tr>
  109. # @tp @b SPHINX_DIR @endtp
  110. # <td>Alternative environment variable for @c Sphinx_DIR.</td>
  111. # </tr>
  112. # <tr>
  113. # @tp @b Sphinx_FIND_COMPONENTS @endtp
  114. # <td>Sphinx build tools to look for, i.e., 'apidoc' and/or 'build'.</td>
  115. # </tr>
  116. # </table>
  117. #
  118. # @par Output variables:
  119. # <table border="0">
  120. # <tr>
  121. # @tp @b Sphinx_FOUND @endtp
  122. # <td>Whether all or only the requested Sphinx build tools were found.</td>
  123. # </tr>
  124. # <tr>
  125. # @tp @b SPHINX_FOUND @endtp
  126. # <td>Alias for @c Sphinx_FOUND.<td>
  127. # </tr>
  128. # <tr>
  129. # @tp @b SPHINX_EXECUTABLE @endtp
  130. # <td>Non-cached alias for @c Sphinx-build_EXECUTABLE.</td>
  131. # </tr>
  132. # <tr>
  133. # @tp @b Sphinx_PYTHON_EXECUTABLE @endtp
  134. # <td>Python executable used to run sphinx-build. This is either the
  135. # by default found Python interpreter or a specific version as
  136. # specified by the shebang (#!) of the sphinx-build script.</td>
  137. # </tr>
  138. # <tr>
  139. # @tp @b Sphinx_PYTHON_OPTIONS @endtp
  140. # <td>A list of Python options extracted from the shebang (#!) of the
  141. # sphinx-build script. The -E option is added by this module
  142. # if the Python executable is not the system default to avoid
  143. # problems with a differing setting of the @c PYTHONHOME.</td>
  144. # </tr>
  145. # <tr>
  146. # @tp @b Sphinx-build_EXECUTABLE @endtp
  147. # <td>Absolute path of the found sphinx-build tool.</td>
  148. # </tr>
  149. # <tr>
  150. # @tp @b Sphinx-apidoc_EXECUTABLE @endtp
  151. # <td>Absolute path of the found sphinx-apidoc tool.</td>
  152. # </tr>
  153. # <tr>
  154. # @tp @b Sphinx_VERSION_STRING @endtp
  155. # <td>Sphinx version found e.g. 1.1.2.</td>
  156. # </tr>
  157. # <tr>
  158. # @tp @b Sphinx_VERSION_MAJOR @endtp
  159. # <td>Sphinx major version found e.g. 1.</td>
  160. # </tr>
  161. # <tr>
  162. # @tp @b Sphinx_VERSION_MINOR @endtp
  163. # <td>Sphinx minor version found e.g. 1.</td>
  164. # </tr>
  165. # <tr>
  166. # @tp @b Sphinx_VERSION_PATCH @endtp
  167. # <td>Sphinx patch version found e.g. 2.</td>
  168. # </tr>
  169. # </table>
  170. #
  171. # @ingroup CMakeFindModules
  172. ##############################################################################
  173. set (_Sphinx_REQUIRED_VARS)
  174. # ----------------------------------------------------------------------------
  175. # initialize search
  176. if (NOT Sphinx_DIR)
  177. if (NOT $ENV{Sphinx_DIR} STREQUAL "")
  178. set (Sphinx_DIR "$ENV{Sphinx_DIR}" CACHE PATH "Installation prefix of Sphinx (docutils)." FORCE)
  179. else ()
  180. set (Sphinx_DIR "$ENV{SPHINX_DIR}" CACHE PATH "Installation prefix of Sphinx (docutils)." FORCE)
  181. endif ()
  182. endif ()
  183. # ----------------------------------------------------------------------------
  184. # default components to look for
  185. if (NOT Sphinx_FIND_COMPONENTS)
  186. set (Sphinx_FIND_COMPONENTS "build")
  187. elseif (NOT Sphinx_FIND_COMPONENTS MATCHES "^(build|apidoc)$")
  188. message (FATAL_ERROR "Invalid Sphinx component in: ${Sphinx_FIND_COMPONENTS}")
  189. endif ()
  190. # ----------------------------------------------------------------------------
  191. # find components, i.e., build tools
  192. foreach (_Sphinx_TOOL IN LISTS Sphinx_FIND_COMPONENTS)
  193. if (Sphinx_DIR)
  194. find_program (
  195. Sphinx-${_Sphinx_TOOL}_EXECUTABLE
  196. NAMES sphinx-${_Sphinx_TOOL} sphinx-${_Sphinx_TOOL}.py
  197. HINTS "${Sphinx_DIR}"
  198. PATH_SUFFIXES bin
  199. DOC "The sphinx-${_Sphinx_TOOL} Python script."
  200. NO_DEFAULT_PATH
  201. )
  202. else ()
  203. find_program (
  204. Sphinx-${_Sphinx_TOOL}_EXECUTABLE
  205. NAMES sphinx-${_Sphinx_TOOL} sphinx-${_Sphinx_TOOL}.py
  206. DOC "The sphinx-${_Sphinx_TOOL} Python script."
  207. )
  208. endif ()
  209. mark_as_advanced (Sphinx-${_Sphinx_TOOL}_EXECUTABLE)
  210. list (APPEND _Sphinx_REQUIRED_VARS Sphinx-${_Sphinx_TOOL}_EXECUTABLE)
  211. endforeach ()
  212. # ----------------------------------------------------------------------------
  213. # determine Python executable used by Sphinx
  214. if (Sphinx-build_EXECUTABLE)
  215. # extract python executable from shebang of sphinx-build
  216. find_package (PythonInterp QUIET)
  217. set (Sphinx_PYTHON_EXECUTABLE "${PYTHON_EXECUTABLE}")
  218. set (Sphinx_PYTHON_OPTIONS)
  219. file (STRINGS "${Sphinx-build_EXECUTABLE}" FIRST_LINE LIMIT_COUNT 1)
  220. if (FIRST_LINE MATCHES "^#!(.*/python.*)") # does not match "#!/usr/bin/env python" !
  221. string (REGEX REPLACE "^ +| +$" "" Sphinx_PYTHON_EXECUTABLE "${CMAKE_MATCH_1}")
  222. if (Sphinx_PYTHON_EXECUTABLE MATCHES "([^ ]+) (.*)")
  223. set (Sphinx_PYTHON_EXECUTABLE "${CMAKE_MATCH_1}")
  224. string (REGEX REPLACE " +" ";" Sphinx_PYTHON_OPTIONS "${CMAKE_MATCH_2}")
  225. endif ()
  226. endif ()
  227. # this is done to avoid problems with multiple Python versions being installed
  228. # remember: CMake command if(STR EQUAL STR) is bad and may cause many troubles !
  229. string (REGEX REPLACE "([.+*?^$])" "\\\\\\1" _Sphinx_PYTHON_EXECUTABLE_RE "${PYTHON_EXECUTABLE}")
  230. list (FIND Sphinx_PYTHON_OPTIONS -E IDX)
  231. if (IDX EQUAL -1 AND NOT Sphinx_PYTHON_EXECUTABLE MATCHES "^${_Sphinx_PYTHON_EXECUTABLE_RE}$")
  232. list (INSERT Sphinx_PYTHON_OPTIONS 0 -E)
  233. endif ()
  234. unset (_Sphinx_PYTHON_EXECUTABLE_RE)
  235. endif ()
  236. # ----------------------------------------------------------------------------
  237. # determine Sphinx version
  238. if (Sphinx-build_EXECUTABLE)
  239. # intentionally use invalid -h option here as the help that is shown then
  240. # will include the Sphinx version information
  241. if (Sphinx_PYTHON_EXECUTABLE)
  242. execute_process (
  243. COMMAND "${Sphinx_PYTHON_EXECUTABLE}" ${Sphinx_PYTHON_OPTIONS} "${Sphinx-build_EXECUTABLE}" -h
  244. OUTPUT_VARIABLE _Sphinx_VERSION
  245. ERROR_VARIABLE _Sphinx_VERSION
  246. )
  247. elseif (UNIX)
  248. execute_process (
  249. COMMAND "${Sphinx-build_EXECUTABLE}" -h
  250. OUTPUT_VARIABLE _Sphinx_VERSION
  251. ERROR_VARIABLE _Sphinx_VERSION
  252. )
  253. endif ()
  254. # The sphinx version can also contain a "b" instead of the last dot.
  255. # For example "Sphinx v1.2b1" so we cannot just split on "."
  256. if (_Sphinx_VERSION MATCHES "Sphinx v([0-9]+\\.[0-9]+(\\.|b)[0-9]+)")
  257. set (Sphinx_VERSION_STRING "${CMAKE_MATCH_1}")
  258. string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.|b)[0-9]+" "\\1" Sphinx_VERSION_MAJOR ${Sphinx_VERSION_STRING})
  259. string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.|b)[0-9]+" "\\1" Sphinx_VERSION_MINOR ${Sphinx_VERSION_STRING})
  260. string(REGEX REPLACE "[0-9]+\\.[0-9]+(\\.|b)([0-9]+)" "\\1" Sphinx_VERSION_PATCH ${Sphinx_VERSION_STRING})
  261. # v1.2.0 -> v1.2
  262. if (Sphinx_VERSION_PATCH EQUAL 0)
  263. string (REGEX REPLACE "\\.0$" "" Sphinx_VERSION_STRING "${Sphinx_VERSION_STRING}")
  264. endif ()
  265. endif()
  266. endif ()
  267. # ----------------------------------------------------------------------------
  268. # compatibility with FindPythonInterp.cmake and FindPerl.cmake
  269. set (SPHINX_EXECUTABLE "${Sphinx-build_EXECUTABLE}")
  270. # ----------------------------------------------------------------------------
  271. # handle the QUIETLY and REQUIRED arguments and set SPHINX_FOUND to TRUE if
  272. # all listed variables are TRUE
  273. include (FindPackageHandleStandardArgs)
  274. FIND_PACKAGE_HANDLE_STANDARD_ARGS (
  275. Sphinx
  276. REQUIRED_VARS
  277. ${_Sphinx_REQUIRED_VARS}
  278. # VERSION_VAR # This isn't available until CMake 2.8.8 so don't use it.
  279. Sphinx_VERSION_STRING
  280. )
  281. # ----------------------------------------------------------------------------
  282. # set Sphinx_DIR
  283. if (NOT Sphinx_DIR AND Sphinx-build_EXECUTABLE)
  284. get_filename_component (Sphinx_DIR "${Sphinx-build_EXECUTABLE}" PATH)
  285. string (REGEX REPLACE "/bin/?" "" Sphinx_DIR "${Sphinx_DIR}")
  286. set (Sphinx_DIR "${Sphinx_DIR}" CACHE PATH "Installation directory of Sphinx tools." FORCE)
  287. endif ()
  288. unset (_Sphinx_VERSION)
  289. unset (_Sphinx_REQUIRED_VARS)