UseLATEX.cmake 69 KB

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