Warning, /DD4hep/cmake/LATEX.cmake is written in an unsupported language. File is not indexed.
0001 # File: UseLATEX.cmake
0002 # CMAKE commands to actually use the LaTeX compiler
0003 # Version: 2.4.6
0004 # Author: Kenneth Moreland <kmorel@sandia.gov>
0005 #
0006 # Copyright 2004, 2015 Sandia Corporation.
0007 # Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
0008 # license for use of this work by or on behalf of the U.S. Government.
0009 #
0010 # This software is released under the BSD 3-Clause License.
0011 #
0012 # Redistribution and use in source and binary forms, with or without
0013 # modification, are permitted provided that the following conditions are
0014 # met:
0015 #
0016 # 1. Redistributions of source code must retain the above copyright notice,
0017 # this list of conditions and the following disclaimer.
0018 #
0019 # 2. Redistributions in binary form must reproduce the above copyright
0020 # notice, this list of conditions and the following disclaimer in the
0021 # documentation and/or other materials provided with the distribution.
0022 #
0023 # 3. Neither the name of the copyright holder nor the names of its
0024 # contributors may be used to endorse or promote products derived from this
0025 # software without specific prior written permission.
0026 #
0027 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
0028 # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
0029 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
0030 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
0031 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
0032 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0033 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
0034 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0035 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
0036 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
0037 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0038 #
0039 #
0040 # The following function is defined:
0041 #
0042 # add_latex_document(<tex_file>
0043 # [BIBFILES <bib_files>]
0044 # [INPUTS <input_tex_files>]
0045 # [IMAGE_DIRS] <image_directories>
0046 # [IMAGES] <image_files>
0047 # [CONFIGURE] <tex_files>
0048 # [DEPENDS] <tex_files>
0049 # [MULTIBIB_NEWCITES] <suffix_list>
0050 # [USE_BIBLATEX]
0051 # [USE_INDEX]
0052 # [INDEX_NAMES <index_names>]
0053 # [USE_GLOSSARY] [USE_NOMENCL]
0054 # [FORCE_PDF] [FORCE_DVI] [FORCE_HTML]
0055 # [TARGET_NAME] <name>
0056 # [EXCLUDE_FROM_ALL]
0057 # [EXCLUDE_FROM_DEFAULTS])
0058 # Adds targets that compile <tex_file>. The latex output is placed
0059 # in LATEX_OUTPUT_PATH or CMAKE_CURRENT_BINARY_DIR if the former is
0060 # not set. The latex program is picky about where files are located,
0061 # so all input files are copied from the source directory to the
0062 # output directory. This includes the target tex file, any tex file
0063 # listed with the INPUTS option, the bibliography files listed with
0064 # the BIBFILES option, and any .cls, .bst, .clo, .sty, .ist, and .fd
0065 # files found in the current source directory. Images found in the
0066 # IMAGE_DIRS directories or listed by IMAGES are also copied to the
0067 # output directory and converted to an appropriate format if necessary.
0068 # Any tex files also listed with the CONFIGURE option are also processed
0069 # with the CMake CONFIGURE_FILE command (with the @ONLY flag). Any file
0070 # listed in CONFIGURE but not the target tex file or listed with INPUTS
0071 # has no effect. DEPENDS can be used to specify generated files that are
0072 # needed to compile the latex target.
0073 #
0074 # The following targets are made. The name prefix is based off of the
0075 # base name of the tex file unless TARGET_NAME is specified. If
0076 # TARGET_NAME is specified, then that name is used for the targets.
0077 #
0078 # name_dvi: Makes <name>.dvi
0079 # name_pdf: Makes <name>.pdf using pdflatex.
0080 # name_safepdf: Makes <name>.pdf using ps2pdf. If using the
0081 # default program arguments, this will ensure all fonts
0082 # are embedded and no lossy compression has been
0083 # performed on images.
0084 # name_ps: Makes <name>.ps
0085 # name_html: Makes <name>.html
0086 # name_auxclean: Deletes <name>.aux and other auxiliary files.
0087 # This is sometimes necessary if a LaTeX error occurs
0088 # and writes a bad aux file. Unlike the regular clean
0089 # target, it does not delete other input files, such as
0090 # converted images, to save time on the rebuild.
0091 #
0092 # Unless the EXCLUDE_FROM_ALL option is given, one of these targets
0093 # is added to the ALL target and built by default. Which target is
0094 # determined by the LATEX_DEFAULT_BUILD CMake variable. See the
0095 # documentation of that variable for more details.
0096 #
0097 # Unless the EXCLUDE_FROM_DEFAULTS option is given, all these targets
0098 # are added as dependencies to targets named dvi, pdf, safepdf, ps,
0099 # html, and auxclean, respectively.
0100 #
0101 # USE_BIBLATEX enables the use of biblatex/biber as an alternative to
0102 # bibtex. Bibtex remains the default if USE_BIBLATEX is not
0103 # specified.
0104 #
0105 # If the argument USE_INDEX is given, then commands to build an index
0106 # are made. If the argument INDEX_NAMES is given, an index file is
0107 # generated for each name in this list. See the LaTeX package multind
0108 # for more information about how to generate multiple indices.
0109 #
0110 # If the argument USE_GLOSSARY is given, then commands to
0111 # build a glossary are made. If the argument MULTIBIB_NEWCITES is
0112 # given, then additional bibtex calls are added to the build to
0113 # support the extra auxiliary files created with the \newcite command
0114 # in the multibib package.
0115 #
0116 # History:
0117 #
0118 # 2.4.6 Fix parse issue with older versions of CMake.
0119 #
0120 # 2.4.5 Fix issues with files and paths containing spaces.
0121 #
0122 # 2.4.4 Improve error reporting message when LaTeX fails.
0123 #
0124 # When LaTeX fails, delete the output file, which is invalid.
0125 #
0126 # Add warnings for "missing characters." These usually mean that a
0127 # non-ASCII character is in the document and will not be printed
0128 # correctly.
0129 #
0130 # 2.4.3 Check for warnings from the natbib package. When using natbib,
0131 # warnings for missing bibliography references look different. So
0132 # far, natbib seems to be quiet unless something is important, so
0133 # look for all natbib warnings. (We can change this later if
0134 # necessary.)
0135 #
0136 # 2.4.2 Fix an issue where new versions of ImageMagick expect the order of
0137 # options in command line execution of magick/convert. (See, for
0138 # example, http://www.imagemagick.org/Usage/basics/#why.)
0139 #
0140 # 2.4.1 Add ability to dump LaTeX log file when using batch mode. Batch
0141 # mode suppresses most output, often including error messages. To
0142 # make sure critical error messages get displayed, show the full log
0143 # on failures.
0144 #
0145 # 2.4.0 Remove "-r 600" from the default PDFTOPS_CONVERTER_FLAGS. The -r flag
0146 # is available from the Poppler version of pdftops, but not the Xpdf
0147 # version.
0148 #
0149 # Fix an issue with the flags for the different programs not being
0150 # properly separated.
0151 #
0152 # Fix an issue on windows where the = character is not allowed for
0153 # ps2pdf arguments.
0154 #
0155 # Change default arguments for latex and pdflatex commands. Makes the
0156 # output more quiet and prints out the file/line where errors occur.
0157 # (Thanks to Nikos Koukis.)
0158 #
0159 # After a LaTeX build, check the log file for warnings that are
0160 # indicative of problems with the build.
0161 #
0162 # Remove support for latex2html. Instead, use the htlatex program.
0163 # This is now part of TeX Live and most other distributions. It also
0164 # behaves much more like the other LaTeX programs. Also fixed some
0165 # nasty issues with the htlatex arguments.
0166 #
0167 # 2.3.2 Declare LaTeX input files as sources for targets so that they show
0168 # up in IDEs like QtCreator.
0169 #
0170 # Fix issue where main tex files in subdirectories were creating
0171 # invalid targets for building HTML. Just disable the HTML targets in
0172 # this case.
0173 #
0174 # 2.3.1 Support use of magick command instead of convert command for
0175 # ImageMagick 7.
0176 #
0177 # 2.3.0 Add USE_BIBLATEX option to support the biblatex package, which
0178 # requires using the program biber as a replacement for bibtex
0179 # (thanks to David Tracey).
0180 #
0181 # 2.2.1 Add STRINGS property to LATEX_DEFAULT_BUILD to make it easier to
0182 # select the default build in the CMake GUI.
0183 #
0184 # 2.2.0 Add TARGET_NAME option.
0185 #
0186 # 2.1.1 Support for finding bmp, ppm, and other image files.
0187 #
0188 # 2.1.0 Fix an error where the pdf target and others were defined multiple
0189 # times if UseLATEX.cmake was included multiple times.
0190 #
0191 # Added INDEX_NAMES option to support multiple indexes in a single
0192 # document from the multind package (thanks to Dan Lipsa).
0193 #
0194 # 2.0.0 First major revision of UseLATEX.cmake updates to more recent features
0195 # of CMake and some non-backward compatible changes.
0196 #
0197 # Changed all function and macro names to lower case. CMake's identifiers
0198 # are case insensitive, but the convention moved from all upper case to
0199 # all lower case somewhere around the release of CMake 2. (The original
0200 # version of UseLATEX.cmake predates that.)
0201 #
0202 # Remove condition matching in if statements. They are no longer necessary
0203 # and are even discouraged (because else clauses get confusing).
0204 #
0205 # Use "new" features available in CMake such as list and argument parsing.
0206 #
0207 # Remove some code that has been deprecated for a while.
0208 #
0209 # Mark variables for compiler and converter executables as advanced to
0210 # match the more conventional CMake behavior.
0211 #
0212 # Changed how default builds are specified and add the ability to force
0213 # a particular build.
0214 #
0215 # Made the base targets (pdf, dvi, etc.) global. add_latex_document
0216 # always mangles its target names and these base targets depend on
0217 # the targets with mangled names.
0218 #
0219 # 1.10.5 Fix for Window's convert check (thanks to Martin Baute).
0220 #
0221 # 1.10.4 Copy font files to binary directory for packages that come with
0222 # their own fonts.
0223 #
0224 # 1.10.3 Check for Windows version of convert being used instead of
0225 # ImageMagick's version (thanks to Martin Baute).
0226 #
0227 # 1.10.2 Use htlatex as a fallback when latex2html is not available (thanks
0228 # to Tomasz Grzegurzko).
0229 #
0230 # 1.10.1 Make convert program mandatory only if actually used (thanks to
0231 # Julien Schueller).
0232 #
0233 # 1.10.0 Added NO_DEFAULT and DEFAULT_PS options.
0234 # Fixed issue with cleaning files for LaTeX documents originating in
0235 # a subdirectory.
0236 #
0237 # 1.9.6 Fixed problem with LATEX_SMALL_IMAGES.
0238 # Strengthened check to make sure the output directory does not contain
0239 # the source files.
0240 #
0241 # 1.9.5 Add support for image types not directly supported by either latex
0242 # or pdflatex. (Thanks to Jorge Gerardo Pena Pastor for SVG support.)
0243 #
0244 # 1.9.4 Fix issues with filenames containing multiple periods.
0245 #
0246 # 1.9.3 Hide some variables that are now cached but should not show up in
0247 # the ccmake list of variables.
0248 #
0249 # 1.9.2 Changed MACRO declarations to FUNCTION declarations. The better
0250 # FUNCTION scoping will hopefully avoid some common but subtle bugs.
0251 # This implicitly increases the minimum CMake version to 4.6 (although
0252 # I honestly only test it with the latest 4.8 version).
0253 #
0254 # Since we are updating the minimum CMake version, I'm going to start
0255 # using the builtin LIST commands that are now available.
0256 #
0257 # Favor using pdftops from the Poppler package to convert from pdf to
0258 # eps. It does a much better job than ImageMagick or ghostscript.
0259 #
0260 # 1.9.1 Fixed typo that caused the LATEX_SMALL_IMAGES option to fail to
0261 # activate.
0262 #
0263 # 1.9.0 Add support for the multibib package (thanks to Antonio LaTorre).
0264 #
0265 # 1.8.2 Fix corner case when an argument name was also a variable containing
0266 # the text of an argument. In this case, the CMake IF was matching
0267 # the argument text with the contents of the variable with the same
0268 # argument name.
0269 #
0270 # 1.8.1 Fix problem where ps2pdf was not getting the appropriate arguments.
0271 #
0272 # 1.8.0 Add support for synctex.
0273 #
0274 # 1.7.7 Support calling xindy when making glossaries.
0275 #
0276 # Improved make clean support.
0277 #
0278 # 1.7.6 Add support for the nomencl package (thanks to Myles English).
0279 #
0280 # 1.7.5 Fix issue with bibfiles being copied two different ways, which causes
0281 # Problems with dependencies (thanks to Edwin van Leeuwen).
0282 #
0283 # 1.7.4 Added the DEFAULT_SAFEPDF option (thanks to Raymond Wan).
0284 #
0285 # Added warnings when image directories are not found (and were
0286 # probably not given relative to the source directory).
0287 #
0288 # 1.7.3 Fix some issues with interactions between makeglossaries and bibtex
0289 # (thanks to Mark de Wever).
0290 #
0291 # 1.7.2 Use ps2pdf to convert eps to pdf to get around the problem with
0292 # ImageMagick dropping the bounding box (thanks to Lukasz Lis).
0293 #
0294 # 1.7.1 Fixed some dependency issues.
0295 #
0296 # 1.7.0 Added DEPENDS options (thanks to Theodore Papadopoulo).
0297 #
0298 # 1.6.1 Ported the makeglossaries command to CMake and embedded the port
0299 # into UseLATEX.cmake.
0300 #
0301 # 1.6.0 Allow the use of the makeglossaries command. Thanks to Oystein
0302 # S. Haaland for the patch.
0303 #
0304 # 1.5.0 Allow any type of file in the INPUTS lists, not just tex file
0305 # (suggested by Eric Noulard). As a consequence, the ability to
0306 # specify tex files without the .tex extension is removed. The removed
0307 # function is of dubious value anyway.
0308 #
0309 # When copying input files, skip over any file that exists in the
0310 # binary directory but does not exist in the source directory with the
0311 # assumption that these files were added by some other mechanism. I
0312 # find this useful when creating large documents with multiple
0313 # chapters that I want to build separately (for speed) as I work on
0314 # them. I use the same boilerplate as the starting point for all
0315 # and just copy it with different configurations. This was what the
0316 # separate ADD_LATEX_DOCUMENT method was supposed to originally be for.
0317 # Since its external use is pretty much deprecated, I removed that
0318 # documentation.
0319 #
0320 # 1.4.1 Copy .sty files along with the other class and package files.
0321 #
0322 # 1.4.0 Added a MANGLE_TARGET_NAMES option that will mangle the target names.
0323 #
0324 # Fixed problem with copying bib files that became apparent with
0325 # CMake 2.4.
0326 #
0327 # 1.3.0 Added a LATEX_OUTPUT_PATH variable that allows you or the user to
0328 # specify where the built latex documents to go. This is especially
0329 # handy if you want to do in-source builds.
0330 #
0331 # Removed the ADD_LATEX_IMAGES macro and absorbed the functionality
0332 # into ADD_LATEX_DOCUMENT. The old interface was always kind of
0333 # clunky anyway since you had to specify the image directory in both
0334 # places. It also made supporting LATEX_OUTPUT_PATH problematic.
0335 #
0336 # Added support for jpeg files.
0337 #
0338 # 1.2.0 Changed the configuration options yet again. Removed the NO_CONFIGURE
0339 # Replaced it with a CONFIGURE option that lists input files for which
0340 # configure should be run.
0341 #
0342 # The pdf target no longer depends on the dvi target. This allows you
0343 # to build latex documents that require pdflatex. Also added an option
0344 # to make the pdf target the default one.
0345 #
0346 # 1.1.1 Added the NO_CONFIGURE option. The @ character can be used when
0347 # specifying table column separators. If two or more are used, then
0348 # will incorrectly substitute them.
0349 #
0350 # 1.1.0 Added ability include multiple bib files. Added ability to do copy
0351 # sub-tex files for multipart tex files.
0352 #
0353 # 1.0.0 If both ps and pdf type images exist, just copy the one that
0354 # matches the current render mode. Replaced a bunch of STRING
0355 # commands with GET_FILENAME_COMPONENT commands that were made to do
0356 # the desired function.
0357 #
0358 # 0.4.0 First version posted to CMake Wiki.
0359 #
0360
0361 if(__USE_LATEX_INCLUDED)
0362 return()
0363 endif()
0364 set(__USE_LATEX_INCLUDED TRUE)
0365
0366 #############################################################################
0367 # Find the location of myself while originally executing. If you do this
0368 # inside of a macro, it will recode where the macro was invoked.
0369 #############################################################################
0370 set(LATEX_USE_LATEX_LOCATION ${CMAKE_CURRENT_LIST_FILE}
0371 CACHE INTERNAL "Location of UseLATEX.cmake file." FORCE
0372 )
0373
0374 #############################################################################
0375 # Generic helper functions
0376 #############################################################################
0377
0378 include(CMakeParseArguments)
0379
0380 function(latex_list_contains var value)
0381 set(input_list ${ARGN})
0382 list(FIND input_list "${value}" index)
0383 if(index GREATER -1)
0384 set(${var} TRUE PARENT_SCOPE)
0385 else()
0386 set(${var} PARENT_SCOPE)
0387 endif()
0388 endfunction(latex_list_contains)
0389
0390 # Match the contents of a file to a regular expression.
0391 function(latex_file_match variable filename regexp default)
0392 # The FILE STRINGS command would be a bit better, but I'm not totally sure
0393 # the match will always be to a whole line, and I don't want to break things.
0394 file(READ ${filename} file_contents)
0395 string(REGEX MATCHALL "${regexp}"
0396 match_result ${file_contents}
0397 )
0398 if(match_result)
0399 set(${variable} "${match_result}" PARENT_SCOPE)
0400 else()
0401 set(${variable} "${default}" PARENT_SCOPE)
0402 endif()
0403 endfunction(latex_file_match)
0404
0405 # A version of GET_FILENAME_COMPONENT that treats extensions after the last
0406 # period rather than the first. To the best of my knowledge, all filenames
0407 # typically used by LaTeX, including image files, have small extensions
0408 # after the last dot.
0409 function(latex_get_filename_component varname filename type)
0410 set(result)
0411 if("${type}" STREQUAL "NAME_WE")
0412 get_filename_component(name ${filename} NAME)
0413 string(REGEX REPLACE "\\.[^.]*\$" "" result "${name}")
0414 elseif("${type}" STREQUAL "EXT")
0415 get_filename_component(name ${filename} NAME)
0416 string(REGEX MATCH "\\.[^.]*\$" result "${name}")
0417 else()
0418 get_filename_component(result ${filename} ${type})
0419 endif()
0420 set(${varname} "${result}" PARENT_SCOPE)
0421 endfunction(latex_get_filename_component)
0422
0423 #############################################################################
0424 # Functions that perform processing during a LaTeX build.
0425 #############################################################################
0426 function(latex_execute_latex)
0427 if(NOT LATEX_TARGET)
0428 message(SEND_ERROR "Need to define LATEX_TARGET")
0429 endif()
0430
0431 if(NOT LATEX_WORKING_DIRECTORY)
0432 message(SEND_ERROR "Need to define LATEX_WORKING_DIRECTORY")
0433 endif()
0434
0435 if(NOT LATEX_FULL_COMMAND)
0436 message(SEND_ERROR "Need to define LATEX_FULL_COMMAND")
0437 endif()
0438
0439 if(NOT LATEX_OUTPUT_FILE)
0440 message(SEND_ERROR "Need to define LATEX_OUTPUT_FILE")
0441 endif()
0442
0443 set(full_command_original "${LATEX_FULL_COMMAND}")
0444
0445 # Chose the native method for parsing command arguments. Newer versions of
0446 # CMake allow you to just use NATIVE_COMMAND.
0447 if (CMAKE_VERSION VERSION_GREATER 3.8)
0448 set(separate_arguments_mode NATIVE_COMMAND)
0449 else()
0450 if (WIN32)
0451 set(separate_arguments_mode WINDOWS_COMMAND)
0452 else()
0453 set(separate_arguments_mode UNIX_COMMAND)
0454 endif()
0455 endif()
0456
0457 # Preps variables for use in execute_process.
0458 # Even though we expect LATEX_WORKING_DIRECTORY to have a single "argument,"
0459 # we also want to make sure that we strip out any escape characters that can
0460 # foul up the WORKING_DIRECTORY argument.
0461 separate_arguments(LATEX_FULL_COMMAND UNIX_COMMAND "${LATEX_FULL_COMMAND}")
0462 separate_arguments(LATEX_WORKING_DIRECTORY UNIX_COMMAND "${LATEX_WORKING_DIRECTORY}")
0463
0464 execute_process(
0465 COMMAND ${LATEX_FULL_COMMAND}
0466 WORKING_DIRECTORY ${LATEX_WORKING_DIRECTORY}
0467 RESULT_VARIABLE execute_result
0468 )
0469
0470 if(NOT ${execute_result} EQUAL 0)
0471 # LaTeX tends to write a file when a failure happens. Delete that file so
0472 # that LaTeX will run again.
0473 file(REMOVE "${LATEX_WORKING_DIRECTORY}/${LATEX_OUTPUT_FILE}")
0474
0475 message("\n\nLaTeX command failed")
0476 message("${full_command_original}")
0477 message("Log output:")
0478 file(READ ${LATEX_WORKING_DIRECTORY}/${LATEX_TARGET}.log log_output)
0479 message("${log_output}")
0480 message(FATAL_ERROR
0481 "Successfully executed LaTeX, but LaTeX returned an error.")
0482 endif()
0483 endfunction(latex_execute_latex)
0484
0485 function(latex_makeglossaries)
0486 # This is really a bare bones port of the makeglossaries perl script into
0487 # CMake scripting.
0488 message("**************************** In makeglossaries")
0489 if(NOT LATEX_TARGET)
0490 message(SEND_ERROR "Need to define LATEX_TARGET")
0491 endif()
0492
0493 set(aux_file ${LATEX_TARGET}.aux)
0494
0495 if(NOT EXISTS ${aux_file})
0496 message(SEND_ERROR "${aux_file} does not exist. Run latex on your target file.")
0497 endif()
0498
0499 latex_file_match(newglossary_lines ${aux_file}
0500 "@newglossary[ \t]*{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}"
0501 "@newglossary{main}{glg}{gls}{glo}"
0502 )
0503
0504 latex_file_match(istfile_line ${aux_file}
0505 "@istfilename[ \t]*{([^}]*)}"
0506 "@istfilename{${LATEX_TARGET}.ist}"
0507 )
0508 string(REGEX REPLACE "@istfilename[ \t]*{([^}]*)}" "\\1"
0509 istfile ${istfile_line}
0510 )
0511
0512 string(REGEX MATCH ".*\\.xdy" use_xindy "${istfile}")
0513 if(use_xindy)
0514 message("*************** Using xindy")
0515 if(NOT XINDY_COMPILER)
0516 message(SEND_ERROR "Need to define XINDY_COMPILER")
0517 endif()
0518 else()
0519 message("*************** Using makeindex")
0520 if(NOT MAKEINDEX_COMPILER)
0521 message(SEND_ERROR "Need to define MAKEINDEX_COMPILER")
0522 endif()
0523 endif()
0524
0525 foreach(newglossary ${newglossary_lines})
0526 string(REGEX REPLACE
0527 "@newglossary[ \t]*{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}"
0528 "\\1" glossary_name ${newglossary}
0529 )
0530 string(REGEX REPLACE
0531 "@newglossary[ \t]*{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}"
0532 "${LATEX_TARGET}.\\2" glossary_log ${newglossary}
0533 )
0534 string(REGEX REPLACE
0535 "@newglossary[ \t]*{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}"
0536 "${LATEX_TARGET}.\\3" glossary_out ${newglossary}
0537 )
0538 string(REGEX REPLACE
0539 "@newglossary[ \t]*{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}"
0540 "${LATEX_TARGET}.\\4" glossary_in ${newglossary}
0541 )
0542
0543 if(use_xindy)
0544 latex_file_match(xdylanguage_line ${aux_file}
0545 "@xdylanguage[ \t]*{${glossary_name}}{([^}]*)}"
0546 "@xdylanguage{${glossary_name}}{english}"
0547 )
0548 string(REGEX REPLACE
0549 "@xdylanguage[ \t]*{${glossary_name}}{([^}]*)}"
0550 "\\1"
0551 language
0552 ${xdylanguage_line}
0553 )
0554 # What crazy person makes a LaTeX index generator that uses different
0555 # identifiers for language than babel (or at least does not support
0556 # the old ones)?
0557 if(${language} STREQUAL "frenchb")
0558 set(language "french")
0559 elseif(${language} MATCHES "^n?germanb?$")
0560 set(language "german")
0561 elseif(${language} STREQUAL "magyar")
0562 set(language "hungarian")
0563 elseif(${language} STREQUAL "lsorbian")
0564 set(language "lower-sorbian")
0565 elseif(${language} STREQUAL "norsk")
0566 set(language "norwegian")
0567 elseif(${language} STREQUAL "portuges")
0568 set(language "portuguese")
0569 elseif(${language} STREQUAL "russianb")
0570 set(language "russian")
0571 elseif(${language} STREQUAL "slovene")
0572 set(language "slovenian")
0573 elseif(${language} STREQUAL "ukraineb")
0574 set(language "ukrainian")
0575 elseif(${language} STREQUAL "usorbian")
0576 set(language "upper-sorbian")
0577 endif()
0578 if(language)
0579 set(language_flags "-L ${language}")
0580 else()
0581 set(language_flags "")
0582 endif()
0583
0584 latex_file_match(codepage_line ${aux_file}
0585 "@gls@codepage[ \t]*{${glossary_name}}{([^}]*)}"
0586 "@gls@codepage{${glossary_name}}{utf}"
0587 )
0588 string(REGEX REPLACE
0589 "@gls@codepage[ \t]*{${glossary_name}}{([^}]*)}"
0590 "\\1"
0591 codepage
0592 ${codepage_line}
0593 )
0594 if(codepage)
0595 set(codepage_flags "-C ${codepage}")
0596 else()
0597 # Ideally, we would check that the language is compatible with the
0598 # default codepage, but I'm hoping that distributions will be smart
0599 # enough to specify their own codepage. I know, it's asking a lot.
0600 set(codepage_flags "")
0601 endif()
0602
0603 message("${XINDY_COMPILER} ${MAKEGLOSSARIES_COMPILER_ARGS} ${language_flags} ${codepage_flags} -I xindy -M ${glossary_name} -t ${glossary_log} -o ${glossary_out} ${glossary_in}"
0604 )
0605 exec_program(${XINDY_COMPILER}
0606 ARGS ${MAKEGLOSSARIES_COMPILER_ARGS}
0607 ${language_flags}
0608 ${codepage_flags}
0609 -I xindy
0610 -M ${glossary_name}
0611 -t ${glossary_log}
0612 -o ${glossary_out}
0613 ${glossary_in}
0614 OUTPUT_VARIABLE xindy_output
0615 )
0616 message("${xindy_output}")
0617
0618 # So, it is possible (perhaps common?) for aux files to specify a
0619 # language and codepage that are incompatible with each other. Check
0620 # for that condition, and if it happens run again with the default
0621 # codepage.
0622 if("${xindy_output}" MATCHES "^Cannot locate xindy module for language (.+) in codepage (.+)\\.$")
0623 message("*************** Retrying xindy with default codepage.")
0624 exec_program(${XINDY_COMPILER}
0625 ARGS ${MAKEGLOSSARIES_COMPILER_ARGS}
0626 ${language_flags}
0627 -I xindy
0628 -M ${glossary_name}
0629 -t ${glossary_log}
0630 -o ${glossary_out}
0631 ${glossary_in}
0632 )
0633 endif()
0634
0635 else()
0636 message("${MAKEINDEX_COMPILER} ${MAKEGLOSSARIES_COMPILER_ARGS} -s ${istfile} -t ${glossary_log} -o ${glossary_out} ${glossary_in}")
0637 exec_program(${MAKEINDEX_COMPILER} ARGS ${MAKEGLOSSARIES_COMPILER_ARGS}
0638 -s ${istfile} -t ${glossary_log} -o ${glossary_out} ${glossary_in}
0639 )
0640 endif()
0641
0642 endforeach(newglossary)
0643 endfunction(latex_makeglossaries)
0644
0645 function(latex_makenomenclature)
0646 message("**************************** In makenomenclature")
0647 if(NOT LATEX_TARGET)
0648 message(SEND_ERROR "Need to define LATEX_TARGET")
0649 endif()
0650
0651 if(NOT MAKEINDEX_COMPILER)
0652 message(SEND_ERROR "Need to define MAKEINDEX_COMPILER")
0653 endif()
0654
0655 set(nomencl_out ${LATEX_TARGET}.nls)
0656 set(nomencl_in ${LATEX_TARGET}.nlo)
0657
0658 exec_program(${MAKEINDEX_COMPILER} ARGS ${MAKENOMENCLATURE_COMPILER_ARGS}
0659 ${nomencl_in} -s "nomencl.ist" -o ${nomencl_out}
0660 )
0661 endfunction(latex_makenomenclature)
0662
0663 function(latex_correct_synctex)
0664 message("**************************** In correct SyncTeX")
0665 if(NOT LATEX_TARGET)
0666 message(SEND_ERROR "Need to define LATEX_TARGET")
0667 endif()
0668
0669 if(NOT GZIP)
0670 message(SEND_ERROR "Need to define GZIP")
0671 endif()
0672
0673 if(NOT LATEX_SOURCE_DIRECTORY)
0674 message(SEND_ERROR "Need to define LATEX_SOURCE_DIRECTORY")
0675 endif()
0676
0677 if(NOT LATEX_BINARY_DIRECTORY)
0678 message(SEND_ERROR "Need to define LATEX_BINARY_DIRECTORY")
0679 endif()
0680
0681 set(synctex_file ${LATEX_BINARY_DIRECTORY}/${LATEX_TARGET}.synctex)
0682 set(synctex_file_gz ${synctex_file}.gz)
0683
0684 if(EXISTS ${synctex_file_gz})
0685
0686 message("Making backup of synctex file.")
0687 configure_file(${synctex_file_gz} ${synctex_file}.bak.gz COPYONLY)
0688
0689 message("Uncompressing synctex file.")
0690 exec_program(${GZIP}
0691 ARGS --decompress ${synctex_file_gz}
0692 )
0693
0694 message("Reading synctex file.")
0695 file(READ ${synctex_file} synctex_data)
0696
0697 message("Replacing relative with absolute paths.")
0698 string(REGEX REPLACE
0699 "(Input:[0-9]+:)([^/\n][^\n]*)"
0700 "\\1${LATEX_SOURCE_DIRECTORY}/\\2"
0701 synctex_data
0702 "${synctex_data}"
0703 )
0704
0705 message("Writing synctex file.")
0706 file(WRITE ${synctex_file} "${synctex_data}")
0707
0708 message("Compressing synctex file.")
0709 exec_program(${GZIP}
0710 ARGS ${synctex_file}
0711 )
0712
0713 else()
0714
0715 message(SEND_ERROR "File ${synctex_file_gz} not found. Perhaps synctex is not supported by your LaTeX compiler.")
0716
0717 endif()
0718
0719 endfunction(latex_correct_synctex)
0720
0721 function(latex_check_important_warnings)
0722 set(log_file ${LATEX_TARGET}.log)
0723
0724 message("\nChecking ${log_file} for important warnings.")
0725 if(NOT LATEX_TARGET)
0726 message(SEND_ERROR "Need to define LATEX_TARGET")
0727 endif()
0728
0729 if(NOT EXISTS ${log_file})
0730 message("Could not find log file: ${log_file}")
0731 return()
0732 endif()
0733
0734 set(found_error)
0735
0736 file(READ ${log_file} log)
0737
0738 # Check for undefined references
0739 string(REGEX MATCHALL
0740 "\n[^\n]*Reference[^\n]*undefined[^\n]*"
0741 reference_warnings
0742 "${log}")
0743 if(reference_warnings)
0744 set(found_error TRUE)
0745 message("\nFound missing reference warnings.")
0746 foreach(warning ${reference_warnings})
0747 string(STRIP "${warning}" warning_no_newline)
0748 message("${warning_no_newline}")
0749 endforeach(warning)
0750 endif()
0751
0752 # Check for natbib warnings
0753 string(REGEX MATCHALL
0754 "\nPackage natbib Warning:[^\n]*"
0755 natbib_warnings
0756 "${log}")
0757 if(natbib_warnings)
0758 set(found_error TRUE)
0759 message("\nFound natbib package warnings.")
0760 foreach(warning ${natbib_warnings})
0761 string(STRIP "${warning}" warning_no_newline)
0762 message("${warning_no_newline}")
0763 endforeach(warning)
0764 endif()
0765
0766 # Check for overfull
0767 string(REGEX MATCHALL
0768 "\nOverfull[^\n]*"
0769 overfull_warnings
0770 "${log}")
0771 if(overfull_warnings)
0772 set(found_error TRUE)
0773 message("\nFound overfull warnings. These are indicative of layout errors.")
0774 foreach(warning ${overfull_warnings})
0775 string(STRIP "${warning}" warning_no_newline)
0776 message("${warning_no_newline}")
0777 endforeach(warning)
0778 endif()
0779
0780 # Check for invalid characters
0781 string(REGEX MATCHALL
0782 "\nMissing character:[^\n]*"
0783 invalid_character_warnings
0784 "${log}")
0785 if(invalid_character_warnings)
0786 set(found_error TRUE)
0787 message("\nFound invalid character warnings. These characters are likely not printed correctly.")
0788 foreach(warning ${invalid_character_warnings})
0789 string(STRIP "${warning}" warning_no_newline)
0790 message("${warning_no_newline}")
0791 endforeach(warning)
0792 endif()
0793
0794 if(found_error)
0795 latex_get_filename_component(log_file_path ${log_file} ABSOLUTE)
0796 message("\nConsult ${log_file_path} for more information on LaTeX build.")
0797 else()
0798 message("No known important warnings found.")
0799 endif(found_error)
0800 endfunction(latex_check_important_warnings)
0801
0802 #############################################################################
0803 # Helper functions for establishing LaTeX build.
0804 #############################################################################
0805
0806 function(latex_needit VAR NAME)
0807 if(NOT ${VAR})
0808 message(SEND_ERROR "I need the ${NAME} command.")
0809 endif()
0810 endfunction(latex_needit)
0811
0812 function(latex_wantit VAR NAME)
0813 if(NOT ${VAR})
0814 message(STATUS "I could not find the ${NAME} command.")
0815 endif()
0816 endfunction(latex_wantit)
0817
0818 function(latex_setup_variables)
0819 set(LATEX_OUTPUT_PATH "${LATEX_OUTPUT_PATH}"
0820 CACHE PATH "If non empty, specifies the location to place LaTeX output."
0821 )
0822
0823 find_package(LATEX)
0824
0825 find_program(XINDY_COMPILER
0826 NAME xindy
0827 PATHS ${MIKTEX_BINARY_PATH} /usr/bin
0828 )
0829
0830 find_package(UnixCommands)
0831
0832 find_program(PDFTOPS_CONVERTER
0833 NAMES pdftops
0834 DOC "The pdf to ps converter program from the Poppler package."
0835 )
0836
0837 find_program(HTLATEX_COMPILER
0838 NAMES htlatex
0839 PATHS ${MIKTEX_BINARY_PATH}
0840 /usr/bin
0841 )
0842
0843 mark_as_advanced(
0844 LATEX_COMPILER
0845 PDFLATEX_COMPILER
0846 BIBTEX_COMPILER
0847 BIBER_COMPILER
0848 MAKEINDEX_COMPILER
0849 XINDY_COMPILER
0850 DVIPS_CONVERTER
0851 PS2PDF_CONVERTER
0852 PDFTOPS_CONVERTER
0853 LATEX2HTML_CONVERTER
0854 HTLATEX_COMPILER
0855 )
0856
0857 latex_needit(LATEX_COMPILER latex)
0858 latex_wantit(PDFLATEX_COMPILER pdflatex)
0859 latex_wantit(HTLATEX_COMPILER htlatex)
0860 latex_needit(BIBTEX_COMPILER bibtex)
0861 latex_wantit(BIBER_COMPILER biber)
0862 latex_needit(MAKEINDEX_COMPILER makeindex)
0863 latex_wantit(DVIPS_CONVERTER dvips)
0864 latex_wantit(PS2PDF_CONVERTER ps2pdf)
0865 latex_wantit(PDFTOPS_CONVERTER pdftops)
0866
0867 set(LATEX_COMPILER_FLAGS "-interaction=batchmode -file-line-error"
0868 CACHE STRING "Flags passed to latex.")
0869 set(PDFLATEX_COMPILER_FLAGS ${LATEX_COMPILER_FLAGS}
0870 CACHE STRING "Flags passed to pdflatex.")
0871 set(HTLATEX_COMPILER_TEX4HT_FLAGS "html"
0872 CACHE STRING "Options for the tex4ht.sty and *.4ht style files.")
0873 set(HTLATEX_COMPILER_TEX4HT_POSTPROCESSOR_FLAGS ""
0874 CACHE STRING "Options for the text4ht postprocessor.")
0875 set(HTLATEX_COMPILER_T4HT_POSTPROCESSOR_FLAGS ""
0876 CACHE STRING "Options for the t4ht postprocessor.")
0877 set(HTLATEX_COMPILER_LATEX_FLAGS ${LATEX_COMPILER_FLAGS}
0878 CACHE STRING "Flags passed from htlatex to the LaTeX compiler.")
0879 set(LATEX_SYNCTEX_FLAGS "-synctex=1"
0880 CACHE STRING "latex/pdflatex flags used to create synctex file.")
0881 set(BIBTEX_COMPILER_FLAGS ""
0882 CACHE STRING "Flags passed to bibtex.")
0883 set(BIBER_COMPILER_FLAGS ""
0884 CACHE STRING "Flags passed to biber.")
0885 set(MAKEINDEX_COMPILER_FLAGS ""
0886 CACHE STRING "Flags passed to makeindex.")
0887 set(MAKEGLOSSARIES_COMPILER_FLAGS ""
0888 CACHE STRING "Flags passed to makeglossaries.")
0889 set(MAKENOMENCLATURE_COMPILER_FLAGS ""
0890 CACHE STRING "Flags passed to makenomenclature.")
0891 set(DVIPS_CONVERTER_FLAGS "-Ppdf -G0 -t letter"
0892 CACHE STRING "Flags passed to dvips.")
0893 if(NOT WIN32)
0894 set(PS2PDF_CONVERTER_FLAGS "-dMaxSubsetPct=100 -dCompatibilityLevel=1.3 -dSubsetFonts=true -dEmbedAllFonts=true -dAutoFilterColorImages=false -dAutoFilterGrayImages=false -dColorImageFilter=/FlateEncode -dGrayImageFilter=/FlateEncode -dMonoImageFilter=/FlateEncode"
0895 CACHE STRING "Flags passed to ps2pdf.")
0896 else()
0897 # Most windows ports of ghostscript utilities use .bat files for ps2pdf
0898 # commands. bat scripts interpret "=" as a special character and separate
0899 # those arguments. To get around this, the ghostscript utilities also
0900 # support using "#" in place of "=".
0901 set(PS2PDF_CONVERTER_FLAGS "-dMaxSubsetPct#100 -dCompatibilityLevel#1.3 -dSubsetFonts#true -dEmbedAllFonts#true -dAutoFilterColorImages#false -dAutoFilterGrayImages#false -dColorImageFilter#/FlateEncode -dGrayImageFilter#/FlateEncode -dMonoImageFilter#/FlateEncode"
0902 CACHE STRING "Flags passed to ps2pdf.")
0903 endif()
0904 set(PDFTOPS_CONVERTER_FLAGS ""
0905 CACHE STRING "Flags passed to pdftops.")
0906 mark_as_advanced(
0907 LATEX_COMPILER_FLAGS
0908 PDFLATEX_COMPILER_FLAGS
0909 HTLATEX_COMPILER_TEX4HT_FLAGS
0910 HTLATEX_COMPILER_TEX4HT_POSTPROCESSOR_FLAGS
0911 HTLATEX_COMPILER_T4HT_POSTPROCESSOR_FLAGS
0912 HTLATEX_COMPILER_LATEX_FLAGS
0913 LATEX_SYNCTEX_FLAGS
0914 BIBTEX_COMPILER_FLAGS
0915 BIBER_COMPILER_FLAGS
0916 MAKEINDEX_COMPILER_FLAGS
0917 MAKEGLOSSARIES_COMPILER_FLAGS
0918 MAKENOMENCLATURE_COMPILER_FLAGS
0919 DVIPS_CONVERTER_FLAGS
0920 PS2PDF_CONVERTER_FLAGS
0921 PDFTOPS_CONVERTER_FLAGS
0922 )
0923
0924 # Because it is easier to type, the flags variables are entered as
0925 # space-separated strings much like you would in a shell. However, when
0926 # using a CMake command to execute a program, it works better to hold the
0927 # arguments in semicolon-separated lists (otherwise the whole string will
0928 # be interpreted as a single argument). Use the separate_arguments to
0929 # convert the space-separated strings to semicolon-separated lists.
0930 separate_arguments(LATEX_COMPILER_FLAGS)
0931 separate_arguments(PDFLATEX_COMPILER_FLAGS)
0932 separate_arguments(HTLATEX_COMPILER_LATEX_FLAGS)
0933 separate_arguments(LATEX_SYNCTEX_FLAGS)
0934 separate_arguments(BIBTEX_COMPILER_FLAGS)
0935 separate_arguments(BIBER_COMPILER_FLAGS)
0936 separate_arguments(MAKEINDEX_COMPILER_FLAGS)
0937 separate_arguments(MAKEGLOSSARIES_COMPILER_FLAGS)
0938 separate_arguments(MAKENOMENCLATURE_COMPILER_FLAGS)
0939 separate_arguments(DVIPS_CONVERTER_FLAGS)
0940 separate_arguments(PS2PDF_CONVERTER_FLAGS)
0941 separate_arguments(PDFTOPS_CONVERTER_FLAGS)
0942
0943 # Not quite done. When you call separate_arguments on a cache variable,
0944 # the result is written to a local variable. That local variable goes
0945 # away when this function returns (which is before any of them are used).
0946 # So, copy these variables with local scope to cache variables with
0947 # global scope.
0948 set(LATEX_COMPILER_ARGS "${LATEX_COMPILER_FLAGS}" CACHE INTERNAL "")
0949 set(PDFLATEX_COMPILER_ARGS "${PDFLATEX_COMPILER_FLAGS}" CACHE INTERNAL "")
0950 set(HTLATEX_COMPILER_ARGS "${HTLATEX_COMPILER_LATEX_FLAGS}" CACHE INTERNAL "")
0951 set(LATEX_SYNCTEX_ARGS "${LATEX_SYNCTEX_FLAGS}" CACHE INTERNAL "")
0952 set(BIBTEX_COMPILER_ARGS "${BIBTEX_COMPILER_FLAGS}" CACHE INTERNAL "")
0953 set(BIBER_COMPILER_ARGS "${BIBER_COMPILER_FLAGS}" CACHE INTERNAL "")
0954 set(MAKEINDEX_COMPILER_ARGS "${MAKEINDEX_COMPILER_FLAGS}" CACHE INTERNAL "")
0955 set(MAKEGLOSSARIES_COMPILER_ARGS "${MAKEGLOSSARIES_COMPILER_FLAGS}" CACHE INTERNAL "")
0956 set(MAKENOMENCLATURE_COMPILER_ARGS "${MAKENOMENCLATURE_COMPILER_FLAGS}" CACHE INTERNAL "")
0957 set(DVIPS_CONVERTER_ARGS "${DVIPS_CONVERTER_FLAGS}" CACHE INTERNAL "")
0958 set(PS2PDF_CONVERTER_ARGS "${PS2PDF_CONVERTER_FLAGS}" CACHE INTERNAL "")
0959 set(PDFTOPS_CONVERTER_ARGS "${PDFTOPS_CONVERTER_FLAGS}" CACHE INTERNAL "")
0960
0961 find_program(IMAGEMAGICK_CONVERT
0962 NAMES magick convert
0963 DOC "The convert program that comes with ImageMagick (available at http://www.imagemagick.org)."
0964 )
0965 mark_as_advanced(IMAGEMAGICK_CONVERT)
0966
0967 if(DEFINED ENV{LATEX_DEFAULT_BUILD})
0968 set(default_build $ENV{LATEX_DEFAULT_BUILD})
0969 else()
0970 set(default_build pdf)
0971 endif()
0972
0973 set(LATEX_DEFAULT_BUILD "${default_build}" CACHE STRING
0974 "Choose the default type of LaTeX build. Valid options are pdf, dvi, ps, safepdf, html"
0975 )
0976 set_property(CACHE LATEX_DEFAULT_BUILD
0977 PROPERTY STRINGS pdf dvi ps safepdf html
0978 )
0979
0980 option(LATEX_USE_SYNCTEX
0981 "If on, have LaTeX generate a synctex file, which WYSIWYG editors can use to correlate output files like dvi and pdf with the lines of LaTeX source that generates them. In addition to adding the LATEX_SYNCTEX_FLAGS to the command line, this option also adds build commands that \"corrects\" the resulting synctex file to point to the original LaTeX files rather than those generated by UseLATEX.cmake."
0982 OFF
0983 )
0984
0985 option(LATEX_SMALL_IMAGES
0986 "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 distribution and can make it faster to read dvi files."
0987 OFF)
0988 if(LATEX_SMALL_IMAGES)
0989 set(LATEX_RASTER_SCALE 16 PARENT_SCOPE)
0990 set(LATEX_OPPOSITE_RASTER_SCALE 100 PARENT_SCOPE)
0991 else()
0992 set(LATEX_RASTER_SCALE 100 PARENT_SCOPE)
0993 set(LATEX_OPPOSITE_RASTER_SCALE 16 PARENT_SCOPE)
0994 endif()
0995
0996 # Just holds extensions for known image types. They should all be lower case.
0997 # For historical reasons, these are all declared in the global scope.
0998 set(LATEX_DVI_VECTOR_IMAGE_EXTENSIONS .eps CACHE INTERNAL "")
0999 set(LATEX_DVI_RASTER_IMAGE_EXTENSIONS CACHE INTERNAL "")
1000 set(LATEX_DVI_IMAGE_EXTENSIONS
1001 ${LATEX_DVI_VECTOR_IMAGE_EXTENSIONS}
1002 ${LATEX_DVI_RASTER_IMAGE_EXTENSIONS}
1003 CACHE INTERNAL ""
1004 )
1005
1006 set(LATEX_PDF_VECTOR_IMAGE_EXTENSIONS .pdf CACHE INTERNAL "")
1007 set(LATEX_PDF_RASTER_IMAGE_EXTENSIONS .jpeg .jpg .png CACHE INTERNAL "")
1008 set(LATEX_PDF_IMAGE_EXTENSIONS
1009 ${LATEX_PDF_VECTOR_IMAGE_EXTENSIONS}
1010 ${LATEX_PDF_RASTER_IMAGE_EXTENSIONS}
1011 CACHE INTERNAL ""
1012 )
1013
1014 set(LATEX_OTHER_VECTOR_IMAGE_EXTENSIONS .ai .dot .svg CACHE INTERNAL "")
1015 set(LATEX_OTHER_RASTER_IMAGE_EXTENSIONS
1016 .bmp .bmp2 .bmp3 .dcm .dcx .ico .gif .pict .ppm .tif .tiff
1017 CACHE INTERNAL "")
1018 set(LATEX_OTHER_IMAGE_EXTENSIONS
1019 ${LATEX_OTHER_VECTOR_IMAGE_EXTENSIONS}
1020 ${LATEX_OTHER_RASTER_IMAGE_EXTENSIONS}
1021 CACHE INTERNAL ""
1022 )
1023
1024 set(LATEX_VECTOR_IMAGE_EXTENSIONS
1025 ${LATEX_DVI_VECTOR_IMAGE_EXTENSIONS}
1026 ${LATEX_PDF_VECTOR_IMAGE_EXTENSIONS}
1027 ${LATEX_OTHER_VECTOR_IMAGE_EXTENSIONS}
1028 CACHE INTERNAL ""
1029 )
1030 set(LATEX_RASTER_IMAGE_EXTENSIONS
1031 ${LATEX_DVI_RASTER_IMAGE_EXTENSIONS}
1032 ${LATEX_PDF_RASTER_IMAGE_EXTENSIONS}
1033 ${LATEX_OTHER_RASTER_IMAGE_EXTENSIONS}
1034 CACHE INTERNAL ""
1035 )
1036 set(LATEX_IMAGE_EXTENSIONS
1037 ${LATEX_DVI_IMAGE_EXTENSIONS}
1038 ${LATEX_PDF_IMAGE_EXTENSIONS}
1039 ${LATEX_OTHER_IMAGE_EXTENSIONS}
1040 CACHE INTERNAL ""
1041 )
1042 endfunction(latex_setup_variables)
1043
1044 function(latex_setup_targets)
1045 if(NOT TARGET pdf)
1046 add_custom_target(pdf)
1047 endif()
1048 if(NOT TARGET dvi)
1049 add_custom_target(dvi)
1050 endif()
1051 if(NOT TARGET ps)
1052 add_custom_target(ps)
1053 endif()
1054 if(NOT TARGET safepdf)
1055 add_custom_target(safepdf)
1056 endif()
1057 if(NOT TARGET html)
1058 add_custom_target(html)
1059 endif()
1060 if(NOT TARGET auxclean)
1061 add_custom_target(auxclean)
1062 endif()
1063 endfunction(latex_setup_targets)
1064
1065 function(latex_get_output_path var)
1066 set(latex_output_path)
1067 if(LATEX_OUTPUT_PATH)
1068 get_filename_component(
1069 LATEX_OUTPUT_PATH_FULL "${LATEX_OUTPUT_PATH}" ABSOLUTE
1070 )
1071 if("${LATEX_OUTPUT_PATH_FULL}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
1072 message(SEND_ERROR "You cannot set LATEX_OUTPUT_PATH to the same directory that contains LaTeX input files.")
1073 else()
1074 set(latex_output_path "${LATEX_OUTPUT_PATH_FULL}")
1075 endif()
1076 else()
1077 if("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
1078 message(SEND_ERROR "LaTeX files must be built out of source or you must set LATEX_OUTPUT_PATH.")
1079 else()
1080 set(latex_output_path "${CMAKE_CURRENT_BINARY_DIR}")
1081 endif()
1082 endif()
1083 set(${var} ${latex_output_path} PARENT_SCOPE)
1084 endfunction(latex_get_output_path)
1085
1086 function(latex_add_convert_command
1087 output_path
1088 input_path
1089 output_extension
1090 input_extension
1091 flags
1092 )
1093 set(require_imagemagick_convert TRUE)
1094 set(convert_flags "")
1095 if(${input_extension} STREQUAL ".eps" AND ${output_extension} STREQUAL ".pdf")
1096 # ImageMagick has broken eps to pdf conversion
1097 # use ps2pdf instead
1098 if(PS2PDF_CONVERTER)
1099 set(require_imagemagick_convert FALSE)
1100 set(converter ${PS2PDF_CONVERTER})
1101 set(convert_flags -dEPSCrop ${PS2PDF_CONVERTER_ARGS})
1102 else()
1103 message(SEND_ERROR "Using postscript files with pdflatex requires ps2pdf for conversion.")
1104 endif()
1105 elseif(${input_extension} STREQUAL ".pdf" AND ${output_extension} STREQUAL ".eps")
1106 # ImageMagick can also be sketchy on pdf to eps conversion. Not good with
1107 # color spaces and tends to unnecessarily rasterize.
1108 # use pdftops instead
1109 if(PDFTOPS_CONVERTER)
1110 set(require_imagemagick_convert FALSE)
1111 set(converter ${PDFTOPS_CONVERTER})
1112 set(convert_flags -eps ${PDFTOPS_CONVERTER_ARGS})
1113 else()
1114 message(STATUS "Consider getting pdftops from Poppler to convert PDF images to EPS images.")
1115 set(convert_flags ${flags})
1116 endif()
1117 else()
1118 set(convert_flags ${flags})
1119 endif()
1120
1121 if(require_imagemagick_convert)
1122 if(IMAGEMAGICK_CONVERT)
1123 string(TOLOWER ${IMAGEMAGICK_CONVERT} IMAGEMAGICK_CONVERT_LOWERCASE)
1124 if(${IMAGEMAGICK_CONVERT_LOWERCASE} MATCHES "system32[/\\\\]convert\\.exe")
1125 message(SEND_ERROR "IMAGEMAGICK_CONVERT set to Window's convert.exe for changing file systems rather than ImageMagick's convert for changing image formats. Please make sure ImageMagick is installed (available at http://www.imagemagick.org). If you have a recent version of ImageMagick (7.0 or higher), use the magick program instead of convert for IMAGEMAGICK_CONVERT.")
1126 else()
1127 set(converter ${IMAGEMAGICK_CONVERT})
1128 # ImageMagick requires a special order of arguments where resize and
1129 # arguments of that nature must be placed after the input image path.
1130 add_custom_command(OUTPUT ${output_path}
1131 COMMAND ${converter}
1132 ARGS ${input_path} ${convert_flags} ${output_path}
1133 DEPENDS ${input_path}
1134 )
1135 endif()
1136 else()
1137 message(SEND_ERROR "Could not find convert program. Please download ImageMagick from http://www.imagemagick.org and install.")
1138 endif()
1139 else() # Not ImageMagick convert
1140 add_custom_command(OUTPUT ${output_path}
1141 COMMAND ${converter}
1142 ARGS ${convert_flags} ${input_path} ${output_path}
1143 DEPENDS ${input_path}
1144 )
1145 endif()
1146 endfunction(latex_add_convert_command)
1147
1148 # Makes custom commands to convert a file to a particular type.
1149 function(latex_convert_image
1150 output_files_var
1151 input_file
1152 output_extension
1153 convert_flags
1154 output_extensions
1155 other_files
1156 )
1157 set(output_file_list)
1158 set(input_dir ${CMAKE_CURRENT_SOURCE_DIR})
1159 latex_get_output_path(output_dir)
1160
1161 latex_get_filename_component(extension "${input_file}" EXT)
1162
1163 # Check input filename for potential problems with LaTeX.
1164 latex_get_filename_component(name "${input_file}" NAME_WE)
1165 set(suggested_name "${name}")
1166 if(suggested_name MATCHES ".*\\..*")
1167 string(REPLACE "." "-" suggested_name "${suggested_name}")
1168 endif()
1169 if(suggested_name MATCHES ".* .*")
1170 string(REPLACE " " "-" suggested_name "${suggested_name}")
1171 endif()
1172 if(NOT suggested_name STREQUAL name)
1173 message(WARNING "Some LaTeX distributions have problems with image file names with multiple extensions or spaces. Consider changing ${name}${extension} to something like ${suggested_name}${extension}.")
1174 endif()
1175
1176 string(REGEX REPLACE "\\.[^.]*\$" ${output_extension} output_file
1177 "${input_file}")
1178
1179 latex_list_contains(is_type ${extension} ${output_extensions})
1180 if(is_type)
1181 if(convert_flags)
1182 latex_add_convert_command(${output_dir}/${output_file}
1183 ${input_dir}/${input_file} ${output_extension} ${extension}
1184 "${convert_flags}")
1185 set(output_file_list ${output_dir}/${output_file})
1186 else()
1187 # As a shortcut, we can just copy the file.
1188 add_custom_command(OUTPUT ${output_dir}/${input_file}
1189 COMMAND ${CMAKE_COMMAND}
1190 ARGS -E copy ${input_dir}/${input_file} ${output_dir}/${input_file}
1191 DEPENDS ${input_dir}/${input_file}
1192 )
1193 set(output_file_list ${output_dir}/${input_file})
1194 endif()
1195 else()
1196 set(do_convert TRUE)
1197 # Check to see if there is another input file of the appropriate type.
1198 foreach(valid_extension ${output_extensions})
1199 string(REGEX REPLACE "\\.[^.]*\$" ${output_extension} try_file
1200 "${input_file}")
1201 latex_list_contains(has_native_file "${try_file}" ${other_files})
1202 if(has_native_file)
1203 set(do_convert FALSE)
1204 endif()
1205 endforeach(valid_extension)
1206
1207 # If we still need to convert, do it.
1208 if(do_convert)
1209 latex_add_convert_command(${output_dir}/${output_file}
1210 ${input_dir}/${input_file} ${output_extension} ${extension}
1211 "${convert_flags}")
1212 set(output_file_list ${output_dir}/${output_file})
1213 endif()
1214 endif()
1215
1216 set(${output_files_var} ${output_file_list} PARENT_SCOPE)
1217 endfunction(latex_convert_image)
1218
1219 # Adds custom commands to process the given files for dvi and pdf builds.
1220 # Adds the output files to the given variables (does not replace).
1221 function(latex_process_images dvi_outputs_var pdf_outputs_var)
1222 latex_get_output_path(output_dir)
1223 set(dvi_outputs)
1224 set(pdf_outputs)
1225 foreach(file ${ARGN})
1226 if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
1227 latex_get_filename_component(extension "${file}" EXT)
1228 set(convert_flags)
1229
1230 # Check to see if we need to downsample the image.
1231 latex_list_contains(is_raster "${extension}"
1232 ${LATEX_RASTER_IMAGE_EXTENSIONS})
1233 if(LATEX_SMALL_IMAGES)
1234 if(is_raster)
1235 set(convert_flags -resize ${LATEX_RASTER_SCALE}%)
1236 endif()
1237 endif()
1238
1239 # Make sure the output directory exists.
1240 latex_get_filename_component(path "${output_dir}/${file}" PATH)
1241 make_directory("${path}")
1242
1243 # Do conversions for dvi.
1244 latex_convert_image(output_files "${file}" .eps "${convert_flags}"
1245 "${LATEX_DVI_IMAGE_EXTENSIONS}" "${ARGN}")
1246 list(APPEND dvi_outputs ${output_files})
1247
1248 # Do conversions for pdf.
1249 if(is_raster)
1250 latex_convert_image(output_files "${file}" .png "${convert_flags}"
1251 "${LATEX_PDF_IMAGE_EXTENSIONS}" "${ARGN}")
1252 list(APPEND pdf_outputs ${output_files})
1253 else()
1254 latex_convert_image(output_files "${file}" .pdf "${convert_flags}"
1255 "${LATEX_PDF_IMAGE_EXTENSIONS}" "${ARGN}")
1256 list(APPEND pdf_outputs ${output_files})
1257 endif()
1258 else()
1259 message(WARNING "Could not find file ${CMAKE_CURRENT_SOURCE_DIR}/${file}. Are you sure you gave relative paths to IMAGES?")
1260 endif()
1261 endforeach(file)
1262
1263 set(${dvi_outputs_var} ${dvi_outputs} PARENT_SCOPE)
1264 set(${pdf_outputs_var} ${pdf_outputs} PARENT_SCOPE)
1265 endfunction(latex_process_images)
1266
1267 function(latex_copy_globbed_files pattern dest)
1268 file(GLOB file_list ${pattern})
1269 foreach(in_file ${file_list})
1270 latex_get_filename_component(out_file ${in_file} NAME)
1271 configure_file(${in_file} ${dest}/${out_file} COPYONLY)
1272 endforeach(in_file)
1273 endfunction(latex_copy_globbed_files)
1274
1275 function(latex_copy_input_file file)
1276 latex_get_output_path(output_dir)
1277
1278 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file})
1279 latex_get_filename_component(path ${file} PATH)
1280 file(MAKE_DIRECTORY ${output_dir}/${path})
1281
1282 latex_list_contains(use_config ${file} ${LATEX_CONFIGURE})
1283 if(use_config)
1284 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${file}
1285 ${output_dir}/${file}
1286 @ONLY
1287 )
1288 add_custom_command(OUTPUT ${output_dir}/${file}
1289 COMMAND ${CMAKE_COMMAND}
1290 ARGS ${CMAKE_BINARY_DIR}
1291 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file}
1292 )
1293 else()
1294 add_custom_command(OUTPUT ${output_dir}/${file}
1295 COMMAND ${CMAKE_COMMAND}
1296 ARGS -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${file} ${output_dir}/${file}
1297 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file}
1298 )
1299 endif()
1300 else()
1301 if(EXISTS ${output_dir}/${file})
1302 # Special case: output exists but input does not. Assume that it was
1303 # created elsewhere and skip the input file copy.
1304 else()
1305 message("Could not find input file ${CMAKE_CURRENT_SOURCE_DIR}/${file}")
1306 endif()
1307 endif()
1308 endfunction(latex_copy_input_file)
1309
1310 #############################################################################
1311 # Commands provided by the UseLATEX.cmake "package"
1312 #############################################################################
1313
1314 function(latex_usage command message)
1315 message(SEND_ERROR
1316 "${message}\n Usage: ${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 [MULTIBIB_NEWCITES] <suffix_list>\n [USE_BIBLATEX] [USE_INDEX] [USE_GLOSSARY] [USE_NOMENCL]\n [FORCE_PDF] [FORCE_DVI] [FORCE_HTML]\n [TARGET_NAME] <name>\n [EXCLUDE_FROM_ALL]\n [EXCLUDE_FROM_DEFAULTS])"
1317 )
1318 endfunction(latex_usage command message)
1319
1320 # Parses arguments to add_latex_document and ADD_LATEX_TARGETS and sets the
1321 # variables LATEX_TARGET, LATEX_IMAGE_DIR, LATEX_BIBFILES, LATEX_DEPENDS, and
1322 # LATEX_INPUTS.
1323 function(parse_add_latex_arguments command latex_main_input)
1324 set(options
1325 USE_BIBLATEX
1326 USE_INDEX
1327 USE_GLOSSARY
1328 USE_NOMENCL
1329 FORCE_PDF
1330 FORCE_DVI
1331 FORCE_HTML
1332 EXCLUDE_FROM_ALL
1333 EXCLUDE_FROM_DEFAULTS
1334 # Deprecated options
1335 USE_GLOSSARIES
1336 DEFAULT_PDF
1337 DEFAULT_SAFEPDF
1338 DEFAULT_PS
1339 NO_DEFAULT
1340 MANGLE_TARGET_NAMES
1341 )
1342 set(oneValueArgs
1343 TARGET_NAME
1344 )
1345 set(multiValueArgs
1346 BIBFILES
1347 MULTIBIB_NEWCITES
1348 INPUTS
1349 IMAGE_DIRS
1350 IMAGES
1351 CONFIGURE
1352 DEPENDS
1353 INDEX_NAMES
1354 )
1355 cmake_parse_arguments(
1356 LATEX "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
1357
1358 # Handle invalid and deprecated arguments
1359 if(LATEX_UNPARSED_ARGUMENTS)
1360 latex_usage(${command} "Invalid or deprecated arguments: ${LATEX_UNPARSED_ARGUMENTS}")
1361 endif()
1362 if(LATEX_USE_GLOSSARIES)
1363 latex_usage(${command} "USE_GLOSSARIES option removed in version 1.6.1. Use USE_GLOSSARY instead.")
1364 endif()
1365 if(LATEX_DEFAULT_PDF)
1366 latex_usage(${command} "DEFAULT_PDF option removed in version 2.0. Use FORCE_PDF option or LATEX_DEFAULT_BUILD CMake variable instead.")
1367 endif()
1368 if(LATEX_DEFAULT_SAFEPDF)
1369 latex_usage(${command} "DEFAULT_SAFEPDF option removed in version 2.0. Use LATEX_DEFAULT_BUILD CMake variable instead.")
1370 endif()
1371 if(LATEX_DEFAULT_DVI)
1372 latex_usage(${command} "DEFAULT_DVI option removed in version 2.0. Use FORCE_DVI option or LATEX_DEFAULT_BUILD CMake variable instead.")
1373 endif()
1374 if(LATEX_NO_DEFAULT)
1375 latex_usage(${command} "NO_DEFAULT option removed in version 2.0. Use EXCLUDE_FROM_ALL instead.")
1376 endif()
1377 if(LATEX_MANGLE_TARGET_NAMES)
1378 latex_usage(${command} "MANGLE_TARGET_NAMES option removed in version 2.0. All LaTeX targets use mangled names now.")
1379 endif()
1380
1381 # Capture the first argument, which is the main LaTeX input.
1382 latex_get_filename_component(latex_target ${latex_main_input} NAME_WE)
1383 set(LATEX_MAIN_INPUT ${latex_main_input} PARENT_SCOPE)
1384 set(LATEX_TARGET ${latex_target} PARENT_SCOPE)
1385
1386 # Propagate the result variables to the caller
1387 foreach(arg_name ${options} ${oneValueArgs} ${multiValueArgs})
1388 set(var_name LATEX_${arg_name})
1389 set(${var_name} ${${var_name}} PARENT_SCOPE)
1390 endforeach(arg_name)
1391 endfunction(parse_add_latex_arguments)
1392
1393 function(add_latex_targets_internal)
1394 latex_get_output_path(output_dir)
1395
1396 if(LATEX_USE_SYNCTEX)
1397 set(synctex_flags ${LATEX_SYNCTEX_ARGS})
1398 else()
1399 set(synctex_flags)
1400 endif()
1401
1402 # The commands to run LaTeX. They are repeated multiple times.
1403 set(latex_build_command
1404 ${LATEX_COMPILER} ${LATEX_COMPILER_ARGS} ${synctex_flags} ${LATEX_MAIN_INPUT}
1405 )
1406 if(LATEX_COMPILER_ARGS MATCHES ".*batchmode.*")
1407 # Wrap command in script that dumps the log file on error. This makes sure
1408 # errors can be seen.
1409 set(latex_build_command
1410 ${CMAKE_COMMAND}
1411 -D LATEX_BUILD_COMMAND=execute_latex
1412 -D LATEX_TARGET=${LATEX_TARGET}
1413 -D LATEX_WORKING_DIRECTORY="${output_dir}"
1414 -D LATEX_FULL_COMMAND="${latex_build_command}"
1415 -D LATEX_OUTPUT_FILE="${LATEX_TARGET}.dvi"
1416 -P "${LATEX_USE_LATEX_LOCATION}"
1417 )
1418 endif()
1419 set(pdflatex_build_command
1420 ${PDFLATEX_COMPILER} ${PDFLATEX_COMPILER_ARGS} ${synctex_flags} ${LATEX_MAIN_INPUT}
1421 )
1422 if(PDFLATEX_COMPILER_ARGS MATCHES ".*batchmode.*")
1423 # Wrap command in script that dumps the log file on error. This makes sure
1424 # errors can be seen.
1425 set(pdflatex_build_command
1426 ${CMAKE_COMMAND}
1427 -D LATEX_BUILD_COMMAND=execute_latex
1428 -D LATEX_TARGET=${LATEX_TARGET}
1429 -D LATEX_WORKING_DIRECTORY="${output_dir}"
1430 -D LATEX_FULL_COMMAND="${pdflatex_build_command}"
1431 -D LATEX_OUTPUT_FILE="${LATEX_TARGET}.pdf"
1432 -P "${LATEX_USE_LATEX_LOCATION}"
1433 )
1434 endif()
1435
1436 if(NOT LATEX_TARGET_NAME)
1437 # Use the main filename (minus the .tex) as the target name. Remove any
1438 # spaces since CMake cannot have spaces in its target names.
1439 string(REPLACE " " "_" LATEX_TARGET_NAME ${LATEX_TARGET})
1440 endif()
1441
1442 # Some LaTeX commands may need to be modified (or may not work) if the main
1443 # tex file is in a subdirectory. Make a flag for that.
1444 get_filename_component(LATEX_MAIN_INPUT_SUBDIR ${LATEX_MAIN_INPUT} DIRECTORY)
1445
1446 # Set up target names.
1447 set(dvi_target ${LATEX_TARGET_NAME}_dvi)
1448 set(pdf_target ${LATEX_TARGET_NAME}_pdf)
1449 set(ps_target ${LATEX_TARGET_NAME}_ps)
1450 set(safepdf_target ${LATEX_TARGET_NAME}_safepdf)
1451 set(html_target ${LATEX_TARGET_NAME}_html)
1452 set(auxclean_target ${LATEX_TARGET_NAME}_auxclean)
1453
1454 # Probably not all of these will be generated, but they could be.
1455 # Note that the aux file is added later.
1456 set(auxiliary_clean_files
1457 ${output_dir}/${LATEX_TARGET}.aux
1458 ${output_dir}/${LATEX_TARGET}.bbl
1459 ${output_dir}/${LATEX_TARGET}.blg
1460 ${output_dir}/${LATEX_TARGET}-blx.bib
1461 ${output_dir}/${LATEX_TARGET}.glg
1462 ${output_dir}/${LATEX_TARGET}.glo
1463 ${output_dir}/${LATEX_TARGET}.gls
1464 ${output_dir}/${LATEX_TARGET}.idx
1465 ${output_dir}/${LATEX_TARGET}.ilg
1466 ${output_dir}/${LATEX_TARGET}.ind
1467 ${output_dir}/${LATEX_TARGET}.ist
1468 ${output_dir}/${LATEX_TARGET}.log
1469 ${output_dir}/${LATEX_TARGET}.out
1470 ${output_dir}/${LATEX_TARGET}.toc
1471 ${output_dir}/${LATEX_TARGET}.lof
1472 ${output_dir}/${LATEX_TARGET}.xdy
1473 ${output_dir}/${LATEX_TARGET}.synctex.gz
1474 ${output_dir}/${LATEX_TARGET}.synctex.bak.gz
1475 ${output_dir}/${LATEX_TARGET}.dvi
1476 ${output_dir}/${LATEX_TARGET}.ps
1477 ${output_dir}/${LATEX_TARGET}.pdf
1478 )
1479
1480 set(image_list ${LATEX_IMAGES})
1481
1482 # For each directory in LATEX_IMAGE_DIRS, glob all the image files and
1483 # place them in LATEX_IMAGES.
1484 foreach(dir ${LATEX_IMAGE_DIRS})
1485 if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir})
1486 message(WARNING "Image directory ${CMAKE_CURRENT_SOURCE_DIR}/${dir} does not exist. Are you sure you gave relative directories to IMAGE_DIRS?")
1487 endif()
1488 foreach(extension ${LATEX_IMAGE_EXTENSIONS})
1489 file(GLOB files ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*${extension})
1490 foreach(file ${files})
1491 latex_get_filename_component(filename ${file} NAME)
1492 list(APPEND image_list ${dir}/${filename})
1493 endforeach(file)
1494 endforeach(extension)
1495 endforeach(dir)
1496
1497 latex_process_images(dvi_images pdf_images ${image_list})
1498
1499 set(make_dvi_command
1500 ${CMAKE_COMMAND} -E chdir ${output_dir}
1501 ${latex_build_command})
1502 set(make_pdf_command
1503 ${CMAKE_COMMAND} -E chdir ${output_dir}
1504 ${pdflatex_build_command}
1505 )
1506
1507 set(make_dvi_depends ${LATEX_DEPENDS} ${dvi_images})
1508 set(make_pdf_depends ${LATEX_DEPENDS} ${pdf_images})
1509 foreach(input ${LATEX_MAIN_INPUT} ${LATEX_INPUTS})
1510 list(APPEND make_dvi_depends ${output_dir}/${input})
1511 list(APPEND make_pdf_depends ${output_dir}/${input})
1512 if(${input} MATCHES "\\.tex$")
1513 # Dependent .tex files might have their own .aux files created. Make
1514 # sure these get cleaned as well. This might replicate the cleaning
1515 # of the main .aux file, which is OK.
1516 string(REGEX REPLACE "\\.tex$" "" input_we ${input})
1517 list(APPEND auxiliary_clean_files
1518 ${output_dir}/${input_we}.aux
1519 ${output_dir}/${input}.aux
1520 )
1521 endif()
1522 endforeach(input)
1523
1524 set(all_latex_sources ${LATEX_MAIN_INPUT} ${LATEX_INPUTS} ${image_list})
1525
1526 if(LATEX_USE_GLOSSARY)
1527 foreach(dummy 0 1) # Repeat these commands twice.
1528 set(make_dvi_command ${make_dvi_command}
1529 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1530 ${CMAKE_COMMAND}
1531 -D LATEX_BUILD_COMMAND=makeglossaries
1532 -D LATEX_TARGET=${LATEX_TARGET}
1533 -D MAKEINDEX_COMPILER=${MAKEINDEX_COMPILER}
1534 -D XINDY_COMPILER=${XINDY_COMPILER}
1535 -D MAKEGLOSSARIES_COMPILER_ARGS=${MAKEGLOSSARIES_COMPILER_ARGS}
1536 -P ${LATEX_USE_LATEX_LOCATION}
1537 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1538 ${latex_build_command}
1539 )
1540 set(make_pdf_command ${make_pdf_command}
1541 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1542 ${CMAKE_COMMAND}
1543 -D LATEX_BUILD_COMMAND=makeglossaries
1544 -D LATEX_TARGET=${LATEX_TARGET}
1545 -D MAKEINDEX_COMPILER=${MAKEINDEX_COMPILER}
1546 -D XINDY_COMPILER=${XINDY_COMPILER}
1547 -D MAKEGLOSSARIES_COMPILER_ARGS=${MAKEGLOSSARIES_COMPILER_ARGS}
1548 -P ${LATEX_USE_LATEX_LOCATION}
1549 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1550 ${pdflatex_build_command}
1551 )
1552 endforeach(dummy)
1553 endif()
1554
1555 if(LATEX_USE_NOMENCL)
1556 foreach(dummy 0 1) # Repeat these commands twice.
1557 set(make_dvi_command ${make_dvi_command}
1558 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1559 ${CMAKE_COMMAND}
1560 -D LATEX_BUILD_COMMAND=makenomenclature
1561 -D LATEX_TARGET=${LATEX_TARGET}
1562 -D MAKEINDEX_COMPILER=${MAKEINDEX_COMPILER}
1563 -D MAKENOMENCLATURE_COMPILER_ARGS=${MAKENOMENCLATURE_COMPILER_ARGS}
1564 -P ${LATEX_USE_LATEX_LOCATION}
1565 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1566 ${latex_build_command}
1567 )
1568 set(make_pdf_command ${make_pdf_command}
1569 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1570 ${CMAKE_COMMAND}
1571 -D LATEX_BUILD_COMMAND=makenomenclature
1572 -D LATEX_TARGET=${LATEX_TARGET}
1573 -D MAKEINDEX_COMPILER=${MAKEINDEX_COMPILER}
1574 -D MAKENOMENCLATURE_COMPILER_ARGS=${MAKENOMENCLATURE_COMPILER_ARGS}
1575 -P ${LATEX_USE_LATEX_LOCATION}
1576 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1577 ${pdflatex_build_command}
1578 )
1579 endforeach(dummy)
1580 endif()
1581
1582 if(LATEX_BIBFILES)
1583 if(LATEX_USE_BIBLATEX)
1584 if(NOT BIBER_COMPILER)
1585 message(SEND_ERROR "I need the biber command.")
1586 endif()
1587 set(bib_compiler ${BIBER_COMPILER})
1588 set(bib_compiler_flags ${BIBER_COMPILER_ARGS})
1589 else()
1590 set(bib_compiler ${BIBTEX_COMPILER})
1591 set(bib_compiler_flags ${BIBTEX_COMPILER_ARGS})
1592 endif()
1593 if(LATEX_MULTIBIB_NEWCITES)
1594 foreach (multibib_auxfile ${LATEX_MULTIBIB_NEWCITES})
1595 latex_get_filename_component(multibib_target ${multibib_auxfile} NAME_WE)
1596 set(make_dvi_command ${make_dvi_command}
1597 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1598 ${bib_compiler} ${bib_compiler_flags} ${multibib_target})
1599 set(make_pdf_command ${make_pdf_command}
1600 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1601 ${bib_compiler} ${bib_compiler_flags} ${multibib_target})
1602 set(auxiliary_clean_files ${auxiliary_clean_files}
1603 ${output_dir}/${multibib_target}.aux)
1604 endforeach (multibib_auxfile ${LATEX_MULTIBIB_NEWCITES})
1605 else()
1606 set(make_dvi_command ${make_dvi_command}
1607 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1608 ${bib_compiler} ${bib_compiler_flags} ${LATEX_TARGET})
1609 set(make_pdf_command ${make_pdf_command}
1610 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1611 ${bib_compiler} ${bib_compiler_flags} ${LATEX_TARGET})
1612 endif()
1613
1614 foreach (bibfile ${LATEX_BIBFILES})
1615 list(APPEND make_dvi_depends ${output_dir}/${bibfile})
1616 list(APPEND make_pdf_depends ${output_dir}/${bibfile})
1617 endforeach (bibfile ${LATEX_BIBFILES})
1618 else()
1619 if(LATEX_MULTIBIB_NEWCITES)
1620 message(WARNING "MULTIBIB_NEWCITES has no effect without BIBFILES option.")
1621 endif()
1622 endif()
1623
1624 if(LATEX_USE_INDEX)
1625 if(LATEX_INDEX_NAMES)
1626 set(INDEX_NAMES ${LATEX_INDEX_NAMES})
1627 else()
1628 set(INDEX_NAMES ${LATEX_TARGET})
1629 endif()
1630 foreach(idx_name ${INDEX_NAMES})
1631 set(make_dvi_command ${make_dvi_command}
1632 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1633 ${latex_build_command}
1634 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1635 ${MAKEINDEX_COMPILER} ${MAKEINDEX_COMPILER_ARGS} ${idx_name}.idx)
1636 set(make_pdf_command ${make_pdf_command}
1637 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1638 ${pdflatex_build_command}
1639 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1640 ${MAKEINDEX_COMPILER} ${MAKEINDEX_COMPILER_ARGS} ${idx_name}.idx)
1641 set(auxiliary_clean_files ${auxiliary_clean_files}
1642 ${output_dir}/${idx_name}.idx
1643 ${output_dir}/${idx_name}.ilg
1644 ${output_dir}/${idx_name}.ind)
1645 endforeach()
1646 else()
1647 if(LATEX_INDEX_NAMES)
1648 message(WARNING "INDEX_NAMES has no effect without USE_INDEX option.")
1649 endif()
1650 endif()
1651
1652 set(make_dvi_command ${make_dvi_command}
1653 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1654 ${latex_build_command}
1655 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1656 ${latex_build_command})
1657 set(make_pdf_command ${make_pdf_command}
1658 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1659 ${pdflatex_build_command}
1660 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1661 ${pdflatex_build_command})
1662
1663 # Need to run one more time to remove biblatex' warning
1664 # about page breaks that have changed.
1665 if(LATEX_USE_BIBLATEX)
1666 set(make_dvi_command ${make_dvi_command}
1667 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1668 ${latex_build_command})
1669 set(make_pdf_command ${make_pdf_command}
1670 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1671 ${pdflatex_build_command})
1672 endif()
1673
1674 if(LATEX_USE_SYNCTEX)
1675 if(NOT GZIP)
1676 message(SEND_ERROR "UseLATEX.cmake: USE_SYNTEX option requires gzip program. Set GZIP variable.")
1677 endif()
1678 set(make_dvi_command ${make_dvi_command}
1679 COMMAND ${CMAKE_COMMAND}
1680 -D LATEX_BUILD_COMMAND=correct_synctex
1681 -D LATEX_TARGET=${LATEX_TARGET}
1682 -D GZIP=${GZIP}
1683 -D "LATEX_SOURCE_DIRECTORY=${CMAKE_CURRENT_SOURCE_DIR}"
1684 -D "LATEX_BINARY_DIRECTORY=${output_dir}"
1685 -P ${LATEX_USE_LATEX_LOCATION}
1686 )
1687 set(make_pdf_command ${make_pdf_command}
1688 COMMAND ${CMAKE_COMMAND}
1689 -D LATEX_BUILD_COMMAND=correct_synctex
1690 -D LATEX_TARGET=${LATEX_TARGET}
1691 -D GZIP=${GZIP}
1692 -D "LATEX_SOURCE_DIRECTORY=${CMAKE_CURRENT_SOURCE_DIR}"
1693 -D "LATEX_BINARY_DIRECTORY=${output_dir}"
1694 -P ${LATEX_USE_LATEX_LOCATION}
1695 )
1696 endif()
1697
1698 # Check LaTeX output for important warnings at end of build
1699 set(make_dvi_command ${make_dvi_command}
1700 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1701 ${CMAKE_COMMAND}
1702 -D LATEX_BUILD_COMMAND=check_important_warnings
1703 -D LATEX_TARGET=${LATEX_TARGET}
1704 -P ${LATEX_USE_LATEX_LOCATION}
1705 )
1706 set(make_pdf_command ${make_pdf_command}
1707 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1708 ${CMAKE_COMMAND}
1709 -D LATEX_BUILD_COMMAND=check_important_warnings
1710 -D LATEX_TARGET=${LATEX_TARGET}
1711 -P ${LATEX_USE_LATEX_LOCATION}
1712 )
1713
1714 # Capture the default build.
1715 string(TOLOWER "${LATEX_DEFAULT_BUILD}" default_build)
1716
1717 if((NOT LATEX_FORCE_PDF) AND (NOT LATEX_FORCE_DVI) AND (NOT LATEX_FORCE_HTML))
1718 set(no_force TRUE)
1719 endif()
1720
1721 # Add commands and targets for building pdf outputs (with pdflatex).
1722 if(LATEX_FORCE_PDF OR no_force)
1723 if(LATEX_FORCE_PDF)
1724 set(default_build pdf)
1725 endif()
1726
1727 if(PDFLATEX_COMPILER)
1728 add_custom_command(OUTPUT ${output_dir}/${LATEX_TARGET}.pdf
1729 COMMAND ${make_pdf_command}
1730 DEPENDS ${make_pdf_depends}
1731 )
1732 add_custom_target(${pdf_target}
1733 DEPENDS ${output_dir}/${LATEX_TARGET}.pdf
1734 SOURCES ${all_latex_sources}
1735 )
1736 if(NOT LATEX_EXCLUDE_FROM_DEFAULTS)
1737 add_dependencies(pdf ${pdf_target})
1738 endif()
1739 endif()
1740 endif()
1741
1742 # Add commands and targets for building dvi outputs.
1743 if(LATEX_FORCE_DVI OR LATEX_FORCE_HTML OR no_force)
1744 if(LATEX_FORCE_DVI)
1745 if((NOT default_build STREQUAL dvi) AND
1746 (NOT default_build STREQUAL ps) AND
1747 (NOT default_build STREQUAL safepdf))
1748 set(default_build dvi)
1749 endif()
1750 endif()
1751
1752 add_custom_command(OUTPUT ${output_dir}/${LATEX_TARGET}.dvi
1753 COMMAND ${make_dvi_command}
1754 DEPENDS ${make_dvi_depends}
1755 )
1756 add_custom_target(${dvi_target}
1757 DEPENDS ${output_dir}/${LATEX_TARGET}.dvi
1758 SOURCES ${all_latex_sources}
1759 )
1760 if(NOT LATEX_EXCLUDE_FROM_DEFAULTS)
1761 add_dependencies(dvi ${dvi_target})
1762 endif()
1763
1764 if(DVIPS_CONVERTER)
1765 add_custom_command(OUTPUT ${output_dir}/${LATEX_TARGET}.ps
1766 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1767 ${DVIPS_CONVERTER} ${DVIPS_CONVERTER_ARGS} -o ${LATEX_TARGET}.ps ${LATEX_TARGET}.dvi
1768 DEPENDS ${output_dir}/${LATEX_TARGET}.dvi)
1769 add_custom_target(${ps_target}
1770 DEPENDS ${output_dir}/${LATEX_TARGET}.ps
1771 SOURCES ${all_latex_sources}
1772 )
1773 if(NOT LATEX_EXCLUDE_FROM_DEFAULTS)
1774 add_dependencies(ps ${ps_target})
1775 endif()
1776 if(PS2PDF_CONVERTER)
1777 # Since both the pdf and safepdf targets have the same output, we
1778 # cannot properly do the dependencies for both. When selecting safepdf,
1779 # simply force a recompile every time.
1780 add_custom_target(${safepdf_target}
1781 ${CMAKE_COMMAND} -E chdir ${output_dir}
1782 ${PS2PDF_CONVERTER} ${PS2PDF_CONVERTER_ARGS} ${LATEX_TARGET}.ps ${LATEX_TARGET}.pdf
1783 DEPENDS ${ps_target}
1784 )
1785 if(NOT LATEX_EXCLUDE_FROM_DEFAULTS)
1786 add_dependencies(safepdf ${safepdf_target})
1787 endif()
1788 endif()
1789 endif()
1790 endif()
1791
1792 if(LATEX_FORCE_HTML OR no_force)
1793 if (LATEX_FORCE_HTML)
1794 set(default_build html)
1795 endif()
1796
1797 if(HTLATEX_COMPILER AND LATEX_MAIN_INPUT_SUBDIR)
1798 message(STATUS
1799 "Disabling HTML build for ${LATEX_TARGET_NAME}.tex because the main file is in subdirectory ${LATEX_MAIN_INPUT_SUBDIR}"
1800 )
1801 # The code below to run HTML assumes that LATEX_TARGET.tex is in the
1802 # current directory. I have tried to specify that LATEX_TARGET.tex is
1803 # in a subdirectory. That makes the build targets correct, but the
1804 # HTML build still fails (at least for htlatex) because files are not
1805 # generated where expected. I am getting around the problem by simply
1806 # disabling HTML in this case. If someone really cares, they can fix
1807 # this, but make sure it runs on many platforms and build programs.
1808 elseif(HTLATEX_COMPILER)
1809 # htlatex places the output in a different location
1810 set(HTML_OUTPUT "${output_dir}/${LATEX_TARGET}.html")
1811 add_custom_command(OUTPUT ${HTML_OUTPUT}
1812 COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
1813 ${HTLATEX_COMPILER} ${LATEX_MAIN_INPUT}
1814 "${HTLATEX_COMPILER_TEX4HT_FLAGS}"
1815 "${HTLATEX_COMPILER_TEX4HT_POSTPROCESSOR_FLAGS}"
1816 "${HTLATEX_COMPILER_T4HT_POSTPROCESSOR_FLAGS}"
1817 ${HTLATEX_COMPILER_ARGS}
1818 DEPENDS
1819 ${output_dir}/${LATEX_TARGET}.tex
1820 ${output_dir}/${LATEX_TARGET}.dvi
1821 VERBATIM
1822 )
1823 add_custom_target(${html_target}
1824 DEPENDS ${HTML_OUTPUT} ${dvi_target}
1825 SOURCES ${all_latex_sources}
1826 )
1827 if(NOT LATEX_EXCLUDE_FROM_DEFAULTS)
1828 add_dependencies(html ${html_target})
1829 endif()
1830 endif()
1831 endif()
1832
1833 # Set default targets.
1834 if("${default_build}" STREQUAL "pdf")
1835 add_custom_target(${LATEX_TARGET_NAME} DEPENDS ${pdf_target})
1836 elseif("${default_build}" STREQUAL "dvi")
1837 add_custom_target(${LATEX_TARGET_NAME} DEPENDS ${dvi_target})
1838 elseif("${default_build}" STREQUAL "ps")
1839 add_custom_target(${LATEX_TARGET_NAME} DEPENDS ${ps_target})
1840 elseif("${default_build}" STREQUAL "safepdf")
1841 add_custom_target(${LATEX_TARGET_NAME} DEPENDS ${safepdf_target})
1842 elseif("${default_build}" STREQUAL "html")
1843 add_custom_target(${LATEX_TARGET_NAME} DEPENDS ${html_target})
1844 else()
1845 message(SEND_ERROR "LATEX_DEFAULT_BUILD set to an invalid value. See the documentation for that variable.")
1846 endif()
1847
1848 if(NOT LATEX_EXCLUDE_FROM_ALL)
1849 add_custom_target(_${LATEX_TARGET_NAME} ALL DEPENDS ${LATEX_TARGET_NAME})
1850 endif()
1851
1852 set_directory_properties(.
1853 ADDITIONAL_MAKE_CLEAN_FILES "${auxiliary_clean_files}"
1854 )
1855
1856 add_custom_target(${auxclean_target}
1857 COMMENT "Cleaning auxiliary LaTeX files."
1858 COMMAND ${CMAKE_COMMAND} -E remove ${auxiliary_clean_files}
1859 )
1860 add_dependencies(auxclean ${auxclean_target})
1861 endfunction(add_latex_targets_internal)
1862
1863 function(add_latex_targets latex_main_input)
1864 latex_get_output_path(output_dir)
1865 parse_add_latex_arguments(ADD_LATEX_TARGETS ${latex_main_input} ${ARGN})
1866
1867 add_latex_targets_internal()
1868 endfunction(add_latex_targets)
1869
1870 function(add_latex_document latex_main_input)
1871 latex_get_output_path(output_dir)
1872 if(output_dir)
1873 parse_add_latex_arguments(add_latex_document ${latex_main_input} ${ARGN})
1874
1875 latex_copy_input_file(${LATEX_MAIN_INPUT})
1876
1877 foreach (bib_file ${LATEX_BIBFILES})
1878 latex_copy_input_file(${bib_file})
1879 endforeach (bib_file)
1880
1881 foreach (input ${LATEX_INPUTS})
1882 latex_copy_input_file(${input})
1883 endforeach(input)
1884
1885 latex_copy_globbed_files(${CMAKE_CURRENT_SOURCE_DIR}/*.cls ${output_dir})
1886 latex_copy_globbed_files(${CMAKE_CURRENT_SOURCE_DIR}/*.bst ${output_dir})
1887 latex_copy_globbed_files(${CMAKE_CURRENT_SOURCE_DIR}/*.clo ${output_dir})
1888 latex_copy_globbed_files(${CMAKE_CURRENT_SOURCE_DIR}/*.sty ${output_dir})
1889 latex_copy_globbed_files(${CMAKE_CURRENT_SOURCE_DIR}/*.ist ${output_dir})
1890 latex_copy_globbed_files(${CMAKE_CURRENT_SOURCE_DIR}/*.fd ${output_dir})
1891
1892 add_latex_targets_internal()
1893 endif()
1894 endfunction(add_latex_document)
1895
1896 #############################################################################
1897 # Actually do stuff
1898 #############################################################################
1899
1900 if(LATEX_BUILD_COMMAND)
1901 set(command_handled)
1902
1903 if("${LATEX_BUILD_COMMAND}" STREQUAL execute_latex)
1904 latex_execute_latex()
1905 set(command_handled TRUE)
1906 endif()
1907
1908 if("${LATEX_BUILD_COMMAND}" STREQUAL makeglossaries)
1909 latex_makeglossaries()
1910 set(command_handled TRUE)
1911 endif()
1912
1913 if("${LATEX_BUILD_COMMAND}" STREQUAL makenomenclature)
1914 latex_makenomenclature()
1915 set(command_handled TRUE)
1916 endif()
1917
1918 if("${LATEX_BUILD_COMMAND}" STREQUAL correct_synctex)
1919 latex_correct_synctex()
1920 set(command_handled TRUE)
1921 endif()
1922
1923 if("${LATEX_BUILD_COMMAND}" STREQUAL check_important_warnings)
1924 latex_check_important_warnings()
1925 set(command_handled TRUE)
1926 endif()
1927
1928 if(NOT command_handled)
1929 message(SEND_ERROR "Unknown command: ${LATEX_BUILD_COMMAND}")
1930 endif()
1931
1932 else()
1933 # Must be part of the actual configure (included from CMakeLists.txt).
1934 latex_setup_variables()
1935 latex_setup_targets()
1936 endif()