FindLATEX.cmake 6.7 KB
Newer Older
1 2 3 4 5 6
#.rst:
# FindLATEX
# ---------
#
# Find Latex
#
7 8
# This module finds an installed Latex and determines the location
# of the compiler.  Additionally the module looks for Latex-related
9
# software like BibTeX.
10
#
11
# This module sets the following result variables::
12
#
13 14
#   LATEX_FOUND:          whether found Latex and requested components
#   LATEX_<component>_FOUND:  whether found <component>
15 16
#   LATEX_COMPILER:       path to the LaTeX compiler
#   PDFLATEX_COMPILER:    path to the PdfLaTeX compiler
17 18
#   XELATEX_COMPILER:     path to the XeLaTeX compiler
#   LUALATEX_COMPILER:    path to the LuaLaTeX compiler
19
#   BIBTEX_COMPILER:      path to the BibTeX compiler
20
#   BIBER_COMPILER:       path to the Biber compiler
21
#   MAKEINDEX_COMPILER:   path to the MakeIndex compiler
22
#   XINDY_COMPILER:       path to the xindy compiler
23
#   DVIPS_CONVERTER:      path to the DVIPS converter
24
#   DVIPDF_CONVERTER:     path to the DVIPDF converter
25
#   PS2PDF_CONVERTER:     path to the PS2PDF converter
26
#   PDFTOPS_CONVERTER:    path to the pdftops converter
27
#   LATEX2HTML_CONVERTER: path to the LaTeX2Html converter
28
#   HTLATEX_COMPILER:     path to the htlatex compiler
29 30 31 32
#
# Possible components are::
#
#   PDFLATEX
33 34
#   XELATEX
#   LUALATEX
35
#   BIBTEX
36
#   BIBER
37
#   MAKEINDEX
38
#   XINDY
39 40 41
#   DVIPS
#   DVIPDF
#   PS2PDF
42
#   PDFTOPS
43
#   LATEX2HTML
44
#   HTLATEX
45 46 47 48 49 50
#
# Example Usages::
#
#   find_package(LATEX)
#   find_package(LATEX COMPONENTS PDFLATEX)
#   find_package(LATEX COMPONENTS BIBTEX PS2PDF)
51

52
#=============================================================================
53 54
# Copyright 2002-2015 Kitware, Inc.
# Copyright 2014-2015 Christoph Grüninger <foss@grueninger.de>
55 56 57 58 59 60 61 62
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
63
# (To distribute this file outside of CMake, substitute the full
64 65
#  License text for the above reference.)

66
if (WIN32)
Sebastien Barre's avatar
Sebastien Barre committed
67
  # Try to find the MikTex binary path (look for its package manager).
68
  find_path(MIKTEX_BINARY_PATH mpm.exe
Sebastien Barre's avatar
Sebastien Barre committed
69
    "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MiK\\MiKTeX\\CurrentVersion\\MiKTeX;Install Root]/miktex/bin"
70
    DOC
Sebastien Barre's avatar
Sebastien Barre committed
71 72
    "Path to the MikTex binary directory."
  )
73
  mark_as_advanced(MIKTEX_BINARY_PATH)
Sebastien Barre's avatar
Sebastien Barre committed
74 75

  # Try to find the GhostScript binary path (look for gswin32).
76
  get_filename_component(GHOSTSCRIPT_BINARY_PATH_FROM_REGISTERY_8_00
Sebastien Barre's avatar
Sebastien Barre committed
77 78 79
     "[HKEY_LOCAL_MACHINE\\SOFTWARE\\AFPL Ghostscript\\8.00;GS_DLL]" PATH
  )

80
  get_filename_component(GHOSTSCRIPT_BINARY_PATH_FROM_REGISTERY_7_04
Sebastien Barre's avatar
Sebastien Barre committed
81 82 83
     "[HKEY_LOCAL_MACHINE\\SOFTWARE\\AFPL Ghostscript\\7.04;GS_DLL]" PATH
  )

84
  find_path(GHOSTSCRIPT_BINARY_PATH gswin32.exe
Sebastien Barre's avatar
Sebastien Barre committed
85 86 87 88
    ${GHOSTSCRIPT_BINARY_PATH_FROM_REGISTERY_8_00}
    ${GHOSTSCRIPT_BINARY_PATH_FROM_REGISTERY_7_04}
    DOC "Path to the GhostScript binary directory."
  )
89
  mark_as_advanced(GHOSTSCRIPT_BINARY_PATH)
Sebastien Barre's avatar
Sebastien Barre committed
90

91
  find_path(GHOSTSCRIPT_LIBRARY_PATH ps2pdf13.bat
Sebastien Barre's avatar
Sebastien Barre committed
92 93 94
    "${GHOSTSCRIPT_BINARY_PATH}/../lib"
    DOC "Path to the GhostScript library directory."
  )
95
  mark_as_advanced(GHOSTSCRIPT_LIBRARY_PATH)
96
endif ()
Sebastien Barre's avatar
Sebastien Barre committed
97

98
# try to find Latex and the related programs
99
find_program(LATEX_COMPILER
100
  NAMES latex
Sebastien Barre's avatar
Sebastien Barre committed
101
  PATHS ${MIKTEX_BINARY_PATH}
102
        /usr/bin
103 104
)

105
# find pdflatex
106
find_program(PDFLATEX_COMPILER
107 108 109 110
  NAMES pdflatex
  PATHS ${MIKTEX_BINARY_PATH}
        /usr/bin
)
111 112 113 114 115
if (PDFLATEX_COMPILER)
  set(LATEX_PDFLATEX_FOUND TRUE)
else()
  set(LATEX_PDFLATEX_FOUND FALSE)
endif()
116

117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
# find xelatex
find_program(XELATEX_COMPILER
  NAMES xelatex
  PATHS ${MIKTEX_BINARY_PATH}
        /usr/bin
)
if (XELATEX_COMPILER)
  set(LATEX_XELATEX_FOUND TRUE)
else()
  set(LATEX_XELATEX_FOUND FALSE)
endif()

# find lualatex
find_program(LUALATEX_COMPILER
  NAMES lualatex
  PATHS ${MIKTEX_BINARY_PATH}
        /usr/bin
)
if (LUALATEX_COMPILER)
  set(LATEX_LUALATEX_FOUND TRUE)
else()
  set(LATEX_LUALATEX_FOUND FALSE)
endif()

141
# find bibtex
142
find_program(BIBTEX_COMPILER
143
  NAMES bibtex
Sebastien Barre's avatar
Sebastien Barre committed
144
  PATHS ${MIKTEX_BINARY_PATH}
145
        /usr/bin
146
)
147 148 149 150 151
if (BIBTEX_COMPILER)
  set(LATEX_BIBTEX_FOUND TRUE)
else()
  set(LATEX_BIBTEX_FOUND FALSE)
endif()
152

153 154 155 156 157 158 159 160 161 162 163 164
# find biber
find_program(BIBER_COMPILER
  NAMES biber
  PATHS ${MIKTEX_BINARY_PATH}
        /usr/bin
)
if (BIBER_COMPILER)
  set(LATEX_BIBER_FOUND TRUE)
else()
  set(LATEX_BIBER_FOUND FALSE)
endif()

165
# find makeindex
166
find_program(MAKEINDEX_COMPILER
Sebastien Barre's avatar
Sebastien Barre committed
167 168
  NAMES makeindex
  PATHS ${MIKTEX_BINARY_PATH}
169
        /usr/bin
170
)
171 172 173 174 175
if (MAKEINDEX_COMPILER)
  set(LATEX_MAKEINDEX_FOUND TRUE)
else()
  set(LATEX_MAKEINDEX_FOUND FALSE)
endif()
176

177 178 179 180 181 182 183 184 185 186 187 188
# find xindy
find_program(XINDY_COMPILER
  NAMES xindy
  PATHS ${MIKTEX_BINARY_PATH}
        /usr/bin
)
if (XINDY_COMPILER)
   set(LATEX_XINDY_FOUND TRUE)
else()
  set(LATEX_XINDY_FOUND FALSE)
endif()

189
# find dvips
190
find_program(DVIPS_CONVERTER
191
  NAMES dvips
Sebastien Barre's avatar
Sebastien Barre committed
192
  PATHS ${MIKTEX_BINARY_PATH}
193 194
        /usr/bin
)
195 196 197 198 199
if (DVIPS_CONVERTER)
  set(LATEX_DVIPS_FOUND TRUE)
else()
  set(LATEX_DVIPS_FOUND FALSE)
endif()
200

201
# find dvipdf
202
find_program(DVIPDF_CONVERTER
203 204 205
  NAMES dvipdfm dvipdft dvipdf
  PATHS ${MIKTEX_BINARY_PATH}
        /usr/bin
206
)
207 208 209 210 211
if (DVIPDF_CONVERTER)
  set(LATEX_DVIPDF_FOUND TRUE)
else()
  set(LATEX_DVIPDF_FOUND FALSE)
endif()
212

213
# find ps2pdf
214 215
if (WIN32)
  find_program(PS2PDF_CONVERTER
216
    NAMES ps2pdf14.bat ps2pdf14 ps2pdf
Sebastien Barre's avatar
Sebastien Barre committed
217
    PATHS ${GHOSTSCRIPT_LIBRARY_PATH}
218
          ${MIKTEX_BINARY_PATH}
Sebastien Barre's avatar
Sebastien Barre committed
219
  )
220
else ()
221
  find_program(PS2PDF_CONVERTER
222
    NAMES ps2pdf14 ps2pdf
Sebastien Barre's avatar
Sebastien Barre committed
223
  )
224
endif ()
225 226 227 228 229
if (PS2PDF_CONVERTER)
  set(LATEX_PS2PDF_FOUND TRUE)
else()
  set(LATEX_PS2PDF_FOUND FALSE)
endif()
230

231 232 233 234 235 236 237 238 239 240 241 242
# find pdftops
find_program(PDFTOPS_CONVERTER
  NAMES pdftops
  PATHS ${MIKTEX_BINARY_PATH}
        /usr/bin
)
if (PDFTOPS_CONVERTER)
  set(LATEX_PDFTOPS_FOUND TRUE)
else()
  set(LATEX_PDFTOPS_FOUND FALSE)
endif()

243
# find latex2html
244
find_program(LATEX2HTML_CONVERTER
245 246 247 248
  NAMES latex2html
  PATHS ${MIKTEX_BINARY_PATH}
        /usr/bin
)
249 250 251 252 253
if (LATEX2HTML_CONVERTER)
  set(LATEX_LATEX2HTML_FOUND TRUE)
else()
  set(LATEX_LATEX2HTML_FOUND FALSE)
endif()
254

255 256 257 258 259 260 261 262 263 264 265 266
# find htlatex
find_program(HTLATEX_COMPILER
  NAMES htlatex
  PATHS ${MIKTEX_BINARY_PATH}
        /usr/bin
)
if (HTLATEX_COMPILER)
  set(LATEX_HTLATEX_FOUND TRUE)
else()
  set(LATEX_HTLATEX_FOUND FALSE)
endif()

267

268
mark_as_advanced(
Sebastien Barre's avatar
Sebastien Barre committed
269
  LATEX_COMPILER
270
  PDFLATEX_COMPILER
271 272
  XELATEX_COMPILER
  LUALATEX_COMPILER
Sebastien Barre's avatar
Sebastien Barre committed
273
  BIBTEX_COMPILER
274
  BIBER_COMPILER
Sebastien Barre's avatar
Sebastien Barre committed
275
  MAKEINDEX_COMPILER
276
  XINDY_COMPILER
Sebastien Barre's avatar
Sebastien Barre committed
277
  DVIPS_CONVERTER
278
  DVIPDF_CONVERTER
Sebastien Barre's avatar
Sebastien Barre committed
279
  PS2PDF_CONVERTER
280
  PDFTOPS_CONVERTER
281
  LATEX2HTML_CONVERTER
282
  HTLATEX_COMPILER
Sebastien Barre's avatar
Sebastien Barre committed
283
)
284

285
# handle variables for found Latex and its components
286
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
287
find_package_handle_standard_args(LATEX
288
  REQUIRED_VARS LATEX_COMPILER
289
  HANDLE_COMPONENTS
290
)