CMakeUserUseLATEX UseLATEX.cmake: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
(Version 1.2.0)
(Version 1.3.0)
Line 4: Line 4:


<pre>
<pre>
#
# File: UseLATEX.cmake
# File: UseLATEX.cmake
# CMAKE commands to actually use the LaTeX compiler
# CMAKE commands to actually use the LaTeX compiler
# Version: 1.2.0
# Version: 1.3.0
# Author: Kenneth Moreland (kmorel at sandia dot gov)
# Author: Kenneth Moreland (kmorel at sandia dot gov)
#
#
Line 19: Line 18:
# The following MACROS are defined:
# The following MACROS are defined:
#
#
# ADD_LATEX_IMAGES(<dir>)
# ADD_LATEX_DOCUMENT(<tex_file>
#       Searches <dir> for images files and creates targets that convert
#                       [BIBFILES <bib_files>]
#       them to types that various LaTeX compilers understand.  Makes the
#                       [INPUTS <input_tex_files>]
#      targets latex_images_ps and latex_images_pdf.
#                      [IMAGE_DIRS] <image_directories>
#
#                      [IMAGES] <image_files>
# ADD_LATEX_DOCUMENT(<tex_file> [<image_dir>]
#                      [BIBFILES <bib_files>] [INPUTS <input_tex_files>]
#                      [CONFIGURE] <tex_files>
#                      [CONFIGURE] <tex_files>
#                      [USE_INDEX] [DEFAULT_PDF])
#                      [USE_INDEX] [DEFAULT_PDF])
#      Adds targets that compile <tex_file>.  It is assumed that
#      Adds targets that compile <tex_file>.  The latex output is placed
#      ADD_LATEX_IMAGES has been called in <image_dir>.  (Note that the
#      in LATEX_OUTPUT_PATH or CMAKE_CURRENT_BINARY_DIR if the former is
#      dir parameter is different for the two commands.) The latex
#      not set.  The latex program is picky about where files are located,
#      program is picky about where files are located, so all input files
#      so all input files are copied from the source directory to the
#      are copied from the source directory to the binary directory.  This
#      output directory.  This includes the target tex file, any tex file
#      includes the target tex file, any tex file listed with the INPUTS
#      listed with the INPUTS option, the bibliography files listed with
#      option, the bibliography files listed with the BIBFILES option, and
#      the BIBFILES option, and any .cls, .bst, and .clo files found in
#      any .cls, .bst, and .clo files found in the current source
#      the current source directory.  Images found in the IMAGE_DIRS
#      directory.  Any tex files also listed with the INPUTS option are
#      directories or listed by IMAGES are also copied to the output
#      also processed with the CMake CONFIGURE_FILE command (with the
#      directory and coverted to an appropriate format if necessary.  Any
#      @ONLY flag.  Any file listed in INPUTS but not the target tex file
#      tex files also listed with the CONFIGURE option are also processed
#      or listed with INPUTS has no effect.
#      with the CMake CONFIGURE_FILE command (with the @ONLY flag.  Any
#      file listed in CONFIGURE but not the target tex file or listed with
#      INPUTS has no effect.
#
#
#      The following targets are made:
#      The following targets are made:
Line 56: Line 55:
#      are made.
#      are made.
#
#
# ADD_LATEX_TARGETS(<tex_file> [<image_dir>]
# ADD_LATEX_TARGETS(<tex_file>
#                      [BIBFILES <bib_files>] [INPUTS <input_tex_files>]
#                      [BIBFILES <bib_files>]
#                      [USE_INDEX])
#                      [INPUTS <input_tex_files>]
#                      [IMAGE_DIRS] <image_directories>
#                      [IMAGES] <image_files>
#                      [CONFIGURE] <tex_files>
#                      [USE_INDEX] [DEFAULT_PDF])
#      Like ADD_LATEX_DOCUMENT, except no files are configured or copied.
#      Like ADD_LATEX_DOCUMENT, except no files are configured or copied.
#      The files are assumed to already be added to the binary directory.
#      The files are assumed to already be added to the output directory.
#      This varient is helpful if one set of latex files makes different
#      This varient is helpful if one set of latex files makes different
#      varients of documents.  For example, with building chapters
#      varients of documents.  For example, with building chapters
Line 66: Line 69:
#
#
# History:
# History:
#
# 1.3.0 Added a LATEX_OUTPUT_PATH variable that allows you or the user to
#      specify where the built latex documents to go.  This is especially
#      handy if you want to do in-source builds.
#
#      Removed the ADD_LATEX_IMAGES macro and absorbed the functionality
#      into ADD_LATEX_DOCUMENT.  The old interface was always kind of
#      clunky anyway since you had to specify the image directory in both
#      places.  It also made supporting LATEX_OUTPUT_PATH problematic.
#
#      Added support for jpeg files.
#
#
# 1.2.0 Changed the configuration options yet again.  Removed the NO_CONFIGURE
# 1.2.0 Changed the configuration options yet again.  Removed the NO_CONFIGURE
Line 90: Line 104:
#
#


IF ("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
SET(LATEX_OUTPUT_PATH "${LATEX_OUTPUT_PATH}"
   MESSAGE(SEND_ERROR "LaTeX files must be built out of source.")
   CACHE PATH "If non empty, specifies the location to place LaTeX output."
ENDIF ("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
  )


INCLUDE(${CMAKE_ROOT}/Modules/FindLATEX.cmake)
MACRO(LATEX_GET_OUTPUT_PATH var)
  SET(${var})
  IF (LATEX_OUTPUT_PATH)
    IF ("${LATEX_OUTPUT_PATH}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
      MESSAGE(SEND_ERROR "You cannot set LATEX_OUTPUT_PATH to the same directory that contains LaTeX input files.")
    ELSE ("${LATEX_OUTPUT_PATH}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
      SET(${var} "${LATEX_OUTPUT_PATH}")
    ENDIF ("${LATEX_OUTPUT_PATH}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
  ELSE (LATEX_OUTPUT_PATH)
    IF ("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
      MESSAGE(SEND_ERROR "LaTeX files must be built out of source or you must set LATEX_OUTPUT_PATH.")
    ELSE ("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
      SET(${var} "${CMAKE_CURRENT_BINARY_DIR}")
    ENDIF ("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
  ENDIF (LATEX_OUTPUT_PATH)
ENDMACRO(LATEX_GET_OUTPUT_PATH)
 
FIND_PACKAGE(LATEX)
MARK_AS_ADVANCED(CLEAR
MARK_AS_ADVANCED(CLEAR
   LATEX_COMPILER
   LATEX_COMPILER
Line 173: Line 204:
ENDIF (LATEX_SMALL_IMAGES)
ENDIF (LATEX_SMALL_IMAGES)


# Helpful list macros.
MACRO(LATEX_CAR var)
MACRO(LATEX_CAR var)
   SET(${var} ${ARGV1})
   SET(${var} ${ARGV1})
Line 180: Line 212:
ENDMACRO(LATEX_CDR)
ENDMACRO(LATEX_CDR)


MACRO(ADD_LATEX_IMAGES dir)
MACRO(LATEX_LIST_CONTAINS var value)
   FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${dir})
   SET(${var})
  FOREACH (value2 ${ARGN})
    IF (${value} STREQUAL ${value2})
      SET(${var} TRUE)
    ENDIF (${value} STREQUAL ${value2})
  ENDFOREACH (value2)
ENDMACRO(LATEX_LIST_CONTAINS)
 
# Just holds extensions for known image types.  They should all be lower case.
SET(LATEX_DVI_VECTOR_IMAGE_EXTENSIONS .eps)
SET(LATEX_DVI_RASTER_IMAGE_EXTENSIONS)
SET(LATEX_DVI_IMAGE_EXTENSIONS
  ${LATEX_DVI_VECTOR_IMAGE_EXTENSIONS} ${LATEX_DVI_RASTER_IMAGE_EXTENSIONS})
SET(LATEX_PDF_VECTOR_IMAGE_EXTENSIONS .pdf)
SET(LATEX_PDF_RASTER_IMAGE_EXTENSIONS .png .jpeg .jpg)
SET(LATEX_PDF_IMAGE_EXTENSIONS
  ${LATEX_PDF_VECTOR_IMAGE_EXTENSIONS} ${LATEX_PDF_RASTER_IMAGE_EXTENSIONS})
SET(LATEX_IMAGE_EXTENSIONS
  ${LATEX_DVI_IMAGE_EXTENSIONS} ${LATEX_PDF_IMAGE_EXTENSIONS})
 
# Makes custom commands to convert a file to a particular type.
MACRO(LATEX_CONVERT_IMAGE output_files input_file output_extension convert_flags
    output_extensions other_files)
  SET(input_dir ${CMAKE_CURRENT_SOURCE_DIR})
  LATEX_GET_OUTPUT_PATH(output_dir)
 
  GET_FILENAME_COMPONENT(extension "${input_file}" EXT)


   # This command just makes sure we rebuild images of LATEX_SMALL_IMAGES
   STRING(REGEX REPLACE "\\.[^.]*\$" ${output_extension} output_file
  # changed.
     "${input_file}")
  ADD_CUSTOM_COMMAND(OUTPUT raster_image_rescale_${LATEX_RASTER_SCALE}
    COMMAND ${CMAKE_COMMAND}
     ARGS -E remove raster_image_rescale_${LATEX_OPPOSITE_RASTER_SCALE} \; ${CMAKE_COMMAND} -E echo Built > raster_image_rescale_${LATEX_RASTER_SCALE}
    )


   FILE(GLOB png_file_list ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*.png)
   LATEX_LIST_CONTAINS(is_type ${extension} ${output_extensions})
   FOREACH (png_file ${png_file_list})
   IF (is_type)
     GET_FILENAME_COMPONENT(image_name ${png_file} NAME_WE)
     IF (convert_flags)
    SET(png_out_file ${CMAKE_CURRENT_BINARY_DIR}/${dir}/${image_name}.png)
      ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${output_file}
    ADD_CUSTOM_COMMAND(OUTPUT ${png_out_file}
      COMMAND ${IMAGEMAGICK_CONVERT}
      ARGS ${png_file} -resize ${LATEX_RASTER_SCALE}% ${png_out_file}
      DEPENDS ${png_file} raster_image_rescale_${LATEX_RASTER_SCALE}
      COMMENT "png image"
      )
    SET(OUT_PNG_FILES ${OUT_PNG_FILES} ${png_out_file})
    IF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${image_name}.eps)
      # An eps file already exists.  No need to convert.
    ELSE (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${image_name}.eps)
      SET(eps_file ${CMAKE_CURRENT_BINARY_DIR}/${dir}/${image_name}.eps)
      ADD_CUSTOM_COMMAND(OUTPUT ${eps_file}
         COMMAND ${IMAGEMAGICK_CONVERT}
         COMMAND ${IMAGEMAGICK_CONVERT}
         ARGS ${png_file} -resize ${LATEX_RASTER_SCALE}% ${eps_file}
         ARGS ${input_dir}/${input_file} ${convert_flags}
         DEPENDS ${png_file} raster_image_rescale_${LATEX_RASTER_SCALE}
          ${output_dir}/${output_file}
         COMMENT "postscript image"
         DEPENDS ${input_dir}/${input_file}
        )
      SET(${output_files} ${${output_files}} ${output_dir}/${output_file})
    ELSE (convert_flags)
      # As a shortcut, we can just copy the file.
      ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${input_file}
        COMMAND ${CMAKE_COMMAND}
         ARGS -E copy ${input_dir}/${input_file} ${output_dir}/${input_file}
        DEPENDS ${input_dir}/${input_file}
         )
         )
       SET(OUT_EPS_FILES ${OUT_EPS_FILES} ${eps_file})
       SET(${output_files} ${${output_files}} ${output_dir}/${input_file})
    ENDIF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${image_name}.eps)
    ENDIF (convert_flags)
  ENDFOREACH (png_file)
   ELSE (is_type)
 
     SET(do_convert TRUE)
   FILE(GLOB eps_file_list ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*.eps)
     # Check to see if there is another input file of the appropriate type.
  FOREACH (eps_file ${eps_file_list})
     FOREACH(valid_extension ${output_extensions})
     GET_FILENAME_COMPONENT(image_name ${eps_file} NAME_WE)
       STRING(REGEX REPLACE "\\.[^.]*\$" ${output_extension} try_file
     IF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${image_name}.pdf)
         "${input_file}")
      # A pdf file already exists.  No need to convert.
      LATEX_LIST_CONTAINS(has_native_file "${try_file}" ${other_files})
     ELSE (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${image_name}.pdf)
       IF (has_native_file)
       IF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${image_name}.png)
        SET(do_convert FALSE)
        # A png file already exists. No need to convert.
      ENDIF (has_native_file)
      ELSE (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${image_name}.png)
     ENDFOREACH(valid_extension)
         SET(pdf_file ${CMAKE_CURRENT_BINARY_DIR}/${dir}/${image_name}.pdf)
        ADD_CUSTOM_COMMAND(OUTPUT ${pdf_file}
          COMMAND ${IMAGEMAGICK_CONVERT}
          ARGS ${eps_file} ${pdf_file}
          DEPENDS ${eps_file}
          COMMENT "pdf image"
          )
        SET(OUT_PDF_FILES ${OUT_PDF_FILES} ${pdf_file})
       ENDIF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${image_name}.png)
    ENDIF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${image_name}.pdf)
    SET(eps_out_file ${CMAKE_CURRENT_BINARY_DIR}/${dir}/${image_name}.eps)
    ADD_CUSTOM_COMMAND(OUTPUT ${eps_out_file}
      COMMAND ${CMAKE_COMMAND}
      ARGS -E copy ${eps_file} ${eps_out_file}
      DEPENDS ${eps_file}
      COMMENT "postscript image"
      )
     SET(OUT_EPS_FILES ${OUT_EPS_FILES} ${eps_out_file})
  ENDFOREACH (eps_file)


  FILE(GLOB pdf_file_list ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*.pdf)
     # If we still need to convert, do it.
  FOREACH (pdf_file ${pdf_file_list})
     IF (do_convert)
    GET_FILENAME_COMPONENT(image_name ${pdf_file} NAME_WE)
       ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${output_file}
    SET(pdf_out_file ${CMAKE_CURRENT_BINARY_DIR}/${dir}/${image_name}.pdf)
    ADD_CUSTOM_COMMAND(OUTPUT ${pdf_out_file}
      COMMAND ${CMAKE_COMMAND}
      ARGS -E copy ${pdf_file} ${pdf_out_file}
      DEPENDS ${pdf_file}
      COMMENT "pdf image"
      )
     SET(OUT_PDF_FILES ${OUT_PDF_FILES} ${pdf_out_file})
    IF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${image_name}.eps)
      # An eps file already exists.  No need to convert
     ELSE (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${image_name}.eps)
       SET(eps_file ${CMAKE_CURRENT_BINARY_DIR}/${dir}/${image_name}.eps)
      ADD_CUSTOM_COMMAND(OUTPUT ${eps_file}
         COMMAND ${IMAGEMAGICK_CONVERT}
         COMMAND ${IMAGEMAGICK_CONVERT}
         ARGS ${pdf_file} ${eps_file}
         ARGS ${input_dir}/${input_file} ${convert_flags}
         DEPENDS ${pdf_file}
          ${output_dir}/${output_file}
        COMMENT "postscript image"
         DEPENDS ${input_dir}/${input_file}
         )
         )
       SET(OUT_EPS_FILES ${OUT_EPS_FILES} ${eps_file})
       SET(${output_files} ${${output_files}} ${output_dir}/${output_file})
     ENDIF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${image_name}.eps)
     ENDIF (do_convert)
  ENDFOREACH (pdf_file)
  ENDIF (is_type)
ENDMACRO(LATEX_CONVERT_IMAGE)
 
# Adds custom commands to process the given files for dvi and pdf builds.
# Adds the output files to the given variables (does not replace).
MACRO(LATEX_PROCESS_IMAGES dvi_outputs pdf_outputs)
  LATEX_GET_OUTPUT_PATH(output_dir)
  FOREACH(file ${ARGN})
    IF (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
      GET_FILENAME_COMPONENT(extension "${file}" EXT)
      SET(convert_flags)
 
      # Check to see if we need to downsample the image.
      LATEX_LIST_CONTAINS(is_raster extension
        ${LATEX_DVI_RASTER_IMAGE_EXTENSIONS}
        ${LATEX_PDF_RASTER_IMAGE_EXTENSIONS})
      IF (LATEX_SMALL_IMAGES)
        IF (is_raster)
          SET(convert_flags -resize ${LATEX_RASTER_SCALE}%)
        ENDIF (is_raster)
      ENDIF (LATEX_SMALL_IMAGES)
 
      # Make sure the output directory exists.
      GET_FILENAME_COMPONENT(path "${output_dir}/${file}" PATH)
      MAKE_DIRECTORY("${path}")


  ADD_CUSTOM_TARGET(latex_images_ps
      # Do conversions for dvi.
    ${CMAKE_COMMAND} -E echo "Building image files for ps documents."
      LATEX_CONVERT_IMAGE(${dvi_outputs} "${file}" .eps "${convert_flags}"
    DEPENDS ${OUT_EPS_FILES}
        "${LATEX_DVI_IMAGE_EXTENSIONS}" "${ARGN}")
     )
 
  ADD_CUSTOM_TARGET(latex_images_pdf
      # Do conversions for pdf.
     DEPENDS ${OUT_PNG_FILES} ${OUT_PDF_FILES})
      IF (is_raster)
        LATEX_CONVERT_IMAGE(${pdf_outputs} "${file}" .png "${convert_flags}"
          "${LATEX_PDF_IMAGE_EXTENSIONS}" "${ARGN}")
      ELSE (is_raster)
        LATEX_CONVERT_IMAGE(${pdf_outputs} "${file}" .pdf "${convert_flags}"
          "${LATEX_PDF_IMAGE_EXTENSIONS}" "${ARGN}")
      ENDIF (is_raster)
     ELSE (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
      MESSAGE("Could not find file \"${CMAKE_CURRENT_SOURCE_DIR}/${file}\"")
     ENDIF (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
  ENDFOREACH(file)
ENDMACRO(LATEX_PROCESS_IMAGES)
 
MACRO(ADD_LATEX_IMAGES)
  MESSAGE("The ADD_LATEX_IMAGES macro is deprecated.  Image directories are specified with LATEX_ADD_DOCUMENT.")
ENDMACRO(ADD_LATEX_IMAGES)
ENDMACRO(ADD_LATEX_IMAGES)


Line 285: Line 341:
   ENDFOREACH(in_file)
   ENDFOREACH(in_file)
ENDMACRO(LATEX_COPY_GLOBBED_FILES)
ENDMACRO(LATEX_COPY_GLOBBED_FILES)
MACRO(LATEX_LIST_CONTAINS var value)
  SET(${var})
  FOREACH (value2 ${ARGN})
    IF (${value} STREQUAL ${value2})
      SET(${var} TRUE)
    ENDIF (${value} STREQUAL ${value2})
  ENDFOREACH (value2)
ENDMACRO(LATEX_LIST_CONTAINS)


MACRO(LATEX_PARSE_ARGUMENTS prefix arg_names option_names)
MACRO(LATEX_PARSE_ARGUMENTS prefix arg_names option_names)
Line 326: Line 373:
MACRO(LATEX_USAGE command message)
MACRO(LATEX_USAGE command message)
   MESSAGE(SEND_ERROR
   MESSAGE(SEND_ERROR
     "${message}\nUsage: ${command}(<tex_file> [<image_dir>]\n          [BIBFILES <bib_file> <bib_file> ...]\n          [INPUTS <tex_file> <tex_file> ...]\n          [CONFIGURE <tex_file> <tex_file> ...]\n          [USE_INDEX] [DEFAULT_PDF])"
     "${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          [USE_INDEX] [DEFAULT_PDF])"
     )
     )
ENDMACRO(LATEX_USAGE command message)
ENDMACRO(LATEX_USAGE command message)
Line 336: Line 383:
   LATEX_PARSE_ARGUMENTS(
   LATEX_PARSE_ARGUMENTS(
     LATEX
     LATEX
     "BIBFILES;INPUTS;CONFIGURE"
     "BIBFILES;INPUTS;IMAGE_DIRS;IMAGES;CONFIGURE"
     "USE_INDEX;DEFAULT_PDF"
     "USE_INDEX;DEFAULT_PDF"
     ${ARGN}
     ${ARGN}
Line 350: Line 397:
   ENDIF (LATEX_DEFAULT_ARGS)
   ENDIF (LATEX_DEFAULT_ARGS)


  # The second argument is the (optional) image dir.
  IF (LATEX_DEFAULT_ARGS)
    LATEX_CAR(LATEX_IMAGE_DIR ${LATEX_DEFAULT_ARGS})
    LATEX_CDR(LATEX_DEFAULT_ARGS ${LATEX_DEFAULT_ARGS})
    IF ("${LATEX_IMAGE_DIR}" STREQUAL NONE)
      # Backward compatibility
      SET(LATEX_IMAGE_DIR)
    ENDIF ("${LATEX_IMAGE_DIR}" STREQUAL NONE)
  ENDIF (LATEX_DEFAULT_ARGS)
  # Old versions of UseLATEX.cmake had a bibtex file as the third argument.
   IF (LATEX_DEFAULT_ARGS)
   IF (LATEX_DEFAULT_ARGS)
     IF ("${LATEX_DEFAULT_ARGS}" STREQUAL NONE)
     LATEX_USAGE(${command} "Invalid or depricated arguments: ${LATEX_DEFAULT_ARGS}")
      # Backward compatibility
    ELSE ("${LATEX_DEFAULT_ARGS}" STREQUAL NONE)
      SET(LATEX_BIBFILES ${LATEX_DEFAULT_ARGS})
    ENDIF ("${LATEX_DEFAULT_ARGS}" STREQUAL NONE)
   ENDIF (LATEX_DEFAULT_ARGS)
   ENDIF (LATEX_DEFAULT_ARGS)
ENDMACRO(PARSE_ADD_LATEX_ARGUMENTS)
ENDMACRO(PARSE_ADD_LATEX_ARGUMENTS)


MACRO(ADD_LATEX_TARGETS)
MACRO(ADD_LATEX_TARGETS)
  LATEX_GET_OUTPUT_PATH(output_dir)
   PARSE_ADD_LATEX_ARGUMENTS(ADD_LATEX_TARGETS ${ARGV})
   PARSE_ADD_LATEX_ARGUMENTS(ADD_LATEX_TARGETS ${ARGV})


   IF (LATEX_IMAGE_DIR)
   # For each directory in LATEX_IMAGE_DIRS, glob all the image files and
    IF (${LATEX_IMAGE_DIR} MATCHES ^[.]?$)
  # place them in LATEX_IMAGES.
      # Do not need to do anything, targets should already be made.
  FOREACH(dir ${LATEX_IMAGE_DIRS})
     ELSE (${LATEX_IMAGE_DIR} MATCHES ^[.]?$)
     FOREACH(extension ${LATEX_IMAGE_EXTENSIONS})
       ADD_CUSTOM_TARGET(latex_images_ps
       FILE(GLOB files ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*${extension})
        ${CMAKE_COMMAND} -E chdir ${LATEX_IMAGE_DIR} ${CMAKE_MAKE_PROGRAM} latex_images_ps)
       FOREACH(file ${files})
       ADD_CUSTOM_TARGET(latex_images_pdf
        GET_FILENAME_COMPONENT(filename ${file} NAME)
         ${CMAKE_COMMAND} -E chdir ${LATEX_IMAGE_DIR} ${CMAKE_MAKE_PROGRAM} latex_images_pdf)
         SET(LATEX_IMAGES ${LATEX_IMAGES} ${dir}/${filename})
     ENDIF (${LATEX_IMAGE_DIR} MATCHES ^[.]?$)
      ENDFOREACH(file)
   ELSE (LATEX_IMAGE_DIR)
     ENDFOREACH(extension)
    # No image directory.  Fake image targets.
   ENDFOREACH(dir)
    ADD_CUSTOM_TARGET(latex_images_ps)
 
    ADD_CUSTOM_TARGET(latex_images_pdf)
  SET(dvi_images)
   ENDIF (LATEX_IMAGE_DIR)
  SET(pdf_images)
   LATEX_PROCESS_IMAGES(dvi_images pdf_images ${LATEX_IMAGES})


   SET(make_dvi_command
   SET(make_dvi_command
    ${CMAKE_COMMAND} -E chdir ${output_dir}
     ${LATEX_COMPILER} ${LATEX_COMPILER_FLAGS} ${LATEX_TARGET}.tex)
     ${LATEX_COMPILER} ${LATEX_COMPILER_FLAGS} ${LATEX_TARGET}.tex)
  SET(make_dvi_depends ${LATEX_TARGET}.tex ${LATEX_INPUTS})
   SET(make_pdf_command
   SET(make_pdf_command
    ${CMAKE_COMMAND} -E chdir ${output_dir}
     ${PDFLATEX_COMPILER} ${PDFLATEX_COMPILER_FLAGS} ${LATEX_TARGET}.tex)
     ${PDFLATEX_COMPILER} ${PDFLATEX_COMPILER_FLAGS} ${LATEX_TARGET}.tex)
   SET(make_pdf_depends ${LATEX_TARGET}.tex ${LATEX_INPUTS})
 
  SET(make_dvi_depends ${dvi_images})
   SET(make_pdf_depends ${pdf_images})
  FOREACH(input ${LATEX_TARGET}.tex ${LATEX_INPUTS})
    SET(make_dvi_depends ${make_dvi_depends} ${output_dir}/${input})
    SET(make_pdf_depends ${make_pdf_depends} ${output_dir}/${input})
  ENDFOREACH(input)


   IF (LATEX_BIBFILES)
   IF (LATEX_BIBFILES)
     SET(make_dvi_command ${make_dvi_command}
     SET(make_dvi_command ${make_dvi_command}
       COMMAND ${BIBTEX_COMPILER} ${BIBTEX_COMPILER_FLAGS} ${LATEX_TARGET})
       COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
      ${BIBTEX_COMPILER} ${BIBTEX_COMPILER_FLAGS} ${LATEX_TARGET})
     SET(make_pdf_command ${make_pdf_command}
     SET(make_pdf_command ${make_pdf_command}
       COMMAND ${BIBTEX_COMPILER} ${BIBTEX_COMPILER_FLAGS} ${LATEX_TARGET})
       COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
     SET(make_dvi_depends ${make_dvi_depends} ${LATEX_BIBFILES})
      ${BIBTEX_COMPILER} ${BIBTEX_COMPILER_FLAGS} ${LATEX_TARGET})
    SET(make_pdf_depends ${make_pdf_depends} ${LATEX_BIBFILES})
     FOREACH (bibfile ${LATEX_BIBFILES})
      SET(make_dvi_depends ${make_dvi_depends} ${output_dir}/${bibfile})
      SET(make_pdf_depends ${make_pdf_depends} ${output_dir}/${bibfile})
    ENDFOREACH (bibfile ${LATEX_BIBFILES})
   ENDIF (LATEX_BIBFILES)
   ENDIF (LATEX_BIBFILES)


   IF (LATEX_USE_INDEX)
   IF (LATEX_USE_INDEX)
     SET(make_dvi_command ${make_dvi_command}
     SET(make_dvi_command ${make_dvi_command}
       COMMAND ${LATEX_COMPILER} ${LATEX_COMPILER_FLAGS} ${LATEX_TARGET}.tex
       COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
       COMMAND ${MAKEINDEX_COMPILER} ${MAKEINDEX_COMPILER_FLAGS} ${LATEX_TARGET}.idx)
      ${LATEX_COMPILER} ${LATEX_COMPILER_FLAGS} ${LATEX_TARGET}.tex
       COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
      ${MAKEINDEX_COMPILER} ${MAKEINDEX_COMPILER_FLAGS} ${LATEX_TARGET}.idx)
     SET(make_pdf_command ${make_pdf_command}
     SET(make_pdf_command ${make_pdf_command}
       COMMAND ${PDFLATEX_COMPILER} ${PDFLATEX_COMPILER_FLAGS} ${LATEX_TARGET}.tex
       COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
       COMMAND ${MAKEINDEX_COMPILER} ${MAKEINDEX_COMPILER_FLAGS} ${LATEX_TARGET}.idx)
      ${PDFLATEX_COMPILER} ${PDFLATEX_COMPILER_FLAGS} ${LATEX_TARGET}.tex
       COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
      ${MAKEINDEX_COMPILER} ${MAKEINDEX_COMPILER_FLAGS} ${LATEX_TARGET}.idx)
   ENDIF (LATEX_USE_INDEX)
   ENDIF (LATEX_USE_INDEX)


   SET(make_dvi_command ${make_dvi_command}
   SET(make_dvi_command ${make_dvi_command}
     COMMAND ${LATEX_COMPILER} ${LATEX_COMPILER_FLAGS} ${LATEX_TARGET}.tex
     COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
     COMMAND ${LATEX_COMPILER} ${LATEX_COMPILER_FLAGS} ${LATEX_TARGET}.tex)
    ${LATEX_COMPILER} ${LATEX_COMPILER_FLAGS} ${LATEX_TARGET}.tex
     COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
    ${LATEX_COMPILER} ${LATEX_COMPILER_FLAGS} ${LATEX_TARGET}.tex)
   SET(make_pdf_command ${make_pdf_command}
   SET(make_pdf_command ${make_pdf_command}
     COMMAND ${PDFLATEX_COMPILER} ${PDFLATEX_COMPILER_FLAGS} ${LATEX_TARGET}.tex
     COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
     COMMAND ${PDFLATEX_COMPILER} ${PDFLATEX_COMPILER_FLAGS} ${LATEX_TARGET}.tex)
    ${PDFLATEX_COMPILER} ${PDFLATEX_COMPILER_FLAGS} ${LATEX_TARGET}.tex
     COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
    ${PDFLATEX_COMPILER} ${PDFLATEX_COMPILER_FLAGS} ${LATEX_TARGET}.tex)


   IF (LATEX_DEFAULT_PDF)
   IF (LATEX_DEFAULT_PDF)
     ADD_CUSTOM_TARGET(dvi ${make_dvi_command})
     ADD_CUSTOM_TARGET(dvi ${make_dvi_command}
      DEPENDS ${make_dvi_depends})
   ELSE (LATEX_DEFAULT_PDF)
   ELSE (LATEX_DEFAULT_PDF)
     ADD_CUSTOM_TARGET(dvi ALL ${make_dvi_command})
     ADD_CUSTOM_TARGET(dvi ALL ${make_dvi_command}
      DEPENDS ${make_dvi_depends})
   ENDIF (LATEX_DEFAULT_PDF)
   ENDIF (LATEX_DEFAULT_PDF)
  ADD_DEPENDENCIES(dvi ${make_dvi_depends} latex_images_ps)


   IF (PDFLATEX_COMPILER)
   IF (PDFLATEX_COMPILER)
     IF (LATEX_DEFAULT_PDF)
     IF (LATEX_DEFAULT_PDF)
       ADD_CUSTOM_TARGET(pdf ALL ${make_pdf_command})
       ADD_CUSTOM_TARGET(pdf ALL ${make_pdf_command}
        DEPENDS ${make_pdf_depends})
     ELSE (LATEX_DEFAULT_PDF)
     ELSE (LATEX_DEFAULT_PDF)
       ADD_CUSTOM_TARGET(pdf ${make_pdf_command})
       ADD_CUSTOM_TARGET(pdf ${make_pdf_command}
        DEPENDS ${make_pdf_depends})
     ENDIF (LATEX_DEFAULT_PDF)
     ENDIF (LATEX_DEFAULT_PDF)
    ADD_DEPENDENCIES(pdf ${make_pdf_depends} latex_images_pdf)
   ENDIF (PDFLATEX_COMPILER)
   ENDIF (PDFLATEX_COMPILER)


   IF (DVIPS_CONVERTER)
   IF (DVIPS_CONVERTER)
     ADD_CUSTOM_TARGET(ps
     ADD_CUSTOM_TARGET(ps
      ${CMAKE_COMMAND} -E chdir ${output_dir}
       ${DVIPS_CONVERTER} ${DVIPS_CONVERTER_FLAGS} -o ${LATEX_TARGET}.ps ${LATEX_TARGET}.dvi
       ${DVIPS_CONVERTER} ${DVIPS_CONVERTER_FLAGS} -o ${LATEX_TARGET}.ps ${LATEX_TARGET}.dvi
       )
       )
Line 443: Line 499:
     IF (PS2PDF_CONVERTER)
     IF (PS2PDF_CONVERTER)
       ADD_CUSTOM_TARGET(safepdf
       ADD_CUSTOM_TARGET(safepdf
        ${CMAKE_COMMAND} -E chdir ${output_dir}
         ${PS2PDF_CONVERTER} ${PS2PDF_CONVERTER_FLAGS} ${LATEX_TARGET}.ps ${LATEX_TARGET}.pdf
         ${PS2PDF_CONVERTER} ${PS2PDF_CONVERTER_FLAGS} ${LATEX_TARGET}.ps ${LATEX_TARGET}.pdf
         )
         )
Line 451: Line 508:
   IF (LATEX2HTML_CONVERTER)
   IF (LATEX2HTML_CONVERTER)
     ADD_CUSTOM_TARGET(html
     ADD_CUSTOM_TARGET(html
      ${CMAKE_COMMAND} -E chdir ${output_dir}
       ${LATEX2HTML_CONVERTER} ${LATEX2HTML_CONVERTER_FLAGS} ${LATEX_TARGET}.tex
       ${LATEX2HTML_CONVERTER} ${LATEX2HTML_CONVERTER_FLAGS} ${LATEX_TARGET}.tex
       )
       )
Line 457: Line 515:


   ADD_CUSTOM_TARGET(auxclean
   ADD_CUSTOM_TARGET(auxclean
     ${CMAKE_COMMAND} -E remove ${LATEX_TARGET}.aux ${LATEX_TARGET}.idx ${LATEX_TARGET}.ind
     ${CMAKE_COMMAND} -E remove ${output_dir}/${LATEX_TARGET}.aux ${output_dir}/${LATEX_TARGET}.idx ${output_dir}/${LATEX_TARGET}.ind
     )
     )
ENDMACRO(ADD_LATEX_TARGETS)
ENDMACRO(ADD_LATEX_TARGETS)


MACRO(LATEX_COPY_TEX_FILE file)
MACRO(LATEX_COPY_TEX_FILE file)
  LATEX_GET_OUTPUT_PATH(output_dir)
   GET_FILENAME_COMPONENT(file_we ${file} NAME_WE)
   GET_FILENAME_COMPONENT(file_we ${file} NAME_WE)
   LATEX_LIST_CONTAINS(use_config1 ${file_we} ${LATEX_CONFIGURE})
   LATEX_LIST_CONTAINS(use_config1 ${file_we} ${LATEX_CONFIGURE})
   LATEX_LIST_CONTAINS(use_config2 ${file_we}.tex ${LATEX_CONFIGURE})
   LATEX_LIST_CONTAINS(use_config2 ${file_we}.tex ${LATEX_CONFIGURE})
   IF (use_config1 OR use_config2)
   IF (use_config1 OR use_config2)
     SET(latex_config_flags @ONLY)
     CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${file_we}.tex
      ${output_dir}/${file_we}.tex
      @ONLY
      )
    ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${file_we}.tex
      COMMAND ${CMAKE_COMMAND}
      ARGS ${CMAKE_BINARY_DIR}
      DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file_we}.tex
      )
   ELSE (use_config1 OR use_config2)
   ELSE (use_config1 OR use_config2)
     SET(latex_config_flags COPYONLY)
     ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${file_we}.tex
      COMMAND ${CMAKE_COMMAND}
      ARGS -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${file_we}.tex ${output_dir}/${file_we}.tex
      DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file_we}.tex
      )
   ENDIF (use_config1 OR use_config2)
   ENDIF (use_config1 OR use_config2)
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${file_we}.tex
 
    ${file_we}.tex
    ${latex_config_flags}
    )
  ADD_CUSTOM_TARGET(${file_we}.tex
    ${CMAKE_COMMAND} .
    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file_we}.tex
    )
ENDMACRO(LATEX_COPY_TEX_FILE)
ENDMACRO(LATEX_COPY_TEX_FILE)


MACRO(ADD_LATEX_DOCUMENT)
MACRO(ADD_LATEX_DOCUMENT)
   PARSE_ADD_LATEX_ARGUMENTS(ADD_LATEX_DOCUMENT ${ARGV})
   LATEX_GET_OUTPUT_PATH(output_dir)
  IF (output_dir)
    PARSE_ADD_LATEX_ARGUMENTS(ADD_LATEX_DOCUMENT ${ARGV})


  LATEX_COPY_TEX_FILE(${LATEX_TARGET})
    LATEX_COPY_TEX_FILE(${LATEX_TARGET})


  FOREACH (bib_file ${LATEX_BIBFILES})
    FOREACH (bib_file ${LATEX_BIBFILES})
    CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${bib_file}
      CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${bib_file}
      ${bib_file}
        ${output_dir}/${bib_file}
      COPYONLY)
        COPYONLY)
    ADD_CUSTOM_TARGET(${bib_file}
      ADD_CUSTOM_TARGET(${output_dir}/${bib_file}
      ${CMAKE_COMMAND} .
        ${CMAKE_COMMAND} .
      DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${bib_file}
        DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${bib_file}
      )
        )
  ENDFOREACH (bib_file)
    ENDFOREACH (bib_file)


  FOREACH (input ${LATEX_INPUTS})
    FOREACH (input ${LATEX_INPUTS})
    LATEX_COPY_TEX_FILE(${input})
      LATEX_COPY_TEX_FILE(${input})
  ENDFOREACH(input)
    ENDFOREACH(input)


  LATEX_COPY_GLOBBED_FILES(${CMAKE_CURRENT_SOURCE_DIR}/*.cls .)
    LATEX_COPY_GLOBBED_FILES(${CMAKE_CURRENT_SOURCE_DIR}/*.cls ${output_dir})
  LATEX_COPY_GLOBBED_FILES(${CMAKE_CURRENT_SOURCE_DIR}/*.bst .)
    LATEX_COPY_GLOBBED_FILES(${CMAKE_CURRENT_SOURCE_DIR}/*.bst ${output_dir})
  LATEX_COPY_GLOBBED_FILES(${CMAKE_CURRENT_SOURCE_DIR}/*.clo .)
    LATEX_COPY_GLOBBED_FILES(${CMAKE_CURRENT_SOURCE_DIR}/*.clo ${output_dir})


  ADD_LATEX_TARGETS(${ARGV})
    ADD_LATEX_TARGETS(${ARGV})
  ENDIF (output_dir)
ENDMACRO(ADD_LATEX_DOCUMENT)
ENDMACRO(ADD_LATEX_DOCUMENT)
</pre>
</pre>

Revision as of 16:25, 8 May 2006

  1. Back

# File: UseLATEX.cmake
# CMAKE commands to actually use the LaTeX compiler
# Version: 1.3.0
# Author: Kenneth Moreland (kmorel at sandia dot gov)
#
# Copyright 2004 Sandia Corporation.
# Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
# license for use of this work by or on behalf of the
# U.S. Government. Redistribution and use in source and binary forms, with
# or without modification, are permitted provided that this Notice and any
# statement of authorship are reproduced on all copies.
#
# The following MACROS are defined:
#
# ADD_LATEX_DOCUMENT(<tex_file>
#                       [BIBFILES <bib_files>]
#                       [INPUTS <input_tex_files>]
#                       [IMAGE_DIRS] <image_directories>
#                       [IMAGES] <image_files>
#                       [CONFIGURE] <tex_files>
#                       [USE_INDEX] [DEFAULT_PDF])
#       Adds targets that compile <tex_file>.  The latex output is placed
#       in LATEX_OUTPUT_PATH or CMAKE_CURRENT_BINARY_DIR if the former is
#       not set.  The latex program is picky about where files are located,
#       so all input files are copied from the source directory to the
#       output directory.  This includes the target tex file, any tex file
#       listed with the INPUTS option, the bibliography files listed with
#       the BIBFILES option, and any .cls, .bst, and .clo files found in
#       the current source directory.  Images found in the IMAGE_DIRS
#       directories or listed by IMAGES are also copied to the output
#       directory and coverted to an appropriate format if necessary.  Any
#       tex files also listed with the CONFIGURE option are also processed
#       with the CMake CONFIGURE_FILE command (with the @ONLY flag.  Any
#       file listed in CONFIGURE but not the target tex file or listed with
#       INPUTS has no effect.
#
#       The following targets are made:
#               dvi: Makes <name>.dvi
#               pdf: Makes <name>.pdf using pdflatex.
#               safepdf: Makes <name>.pdf using ps2pdf.  If using the default
#                       program arguments, this will ensure all fonts are
#                       embedded and no lossy compression has been performed
#                       on images.
#               ps: Makes <name>.ps
#               html: Makes <name>.html
#               auxclean: Deletes <name>.aux.  This is sometimes necessary
#                       if a LaTeX error occurs and writes a bad aux file.
#
#       If the argument USE_INDEX is given, then commands to build an index
#       are made.
#
# ADD_LATEX_TARGETS(<tex_file>
#                       [BIBFILES <bib_files>]
#                       [INPUTS <input_tex_files>]
#                       [IMAGE_DIRS] <image_directories>
#                       [IMAGES] <image_files>
#                       [CONFIGURE] <tex_files>
#                       [USE_INDEX] [DEFAULT_PDF])
#       Like ADD_LATEX_DOCUMENT, except no files are configured or copied.
#       The files are assumed to already be added to the output directory.
#       This varient is helpful if one set of latex files makes different
#       varients of documents.  For example, with building chapters
#       separately from the entire document.
#
# History:
#
# 1.3.0 Added a LATEX_OUTPUT_PATH variable that allows you or the user to
#       specify where the built latex documents to go.  This is especially
#       handy if you want to do in-source builds.
#
#       Removed the ADD_LATEX_IMAGES macro and absorbed the functionality
#       into ADD_LATEX_DOCUMENT.  The old interface was always kind of
#       clunky anyway since you had to specify the image directory in both
#       places.  It also made supporting LATEX_OUTPUT_PATH problematic.
#
#       Added support for jpeg files.
#
# 1.2.0 Changed the configuration options yet again.  Removed the NO_CONFIGURE
#       Replaced it with a CONFIGURE option that lists input files for which
#       configure should be run.
#
#       The pdf target no longer depends on the dvi target.  This allows you
#       to build latex documents that require pdflatex.  Also added an option
#       to make the pdf target the default one.
#
# 1.1.1 Added the NO_CONFIGURE option.  The @ character can be used when
#       specifying table column separators.  If two or more are used, then
#       will incorrectly substitute them.
#
# 1.1.0 Added ability include multiple bib files.  Added ability to do copy
#       sub-tex files for multipart tex files.
#
# 1.0.0 If both ps and pdf type images exist, just copy the one that
#       matches the current render mode.  Replaced a bunch of STRING
#       commands with GET_FILENAME_COMPONENT commands that were made to do
#       the desired function.
#
# 0.4.0 First version posted to CMake Wiki.
#

SET(LATEX_OUTPUT_PATH "${LATEX_OUTPUT_PATH}"
  CACHE PATH "If non empty, specifies the location to place LaTeX output."
  )

MACRO(LATEX_GET_OUTPUT_PATH var)
  SET(${var})
  IF (LATEX_OUTPUT_PATH)
    IF ("${LATEX_OUTPUT_PATH}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
      MESSAGE(SEND_ERROR "You cannot set LATEX_OUTPUT_PATH to the same directory that contains LaTeX input files.")
    ELSE ("${LATEX_OUTPUT_PATH}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
      SET(${var} "${LATEX_OUTPUT_PATH}")
    ENDIF ("${LATEX_OUTPUT_PATH}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
  ELSE (LATEX_OUTPUT_PATH)
    IF ("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
      MESSAGE(SEND_ERROR "LaTeX files must be built out of source or you must set LATEX_OUTPUT_PATH.")
    ELSE ("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
      SET(${var} "${CMAKE_CURRENT_BINARY_DIR}")
    ENDIF ("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
  ENDIF (LATEX_OUTPUT_PATH)
ENDMACRO(LATEX_GET_OUTPUT_PATH)

FIND_PACKAGE(LATEX)
MARK_AS_ADVANCED(CLEAR
  LATEX_COMPILER
  PDFLATEX_COMPILER
  BIBTEX_COMPILER
  MAKEINDEX_COMPILER
  DVIPS_CONVERTER
  PS2PDF_CONVERTER
  LATEX2HTML_CONVERTER
  )

MACRO(LATEX_NEEDIT VAR NAME)
  IF (NOT ${VAR})
    MESSAGE(SEND_ERROR "I need the ${NAME} command.")
  ENDIF(NOT ${VAR})
ENDMACRO(LATEX_NEEDIT)
MACRO(LATEX_WANTIT VAR NAME)
  IF (NOT ${VAR})
    MESSAGE(STATUS "I could not find the ${NAME} command.")
  ENDIF(NOT ${VAR})
ENDMACRO(LATEX_WANTIT)

LATEX_NEEDIT(LATEX_COMPILER latex)
LATEX_WANTIT(PDFLATEX_COMPILER pdflatex)
LATEX_NEEDIT(BIBTEX_COMPILER bibtex)
LATEX_NEEDIT(MAKEINDEX_COMPILER makeindex)
LATEX_WANTIT(DVIPS_CONVERTER dvips)
LATEX_WANTIT(PS2PDF_CONVERTER ps2pdf)
LATEX_WANTIT(LATEX2HTML_CONVERTER latex2html)

SET(LATEX_COMPILER_FLAGS "-interaction=nonstopmode"
  CACHE STRING "Flags passed to latex.")
SET(PDFLATEX_COMPILER_FLAGS ${LATEX_COMPILER_FLAGS}
  CACHE STRING "Flags passed to pdflatex.")
SET(BIBTEX_COMPILER_FLAGS ""
  CACHE STRING "Flags passed to bibtex.")
SET(MAKEINDEX_COMPILER_FLAGS ""
  CACHE STRING "Flags passed to makeindex.")
SET(DVIPS_CONVERTER_FLAGS "-Ppdf -G0 -t letter"
  CACHE STRING "Flags passed to dvips.")
SET(PS2PDF_CONVERTER_FLAGS "-dMaxSubsetPct=100 -dCompatibilityLevel=1.3 -dSubsetFonts=true -dEmbedAllFonts=true -dAutoFilterColorImages=false -dAutoFilterGrayImages=false -dColorImageFilter=/FlateEncode -dGrayImageFilter=/FlateEncode -dMonoImageFilter=/FlateEncode"
  CACHE STRING "Flags passed to ps2pdf.")
SET(LATEX2HTML_CONVERTER_FLAGS ""
  CACHE STRING "Flags passed to latex2html.")
MARK_AS_ADVANCED(
  LATEX_COMPILER_FLAGS
  PDFLATEX_COMPILER_FLAGS
  BIBTEX_COMPILER_FLAGS
  MAKEINDEX_COMPILER_FLAGS
  DVIPS_CONVERTER_FLAGS
  PS2PDF_CONVERTER_FLAGS
  LATEX2HTML_CONVERTER_FLAGS
  )
SEPARATE_ARGUMENTS(LATEX_COMPILER_FLAGS)
SEPARATE_ARGUMENTS(PDFLATEX_COMPILER_FLAGS)
SEPARATE_ARGUMENTS(BIBTEX_COMPILER_FLAGS)
SEPARATE_ARGUMENTS(MAKEINDEX_COMPILER_FLAGS)
SEPARATE_ARGUMENTS(DVIPS_CONVERTER_FLAGS)
SEPARATE_ARGUMENTS(PS2PDF_CONVERTER_FLAGS)
SEPARATE_ARGUMENTS(LATEX2HTML_CONVERTER_FLAGS)

FIND_PROGRAM(IMAGEMAGICK_CONVERT convert
  DOC "The convert program that comes with ImageMagick (available at http://www.imagemagick.org)."
  )
IF (NOT IMAGEMAGICK_CONVERT)
  MESSAGE(SEND_ERROR "Could not find convert program.  Please download ImageMagick from http://www.imagemagick.org and install.")
ENDIF (NOT IMAGEMAGICK_CONVERT)

OPTION(LATEX_SMALL_IMAGES
  "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."
  OFF)
IF (LATEX_SMALL_IMAGES)
  SET(LATEX_RASTER_SCALE 16)
  SET(LATEX_OPPOSITE_RASTER_SCALE 100)
ELSE (LATEX_SMALL_IMAGES)
  SET(LATEX_RASTER_SCALE 100)
  SET(LATEX_OPPOSITE_RASTER_SCALE 16)
ENDIF (LATEX_SMALL_IMAGES)

# Helpful list macros.
MACRO(LATEX_CAR var)
  SET(${var} ${ARGV1})
ENDMACRO(LATEX_CAR)
MACRO(LATEX_CDR var junk)
  SET(${var} ${ARGN})
ENDMACRO(LATEX_CDR)

MACRO(LATEX_LIST_CONTAINS var value)
  SET(${var})
  FOREACH (value2 ${ARGN})
    IF (${value} STREQUAL ${value2})
      SET(${var} TRUE)
    ENDIF (${value} STREQUAL ${value2})
  ENDFOREACH (value2)
ENDMACRO(LATEX_LIST_CONTAINS)

# Just holds extensions for known image types.  They should all be lower case.
SET(LATEX_DVI_VECTOR_IMAGE_EXTENSIONS .eps)
SET(LATEX_DVI_RASTER_IMAGE_EXTENSIONS)
SET(LATEX_DVI_IMAGE_EXTENSIONS
  ${LATEX_DVI_VECTOR_IMAGE_EXTENSIONS} ${LATEX_DVI_RASTER_IMAGE_EXTENSIONS})
SET(LATEX_PDF_VECTOR_IMAGE_EXTENSIONS .pdf)
SET(LATEX_PDF_RASTER_IMAGE_EXTENSIONS .png .jpeg .jpg)
SET(LATEX_PDF_IMAGE_EXTENSIONS
  ${LATEX_PDF_VECTOR_IMAGE_EXTENSIONS} ${LATEX_PDF_RASTER_IMAGE_EXTENSIONS})
SET(LATEX_IMAGE_EXTENSIONS
  ${LATEX_DVI_IMAGE_EXTENSIONS} ${LATEX_PDF_IMAGE_EXTENSIONS})

# Makes custom commands to convert a file to a particular type.
MACRO(LATEX_CONVERT_IMAGE output_files input_file output_extension convert_flags
    output_extensions other_files)
  SET(input_dir ${CMAKE_CURRENT_SOURCE_DIR})
  LATEX_GET_OUTPUT_PATH(output_dir)

  GET_FILENAME_COMPONENT(extension "${input_file}" EXT)

  STRING(REGEX REPLACE "\\.[^.]*\$" ${output_extension} output_file
    "${input_file}")

  LATEX_LIST_CONTAINS(is_type ${extension} ${output_extensions})
  IF (is_type)
    IF (convert_flags)
      ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${output_file}
        COMMAND ${IMAGEMAGICK_CONVERT}
        ARGS ${input_dir}/${input_file} ${convert_flags}
          ${output_dir}/${output_file}
        DEPENDS ${input_dir}/${input_file}
        )
      SET(${output_files} ${${output_files}} ${output_dir}/${output_file})
    ELSE (convert_flags)
      # As a shortcut, we can just copy the file.
      ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${input_file}
        COMMAND ${CMAKE_COMMAND}
        ARGS -E copy ${input_dir}/${input_file} ${output_dir}/${input_file}
        DEPENDS ${input_dir}/${input_file}
        )
      SET(${output_files} ${${output_files}} ${output_dir}/${input_file})
    ENDIF (convert_flags)
  ELSE (is_type)
    SET(do_convert TRUE)
    # Check to see if there is another input file of the appropriate type.
    FOREACH(valid_extension ${output_extensions})
      STRING(REGEX REPLACE "\\.[^.]*\$" ${output_extension} try_file
        "${input_file}")
      LATEX_LIST_CONTAINS(has_native_file "${try_file}" ${other_files})
      IF (has_native_file)
        SET(do_convert FALSE)
      ENDIF (has_native_file)
    ENDFOREACH(valid_extension)

    # If we still need to convert, do it.
    IF (do_convert)
      ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${output_file}
        COMMAND ${IMAGEMAGICK_CONVERT}
        ARGS ${input_dir}/${input_file} ${convert_flags}
          ${output_dir}/${output_file}
        DEPENDS ${input_dir}/${input_file}
        )
      SET(${output_files} ${${output_files}} ${output_dir}/${output_file})
    ENDIF (do_convert)
  ENDIF (is_type)
ENDMACRO(LATEX_CONVERT_IMAGE)

# Adds custom commands to process the given files for dvi and pdf builds.
# Adds the output files to the given variables (does not replace).
MACRO(LATEX_PROCESS_IMAGES dvi_outputs pdf_outputs)
  LATEX_GET_OUTPUT_PATH(output_dir)
  FOREACH(file ${ARGN})
    IF (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
      GET_FILENAME_COMPONENT(extension "${file}" EXT)
      SET(convert_flags)

      # Check to see if we need to downsample the image.
      LATEX_LIST_CONTAINS(is_raster extension
        ${LATEX_DVI_RASTER_IMAGE_EXTENSIONS}
        ${LATEX_PDF_RASTER_IMAGE_EXTENSIONS})
      IF (LATEX_SMALL_IMAGES)
        IF (is_raster)
          SET(convert_flags -resize ${LATEX_RASTER_SCALE}%)
        ENDIF (is_raster)
      ENDIF (LATEX_SMALL_IMAGES)

      # Make sure the output directory exists.
      GET_FILENAME_COMPONENT(path "${output_dir}/${file}" PATH)
      MAKE_DIRECTORY("${path}")

      # Do conversions for dvi.
      LATEX_CONVERT_IMAGE(${dvi_outputs} "${file}" .eps "${convert_flags}"
        "${LATEX_DVI_IMAGE_EXTENSIONS}" "${ARGN}")

      # Do conversions for pdf.
      IF (is_raster)
        LATEX_CONVERT_IMAGE(${pdf_outputs} "${file}" .png "${convert_flags}"
          "${LATEX_PDF_IMAGE_EXTENSIONS}" "${ARGN}")
      ELSE (is_raster)
        LATEX_CONVERT_IMAGE(${pdf_outputs} "${file}" .pdf "${convert_flags}"
          "${LATEX_PDF_IMAGE_EXTENSIONS}" "${ARGN}")
      ENDIF (is_raster)
    ELSE (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
      MESSAGE("Could not find file \"${CMAKE_CURRENT_SOURCE_DIR}/${file}\"")
    ENDIF (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
  ENDFOREACH(file)
ENDMACRO(LATEX_PROCESS_IMAGES)

MACRO(ADD_LATEX_IMAGES)
  MESSAGE("The ADD_LATEX_IMAGES macro is deprecated.  Image directories are specified with LATEX_ADD_DOCUMENT.")
ENDMACRO(ADD_LATEX_IMAGES)


MACRO(LATEX_COPY_GLOBBED_FILES pattern dest)
  FILE(GLOB file_list ${pattern})
  FOREACH(in_file ${file_list})
    GET_FILENAME_COMPONENT(out_file ${in_file} NAME)
    CONFIGURE_FILE(${in_file} ${dest}/${out_file} COPYONLY)
  ENDFOREACH(in_file)
ENDMACRO(LATEX_COPY_GLOBBED_FILES)

MACRO(LATEX_PARSE_ARGUMENTS prefix arg_names option_names)
  SET(DEFAULT_ARGS)
  FOREACH(arg_name ${arg_names})
    SET(${prefix}_${arg_name})
  ENDFOREACH(arg_name)
  FOREACH(option ${option_names})
    SET(${prefix}_${option})
  ENDFOREACH(option)

  SET(current_arg_name DEFAULT_ARGS)
  SET(current_arg_list)
  FOREACH(arg ${ARGN})
    LATEX_LIST_CONTAINS(is_arg_name ${arg} ${arg_names})
    IF (is_arg_name)
      SET(${prefix}_${current_arg_name} ${current_arg_list})
      SET(current_arg_name ${arg})
      SET(current_arg_list)
    ELSE (is_arg_name)
      LATEX_LIST_CONTAINS(is_option ${arg} ${option_names})
      IF (is_option)
        SET(${prefix}_${arg} TRUE)
      ELSE (is_option)
        SET(current_arg_list ${current_arg_list} ${arg})
      ENDIF (is_option)
    ENDIF (is_arg_name)
  ENDFOREACH(arg)
  SET(${prefix}_${current_arg_name} ${current_arg_list})
ENDMACRO(LATEX_PARSE_ARGUMENTS)

MACRO(LATEX_USAGE command message)
  MESSAGE(SEND_ERROR
    "${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           [USE_INDEX] [DEFAULT_PDF])"
    )
ENDMACRO(LATEX_USAGE command message)

# Parses arguments to ADD_LATEX_DOCUMENT and ADD_LATEX_TARGETS and sets the
# variables LATEX_TARGET, LATEX_IMAGE_DIR, LATEX_BIBFILES, and
# LATEX_INPUTS.
MACRO(PARSE_ADD_LATEX_ARGUMENTS command)
  LATEX_PARSE_ARGUMENTS(
    LATEX
    "BIBFILES;INPUTS;IMAGE_DIRS;IMAGES;CONFIGURE"
    "USE_INDEX;DEFAULT_PDF"
    ${ARGN}
    )

  # The first argument is the target latex file.
  IF (LATEX_DEFAULT_ARGS)
    LATEX_CAR(target ${LATEX_DEFAULT_ARGS})
    LATEX_CDR(LATEX_DEFAULT_ARGS ${LATEX_DEFAULT_ARGS})
    GET_FILENAME_COMPONENT(LATEX_TARGET ${target} NAME_WE)
  ELSE (LATEX_DEFAULT_ARGS)
    LATEX_USAGE(${command} "No tex file target given to ${command}.")
  ENDIF (LATEX_DEFAULT_ARGS)

  IF (LATEX_DEFAULT_ARGS)
    LATEX_USAGE(${command} "Invalid or depricated arguments: ${LATEX_DEFAULT_ARGS}")
  ENDIF (LATEX_DEFAULT_ARGS)
ENDMACRO(PARSE_ADD_LATEX_ARGUMENTS)

MACRO(ADD_LATEX_TARGETS)
  LATEX_GET_OUTPUT_PATH(output_dir)
  PARSE_ADD_LATEX_ARGUMENTS(ADD_LATEX_TARGETS ${ARGV})

  # For each directory in LATEX_IMAGE_DIRS, glob all the image files and
  # place them in LATEX_IMAGES.
  FOREACH(dir ${LATEX_IMAGE_DIRS})
    FOREACH(extension ${LATEX_IMAGE_EXTENSIONS})
      FILE(GLOB files ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*${extension})
      FOREACH(file ${files})
        GET_FILENAME_COMPONENT(filename ${file} NAME)
        SET(LATEX_IMAGES ${LATEX_IMAGES} ${dir}/${filename})
      ENDFOREACH(file)
    ENDFOREACH(extension)
  ENDFOREACH(dir)

  SET(dvi_images)
  SET(pdf_images)
  LATEX_PROCESS_IMAGES(dvi_images pdf_images ${LATEX_IMAGES})

  SET(make_dvi_command
    ${CMAKE_COMMAND} -E chdir ${output_dir}
    ${LATEX_COMPILER} ${LATEX_COMPILER_FLAGS} ${LATEX_TARGET}.tex)
  SET(make_pdf_command
    ${CMAKE_COMMAND} -E chdir ${output_dir}
    ${PDFLATEX_COMPILER} ${PDFLATEX_COMPILER_FLAGS} ${LATEX_TARGET}.tex)

  SET(make_dvi_depends ${dvi_images})
  SET(make_pdf_depends ${pdf_images})
  FOREACH(input ${LATEX_TARGET}.tex ${LATEX_INPUTS})
    SET(make_dvi_depends ${make_dvi_depends} ${output_dir}/${input})
    SET(make_pdf_depends ${make_pdf_depends} ${output_dir}/${input})
  ENDFOREACH(input)

  IF (LATEX_BIBFILES)
    SET(make_dvi_command ${make_dvi_command}
      COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
      ${BIBTEX_COMPILER} ${BIBTEX_COMPILER_FLAGS} ${LATEX_TARGET})
    SET(make_pdf_command ${make_pdf_command}
      COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
      ${BIBTEX_COMPILER} ${BIBTEX_COMPILER_FLAGS} ${LATEX_TARGET})
    FOREACH (bibfile ${LATEX_BIBFILES})
      SET(make_dvi_depends ${make_dvi_depends} ${output_dir}/${bibfile})
      SET(make_pdf_depends ${make_pdf_depends} ${output_dir}/${bibfile})
    ENDFOREACH (bibfile ${LATEX_BIBFILES})
  ENDIF (LATEX_BIBFILES)

  IF (LATEX_USE_INDEX)
    SET(make_dvi_command ${make_dvi_command}
      COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
      ${LATEX_COMPILER} ${LATEX_COMPILER_FLAGS} ${LATEX_TARGET}.tex
      COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
      ${MAKEINDEX_COMPILER} ${MAKEINDEX_COMPILER_FLAGS} ${LATEX_TARGET}.idx)
    SET(make_pdf_command ${make_pdf_command}
      COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
      ${PDFLATEX_COMPILER} ${PDFLATEX_COMPILER_FLAGS} ${LATEX_TARGET}.tex
      COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
      ${MAKEINDEX_COMPILER} ${MAKEINDEX_COMPILER_FLAGS} ${LATEX_TARGET}.idx)
  ENDIF (LATEX_USE_INDEX)

  SET(make_dvi_command ${make_dvi_command}
    COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
    ${LATEX_COMPILER} ${LATEX_COMPILER_FLAGS} ${LATEX_TARGET}.tex
    COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
    ${LATEX_COMPILER} ${LATEX_COMPILER_FLAGS} ${LATEX_TARGET}.tex)
  SET(make_pdf_command ${make_pdf_command}
    COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
    ${PDFLATEX_COMPILER} ${PDFLATEX_COMPILER_FLAGS} ${LATEX_TARGET}.tex
    COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
    ${PDFLATEX_COMPILER} ${PDFLATEX_COMPILER_FLAGS} ${LATEX_TARGET}.tex)

  IF (LATEX_DEFAULT_PDF)
    ADD_CUSTOM_TARGET(dvi ${make_dvi_command}
      DEPENDS ${make_dvi_depends})
  ELSE (LATEX_DEFAULT_PDF)
    ADD_CUSTOM_TARGET(dvi ALL ${make_dvi_command}
      DEPENDS ${make_dvi_depends})
  ENDIF (LATEX_DEFAULT_PDF)

  IF (PDFLATEX_COMPILER)
    IF (LATEX_DEFAULT_PDF)
      ADD_CUSTOM_TARGET(pdf ALL ${make_pdf_command}
        DEPENDS ${make_pdf_depends})
    ELSE (LATEX_DEFAULT_PDF)
      ADD_CUSTOM_TARGET(pdf ${make_pdf_command}
        DEPENDS ${make_pdf_depends})
    ENDIF (LATEX_DEFAULT_PDF)
  ENDIF (PDFLATEX_COMPILER)

  IF (DVIPS_CONVERTER)
    ADD_CUSTOM_TARGET(ps
      ${CMAKE_COMMAND} -E chdir ${output_dir}
      ${DVIPS_CONVERTER} ${DVIPS_CONVERTER_FLAGS} -o ${LATEX_TARGET}.ps ${LATEX_TARGET}.dvi
      )
    ADD_DEPENDENCIES(ps dvi)
    IF (PS2PDF_CONVERTER)
      ADD_CUSTOM_TARGET(safepdf
        ${CMAKE_COMMAND} -E chdir ${output_dir}
        ${PS2PDF_CONVERTER} ${PS2PDF_CONVERTER_FLAGS} ${LATEX_TARGET}.ps ${LATEX_TARGET}.pdf
        )
      ADD_DEPENDENCIES(safepdf ps)
    ENDIF (PS2PDF_CONVERTER)
  ENDIF (DVIPS_CONVERTER)

  IF (LATEX2HTML_CONVERTER)
    ADD_CUSTOM_TARGET(html
      ${CMAKE_COMMAND} -E chdir ${output_dir}
      ${LATEX2HTML_CONVERTER} ${LATEX2HTML_CONVERTER_FLAGS} ${LATEX_TARGET}.tex
      )
    ADD_DEPENDENCIES(html ${LATEX_TARGET}.tex ${LATEX_INPUTS})
  ENDIF (LATEX2HTML_CONVERTER)

  ADD_CUSTOM_TARGET(auxclean
    ${CMAKE_COMMAND} -E remove ${output_dir}/${LATEX_TARGET}.aux ${output_dir}/${LATEX_TARGET}.idx ${output_dir}/${LATEX_TARGET}.ind
    )
ENDMACRO(ADD_LATEX_TARGETS)

MACRO(LATEX_COPY_TEX_FILE file)
  LATEX_GET_OUTPUT_PATH(output_dir)

  GET_FILENAME_COMPONENT(file_we ${file} NAME_WE)
  LATEX_LIST_CONTAINS(use_config1 ${file_we} ${LATEX_CONFIGURE})
  LATEX_LIST_CONTAINS(use_config2 ${file_we}.tex ${LATEX_CONFIGURE})
  IF (use_config1 OR use_config2)
    CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${file_we}.tex
      ${output_dir}/${file_we}.tex
      @ONLY
      )
    ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${file_we}.tex
      COMMAND ${CMAKE_COMMAND}
      ARGS ${CMAKE_BINARY_DIR}
      DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file_we}.tex
      )
  ELSE (use_config1 OR use_config2)
    ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${file_we}.tex
      COMMAND ${CMAKE_COMMAND}
      ARGS -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${file_we}.tex ${output_dir}/${file_we}.tex
      DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file_we}.tex
      )
  ENDIF (use_config1 OR use_config2)

ENDMACRO(LATEX_COPY_TEX_FILE)

MACRO(ADD_LATEX_DOCUMENT)
  LATEX_GET_OUTPUT_PATH(output_dir)
  IF (output_dir)
    PARSE_ADD_LATEX_ARGUMENTS(ADD_LATEX_DOCUMENT ${ARGV})

    LATEX_COPY_TEX_FILE(${LATEX_TARGET})

    FOREACH (bib_file ${LATEX_BIBFILES})
      CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${bib_file}
        ${output_dir}/${bib_file}
        COPYONLY)
      ADD_CUSTOM_TARGET(${output_dir}/${bib_file}
        ${CMAKE_COMMAND} .
        DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${bib_file}
        )
    ENDFOREACH (bib_file)

    FOREACH (input ${LATEX_INPUTS})
      LATEX_COPY_TEX_FILE(${input})
    ENDFOREACH(input)

    LATEX_COPY_GLOBBED_FILES(${CMAKE_CURRENT_SOURCE_DIR}/*.cls ${output_dir})
    LATEX_COPY_GLOBBED_FILES(${CMAKE_CURRENT_SOURCE_DIR}/*.bst ${output_dir})
    LATEX_COPY_GLOBBED_FILES(${CMAKE_CURRENT_SOURCE_DIR}/*.clo ${output_dir})

    ADD_LATEX_TARGETS(${ARGV})
  ENDIF (output_dir)
ENDMACRO(ADD_LATEX_DOCUMENT)

  1. Back



CMake: [Welcome | Site Map]