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]
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. This is sometimes necessary
51 # if a LaTeX error occurs and writes a bad aux file.
53 # The dvi target is added to the ALL. That is, it will be the target
54 # built by default. If the DEFAULT_PDF argument is given, then the
55 # pdf target will be the default instead of dvi. In GROMACS, we
56 # have hacked this - no target is ever added to ALL.
58 # If the argument MANGLE_TARGET_NAMES is given, then each of the
59 # target names above will be mangled with the <tex_file> name. This
60 # is to make the targets unique if ADD_LATEX_DOCUMENT is called for
61 # multiple documents. If the argument USE_INDEX is given, then
62 # commands to build an index are made. If the argument USE_GLOSSARY
63 # is given, then commands to build a glossary are made.
67 # 1.7.4 Added the DEFAULT_SAFEPDF option (thanks to Raymond Wan).
69 # Added warnings when image directories are not found (and were
70 # probably not given relative to the source directory).
72 # 1.7.3 Fix some issues with interactions between makeglossaries and bibtex
73 # (thanks to Mark de Wever).
75 # 1.7.2 Use ps2pdf to convert eps to pdf to get around the problem with
76 # ImageMagick dropping the bounding box (thanks to Lukasz Lis).
78 # 1.7.1 Fixed some dependency issues.
80 # 1.7.0 Added DEPENDS options (thanks to Theodore Papadopoulo).
82 # 1.6.1 Ported the makeglossaries command to CMake and embedded the port
83 # into UseLATEX.cmake.
85 # 1.6.0 Allow the use of the makeglossaries command. Thanks to Oystein
86 # S. Haaland for the patch.
88 # 1.5.0 Allow any type of file in the INPUTS lists, not just tex file
89 # (suggested by Eric Noulard). As a consequence, the ability to
90 # specify tex files without the .tex extension is removed. The removed
91 # function is of dubious value anyway.
93 # When copying input files, skip over any file that exists in the
94 # binary directory but does not exist in the source directory with the
95 # assumption that these files were added by some other mechanism. I
96 # find this useful when creating large documents with multiple
97 # chapters that I want to build separately (for speed) as I work on
98 # them. I use the same boilerplate as the starting point for all
99 # and just copy it with different configurations. This was what the
100 # separate ADD_LATEX_DOCUMENT method was supposed to originally be for.
101 # Since its external use is pretty much deprecated, I removed that
104 # 1.4.1 Copy .sty files along with the other class and package files.
106 # 1.4.0 Added a MANGLE_TARGET_NAMES option that will mangle the target names.
108 # Fixed problem with copying bib files that became apparent with
111 # 1.3.0 Added a LATEX_OUTPUT_PATH variable that allows you or the user to
112 # specify where the built latex documents to go. This is especially
113 # handy if you want to do in-source builds.
115 # Removed the ADD_LATEX_IMAGES macro and absorbed the functionality
116 # into ADD_LATEX_DOCUMENT. The old interface was always kind of
117 # clunky anyway since you had to specify the image directory in both
118 # places. It also made supporting LATEX_OUTPUT_PATH problematic.
120 # Added support for jpeg files.
122 # 1.2.0 Changed the configuration options yet again. Removed the NO_CONFIGURE
123 # Replaced it with a CONFIGURE option that lists input files for which
124 # configure should be run.
126 # The pdf target no longer depends on the dvi target. This allows you
127 # to build latex documents that require pdflatex. Also added an option
128 # to make the pdf target the default one.
130 # 1.1.1 Added the NO_CONFIGURE option. The @ character can be used when
131 # specifying table column separators. If two or more are used, then
132 # will incorrectly substitute them.
134 # 1.1.0 Added ability include multiple bib files. Added ability to do copy
135 # sub-tex files for multipart tex files.
137 # 1.0.0 If both ps and pdf type images exist, just copy the one that
138 # matches the current render mode. Replaced a bunch of STRING
139 # commands with GET_FILENAME_COMPONENT commands that were made to do
140 # the desired function.
142 # 0.4.0 First version posted to CMake Wiki.
145 #############################################################################
146 # Find the location of myself while originally executing. If you do this
147 # inside of a macro, it will recode where the macro was invoked.
148 #############################################################################
149 SET(LATEX_USE_LATEX_LOCATION ${CMAKE_CURRENT_LIST_FILE}
150 CACHE INTERNAL "Location of UseLATEX.cmake file." FORCE
153 #############################################################################
154 # Generic helper macros
155 #############################################################################
157 # Helpful list macros.
161 MACRO(LATEX_CDR var junk)
165 MACRO(LATEX_LIST_CONTAINS var value)
167 FOREACH (value2 ${ARGN})
168 IF (${value} STREQUAL ${value2})
170 ENDIF (${value} STREQUAL ${value2})
172 ENDMACRO(LATEX_LIST_CONTAINS)
174 # Parse macro arguments.
175 MACRO(LATEX_PARSE_ARGUMENTS prefix arg_names option_names)
177 FOREACH(arg_name ${arg_names})
178 SET(${prefix}_${arg_name})
180 FOREACH(option ${option_names})
181 SET(${prefix}_${option})
184 SET(current_arg_name DEFAULT_ARGS)
185 SET(current_arg_list)
187 LATEX_LIST_CONTAINS(is_arg_name ${arg} ${arg_names})
189 SET(${prefix}_${current_arg_name} ${current_arg_list})
190 SET(current_arg_name ${arg})
191 SET(current_arg_list)
193 LATEX_LIST_CONTAINS(is_option ${arg} ${option_names})
195 SET(${prefix}_${arg} TRUE)
197 SET(current_arg_list ${current_arg_list} ${arg})
201 SET(${prefix}_${current_arg_name} ${current_arg_list})
202 ENDMACRO(LATEX_PARSE_ARGUMENTS)
204 # Match the contents of a file to a regular expression.
205 MACRO(LATEX_FILE_MATCH variable filename regexp default)
206 # The FILE STRINGS command would be a bit better, but it's not supported on
207 # older versions of CMake.
208 FILE(READ ${filename} file_contents)
209 STRING(REGEX MATCHALL "${regexp}"
210 ${variable} ${file_contents}
213 SET(${variable} "${default}")
214 ENDIF (NOT ${variable})
215 ENDMACRO(LATEX_FILE_MATCH)
217 #############################################################################
218 # Macros that perform processing during a LaTeX build.
219 #############################################################################
220 MACRO(LATEX_MAKEGLOSSARIES)
221 MESSAGE("**************************** In makeglossaries")
222 IF (NOT LATEX_TARGET)
223 MESSAGE(SEND_ERROR "Need to define LATEX_TARGET")
224 ENDIF (NOT LATEX_TARGET)
226 IF (NOT MAKEINDEX_COMPILER)
227 MESSAGE(SEND_ERROR "Need to define MAKEINDEX_COMPILER")
228 ENDIF (NOT MAKEINDEX_COMPILER)
230 SET(aux_file ${LATEX_TARGET}.aux)
232 IF (NOT EXISTS ${aux_file})
233 MESSAGE(SEND_ERROR "${aux_file} does not exist. Run latex on your target file.")
234 ENDIF (NOT EXISTS ${aux_file})
236 LATEX_FILE_MATCH(newglossary_lines ${aux_file}
237 "@newglossary[ \t]*{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}"
238 "@newglossary{main}{glg}{gls}{glo}"
241 LATEX_FILE_MATCH(istfile_line ${aux_file}
242 "@istfilename[ \t]*{([^}]*)}"
243 "@istfilename{${LATEX_TARGET}.ist}"
245 STRING(REGEX REPLACE "@istfilename[ \t]*{([^}]*)}" "\\1"
246 istfile ${istfile_line}
249 FOREACH(newglossary ${newglossary_lines})
251 "@newglossary[ \t]*{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}"
252 "\\1" glossary_name ${newglossary}
255 "@newglossary[ \t]*{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}"
256 "${LATEX_TARGET}.\\2" glossary_log ${newglossary}
259 "@newglossary[ \t]*{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}"
260 "${LATEX_TARGET}.\\3" glossary_out ${newglossary}
263 "@newglossary[ \t]*{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}"
264 "${LATEX_TARGET}.\\4" glossary_in ${newglossary}
266 MESSAGE("${MAKEINDEX_COMPILER} ${MAKEGLOSSARIES_COMPILER_FLAGS} -s ${istfile} -t ${glossary_log} -o ${glossary_out} ${glossary_in}")
267 EXEC_PROGRAM(${MAKEINDEX_COMPILER} ARGS ${MAKEGLOSSARIES_COMPILER_FLAGS}
268 -s ${istfile} -t ${glossary_log} -o ${glossary_out} ${glossary_in}
270 ENDFOREACH(newglossary)
271 ENDMACRO(LATEX_MAKEGLOSSARIES)
273 #############################################################################
274 # Helper macros for establishing LaTeX build.
275 #############################################################################
277 MACRO(LATEX_NEEDIT VAR NAME)
279 MESSAGE(SEND_ERROR "I need the ${NAME} command.")
281 ENDMACRO(LATEX_NEEDIT)
283 MACRO(LATEX_WANTIT VAR NAME)
285 MESSAGE(STATUS "I could not find the ${NAME} command.")
287 ENDMACRO(LATEX_WANTIT)
289 MACRO(LATEX_SETUP_VARIABLES)
290 SET(LATEX_OUTPUT_PATH "${LATEX_OUTPUT_PATH}"
291 CACHE PATH "If non empty, specifies the location to place LaTeX output."
296 MARK_AS_ADVANCED(CLEAR
306 # LATEX_NEEDIT(LATEX_COMPILER latex)
307 # LATEX_WANTIT(PDFLATEX_COMPILER pdflatex)
308 # LATEX_NEEDIT(BIBTEX_COMPILER bibtex)
309 # LATEX_NEEDIT(MAKEINDEX_COMPILER makeindex)
310 # LATEX_WANTIT(DVIPS_CONVERTER dvips)
311 # LATEX_WANTIT(PS2PDF_CONVERTER ps2pdf)
312 # LATEX_WANTIT(LATEX2HTML_CONVERTER latex2html)
314 SET(LATEX_COMPILER_FLAGS "-interaction=nonstopmode"
315 CACHE STRING "Flags passed to latex.")
316 SET(PDFLATEX_COMPILER_FLAGS ${LATEX_COMPILER_FLAGS}
317 CACHE STRING "Flags passed to pdflatex.")
318 SET(BIBTEX_COMPILER_FLAGS ""
319 CACHE STRING "Flags passed to bibtex.")
320 SET(MAKEINDEX_COMPILER_FLAGS ""
321 CACHE STRING "Flags passed to makeindex.")
322 SET(MAKEGLOSSARIES_COMPILER_FLAGS ""
323 CACHE STRING "Flags passed to makeglossaries.")
324 SET(DVIPS_CONVERTER_FLAGS "-Ppdf -G0 -t letter"
325 CACHE STRING "Flags passed to dvips.")
326 SET(PS2PDF_CONVERTER_FLAGS "-dMaxSubsetPct=100 -dCompatibilityLevel=1.3 -dSubsetFonts=true -dEmbedAllFonts=true -dAutoFilterColorImages=false -dAutoFilterGrayImages=false -dColorImageFilter=/FlateEncode -dGrayImageFilter=/FlateEncode -dMonoImageFilter=/FlateEncode"
327 CACHE STRING "Flags passed to ps2pdf.")
328 SET(LATEX2HTML_CONVERTER_FLAGS ""
329 CACHE STRING "Flags passed to latex2html.")
332 PDFLATEX_COMPILER_FLAGS
333 BIBTEX_COMPILER_FLAGS
334 MAKEINDEX_COMPILER_FLAGS
335 MAKEGLOSSARIES_COMPILER_FLAGS
336 DVIPS_CONVERTER_FLAGS
337 PS2PDF_CONVERTER_FLAGS
338 LATEX2HTML_CONVERTER_FLAGS
340 SEPARATE_ARGUMENTS(LATEX_COMPILER_FLAGS)
341 SEPARATE_ARGUMENTS(PDFLATEX_COMPILER_FLAGS)
342 SEPARATE_ARGUMENTS(BIBTEX_COMPILER_FLAGS)
343 SEPARATE_ARGUMENTS(MAKEINDEX_COMPILER_FLAGS)
344 SEPARATE_ARGUMENTS(MAKEGLOSSARIES_COMPILER_FLAGS)
345 SEPARATE_ARGUMENTS(DVIPS_CONVERTER_FLAGS)
346 SEPARATE_ARGUMENTS(PS2PDF_CONVERTER_FLAGS)
347 SEPARATE_ARGUMENTS(LATEX2HTML_CONVERTER_FLAGS)
349 FIND_PROGRAM(IMAGEMAGICK_CONVERT convert
350 DOC "The convert program that comes with ImageMagick (available at http://www.imagemagick.org)."
353 OPTION(LATEX_SMALL_IMAGES
354 "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."
356 IF (LATEX_SMALL_IMAGES)
357 SET(LATEX_RASTER_SCALE 16)
358 SET(LATEX_OPPOSITE_RASTER_SCALE 100)
359 ELSE (LATEX_SMALL_IMAGES)
360 SET(LATEX_RASTER_SCALE 100)
361 SET(LATEX_OPPOSITE_RASTER_SCALE 16)
362 ENDIF (LATEX_SMALL_IMAGES)
364 # Just holds extensions for known image types. They should all be lower case.
365 SET(LATEX_DVI_VECTOR_IMAGE_EXTENSIONS .eps)
366 SET(LATEX_DVI_RASTER_IMAGE_EXTENSIONS)
367 SET(LATEX_DVI_IMAGE_EXTENSIONS
368 ${LATEX_DVI_VECTOR_IMAGE_EXTENSIONS} ${LATEX_DVI_RASTER_IMAGE_EXTENSIONS})
369 SET(LATEX_PDF_VECTOR_IMAGE_EXTENSIONS .pdf)
370 SET(LATEX_PDF_RASTER_IMAGE_EXTENSIONS .png .jpeg .jpg)
371 SET(LATEX_PDF_IMAGE_EXTENSIONS
372 ${LATEX_PDF_VECTOR_IMAGE_EXTENSIONS} ${LATEX_PDF_RASTER_IMAGE_EXTENSIONS})
373 SET(LATEX_IMAGE_EXTENSIONS
374 ${LATEX_DVI_IMAGE_EXTENSIONS} ${LATEX_PDF_IMAGE_EXTENSIONS})
375 ENDMACRO(LATEX_SETUP_VARIABLES)
377 MACRO(LATEX_GET_OUTPUT_PATH var)
379 IF (LATEX_OUTPUT_PATH)
380 IF ("${LATEX_OUTPUT_PATH}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
381 MESSAGE(SEND_ERROR "You cannot set LATEX_OUTPUT_PATH to the same directory that contains LaTeX input files.")
382 ELSE ("${LATEX_OUTPUT_PATH}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
383 SET(${var} "${LATEX_OUTPUT_PATH}")
384 ENDIF ("${LATEX_OUTPUT_PATH}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
385 ELSE (LATEX_OUTPUT_PATH)
386 IF ("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
387 MESSAGE(SEND_ERROR "LaTeX files must be built out of source or you must set LATEX_OUTPUT_PATH.")
388 ELSE ("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
389 SET(${var} "${CMAKE_CURRENT_BINARY_DIR}")
390 ENDIF ("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
391 ENDIF (LATEX_OUTPUT_PATH)
392 ENDMACRO(LATEX_GET_OUTPUT_PATH)
394 MACRO(LATEX_ADD_CONVERT_COMMAND output_path input_path output_extension
395 input_extension flags)
396 SET (converter ${IMAGEMAGICK_CONVERT})
397 SET (convert_flags "")
398 # ImageMagick has broken eps to pdf conversion
400 IF (${input_extension} STREQUAL ".eps" AND ${output_extension} STREQUAL ".pdf")
401 IF (PS2PDF_CONVERTER)
402 SET (converter ${PS2PDF_CONVERTER})
403 SET (convert_flags "-dEPSCrop ${flags}")
404 ELSE (PS2PDF_CONVERTER)
405 MESSAGE(SEND_ERROR "Using postscript files with pdflatex requires ps2pdf for conversion.")
406 ENDIF (PS2PDF_CONVERTER)
407 ELSE (${input_extension} STREQUAL ".eps" AND ${output_extension} STREQUAL ".pdf")
408 SET (convert_flags ${flags})
409 ENDIF (${input_extension} STREQUAL ".eps" AND ${output_extension} STREQUAL ".pdf")
411 ADD_CUSTOM_COMMAND(OUTPUT ${output_path}
413 ARGS ${convert_flags} ${input_path} ${output_path}
414 DEPENDS ${input_path}
416 ENDMACRO(LATEX_ADD_CONVERT_COMMAND)
418 # Makes custom commands to convert a file to a particular type.
419 MACRO(LATEX_CONVERT_IMAGE output_files input_file output_extension convert_flags
420 output_extensions other_files)
421 SET(input_dir ${CMAKE_CURRENT_SOURCE_DIR})
422 LATEX_GET_OUTPUT_PATH(output_dir)
424 GET_FILENAME_COMPONENT(extension "${input_file}" EXT)
426 STRING(REGEX REPLACE "\\.[^.]*\$" ${output_extension} output_file
429 LATEX_LIST_CONTAINS(is_type ${extension} ${output_extensions})
432 LATEX_ADD_CONVERT_COMMAND(${output_dir}/${output_file}
433 ${input_dir}/${input_file} ${output_extension} ${extension}
435 SET(${output_files} ${${output_files}} ${output_dir}/${output_file})
437 # As a shortcut, we can just copy the file.
438 ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${input_file}
439 COMMAND ${CMAKE_COMMAND}
440 ARGS -E copy ${input_dir}/${input_file} ${output_dir}/${input_file}
441 DEPENDS ${input_dir}/${input_file}
443 SET(${output_files} ${${output_files}} ${output_dir}/${input_file})
444 ENDIF (convert_flags)
447 # Check to see if there is another input file of the appropriate type.
448 FOREACH(valid_extension ${output_extensions})
449 STRING(REGEX REPLACE "\\.[^.]*\$" ${output_extension} try_file
451 LATEX_LIST_CONTAINS(has_native_file "${try_file}" ${other_files})
453 SET(do_convert FALSE)
454 ENDIF (has_native_file)
455 ENDFOREACH(valid_extension)
457 # If we still need to convert, do it.
459 LATEX_ADD_CONVERT_COMMAND(${output_dir}/${output_file}
460 ${input_dir}/${input_file} ${output_extension} ${extension}
462 SET(${output_files} ${${output_files}} ${output_dir}/${output_file})
465 ENDMACRO(LATEX_CONVERT_IMAGE)
467 # Adds custom commands to process the given files for dvi and pdf builds.
468 # Adds the output files to the given variables (does not replace).
469 MACRO(LATEX_PROCESS_IMAGES dvi_outputs pdf_outputs)
470 LATEX_GET_OUTPUT_PATH(output_dir)
471 FOREACH(file ${ARGN})
472 IF (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
473 GET_FILENAME_COMPONENT(extension "${file}" EXT)
476 # Check to see if we need to downsample the image.
477 LATEX_LIST_CONTAINS(is_raster extension
478 ${LATEX_DVI_RASTER_IMAGE_EXTENSIONS}
479 ${LATEX_PDF_RASTER_IMAGE_EXTENSIONS})
480 IF (LATEX_SMALL_IMAGES)
482 SET(convert_flags -resize ${LATEX_RASTER_SCALE}%)
484 ENDIF (LATEX_SMALL_IMAGES)
486 # Make sure the output directory exists.
487 GET_FILENAME_COMPONENT(path "${output_dir}/${file}" PATH)
488 MAKE_DIRECTORY("${path}")
490 # Do conversions for dvi.
491 LATEX_CONVERT_IMAGE(${dvi_outputs} "${file}" .eps "${convert_flags}"
492 "${LATEX_DVI_IMAGE_EXTENSIONS}" "${ARGN}")
494 # Do conversions for pdf.
496 LATEX_CONVERT_IMAGE(${pdf_outputs} "${file}" .png "${convert_flags}"
497 "${LATEX_PDF_IMAGE_EXTENSIONS}" "${ARGN}")
499 LATEX_CONVERT_IMAGE(${pdf_outputs} "${file}" .pdf "${convert_flags}"
500 "${LATEX_PDF_IMAGE_EXTENSIONS}" "${ARGN}")
502 ELSE (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
503 MESSAGE(WARNING "Could not find file ${CMAKE_CURRENT_SOURCE_DIR}/${file}. Are you sure you gave relative paths to IMAGES?")
504 ENDIF (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
506 ENDMACRO(LATEX_PROCESS_IMAGES)
508 MACRO(ADD_LATEX_IMAGES)
509 MESSAGE("The ADD_LATEX_IMAGES macro is deprecated. Image directories are specified with LATEX_ADD_DOCUMENT.")
510 ENDMACRO(ADD_LATEX_IMAGES)
512 MACRO(LATEX_COPY_GLOBBED_FILES pattern dest)
513 FILE(GLOB file_list ${pattern})
514 FOREACH(in_file ${file_list})
515 GET_FILENAME_COMPONENT(out_file ${in_file} NAME)
516 CONFIGURE_FILE(${in_file} ${dest}/${out_file} COPYONLY)
518 ENDMACRO(LATEX_COPY_GLOBBED_FILES)
520 MACRO(LATEX_COPY_INPUT_FILE file)
521 LATEX_GET_OUTPUT_PATH(output_dir)
523 IF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file})
524 GET_FILENAME_COMPONENT(path ${file} PATH)
525 FILE(MAKE_DIRECTORY ${output_dir}/${path})
527 LATEX_LIST_CONTAINS(use_config ${file} ${LATEX_CONFIGURE})
529 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${file}
530 ${output_dir}/${file}
533 ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${file}
534 COMMAND ${CMAKE_COMMAND}
535 ARGS ${CMAKE_BINARY_DIR}
536 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file}
539 ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${file}
540 COMMAND ${CMAKE_COMMAND}
541 ARGS -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${file} ${output_dir}/${file}
542 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file}
545 ELSE (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file})
546 IF (EXISTS ${output_dir}/${file})
547 # Special case: output exists but input does not. Assume that it was
548 # created elsewhere and skip the input file copy.
549 ELSE (EXISTS ${output_dir}/${file})
550 MESSAGE("Could not find input file ${CMAKE_CURRENT_SOURCE_DIR}/${file}")
551 ENDIF (EXISTS ${output_dir}/${file})
552 ENDIF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file})
553 ENDMACRO(LATEX_COPY_INPUT_FILE)
555 #############################################################################
556 # Commands provided by the UseLATEX.cmake "package"
557 #############################################################################
559 MACRO(LATEX_USAGE command message)
561 "${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]\n [DEFAULT_PDF] [DEFAULT_SAFEPDF]\n [MANGLE_TARGET_NAMES])"
563 ENDMACRO(LATEX_USAGE command message)
565 # Parses arguments to ADD_LATEX_DOCUMENT and ADD_LATEX_TARGETS and sets the
566 # variables LATEX_TARGET, LATEX_IMAGE_DIR, LATEX_BIBFILES, LATEX_DEPENDS, and
568 MACRO(PARSE_ADD_LATEX_ARGUMENTS command)
569 LATEX_PARSE_ARGUMENTS(
571 "BIBFILES;INPUTS;IMAGE_DIRS;IMAGES;CONFIGURE;DEPENDS"
572 "USE_INDEX;USE_GLOSSARY;USE_GLOSSARIES;DEFAULT_PDF;DEFAULT_SAFEPDF;MANGLE_TARGET_NAMES"
576 # The first argument is the target latex file.
577 IF (LATEX_DEFAULT_ARGS)
578 LATEX_CAR(LATEX_MAIN_INPUT ${LATEX_DEFAULT_ARGS})
579 LATEX_CDR(LATEX_DEFAULT_ARGS ${LATEX_DEFAULT_ARGS})
580 GET_FILENAME_COMPONENT(LATEX_TARGET ${LATEX_MAIN_INPUT} NAME_WE)
581 ELSE (LATEX_DEFAULT_ARGS)
582 LATEX_USAGE(${command} "No tex file target given to ${command}.")
583 ENDIF (LATEX_DEFAULT_ARGS)
585 IF (LATEX_DEFAULT_ARGS)
586 LATEX_USAGE(${command} "Invalid or depricated arguments: ${LATEX_DEFAULT_ARGS}")
587 ENDIF (LATEX_DEFAULT_ARGS)
589 # Backward compatibility between 1.6.0 and 1.6.1.
590 IF (LATEX_USE_GLOSSARIES)
591 SET(LATEX_USE_GLOSSARY TRUE)
592 ENDIF (LATEX_USE_GLOSSARIES)
593 ENDMACRO(PARSE_ADD_LATEX_ARGUMENTS)
595 MACRO(ADD_LATEX_TARGETS)
596 LATEX_GET_OUTPUT_PATH(output_dir)
597 PARSE_ADD_LATEX_ARGUMENTS(ADD_LATEX_TARGETS ${ARGV})
599 # Set up target names.
600 IF (LATEX_MANGLE_TARGET_NAMES)
601 SET(dvi_target ${LATEX_TARGET}_dvi)
602 SET(pdf_target ${LATEX_TARGET}_pdf)
603 SET(ps_target ${LATEX_TARGET}_ps)
604 SET(safepdf_target ${LATEX_TARGET}_safepdf)
605 SET(html_target ${LATEX_TARGET}_html)
606 SET(auxclean_target ${LATEX_TARGET}_auxclean)
607 ELSE (LATEX_MANGLE_TARGET_NAMES)
611 SET(safepdf_target safepdf)
612 SET(html_target html)
613 SET(auxclean_target auxclean)
614 ENDIF (LATEX_MANGLE_TARGET_NAMES)
616 # For each directory in LATEX_IMAGE_DIRS, glob all the image files and
617 # place them in LATEX_IMAGES.
618 FOREACH(dir ${LATEX_IMAGE_DIRS})
619 FOREACH(extension ${LATEX_IMAGE_EXTENSIONS})
620 IF (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir})
621 MESSAGE(WARNING "Image directory ${CMAKE_CURRENT_SOURCE_DIR}/${dir} does not exist. Are you sure you gave relative directories to IMAGE_DIRS?")
622 ENDIF (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir})
623 FILE(GLOB files ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*${extension})
624 FOREACH(file ${files})
625 GET_FILENAME_COMPONENT(filename ${file} NAME)
626 SET(LATEX_IMAGES ${LATEX_IMAGES} ${dir}/${filename})
628 ENDFOREACH(extension)
633 LATEX_PROCESS_IMAGES(dvi_images pdf_images ${LATEX_IMAGES})
636 ${CMAKE_COMMAND} -E chdir ${output_dir}
637 ${LATEX_COMPILER} ${LATEX_COMPILER_FLAGS} ${LATEX_MAIN_INPUT})
639 ${CMAKE_COMMAND} -E chdir ${output_dir}
640 ${PDFLATEX_COMPILER} ${PDFLATEX_COMPILER_FLAGS} ${LATEX_MAIN_INPUT})
642 SET(make_dvi_depends ${LATEX_DEPENDS} ${dvi_images})
643 SET(make_pdf_depends ${LATEX_DEPENDS} ${pdf_images})
644 FOREACH(input ${LATEX_MAIN_INPUT} ${LATEX_INPUTS})
645 SET(make_dvi_depends ${make_dvi_depends} ${output_dir}/${input})
646 SET(make_pdf_depends ${make_pdf_depends} ${output_dir}/${input})
649 IF (LATEX_USE_GLOSSARY)
650 FOREACH(dummy 0 1) # Repeat these commands twice.
651 SET(make_dvi_command ${make_dvi_command}
652 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
654 -D LATEX_BUILD_COMMAND=makeglossaries
655 -D LATEX_TARGET=${LATEX_TARGET}
656 -D MAKEINDEX_COMPILER=${MAKEINDEX_COMPILER}
657 -D MAKEGLOSSARIES_COMPILER_FLAGS=${MAKEGLOSSARIES_COMPILER_FLAGS}
658 -P ${LATEX_USE_LATEX_LOCATION}
659 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
660 ${LATEX_COMPILER} ${LATEX_COMPILER_FLAGS} ${LATEX_MAIN_INPUT}
662 SET(make_pdf_command ${make_pdf_command}
663 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
665 -D LATEX_BUILD_COMMAND=makeglossaries
666 -D LATEX_TARGET=${LATEX_TARGET}
667 -D MAKEINDEX_COMPILER=${MAKEINDEX_COMPILER}
668 -D MAKEGLOSSARIES_COMPILER_FLAGS=${MAKEGLOSSARIES_COMPILER_FLAGS}
669 -P ${LATEX_USE_LATEX_LOCATION}
670 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
671 ${PDFLATEX_COMPILER} ${PDFLATEX_COMPILER_FLAGS} ${LATEX_MAIN_INPUT}
674 ENDIF (LATEX_USE_GLOSSARY)
677 SET(make_dvi_command ${make_dvi_command}
678 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
679 ${BIBTEX_COMPILER} ${BIBTEX_COMPILER_FLAGS} ${LATEX_TARGET})
680 SET(make_pdf_command ${make_pdf_command}
681 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
682 ${BIBTEX_COMPILER} ${BIBTEX_COMPILER_FLAGS} ${LATEX_TARGET})
683 FOREACH (bibfile ${LATEX_BIBFILES})
684 SET(make_dvi_depends ${make_dvi_depends} ${output_dir}/${bibfile})
685 SET(make_pdf_depends ${make_pdf_depends} ${output_dir}/${bibfile})
686 ENDFOREACH (bibfile ${LATEX_BIBFILES})
687 ENDIF (LATEX_BIBFILES)
690 SET(make_dvi_command ${make_dvi_command}
691 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
692 ${LATEX_COMPILER} ${LATEX_COMPILER_FLAGS} ${LATEX_MAIN_INPUT}
693 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
694 ${MAKEINDEX_COMPILER} ${MAKEINDEX_COMPILER_FLAGS} ${LATEX_TARGET}.idx
695 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
696 ${CMAKE_CURRENT_SOURCE_DIR}/subindex gromacs.ind > gromacs.sind
697 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
698 mv gromacs.sind gromacs.ind)
699 SET(make_pdf_command ${make_pdf_command}
700 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
701 ${PDFLATEX_COMPILER} ${PDFLATEX_COMPILER_FLAGS} ${LATEX_MAIN_INPUT}
702 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
703 ${MAKEINDEX_COMPILER} ${MAKEINDEX_COMPILER_FLAGS} ${LATEX_TARGET}.idx
704 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
705 ${CMAKE_CURRENT_SOURCE_DIR}/subindex gromacs.ind > gromacs.sind
706 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
707 mv gromacs.sind gromacs.ind
709 ENDIF (LATEX_USE_INDEX)
711 SET(make_dvi_command ${make_dvi_command}
712 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
713 ${LATEX_COMPILER} ${LATEX_COMPILER_FLAGS} ${LATEX_MAIN_INPUT}
714 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
715 ${LATEX_COMPILER} ${LATEX_COMPILER_FLAGS} ${LATEX_MAIN_INPUT})
716 SET(make_pdf_command ${make_pdf_command}
717 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
718 ${PDFLATEX_COMPILER} ${PDFLATEX_COMPILER_FLAGS} ${LATEX_MAIN_INPUT}
719 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
720 ${PDFLATEX_COMPILER} ${PDFLATEX_COMPILER_FLAGS} ${LATEX_MAIN_INPUT})
722 # Add commands and targets for building dvi outputs.
723 ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${LATEX_TARGET}.dvi
724 COMMAND ${make_dvi_command}
725 DEPENDS ${make_dvi_depends}
727 IF (LATEX_DEFAULT_PDF OR LATEX_DEFAULT_SAFEPDF)
728 ADD_CUSTOM_TARGET(${dvi_target}
729 DEPENDS ${output_dir}/${LATEX_TARGET}.dvi)
730 ELSE (LATEX_DEFAULT_PDF OR LATEX_DEFAULT_SAFEPDF)
731 ADD_CUSTOM_TARGET(${dvi_target}
732 DEPENDS ${output_dir}/${LATEX_TARGET}.dvi)
733 ENDIF (LATEX_DEFAULT_PDF OR LATEX_DEFAULT_SAFEPDF)
735 # Add commands and targets for building pdf outputs (with pdflatex).
736 IF (PDFLATEX_COMPILER)
737 ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${LATEX_TARGET}.pdf
738 COMMAND ${make_pdf_command}
739 DEPENDS ${make_pdf_depends}
741 IF (LATEX_DEFAULT_PDF)
742 ADD_CUSTOM_TARGET(${pdf_target}
743 DEPENDS ${output_dir}/${LATEX_TARGET}.pdf)
744 ELSE (LATEX_DEFAULT_PDF)
745 ADD_CUSTOM_TARGET(${pdf_target}
746 DEPENDS ${output_dir}/${LATEX_TARGET}.pdf)
747 ENDIF (LATEX_DEFAULT_PDF)
748 ENDIF (PDFLATEX_COMPILER)
751 ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${LATEX_TARGET}.ps
752 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
753 ${DVIPS_CONVERTER} ${DVIPS_CONVERTER_FLAGS} -o ${LATEX_TARGET}.ps ${LATEX_TARGET}.dvi
754 DEPENDS ${output_dir}/${LATEX_TARGET}.dvi)
755 ADD_CUSTOM_TARGET(${ps_target}
756 DEPENDS ${output_dir}/${LATEX_TARGET}.ps)
757 IF (PS2PDF_CONVERTER)
758 # Since both the pdf and safepdf targets have the same output, we
759 # cannot properly do the dependencies for both. When selecting safepdf,
760 # simply force a recompile every time.
761 IF (LATEX_DEFAULT_SAFEPDF)
762 ADD_CUSTOM_TARGET(${safepdf_target}
763 ${CMAKE_COMMAND} -E chdir ${output_dir}
764 ${PS2PDF_CONVERTER} ${PS2PDF_CONVERTER_FLAGS} ${LATEX_TARGET}.ps ${LATEX_TARGET}.pdf
766 ELSE (LATEX_DEFAULT_SAFEPDF)
767 ADD_CUSTOM_TARGET(${safepdf_target}
768 ${CMAKE_COMMAND} -E chdir ${output_dir}
769 ${PS2PDF_CONVERTER} ${PS2PDF_CONVERTER_FLAGS} ${LATEX_TARGET}.ps ${LATEX_TARGET}.pdf
771 ENDIF (LATEX_DEFAULT_SAFEPDF)
772 ADD_DEPENDENCIES(${safepdf_target} ${ps_target})
773 ENDIF (PS2PDF_CONVERTER)
774 ENDIF (DVIPS_CONVERTER)
776 IF (LATEX2HTML_CONVERTER)
777 ADD_CUSTOM_TARGET(${html_target}
778 ${CMAKE_COMMAND} -E chdir ${output_dir}
779 ${LATEX2HTML_CONVERTER} ${LATEX2HTML_CONVERTER_FLAGS} ${LATEX_MAIN_INPUT}
781 ADD_DEPENDENCIES(${html_target} ${LATEX_MAIN_INPUT} ${LATEX_INPUTS})
782 ENDIF (LATEX2HTML_CONVERTER)
784 ADD_CUSTOM_TARGET(${auxclean_target}
785 ${CMAKE_COMMAND} -E remove ${output_dir}/${LATEX_TARGET}.aux ${output_dir}/${LATEX_TARGET}.idx ${output_dir}/${LATEX_TARGET}.ind
787 ENDMACRO(ADD_LATEX_TARGETS)
789 MACRO(ADD_LATEX_DOCUMENT)
790 LATEX_GET_OUTPUT_PATH(output_dir)
792 PARSE_ADD_LATEX_ARGUMENTS(ADD_LATEX_DOCUMENT ${ARGV})
794 LATEX_COPY_INPUT_FILE(${LATEX_MAIN_INPUT})
796 FOREACH (bib_file ${LATEX_BIBFILES})
797 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${bib_file}
798 ${output_dir}/${bib_file}
800 ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${bib_file}
801 COMMAND ${CMAKE_COMMAND}
802 ARGS -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${bib_file} ${output_dir}/${bib_file}
803 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${bib_file}
805 ENDFOREACH (bib_file)
807 FOREACH (input ${LATEX_INPUTS})
808 LATEX_COPY_INPUT_FILE(${input})
811 LATEX_COPY_GLOBBED_FILES(${CMAKE_CURRENT_SOURCE_DIR}/*.cls ${output_dir})
812 LATEX_COPY_GLOBBED_FILES(${CMAKE_CURRENT_SOURCE_DIR}/*.bst ${output_dir})
813 LATEX_COPY_GLOBBED_FILES(${CMAKE_CURRENT_SOURCE_DIR}/*.clo ${output_dir})
814 LATEX_COPY_GLOBBED_FILES(${CMAKE_CURRENT_SOURCE_DIR}/*.sty ${output_dir})
816 ADD_LATEX_TARGETS(${ARGV})
818 ENDMACRO(ADD_LATEX_DOCUMENT)
820 #############################################################################
822 #############################################################################
824 IF (LATEX_BUILD_COMMAND)
827 IF ("${LATEX_BUILD_COMMAND}" STREQUAL makeglossaries)
828 LATEX_MAKEGLOSSARIES()
829 SET(command_handled TRUE)
830 ENDIF ("${LATEX_BUILD_COMMAND}" STREQUAL makeglossaries)
832 IF (NOT command_handled)
833 MESSAGE(SEND_ERROR "Unknown command: ${LATEX_BUILD_COMMAND}")
834 ENDIF (NOT command_handled)
836 ELSE (LATEX_BUILD_COMMAND)
837 # Must be part of the actual configure (included from CMakeLists.txt).
838 LATEX_SETUP_VARIABLES()
839 ENDIF (LATEX_BUILD_COMMAND)