UseLATEX.cmake 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968
  1. # File: UseLATEX.cmake
  2. # CMAKE commands to actually use the LaTeX compiler
  3. # Version: 2.4.9
  4. # Author: Kenneth Moreland <kmorel@sandia.gov>
  5. #
  6. # Copyright 2004, 2015 Sandia Corporation.
  7. # Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
  8. # license for use of this work by or on behalf of the U.S. Government.
  9. #
  10. # This software is released under the BSD 3-Clause License.
  11. #
  12. # Redistribution and use in source and binary forms, with or without
  13. # modification, are permitted provided that the following conditions are
  14. # met:
  15. #
  16. # 1. Redistributions of source code must retain the above copyright notice,
  17. # this list of conditions and the following disclaimer.
  18. #
  19. # 2. Redistributions in binary form must reproduce the above copyright
  20. # notice, this list of conditions and the following disclaimer in the
  21. # documentation and/or other materials provided with the distribution.
  22. #
  23. # 3. Neither the name of the copyright holder nor the names of its
  24. # contributors may be used to endorse or promote products derived from this
  25. # software without specific prior written permission.
  26. #
  27. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28. # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29. # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30. # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  31. # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  32. # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  33. # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34. # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35. # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  36. # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  37. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. #
  39. #
  40. # The following function is defined:
  41. #
  42. # add_latex_document(<tex_file>
  43. # [BIBFILES <bib_files>]
  44. # [INPUTS <input_tex_files>]
  45. # [IMAGE_DIRS] <image_directories>
  46. # [IMAGES] <image_files>
  47. # [CONFIGURE] <tex_files>
  48. # [DEPENDS] <tex_files>
  49. # [MULTIBIB_NEWCITES] <suffix_list>
  50. # [USE_BIBLATEX]
  51. # [USE_INDEX]
  52. # [INDEX_NAMES <index_names>]
  53. # [USE_GLOSSARY] [USE_NOMENCL]
  54. # [FORCE_PDF] [FORCE_DVI] [FORCE_HTML]
  55. # [TARGET_NAME] <name>
  56. # [EXCLUDE_FROM_ALL]
  57. # [EXCLUDE_FROM_DEFAULTS])
  58. # Adds targets that compile <tex_file>. The latex output is placed
  59. # in LATEX_OUTPUT_PATH or CMAKE_CURRENT_BINARY_DIR if the former is
  60. # not set. The latex program is picky about where files are located,
  61. # so all input files are copied from the source directory to the
  62. # output directory. This includes the target tex file, any tex file
  63. # listed with the INPUTS option, the bibliography files listed with
  64. # the BIBFILES option, and any .cls, .bst, .clo, .sty, .ist, and .fd
  65. # files found in the current source directory. Images found in the
  66. # IMAGE_DIRS directories or listed by IMAGES are also copied to the
  67. # output directory and converted to an appropriate format if necessary.
  68. # Any tex files also listed with the CONFIGURE option are also processed
  69. # with the CMake CONFIGURE_FILE command (with the @ONLY flag). Any file
  70. # listed in CONFIGURE but not the target tex file or listed with INPUTS
  71. # has no effect. DEPENDS can be used to specify generated files that are
  72. # needed to compile the latex target.
  73. #
  74. # The following targets are made. The name prefix is based off of the
  75. # base name of the tex file unless TARGET_NAME is specified. If
  76. # TARGET_NAME is specified, then that name is used for the targets.
  77. #
  78. # name_dvi: Makes <name>.dvi
  79. # name_pdf: Makes <name>.pdf using pdflatex.
  80. # name_safepdf: Makes <name>.pdf using ps2pdf. If using the
  81. # default program arguments, this will ensure all fonts
  82. # are embedded and no lossy compression has been
  83. # performed on images.
  84. # name_ps: Makes <name>.ps
  85. # name_html: Makes <name>.html
  86. # name_auxclean: Deletes <name>.aux and other auxiliary files.
  87. # This is sometimes necessary if a LaTeX error occurs
  88. # and writes a bad aux file. Unlike the regular clean
  89. # target, it does not delete other input files, such as
  90. # converted images, to save time on the rebuild.
  91. #
  92. # Unless the EXCLUDE_FROM_ALL option is given, one of these targets
  93. # is added to the ALL target and built by default. Which target is
  94. # determined by the LATEX_DEFAULT_BUILD CMake variable. See the
  95. # documentation of that variable for more details.
  96. #
  97. # Unless the EXCLUDE_FROM_DEFAULTS option is given, all these targets
  98. # are added as dependencies to targets named dvi, pdf, safepdf, ps,
  99. # html, and auxclean, respectively.
  100. #
  101. # USE_BIBLATEX enables the use of biblatex/biber as an alternative to
  102. # bibtex. Bibtex remains the default if USE_BIBLATEX is not
  103. # specified.
  104. #
  105. # If the argument USE_INDEX is given, then commands to build an index
  106. # are made. If the argument INDEX_NAMES is given, an index file is
  107. # generated for each name in this list. See the LaTeX package multind
  108. # for more information about how to generate multiple indices.
  109. #
  110. # If the argument USE_GLOSSARY is given, then commands to
  111. # build a glossary are made. If the argument MULTIBIB_NEWCITES is
  112. # given, then additional bibtex calls are added to the build to
  113. # support the extra auxiliary files created with the \newcite command
  114. # in the multibib package.
  115. #
  116. # History:
  117. #
  118. # 2.4.9 Use biblatex.cfg file if it exists and the USE_BIBLATEX option is ON.
  119. #
  120. # 2.4.8 Fix synctex issue with absolute paths not being converted.
  121. #
  122. # 2.4.7 Fix some issues with spaces in the path of the working directory where
  123. # LaTeX is executed.
  124. #
  125. # 2.4.6 Fix parse issue with older versions of CMake.
  126. #
  127. # 2.4.5 Fix issues with files and paths containing spaces.
  128. #
  129. # 2.4.4 Improve error reporting message when LaTeX fails.
  130. #
  131. # When LaTeX fails, delete the output file, which is invalid.
  132. #
  133. # Add warnings for "missing characters." These usually mean that a
  134. # non-ASCII character is in the document and will not be printed
  135. # correctly.
  136. #
  137. # 2.4.3 Check for warnings from the natbib package. When using natbib,
  138. # warnings for missing bibliography references look different. So
  139. # far, natbib seems to be quiet unless something is important, so
  140. # look for all natbib warnings. (We can change this later if
  141. # necessary.)
  142. #
  143. # 2.4.2 Fix an issue where new versions of ImageMagick expect the order of
  144. # options in command line execution of magick/convert. (See, for
  145. # example, http://www.imagemagick.org/Usage/basics/#why.)
  146. #
  147. # 2.4.1 Add ability to dump LaTeX log file when using batch mode. Batch
  148. # mode suppresses most output, often including error messages. To
  149. # make sure critical error messages get displayed, show the full log
  150. # on failures.
  151. #
  152. # 2.4.0 Remove "-r 600" from the default PDFTOPS_CONVERTER_FLAGS. The -r flag
  153. # is available from the Poppler version of pdftops, but not the Xpdf
  154. # version.
  155. #
  156. # Fix an issue with the flags for the different programs not being
  157. # properly separated.
  158. #
  159. # Fix an issue on windows where the = character is not allowed for
  160. # ps2pdf arguments.
  161. #
  162. # Change default arguments for latex and pdflatex commands. Makes the
  163. # output more quiet and prints out the file/line where errors occur.
  164. # (Thanks to Nikos Koukis.)
  165. #
  166. # After a LaTeX build, check the log file for warnings that are
  167. # indicative of problems with the build.
  168. #
  169. # Remove support for latex2html. Instead, use the htlatex program.
  170. # This is now part of TeX Live and most other distributions. It also
  171. # behaves much more like the other LaTeX programs. Also fixed some
  172. # nasty issues with the htlatex arguments.
  173. #
  174. # 2.3.2 Declare LaTeX input files as sources for targets so that they show
  175. # up in IDEs like QtCreator.
  176. #
  177. # Fix issue where main tex files in subdirectories were creating
  178. # invalid targets for building HTML. Just disable the HTML targets in
  179. # this case.
  180. #
  181. # 2.3.1 Support use of magick command instead of convert command for
  182. # ImageMagick 7.
  183. #
  184. # 2.3.0 Add USE_BIBLATEX option to support the biblatex package, which
  185. # requires using the program biber as a replacement for bibtex
  186. # (thanks to David Tracey).
  187. #
  188. # 2.2.1 Add STRINGS property to LATEX_DEFAULT_BUILD to make it easier to
  189. # select the default build in the CMake GUI.
  190. #
  191. # 2.2.0 Add TARGET_NAME option.
  192. #
  193. # 2.1.1 Support for finding bmp, ppm, and other image files.
  194. #
  195. # 2.1.0 Fix an error where the pdf target and others were defined multiple
  196. # times if UseLATEX.cmake was included multiple times.
  197. #
  198. # Added INDEX_NAMES option to support multiple indexes in a single
  199. # document from the multind package (thanks to Dan Lipsa).
  200. #
  201. # 2.0.0 First major revision of UseLATEX.cmake updates to more recent features
  202. # of CMake and some non-backward compatible changes.
  203. #
  204. # Changed all function and macro names to lower case. CMake's identifiers
  205. # are case insensitive, but the convention moved from all upper case to
  206. # all lower case somewhere around the release of CMake 2. (The original
  207. # version of UseLATEX.cmake predates that.)
  208. #
  209. # Remove condition matching in if statements. They are no longer necessary
  210. # and are even discouraged (because else clauses get confusing).
  211. #
  212. # Use "new" features available in CMake such as list and argument parsing.
  213. #
  214. # Remove some code that has been deprecated for a while.
  215. #
  216. # Mark variables for compiler and converter executables as advanced to
  217. # match the more conventional CMake behavior.
  218. #
  219. # Changed how default builds are specified and add the ability to force
  220. # a particular build.
  221. #
  222. # Made the base targets (pdf, dvi, etc.) global. add_latex_document
  223. # always mangles its target names and these base targets depend on
  224. # the targets with mangled names.
  225. #
  226. # 1.10.5 Fix for Window's convert check (thanks to Martin Baute).
  227. #
  228. # 1.10.4 Copy font files to binary directory for packages that come with
  229. # their own fonts.
  230. #
  231. # 1.10.3 Check for Windows version of convert being used instead of
  232. # ImageMagick's version (thanks to Martin Baute).
  233. #
  234. # 1.10.2 Use htlatex as a fallback when latex2html is not available (thanks
  235. # to Tomasz Grzegurzko).
  236. #
  237. # 1.10.1 Make convert program mandatory only if actually used (thanks to
  238. # Julien Schueller).
  239. #
  240. # 1.10.0 Added NO_DEFAULT and DEFAULT_PS options.
  241. # Fixed issue with cleaning files for LaTeX documents originating in
  242. # a subdirectory.
  243. #
  244. # 1.9.6 Fixed problem with LATEX_SMALL_IMAGES.
  245. # Strengthened check to make sure the output directory does not contain
  246. # the source files.
  247. #
  248. # 1.9.5 Add support for image types not directly supported by either latex
  249. # or pdflatex. (Thanks to Jorge Gerardo Pena Pastor for SVG support.)
  250. #
  251. # 1.9.4 Fix issues with filenames containing multiple periods.
  252. #
  253. # 1.9.3 Hide some variables that are now cached but should not show up in
  254. # the ccmake list of variables.
  255. #
  256. # 1.9.2 Changed MACRO declarations to FUNCTION declarations. The better
  257. # FUNCTION scoping will hopefully avoid some common but subtle bugs.
  258. # This implicitly increases the minimum CMake version to 4.6 (although
  259. # I honestly only test it with the latest 4.8 version).
  260. #
  261. # Since we are updating the minimum CMake version, I'm going to start
  262. # using the builtin LIST commands that are now available.
  263. #
  264. # Favor using pdftops from the Poppler package to convert from pdf to
  265. # eps. It does a much better job than ImageMagick or ghostscript.
  266. #
  267. # 1.9.1 Fixed typo that caused the LATEX_SMALL_IMAGES option to fail to
  268. # activate.
  269. #
  270. # 1.9.0 Add support for the multibib package (thanks to Antonio LaTorre).
  271. #
  272. # 1.8.2 Fix corner case when an argument name was also a variable containing
  273. # the text of an argument. In this case, the CMake IF was matching
  274. # the argument text with the contents of the variable with the same
  275. # argument name.
  276. #
  277. # 1.8.1 Fix problem where ps2pdf was not getting the appropriate arguments.
  278. #
  279. # 1.8.0 Add support for synctex.
  280. #
  281. # 1.7.7 Support calling xindy when making glossaries.
  282. #
  283. # Improved make clean support.
  284. #
  285. # 1.7.6 Add support for the nomencl package (thanks to Myles English).
  286. #
  287. # 1.7.5 Fix issue with bibfiles being copied two different ways, which causes
  288. # Problems with dependencies (thanks to Edwin van Leeuwen).
  289. #
  290. # 1.7.4 Added the DEFAULT_SAFEPDF option (thanks to Raymond Wan).
  291. #
  292. # Added warnings when image directories are not found (and were
  293. # probably not given relative to the source directory).
  294. #
  295. # 1.7.3 Fix some issues with interactions between makeglossaries and bibtex
  296. # (thanks to Mark de Wever).
  297. #
  298. # 1.7.2 Use ps2pdf to convert eps to pdf to get around the problem with
  299. # ImageMagick dropping the bounding box (thanks to Lukasz Lis).
  300. #
  301. # 1.7.1 Fixed some dependency issues.
  302. #
  303. # 1.7.0 Added DEPENDS options (thanks to Theodore Papadopoulo).
  304. #
  305. # 1.6.1 Ported the makeglossaries command to CMake and embedded the port
  306. # into UseLATEX.cmake.
  307. #
  308. # 1.6.0 Allow the use of the makeglossaries command. Thanks to Oystein
  309. # S. Haaland for the patch.
  310. #
  311. # 1.5.0 Allow any type of file in the INPUTS lists, not just tex file
  312. # (suggested by Eric Noulard). As a consequence, the ability to
  313. # specify tex files without the .tex extension is removed. The removed
  314. # function is of dubious value anyway.
  315. #
  316. # When copying input files, skip over any file that exists in the
  317. # binary directory but does not exist in the source directory with the
  318. # assumption that these files were added by some other mechanism. I
  319. # find this useful when creating large documents with multiple
  320. # chapters that I want to build separately (for speed) as I work on
  321. # them. I use the same boilerplate as the starting point for all
  322. # and just copy it with different configurations. This was what the
  323. # separate ADD_LATEX_DOCUMENT method was supposed to originally be for.
  324. # Since its external use is pretty much deprecated, I removed that
  325. # documentation.
  326. #
  327. # 1.4.1 Copy .sty files along with the other class and package files.
  328. #
  329. # 1.4.0 Added a MANGLE_TARGET_NAMES option that will mangle the target names.
  330. #
  331. # Fixed problem with copying bib files that became apparent with
  332. # CMake 2.4.
  333. #
  334. # 1.3.0 Added a LATEX_OUTPUT_PATH variable that allows you or the user to
  335. # specify where the built latex documents to go. This is especially
  336. # handy if you want to do in-source builds.
  337. #
  338. # Removed the ADD_LATEX_IMAGES macro and absorbed the functionality
  339. # into ADD_LATEX_DOCUMENT. The old interface was always kind of
  340. # clunky anyway since you had to specify the image directory in both
  341. # places. It also made supporting LATEX_OUTPUT_PATH problematic.
  342. #
  343. # Added support for jpeg files.
  344. #
  345. # 1.2.0 Changed the configuration options yet again. Removed the NO_CONFIGURE
  346. # Replaced it with a CONFIGURE option that lists input files for which
  347. # configure should be run.
  348. #
  349. # The pdf target no longer depends on the dvi target. This allows you
  350. # to build latex documents that require pdflatex. Also added an option
  351. # to make the pdf target the default one.
  352. #
  353. # 1.1.1 Added the NO_CONFIGURE option. The @ character can be used when
  354. # specifying table column separators. If two or more are used, then
  355. # will incorrectly substitute them.
  356. #
  357. # 1.1.0 Added ability include multiple bib files. Added ability to do copy
  358. # sub-tex files for multipart tex files.
  359. #
  360. # 1.0.0 If both ps and pdf type images exist, just copy the one that
  361. # matches the current render mode. Replaced a bunch of STRING
  362. # commands with GET_FILENAME_COMPONENT commands that were made to do
  363. # the desired function.
  364. #
  365. # 0.4.0 First version posted to CMake Wiki.
  366. #
  367. if(__USE_LATEX_INCLUDED)
  368. return()
  369. endif()
  370. set(__USE_LATEX_INCLUDED TRUE)
  371. #############################################################################
  372. # Find the location of myself while originally executing. If you do this
  373. # inside of a macro, it will recode where the macro was invoked.
  374. #############################################################################
  375. set(LATEX_USE_LATEX_LOCATION ${CMAKE_CURRENT_LIST_FILE}
  376. CACHE INTERNAL "Location of UseLATEX.cmake file." FORCE
  377. )
  378. #############################################################################
  379. # Generic helper functions
  380. #############################################################################
  381. include(CMakeParseArguments)
  382. function(latex_list_contains var value)
  383. set(input_list ${ARGN})
  384. list(FIND input_list "${value}" index)
  385. if(index GREATER -1)
  386. set(${var} TRUE PARENT_SCOPE)
  387. else()
  388. set(${var} PARENT_SCOPE)
  389. endif()
  390. endfunction(latex_list_contains)
  391. # Match the contents of a file to a regular expression.
  392. function(latex_file_match variable filename regexp default)
  393. # The FILE STRINGS command would be a bit better, but I'm not totally sure
  394. # the match will always be to a whole line, and I don't want to break things.
  395. file(READ ${filename} file_contents)
  396. string(REGEX MATCHALL "${regexp}"
  397. match_result ${file_contents}
  398. )
  399. if(match_result)
  400. set(${variable} "${match_result}" PARENT_SCOPE)
  401. else()
  402. set(${variable} "${default}" PARENT_SCOPE)
  403. endif()
  404. endfunction(latex_file_match)
  405. # A version of GET_FILENAME_COMPONENT that treats extensions after the last
  406. # period rather than the first. To the best of my knowledge, all filenames
  407. # typically used by LaTeX, including image files, have small extensions
  408. # after the last dot.
  409. function(latex_get_filename_component varname filename type)
  410. set(result)
  411. if("${type}" STREQUAL "NAME_WE")
  412. get_filename_component(name ${filename} NAME)
  413. string(REGEX REPLACE "\\.[^.]*\$" "" result "${name}")
  414. elseif("${type}" STREQUAL "EXT")
  415. get_filename_component(name ${filename} NAME)
  416. string(REGEX MATCH "\\.[^.]*\$" result "${name}")
  417. else()
  418. get_filename_component(result ${filename} ${type})
  419. endif()
  420. set(${varname} "${result}" PARENT_SCOPE)
  421. endfunction(latex_get_filename_component)
  422. #############################################################################
  423. # Functions that perform processing during a LaTeX build.
  424. #############################################################################
  425. function(latex_execute_latex)
  426. if(NOT LATEX_TARGET)
  427. message(SEND_ERROR "Need to define LATEX_TARGET")
  428. endif()
  429. if(NOT LATEX_WORKING_DIRECTORY)
  430. message(SEND_ERROR "Need to define LATEX_WORKING_DIRECTORY")
  431. endif()
  432. if(NOT LATEX_FULL_COMMAND)
  433. message(SEND_ERROR "Need to define LATEX_FULL_COMMAND")
  434. endif()
  435. if(NOT LATEX_OUTPUT_FILE)
  436. message(SEND_ERROR "Need to define LATEX_OUTPUT_FILE")
  437. endif()
  438. set(full_command_original "${LATEX_FULL_COMMAND}")
  439. # Chose the native method for parsing command arguments. Newer versions of
  440. # CMake allow you to just use NATIVE_COMMAND.
  441. if (CMAKE_VERSION VERSION_GREATER 3.8)
  442. set(separate_arguments_mode NATIVE_COMMAND)
  443. else()
  444. if (WIN32)
  445. set(separate_arguments_mode WINDOWS_COMMAND)
  446. else()
  447. set(separate_arguments_mode UNIX_COMMAND)
  448. endif()
  449. endif()
  450. # Preps variables for use in execute_process.
  451. # Even though we expect LATEX_WORKING_DIRECTORY to have a single "argument,"
  452. # we also want to make sure that we strip out any escape characters that can
  453. # foul up the WORKING_DIRECTORY argument.
  454. separate_arguments(LATEX_FULL_COMMAND UNIX_COMMAND "${LATEX_FULL_COMMAND}")
  455. separate_arguments(LATEX_WORKING_DIRECTORY_SEP UNIX_COMMAND "${LATEX_WORKING_DIRECTORY}")
  456. execute_process(
  457. COMMAND ${LATEX_FULL_COMMAND}
  458. WORKING_DIRECTORY "${LATEX_WORKING_DIRECTORY_SEP}"
  459. RESULT_VARIABLE execute_result
  460. )
  461. if(NOT ${execute_result} EQUAL 0)
  462. # LaTeX tends to write a file when a failure happens. Delete that file so
  463. # that LaTeX will run again.
  464. file(REMOVE "${LATEX_WORKING_DIRECTORY}/${LATEX_OUTPUT_FILE}")
  465. message("\n\nLaTeX command failed")
  466. message("${full_command_original}")
  467. message("Log output:")
  468. file(READ "${LATEX_WORKING_DIRECTORY}/${LATEX_TARGET}.log" log_output)
  469. message("${log_output}")
  470. message(FATAL_ERROR
  471. "Successfully executed LaTeX, but LaTeX returned an error.")
  472. endif()
  473. endfunction(latex_execute_latex)
  474. function(latex_makeglossaries)
  475. # This is really a bare bones port of the makeglossaries perl script into
  476. # CMake scripting.
  477. message("**************************** In makeglossaries")
  478. if(NOT LATEX_TARGET)
  479. message(SEND_ERROR "Need to define LATEX_TARGET")
  480. endif()
  481. set(aux_file ${LATEX_TARGET}.aux)
  482. if(NOT EXISTS ${aux_file})
  483. message(SEND_ERROR "${aux_file} does not exist. Run latex on your target file.")
  484. endif()
  485. latex_file_match(newglossary_lines ${aux_file}
  486. "@newglossary[ \t]*{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}"
  487. "@newglossary{main}{glg}{gls}{glo}"
  488. )
  489. latex_file_match(istfile_line ${aux_file}
  490. "@istfilename[ \t]*{([^}]*)}"
  491. "@istfilename{${LATEX_TARGET}.ist}"
  492. )
  493. string(REGEX REPLACE "@istfilename[ \t]*{([^}]*)}" "\\1"
  494. istfile ${istfile_line}
  495. )
  496. string(REGEX MATCH ".*\\.xdy" use_xindy "${istfile}")
  497. if(use_xindy)
  498. message("*************** Using xindy")
  499. if(NOT XINDY_COMPILER)
  500. message(SEND_ERROR "Need to define XINDY_COMPILER")
  501. endif()
  502. else()
  503. message("*************** Using makeindex")
  504. if(NOT MAKEINDEX_COMPILER)
  505. message(SEND_ERROR "Need to define MAKEINDEX_COMPILER")
  506. endif()
  507. endif()
  508. foreach(newglossary ${newglossary_lines})
  509. string(REGEX REPLACE
  510. "@newglossary[ \t]*{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}"
  511. "\\1" glossary_name ${newglossary}
  512. )
  513. string(REGEX REPLACE
  514. "@newglossary[ \t]*{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}"
  515. "${LATEX_TARGET}.\\2" glossary_log ${newglossary}
  516. )
  517. string(REGEX REPLACE
  518. "@newglossary[ \t]*{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}"
  519. "${LATEX_TARGET}.\\3" glossary_out ${newglossary}
  520. )
  521. string(REGEX REPLACE
  522. "@newglossary[ \t]*{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}"
  523. "${LATEX_TARGET}.\\4" glossary_in ${newglossary}
  524. )
  525. if(use_xindy)
  526. latex_file_match(xdylanguage_line ${aux_file}
  527. "@xdylanguage[ \t]*{${glossary_name}}{([^}]*)}"
  528. "@xdylanguage{${glossary_name}}{english}"
  529. )
  530. string(REGEX REPLACE
  531. "@xdylanguage[ \t]*{${glossary_name}}{([^}]*)}"
  532. "\\1"
  533. language
  534. ${xdylanguage_line}
  535. )
  536. # What crazy person makes a LaTeX index generator that uses different
  537. # identifiers for language than babel (or at least does not support
  538. # the old ones)?
  539. if(${language} STREQUAL "frenchb")
  540. set(language "french")
  541. elseif(${language} MATCHES "^n?germanb?$")
  542. set(language "german")
  543. elseif(${language} STREQUAL "magyar")
  544. set(language "hungarian")
  545. elseif(${language} STREQUAL "lsorbian")
  546. set(language "lower-sorbian")
  547. elseif(${language} STREQUAL "norsk")
  548. set(language "norwegian")
  549. elseif(${language} STREQUAL "portuges")
  550. set(language "portuguese")
  551. elseif(${language} STREQUAL "russianb")
  552. set(language "russian")
  553. elseif(${language} STREQUAL "slovene")
  554. set(language "slovenian")
  555. elseif(${language} STREQUAL "ukraineb")
  556. set(language "ukrainian")
  557. elseif(${language} STREQUAL "usorbian")
  558. set(language "upper-sorbian")
  559. endif()
  560. if(language)
  561. set(language_flags "-L ${language}")
  562. else()
  563. set(language_flags "")
  564. endif()
  565. latex_file_match(codepage_line ${aux_file}
  566. "@gls@codepage[ \t]*{${glossary_name}}{([^}]*)}"
  567. "@gls@codepage{${glossary_name}}{utf}"
  568. )
  569. string(REGEX REPLACE
  570. "@gls@codepage[ \t]*{${glossary_name}}{([^}]*)}"
  571. "\\1"
  572. codepage
  573. ${codepage_line}
  574. )
  575. if(codepage)
  576. set(codepage_flags "-C ${codepage}")
  577. else()
  578. # Ideally, we would check that the language is compatible with the
  579. # default codepage, but I'm hoping that distributions will be smart
  580. # enough to specify their own codepage. I know, it's asking a lot.
  581. set(codepage_flags "")
  582. endif()
  583. message("${XINDY_COMPILER} ${MAKEGLOSSARIES_COMPILER_ARGS} ${language_flags} ${codepage_flags} -I xindy -M ${glossary_name} -t ${glossary_log} -o ${glossary_out} ${glossary_in}"
  584. )
  585. exec_program(${XINDY_COMPILER}
  586. ARGS ${MAKEGLOSSARIES_COMPILER_ARGS}
  587. ${language_flags}
  588. ${codepage_flags}
  589. -I xindy
  590. -M ${glossary_name}
  591. -t ${glossary_log}
  592. -o ${glossary_out}
  593. ${glossary_in}
  594. OUTPUT_VARIABLE xindy_output
  595. )
  596. message("${xindy_output}")
  597. # So, it is possible (perhaps common?) for aux files to specify a
  598. # language and codepage that are incompatible with each other. Check
  599. # for that condition, and if it happens run again with the default
  600. # codepage.
  601. if("${xindy_output}" MATCHES "^Cannot locate xindy module for language (.+) in codepage (.+)\\.$")
  602. message("*************** Retrying xindy with default codepage.")
  603. exec_program(${XINDY_COMPILER}
  604. ARGS ${MAKEGLOSSARIES_COMPILER_ARGS}
  605. ${language_flags}
  606. -I xindy
  607. -M ${glossary_name}
  608. -t ${glossary_log}
  609. -o ${glossary_out}
  610. ${glossary_in}
  611. )
  612. endif()
  613. else()
  614. message("${MAKEINDEX_COMPILER} ${MAKEGLOSSARIES_COMPILER_ARGS} -s ${istfile} -t ${glossary_log} -o ${glossary_out} ${glossary_in}")
  615. exec_program(${MAKEINDEX_COMPILER} ARGS ${MAKEGLOSSARIES_COMPILER_ARGS}
  616. -s ${istfile} -t ${glossary_log} -o ${glossary_out} ${glossary_in}
  617. )
  618. endif()
  619. endforeach(newglossary)
  620. endfunction(latex_makeglossaries)
  621. function(latex_makenomenclature)
  622. message("**************************** In makenomenclature")
  623. if(NOT LATEX_TARGET)
  624. message(SEND_ERROR "Need to define LATEX_TARGET")
  625. endif()
  626. if(NOT MAKEINDEX_COMPILER)
  627. message(SEND_ERROR "Need to define MAKEINDEX_COMPILER")
  628. endif()
  629. set(nomencl_out ${LATEX_TARGET}.nls)
  630. set(nomencl_in ${LATEX_TARGET}.nlo)
  631. exec_program(${MAKEINDEX_COMPILER} ARGS ${MAKENOMENCLATURE_COMPILER_ARGS}
  632. ${nomencl_in} -s "nomencl.ist" -o ${nomencl_out}
  633. )
  634. endfunction(latex_makenomenclature)
  635. function(latex_correct_synctex)
  636. message("**************************** In correct SyncTeX")
  637. if(NOT LATEX_TARGET)
  638. message(SEND_ERROR "Need to define LATEX_TARGET")
  639. endif()
  640. if(NOT GZIP)
  641. message(SEND_ERROR "Need to define GZIP")
  642. endif()
  643. if(NOT LATEX_SOURCE_DIRECTORY)
  644. message(SEND_ERROR "Need to define LATEX_SOURCE_DIRECTORY")
  645. endif()
  646. if(NOT LATEX_BINARY_DIRECTORY)
  647. message(SEND_ERROR "Need to define LATEX_BINARY_DIRECTORY")
  648. endif()
  649. message("${LATEX_BINARY_DIRECTORY}")
  650. message("${LATEX_SOURCE_DIRECTORY}")
  651. set(synctex_file ${LATEX_BINARY_DIRECTORY}/${LATEX_TARGET}.synctex)
  652. set(synctex_file_gz ${synctex_file}.gz)
  653. if(EXISTS ${synctex_file_gz})
  654. message("Making backup of synctex file.")
  655. configure_file(${synctex_file_gz} ${synctex_file}.bak.gz COPYONLY)
  656. message("Uncompressing synctex file.")
  657. exec_program(${GZIP}
  658. ARGS --decompress ${synctex_file_gz}
  659. )
  660. message("Reading synctex file.")
  661. file(READ ${synctex_file} synctex_data)
  662. message("Replacing output paths with input paths.")
  663. foreach(extension tex cls bst clo sty ist fd)
  664. # Relative paths
  665. string(REGEX REPLACE
  666. "(Input:[0-9]+:)([^/\n][^\n]\\.${extension}*)"
  667. "\\1${LATEX_SOURCE_DIRECTORY}/\\2"
  668. synctex_data
  669. "${synctex_data}"
  670. )
  671. # Absolute paths
  672. string(REGEX REPLACE
  673. "(Input:[0-9]+:)${LATEX_BINARY_DIRECTORY}([^\n]*\\.${extension})"
  674. "\\1${LATEX_SOURCE_DIRECTORY}\\2"
  675. synctex_data
  676. "${synctex_data}"
  677. )
  678. endforeach(extension)
  679. message("Writing synctex file.")
  680. file(WRITE ${synctex_file} "${synctex_data}")
  681. message("Compressing synctex file.")
  682. exec_program(${GZIP}
  683. ARGS ${synctex_file}
  684. )
  685. else()
  686. message(SEND_ERROR "File ${synctex_file_gz} not found. Perhaps synctex is not supported by your LaTeX compiler.")
  687. endif()
  688. endfunction(latex_correct_synctex)
  689. function(latex_check_important_warnings)
  690. set(log_file ${LATEX_TARGET}.log)
  691. message("\nChecking ${log_file} for important warnings.")
  692. if(NOT LATEX_TARGET)
  693. message(SEND_ERROR "Need to define LATEX_TARGET")
  694. endif()
  695. if(NOT EXISTS ${log_file})
  696. message("Could not find log file: ${log_file}")
  697. return()
  698. endif()
  699. set(found_error)
  700. file(READ ${log_file} log)
  701. # Check for undefined references
  702. string(REGEX MATCHALL
  703. "\n[^\n]*Reference[^\n]*undefined[^\n]*"
  704. reference_warnings
  705. "${log}")
  706. if(reference_warnings)
  707. set(found_error TRUE)
  708. message("\nFound missing reference warnings.")
  709. foreach(warning ${reference_warnings})
  710. string(STRIP "${warning}" warning_no_newline)
  711. message("${warning_no_newline}")
  712. endforeach(warning)
  713. endif()
  714. # Check for natbib warnings
  715. string(REGEX MATCHALL
  716. "\nPackage natbib Warning:[^\n]*"
  717. natbib_warnings
  718. "${log}")
  719. if(natbib_warnings)
  720. set(found_error TRUE)
  721. message("\nFound natbib package warnings.")
  722. foreach(warning ${natbib_warnings})
  723. string(STRIP "${warning}" warning_no_newline)
  724. message("${warning_no_newline}")
  725. endforeach(warning)
  726. endif()
  727. # Check for overfull
  728. string(REGEX MATCHALL
  729. "\nOverfull[^\n]*"
  730. overfull_warnings
  731. "${log}")
  732. if(overfull_warnings)
  733. set(found_error TRUE)
  734. message("\nFound overfull warnings. These are indicative of layout errors.")
  735. foreach(warning ${overfull_warnings})
  736. string(STRIP "${warning}" warning_no_newline)
  737. message("${warning_no_newline}")
  738. endforeach(warning)
  739. endif()
  740. # Check for invalid characters
  741. string(REGEX MATCHALL
  742. "\nMissing character:[^\n]*"
  743. invalid_character_warnings
  744. "${log}")
  745. if(invalid_character_warnings)
  746. set(found_error TRUE)
  747. message("\nFound invalid character warnings. These characters are likely not printed correctly.")
  748. foreach(warning ${invalid_character_warnings})
  749. string(STRIP "${warning}" warning_no_newline)
  750. message("${warning_no_newline}")
  751. endforeach(warning)
  752. endif()
  753. if(found_error)
  754. latex_get_filename_component(log_file_path ${log_file} ABSOLUTE)
  755. message("\nConsult ${log_file_path} for more information on LaTeX build.")
  756. else()
  757. message("No known important warnings found.")
  758. endif(found_error)
  759. endfunction(latex_check_important_warnings)
  760. #############################################################################
  761. # Helper functions for establishing LaTeX build.
  762. #############################################################################
  763. function(latex_needit VAR NAME)
  764. if(NOT ${VAR})
  765. message(SEND_ERROR "I need the ${NAME} command.")
  766. endif()
  767. endfunction(latex_needit)
  768. function(latex_wantit VAR NAME)
  769. if(NOT ${VAR})
  770. message(STATUS "I could not find the ${NAME} command.")
  771. endif()
  772. endfunction(latex_wantit)
  773. function(latex_setup_variables)
  774. set(LATEX_OUTPUT_PATH "${LATEX_OUTPUT_PATH}"
  775. CACHE PATH "If non empty, specifies the location to place LaTeX output."
  776. )
  777. find_package(LATEX)
  778. find_program(XINDY_COMPILER
  779. NAME xindy
  780. PATHS ${MIKTEX_BINARY_PATH} /usr/bin
  781. )
  782. find_package(UnixCommands)
  783. find_program(PDFTOPS_CONVERTER
  784. NAMES pdftops
  785. DOC "The pdf to ps converter program from the Poppler package."
  786. )
  787. find_program(HTLATEX_COMPILER
  788. NAMES htlatex
  789. PATHS ${MIKTEX_BINARY_PATH}
  790. /usr/bin
  791. )
  792. mark_as_advanced(
  793. LATEX_COMPILER
  794. PDFLATEX_COMPILER
  795. BIBTEX_COMPILER
  796. BIBER_COMPILER
  797. MAKEINDEX_COMPILER
  798. XINDY_COMPILER
  799. DVIPS_CONVERTER
  800. PS2PDF_CONVERTER
  801. PDFTOPS_CONVERTER
  802. LATEX2HTML_CONVERTER
  803. HTLATEX_COMPILER
  804. )
  805. latex_needit(LATEX_COMPILER latex)
  806. latex_wantit(PDFLATEX_COMPILER pdflatex)
  807. latex_wantit(HTLATEX_COMPILER htlatex)
  808. latex_needit(BIBTEX_COMPILER bibtex)
  809. latex_wantit(BIBER_COMPILER biber)
  810. latex_needit(MAKEINDEX_COMPILER makeindex)
  811. latex_wantit(DVIPS_CONVERTER dvips)
  812. latex_wantit(PS2PDF_CONVERTER ps2pdf)
  813. latex_wantit(PDFTOPS_CONVERTER pdftops)
  814. set(LATEX_COMPILER_FLAGS "-interaction=batchmode -file-line-error"
  815. CACHE STRING "Flags passed to latex.")
  816. set(PDFLATEX_COMPILER_FLAGS ${LATEX_COMPILER_FLAGS}
  817. CACHE STRING "Flags passed to pdflatex.")
  818. set(HTLATEX_COMPILER_TEX4HT_FLAGS "html"
  819. CACHE STRING "Options for the tex4ht.sty and *.4ht style files.")
  820. set(HTLATEX_COMPILER_TEX4HT_POSTPROCESSOR_FLAGS ""
  821. CACHE STRING "Options for the text4ht postprocessor.")
  822. set(HTLATEX_COMPILER_T4HT_POSTPROCESSOR_FLAGS ""
  823. CACHE STRING "Options for the t4ht postprocessor.")
  824. set(HTLATEX_COMPILER_LATEX_FLAGS ${LATEX_COMPILER_FLAGS}
  825. CACHE STRING "Flags passed from htlatex to the LaTeX compiler.")
  826. set(LATEX_SYNCTEX_FLAGS "-synctex=1"
  827. CACHE STRING "latex/pdflatex flags used to create synctex file.")
  828. set(BIBTEX_COMPILER_FLAGS ""
  829. CACHE STRING "Flags passed to bibtex.")
  830. set(BIBER_COMPILER_FLAGS ""
  831. CACHE STRING "Flags passed to biber.")
  832. set(MAKEINDEX_COMPILER_FLAGS ""
  833. CACHE STRING "Flags passed to makeindex.")
  834. set(MAKEGLOSSARIES_COMPILER_FLAGS ""
  835. CACHE STRING "Flags passed to makeglossaries.")
  836. set(MAKENOMENCLATURE_COMPILER_FLAGS ""
  837. CACHE STRING "Flags passed to makenomenclature.")
  838. set(DVIPS_CONVERTER_FLAGS "-Ppdf -G0 -t letter"
  839. CACHE STRING "Flags passed to dvips.")
  840. if(NOT WIN32)
  841. set(PS2PDF_CONVERTER_FLAGS "-dMaxSubsetPct=100 -dCompatibilityLevel=1.3 -dSubsetFonts=true -dEmbedAllFonts=true -dAutoFilterColorImages=false -dAutoFilterGrayImages=false -dColorImageFilter=/FlateEncode -dGrayImageFilter=/FlateEncode -dMonoImageFilter=/FlateEncode"
  842. CACHE STRING "Flags passed to ps2pdf.")
  843. else()
  844. # Most windows ports of ghostscript utilities use .bat files for ps2pdf
  845. # commands. bat scripts interpret "=" as a special character and separate
  846. # those arguments. To get around this, the ghostscript utilities also
  847. # support using "#" in place of "=".
  848. set(PS2PDF_CONVERTER_FLAGS "-dMaxSubsetPct#100 -dCompatibilityLevel#1.3 -dSubsetFonts#true -dEmbedAllFonts#true -dAutoFilterColorImages#false -dAutoFilterGrayImages#false -dColorImageFilter#/FlateEncode -dGrayImageFilter#/FlateEncode -dMonoImageFilter#/FlateEncode"
  849. CACHE STRING "Flags passed to ps2pdf.")
  850. endif()
  851. set(PDFTOPS_CONVERTER_FLAGS ""
  852. CACHE STRING "Flags passed to pdftops.")
  853. mark_as_advanced(
  854. LATEX_COMPILER_FLAGS
  855. PDFLATEX_COMPILER_FLAGS
  856. HTLATEX_COMPILER_TEX4HT_FLAGS
  857. HTLATEX_COMPILER_TEX4HT_POSTPROCESSOR_FLAGS
  858. HTLATEX_COMPILER_T4HT_POSTPROCESSOR_FLAGS
  859. HTLATEX_COMPILER_LATEX_FLAGS
  860. LATEX_SYNCTEX_FLAGS
  861. BIBTEX_COMPILER_FLAGS
  862. BIBER_COMPILER_FLAGS
  863. MAKEINDEX_COMPILER_FLAGS
  864. MAKEGLOSSARIES_COMPILER_FLAGS
  865. MAKENOMENCLATURE_COMPILER_FLAGS
  866. DVIPS_CONVERTER_FLAGS
  867. PS2PDF_CONVERTER_FLAGS
  868. PDFTOPS_CONVERTER_FLAGS
  869. )
  870. # Because it is easier to type, the flags variables are entered as
  871. # space-separated strings much like you would in a shell. However, when
  872. # using a CMake command to execute a program, it works better to hold the
  873. # arguments in semicolon-separated lists (otherwise the whole string will
  874. # be interpreted as a single argument). Use the separate_arguments to
  875. # convert the space-separated strings to semicolon-separated lists.
  876. separate_arguments(LATEX_COMPILER_FLAGS)
  877. separate_arguments(PDFLATEX_COMPILER_FLAGS)
  878. separate_arguments(HTLATEX_COMPILER_LATEX_FLAGS)
  879. separate_arguments(LATEX_SYNCTEX_FLAGS)
  880. separate_arguments(BIBTEX_COMPILER_FLAGS)
  881. separate_arguments(BIBER_COMPILER_FLAGS)
  882. separate_arguments(MAKEINDEX_COMPILER_FLAGS)
  883. separate_arguments(MAKEGLOSSARIES_COMPILER_FLAGS)
  884. separate_arguments(MAKENOMENCLATURE_COMPILER_FLAGS)
  885. separate_arguments(DVIPS_CONVERTER_FLAGS)
  886. separate_arguments(PS2PDF_CONVERTER_FLAGS)
  887. separate_arguments(PDFTOPS_CONVERTER_FLAGS)
  888. # Not quite done. When you call separate_arguments on a cache variable,
  889. # the result is written to a local variable. That local variable goes
  890. # away when this function returns (which is before any of them are used).
  891. # So, copy these variables with local scope to cache variables with
  892. # global scope.
  893. set(LATEX_COMPILER_ARGS "${LATEX_COMPILER_FLAGS}" CACHE INTERNAL "")
  894. set(PDFLATEX_COMPILER_ARGS "${PDFLATEX_COMPILER_FLAGS}" CACHE INTERNAL "")
  895. set(HTLATEX_COMPILER_ARGS "${HTLATEX_COMPILER_LATEX_FLAGS}" CACHE INTERNAL "")
  896. set(LATEX_SYNCTEX_ARGS "${LATEX_SYNCTEX_FLAGS}" CACHE INTERNAL "")
  897. set(BIBTEX_COMPILER_ARGS "${BIBTEX_COMPILER_FLAGS}" CACHE INTERNAL "")
  898. set(BIBER_COMPILER_ARGS "${BIBER_COMPILER_FLAGS}" CACHE INTERNAL "")
  899. set(MAKEINDEX_COMPILER_ARGS "${MAKEINDEX_COMPILER_FLAGS}" CACHE INTERNAL "")
  900. set(MAKEGLOSSARIES_COMPILER_ARGS "${MAKEGLOSSARIES_COMPILER_FLAGS}" CACHE INTERNAL "")
  901. set(MAKENOMENCLATURE_COMPILER_ARGS "${MAKENOMENCLATURE_COMPILER_FLAGS}" CACHE INTERNAL "")
  902. set(DVIPS_CONVERTER_ARGS "${DVIPS_CONVERTER_FLAGS}" CACHE INTERNAL "")
  903. set(PS2PDF_CONVERTER_ARGS "${PS2PDF_CONVERTER_FLAGS}" CACHE INTERNAL "")
  904. set(PDFTOPS_CONVERTER_ARGS "${PDFTOPS_CONVERTER_FLAGS}" CACHE INTERNAL "")
  905. find_program(IMAGEMAGICK_CONVERT
  906. NAMES magick convert
  907. DOC "The convert program that comes with ImageMagick (available at http://www.imagemagick.org)."
  908. )
  909. mark_as_advanced(IMAGEMAGICK_CONVERT)
  910. if(DEFINED ENV{LATEX_DEFAULT_BUILD})
  911. set(default_build $ENV{LATEX_DEFAULT_BUILD})
  912. else()
  913. set(default_build pdf)
  914. endif()
  915. set(LATEX_DEFAULT_BUILD "${default_build}" CACHE STRING
  916. "Choose the default type of LaTeX build. Valid options are pdf, dvi, ps, safepdf, html"
  917. )
  918. set_property(CACHE LATEX_DEFAULT_BUILD
  919. PROPERTY STRINGS pdf dvi ps safepdf html
  920. )
  921. option(LATEX_USE_SYNCTEX
  922. "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."
  923. OFF
  924. )
  925. option(LATEX_SMALL_IMAGES
  926. "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."
  927. OFF)
  928. if(LATEX_SMALL_IMAGES)
  929. set(LATEX_RASTER_SCALE 16 PARENT_SCOPE)
  930. set(LATEX_OPPOSITE_RASTER_SCALE 100 PARENT_SCOPE)
  931. else()
  932. set(LATEX_RASTER_SCALE 100 PARENT_SCOPE)
  933. set(LATEX_OPPOSITE_RASTER_SCALE 16 PARENT_SCOPE)
  934. endif()
  935. # Just holds extensions for known image types. They should all be lower case.
  936. # For historical reasons, these are all declared in the global scope.
  937. set(LATEX_DVI_VECTOR_IMAGE_EXTENSIONS .eps CACHE INTERNAL "")
  938. set(LATEX_DVI_RASTER_IMAGE_EXTENSIONS CACHE INTERNAL "")
  939. set(LATEX_DVI_IMAGE_EXTENSIONS
  940. ${LATEX_DVI_VECTOR_IMAGE_EXTENSIONS}
  941. ${LATEX_DVI_RASTER_IMAGE_EXTENSIONS}
  942. CACHE INTERNAL ""
  943. )
  944. set(LATEX_PDF_VECTOR_IMAGE_EXTENSIONS .pdf CACHE INTERNAL "")
  945. set(LATEX_PDF_RASTER_IMAGE_EXTENSIONS .jpeg .jpg .png CACHE INTERNAL "")
  946. set(LATEX_PDF_IMAGE_EXTENSIONS
  947. ${LATEX_PDF_VECTOR_IMAGE_EXTENSIONS}
  948. ${LATEX_PDF_RASTER_IMAGE_EXTENSIONS}
  949. CACHE INTERNAL ""
  950. )
  951. set(LATEX_OTHER_VECTOR_IMAGE_EXTENSIONS .ai .dot .svg CACHE INTERNAL "")
  952. set(LATEX_OTHER_RASTER_IMAGE_EXTENSIONS
  953. .bmp .bmp2 .bmp3 .dcm .dcx .ico .gif .pict .ppm .tif .tiff
  954. CACHE INTERNAL "")
  955. set(LATEX_OTHER_IMAGE_EXTENSIONS
  956. ${LATEX_OTHER_VECTOR_IMAGE_EXTENSIONS}
  957. ${LATEX_OTHER_RASTER_IMAGE_EXTENSIONS}
  958. CACHE INTERNAL ""
  959. )
  960. set(LATEX_VECTOR_IMAGE_EXTENSIONS
  961. ${LATEX_DVI_VECTOR_IMAGE_EXTENSIONS}
  962. ${LATEX_PDF_VECTOR_IMAGE_EXTENSIONS}
  963. ${LATEX_OTHER_VECTOR_IMAGE_EXTENSIONS}
  964. CACHE INTERNAL ""
  965. )
  966. set(LATEX_RASTER_IMAGE_EXTENSIONS
  967. ${LATEX_DVI_RASTER_IMAGE_EXTENSIONS}
  968. ${LATEX_PDF_RASTER_IMAGE_EXTENSIONS}
  969. ${LATEX_OTHER_RASTER_IMAGE_EXTENSIONS}
  970. CACHE INTERNAL ""
  971. )
  972. set(LATEX_IMAGE_EXTENSIONS
  973. ${LATEX_DVI_IMAGE_EXTENSIONS}
  974. ${LATEX_PDF_IMAGE_EXTENSIONS}
  975. ${LATEX_OTHER_IMAGE_EXTENSIONS}
  976. CACHE INTERNAL ""
  977. )
  978. endfunction(latex_setup_variables)
  979. function(latex_setup_targets)
  980. if(NOT TARGET pdf)
  981. add_custom_target(pdf)
  982. endif()
  983. if(NOT TARGET dvi)
  984. add_custom_target(dvi)
  985. endif()
  986. if(NOT TARGET ps)
  987. add_custom_target(ps)
  988. endif()
  989. if(NOT TARGET safepdf)
  990. add_custom_target(safepdf)
  991. endif()
  992. if(NOT TARGET html)
  993. add_custom_target(html)
  994. endif()
  995. if(NOT TARGET auxclean)
  996. add_custom_target(auxclean)
  997. endif()
  998. endfunction(latex_setup_targets)
  999. function(latex_get_output_path var)
  1000. set(latex_output_path)
  1001. if(LATEX_OUTPUT_PATH)
  1002. get_filename_component(
  1003. LATEX_OUTPUT_PATH_FULL "${LATEX_OUTPUT_PATH}" ABSOLUTE
  1004. )
  1005. if("${LATEX_OUTPUT_PATH_FULL}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
  1006. message(SEND_ERROR "You cannot set LATEX_OUTPUT_PATH to the same directory that contains LaTeX input files.")
  1007. else()
  1008. set(latex_output_path "${LATEX_OUTPUT_PATH_FULL}")
  1009. endif()
  1010. else()
  1011. if("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
  1012. message(SEND_ERROR "LaTeX files must be built out of source or you must set LATEX_OUTPUT_PATH.")
  1013. else()
  1014. set(latex_output_path "${CMAKE_CURRENT_BINARY_DIR}")
  1015. endif()
  1016. endif()
  1017. set(${var} ${latex_output_path} PARENT_SCOPE)
  1018. endfunction(latex_get_output_path)
  1019. function(latex_add_convert_command
  1020. output_path
  1021. input_path
  1022. output_extension
  1023. input_extension
  1024. flags
  1025. )
  1026. set(require_imagemagick_convert TRUE)
  1027. set(convert_flags "")
  1028. if(${input_extension} STREQUAL ".eps" AND ${output_extension} STREQUAL ".pdf")
  1029. # ImageMagick has broken eps to pdf conversion
  1030. # use ps2pdf instead
  1031. if(PS2PDF_CONVERTER)
  1032. set(require_imagemagick_convert FALSE)
  1033. set(converter ${PS2PDF_CONVERTER})
  1034. set(convert_flags -dEPSCrop ${PS2PDF_CONVERTER_ARGS})
  1035. else()
  1036. message(SEND_ERROR "Using postscript files with pdflatex requires ps2pdf for conversion.")
  1037. endif()
  1038. elseif(${input_extension} STREQUAL ".pdf" AND ${output_extension} STREQUAL ".eps")
  1039. # ImageMagick can also be sketchy on pdf to eps conversion. Not good with
  1040. # color spaces and tends to unnecessarily rasterize.
  1041. # use pdftops instead
  1042. if(PDFTOPS_CONVERTER)
  1043. set(require_imagemagick_convert FALSE)
  1044. set(converter ${PDFTOPS_CONVERTER})
  1045. set(convert_flags -eps ${PDFTOPS_CONVERTER_ARGS})
  1046. else()
  1047. message(STATUS "Consider getting pdftops from Poppler to convert PDF images to EPS images.")
  1048. set(convert_flags ${flags})
  1049. endif()
  1050. else()
  1051. set(convert_flags ${flags})
  1052. endif()
  1053. if(require_imagemagick_convert)
  1054. if(IMAGEMAGICK_CONVERT)
  1055. string(TOLOWER ${IMAGEMAGICK_CONVERT} IMAGEMAGICK_CONVERT_LOWERCASE)
  1056. if(${IMAGEMAGICK_CONVERT_LOWERCASE} MATCHES "system32[/\\\\]convert\\.exe")
  1057. 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.")
  1058. else()
  1059. set(converter ${IMAGEMAGICK_CONVERT})
  1060. # ImageMagick requires a special order of arguments where resize and
  1061. # arguments of that nature must be placed after the input image path.
  1062. add_custom_command(OUTPUT ${output_path}
  1063. COMMAND ${converter}
  1064. ARGS ${input_path} ${convert_flags} ${output_path}
  1065. DEPENDS ${input_path}
  1066. )
  1067. endif()
  1068. else()
  1069. message(SEND_ERROR "Could not find convert program. Please download ImageMagick from http://www.imagemagick.org and install.")
  1070. endif()
  1071. else() # Not ImageMagick convert
  1072. add_custom_command(OUTPUT ${output_path}
  1073. COMMAND ${converter}
  1074. ARGS ${convert_flags} ${input_path} ${output_path}
  1075. DEPENDS ${input_path}
  1076. )
  1077. endif()
  1078. endfunction(latex_add_convert_command)
  1079. # Makes custom commands to convert a file to a particular type.
  1080. function(latex_convert_image
  1081. output_files_var
  1082. input_file
  1083. output_extension
  1084. convert_flags
  1085. output_extensions
  1086. other_files
  1087. )
  1088. set(output_file_list)
  1089. set(input_dir ${CMAKE_CURRENT_SOURCE_DIR})
  1090. latex_get_output_path(output_dir)
  1091. latex_get_filename_component(extension "${input_file}" EXT)
  1092. # Check input filename for potential problems with LaTeX.
  1093. latex_get_filename_component(name "${input_file}" NAME_WE)
  1094. set(suggested_name "${name}")
  1095. if(suggested_name MATCHES ".*\\..*")
  1096. string(REPLACE "." "-" suggested_name "${suggested_name}")
  1097. endif()
  1098. if(suggested_name MATCHES ".* .*")
  1099. string(REPLACE " " "-" suggested_name "${suggested_name}")
  1100. endif()
  1101. if(NOT suggested_name STREQUAL name)
  1102. 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}.")
  1103. endif()
  1104. string(REGEX REPLACE "\\.[^.]*\$" ${output_extension} output_file
  1105. "${input_file}")
  1106. latex_list_contains(is_type ${extension} ${output_extensions})
  1107. if(is_type)
  1108. if(convert_flags)
  1109. latex_add_convert_command(${output_dir}/${output_file}
  1110. ${input_dir}/${input_file} ${output_extension} ${extension}
  1111. "${convert_flags}")
  1112. set(output_file_list ${output_dir}/${output_file})
  1113. else()
  1114. # As a shortcut, we can just copy the file.
  1115. add_custom_command(OUTPUT ${output_dir}/${input_file}
  1116. COMMAND ${CMAKE_COMMAND}
  1117. ARGS -E copy ${input_dir}/${input_file} ${output_dir}/${input_file}
  1118. DEPENDS ${input_dir}/${input_file}
  1119. )
  1120. set(output_file_list ${output_dir}/${input_file})
  1121. endif()
  1122. else()
  1123. set(do_convert TRUE)
  1124. # Check to see if there is another input file of the appropriate type.
  1125. foreach(valid_extension ${output_extensions})
  1126. string(REGEX REPLACE "\\.[^.]*\$" ${output_extension} try_file
  1127. "${input_file}")
  1128. latex_list_contains(has_native_file "${try_file}" ${other_files})
  1129. if(has_native_file)
  1130. set(do_convert FALSE)
  1131. endif()
  1132. endforeach(valid_extension)
  1133. # If we still need to convert, do it.
  1134. if(do_convert)
  1135. latex_add_convert_command(${output_dir}/${output_file}
  1136. ${input_dir}/${input_file} ${output_extension} ${extension}
  1137. "${convert_flags}")
  1138. set(output_file_list ${output_dir}/${output_file})
  1139. endif()
  1140. endif()
  1141. set(${output_files_var} ${output_file_list} PARENT_SCOPE)
  1142. endfunction(latex_convert_image)
  1143. # Adds custom commands to process the given files for dvi and pdf builds.
  1144. # Adds the output files to the given variables (does not replace).
  1145. function(latex_process_images dvi_outputs_var pdf_outputs_var)
  1146. latex_get_output_path(output_dir)
  1147. set(dvi_outputs)
  1148. set(pdf_outputs)
  1149. foreach(file ${ARGN})
  1150. if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
  1151. latex_get_filename_component(extension "${file}" EXT)
  1152. set(convert_flags)
  1153. # Check to see if we need to downsample the image.
  1154. latex_list_contains(is_raster "${extension}"
  1155. ${LATEX_RASTER_IMAGE_EXTENSIONS})
  1156. if(LATEX_SMALL_IMAGES)
  1157. if(is_raster)
  1158. set(convert_flags -resize ${LATEX_RASTER_SCALE}%)
  1159. endif()
  1160. endif()
  1161. # Make sure the output directory exists.
  1162. latex_get_filename_component(path "${output_dir}/${file}" PATH)
  1163. make_directory("${path}")
  1164. # Do conversions for dvi.
  1165. latex_convert_image(output_files "${file}" .eps "${convert_flags}"
  1166. "${LATEX_DVI_IMAGE_EXTENSIONS}" "${ARGN}")
  1167. list(APPEND dvi_outputs ${output_files})
  1168. # Do conversions for pdf.
  1169. if(is_raster)
  1170. latex_convert_image(output_files "${file}" .png "${convert_flags}"
  1171. "${LATEX_PDF_IMAGE_EXTENSIONS}" "${ARGN}")
  1172. list(APPEND pdf_outputs ${output_files})
  1173. else()
  1174. latex_convert_image(output_files "${file}" .pdf "${convert_flags}"
  1175. "${LATEX_PDF_IMAGE_EXTENSIONS}" "${ARGN}")
  1176. list(APPEND pdf_outputs ${output_files})
  1177. endif()
  1178. else()
  1179. message(WARNING "Could not find file ${CMAKE_CURRENT_SOURCE_DIR}/${file}. Are you sure you gave relative paths to IMAGES?")
  1180. endif()
  1181. endforeach(file)
  1182. set(${dvi_outputs_var} ${dvi_outputs} PARENT_SCOPE)
  1183. set(${pdf_outputs_var} ${pdf_outputs} PARENT_SCOPE)
  1184. endfunction(latex_process_images)
  1185. function(latex_copy_globbed_files pattern dest)
  1186. file(GLOB file_list ${pattern})
  1187. foreach(in_file ${file_list})
  1188. latex_get_filename_component(out_file ${in_file} NAME)
  1189. configure_file(${in_file} ${dest}/${out_file} COPYONLY)
  1190. endforeach(in_file)
  1191. endfunction(latex_copy_globbed_files)
  1192. function(latex_copy_input_file file)
  1193. latex_get_output_path(output_dir)
  1194. if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file})
  1195. latex_get_filename_component(path ${file} PATH)
  1196. file(MAKE_DIRECTORY ${output_dir}/${path})
  1197. latex_list_contains(use_config ${file} ${LATEX_CONFIGURE})
  1198. if(use_config)
  1199. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${file}
  1200. ${output_dir}/${file}
  1201. @ONLY
  1202. )
  1203. add_custom_command(OUTPUT ${output_dir}/${file}
  1204. COMMAND ${CMAKE_COMMAND}
  1205. ARGS ${CMAKE_BINARY_DIR}
  1206. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file}
  1207. )
  1208. else()
  1209. add_custom_command(OUTPUT ${output_dir}/${file}
  1210. COMMAND ${CMAKE_COMMAND}
  1211. ARGS -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${file} ${output_dir}/${file}
  1212. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file}
  1213. )
  1214. endif()
  1215. else()
  1216. if(EXISTS ${output_dir}/${file})
  1217. # Special case: output exists but input does not. Assume that it was
  1218. # created elsewhere and skip the input file copy.
  1219. else()
  1220. message("Could not find input file ${CMAKE_CURRENT_SOURCE_DIR}/${file}")
  1221. endif()
  1222. endif()
  1223. endfunction(latex_copy_input_file)
  1224. #############################################################################
  1225. # Commands provided by the UseLATEX.cmake "package"
  1226. #############################################################################
  1227. function(latex_usage command message)
  1228. message(SEND_ERROR
  1229. "${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])"
  1230. )
  1231. endfunction(latex_usage command message)
  1232. # Parses arguments to add_latex_document and ADD_LATEX_TARGETS and sets the
  1233. # variables LATEX_TARGET, LATEX_IMAGE_DIR, LATEX_BIBFILES, LATEX_DEPENDS, and
  1234. # LATEX_INPUTS.
  1235. function(parse_add_latex_arguments command latex_main_input)
  1236. set(options
  1237. USE_BIBLATEX
  1238. USE_INDEX
  1239. USE_GLOSSARY
  1240. USE_NOMENCL
  1241. FORCE_PDF
  1242. FORCE_DVI
  1243. FORCE_HTML
  1244. EXCLUDE_FROM_ALL
  1245. EXCLUDE_FROM_DEFAULTS
  1246. # Deprecated options
  1247. USE_GLOSSARIES
  1248. DEFAULT_PDF
  1249. DEFAULT_SAFEPDF
  1250. DEFAULT_PS
  1251. NO_DEFAULT
  1252. MANGLE_TARGET_NAMES
  1253. )
  1254. set(oneValueArgs
  1255. TARGET_NAME
  1256. )
  1257. set(multiValueArgs
  1258. BIBFILES
  1259. MULTIBIB_NEWCITES
  1260. INPUTS
  1261. IMAGE_DIRS
  1262. IMAGES
  1263. CONFIGURE
  1264. DEPENDS
  1265. INDEX_NAMES
  1266. )
  1267. cmake_parse_arguments(
  1268. LATEX "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  1269. # Handle invalid and deprecated arguments
  1270. if(LATEX_UNPARSED_ARGUMENTS)
  1271. latex_usage(${command} "Invalid or deprecated arguments: ${LATEX_UNPARSED_ARGUMENTS}")
  1272. endif()
  1273. if(LATEX_USE_GLOSSARIES)
  1274. latex_usage(${command} "USE_GLOSSARIES option removed in version 1.6.1. Use USE_GLOSSARY instead.")
  1275. endif()
  1276. if(LATEX_DEFAULT_PDF)
  1277. latex_usage(${command} "DEFAULT_PDF option removed in version 2.0. Use FORCE_PDF option or LATEX_DEFAULT_BUILD CMake variable instead.")
  1278. endif()
  1279. if(LATEX_DEFAULT_SAFEPDF)
  1280. latex_usage(${command} "DEFAULT_SAFEPDF option removed in version 2.0. Use LATEX_DEFAULT_BUILD CMake variable instead.")
  1281. endif()
  1282. if(LATEX_DEFAULT_DVI)
  1283. latex_usage(${command} "DEFAULT_DVI option removed in version 2.0. Use FORCE_DVI option or LATEX_DEFAULT_BUILD CMake variable instead.")
  1284. endif()
  1285. if(LATEX_NO_DEFAULT)
  1286. latex_usage(${command} "NO_DEFAULT option removed in version 2.0. Use EXCLUDE_FROM_ALL instead.")
  1287. endif()
  1288. if(LATEX_MANGLE_TARGET_NAMES)
  1289. latex_usage(${command} "MANGLE_TARGET_NAMES option removed in version 2.0. All LaTeX targets use mangled names now.")
  1290. endif()
  1291. # Capture the first argument, which is the main LaTeX input.
  1292. latex_get_filename_component(latex_target ${latex_main_input} NAME_WE)
  1293. set(LATEX_MAIN_INPUT ${latex_main_input} PARENT_SCOPE)
  1294. set(LATEX_TARGET ${latex_target} PARENT_SCOPE)
  1295. # Propagate the result variables to the caller
  1296. foreach(arg_name ${options} ${oneValueArgs} ${multiValueArgs})
  1297. set(var_name LATEX_${arg_name})
  1298. set(${var_name} ${${var_name}} PARENT_SCOPE)
  1299. endforeach(arg_name)
  1300. endfunction(parse_add_latex_arguments)
  1301. function(add_latex_targets_internal)
  1302. latex_get_output_path(output_dir)
  1303. if(LATEX_USE_SYNCTEX)
  1304. set(synctex_flags ${LATEX_SYNCTEX_ARGS})
  1305. else()
  1306. set(synctex_flags)
  1307. endif()
  1308. # The commands to run LaTeX. They are repeated multiple times.
  1309. set(latex_build_command
  1310. ${LATEX_COMPILER} ${LATEX_COMPILER_ARGS} ${synctex_flags} ${LATEX_MAIN_INPUT}
  1311. )
  1312. if(LATEX_COMPILER_ARGS MATCHES ".*batchmode.*")
  1313. # Wrap command in script that dumps the log file on error. This makes sure
  1314. # errors can be seen.
  1315. set(latex_build_command
  1316. ${CMAKE_COMMAND}
  1317. -D LATEX_BUILD_COMMAND=execute_latex
  1318. -D LATEX_TARGET=${LATEX_TARGET}
  1319. -D LATEX_WORKING_DIRECTORY="${output_dir}"
  1320. -D LATEX_FULL_COMMAND="${latex_build_command}"
  1321. -D LATEX_OUTPUT_FILE="${LATEX_TARGET}.dvi"
  1322. -P "${LATEX_USE_LATEX_LOCATION}"
  1323. )
  1324. endif()
  1325. set(pdflatex_build_command
  1326. ${PDFLATEX_COMPILER} ${PDFLATEX_COMPILER_ARGS} ${synctex_flags} ${LATEX_MAIN_INPUT}
  1327. )
  1328. if(PDFLATEX_COMPILER_ARGS MATCHES ".*batchmode.*")
  1329. # Wrap command in script that dumps the log file on error. This makes sure
  1330. # errors can be seen.
  1331. set(pdflatex_build_command
  1332. ${CMAKE_COMMAND}
  1333. -D LATEX_BUILD_COMMAND=execute_latex
  1334. -D LATEX_TARGET=${LATEX_TARGET}
  1335. -D LATEX_WORKING_DIRECTORY="${output_dir}"
  1336. -D LATEX_FULL_COMMAND="${pdflatex_build_command}"
  1337. -D LATEX_OUTPUT_FILE="${LATEX_TARGET}.pdf"
  1338. -P "${LATEX_USE_LATEX_LOCATION}"
  1339. )
  1340. endif()
  1341. if(NOT LATEX_TARGET_NAME)
  1342. # Use the main filename (minus the .tex) as the target name. Remove any
  1343. # spaces since CMake cannot have spaces in its target names.
  1344. string(REPLACE " " "_" LATEX_TARGET_NAME ${LATEX_TARGET})
  1345. endif()
  1346. # Some LaTeX commands may need to be modified (or may not work) if the main
  1347. # tex file is in a subdirectory. Make a flag for that.
  1348. get_filename_component(LATEX_MAIN_INPUT_SUBDIR ${LATEX_MAIN_INPUT} DIRECTORY)
  1349. # Set up target names.
  1350. set(dvi_target ${LATEX_TARGET_NAME}_dvi)
  1351. set(pdf_target ${LATEX_TARGET_NAME}_pdf)
  1352. set(ps_target ${LATEX_TARGET_NAME}_ps)
  1353. set(safepdf_target ${LATEX_TARGET_NAME}_safepdf)
  1354. set(html_target ${LATEX_TARGET_NAME}_html)
  1355. set(auxclean_target ${LATEX_TARGET_NAME}_auxclean)
  1356. # Probably not all of these will be generated, but they could be.
  1357. # Note that the aux file is added later.
  1358. set(auxiliary_clean_files
  1359. ${output_dir}/${LATEX_TARGET}.aux
  1360. ${output_dir}/${LATEX_TARGET}.bbl
  1361. ${output_dir}/${LATEX_TARGET}.blg
  1362. ${output_dir}/${LATEX_TARGET}-blx.bib
  1363. ${output_dir}/${LATEX_TARGET}.glg
  1364. ${output_dir}/${LATEX_TARGET}.glo
  1365. ${output_dir}/${LATEX_TARGET}.gls
  1366. ${output_dir}/${LATEX_TARGET}.idx
  1367. ${output_dir}/${LATEX_TARGET}.ilg
  1368. ${output_dir}/${LATEX_TARGET}.ind
  1369. ${output_dir}/${LATEX_TARGET}.ist
  1370. ${output_dir}/${LATEX_TARGET}.log
  1371. ${output_dir}/${LATEX_TARGET}.out
  1372. ${output_dir}/${LATEX_TARGET}.toc
  1373. ${output_dir}/${LATEX_TARGET}.lof
  1374. ${output_dir}/${LATEX_TARGET}.xdy
  1375. ${output_dir}/${LATEX_TARGET}.synctex.gz
  1376. ${output_dir}/${LATEX_TARGET}.synctex.bak.gz
  1377. ${output_dir}/${LATEX_TARGET}.dvi
  1378. ${output_dir}/${LATEX_TARGET}.ps
  1379. ${output_dir}/${LATEX_TARGET}.pdf
  1380. )
  1381. set(image_list ${LATEX_IMAGES})
  1382. # For each directory in LATEX_IMAGE_DIRS, glob all the image files and
  1383. # place them in LATEX_IMAGES.
  1384. foreach(dir ${LATEX_IMAGE_DIRS})
  1385. if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir})
  1386. message(WARNING "Image directory ${CMAKE_CURRENT_SOURCE_DIR}/${dir} does not exist. Are you sure you gave relative directories to IMAGE_DIRS?")
  1387. endif()
  1388. foreach(extension ${LATEX_IMAGE_EXTENSIONS})
  1389. file(GLOB files ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*${extension})
  1390. foreach(file ${files})
  1391. latex_get_filename_component(filename ${file} NAME)
  1392. list(APPEND image_list ${dir}/${filename})
  1393. endforeach(file)
  1394. endforeach(extension)
  1395. endforeach(dir)
  1396. latex_process_images(dvi_images pdf_images ${image_list})
  1397. set(make_dvi_command
  1398. ${CMAKE_COMMAND} -E chdir ${output_dir}
  1399. ${latex_build_command})
  1400. set(make_pdf_command
  1401. ${CMAKE_COMMAND} -E chdir ${output_dir}
  1402. ${pdflatex_build_command}
  1403. )
  1404. set(make_dvi_depends ${LATEX_DEPENDS} ${dvi_images})
  1405. set(make_pdf_depends ${LATEX_DEPENDS} ${pdf_images})
  1406. foreach(input ${LATEX_MAIN_INPUT} ${LATEX_INPUTS})
  1407. list(APPEND make_dvi_depends ${output_dir}/${input})
  1408. list(APPEND make_pdf_depends ${output_dir}/${input})
  1409. if(${input} MATCHES "\\.tex$")
  1410. # Dependent .tex files might have their own .aux files created. Make
  1411. # sure these get cleaned as well. This might replicate the cleaning
  1412. # of the main .aux file, which is OK.
  1413. string(REGEX REPLACE "\\.tex$" "" input_we ${input})
  1414. list(APPEND auxiliary_clean_files
  1415. ${output_dir}/${input_we}.aux
  1416. ${output_dir}/${input}.aux
  1417. )
  1418. endif()
  1419. endforeach(input)
  1420. set(all_latex_sources ${LATEX_MAIN_INPUT} ${LATEX_INPUTS} ${image_list})
  1421. if(LATEX_USE_GLOSSARY)
  1422. foreach(dummy 0 1) # Repeat these commands twice.
  1423. set(make_dvi_command ${make_dvi_command}
  1424. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1425. ${CMAKE_COMMAND}
  1426. -D LATEX_BUILD_COMMAND=makeglossaries
  1427. -D LATEX_TARGET=${LATEX_TARGET}
  1428. -D MAKEINDEX_COMPILER=${MAKEINDEX_COMPILER}
  1429. -D XINDY_COMPILER=${XINDY_COMPILER}
  1430. -D MAKEGLOSSARIES_COMPILER_ARGS=${MAKEGLOSSARIES_COMPILER_ARGS}
  1431. -P ${LATEX_USE_LATEX_LOCATION}
  1432. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1433. ${latex_build_command}
  1434. )
  1435. set(make_pdf_command ${make_pdf_command}
  1436. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1437. ${CMAKE_COMMAND}
  1438. -D LATEX_BUILD_COMMAND=makeglossaries
  1439. -D LATEX_TARGET=${LATEX_TARGET}
  1440. -D MAKEINDEX_COMPILER=${MAKEINDEX_COMPILER}
  1441. -D XINDY_COMPILER=${XINDY_COMPILER}
  1442. -D MAKEGLOSSARIES_COMPILER_ARGS=${MAKEGLOSSARIES_COMPILER_ARGS}
  1443. -P ${LATEX_USE_LATEX_LOCATION}
  1444. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1445. ${pdflatex_build_command}
  1446. )
  1447. endforeach(dummy)
  1448. endif()
  1449. if(LATEX_USE_NOMENCL)
  1450. foreach(dummy 0 1) # Repeat these commands twice.
  1451. set(make_dvi_command ${make_dvi_command}
  1452. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1453. ${CMAKE_COMMAND}
  1454. -D LATEX_BUILD_COMMAND=makenomenclature
  1455. -D LATEX_TARGET=${LATEX_TARGET}
  1456. -D MAKEINDEX_COMPILER=${MAKEINDEX_COMPILER}
  1457. -D MAKENOMENCLATURE_COMPILER_ARGS=${MAKENOMENCLATURE_COMPILER_ARGS}
  1458. -P ${LATEX_USE_LATEX_LOCATION}
  1459. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1460. ${latex_build_command}
  1461. )
  1462. set(make_pdf_command ${make_pdf_command}
  1463. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1464. ${CMAKE_COMMAND}
  1465. -D LATEX_BUILD_COMMAND=makenomenclature
  1466. -D LATEX_TARGET=${LATEX_TARGET}
  1467. -D MAKEINDEX_COMPILER=${MAKEINDEX_COMPILER}
  1468. -D MAKENOMENCLATURE_COMPILER_ARGS=${MAKENOMENCLATURE_COMPILER_ARGS}
  1469. -P ${LATEX_USE_LATEX_LOCATION}
  1470. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1471. ${pdflatex_build_command}
  1472. )
  1473. endforeach(dummy)
  1474. endif()
  1475. if(LATEX_BIBFILES)
  1476. if(LATEX_USE_BIBLATEX)
  1477. if(NOT BIBER_COMPILER)
  1478. message(SEND_ERROR "I need the biber command.")
  1479. endif()
  1480. set(bib_compiler ${BIBER_COMPILER})
  1481. set(bib_compiler_flags ${BIBER_COMPILER_ARGS})
  1482. if (LATEX_USE_BIBLATEX_CONFIG)
  1483. list(APPEND auxiliary_clean_files ${output_dir}/biblatex.cfg)
  1484. list(APPEND make_dvi_depends ${output_dir}/biblatex.cfg)
  1485. list(APPEND make_pdf_depends ${output_dir}/biblatex.cfg)
  1486. endif()
  1487. else()
  1488. set(bib_compiler ${BIBTEX_COMPILER})
  1489. set(bib_compiler_flags ${BIBTEX_COMPILER_ARGS})
  1490. endif()
  1491. if(LATEX_MULTIBIB_NEWCITES)
  1492. foreach (multibib_auxfile ${LATEX_MULTIBIB_NEWCITES})
  1493. latex_get_filename_component(multibib_target ${multibib_auxfile} NAME_WE)
  1494. set(make_dvi_command ${make_dvi_command}
  1495. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1496. ${bib_compiler} ${bib_compiler_flags} ${multibib_target})
  1497. set(make_pdf_command ${make_pdf_command}
  1498. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1499. ${bib_compiler} ${bib_compiler_flags} ${multibib_target})
  1500. set(auxiliary_clean_files ${auxiliary_clean_files}
  1501. ${output_dir}/${multibib_target}.aux)
  1502. endforeach (multibib_auxfile ${LATEX_MULTIBIB_NEWCITES})
  1503. else()
  1504. set(make_dvi_command ${make_dvi_command}
  1505. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1506. ${bib_compiler} ${bib_compiler_flags} ${LATEX_TARGET})
  1507. set(make_pdf_command ${make_pdf_command}
  1508. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1509. ${bib_compiler} ${bib_compiler_flags} ${LATEX_TARGET})
  1510. endif()
  1511. foreach (bibfile ${LATEX_BIBFILES})
  1512. list(APPEND make_dvi_depends ${output_dir}/${bibfile})
  1513. list(APPEND make_pdf_depends ${output_dir}/${bibfile})
  1514. endforeach (bibfile ${LATEX_BIBFILES})
  1515. else()
  1516. if(LATEX_MULTIBIB_NEWCITES)
  1517. message(WARNING "MULTIBIB_NEWCITES has no effect without BIBFILES option.")
  1518. endif()
  1519. endif()
  1520. if(LATEX_USE_INDEX)
  1521. if(LATEX_INDEX_NAMES)
  1522. set(INDEX_NAMES ${LATEX_INDEX_NAMES})
  1523. else()
  1524. set(INDEX_NAMES ${LATEX_TARGET})
  1525. endif()
  1526. foreach(idx_name ${INDEX_NAMES})
  1527. set(make_dvi_command ${make_dvi_command}
  1528. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1529. ${latex_build_command}
  1530. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1531. ${MAKEINDEX_COMPILER} ${MAKEINDEX_COMPILER_ARGS} ${idx_name}.idx)
  1532. set(make_pdf_command ${make_pdf_command}
  1533. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1534. ${pdflatex_build_command}
  1535. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1536. ${MAKEINDEX_COMPILER} ${MAKEINDEX_COMPILER_ARGS} ${idx_name}.idx)
  1537. set(auxiliary_clean_files ${auxiliary_clean_files}
  1538. ${output_dir}/${idx_name}.idx
  1539. ${output_dir}/${idx_name}.ilg
  1540. ${output_dir}/${idx_name}.ind)
  1541. endforeach()
  1542. else()
  1543. if(LATEX_INDEX_NAMES)
  1544. message(WARNING "INDEX_NAMES has no effect without USE_INDEX option.")
  1545. endif()
  1546. endif()
  1547. set(make_dvi_command ${make_dvi_command}
  1548. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1549. ${latex_build_command}
  1550. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1551. ${latex_build_command})
  1552. set(make_pdf_command ${make_pdf_command}
  1553. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1554. ${pdflatex_build_command}
  1555. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1556. ${pdflatex_build_command})
  1557. # Need to run one more time to remove biblatex' warning
  1558. # about page breaks that have changed.
  1559. if(LATEX_USE_BIBLATEX)
  1560. set(make_dvi_command ${make_dvi_command}
  1561. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1562. ${latex_build_command})
  1563. set(make_pdf_command ${make_pdf_command}
  1564. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1565. ${pdflatex_build_command})
  1566. endif()
  1567. if(LATEX_USE_SYNCTEX)
  1568. if(NOT GZIP)
  1569. message(SEND_ERROR "UseLATEX.cmake: USE_SYNTEX option requires gzip program. Set GZIP variable.")
  1570. endif()
  1571. set(make_dvi_command ${make_dvi_command}
  1572. COMMAND ${CMAKE_COMMAND}
  1573. -D LATEX_BUILD_COMMAND=correct_synctex
  1574. -D LATEX_TARGET=${LATEX_TARGET}
  1575. -D GZIP=${GZIP}
  1576. -D "LATEX_SOURCE_DIRECTORY=${CMAKE_CURRENT_SOURCE_DIR}"
  1577. -D "LATEX_BINARY_DIRECTORY=${output_dir}"
  1578. -P ${LATEX_USE_LATEX_LOCATION}
  1579. )
  1580. set(make_pdf_command ${make_pdf_command}
  1581. COMMAND ${CMAKE_COMMAND}
  1582. -D LATEX_BUILD_COMMAND=correct_synctex
  1583. -D LATEX_TARGET=${LATEX_TARGET}
  1584. -D GZIP=${GZIP}
  1585. -D "LATEX_SOURCE_DIRECTORY=${CMAKE_CURRENT_SOURCE_DIR}"
  1586. -D "LATEX_BINARY_DIRECTORY=${output_dir}"
  1587. -P ${LATEX_USE_LATEX_LOCATION}
  1588. )
  1589. endif()
  1590. # Check LaTeX output for important warnings at end of build
  1591. set(make_dvi_command ${make_dvi_command}
  1592. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1593. ${CMAKE_COMMAND}
  1594. -D LATEX_BUILD_COMMAND=check_important_warnings
  1595. -D LATEX_TARGET=${LATEX_TARGET}
  1596. -P ${LATEX_USE_LATEX_LOCATION}
  1597. )
  1598. set(make_pdf_command ${make_pdf_command}
  1599. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1600. ${CMAKE_COMMAND}
  1601. -D LATEX_BUILD_COMMAND=check_important_warnings
  1602. -D LATEX_TARGET=${LATEX_TARGET}
  1603. -P ${LATEX_USE_LATEX_LOCATION}
  1604. )
  1605. # Capture the default build.
  1606. string(TOLOWER "${LATEX_DEFAULT_BUILD}" default_build)
  1607. if((NOT LATEX_FORCE_PDF) AND (NOT LATEX_FORCE_DVI) AND (NOT LATEX_FORCE_HTML))
  1608. set(no_force TRUE)
  1609. endif()
  1610. # Add commands and targets for building pdf outputs (with pdflatex).
  1611. if(LATEX_FORCE_PDF OR no_force)
  1612. if(LATEX_FORCE_PDF)
  1613. set(default_build pdf)
  1614. endif()
  1615. if(PDFLATEX_COMPILER)
  1616. add_custom_command(OUTPUT ${output_dir}/${LATEX_TARGET}.pdf
  1617. COMMAND ${make_pdf_command}
  1618. DEPENDS ${make_pdf_depends}
  1619. )
  1620. add_custom_target(${pdf_target}
  1621. DEPENDS ${output_dir}/${LATEX_TARGET}.pdf
  1622. SOURCES ${all_latex_sources}
  1623. )
  1624. if(NOT LATEX_EXCLUDE_FROM_DEFAULTS)
  1625. add_dependencies(pdf ${pdf_target})
  1626. endif()
  1627. endif()
  1628. endif()
  1629. # Add commands and targets for building dvi outputs.
  1630. if(LATEX_FORCE_DVI OR LATEX_FORCE_HTML OR no_force)
  1631. if(LATEX_FORCE_DVI)
  1632. if((NOT default_build STREQUAL dvi) AND
  1633. (NOT default_build STREQUAL ps) AND
  1634. (NOT default_build STREQUAL safepdf))
  1635. set(default_build dvi)
  1636. endif()
  1637. endif()
  1638. add_custom_command(OUTPUT ${output_dir}/${LATEX_TARGET}.dvi
  1639. COMMAND ${make_dvi_command}
  1640. DEPENDS ${make_dvi_depends}
  1641. )
  1642. add_custom_target(${dvi_target}
  1643. DEPENDS ${output_dir}/${LATEX_TARGET}.dvi
  1644. SOURCES ${all_latex_sources}
  1645. )
  1646. if(NOT LATEX_EXCLUDE_FROM_DEFAULTS)
  1647. add_dependencies(dvi ${dvi_target})
  1648. endif()
  1649. if(DVIPS_CONVERTER)
  1650. add_custom_command(OUTPUT ${output_dir}/${LATEX_TARGET}.ps
  1651. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1652. ${DVIPS_CONVERTER} ${DVIPS_CONVERTER_ARGS} -o ${LATEX_TARGET}.ps ${LATEX_TARGET}.dvi
  1653. DEPENDS ${output_dir}/${LATEX_TARGET}.dvi)
  1654. add_custom_target(${ps_target}
  1655. DEPENDS ${output_dir}/${LATEX_TARGET}.ps
  1656. SOURCES ${all_latex_sources}
  1657. )
  1658. if(NOT LATEX_EXCLUDE_FROM_DEFAULTS)
  1659. add_dependencies(ps ${ps_target})
  1660. endif()
  1661. if(PS2PDF_CONVERTER)
  1662. # Since both the pdf and safepdf targets have the same output, we
  1663. # cannot properly do the dependencies for both. When selecting safepdf,
  1664. # simply force a recompile every time.
  1665. add_custom_target(${safepdf_target}
  1666. ${CMAKE_COMMAND} -E chdir ${output_dir}
  1667. ${PS2PDF_CONVERTER} ${PS2PDF_CONVERTER_ARGS} ${LATEX_TARGET}.ps ${LATEX_TARGET}.pdf
  1668. DEPENDS ${ps_target}
  1669. )
  1670. if(NOT LATEX_EXCLUDE_FROM_DEFAULTS)
  1671. add_dependencies(safepdf ${safepdf_target})
  1672. endif()
  1673. endif()
  1674. endif()
  1675. endif()
  1676. if(LATEX_FORCE_HTML OR no_force)
  1677. if (LATEX_FORCE_HTML)
  1678. set(default_build html)
  1679. endif()
  1680. if(HTLATEX_COMPILER AND LATEX_MAIN_INPUT_SUBDIR)
  1681. message(STATUS
  1682. "Disabling HTML build for ${LATEX_TARGET_NAME}.tex because the main file is in subdirectory ${LATEX_MAIN_INPUT_SUBDIR}"
  1683. )
  1684. # The code below to run HTML assumes that LATEX_TARGET.tex is in the
  1685. # current directory. I have tried to specify that LATEX_TARGET.tex is
  1686. # in a subdirectory. That makes the build targets correct, but the
  1687. # HTML build still fails (at least for htlatex) because files are not
  1688. # generated where expected. I am getting around the problem by simply
  1689. # disabling HTML in this case. If someone really cares, they can fix
  1690. # this, but make sure it runs on many platforms and build programs.
  1691. elseif(HTLATEX_COMPILER)
  1692. # htlatex places the output in a different location
  1693. set(HTML_OUTPUT "${output_dir}/${LATEX_TARGET}.html")
  1694. add_custom_command(OUTPUT ${HTML_OUTPUT}
  1695. COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
  1696. ${HTLATEX_COMPILER} ${LATEX_MAIN_INPUT}
  1697. "${HTLATEX_COMPILER_TEX4HT_FLAGS}"
  1698. "${HTLATEX_COMPILER_TEX4HT_POSTPROCESSOR_FLAGS}"
  1699. "${HTLATEX_COMPILER_T4HT_POSTPROCESSOR_FLAGS}"
  1700. ${HTLATEX_COMPILER_ARGS}
  1701. DEPENDS
  1702. ${output_dir}/${LATEX_TARGET}.tex
  1703. ${output_dir}/${LATEX_TARGET}.dvi
  1704. VERBATIM
  1705. )
  1706. add_custom_target(${html_target}
  1707. DEPENDS ${HTML_OUTPUT} ${dvi_target}
  1708. SOURCES ${all_latex_sources}
  1709. )
  1710. if(NOT LATEX_EXCLUDE_FROM_DEFAULTS)
  1711. add_dependencies(html ${html_target})
  1712. endif()
  1713. endif()
  1714. endif()
  1715. # Set default targets.
  1716. if("${default_build}" STREQUAL "pdf")
  1717. add_custom_target(${LATEX_TARGET_NAME} DEPENDS ${pdf_target})
  1718. elseif("${default_build}" STREQUAL "dvi")
  1719. add_custom_target(${LATEX_TARGET_NAME} DEPENDS ${dvi_target})
  1720. elseif("${default_build}" STREQUAL "ps")
  1721. add_custom_target(${LATEX_TARGET_NAME} DEPENDS ${ps_target})
  1722. elseif("${default_build}" STREQUAL "safepdf")
  1723. add_custom_target(${LATEX_TARGET_NAME} DEPENDS ${safepdf_target})
  1724. elseif("${default_build}" STREQUAL "html")
  1725. add_custom_target(${LATEX_TARGET_NAME} DEPENDS ${html_target})
  1726. else()
  1727. message(SEND_ERROR "LATEX_DEFAULT_BUILD set to an invalid value. See the documentation for that variable.")
  1728. endif()
  1729. if(NOT LATEX_EXCLUDE_FROM_ALL)
  1730. add_custom_target(_${LATEX_TARGET_NAME} ALL DEPENDS ${LATEX_TARGET_NAME})
  1731. endif()
  1732. set_directory_properties(.
  1733. ADDITIONAL_MAKE_CLEAN_FILES "${auxiliary_clean_files}"
  1734. )
  1735. add_custom_target(${auxclean_target}
  1736. COMMENT "Cleaning auxiliary LaTeX files."
  1737. COMMAND ${CMAKE_COMMAND} -E remove ${auxiliary_clean_files}
  1738. )
  1739. add_dependencies(auxclean ${auxclean_target})
  1740. endfunction(add_latex_targets_internal)
  1741. function(add_latex_targets latex_main_input)
  1742. latex_get_output_path(output_dir)
  1743. parse_add_latex_arguments(ADD_LATEX_TARGETS ${latex_main_input} ${ARGN})
  1744. add_latex_targets_internal()
  1745. endfunction(add_latex_targets)
  1746. function(add_latex_document latex_main_input)
  1747. latex_get_output_path(output_dir)
  1748. if(output_dir)
  1749. parse_add_latex_arguments(add_latex_document ${latex_main_input} ${ARGN})
  1750. latex_copy_input_file(${LATEX_MAIN_INPUT})
  1751. foreach (bib_file ${LATEX_BIBFILES})
  1752. latex_copy_input_file(${bib_file})
  1753. endforeach (bib_file)
  1754. if (LATEX_USE_BIBLATEX AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/biblatex.cfg)
  1755. latex_copy_input_file(biblatex.cfg)
  1756. set(LATEX_USE_BIBLATEX_CONFIG TRUE)
  1757. endif()
  1758. foreach (input ${LATEX_INPUTS})
  1759. latex_copy_input_file(${input})
  1760. endforeach(input)
  1761. latex_copy_globbed_files(${CMAKE_CURRENT_SOURCE_DIR}/*.cls ${output_dir})
  1762. latex_copy_globbed_files(${CMAKE_CURRENT_SOURCE_DIR}/*.bst ${output_dir})
  1763. latex_copy_globbed_files(${CMAKE_CURRENT_SOURCE_DIR}/*.clo ${output_dir})
  1764. latex_copy_globbed_files(${CMAKE_CURRENT_SOURCE_DIR}/*.sty ${output_dir})
  1765. latex_copy_globbed_files(${CMAKE_CURRENT_SOURCE_DIR}/*.ist ${output_dir})
  1766. latex_copy_globbed_files(${CMAKE_CURRENT_SOURCE_DIR}/*.fd ${output_dir})
  1767. add_latex_targets_internal()
  1768. endif()
  1769. endfunction(add_latex_document)
  1770. #############################################################################
  1771. # Actually do stuff
  1772. #############################################################################
  1773. if(LATEX_BUILD_COMMAND)
  1774. set(command_handled)
  1775. if("${LATEX_BUILD_COMMAND}" STREQUAL execute_latex)
  1776. latex_execute_latex()
  1777. set(command_handled TRUE)
  1778. endif()
  1779. if("${LATEX_BUILD_COMMAND}" STREQUAL makeglossaries)
  1780. latex_makeglossaries()
  1781. set(command_handled TRUE)
  1782. endif()
  1783. if("${LATEX_BUILD_COMMAND}" STREQUAL makenomenclature)
  1784. latex_makenomenclature()
  1785. set(command_handled TRUE)
  1786. endif()
  1787. if("${LATEX_BUILD_COMMAND}" STREQUAL correct_synctex)
  1788. latex_correct_synctex()
  1789. set(command_handled TRUE)
  1790. endif()
  1791. if("${LATEX_BUILD_COMMAND}" STREQUAL check_important_warnings)
  1792. latex_check_important_warnings()
  1793. set(command_handled TRUE)
  1794. endif()
  1795. if(NOT command_handled)
  1796. message(SEND_ERROR "Unknown command: ${LATEX_BUILD_COMMAND}")
  1797. endif()
  1798. else()
  1799. # Must be part of the actual configure (included from CMakeLists.txt).
  1800. latex_setup_variables()
  1801. latex_setup_targets()
  1802. endif()