[CMake] Weird behaviour of mark_as_advanced(), find_program() and the cache

Brad King brad.king at kitware.com
Wed Mar 3 08:33:55 EST 2010


Alexander Neundorf wrote:
> This sees the variable is already in the cache, but without meta info and adds 
> it using AddCacheDefinition().
> After this call, makefile->GetDefinition("FOO") returns an empty string,
> before this call it still returns "foo".

It's not the empty string in find_program()'s call to AddCacheDefinition
that raises this problem.  It's the bottom of cmMakefile's implementation
of the method:

  // if there was a definition then remove it
  this->Internal->VarStack.top().Set(name, 0);

> I didn't figure out the correct way how to improve this.

This is related to the open issue

  http://www.cmake.org/Bug/view.php?id=9008

discussed previously.

> I think it should end up in the cache as "foo" with the type "FILEPATH", but I 
> didn't figure out how to achieve this.

Issue #9008 basically means you should never mix cache and non-cache variables
with the same name.  There are all kinds of historical reasons behind their
interaction and changing anything will lead to subtle breakage for someone.
(The original attempt at CMP0015 for issue 9008 is evidence of this.)

The only safe way to combine cache and local variables of the same name
is to do *all* the cache stuff first, and then later override it locally.

-Brad


More information about the CMake mailing list