summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/cmGetPropertyCommand.cxx21
-rw-r--r--Source/cmGetPropertyCommand.h9
-rw-r--r--Source/cmSetPropertyCommand.cxx48
-rw-r--r--Source/cmSetPropertyCommand.h1
-rw-r--r--Source/cmSourceFile.cxx4
-rw-r--r--Source/cmTarget.cxx4
-rw-r--r--Source/cmTest.cxx4
-rw-r--r--Tests/Properties/CMakeLists.txt38
8 files changed, 100 insertions, 29 deletions
diff --git a/Source/cmGetPropertyCommand.cxx b/Source/cmGetPropertyCommand.cxx
index 830be0c..3d2140c 100644
--- a/Source/cmGetPropertyCommand.cxx
+++ b/Source/cmGetPropertyCommand.cxx
@@ -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");
}
diff --git a/Source/cmGetPropertyCommand.h b/Source/cmGetPropertyCommand.h
index 0df2371..d7503ba 100644
--- a/Source/cmGetPropertyCommand.h
+++ b/Source/cmGetPropertyCommand.h
@@ -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;
diff --git a/Source/cmSetPropertyCommand.cxx b/Source/cmSetPropertyCommand.cxx
index c1ed54b..21eeaf1 100644
--- a/Source/cmSetPropertyCommand.cxx
+++ b/Source/cmSetPropertyCommand.cxx
@@ -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;
diff --git a/Source/cmSetPropertyCommand.h b/Source/cmSetPropertyCommand.h
index a6d3966..8ef0b7c 100644
--- a/Source/cmSetPropertyCommand.h
+++ b/Source/cmSetPropertyCommand.h
@@ -92,6 +92,7 @@ private:
std::set<cmStdString> Names;
std::string PropertyName;
std::string PropertyValue;
+ bool Remove;
bool AppendMode;
// Implementation of each property type.
diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx
index a9eb668..1cc2b2c 100644
--- a/Source/cmSourceFile.cxx
+++ b/Source/cmSourceFile.cxx
@@ -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);
}
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index ee2930e..aa4c403 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -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);
diff --git a/Source/cmTest.cxx b/Source/cmTest.cxx
index 0a59fe0..2abebd8 100644
--- a/Source/cmTest.cxx
+++ b/Source/cmTest.cxx
@@ -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);
}
diff --git a/Tests/Properties/CMakeLists.txt b/Tests/Properties/CMakeLists.txt
index 546a96a..8cdd61b 100644
--- a/Tests/Properties/CMakeLists.txt
+++ b/Tests/Properties/CMakeLists.txt
@@ -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)