[CMake] IMPORTANT!! SET CACHE FORCE not wortking with UNINITIALIZED variables

Eric NOULARD eric.noulard at gmail.com
Tue Nov 11 09:19:58 EST 2008


Le Tue, 11 Nov 2008 11:47:20 -0200,
Fernando Cacciola <fernando.cacciola at gmail.com> a écrit :
> Hi,
> 
> Since my last post about this got unnoticed I'm reposting it, this
> time with additional information.
> 

[...]
May be CMake devel are busy :-)

> The culprint is in the following section of the cmake sources:
> 
> 
> void cmMakefile::AddCacheDefinition(const char* name, const char*
> value, const char* doc,
>                                      cmCacheManager::CacheEntryType
> type) {
>    const char* val = value;
>    cmCacheManager::CacheIterator it =
>      this->GetCacheManager()->GetCacheIterator(name);
>    if(!it.IsAtEnd() && (it.GetType() ==
> cmCacheManager::UNINITIALIZED) &&
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
>       it.Initialized())
>      {
> 
>      val = it.GetValue();
>      ^^^^^^^^^^^^^^^^^^^^
> 
> 
> As you can see, when SET sees an UNINITIALIZED variable it just
> ignores the value being passed on and just keeps the previous value.

After some CVS history browsing, the code is there at least since
CMake 2.4.4 (may be older).
 
> IMO this is a bug, and I even wonder if that comparison didn't intend
> to be != instead  ??

The bug, if ever this is one should be elsewhere.

> Fortunately, the variable is nevertheless overwritten into the cache, 
> with the old (wrong) value but the correct type, hence, the following 
> works around the bug:
> 
> 
> SET( VAR "321" CACHE STRING "" FORCE )
> SET( VAR "321" CACHE STRING "" FORCE )
> MESSAGE( STATUS "VAR=${VAR}" )
> 
> That is, the first SET "fixes" the type, allowing the second SET to
> do what it should.
>  
> Shall I add this to the tracker or is this behaviour on purpose??

I would say that this deserve a bug report at least in order to add
some documentation about the current behavior.

Nevertheless CMake 2.6.2 documentation (cmake --help) says:

-D <var>:<type>=<value>     = Create a cmake cache entry.

and cmake --help-command SET says:

If CACHE is present, then the <variable> is put in the cache.
  <type> and <docstring> are then ***required***.

Does this mean that in order to have a proper CACHE entry one MUST
specify <type>. Or more generally what is the purpose of

UNINITIALIZED cache entry.

I'm afraid we'll have to wait peacefully for CMake 
developper spare time in order to have technical answer for this :=)

-- 
Erk


More information about the CMake mailing list