From 0a0672c01f784e67a0de9de0a8633c0c16bf7749 Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Mon, 21 Apr 2008 16:57:11 -0400 Subject: [PATCH] ENH: fix list command with empty elements --- Source/cmListCommand.cxx | 58 ++++++++++++++++++++++++++++++++++++++-- Source/cmPolicies.cxx | 12 +++++++++ Source/cmPolicies.h | 1 + 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx index 4b8fa0a77c..9d71860dd6 100644 --- a/Source/cmListCommand.cxx +++ b/Source/cmListCommand.cxx @@ -103,8 +103,62 @@ bool cmListCommand::GetList(std::vector& 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::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 4e1b857d92..64caf25f8f 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 fed9d3194a..1085d4c6dd 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.