Skip to content
Snippets Groups Projects
Commit bc8f6712 authored by Kenneth Moreland's avatar Kenneth Moreland
Browse files

Fix corner case when an argument name is a variable.

When parsing arguments, there is an IF statement that compares an
argument to an argument name (such as BIBFILES, IMAGES, etc.).
If there exists a variable with the same name, then the IF statement
will also try to dereference the variable and compare them.  Thus,
if that variable equaled one of the arguments, it would be incorrectly
identified as an argument name.

As an example, consider this CMake code.

set(BIBFILES mydoc.bib)
add_latex_document(mydoc.tex BIBFILES ${BIBFILES})

These arguments, obviously, expand to "mydoc.tex;BIBFILES;mydoc.bib".
When checking the argument mydoc.bib, you would expect it to be
considered an argument to BIBFILES.  However, deep in the call stack
there is an if statement that expands to

IF (BIBFILES STREQUAL mydoc.bib)

Clearly we mean these to be unequal.  But because BIBFILES is also
a variable containing mydoc.bib, CMake considers this to be true.
Thus, UseLATEX though mydoc.bib was the start of a list of bibliography
files rather than a bibliography file itself.

The problem is solved by prepending "non_a_var_" to each string we
are comparing.

IF (not_a_var_BIBFILES STREQUAL not_a_var_mydoc.bib)

This makes it highly unlikely that either side of this comparison
will be a variable that gets expanded.
parent 0a184ba2
No related branches found
No related tags found
No related merge requests found
# File: UseLATEX.cmake
# CMAKE commands to actually use the LaTeX compiler
# Version: 1.8.1
# Author: Kenneth Moreland (kmorel at sandia dot gov)
# Version: 1.8.2
# Author: Kenneth Moreland <kmorel@sandia.gov>
#
# Copyright 2004 Sandia Corporation.
# Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
......@@ -66,6 +66,11 @@
#
# History:
#
# 1.8.2 Fix corner case when an argument name was also a variable containing
# the text of an argument. In this case, the CMake IF was matching
# the argument text with the contents of the variable with the same
# argument name.
#
# 1.8.1 Fix problem where ps2pdf was not getting the appropriate arguments.
#
# 1.8.0 Add support for synctex.
......@@ -180,9 +185,9 @@ ENDMACRO(LATEX_CDR)
MACRO(LATEX_LIST_CONTAINS var value)
SET(${var})
FOREACH (value2 ${ARGN})
IF (${value} STREQUAL ${value2})
IF ("not_a_var_${value}" STREQUAL "not_a_var_${value2}")
SET(${var} TRUE)
ENDIF (${value} STREQUAL ${value2})
ENDIF ("not_a_var_${value}" STREQUAL "not_a_var_${value2}")
ENDFOREACH (value2)
ENDMACRO(LATEX_LIST_CONTAINS)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment