[CMake] IMPORTANT!! SET CACHE FORCE not wortking with UNINITIALIZED variables
Fernando Cacciola
fernando.cacciola at gmail.com
Tue Nov 11 08:47:20 EST 2008
Hi,
Since my last post about this got unnoticed I'm reposting it, this time
with additional information.
If you run cmake with a definition in the command-line, like so:
cmake -DVAR=123 .
in 2.6.2 that goes into the cache as an UNINITIALIZED variable:
VAR:UNINITIALIZED=123
And, since it is of UNINITIALIZED type, SET doesn't set the value
indicated even if FORCE is used.
That is, with the following script:
SET( VAR "321" CACHE STRING "" FORCE )
MESSAGE( STATUS "VAR=${VAR}" )
Calling
cmake -DVAR=123 .
prints
-- VAR=123
While calling
cmake -DVAR:STRING=123 .
prints
-- VAR=321
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.
IMO this is a bug, and I even wonder if that comparison didn't intend to
be != instead ??
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??
TIA
Fernando Cacciola
if
More information about the CMake
mailing list