2 # CMAKE commands to actually use the LaTeX compiler
4 # Author: Kenneth Moreland (kmorel at sandia dot gov)
6 # Copyright 2004 Sandia Corporation.
7 # Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 # license for use of this work by or on behalf of the
9 # U.S. Government. Redistribution and use in source and binary forms, with
10 # or without modification, are permitted provided that this Notice and any
11 # statement of authorship are reproduced on all copies.
13 # The following MACROS are defined:
15 # ADD_LATEX_DOCUMENT(<tex_file>
16 # [BIBFILES <bib_files>]
17 # [INPUTS <input_tex_files>]
18 # [IMAGE_DIRS] <image_directories>
19 # [IMAGES] <image_files>
20 # [CONFIGURE] <tex_files>
21 # [DEPENDS] <tex_files>
22 # [USE_INDEX] [USE_GLOSSARY] [USE_NOMENCL]
23 # [DEFAULT_PDF] [DEFAULT_SAFEPDF]
24 # [MANGLE_TARGET_NAMES])
25 # Adds targets that compile <tex_file>. The latex output is placed
26 # in LATEX_OUTPUT_PATH or CMAKE_CURRENT_BINARY_DIR if the former is
27 # not set. The latex program is picky about where files are located,
28 # so all input files are copied from the source directory to the
29 # output directory. This includes the target tex file, any tex file
30 # listed with the INPUTS option, the bibliography files listed with
31 # the BIBFILES option, and any .cls, .bst, and .clo files found in
32 # the current source directory. Images found in the IMAGE_DIRS
33 # directories or listed by IMAGES are also copied to the output
34 # directory and coverted to an appropriate format if necessary. Any
35 # tex files also listed with the CONFIGURE option are also processed
36 # with the CMake CONFIGURE_FILE command (with the @ONLY flag. Any
37 # file listed in CONFIGURE but not the target tex file or listed with
38 # INPUTS has no effect. DEPENDS can be used to specify generated files
39 # that are needed to compile the latex target.
41 # The following targets are made:
42 # dvi: Makes <name>.dvi
43 # pdf: Makes <name>.pdf using pdflatex.
44 # safepdf: Makes <name>.pdf using ps2pdf. If using the default
45 # program arguments, this will ensure all fonts are
46 # embedded and no lossy compression has been performed
49 # html: Makes <name>.html
50 # auxclean: Deletes <name>.aux and other auxiliary files.
51 # This is sometimes necessary if a LaTeX error occurs
52 # and writes a bad aux file. Unlike the regular clean
53 # target, it does not delete other input files, such as
54 # converted images, to save time on the rebuild.
56 # The dvi target is added to the ALL. That is, it will be the target
57 # built by default. If the DEFAULT_PDF argument is given, then the
58 # pdf target will be the default instead of dvi.
60 # If the argument MANGLE_TARGET_NAMES is given, then each of the
61 # target names above will be mangled with the <tex_file> name. This
62 # is to make the targets unique if ADD_LATEX_DOCUMENT is called for
63 # multiple documents. If the argument USE_INDEX is given, then
64 # commands to build an index are made. If the argument USE_GLOSSARY
65 # is given, then commands to build a glossary are made.
69 # 1.8.1 Fix problem where ps2pdf was not getting the appropriate arguments.
71 # 1.8.0 Add support for synctex.
73 # 1.7.7 Support calling xindy when making glossaries.
75 # Improved make clean support.
77 # 1.7.6 Add support for the nomencl package (thanks to Myles English).
79 # 1.7.5 Fix issue with bibfiles being copied two different ways, which causes
80 # Problems with dependencies (thanks to Edwin van Leeuwen).
82 # 1.7.4 Added the DEFAULT_SAFEPDF option (thanks to Raymond Wan).
84 # Added warnings when image directories are not found (and were
85 # probably not given relative to the source directory).
87 # 1.7.3 Fix some issues with interactions between makeglossaries and bibtex
88 # (thanks to Mark de Wever).
90 # 1.7.2 Use ps2pdf to convert eps to pdf to get around the problem with
91 # ImageMagick dropping the bounding box (thanks to Lukasz Lis).
93 # 1.7.1 Fixed some dependency issues.
95 # 1.7.0 Added DEPENDS options (thanks to Theodore Papadopoulo).
97 # 1.6.1 Ported the makeglossaries command to CMake and embedded the port
98 # into UseLATEX.cmake.
100 # 1.6.0 Allow the use of the makeglossaries command. Thanks to Oystein
101 # S. Haaland for the patch.
103 # 1.5.0 Allow any type of file in the INPUTS lists, not just tex file
104 # (suggested by Eric Noulard). As a consequence, the ability to
105 # specify tex files without the .tex extension is removed. The removed
106 # function is of dubious value anyway.
108 # When copying input files, skip over any file that exists in the
109 # binary directory but does not exist in the source directory with the
110 # assumption that these files were added by some other mechanism. I
111 # find this useful when creating large documents with multiple
112 # chapters that I want to build separately (for speed) as I work on
113 # them. I use the same boilerplate as the starting point for all
114 # and just copy it with different configurations. This was what the
115 # separate ADD_LATEX_DOCUMENT method was supposed to originally be for.
116 # Since its external use is pretty much deprecated, I removed that
119 # 1.4.1 Copy .sty files along with the other class and package files.
121 # 1.4.0 Added a MANGLE_TARGET_NAMES option that will mangle the target names.
123 # Fixed problem with copying bib files that became apparent with
126 # 1.3.0 Added a LATEX_OUTPUT_PATH variable that allows you or the user to
127 # specify where the built latex documents to go. This is especially
128 # handy if you want to do in-source builds.
130 # Removed the ADD_LATEX_IMAGES macro and absorbed the functionality
131 # into ADD_LATEX_DOCUMENT. The old interface was always kind of
132 # clunky anyway since you had to specify the image directory in both
133 # places. It also made supporting LATEX_OUTPUT_PATH problematic.
135 # Added support for jpeg files.
137 # 1.2.0 Changed the configuration options yet again. Removed the NO_CONFIGURE
138 # Replaced it with a CONFIGURE option that lists input files for which
139 # configure should be run.
141 # The pdf target no longer depends on the dvi target. This allows you
142 # to build latex documents that require pdflatex. Also added an option
143 # to make the pdf target the default one.
145 # 1.1.1 Added the NO_CONFIGURE option. The @ character can be used when
146 # specifying table column separators. If two or more are used, then
147 # will incorrectly substitute them.
149 # 1.1.0 Added ability include multiple bib files. Added ability to do copy
150 # sub-tex files for multipart tex files.
152 # 1.0.0 If both ps and pdf type images exist, just copy the one that
153 # matches the current render mode. Replaced a bunch of STRING
154 # commands with GET_FILENAME_COMPONENT commands that were made to do
155 # the desired function.
157 # 0.4.0 First version posted to CMake Wiki.
160 #############################################################################
161 # Find the location of myself while originally executing. If you do this
162 # inside of a macro, it will recode where the macro was invoked.
163 #############################################################################
164 SET(LATEX_USE_LATEX_LOCATION ${CMAKE_CURRENT_LIST_FILE}
165 CACHE INTERNAL "Location of UseLATEX.cmake file." FORCE
168 #############################################################################
169 # Generic helper macros
170 #############################################################################
172 # Helpful list macros.
176 MACRO(LATEX_CDR var junk)
180 MACRO(LATEX_LIST_CONTAINS var value)
182 FOREACH (value2 ${ARGN})
183 IF (${value} STREQUAL ${value2})
185 ENDIF (${value} STREQUAL ${value2})
187 ENDMACRO(LATEX_LIST_CONTAINS)
189 # Parse macro arguments.
190 MACRO(LATEX_PARSE_ARGUMENTS prefix arg_names option_names)
192 FOREACH(arg_name ${arg_names})
193 SET(${prefix}_${arg_name})
195 FOREACH(option ${option_names})
196 SET(${prefix}_${option})
199 SET(current_arg_name DEFAULT_ARGS)
200 SET(current_arg_list)
202 LATEX_LIST_CONTAINS(is_arg_name ${arg} ${arg_names})
204 SET(${prefix}_${current_arg_name} ${current_arg_list})
205 SET(current_arg_name ${arg})
206 SET(current_arg_list)
208 LATEX_LIST_CONTAINS(is_option ${arg} ${option_names})
210 SET(${prefix}_${arg} TRUE)
212 SET(current_arg_list ${current_arg_list} ${arg})
216 SET(${prefix}_${current_arg_name} ${current_arg_list})
217 ENDMACRO(LATEX_PARSE_ARGUMENTS)
219 # Match the contents of a file to a regular expression.
220 MACRO(LATEX_FILE_MATCH variable filename regexp default)
221 # The FILE STRINGS command would be a bit better, but it's not supported on
222 # older versions of CMake.
223 FILE(READ ${filename} file_contents)
224 STRING(REGEX MATCHALL "${regexp}"
225 ${variable} ${file_contents}
228 SET(${variable} "${default}")
229 ENDIF (NOT ${variable})
230 ENDMACRO(LATEX_FILE_MATCH)
232 #############################################################################
233 # Macros that perform processing during a LaTeX build.
234 #############################################################################
235 MACRO(LATEX_MAKEGLOSSARIES)
236 # This is really a bare bones port of the makeglossaries perl script into
238 MESSAGE("**************************** In makeglossaries")
239 IF (NOT LATEX_TARGET)
240 MESSAGE(SEND_ERROR "Need to define LATEX_TARGET")
241 ENDIF (NOT LATEX_TARGET)
243 SET(aux_file ${LATEX_TARGET}.aux)
245 IF (NOT EXISTS ${aux_file})
246 MESSAGE(SEND_ERROR "${aux_file} does not exist. Run latex on your target file.")
247 ENDIF (NOT EXISTS ${aux_file})
249 LATEX_FILE_MATCH(newglossary_lines ${aux_file}
250 "@newglossary[ \t]*{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}"
251 "@newglossary{main}{glg}{gls}{glo}"
254 LATEX_FILE_MATCH(istfile_line ${aux_file}
255 "@istfilename[ \t]*{([^}]*)}"
256 "@istfilename{${LATEX_TARGET}.ist}"
258 STRING(REGEX REPLACE "@istfilename[ \t]*{([^}]*)}" "\\1"
259 istfile ${istfile_line}
262 STRING(REGEX MATCH ".*\\.xdy" use_xindy "${istfile}")
264 MESSAGE("*************** Using xindy")
265 IF (NOT XINDY_COMPILER)
266 MESSAGE(SEND_ERROR "Need to define XINDY_COMPILER")
267 ENDIF (NOT XINDY_COMPILER)
269 MESSAGE("*************** Using makeindex")
270 IF (NOT MAKEINDEX_COMPILER)
271 MESSAGE(SEND_ERROR "Need to define MAKEINDEX_COMPILER")
272 ENDIF (NOT MAKEINDEX_COMPILER)
275 FOREACH(newglossary ${newglossary_lines})
277 "@newglossary[ \t]*{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}"
278 "\\1" glossary_name ${newglossary}
281 "@newglossary[ \t]*{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}"
282 "${LATEX_TARGET}.\\2" glossary_log ${newglossary}
285 "@newglossary[ \t]*{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}"
286 "${LATEX_TARGET}.\\3" glossary_out ${newglossary}
289 "@newglossary[ \t]*{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}"
290 "${LATEX_TARGET}.\\4" glossary_in ${newglossary}
294 LATEX_FILE_MATCH(xdylanguage_line ${aux_file}
295 "@xdylanguage[ \t]*{${glossary_name}}{([^}]*)}"
296 "@xdylanguage{${glossary_name}}{english}"
299 "@xdylanguage[ \t]*{${glossary_name}}{([^}]*)}"
304 # What crazy person makes a LaTeX index generater that uses different
305 # identifiers for language than babel (or at least does not support
307 IF (${language} STREQUAL "frenchb")
308 SET(language "french")
309 ELSEIF (${language} MATCHES "^n?germanb?$")
310 SET(language "german")
311 ELSEIF (${language} STREQUAL "magyar")
312 SET(language "hungarian")
313 ELSEIF (${language} STREQUAL "lsorbian")
314 SET(language "lower-sorbian")
315 ELSEIF (${language} STREQUAL "norsk")
316 SET(language "norwegian")
317 ELSEIF (${language} STREQUAL "portuges")
318 SET(language "portuguese")
319 ELSEIF (${language} STREQUAL "russianb")
320 SET(language "russian")
321 ELSEIF (${language} STREQUAL "slovene")
322 SET(language "slovenian")
323 ELSEIF (${language} STREQUAL "ukraineb")
324 SET(language "ukrainian")
325 ELSEIF (${language} STREQUAL "usorbian")
326 SET(language "upper-sorbian")
327 ENDIF (${language} STREQUAL "frenchb")
329 SET(language_flags "-L ${language}")
331 SET(language_flags "")
334 LATEX_FILE_MATCH(codepage_line ${aux_file}
335 "@gls@codepage[ \t]*{${glossary_name}}{([^}]*)}"
336 "@gls@codepage{${glossary_name}}{utf}"
339 "@gls@codepage[ \t]*{${glossary_name}}{([^}]*)}"
345 SET(codepage_flags "-C ${codepage}")
347 # Ideally, we would check that the language is compatible with the
348 # default codepage, but I'm hoping that distributions will be smart
349 # enough to specify their own codepage. I know, it's asking a lot.
350 SET(codepage_flags "")
353 MESSAGE("${XINDY_COMPILER} ${MAKEGLOSSARIES_COMPILER_FLAGS} ${language_flags} ${codepage_flags} -I xindy -M ${glossary_name} -t ${glossary_log} -o ${glossary_out} ${glossary_in}"
355 EXEC_PROGRAM(${XINDY_COMPILER}
356 ARGS ${MAKEGLOSSARIES_COMPILER_FLAGS}
364 OUTPUT_VARIABLE xindy_output
366 MESSAGE("${xindy_output}")
368 # So, it is possible (perhaps common?) for aux files to specify a
369 # language and codepage that are incompatible with each other. Check
370 # for that condition, and if it happens run again with the default
372 IF ("${xindy_output}" MATCHES "^Cannot locate xindy module for language (.+) in codepage (.+)\\.$")
373 MESSAGE("*************** Retrying xindy with default codepage.")
374 EXEC_PROGRAM(${XINDY_COMPILER}
375 ARGS ${MAKEGLOSSARIES_COMPILER_FLAGS}
383 ENDIF ("${xindy_output}" MATCHES "^Cannot locate xindy module for language (.+) in codepage (.+)\\.$")
384 #ENDIF ("${xindy_output}" MATCHES "Cannot locate xindy module for language (.+) in codepage (.+)\\.")
387 MESSAGE("${MAKEINDEX_COMPILER} ${MAKEGLOSSARIES_COMPILER_FLAGS} -s ${istfile} -t ${glossary_log} -o ${glossary_out} ${glossary_in}")
388 EXEC_PROGRAM(${MAKEINDEX_COMPILER} ARGS ${MAKEGLOSSARIES_COMPILER_FLAGS}
389 -s ${istfile} -t ${glossary_log} -o ${glossary_out} ${glossary_in}
393 ENDFOREACH(newglossary)
394 ENDMACRO(LATEX_MAKEGLOSSARIES)
396 MACRO(LATEX_MAKENOMENCLATURE)
397 MESSAGE("**************************** In makenomenclature")
398 IF (NOT LATEX_TARGET)
399 MESSAGE(SEND_ERROR "Need to define LATEX_TARGET")
400 ENDIF (NOT LATEX_TARGET)
402 IF (NOT MAKEINDEX_COMPILER)
403 MESSAGE(SEND_ERROR "Need to define MAKEINDEX_COMPILER")
404 ENDIF (NOT MAKEINDEX_COMPILER)
406 SET(nomencl_out ${LATEX_TARGET}.nls)
407 SET(nomencl_in ${LATEX_TARGET}.nlo)
409 EXEC_PROGRAM(${MAKEINDEX_COMPILER} ARGS ${MAKENOMENCLATURE_COMPILER_FLAGS}
410 ${nomencl_in} -s "nomencl.ist" -o ${nomencl_out}
412 ENDMACRO(LATEX_MAKENOMENCLATURE)
414 MACRO(LATEX_CORRECT_SYNCTEX)
415 MESSAGE("**************************** In correct SyncTeX")
416 IF (NOT LATEX_TARGET)
417 MESSAGE(SEND_ERROR "Need to define LATEX_TARGET")
418 ENDIF (NOT LATEX_TARGET)
421 MESSAGE(SEND_ERROR "Need to define GZIP")
424 IF (NOT LATEX_SOURCE_DIRECTORY)
425 MESSAGE(SEND_ERROR "Need to define LATEX_SOURCE_DIRECTORY")
426 ENDIF (NOT LATEX_SOURCE_DIRECTORY)
428 IF (NOT LATEX_BINARY_DIRECTORY)
429 MESSAGE(SEND_ERROR "Need to define LATEX_BINARY_DIRECTORY")
430 ENDIF (NOT LATEX_BINARY_DIRECTORY)
432 SET(synctex_file ${LATEX_BINARY_DIRECTORY}/${LATEX_TARGET}.synctex)
433 SET(synctex_file_gz ${synctex_file}.gz)
435 IF (EXISTS ${synctex_file_gz})
437 MESSAGE("Making backup of synctex file.")
438 CONFIGURE_FILE(${synctex_file_gz} ${synctex_file}.bak.gz COPYONLY)
440 MESSAGE("Uncompressing synctex file.")
442 ARGS --decompress ${synctex_file_gz}
445 MESSAGE("Reading synctex file.")
446 FILE(READ ${synctex_file} synctex_data)
448 MESSAGE("Replacing relative with absolute paths.")
450 "(Input:[0-9]+:)([^/\n][^\n]*)"
451 "\\1${LATEX_SOURCE_DIRECTORY}/\\2"
456 MESSAGE("Writing synctex file.")
457 FILE(WRITE ${synctex_file} "${synctex_data}")
459 MESSAGE("Compressing synctex file.")
464 ELSE (EXISTS ${synctex_file_gz})
466 MESSAGE(SEND_ERROR "File ${synctex_file_gz} not found. Perhaps synctex is not supported by your LaTeX compiler.")
468 ENDIF (EXISTS ${synctex_file_gz})
470 ENDMACRO(LATEX_CORRECT_SYNCTEX)
472 #############################################################################
473 # Helper macros for establishing LaTeX build.
474 #############################################################################
476 MACRO(LATEX_NEEDIT VAR NAME)
478 MESSAGE(SEND_ERROR "I need the ${NAME} command.")
480 ENDMACRO(LATEX_NEEDIT)
482 MACRO(LATEX_WANTIT VAR NAME)
484 MESSAGE(STATUS "I could not find the ${NAME} command.")
486 ENDMACRO(LATEX_WANTIT)
488 MACRO(LATEX_SETUP_VARIABLES)
489 SET(LATEX_OUTPUT_PATH "${LATEX_OUTPUT_PATH}"
490 CACHE PATH "If non empty, specifies the location to place LaTeX output."
495 FIND_PROGRAM(XINDY_COMPILER
497 PATHS ${MIKTEX_BINARY_PATH} /usr/bin
500 FIND_PACKAGE(UnixCommands)
502 MARK_AS_ADVANCED(CLEAR
513 LATEX_NEEDIT(LATEX_COMPILER latex)
514 LATEX_WANTIT(PDFLATEX_COMPILER pdflatex)
515 LATEX_NEEDIT(BIBTEX_COMPILER bibtex)
516 LATEX_NEEDIT(MAKEINDEX_COMPILER makeindex)
517 LATEX_WANTIT(DVIPS_CONVERTER dvips)
518 LATEX_WANTIT(PS2PDF_CONVERTER ps2pdf)
519 LATEX_WANTIT(LATEX2HTML_CONVERTER latex2html)
521 SET(LATEX_COMPILER_FLAGS "-interaction=nonstopmode"
522 CACHE STRING "Flags passed to latex.")
523 SET(PDFLATEX_COMPILER_FLAGS ${LATEX_COMPILER_FLAGS}
524 CACHE STRING "Flags passed to pdflatex.")
525 SET(LATEX_SYNCTEX_FLAGS "-synctex=1"
526 CACHE STRING "latex/pdflatex flags used to create synctex file.")
527 SET(BIBTEX_COMPILER_FLAGS ""
528 CACHE STRING "Flags passed to bibtex.")
529 SET(MAKEINDEX_COMPILER_FLAGS ""
530 CACHE STRING "Flags passed to makeindex.")
531 SET(MAKEGLOSSARIES_COMPILER_FLAGS ""
532 CACHE STRING "Flags passed to makeglossaries.")
533 SET(MAKENOMENCLATURE_COMPILER_FLAGS ""
534 CACHE STRING "Flags passed to makenomenclature.")
535 SET(DVIPS_CONVERTER_FLAGS "-Ppdf -G0 -t letter"
536 CACHE STRING "Flags passed to dvips.")
537 SET(PS2PDF_CONVERTER_FLAGS "-dMaxSubsetPct=100 -dCompatibilityLevel=1.3 -dSubsetFonts=true -dEmbedAllFonts=true -dAutoFilterColorImages=false -dAutoFilterGrayImages=false -dColorImageFilter=/FlateEncode -dGrayImageFilter=/FlateEncode -dMonoImageFilter=/FlateEncode"
538 CACHE STRING "Flags passed to ps2pdf.")
539 SET(LATEX2HTML_CONVERTER_FLAGS ""
540 CACHE STRING "Flags passed to latex2html.")
543 PDFLATEX_COMPILER_FLAGS
545 BIBTEX_COMPILER_FLAGS
546 MAKEINDEX_COMPILER_FLAGS
547 MAKEGLOSSARIES_COMPILER_FLAGS
548 MAKENOMENCLATURE_COMPILER_FLAGS
549 DVIPS_CONVERTER_FLAGS
550 PS2PDF_CONVERTER_FLAGS
551 LATEX2HTML_CONVERTER_FLAGS
553 SEPARATE_ARGUMENTS(LATEX_COMPILER_FLAGS)
554 SEPARATE_ARGUMENTS(PDFLATEX_COMPILER_FLAGS)
555 SEPARATE_ARGUMENTS(LATEX_SYNCTEX_FLAGS)
556 SEPARATE_ARGUMENTS(BIBTEX_COMPILER_FLAGS)
557 SEPARATE_ARGUMENTS(MAKEINDEX_COMPILER_FLAGS)
558 SEPARATE_ARGUMENTS(MAKEGLOSSARIES_COMPILER_FLAGS)
559 SEPARATE_ARGUMENTS(MAKENOMENCLATURE_COMPILER_FLAGS)
560 SEPARATE_ARGUMENTS(DVIPS_CONVERTER_FLAGS)
561 SEPARATE_ARGUMENTS(PS2PDF_CONVERTER_FLAGS)
562 SEPARATE_ARGUMENTS(LATEX2HTML_CONVERTER_FLAGS)
564 OPTION(LATEX_SMALL_IMAGES
565 "If on, the raster images will be converted to 1/6 the original size. This is because papers usually require 600 dpi images whereas most monitors only require at most 96 dpi. Thus, smaller images make smaller files for web distributation and can make it faster to read dvi files."
567 IF (LATEX_SMALL_IMAGES)
568 SET(LATEX_RASTER_SCALE 16)
569 SET(LATEX_OPPOSITE_RASTER_SCALE 100)
570 ELSE (LATEX_SMALL_IMAGES)
571 SET(LATEX_RASTER_SCALE 100)
572 SET(LATEX_OPPOSITE_RASTER_SCALE 16)
573 ENDIF (LATEX_SMALL_IMAGES)
575 # Just holds extensions for known image types. They should all be lower case.
576 SET(LATEX_DVI_VECTOR_IMAGE_EXTENSIONS .eps)
577 SET(LATEX_DVI_RASTER_IMAGE_EXTENSIONS)
578 SET(LATEX_DVI_IMAGE_EXTENSIONS
579 ${LATEX_DVI_VECTOR_IMAGE_EXTENSIONS} ${LATEX_DVI_RASTER_IMAGE_EXTENSIONS})
580 SET(LATEX_PDF_VECTOR_IMAGE_EXTENSIONS .pdf)
581 SET(LATEX_PDF_RASTER_IMAGE_EXTENSIONS .png .jpeg .jpg)
582 SET(LATEX_PDF_IMAGE_EXTENSIONS
583 ${LATEX_PDF_VECTOR_IMAGE_EXTENSIONS} ${LATEX_PDF_RASTER_IMAGE_EXTENSIONS})
584 SET(LATEX_IMAGE_EXTENSIONS
585 ${LATEX_DVI_IMAGE_EXTENSIONS} ${LATEX_PDF_IMAGE_EXTENSIONS})
586 ENDMACRO(LATEX_SETUP_VARIABLES)
588 MACRO(LATEX_GET_OUTPUT_PATH var)
590 IF (LATEX_OUTPUT_PATH)
591 IF ("${LATEX_OUTPUT_PATH}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
592 MESSAGE(SEND_ERROR "You cannot set LATEX_OUTPUT_PATH to the same directory that contains LaTeX input files.")
593 ELSE ("${LATEX_OUTPUT_PATH}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
594 SET(${var} "${LATEX_OUTPUT_PATH}")
595 ENDIF ("${LATEX_OUTPUT_PATH}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
596 ELSE (LATEX_OUTPUT_PATH)
597 IF ("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
598 MESSAGE(SEND_ERROR "LaTeX files must be built out of source or you must set LATEX_OUTPUT_PATH.")
599 ELSE ("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
600 SET(${var} "${CMAKE_CURRENT_BINARY_DIR}")
601 ENDIF ("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
602 ENDIF (LATEX_OUTPUT_PATH)
603 ENDMACRO(LATEX_GET_OUTPUT_PATH)
605 MACRO(LATEX_ADD_CONVERT_COMMAND output_path input_path output_extension
606 input_extension flags)
607 SET (converter ${IMAGEMAGICK_CONVERT})
608 SET (convert_flags "")
609 # ImageMagick has broken eps to pdf conversion
611 IF (${input_extension} STREQUAL ".eps" AND ${output_extension} STREQUAL ".pdf")
612 IF (PS2PDF_CONVERTER)
613 SET (converter ${PS2PDF_CONVERTER})
614 SET (convert_flags -dEPSCrop ${PS2PDF_CONVERTER_FLAGS})
615 ELSE (PS2PDF_CONVERTER)
616 MESSAGE(SEND_ERROR "Using postscript files with pdflatex requires ps2pdf for conversion.")
617 ENDIF (PS2PDF_CONVERTER)
618 ELSE (${input_extension} STREQUAL ".eps" AND ${output_extension} STREQUAL ".pdf")
619 SET (convert_flags ${flags})
620 ENDIF (${input_extension} STREQUAL ".eps" AND ${output_extension} STREQUAL ".pdf")
622 ADD_CUSTOM_COMMAND(OUTPUT ${output_path}
624 ARGS ${convert_flags} ${input_path} ${output_path}
625 DEPENDS ${input_path}
627 ENDMACRO(LATEX_ADD_CONVERT_COMMAND)
629 # Makes custom commands to convert a file to a particular type.
630 MACRO(LATEX_CONVERT_IMAGE output_files input_file output_extension convert_flags
631 output_extensions other_files)
632 SET(input_dir ${CMAKE_CURRENT_SOURCE_DIR})
633 LATEX_GET_OUTPUT_PATH(output_dir)
635 GET_FILENAME_COMPONENT(extension "${input_file}" EXT)
637 STRING(REGEX REPLACE "\\.[^.]*\$" ${output_extension} output_file
640 LATEX_LIST_CONTAINS(is_type ${extension} ${output_extensions})
643 LATEX_ADD_CONVERT_COMMAND(${output_dir}/${output_file}
644 ${input_dir}/${input_file} ${output_extension} ${extension}
646 SET(${output_files} ${${output_files}} ${output_dir}/${output_file})
648 # As a shortcut, we can just copy the file.
649 ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${input_file}
650 COMMAND ${CMAKE_COMMAND}
651 ARGS -E copy ${input_dir}/${input_file} ${output_dir}/${input_file}
652 DEPENDS ${input_dir}/${input_file}
654 SET(${output_files} ${${output_files}} ${output_dir}/${input_file})
655 ENDIF (convert_flags)
658 # Check to see if there is another input file of the appropriate type.
659 FOREACH(valid_extension ${output_extensions})
660 STRING(REGEX REPLACE "\\.[^.]*\$" ${output_extension} try_file
662 LATEX_LIST_CONTAINS(has_native_file "${try_file}" ${other_files})
664 SET(do_convert FALSE)
665 ENDIF (has_native_file)
666 ENDFOREACH(valid_extension)
668 # If we still need to convert, do it.
670 LATEX_ADD_CONVERT_COMMAND(${output_dir}/${output_file}
671 ${input_dir}/${input_file} ${output_extension} ${extension}
673 SET(${output_files} ${${output_files}} ${output_dir}/${output_file})
676 ENDMACRO(LATEX_CONVERT_IMAGE)
678 # Adds custom commands to process the given files for dvi and pdf builds.
679 # Adds the output files to the given variables (does not replace).
680 MACRO(LATEX_PROCESS_IMAGES dvi_outputs pdf_outputs)
681 LATEX_GET_OUTPUT_PATH(output_dir)
682 FOREACH(file ${ARGN})
683 IF (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
684 GET_FILENAME_COMPONENT(extension "${file}" EXT)
687 # Check to see if we need to downsample the image.
688 LATEX_LIST_CONTAINS(is_raster extension
689 ${LATEX_DVI_RASTER_IMAGE_EXTENSIONS}
690 ${LATEX_PDF_RASTER_IMAGE_EXTENSIONS})
691 IF (LATEX_SMALL_IMAGES)
693 SET(convert_flags -resize ${LATEX_RASTER_SCALE}%)
695 ENDIF (LATEX_SMALL_IMAGES)
697 # Make sure the output directory exists.
698 GET_FILENAME_COMPONENT(path "${output_dir}/${file}" PATH)
699 MAKE_DIRECTORY("${path}")
701 # Do conversions for dvi.
702 LATEX_CONVERT_IMAGE(${dvi_outputs} "${file}" .eps "${convert_flags}"
703 "${LATEX_DVI_IMAGE_EXTENSIONS}" "${ARGN}")
705 # Do conversions for pdf.
707 LATEX_CONVERT_IMAGE(${pdf_outputs} "${file}" .png "${convert_flags}"
708 "${LATEX_PDF_IMAGE_EXTENSIONS}" "${ARGN}")
710 LATEX_CONVERT_IMAGE(${pdf_outputs} "${file}" .pdf "${convert_flags}"
711 "${LATEX_PDF_IMAGE_EXTENSIONS}" "${ARGN}")
713 ELSE (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
714 MESSAGE(WARNING "Could not find file ${CMAKE_CURRENT_SOURCE_DIR}/${file}. Are you sure you gave relative paths to IMAGES?")
715 ENDIF (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
717 ENDMACRO(LATEX_PROCESS_IMAGES)
719 MACRO(ADD_LATEX_IMAGES)
720 MESSAGE("The ADD_LATEX_IMAGES macro is deprecated. Image directories are specified with LATEX_ADD_DOCUMENT.")
721 ENDMACRO(ADD_LATEX_IMAGES)
723 MACRO(LATEX_COPY_GLOBBED_FILES pattern dest)
724 FILE(GLOB file_list ${pattern})
725 FOREACH(in_file ${file_list})
726 GET_FILENAME_COMPONENT(out_file ${in_file} NAME)
727 CONFIGURE_FILE(${in_file} ${dest}/${out_file} COPYONLY)
729 ENDMACRO(LATEX_COPY_GLOBBED_FILES)
731 MACRO(LATEX_COPY_INPUT_FILE file)
732 LATEX_GET_OUTPUT_PATH(output_dir)
734 IF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file})
735 GET_FILENAME_COMPONENT(path ${file} PATH)
736 FILE(MAKE_DIRECTORY ${output_dir}/${path})
738 LATEX_LIST_CONTAINS(use_config ${file} ${LATEX_CONFIGURE})
740 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${file}
741 ${output_dir}/${file}
744 ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${file}
745 COMMAND ${CMAKE_COMMAND}
746 ARGS ${CMAKE_BINARY_DIR}
747 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file}
750 ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${file}
751 COMMAND ${CMAKE_COMMAND}
752 ARGS -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${file} ${output_dir}/${file}
753 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file}
756 ELSE (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file})
757 IF (EXISTS ${output_dir}/${file})
758 # Special case: output exists but input does not. Assume that it was
759 # created elsewhere and skip the input file copy.
760 ELSE (EXISTS ${output_dir}/${file})
761 MESSAGE("Could not find input file ${CMAKE_CURRENT_SOURCE_DIR}/${file}")
762 ENDIF (EXISTS ${output_dir}/${file})
763 ENDIF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file})
764 ENDMACRO(LATEX_COPY_INPUT_FILE)
766 #############################################################################
767 # Commands provided by the UseLATEX.cmake "package"
768 #############################################################################
770 MACRO(LATEX_USAGE command message)
772 "${message}\nUsage: ${command}(<tex_file>\n [BIBFILES <bib_file> <bib_file> ...]\n [INPUTS <tex_file> <tex_file> ...]\n [IMAGE_DIRS <directory1> <directory2> ...]\n [IMAGES <image_file1> <image_file2>\n [CONFIGURE <tex_file> <tex_file> ...]\n [DEPENDS <tex_file> <tex_file> ...]\n [USE_INDEX] [USE_GLOSSARY] [USE_NOMENCL]\n [DEFAULT_PDF] [DEFAULT_SAFEPDF]\n [MANGLE_TARGET_NAMES])"
774 ENDMACRO(LATEX_USAGE command message)
776 # Parses arguments to ADD_LATEX_DOCUMENT and ADD_LATEX_TARGETS and sets the
777 # variables LATEX_TARGET, LATEX_IMAGE_DIR, LATEX_BIBFILES, LATEX_DEPENDS, and
779 MACRO(PARSE_ADD_LATEX_ARGUMENTS command)
780 LATEX_PARSE_ARGUMENTS(
782 "BIBFILES;INPUTS;IMAGE_DIRS;IMAGES;CONFIGURE;DEPENDS"
783 "USE_INDEX;USE_GLOSSARY;USE_GLOSSARIES;USE_NOMENCL;DEFAULT_PDF;DEFAULT_SAFEPDF;MANGLE_TARGET_NAMES"
787 # The first argument is the target latex file.
788 IF (LATEX_DEFAULT_ARGS)
789 LATEX_CAR(LATEX_MAIN_INPUT ${LATEX_DEFAULT_ARGS})
790 LATEX_CDR(LATEX_DEFAULT_ARGS ${LATEX_DEFAULT_ARGS})
791 GET_FILENAME_COMPONENT(LATEX_TARGET ${LATEX_MAIN_INPUT} NAME_WE)
792 ELSE (LATEX_DEFAULT_ARGS)
793 LATEX_USAGE(${command} "No tex file target given to ${command}.")
794 ENDIF (LATEX_DEFAULT_ARGS)
796 IF (LATEX_DEFAULT_ARGS)
797 LATEX_USAGE(${command} "Invalid or depricated arguments: ${LATEX_DEFAULT_ARGS}")
798 ENDIF (LATEX_DEFAULT_ARGS)
800 # Backward compatibility between 1.6.0 and 1.6.1.
801 IF (LATEX_USE_GLOSSARIES)
802 SET(LATEX_USE_GLOSSARY TRUE)
803 ENDIF (LATEX_USE_GLOSSARIES)
804 ENDMACRO(PARSE_ADD_LATEX_ARGUMENTS)
806 MACRO(ADD_LATEX_TARGETS)
807 LATEX_GET_OUTPUT_PATH(output_dir)
808 PARSE_ADD_LATEX_ARGUMENTS(ADD_LATEX_TARGETS ${ARGV})
810 IF (LATEX_USE_SYNCTEX)
811 SET(synctex_flags ${LATEX_SYNCTEX_FLAGS})
812 ELSE (LATEX_USE_SYNCTEX)
814 ENDIF (LATEX_USE_SYNCTEX)
816 # The commands to run LaTeX. They are repeated multiple times.
817 SET(latex_build_command
818 ${LATEX_COMPILER} ${LATEX_COMPILER_FLAGS} ${synctex_flags} ${LATEX_MAIN_INPUT}
820 SET(pdflatex_build_command
821 ${PDFLATEX_COMPILER} ${PDFLATEX_COMPILER_FLAGS} ${synctex_flags} ${LATEX_MAIN_INPUT}
824 # Set up target names.
825 IF (LATEX_MANGLE_TARGET_NAMES)
826 SET(dvi_target ${LATEX_TARGET}_dvi)
827 SET(pdf_target ${LATEX_TARGET}_pdf)
828 SET(ps_target ${LATEX_TARGET}_ps)
829 SET(safepdf_target ${LATEX_TARGET}_safepdf)
830 SET(html_target ${LATEX_TARGET}_html)
831 SET(auxclean_target ${LATEX_TARGET}_auxclean)
832 ELSE (LATEX_MANGLE_TARGET_NAMES)
836 SET(safepdf_target safepdf)
837 SET(html_target html)
838 SET(auxclean_target auxclean)
839 ENDIF (LATEX_MANGLE_TARGET_NAMES)
841 # Probably not all of these will be generated, but they could be.
842 # Note that the aux file is added later.
843 SET(auxiliary_clean_files
844 ${output_dir}/${LATEX_TARGET}.bbl
845 ${output_dir}/${LATEX_TARGET}.blg
846 ${output_dir}/${LATEX_TARGET}-blx.bib
847 ${output_dir}/${LATEX_TARGET}.glg
848 ${output_dir}/${LATEX_TARGET}.glo
849 ${output_dir}/${LATEX_TARGET}.gls
850 ${output_dir}/${LATEX_TARGET}.idx
851 ${output_dir}/${LATEX_TARGET}.ilg
852 ${output_dir}/${LATEX_TARGET}.ind
853 ${output_dir}/${LATEX_TARGET}.ist
854 ${output_dir}/${LATEX_TARGET}.log
855 ${output_dir}/${LATEX_TARGET}.out
856 ${output_dir}/${LATEX_TARGET}.toc
857 ${output_dir}/${LATEX_TARGET}.lof
858 ${output_dir}/${LATEX_TARGET}.xdy
859 ${output_dir}/${LATEX_TARGET}.synctex.gz
860 ${output_dir}/${LATEX_TARGET}.synctex.bak.gz
861 ${output_dir}/${LATEX_TARGET}.dvi
862 ${output_dir}/${LATEX_TARGET}.ps
863 ${output_dir}/${LATEX_TARGET}.pdf
866 # For each directory in LATEX_IMAGE_DIRS, glob all the image files and
867 # place them in LATEX_IMAGES.
868 FOREACH(dir ${LATEX_IMAGE_DIRS})
869 FOREACH(extension ${LATEX_IMAGE_EXTENSIONS})
870 IF (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir})
871 MESSAGE(WARNING "Image directory ${CMAKE_CURRENT_SOURCE_DIR}/${dir} does not exist. Are you sure you gave relative directories to IMAGE_DIRS?")
872 ENDIF (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir})
873 FILE(GLOB files ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*${extension})
874 FOREACH(file ${files})
875 GET_FILENAME_COMPONENT(filename ${file} NAME)
876 SET(LATEX_IMAGES ${LATEX_IMAGES} ${dir}/${filename})
878 ENDFOREACH(extension)
883 LATEX_PROCESS_IMAGES(dvi_images pdf_images ${LATEX_IMAGES})
886 ${CMAKE_COMMAND} -E chdir ${output_dir}
887 ${latex_build_command})
889 ${CMAKE_COMMAND} -E chdir ${output_dir}
890 ${pdflatex_build_command}
893 SET(make_dvi_depends ${LATEX_DEPENDS} ${dvi_images})
894 SET(make_pdf_depends ${LATEX_DEPENDS} ${pdf_images})
895 FOREACH(input ${LATEX_MAIN_INPUT} ${LATEX_INPUTS})
896 SET(make_dvi_depends ${make_dvi_depends} ${output_dir}/${input})
897 SET(make_pdf_depends ${make_pdf_depends} ${output_dir}/${input})
898 IF (${input} MATCHES "\\.tex$")
899 STRING(REGEX REPLACE "\\.tex$" "" input_we ${input})
900 SET(auxiliary_clean_files ${auxiliary_clean_files}
901 ${output_dir}/${input_we}.aux
902 ${output_dir}/${input}.aux
904 ENDIF (${input} MATCHES "\\.tex$")
907 IF (LATEX_USE_GLOSSARY)
908 FOREACH(dummy 0 1) # Repeat these commands twice.
909 SET(make_dvi_command ${make_dvi_command}
910 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
912 -D LATEX_BUILD_COMMAND=makeglossaries
913 -D LATEX_TARGET=${LATEX_TARGET}
914 -D MAKEINDEX_COMPILER=${MAKEINDEX_COMPILER}
915 -D XINDY_COMPILER=${XINDY_COMPILER}
916 -D MAKEGLOSSARIES_COMPILER_FLAGS=${MAKEGLOSSARIES_COMPILER_FLAGS}
917 -P ${LATEX_USE_LATEX_LOCATION}
918 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
919 ${latex_build_command}
921 SET(make_pdf_command ${make_pdf_command}
922 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
924 -D LATEX_BUILD_COMMAND=makeglossaries
925 -D LATEX_TARGET=${LATEX_TARGET}
926 -D MAKEINDEX_COMPILER=${MAKEINDEX_COMPILER}
927 -D XINDY_COMPILER=${XINDY_COMPILER}
928 -D MAKEGLOSSARIES_COMPILER_FLAGS=${MAKEGLOSSARIES_COMPILER_FLAGS}
929 -P ${LATEX_USE_LATEX_LOCATION}
930 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
931 ${pdflatex_build_command}
934 ENDIF (LATEX_USE_GLOSSARY)
936 IF (LATEX_USE_NOMENCL)
937 FOREACH(dummy 0 1) # Repeat these commands twice.
938 SET(make_dvi_command ${make_dvi_command}
939 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
941 -D LATEX_BUILD_COMMAND=makenomenclature
942 -D LATEX_TARGET=${LATEX_TARGET}
943 -D MAKEINDEX_COMPILER=${MAKEINDEX_COMPILER}
944 -D MAKENOMENCLATURE_COMPILER_FLAGS=${MAKENOMENCLATURE_COMPILER_FLAGS}
945 -P ${LATEX_USE_LATEX_LOCATION}
946 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
947 ${latex_build_command}
949 SET(make_pdf_command ${make_pdf_command}
950 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
952 -D LATEX_BUILD_COMMAND=makenomenclature
953 -D LATEX_TARGET=${LATEX_TARGET}
954 -D MAKEINDEX_COMPILER=${MAKEINDEX_COMPILER}
955 -D MAKENOMENCLATURE_COMPILER_FLAGS=${MAKENOMENCLATURE_COMPILER_FLAGS}
956 -P ${LATEX_USE_LATEX_LOCATION}
957 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
958 ${pdflatex_build_command}
961 ENDIF (LATEX_USE_NOMENCL)
964 SET(make_dvi_command ${make_dvi_command}
965 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
966 ${BIBTEX_COMPILER} ${BIBTEX_COMPILER_FLAGS} ${LATEX_TARGET})
967 SET(make_pdf_command ${make_pdf_command}
968 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
969 ${BIBTEX_COMPILER} ${BIBTEX_COMPILER_FLAGS} ${LATEX_TARGET})
970 FOREACH (bibfile ${LATEX_BIBFILES})
971 SET(make_dvi_depends ${make_dvi_depends} ${output_dir}/${bibfile})
972 SET(make_pdf_depends ${make_pdf_depends} ${output_dir}/${bibfile})
973 ENDFOREACH (bibfile ${LATEX_BIBFILES})
974 ENDIF (LATEX_BIBFILES)
977 SET(make_dvi_command ${make_dvi_command}
978 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
979 ${latex_build_command}
980 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
981 ${MAKEINDEX_COMPILER} ${MAKEINDEX_COMPILER_FLAGS} ${LATEX_TARGET}.idx)
982 SET(make_pdf_command ${make_pdf_command}
983 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
984 ${pdflatex_build_command}
985 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
986 ${MAKEINDEX_COMPILER} ${MAKEINDEX_COMPILER_FLAGS} ${LATEX_TARGET}.idx)
987 ENDIF (LATEX_USE_INDEX)
989 SET(make_dvi_command ${make_dvi_command}
990 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
991 ${latex_build_command}
992 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
993 ${latex_build_command})
994 SET(make_pdf_command ${make_pdf_command}
995 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
996 ${pdflatex_build_command}
997 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
998 ${pdflatex_build_command})
1000 IF (LATEX_USE_SYNCTEX)
1002 MESSAGE(SEND_ERROR "UseLATEX.cmake: USE_SYNTEX option requires gzip program. Set GZIP variable.")
1004 SET(make_dvi_command ${make_dvi_command}
1005 COMMAND ${CMAKE_COMMAND}
1006 -D LATEX_BUILD_COMMAND=correct_synctex
1007 -D LATEX_TARGET=${LATEX_TARGET}
1009 -D "LATEX_SOURCE_DIRECTORY=${CMAKE_CURRENT_SOURCE_DIR}"
1010 -D "LATEX_BINARY_DIRECTORY=${output_dir}"
1011 -P ${LATEX_USE_LATEX_LOCATION}
1013 SET(make_pdf_command ${make_pdf_command}
1014 COMMAND ${CMAKE_COMMAND}
1015 -D LATEX_BUILD_COMMAND=correct_synctex
1016 -D LATEX_TARGET=${LATEX_TARGET}
1018 -D "LATEX_SOURCE_DIRECTORY=${CMAKE_CURRENT_SOURCE_DIR}"
1019 -D "LATEX_BINARY_DIRECTORY=${output_dir}"
1020 -P ${LATEX_USE_LATEX_LOCATION}
1022 ENDIF (LATEX_USE_SYNCTEX)
1024 # Add commands and targets for building dvi outputs.
1025 ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${LATEX_TARGET}.dvi
1026 COMMAND ${make_dvi_command}
1027 DEPENDS ${make_dvi_depends}
1029 IF (LATEX_DEFAULT_PDF OR LATEX_DEFAULT_SAFEPDF)
1030 ADD_CUSTOM_TARGET(${dvi_target}
1031 DEPENDS ${output_dir}/${LATEX_TARGET}.dvi)
1032 ELSE (LATEX_DEFAULT_PDF OR LATEX_DEFAULT_SAFEPDF)
1033 ADD_CUSTOM_TARGET(${dvi_target} ALL
1034 DEPENDS ${output_dir}/${LATEX_TARGET}.dvi)
1035 ENDIF (LATEX_DEFAULT_PDF OR LATEX_DEFAULT_SAFEPDF)
1037 # Add commands and targets for building pdf outputs (with pdflatex).
1038 IF (PDFLATEX_COMPILER)
1039 ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${LATEX_TARGET}.pdf
1040 COMMAND ${make_pdf_command}
1041 DEPENDS ${make_pdf_depends}
1043 IF (LATEX_DEFAULT_PDF)
1044 ADD_CUSTOM_TARGET(${pdf_target} ALL
1045 DEPENDS ${output_dir}/${LATEX_TARGET}.pdf)
1046 ELSE (LATEX_DEFAULT_PDF)
1047 ADD_CUSTOM_TARGET(${pdf_target}
1048 DEPENDS ${output_dir}/${LATEX_TARGET}.pdf)
1049 ENDIF (LATEX_DEFAULT_PDF)
1050 ENDIF (PDFLATEX_COMPILER)
1052 IF (DVIPS_CONVERTER)
1053 ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${LATEX_TARGET}.ps
1054 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1055 ${DVIPS_CONVERTER} ${DVIPS_CONVERTER_FLAGS} -o ${LATEX_TARGET}.ps ${LATEX_TARGET}.dvi
1056 DEPENDS ${output_dir}/${LATEX_TARGET}.dvi)
1057 ADD_CUSTOM_TARGET(${ps_target}
1058 DEPENDS ${output_dir}/${LATEX_TARGET}.ps)
1059 IF (PS2PDF_CONVERTER)
1060 # Since both the pdf and safepdf targets have the same output, we
1061 # cannot properly do the dependencies for both. When selecting safepdf,
1062 # simply force a recompile every time.
1063 IF (LATEX_DEFAULT_SAFEPDF)
1064 ADD_CUSTOM_TARGET(${safepdf_target} ALL
1065 ${CMAKE_COMMAND} -E chdir ${output_dir}
1066 ${PS2PDF_CONVERTER} ${PS2PDF_CONVERTER_FLAGS} ${LATEX_TARGET}.ps ${LATEX_TARGET}.pdf
1068 ELSE (LATEX_DEFAULT_SAFEPDF)
1069 ADD_CUSTOM_TARGET(${safepdf_target}
1070 ${CMAKE_COMMAND} -E chdir ${output_dir}
1071 ${PS2PDF_CONVERTER} ${PS2PDF_CONVERTER_FLAGS} ${LATEX_TARGET}.ps ${LATEX_TARGET}.pdf
1073 ENDIF (LATEX_DEFAULT_SAFEPDF)
1074 ADD_DEPENDENCIES(${safepdf_target} ${ps_target})
1075 ENDIF (PS2PDF_CONVERTER)
1076 ENDIF (DVIPS_CONVERTER)
1078 IF (LATEX2HTML_CONVERTER)
1079 ADD_CUSTOM_TARGET(${html_target}
1080 ${CMAKE_COMMAND} -E chdir ${output_dir}
1081 ${LATEX2HTML_CONVERTER} ${LATEX2HTML_CONVERTER_FLAGS} ${LATEX_MAIN_INPUT}
1083 ADD_DEPENDENCIES(${html_target} ${LATEX_MAIN_INPUT} ${LATEX_INPUTS})
1084 ENDIF (LATEX2HTML_CONVERTER)
1086 SET_DIRECTORY_PROPERTIES(.
1087 ADDITIONAL_MAKE_CLEAN_FILES "${auxiliary_clean_files}"
1090 ADD_CUSTOM_TARGET(${auxclean_target}
1091 COMMENT "Cleaning auxiliary LaTeX files."
1092 COMMAND ${CMAKE_COMMAND} -E remove ${auxiliary_clean_files}
1094 ENDMACRO(ADD_LATEX_TARGETS)
1096 MACRO(ADD_LATEX_DOCUMENT)
1097 LATEX_GET_OUTPUT_PATH(output_dir)
1099 PARSE_ADD_LATEX_ARGUMENTS(ADD_LATEX_DOCUMENT ${ARGV})
1101 LATEX_COPY_INPUT_FILE(${LATEX_MAIN_INPUT})
1103 FOREACH (bib_file ${LATEX_BIBFILES})
1104 LATEX_COPY_INPUT_FILE(${bib_file})
1105 ENDFOREACH (bib_file)
1107 FOREACH (input ${LATEX_INPUTS})
1108 LATEX_COPY_INPUT_FILE(${input})
1111 LATEX_COPY_GLOBBED_FILES(${CMAKE_CURRENT_SOURCE_DIR}/*.cls ${output_dir})
1112 LATEX_COPY_GLOBBED_FILES(${CMAKE_CURRENT_SOURCE_DIR}/*.bst ${output_dir})
1113 LATEX_COPY_GLOBBED_FILES(${CMAKE_CURRENT_SOURCE_DIR}/*.clo ${output_dir})
1114 LATEX_COPY_GLOBBED_FILES(${CMAKE_CURRENT_SOURCE_DIR}/*.sty ${output_dir})
1115 LATEX_COPY_GLOBBED_FILES(${CMAKE_CURRENT_SOURCE_DIR}/*.ist ${output_dir})
1117 ADD_LATEX_TARGETS(${ARGV})
1119 ENDMACRO(ADD_LATEX_DOCUMENT)
1121 #############################################################################
1123 #############################################################################
1125 IF (LATEX_BUILD_COMMAND)
1126 SET(command_handled)
1128 IF ("${LATEX_BUILD_COMMAND}" STREQUAL makeglossaries)
1129 LATEX_MAKEGLOSSARIES()
1130 SET(command_handled TRUE)
1131 ENDIF ("${LATEX_BUILD_COMMAND}" STREQUAL makeglossaries)
1133 IF ("${LATEX_BUILD_COMMAND}" STREQUAL makenomenclature)
1134 LATEX_MAKENOMENCLATURE()
1135 SET(command_handled TRUE)
1136 ENDIF ("${LATEX_BUILD_COMMAND}" STREQUAL makenomenclature)
1138 IF ("${LATEX_BUILD_COMMAND}" STREQUAL correct_synctex)
1139 LATEX_CORRECT_SYNCTEX()
1140 SET(command_handled TRUE)
1141 ENDIF ("${LATEX_BUILD_COMMAND}" STREQUAL correct_synctex)
1143 IF (NOT command_handled)
1144 MESSAGE(SEND_ERROR "Unknown command: ${LATEX_BUILD_COMMAND}")
1145 ENDIF (NOT command_handled)
1147 ELSE (LATEX_BUILD_COMMAND)
1148 # Must be part of the actual configure (included from CMakeLists.txt).
1149 LATEX_SETUP_VARIABLES()
1150 ENDIF (LATEX_BUILD_COMMAND)