Skip to content
Snippets Groups Projects
Commit 8ec6bc35 authored by Christoph Grüninger's avatar Christoph Grüninger
Browse files

Merge branch 'feature/update-uselatex.cmake' into 'master'

[cmake] Update UseLATEX.cmake to upstream 2.4.6

See merge request !380

(cherry picked from commit ad1bc70c)

7adf5525 [cmake] Update UseLATEX.cmake to upstream 2.4.6
parent 0053059b
Branches
Tags
4 merge requests!586Centralize CI config for 2.6 release,!531Update CI for 2.6 release branch,!407[bugfix,2.6] Fix CMake with deactivated compiler version check,!389Merge branch 'feature/update-uselatex.cmake' into 'master'
Pipeline #
# File: UseLATEX.cmake
# CMAKE commands to actually use the LaTeX compiler
# Version: 2.3.0
# Version: 2.4.6
# Author: Kenneth Moreland <kmorel@sandia.gov>
#
# Copyright 2004, 2015 Sandia Corporation.
......@@ -61,15 +61,15 @@
# so all input files are copied from the source directory to the
# output directory. This includes the target tex file, any tex file
# listed with the INPUTS option, the bibliography files listed with
# the BIBFILES option, and any .cls, .bst, and .clo files found in
# the current source directory. Images found in the IMAGE_DIRS
# directories or listed by IMAGES are also copied to the output
# directory and converted to an appropriate format if necessary. Any
# tex files also listed with the CONFIGURE option are also processed
# with the CMake CONFIGURE_FILE command (with the @ONLY flag). Any
# file listed in CONFIGURE but not the target tex file or listed with
# INPUTS has no effect. DEPENDS can be used to specify generated files
# that are needed to compile the latex target.
# the BIBFILES option, and any .cls, .bst, .clo, .sty, .ist, and .fd
# files found in the current source directory. Images found in the
# IMAGE_DIRS directories or listed by IMAGES are also copied to the
# output directory and converted to an appropriate format if necessary.
# Any tex files also listed with the CONFIGURE option are also processed
# with the CMake CONFIGURE_FILE command (with the @ONLY flag). Any file
# listed in CONFIGURE but not the target tex file or listed with INPUTS
# has no effect. DEPENDS can be used to specify generated files that are
# needed to compile the latex target.
#
# The following targets are made. The name prefix is based off of the
# base name of the tex file unless TARGET_NAME is specified. If
......@@ -115,6 +115,65 @@
#
# History:
#
# 2.4.6 Fix parse issue with older versions of CMake.
#
# 2.4.5 Fix issues with files and paths containing spaces.
#
# 2.4.4 Improve error reporting message when LaTeX fails.
#
# When LaTeX fails, delete the output file, which is invalid.
#
# Add warnings for "missing characters." These usually mean that a
# non-ASCII character is in the document and will not be printed
# correctly.
#
# 2.4.3 Check for warnings from the natbib package. When using natbib,
# warnings for missing bibliography references look different. So
# far, natbib seems to be quiet unless something is important, so
# look for all natbib warnings. (We can change this later if
# necessary.)
#
# 2.4.2 Fix an issue where new versions of ImageMagick expect the order of
# options in command line execution of magick/convert. (See, for
# example, http://www.imagemagick.org/Usage/basics/#why.)
#
# 2.4.1 Add ability to dump LaTeX log file when using batch mode. Batch
# mode suppresses most output, often including error messages. To
# make sure critical error messages get displayed, show the full log
# on failures.
#
# 2.4.0 Remove "-r 600" from the default PDFTOPS_CONVERTER_FLAGS. The -r flag
# is available from the Poppler version of pdftops, but not the Xpdf
# version.
#
# Fix an issue with the flags for the different programs not being
# properly separated.
#
# Fix an issue on windows where the = character is not allowed for
# ps2pdf arguments.
#
# Change default arguments for latex and pdflatex commands. Makes the
# output more quiet and prints out the file/line where errors occur.
# (Thanks to Nikos Koukis.)
#
# After a LaTeX build, check the log file for warnings that are
# indicative of problems with the build.
#
# Remove support for latex2html. Instead, use the htlatex program.
# This is now part of TeX Live and most other distributions. It also
# behaves much more like the other LaTeX programs. Also fixed some
# nasty issues with the htlatex arguments.
#
# 2.3.2 Declare LaTeX input files as sources for targets so that they show
# up in IDEs like QtCreator.
#
# Fix issue where main tex files in subdirectories were creating
# invalid targets for building HTML. Just disable the HTML targets in
# this case.
#
# 2.3.1 Support use of magick command instead of convert command for
# ImageMagick 7.
#
# 2.3.0 Add USE_BIBLATEX option to support the biblatex package, which
# requires using the program biber as a replacement for bibtex
# (thanks to David Tracey).
......@@ -364,6 +423,65 @@ endfunction(latex_get_filename_component)
#############################################################################
# Functions that perform processing during a LaTeX build.
#############################################################################
function(latex_execute_latex)
if(NOT LATEX_TARGET)
message(SEND_ERROR "Need to define LATEX_TARGET")
endif()
if(NOT LATEX_WORKING_DIRECTORY)
message(SEND_ERROR "Need to define LATEX_WORKING_DIRECTORY")
endif()
if(NOT LATEX_FULL_COMMAND)
message(SEND_ERROR "Need to define LATEX_FULL_COMMAND")
endif()
if(NOT LATEX_OUTPUT_FILE)
message(SEND_ERROR "Need to define LATEX_OUTPUT_FILE")
endif()
set(full_command_original "${LATEX_FULL_COMMAND}")
# Chose the native method for parsing command arguments. Newer versions of
# CMake allow you to just use NATIVE_COMMAND.
if (CMAKE_VERSION VERSION_GREATER 3.8)
set(separate_arguments_mode NATIVE_COMMAND)
else()
if (WIN32)
set(separate_arguments_mode WINDOWS_COMMAND)
else()
set(separate_arguments_mode UNIX_COMMAND)
endif()
endif()
# Preps variables for use in execute_process.
# Even though we expect LATEX_WORKING_DIRECTORY to have a single "argument,"
# we also want to make sure that we strip out any escape characters that can
# foul up the WORKING_DIRECTORY argument.
separate_arguments(LATEX_FULL_COMMAND UNIX_COMMAND "${LATEX_FULL_COMMAND}")
separate_arguments(LATEX_WORKING_DIRECTORY UNIX_COMMAND "${LATEX_WORKING_DIRECTORY}")
execute_process(
COMMAND ${LATEX_FULL_COMMAND}
WORKING_DIRECTORY ${LATEX_WORKING_DIRECTORY}
RESULT_VARIABLE execute_result
)
if(NOT ${execute_result} EQUAL 0)
# LaTeX tends to write a file when a failure happens. Delete that file so
# that LaTeX will run again.
file(REMOVE "${LATEX_WORKING_DIRECTORY}/${LATEX_OUTPUT_FILE}")
message("\n\nLaTeX command failed")
message("${full_command_original}")
message("Log output:")
file(READ ${LATEX_WORKING_DIRECTORY}/${LATEX_TARGET}.log log_output)
message("${log_output}")
message(FATAL_ERROR
"Successfully executed LaTeX, but LaTeX returned an error.")
endif()
endfunction(latex_execute_latex)
function(latex_makeglossaries)
# This is really a bare bones port of the makeglossaries perl script into
# CMake scripting.
......@@ -482,10 +600,10 @@ function(latex_makeglossaries)
set(codepage_flags "")
endif()
message("${XINDY_COMPILER} ${MAKEGLOSSARIES_COMPILER_FLAGS} ${language_flags} ${codepage_flags} -I xindy -M ${glossary_name} -t ${glossary_log} -o ${glossary_out} ${glossary_in}"
message("${XINDY_COMPILER} ${MAKEGLOSSARIES_COMPILER_ARGS} ${language_flags} ${codepage_flags} -I xindy -M ${glossary_name} -t ${glossary_log} -o ${glossary_out} ${glossary_in}"
)
exec_program(${XINDY_COMPILER}
ARGS ${MAKEGLOSSARIES_COMPILER_FLAGS}
ARGS ${MAKEGLOSSARIES_COMPILER_ARGS}
${language_flags}
${codepage_flags}
-I xindy
......@@ -504,7 +622,7 @@ function(latex_makeglossaries)
if("${xindy_output}" MATCHES "^Cannot locate xindy module for language (.+) in codepage (.+)\\.$")
message("*************** Retrying xindy with default codepage.")
exec_program(${XINDY_COMPILER}
ARGS ${MAKEGLOSSARIES_COMPILER_FLAGS}
ARGS ${MAKEGLOSSARIES_COMPILER_ARGS}
${language_flags}
-I xindy
-M ${glossary_name}
......@@ -515,8 +633,8 @@ function(latex_makeglossaries)
endif()
else()
message("${MAKEINDEX_COMPILER} ${MAKEGLOSSARIES_COMPILER_FLAGS} -s ${istfile} -t ${glossary_log} -o ${glossary_out} ${glossary_in}")
exec_program(${MAKEINDEX_COMPILER} ARGS ${MAKEGLOSSARIES_COMPILER_FLAGS}
message("${MAKEINDEX_COMPILER} ${MAKEGLOSSARIES_COMPILER_ARGS} -s ${istfile} -t ${glossary_log} -o ${glossary_out} ${glossary_in}")
exec_program(${MAKEINDEX_COMPILER} ARGS ${MAKEGLOSSARIES_COMPILER_ARGS}
-s ${istfile} -t ${glossary_log} -o ${glossary_out} ${glossary_in}
)
endif()
......@@ -537,7 +655,7 @@ function(latex_makenomenclature)
set(nomencl_out ${LATEX_TARGET}.nls)
set(nomencl_in ${LATEX_TARGET}.nlo)
exec_program(${MAKEINDEX_COMPILER} ARGS ${MAKENOMENCLATURE_COMPILER_FLAGS}
exec_program(${MAKEINDEX_COMPILER} ARGS ${MAKENOMENCLATURE_COMPILER_ARGS}
${nomencl_in} -s "nomencl.ist" -o ${nomencl_out}
)
endfunction(latex_makenomenclature)
......@@ -600,6 +718,87 @@ function(latex_correct_synctex)
endfunction(latex_correct_synctex)
function(latex_check_important_warnings)
set(log_file ${LATEX_TARGET}.log)
message("\nChecking ${log_file} for important warnings.")
if(NOT LATEX_TARGET)
message(SEND_ERROR "Need to define LATEX_TARGET")
endif()
if(NOT EXISTS ${log_file})
message("Could not find log file: ${log_file}")
return()
endif()
set(found_error)
file(READ ${log_file} log)
# Check for undefined references
string(REGEX MATCHALL
"\n[^\n]*Reference[^\n]*undefined[^\n]*"
reference_warnings
"${log}")
if(reference_warnings)
set(found_error TRUE)
message("\nFound missing reference warnings.")
foreach(warning ${reference_warnings})
string(STRIP "${warning}" warning_no_newline)
message("${warning_no_newline}")
endforeach(warning)
endif()
# Check for natbib warnings
string(REGEX MATCHALL
"\nPackage natbib Warning:[^\n]*"
natbib_warnings
"${log}")
if(natbib_warnings)
set(found_error TRUE)
message("\nFound natbib package warnings.")
foreach(warning ${natbib_warnings})
string(STRIP "${warning}" warning_no_newline)
message("${warning_no_newline}")
endforeach(warning)
endif()
# Check for overfull
string(REGEX MATCHALL
"\nOverfull[^\n]*"
overfull_warnings
"${log}")
if(overfull_warnings)
set(found_error TRUE)
message("\nFound overfull warnings. These are indicative of layout errors.")
foreach(warning ${overfull_warnings})
string(STRIP "${warning}" warning_no_newline)
message("${warning_no_newline}")
endforeach(warning)
endif()
# Check for invalid characters
string(REGEX MATCHALL
"\nMissing character:[^\n]*"
invalid_character_warnings
"${log}")
if(invalid_character_warnings)
set(found_error TRUE)
message("\nFound invalid character warnings. These characters are likely not printed correctly.")
foreach(warning ${invalid_character_warnings})
string(STRIP "${warning}" warning_no_newline)
message("${warning_no_newline}")
endforeach(warning)
endif()
if(found_error)
latex_get_filename_component(log_file_path ${log_file} ABSOLUTE)
message("\nConsult ${log_file_path} for more information on LaTeX build.")
else()
message("No known important warnings found.")
endif(found_error)
endfunction(latex_check_important_warnings)
#############################################################################
# Helper functions for establishing LaTeX build.
#############################################################################
......@@ -635,6 +834,12 @@ function(latex_setup_variables)
DOC "The pdf to ps converter program from the Poppler package."
)
find_program(HTLATEX_COMPILER
NAMES htlatex
PATHS ${MIKTEX_BINARY_PATH}
/usr/bin
)
mark_as_advanced(
LATEX_COMPILER
PDFLATEX_COMPILER
......@@ -646,38 +851,31 @@ function(latex_setup_variables)
PS2PDF_CONVERTER
PDFTOPS_CONVERTER
LATEX2HTML_CONVERTER
HTLATEX_COMPILER
)
latex_needit(LATEX_COMPILER latex)
latex_wantit(PDFLATEX_COMPILER pdflatex)
latex_wantit(HTLATEX_COMPILER htlatex)
latex_needit(BIBTEX_COMPILER bibtex)
latex_wantit(BIBER_COMPILER biber)
latex_needit(MAKEINDEX_COMPILER makeindex)
latex_wantit(DVIPS_CONVERTER dvips)
latex_wantit(PS2PDF_CONVERTER ps2pdf)
latex_wantit(PDFTOPS_CONVERTER pdftops)
# MiKTeX calls latex2html htlatex
if(NOT ${LATEX2HTML_CONVERTER})
find_program(HTLATEX_CONVERTER
NAMES htlatex
PATHS ${MIKTEX_BINARY_PATH}
/usr/bin
)
mark_as_advanced(HTLATEX_CONVERTER)
if(HTLATEX_CONVERTER)
set(USING_HTLATEX TRUE CACHE INTERNAL "True when using MiKTeX htlatex instead of latex2html" FORCE)
set(LATEX2HTML_CONVERTER ${HTLATEX_CONVERTER}
CACHE FILEPATH "htlatex taking the place of latex2html" FORCE)
else()
set(USING_HTLATEX FALSE CACHE INTERNAL "True when using MiKTeX htlatex instead of latex2html" FORCE)
endif()
endif()
latex_wantit(LATEX2HTML_CONVERTER latex2html)
set(LATEX_COMPILER_FLAGS "-interaction=nonstopmode"
set(LATEX_COMPILER_FLAGS "-interaction=batchmode -file-line-error"
CACHE STRING "Flags passed to latex.")
set(PDFLATEX_COMPILER_FLAGS ${LATEX_COMPILER_FLAGS}
CACHE STRING "Flags passed to pdflatex.")
set(HTLATEX_COMPILER_TEX4HT_FLAGS "html"
CACHE STRING "Options for the tex4ht.sty and *.4ht style files.")
set(HTLATEX_COMPILER_TEX4HT_POSTPROCESSOR_FLAGS ""
CACHE STRING "Options for the text4ht postprocessor.")
set(HTLATEX_COMPILER_T4HT_POSTPROCESSOR_FLAGS ""
CACHE STRING "Options for the t4ht postprocessor.")
set(HTLATEX_COMPILER_LATEX_FLAGS ${LATEX_COMPILER_FLAGS}
CACHE STRING "Flags passed from htlatex to the LaTeX compiler.")
set(LATEX_SYNCTEX_FLAGS "-synctex=1"
CACHE STRING "latex/pdflatex flags used to create synctex file.")
set(BIBTEX_COMPILER_FLAGS ""
......@@ -692,15 +890,26 @@ function(latex_setup_variables)
CACHE STRING "Flags passed to makenomenclature.")
set(DVIPS_CONVERTER_FLAGS "-Ppdf -G0 -t letter"
CACHE STRING "Flags passed to dvips.")
set(PS2PDF_CONVERTER_FLAGS "-dMaxSubsetPct=100 -dCompatibilityLevel=1.3 -dSubsetFonts=true -dEmbedAllFonts=true -dAutoFilterColorImages=false -dAutoFilterGrayImages=false -dColorImageFilter=/FlateEncode -dGrayImageFilter=/FlateEncode -dMonoImageFilter=/FlateEncode"
CACHE STRING "Flags passed to ps2pdf.")
set(PDFTOPS_CONVERTER_FLAGS -r 600
if(NOT WIN32)
set(PS2PDF_CONVERTER_FLAGS "-dMaxSubsetPct=100 -dCompatibilityLevel=1.3 -dSubsetFonts=true -dEmbedAllFonts=true -dAutoFilterColorImages=false -dAutoFilterGrayImages=false -dColorImageFilter=/FlateEncode -dGrayImageFilter=/FlateEncode -dMonoImageFilter=/FlateEncode"
CACHE STRING "Flags passed to ps2pdf.")
else()
# Most windows ports of ghostscript utilities use .bat files for ps2pdf
# commands. bat scripts interpret "=" as a special character and separate
# those arguments. To get around this, the ghostscript utilities also
# support using "#" in place of "=".
set(PS2PDF_CONVERTER_FLAGS "-dMaxSubsetPct#100 -dCompatibilityLevel#1.3 -dSubsetFonts#true -dEmbedAllFonts#true -dAutoFilterColorImages#false -dAutoFilterGrayImages#false -dColorImageFilter#/FlateEncode -dGrayImageFilter#/FlateEncode -dMonoImageFilter#/FlateEncode"
CACHE STRING "Flags passed to ps2pdf.")
endif()
set(PDFTOPS_CONVERTER_FLAGS ""
CACHE STRING "Flags passed to pdftops.")
set(LATEX2HTML_CONVERTER_FLAGS ""
CACHE STRING "Flags passed to latex2html.")
mark_as_advanced(
LATEX_COMPILER_FLAGS
PDFLATEX_COMPILER_FLAGS
HTLATEX_COMPILER_TEX4HT_FLAGS
HTLATEX_COMPILER_TEX4HT_POSTPROCESSOR_FLAGS
HTLATEX_COMPILER_T4HT_POSTPROCESSOR_FLAGS
HTLATEX_COMPILER_LATEX_FLAGS
LATEX_SYNCTEX_FLAGS
BIBTEX_COMPILER_FLAGS
BIBER_COMPILER_FLAGS
......@@ -710,10 +919,17 @@ function(latex_setup_variables)
DVIPS_CONVERTER_FLAGS
PS2PDF_CONVERTER_FLAGS
PDFTOPS_CONVERTER_FLAGS
LATEX2HTML_CONVERTER_FLAGS
)
# Because it is easier to type, the flags variables are entered as
# space-separated strings much like you would in a shell. However, when
# using a CMake command to execute a program, it works better to hold the
# arguments in semicolon-separated lists (otherwise the whole string will
# be interpreted as a single argument). Use the separate_arguments to
# convert the space-separated strings to semicolon-separated lists.
separate_arguments(LATEX_COMPILER_FLAGS)
separate_arguments(PDFLATEX_COMPILER_FLAGS)
separate_arguments(HTLATEX_COMPILER_LATEX_FLAGS)
separate_arguments(LATEX_SYNCTEX_FLAGS)
separate_arguments(BIBTEX_COMPILER_FLAGS)
separate_arguments(BIBER_COMPILER_FLAGS)
......@@ -723,9 +939,27 @@ function(latex_setup_variables)
separate_arguments(DVIPS_CONVERTER_FLAGS)
separate_arguments(PS2PDF_CONVERTER_FLAGS)
separate_arguments(PDFTOPS_CONVERTER_FLAGS)
separate_arguments(LATEX2HTML_CONVERTER_FLAGS)
find_program(IMAGEMAGICK_CONVERT convert
# Not quite done. When you call separate_arguments on a cache variable,
# the result is written to a local variable. That local variable goes
# away when this function returns (which is before any of them are used).
# So, copy these variables with local scope to cache variables with
# global scope.
set(LATEX_COMPILER_ARGS "${LATEX_COMPILER_FLAGS}" CACHE INTERNAL "")
set(PDFLATEX_COMPILER_ARGS "${PDFLATEX_COMPILER_FLAGS}" CACHE INTERNAL "")
set(HTLATEX_COMPILER_ARGS "${HTLATEX_COMPILER_LATEX_FLAGS}" CACHE INTERNAL "")
set(LATEX_SYNCTEX_ARGS "${LATEX_SYNCTEX_FLAGS}" CACHE INTERNAL "")
set(BIBTEX_COMPILER_ARGS "${BIBTEX_COMPILER_FLAGS}" CACHE INTERNAL "")
set(BIBER_COMPILER_ARGS "${BIBER_COMPILER_FLAGS}" CACHE INTERNAL "")
set(MAKEINDEX_COMPILER_ARGS "${MAKEINDEX_COMPILER_FLAGS}" CACHE INTERNAL "")
set(MAKEGLOSSARIES_COMPILER_ARGS "${MAKEGLOSSARIES_COMPILER_FLAGS}" CACHE INTERNAL "")
set(MAKENOMENCLATURE_COMPILER_ARGS "${MAKENOMENCLATURE_COMPILER_FLAGS}" CACHE INTERNAL "")
set(DVIPS_CONVERTER_ARGS "${DVIPS_CONVERTER_FLAGS}" CACHE INTERNAL "")
set(PS2PDF_CONVERTER_ARGS "${PS2PDF_CONVERTER_FLAGS}" CACHE INTERNAL "")
set(PDFTOPS_CONVERTER_ARGS "${PDFTOPS_CONVERTER_FLAGS}" CACHE INTERNAL "")
find_program(IMAGEMAGICK_CONVERT
NAMES magick convert
DOC "The convert program that comes with ImageMagick (available at http://www.imagemagick.org)."
)
mark_as_advanced(IMAGEMAGICK_CONVERT)
......@@ -864,7 +1098,7 @@ function(latex_add_convert_command
if(PS2PDF_CONVERTER)
set(require_imagemagick_convert FALSE)
set(converter ${PS2PDF_CONVERTER})
set(convert_flags -dEPSCrop ${PS2PDF_CONVERTER_FLAGS})
set(convert_flags -dEPSCrop ${PS2PDF_CONVERTER_ARGS})
else()
message(SEND_ERROR "Using postscript files with pdflatex requires ps2pdf for conversion.")
endif()
......@@ -875,7 +1109,7 @@ function(latex_add_convert_command
if(PDFTOPS_CONVERTER)
set(require_imagemagick_convert FALSE)
set(converter ${PDFTOPS_CONVERTER})
set(convert_flags -eps ${PDFTOPS_CONVERTER_FLAGS})
set(convert_flags -eps ${PDFTOPS_CONVERTER_ARGS})
else()
message(STATUS "Consider getting pdftops from Poppler to convert PDF images to EPS images.")
set(convert_flags ${flags})
......@@ -888,20 +1122,27 @@ function(latex_add_convert_command
if(IMAGEMAGICK_CONVERT)
string(TOLOWER ${IMAGEMAGICK_CONVERT} IMAGEMAGICK_CONVERT_LOWERCASE)
if(${IMAGEMAGICK_CONVERT_LOWERCASE} MATCHES "system32[/\\\\]convert\\.exe")
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) and its convert program is used for IMAGEMAGICK_CONVERT. (It is helpful if ImageMagick's path is before the Windows system paths.)")
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.")
else()
set(converter ${IMAGEMAGICK_CONVERT})
# ImageMagick requires a special order of arguments where resize and
# arguments of that nature must be placed after the input image path.
add_custom_command(OUTPUT ${output_path}
COMMAND ${converter}
ARGS ${input_path} ${convert_flags} ${output_path}
DEPENDS ${input_path}
)
endif()
else()
message(SEND_ERROR "Could not find convert program. Please download ImageMagick from http://www.imagemagick.org and install.")
endif()
else() # Not ImageMagick convert
add_custom_command(OUTPUT ${output_path}
COMMAND ${converter}
ARGS ${convert_flags} ${input_path} ${output_path}
DEPENDS ${input_path}
)
endif()
add_custom_command(OUTPUT ${output_path}
COMMAND ${converter}
ARGS ${convert_flags} ${input_path} ${output_path}
DEPENDS ${input_path}
)
endfunction(latex_add_convert_command)
# Makes custom commands to convert a file to a particular type.
......@@ -921,10 +1162,15 @@ function(latex_convert_image
# Check input filename for potential problems with LaTeX.
latex_get_filename_component(name "${input_file}" NAME_WE)
if(name MATCHES ".*\\..*")
string(REPLACE "." "-" suggested_name "${name}")
set(suggested_name "${suggested_name}${extension}")
message(WARNING "Some LaTeX distributions have problems with image file names with multiple extensions. Consider changing ${name}${extension} to something like ${suggested_name}.")
set(suggested_name "${name}")
if(suggested_name MATCHES ".*\\..*")
string(REPLACE "." "-" suggested_name "${suggested_name}")
endif()
if(suggested_name MATCHES ".* .*")
string(REPLACE " " "-" suggested_name "${suggested_name}")
endif()
if(NOT suggested_name STREQUAL name)
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}.")
endif()
string(REGEX REPLACE "\\.[^.]*\$" ${output_extension} output_file
......@@ -1145,24 +1391,58 @@ function(parse_add_latex_arguments command latex_main_input)
endfunction(parse_add_latex_arguments)
function(add_latex_targets_internal)
latex_get_output_path(output_dir)
if(LATEX_USE_SYNCTEX)
set(synctex_flags ${LATEX_SYNCTEX_FLAGS})
set(synctex_flags ${LATEX_SYNCTEX_ARGS})
else()
set(synctex_flags)
endif()
# The commands to run LaTeX. They are repeated multiple times.
set(latex_build_command
${LATEX_COMPILER} ${LATEX_COMPILER_FLAGS} ${synctex_flags} ${LATEX_MAIN_INPUT}
${LATEX_COMPILER} ${LATEX_COMPILER_ARGS} ${synctex_flags} ${LATEX_MAIN_INPUT}
)
if(LATEX_COMPILER_ARGS MATCHES ".*batchmode.*")
# Wrap command in script that dumps the log file on error. This makes sure
# errors can be seen.
set(latex_build_command
${CMAKE_COMMAND}
-D LATEX_BUILD_COMMAND=execute_latex
-D LATEX_TARGET=${LATEX_TARGET}
-D LATEX_WORKING_DIRECTORY="${output_dir}"
-D LATEX_FULL_COMMAND="${latex_build_command}"
-D LATEX_OUTPUT_FILE="${LATEX_TARGET}.dvi"
-P "${LATEX_USE_LATEX_LOCATION}"
)
endif()
set(pdflatex_build_command
${PDFLATEX_COMPILER} ${PDFLATEX_COMPILER_FLAGS} ${synctex_flags} ${LATEX_MAIN_INPUT}
${PDFLATEX_COMPILER} ${PDFLATEX_COMPILER_ARGS} ${synctex_flags} ${LATEX_MAIN_INPUT}
)
if(PDFLATEX_COMPILER_ARGS MATCHES ".*batchmode.*")
# Wrap command in script that dumps the log file on error. This makes sure
# errors can be seen.
set(pdflatex_build_command
${CMAKE_COMMAND}
-D LATEX_BUILD_COMMAND=execute_latex
-D LATEX_TARGET=${LATEX_TARGET}
-D LATEX_WORKING_DIRECTORY="${output_dir}"
-D LATEX_FULL_COMMAND="${pdflatex_build_command}"
-D LATEX_OUTPUT_FILE="${LATEX_TARGET}.pdf"
-P "${LATEX_USE_LATEX_LOCATION}"
)
endif()
if(NOT LATEX_TARGET_NAME)
set(LATEX_TARGET_NAME ${LATEX_TARGET})
# Use the main filename (minus the .tex) as the target name. Remove any
# spaces since CMake cannot have spaces in its target names.
string(REPLACE " " "_" LATEX_TARGET_NAME ${LATEX_TARGET})
endif()
# Some LaTeX commands may need to be modified (or may not work) if the main
# tex file is in a subdirectory. Make a flag for that.
get_filename_component(LATEX_MAIN_INPUT_SUBDIR ${LATEX_MAIN_INPUT} DIRECTORY)
# Set up target names.
set(dvi_target ${LATEX_TARGET_NAME}_dvi)
set(pdf_target ${LATEX_TARGET_NAME}_pdf)
......@@ -1241,6 +1521,8 @@ function(add_latex_targets_internal)
endif()
endforeach(input)
set(all_latex_sources ${LATEX_MAIN_INPUT} ${LATEX_INPUTS} ${image_list})
if(LATEX_USE_GLOSSARY)
foreach(dummy 0 1) # Repeat these commands twice.
set(make_dvi_command ${make_dvi_command}
......@@ -1250,7 +1532,7 @@ function(add_latex_targets_internal)
-D LATEX_TARGET=${LATEX_TARGET}
-D MAKEINDEX_COMPILER=${MAKEINDEX_COMPILER}
-D XINDY_COMPILER=${XINDY_COMPILER}
-D MAKEGLOSSARIES_COMPILER_FLAGS=${MAKEGLOSSARIES_COMPILER_FLAGS}
-D MAKEGLOSSARIES_COMPILER_ARGS=${MAKEGLOSSARIES_COMPILER_ARGS}
-P ${LATEX_USE_LATEX_LOCATION}
COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
${latex_build_command}
......@@ -1262,7 +1544,7 @@ function(add_latex_targets_internal)
-D LATEX_TARGET=${LATEX_TARGET}
-D MAKEINDEX_COMPILER=${MAKEINDEX_COMPILER}
-D XINDY_COMPILER=${XINDY_COMPILER}
-D MAKEGLOSSARIES_COMPILER_FLAGS=${MAKEGLOSSARIES_COMPILER_FLAGS}
-D MAKEGLOSSARIES_COMPILER_ARGS=${MAKEGLOSSARIES_COMPILER_ARGS}
-P ${LATEX_USE_LATEX_LOCATION}
COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
${pdflatex_build_command}
......@@ -1278,7 +1560,7 @@ function(add_latex_targets_internal)
-D LATEX_BUILD_COMMAND=makenomenclature
-D LATEX_TARGET=${LATEX_TARGET}
-D MAKEINDEX_COMPILER=${MAKEINDEX_COMPILER}
-D MAKENOMENCLATURE_COMPILER_FLAGS=${MAKENOMENCLATURE_COMPILER_FLAGS}
-D MAKENOMENCLATURE_COMPILER_ARGS=${MAKENOMENCLATURE_COMPILER_ARGS}
-P ${LATEX_USE_LATEX_LOCATION}
COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
${latex_build_command}
......@@ -1289,7 +1571,7 @@ function(add_latex_targets_internal)
-D LATEX_BUILD_COMMAND=makenomenclature
-D LATEX_TARGET=${LATEX_TARGET}
-D MAKEINDEX_COMPILER=${MAKEINDEX_COMPILER}
-D MAKENOMENCLATURE_COMPILER_FLAGS=${MAKENOMENCLATURE_COMPILER_FLAGS}
-D MAKENOMENCLATURE_COMPILER_ARGS=${MAKENOMENCLATURE_COMPILER_ARGS}
-P ${LATEX_USE_LATEX_LOCATION}
COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
${pdflatex_build_command}
......@@ -1303,10 +1585,10 @@ function(add_latex_targets_internal)
message(SEND_ERROR "I need the biber command.")
endif()
set(bib_compiler ${BIBER_COMPILER})
set(bib_compiler_flags ${BIBER_COMPILER_FLAGS})
set(bib_compiler_flags ${BIBER_COMPILER_ARGS})
else()
set(bib_compiler ${BIBTEX_COMPILER})
set(bib_compiler_flags ${BIBTEX_COMPILER_FLAGS})
set(bib_compiler_flags ${BIBTEX_COMPILER_ARGS})
endif()
if(LATEX_MULTIBIB_NEWCITES)
foreach (multibib_auxfile ${LATEX_MULTIBIB_NEWCITES})
......@@ -1350,12 +1632,12 @@ function(add_latex_targets_internal)
COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
${latex_build_command}
COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
${MAKEINDEX_COMPILER} ${MAKEINDEX_COMPILER_FLAGS} ${idx_name}.idx)
${MAKEINDEX_COMPILER} ${MAKEINDEX_COMPILER_ARGS} ${idx_name}.idx)
set(make_pdf_command ${make_pdf_command}
COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
${pdflatex_build_command}
COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
${MAKEINDEX_COMPILER} ${MAKEINDEX_COMPILER_FLAGS} ${idx_name}.idx)
${MAKEINDEX_COMPILER} ${MAKEINDEX_COMPILER_ARGS} ${idx_name}.idx)
set(auxiliary_clean_files ${auxiliary_clean_files}
${output_dir}/${idx_name}.idx
${output_dir}/${idx_name}.ilg
......@@ -1413,6 +1695,22 @@ function(add_latex_targets_internal)
)
endif()
# Check LaTeX output for important warnings at end of build
set(make_dvi_command ${make_dvi_command}
COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
${CMAKE_COMMAND}
-D LATEX_BUILD_COMMAND=check_important_warnings
-D LATEX_TARGET=${LATEX_TARGET}
-P ${LATEX_USE_LATEX_LOCATION}
)
set(make_pdf_command ${make_pdf_command}
COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
${CMAKE_COMMAND}
-D LATEX_BUILD_COMMAND=check_important_warnings
-D LATEX_TARGET=${LATEX_TARGET}
-P ${LATEX_USE_LATEX_LOCATION}
)
# Capture the default build.
string(TOLOWER "${LATEX_DEFAULT_BUILD}" default_build)
......@@ -1431,7 +1729,10 @@ function(add_latex_targets_internal)
COMMAND ${make_pdf_command}
DEPENDS ${make_pdf_depends}
)
add_custom_target(${pdf_target} DEPENDS ${output_dir}/${LATEX_TARGET}.pdf)
add_custom_target(${pdf_target}
DEPENDS ${output_dir}/${LATEX_TARGET}.pdf
SOURCES ${all_latex_sources}
)
if(NOT LATEX_EXCLUDE_FROM_DEFAULTS)
add_dependencies(pdf ${pdf_target})
endif()
......@@ -1452,7 +1753,10 @@ function(add_latex_targets_internal)
COMMAND ${make_dvi_command}
DEPENDS ${make_dvi_depends}
)
add_custom_target(${dvi_target} DEPENDS ${output_dir}/${LATEX_TARGET}.dvi)
add_custom_target(${dvi_target}
DEPENDS ${output_dir}/${LATEX_TARGET}.dvi
SOURCES ${all_latex_sources}
)
if(NOT LATEX_EXCLUDE_FROM_DEFAULTS)
add_dependencies(dvi ${dvi_target})
endif()
......@@ -1460,9 +1764,12 @@ function(add_latex_targets_internal)
if(DVIPS_CONVERTER)
add_custom_command(OUTPUT ${output_dir}/${LATEX_TARGET}.ps
COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
${DVIPS_CONVERTER} ${DVIPS_CONVERTER_FLAGS} -o ${LATEX_TARGET}.ps ${LATEX_TARGET}.dvi
${DVIPS_CONVERTER} ${DVIPS_CONVERTER_ARGS} -o ${LATEX_TARGET}.ps ${LATEX_TARGET}.dvi
DEPENDS ${output_dir}/${LATEX_TARGET}.dvi)
add_custom_target(${ps_target} DEPENDS ${output_dir}/${LATEX_TARGET}.ps)
add_custom_target(${ps_target}
DEPENDS ${output_dir}/${LATEX_TARGET}.ps
SOURCES ${all_latex_sources}
)
if(NOT LATEX_EXCLUDE_FROM_DEFAULTS)
add_dependencies(ps ${ps_target})
endif()
......@@ -1472,7 +1779,7 @@ function(add_latex_targets_internal)
# simply force a recompile every time.
add_custom_target(${safepdf_target}
${CMAKE_COMMAND} -E chdir ${output_dir}
${PS2PDF_CONVERTER} ${PS2PDF_CONVERTER_FLAGS} ${LATEX_TARGET}.ps ${LATEX_TARGET}.pdf
${PS2PDF_CONVERTER} ${PS2PDF_CONVERTER_ARGS} ${LATEX_TARGET}.ps ${LATEX_TARGET}.pdf
DEPENDS ${ps_target}
)
if(NOT LATEX_EXCLUDE_FROM_DEFAULTS)
......@@ -1487,19 +1794,36 @@ function(add_latex_targets_internal)
set(default_build html)
endif()
if(LATEX2HTML_CONVERTER)
if(USING_HTLATEX)
# htlatex places the output in a different location
set(HTML_OUTPUT "${output_dir}/${LATEX_TARGET}.html")
else()
set(HTML_OUTPUT "${output_dir}/${LATEX_TARGET}/${LATEX_TARGET}.html")
endif()
if(HTLATEX_COMPILER AND LATEX_MAIN_INPUT_SUBDIR)
message(STATUS
"Disabling HTML build for ${LATEX_TARGET_NAME}.tex because the main file is in subdirectory ${LATEX_MAIN_INPUT_SUBDIR}"
)
# The code below to run HTML assumes that LATEX_TARGET.tex is in the
# current directory. I have tried to specify that LATEX_TARGET.tex is
# in a subdirectory. That makes the build targets correct, but the
# HTML build still fails (at least for htlatex) because files are not
# generated where expected. I am getting around the problem by simply
# disabling HTML in this case. If someone really cares, they can fix
# this, but make sure it runs on many platforms and build programs.
elseif(HTLATEX_COMPILER)
# htlatex places the output in a different location
set(HTML_OUTPUT "${output_dir}/${LATEX_TARGET}.html")
add_custom_command(OUTPUT ${HTML_OUTPUT}
COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
${LATEX2HTML_CONVERTER} ${LATEX2HTML_CONVERTER_FLAGS} ${LATEX_MAIN_INPUT}
DEPENDS ${output_dir}/${LATEX_TARGET}.tex
${HTLATEX_COMPILER} ${LATEX_MAIN_INPUT}
"${HTLATEX_COMPILER_TEX4HT_FLAGS}"
"${HTLATEX_COMPILER_TEX4HT_POSTPROCESSOR_FLAGS}"
"${HTLATEX_COMPILER_T4HT_POSTPROCESSOR_FLAGS}"
${HTLATEX_COMPILER_ARGS}
DEPENDS
${output_dir}/${LATEX_TARGET}.tex
${output_dir}/${LATEX_TARGET}.dvi
VERBATIM
)
add_custom_target(${html_target}
DEPENDS ${HTML_OUTPUT} ${dvi_target}
SOURCES ${all_latex_sources}
)
add_custom_target(${html_target} DEPENDS ${HTML_OUTPUT} ${dvi_target})
if(NOT LATEX_EXCLUDE_FROM_DEFAULTS)
add_dependencies(html ${html_target})
endif()
......@@ -1576,6 +1900,11 @@ endfunction(add_latex_document)
if(LATEX_BUILD_COMMAND)
set(command_handled)
if("${LATEX_BUILD_COMMAND}" STREQUAL execute_latex)
latex_execute_latex()
set(command_handled TRUE)
endif()
if("${LATEX_BUILD_COMMAND}" STREQUAL makeglossaries)
latex_makeglossaries()
set(command_handled TRUE)
......@@ -1591,6 +1920,11 @@ if(LATEX_BUILD_COMMAND)
set(command_handled TRUE)
endif()
if("${LATEX_BUILD_COMMAND}" STREQUAL check_important_warnings)
latex_check_important_warnings()
set(command_handled TRUE)
endif()
if(NOT command_handled)
message(SEND_ERROR "Unknown command: ${LATEX_BUILD_COMMAND}")
endif()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment