FindLATEX.cmake 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindLATEX
  5. ---------
  6. Find LaTeX
  7. This module finds an installed LaTeX and determines the location
  8. of the compiler. Additionally the module looks for Latex-related
  9. software like BibTeX.
  10. This module sets the following result variables::
  11. LATEX_FOUND: whether found Latex and requested components
  12. LATEX_<component>_FOUND: whether found <component>
  13. LATEX_COMPILER: path to the LaTeX compiler
  14. PDFLATEX_COMPILER: path to the PdfLaTeX compiler
  15. XELATEX_COMPILER: path to the XeLaTeX compiler
  16. LUALATEX_COMPILER: path to the LuaLaTeX compiler
  17. BIBTEX_COMPILER: path to the BibTeX compiler
  18. BIBER_COMPILER: path to the Biber compiler
  19. MAKEINDEX_COMPILER: path to the MakeIndex compiler
  20. XINDY_COMPILER: path to the xindy compiler
  21. DVIPS_CONVERTER: path to the DVIPS converter
  22. DVIPDF_CONVERTER: path to the DVIPDF converter
  23. PS2PDF_CONVERTER: path to the PS2PDF converter
  24. PDFTOPS_CONVERTER: path to the pdftops converter
  25. LATEX2HTML_CONVERTER: path to the LaTeX2Html converter
  26. HTLATEX_COMPILER: path to the htlatex compiler
  27. Possible components are::
  28. PDFLATEX
  29. XELATEX
  30. LUALATEX
  31. BIBTEX
  32. BIBER
  33. MAKEINDEX
  34. XINDY
  35. DVIPS
  36. DVIPDF
  37. PS2PDF
  38. PDFTOPS
  39. LATEX2HTML
  40. HTLATEX
  41. Example Usages::
  42. find_package(LATEX)
  43. find_package(LATEX COMPONENTS PDFLATEX)
  44. find_package(LATEX COMPONENTS BIBTEX PS2PDF)
  45. #]=======================================================================]
  46. if (WIN32)
  47. # Try to find the MikTex binary path (look for its package manager).
  48. find_path(MIKTEX_BINARY_PATH mpm.exe
  49. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MiK\\MiKTeX\\CurrentVersion\\MiKTeX;Install Root]/miktex/bin"
  50. DOC
  51. "Path to the MikTex binary directory."
  52. )
  53. mark_as_advanced(MIKTEX_BINARY_PATH)
  54. # Try to find the GhostScript binary path (look for gswin32).
  55. get_filename_component(GHOSTSCRIPT_BINARY_PATH_FROM_REGISTERY_8_00
  56. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\AFPL Ghostscript\\8.00;GS_DLL]" PATH
  57. )
  58. get_filename_component(GHOSTSCRIPT_BINARY_PATH_FROM_REGISTERY_7_04
  59. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\AFPL Ghostscript\\7.04;GS_DLL]" PATH
  60. )
  61. find_path(GHOSTSCRIPT_BINARY_PATH gswin32.exe
  62. ${GHOSTSCRIPT_BINARY_PATH_FROM_REGISTERY_8_00}
  63. ${GHOSTSCRIPT_BINARY_PATH_FROM_REGISTERY_7_04}
  64. DOC "Path to the GhostScript binary directory."
  65. )
  66. mark_as_advanced(GHOSTSCRIPT_BINARY_PATH)
  67. find_path(GHOSTSCRIPT_LIBRARY_PATH ps2pdf13.bat
  68. "${GHOSTSCRIPT_BINARY_PATH}/../lib"
  69. DOC "Path to the GhostScript library directory."
  70. )
  71. mark_as_advanced(GHOSTSCRIPT_LIBRARY_PATH)
  72. endif ()
  73. # try to find Latex and the related programs
  74. find_program(LATEX_COMPILER
  75. NAMES latex
  76. PATHS ${MIKTEX_BINARY_PATH}
  77. /usr/bin
  78. )
  79. # find pdflatex
  80. find_program(PDFLATEX_COMPILER
  81. NAMES pdflatex
  82. PATHS ${MIKTEX_BINARY_PATH}
  83. /usr/bin
  84. )
  85. if (PDFLATEX_COMPILER)
  86. set(LATEX_PDFLATEX_FOUND TRUE)
  87. else()
  88. set(LATEX_PDFLATEX_FOUND FALSE)
  89. endif()
  90. # find xelatex
  91. find_program(XELATEX_COMPILER
  92. NAMES xelatex
  93. PATHS ${MIKTEX_BINARY_PATH}
  94. /usr/bin
  95. )
  96. if (XELATEX_COMPILER)
  97. set(LATEX_XELATEX_FOUND TRUE)
  98. else()
  99. set(LATEX_XELATEX_FOUND FALSE)
  100. endif()
  101. # find lualatex
  102. find_program(LUALATEX_COMPILER
  103. NAMES lualatex
  104. PATHS ${MIKTEX_BINARY_PATH}
  105. /usr/bin
  106. )
  107. if (LUALATEX_COMPILER)
  108. set(LATEX_LUALATEX_FOUND TRUE)
  109. else()
  110. set(LATEX_LUALATEX_FOUND FALSE)
  111. endif()
  112. # find bibtex
  113. find_program(BIBTEX_COMPILER
  114. NAMES bibtex
  115. PATHS ${MIKTEX_BINARY_PATH}
  116. /usr/bin
  117. )
  118. if (BIBTEX_COMPILER)
  119. set(LATEX_BIBTEX_FOUND TRUE)
  120. else()
  121. set(LATEX_BIBTEX_FOUND FALSE)
  122. endif()
  123. # find biber
  124. find_program(BIBER_COMPILER
  125. NAMES biber
  126. PATHS ${MIKTEX_BINARY_PATH}
  127. /usr/bin
  128. )
  129. if (BIBER_COMPILER)
  130. set(LATEX_BIBER_FOUND TRUE)
  131. else()
  132. set(LATEX_BIBER_FOUND FALSE)
  133. endif()
  134. # find makeindex
  135. find_program(MAKEINDEX_COMPILER
  136. NAMES makeindex
  137. PATHS ${MIKTEX_BINARY_PATH}
  138. /usr/bin
  139. )
  140. if (MAKEINDEX_COMPILER)
  141. set(LATEX_MAKEINDEX_FOUND TRUE)
  142. else()
  143. set(LATEX_MAKEINDEX_FOUND FALSE)
  144. endif()
  145. # find xindy
  146. find_program(XINDY_COMPILER
  147. NAMES xindy
  148. PATHS ${MIKTEX_BINARY_PATH}
  149. /usr/bin
  150. )
  151. if (XINDY_COMPILER)
  152. set(LATEX_XINDY_FOUND TRUE)
  153. else()
  154. set(LATEX_XINDY_FOUND FALSE)
  155. endif()
  156. # find dvips
  157. find_program(DVIPS_CONVERTER
  158. NAMES dvips
  159. PATHS ${MIKTEX_BINARY_PATH}
  160. /usr/bin
  161. )
  162. if (DVIPS_CONVERTER)
  163. set(LATEX_DVIPS_FOUND TRUE)
  164. else()
  165. set(LATEX_DVIPS_FOUND FALSE)
  166. endif()
  167. # find dvipdf
  168. find_program(DVIPDF_CONVERTER
  169. NAMES dvipdfm dvipdft dvipdf
  170. PATHS ${MIKTEX_BINARY_PATH}
  171. /usr/bin
  172. )
  173. if (DVIPDF_CONVERTER)
  174. set(LATEX_DVIPDF_FOUND TRUE)
  175. else()
  176. set(LATEX_DVIPDF_FOUND FALSE)
  177. endif()
  178. # find ps2pdf
  179. if (WIN32)
  180. find_program(PS2PDF_CONVERTER
  181. NAMES ps2pdf14.bat ps2pdf14 ps2pdf
  182. PATHS ${GHOSTSCRIPT_LIBRARY_PATH}
  183. ${MIKTEX_BINARY_PATH}
  184. )
  185. else ()
  186. find_program(PS2PDF_CONVERTER
  187. NAMES ps2pdf14 ps2pdf
  188. )
  189. endif ()
  190. if (PS2PDF_CONVERTER)
  191. set(LATEX_PS2PDF_FOUND TRUE)
  192. else()
  193. set(LATEX_PS2PDF_FOUND FALSE)
  194. endif()
  195. # find pdftops
  196. find_program(PDFTOPS_CONVERTER
  197. NAMES pdftops
  198. PATHS ${MIKTEX_BINARY_PATH}
  199. /usr/bin
  200. )
  201. if (PDFTOPS_CONVERTER)
  202. set(LATEX_PDFTOPS_FOUND TRUE)
  203. else()
  204. set(LATEX_PDFTOPS_FOUND FALSE)
  205. endif()
  206. # find latex2html
  207. find_program(LATEX2HTML_CONVERTER
  208. NAMES latex2html
  209. PATHS ${MIKTEX_BINARY_PATH}
  210. /usr/bin
  211. )
  212. if (LATEX2HTML_CONVERTER)
  213. set(LATEX_LATEX2HTML_FOUND TRUE)
  214. else()
  215. set(LATEX_LATEX2HTML_FOUND FALSE)
  216. endif()
  217. # find htlatex
  218. find_program(HTLATEX_COMPILER
  219. NAMES htlatex
  220. PATHS ${MIKTEX_BINARY_PATH}
  221. /usr/bin
  222. )
  223. if (HTLATEX_COMPILER)
  224. set(LATEX_HTLATEX_FOUND TRUE)
  225. else()
  226. set(LATEX_HTLATEX_FOUND FALSE)
  227. endif()
  228. mark_as_advanced(
  229. LATEX_COMPILER
  230. PDFLATEX_COMPILER
  231. XELATEX_COMPILER
  232. LUALATEX_COMPILER
  233. BIBTEX_COMPILER
  234. BIBER_COMPILER
  235. MAKEINDEX_COMPILER
  236. XINDY_COMPILER
  237. DVIPS_CONVERTER
  238. DVIPDF_CONVERTER
  239. PS2PDF_CONVERTER
  240. PDFTOPS_CONVERTER
  241. LATEX2HTML_CONVERTER
  242. HTLATEX_COMPILER
  243. )
  244. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  245. find_package_handle_standard_args(LATEX
  246. REQUIRED_VARS LATEX_COMPILER
  247. HANDLE_COMPONENTS
  248. )