<div class="gmail_quote">On Sun, May 10, 2009 at 5:08 PM, Alexander Neundorf <span dir="ltr"><<a href="mailto:a.neundorf-work@gmx.net" target="_blank">a.neundorf-work@gmx.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
The attached patch (against current cvs HEAD) changes the behaviour of set(<br>
CACHE) and option() slightly.<br>
<br>
Until now it behaves like this:<br>
if a variable FOO is set to a value, and then set FOO to a value in the CACHE,<br>
and FOO was not yet in the cache, then afterwards the visible value of FOO is<br>
the one specified in the set( CACHE) command.<br>
<br>
Now assume the same, but FOO is already in the cache. In this case after the<br>
set() and the set(CACHE) the value in the cache won't have changed (which is<br>
good), but also the value from the cache will not be visible, but instead FOO<br>
will have the value from the set(), i.e. the value in the cache doesn't<br>
matter at all, even although the set(CACHE) was after the set().<br>
<br>
<br>
You can test this with the following CMakeLists.txt:<br>
<br>
set(FOO foo)<br>
message(STATUS "FOO 1: ${FOO}")<br>
set(FOO bar CACHE STRING "fofofofof")<br>
message(STATUS "FOO 2: ${FOO}")<br>
<br>
set(OPT abc)<br>
message(STATUS "OPT 1: ${OPT}")<br>
option(OPT "daf df df sdf " ON)<br>
message(STATUS "OPT 2: ${OPT}")<br>
<br>
Current cvs HEAD gives:<br>
<br>
$ cmake .<br>
-- FOO 1: foo<br>
-- FOO 2: bar<br>
-- OPT 1: abc<br>
-- OPT 2: ON<br>
$ cmake .<br>
-- FOO 1: foo<br>
-- FOO 2: foo<br>
-- OPT 1: abc<br>
-- OPT 2: abc<br>
<br>
With the patch you get:<br>
$ cmake .<br>
-- FOO 1: foo<br>
-- FOO 2: bar<br>
-- OPT 1: abc<br>
-- OPT 2: ON<br>
$ cmake .<br>
-- FOO 1: foo<br>
-- FOO 2: bar<br>
-- OPT 1: abc<br>
-- OPT 2: ON<br></blockquote><div><br>I would have expected CMake to behave like this:<br> <br>$ cmake .<br>
-- FOO 1: foo<br>
-- FOO 2: foo<br>
-- OPT 1: abc<br>
-- OPT 2: abc<br>
$ cmake .<br>
-- FOO 1: foo<br>
-- FOO 2: foo<br>
-- OPT 1: abc<br>
-- OPT 2: abc<br><br>1. In CMake right now is "local overrides cache, unless a cache variable is being created during a particular configure"<br>2. Alex's patch looks like "cache overrides local once set(..CACHE) or option() is encountered"<br>
3. My expectation of what CMake should have done is based on "local overrides cache, always"<br><br>Basically what it boils down to is do we:<br>1. Remove local variables only when set(.. CACHE) or option() is run the first time (while creating a cache var)<br>
2. Remove local variables once set(..CACHE) or option() is encountered<br>3. Never remove local variables<br><br>The patch for the 3rd behavior is below. Personally, I prefer it to the 2nd (which could be slightly confusing depending on when the user evaluates the variable) although either is preferable in my mind to the 1st (which changes behavior depending on how many times you configure the build!)<br>
<br>Index: Source/cmMakefile.cxx<br>===================================================================<br>RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.cxx,v<br>retrieving revision 1.508<br>diff -u -b -B -u -r1.508 cmMakefile.cxx<br>
--- Source/cmMakefile.cxx 24 Apr 2009 15:18:05 -0000 1.508<br>+++ Source/cmMakefile.cxx 11 May 2009 02:59:42 -0000<br>@@ -1702,8 +1702,6 @@<br> <br> }<br> this->GetCacheManager()->AddCacheEntry(name, val, doc, type);<br>
- // if there was a definition then remove it<br>- this->DefinitionStack.back().erase( DefinitionMap::key_type(name));<br> }<br> <br> <br>@@ -1747,7 +1745,6 @@<br> val = it.GetValueAsBool();<br> }<br> this->GetCacheManager()->AddCacheEntry(name, val, doc);<br>
- this->AddDefinition(name, val);<br> }<br> <br> void cmMakefile::RemoveDefinition(const char* name)<br><br></div></div><br>-- <br>Philip Lowman<br>