ENH: support unset of properties

This commit is contained in:
Ken Martin 2008-04-01 14:22:09 -04:00
parent d00476610d
commit 16f1cc9b59
8 changed files with 100 additions and 29 deletions

View File

@ -94,6 +94,11 @@ bool cmGetPropertyCommand
doing = DoingNone;
this->InfoType = OutFullDoc;
}
else if(args[i] == "SET")
{
doing = DoingNone;
this->InfoType = OutSet;
}
else if(args[i] == "DEFINED")
{
doing = DoingNone;
@ -158,6 +163,20 @@ bool cmGetPropertyCommand
}
this->Makefile->AddDefinition(this->Variable.c_str(), output.c_str());
}
else if(this->InfoType == OutDefined)
{
// Lookup if the property is defined
const char *value;
if(this->Makefile->GetCMakeInstance()->
GetPropertyDefinition(this->PropertyName.c_str(), scope))
{
this->Makefile->AddDefinition(this->Variable.c_str(), "1");
}
else
{
this->Makefile->AddDefinition(this->Variable.c_str(), "0");
}
}
else
{
// Dispatch property getting.
@ -181,7 +200,7 @@ bool cmGetPropertyCommand
//----------------------------------------------------------------------------
bool cmGetPropertyCommand::StoreResult(const char* value)
{
if(this->InfoType == OutDefined)
if(this->InfoType == OutSet)
{
this->Makefile->AddDefinition(this->Variable.c_str(), value? "1":"0");
}

View File

@ -68,7 +68,7 @@ public:
" TEST <test> |\n"
" VARIABLE>\n"
" PROPERTY <name>\n"
" [DEFINED | BRIEF_DOCS | FULL_DOCS])\n"
" [SET | DEFINED | BRIEF_DOCS | FULL_DOCS])\n"
"Get one property from one object in a scope. "
"The first argument specifies the variable in which to store the "
"result. "
@ -85,8 +85,11 @@ public:
"The required PROPERTY option is immediately followed by the name "
"of the property to get. "
"If the property is not set an empty value is returned. "
"If the SET option is given the variable is set to a boolean "
"value indicating whether the property has been set."
"If the DEFINED option is given the variable is set to a boolean "
"value indicating whether the property has been set. "
"value indicating whether the property has been defined "
"such as with define_property. "
"If BRIEF_DOCS or FULL_DOCS is given then the variable is set to "
"a string containing documentation for the requested property. "
"If documentation is requested for a property that has not been "
@ -95,7 +98,7 @@ public:
cmTypeMacro(cmGetPropertyCommand, cmCommand);
private:
enum OutType { OutValue, OutDefined, OutBriefDoc, OutFullDoc };
enum OutType { OutValue, OutDefined, OutBriefDoc, OutFullDoc, OutSet };
std::string Variable;
std::string Name;
std::string PropertyName;

View File

@ -23,6 +23,7 @@
cmSetPropertyCommand::cmSetPropertyCommand()
{
this->AppendMode = false;
this->Remove = true;
}
//----------------------------------------------------------------------------
@ -96,6 +97,7 @@ bool cmSetPropertyCommand
this->PropertyValue += sep;
sep = ";";
this->PropertyValue += *arg;
this->Remove = false;
}
else
{
@ -141,13 +143,18 @@ bool cmSetPropertyCommand::HandleGlobalMode()
// Set or append the property.
cmake* cm = this->Makefile->GetCMakeInstance();
const char* name = this->PropertyName.c_str();
const char *value = this->PropertyValue.c_str();
if (this->Remove)
{
value = 0;
}
if(this->AppendMode)
{
cm->AppendProperty(name, this->PropertyValue.c_str());
cm->AppendProperty(name, value);
}
else
{
cm->SetProperty(name, this->PropertyValue.c_str());
cm->SetProperty(name, value);
}
return true;
@ -202,13 +209,18 @@ bool cmSetPropertyCommand::HandleDirectoryMode()
// Set or append the property.
const char* name = this->PropertyName.c_str();
const char *value = this->PropertyValue.c_str();
if (this->Remove)
{
value = 0;
}
if(this->AppendMode)
{
mf->AppendProperty(name, this->PropertyValue.c_str());
mf->AppendProperty(name, value);
}
else
{
mf->SetProperty(name, this->PropertyValue.c_str());
mf->SetProperty(name, value);
}
return true;
@ -245,13 +257,18 @@ bool cmSetPropertyCommand::HandleTarget(cmTarget* target)
{
// Set or append the property.
const char* name = this->PropertyName.c_str();
const char *value = this->PropertyValue.c_str();
if (this->Remove)
{
value = 0;
}
if(this->AppendMode)
{
target->AppendProperty(name, this->PropertyValue.c_str());
target->AppendProperty(name, value);
}
else
{
target->SetProperty(name, this->PropertyValue.c_str());
target->SetProperty(name, value);
}
return true;
@ -287,13 +304,19 @@ bool cmSetPropertyCommand::HandleSource(cmSourceFile* sf)
{
// Set or append the property.
const char* name = this->PropertyName.c_str();
const char *value = this->PropertyValue.c_str();
if (this->Remove)
{
value = 0;
}
if(this->AppendMode)
{
sf->AppendProperty(name, this->PropertyValue.c_str());
sf->AppendProperty(name, value);
}
else
{
sf->SetProperty(name, this->PropertyValue.c_str());
sf->SetProperty(name, value);
}
return true;
}
@ -343,13 +366,18 @@ bool cmSetPropertyCommand::HandleTest(cmTest* test)
{
// Set or append the property.
const char* name = this->PropertyName.c_str();
const char *value = this->PropertyValue.c_str();
if (this->Remove)
{
value = 0;
}
if(this->AppendMode)
{
test->AppendProperty(name, this->PropertyValue.c_str());
test->AppendProperty(name, value);
}
else
{
test->SetProperty(name, this->PropertyValue.c_str());
test->SetProperty(name, value);
}
return true;

View File

@ -92,6 +92,7 @@ private:
std::set<cmStdString> Names;
std::string PropertyName;
std::string PropertyValue;
bool Remove;
bool AppendMode;
// Implementation of each property type.

View File

@ -262,10 +262,6 @@ void cmSourceFile::SetProperty(const char* prop, const char* value)
{
return;
}
if (!value)
{
value = "NOTFOUND";
}
this->Properties.SetProperty(prop, value, cmProperty::SOURCE_FILE);
}

View File

@ -1591,10 +1591,6 @@ void cmTarget::SetProperty(const char* prop, const char* value)
{
return;
}
if (!value)
{
value = "NOTFOUND";
}
this->Properties.SetProperty(prop, value, cmProperty::TARGET);

View File

@ -76,10 +76,6 @@ void cmTest::SetProperty(const char* prop, const char* value)
{
return;
}
if (!value)
{
value = "NOTFOUND";
}
this->Properties.SetProperty(prop, value, cmProperty::TEST);
}

View File

@ -23,10 +23,23 @@ include_directories("${Properties_SOURCE_DIR}" "${Properties_BINARY_DIR}")
# test generic property interfaces
get_property(GLOBALRESULT GLOBAL PROPERTY GLOBALTEST DEFINED)
if (GLOBALRESULT)
message(SEND_ERROR "Error: global prop defined when it should not be, "
"result is GLOBALRESULT=${GLOBALRESULT}")
endif (GLOBALRESULT)
define_property(GLOBAL PROPERTY GLOBALTEST
BRIEF_DOCS "A test property"
FULL_DOCS "A long description of this test property"
)
get_property(GLOBALRESULT GLOBAL PROPERTY GLOBALTEST DEFINED)
if (NOT GLOBALRESULT)
message(SEND_ERROR "Error: global prop not defined "
"result is GLOBALRESULT=${GLOBALRESULT}")
endif (NOT GLOBALRESULT)
set_property(GLOBAL PROPERTY GLOBALTEST 1)
set_property(DIRECTORY PROPERTY DIRECTORYTEST 1)
set_property(SOURCE SubDir/properties3.cxx PROPERTY SOURCETEST 1)
@ -42,7 +55,8 @@ if (RESULT1 AND RESULT2 AND RESULT3 AND GLOBALRESULT AND
add_executable (Properties SubDir/properties3.cxx properties)
else (RESULT1 AND RESULT2 AND RESULT3 AND GLOBALRESULT AND
DIRECTORYRESULT AND SOURCERESULT)
message("Error: test results are RESULT1=${RESULT1} RESULT2=${RESULT2} "
message(SEND_ERROR
"Error: test results are RESULT1=${RESULT1} RESULT2=${RESULT2} "
"RESULT3=${RESULT3} GLOBALRESULT=${GLOBALRESULT} "
"DIRECTORYRESULT=${DIRECTORYRESULT} "
"SOURCERESULT=${SOURCERESULT}")
@ -53,15 +67,33 @@ endif (RESULT1 AND RESULT2 AND RESULT3 AND GLOBALRESULT AND
set_property(TARGET Properties PROPERTY TARGETTEST 1)
get_property(TARGETRESULT TARGET Properties PROPERTY TARGETTEST)
if (NOT TARGETRESULT)
message("Error: target result is TARGETRESULT=${TARGETRESULT}")
message(SEND_ERROR
"Error: target result is TARGETRESULT=${TARGETRESULT}")
endif (NOT TARGETRESULT)
# test get_property SET
get_property(TARGETRESULT TARGET Properties PROPERTY TARGETTEST SET)
if (NOT TARGETRESULT)
message(SEND_ERROR
"Error: target prop not set, result is TARGETRESULT=${TARGETRESULT}")
endif (NOT TARGETRESULT)
# test unsetting a property
set_property(TARGET Properties PROPERTY TARGETTEST)
get_property(TARGETRESULT TARGET Properties PROPERTY TARGETTEST SET)
if (TARGETRESULT)
message(SEND_ERROR "Error: target prop not unset, "
"result is TARGETRESULT=${TARGETRESULT}")
endif (TARGETRESULT)
# test the target SOURCES property
get_property(Properties_SOURCES TARGET Properties PROPERTY SOURCES)
set_source_files_properties(${Properties_SOURCES} PROPERTIES TEST4 1)
get_source_file_property(RESULT4 properties.h TEST4)
if(NOT RESULT4)
message("Error: target result is"
message(SEND_ERROR "Error: target result is"
" RESULT4=${RESULT4}"
" Properties_SOURCES=[${Properties_SOURCES}]")
endif(NOT RESULT4)