summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBill Hoffman <bill.hoffman@kitware.com>2008-04-21 20:57:11 (GMT)
committerBill Hoffman <bill.hoffman@kitware.com>2008-04-21 20:57:11 (GMT)
commit0a0672c01f784e67a0de9de0a8633c0c16bf7749 (patch)
treea614c6eaf1c80c5baa5a58e249bed49b9d8db83c /Source
parentaa10b4e33cd4a0c304f3cd3ffd5f0f382a6b6178 (diff)
downloadCMake-0a0672c01f784e67a0de9de0a8633c0c16bf7749.zip
CMake-0a0672c01f784e67a0de9de0a8633c0c16bf7749.tar.gz
CMake-0a0672c01f784e67a0de9de0a8633c0c16bf7749.tar.bz2
ENH: fix list command with empty elements
Diffstat (limited to 'Source')
-rw-r--r--Source/cmListCommand.cxx58
-rw-r--r--Source/cmPolicies.cxx12
-rw-r--r--Source/cmPolicies.h1
3 files changed, 69 insertions, 2 deletions
diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx
index 4b8fa0a..9d71860 100644
--- a/Source/cmListCommand.cxx
+++ b/Source/cmListCommand.cxx
@@ -103,8 +103,62 @@ bool cmListCommand::GetList(std::vector<std::string>& list, const char* var)
{
return false;
}
- // expand the variable
- cmSystemTools::ExpandListArgument(listString, list);
+ // expand the variable into a list
+ cmSystemTools::ExpandListArgument(listString, list, true);
+ // check the list for empty values
+ bool hasEmpty = false;
+ for(std::vector<std::string>::iterator i = list.begin();
+ i != list.end(); ++i)
+ {
+ if(i->size() == 0)
+ {
+ hasEmpty = true;
+ break;
+ }
+ }
+ // if no empty elements then just return
+ if(!hasEmpty)
+ {
+ return true;
+ }
+ // if we have empty elements we need to check policy CMP0007
+ switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0007))
+ {
+ case cmPolicies::WARN:
+ {
+ // Default is to warn and use old behavior
+ // OLD behavior is to allow compatibility, so recall
+ // ExpandListArgument without the true which will remove
+ // empty values
+ list.clear();
+ cmSystemTools::ExpandListArgument(listString, list);
+ std::string warn = this->Makefile->GetPolicies()->
+ GetPolicyWarning(cmPolicies::CMP0007);
+ warn += " List has value = [";
+ warn += listString;
+ warn += "].";
+ this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
+ warn);
+ return true;
+ }
+ case cmPolicies::OLD:
+ // OLD behavior is to allow compatibility, so recall
+ // ExpandListArgument without the true which will remove
+ // empty values
+ list.clear();
+ cmSystemTools::ExpandListArgument(listString, list);
+ return true;
+ case cmPolicies::NEW:
+ return true;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ this->Makefile->IssueMessage(
+ cmake::FATAL_ERROR,
+ this->Makefile->GetPolicies()
+ ->GetRequiredPolicyError(cmPolicies::CMP0007)
+ );
+ return false;
+ }
return true;
}
diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx
index 4e1b857..64caf25 100644
--- a/Source/cmPolicies.cxx
+++ b/Source/cmPolicies.cxx
@@ -269,6 +269,18 @@ cmPolicies::cmPolicies()
"The NEW behavior for this policy is to produce an error if a bundle "
"target is installed without a BUNDLE DESTINATION.",
2,6,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0007, "CMP0007",
+ "list command no longer ignores empty elements.",
+ "This policy determines whether the list command will "
+ "ignore empty elements in the list. "
+ "CMake 2.4 and below list commands ignored all empty elements"
+ " in the list. For example, a;b;;c would have length 3 and not 4. "
+ "The OLD behavior for this policy is to ignore empty list elements. "
+ "The NEW behavior for this policy is to correctly count empty "
+ "elements in a list. ",
+ 2,6,0, cmPolicies::WARN);
}
cmPolicies::~cmPolicies()
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
index fed9d31..1085d4c 100644
--- a/Source/cmPolicies.h
+++ b/Source/cmPolicies.h
@@ -47,6 +47,7 @@ public:
CMP0004, // Libraries linked may not have leading or trailing whitespace
CMP0005, // Definition value escaping
CMP0006, // BUNDLE install rules needed for MACOSX_BUNDLE targets
+ CMP0007, // list command handling of empty elements
// Always the last entry. Useful mostly to avoid adding a comma
// the last policy when adding a new one.