summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2013-02-06 13:32:15 +0100
committerStephen Kelly <steveire@gmail.com>2013-02-07 16:21:08 +0100
commit7c0ec75cfa6860b53036fe46c005b84277cdbc24 (patch)
tree830a43484968760685ca2eeb07a5777d91f87a5e
parent92e98dd909bd399f508ff7c2f9657095ddc766cc (diff)
downloadcmake-7c0ec75cfa6860b53036fe46c005b84277cdbc24.tar.gz
De-duplicate validation of genex target names.
-rw-r--r--Source/cmGeneratorExpression.cxx18
-rw-r--r--Source/cmGeneratorExpression.h2
-rw-r--r--Source/cmGeneratorExpressionEvaluator.cxx11
-rw-r--r--Source/cmTargetLinkLibrariesCommand.cxx7
4 files changed, 22 insertions, 16 deletions
diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx
index c9f784be4d..60bf179257 100644
--- a/Source/cmGeneratorExpression.cxx
+++ b/Source/cmGeneratorExpression.cxx
@@ -371,10 +371,20 @@ std::string::size_type cmGeneratorExpression::Find(const std::string &input)
{
const std::string::size_type openpos = input.find("$<");
if (openpos != std::string::npos
- && input.find(">", openpos) != std::string::npos)
- {
- return openpos;
- }
+ && input.find(">", openpos) != std::string::npos)
+ {
+ return openpos;
}
return std::string::npos;
}
+
+//----------------------------------------------------------------------------
+bool cmGeneratorExpression::IsValidTargetName(const std::string &input)
+{
+ cmsys::RegularExpression targetNameValidator;
+ // The ':' is supported to allow use with IMPORTED targets. At least
+ // Qt 4 and 5 IMPORTED targets use ':' as the namespace delimiter.
+ targetNameValidator.compile("^[A-Za-z0-9_.:-]+$");
+
+ return targetNameValidator.find(input.c_str());
+}
diff --git a/Source/cmGeneratorExpression.h b/Source/cmGeneratorExpression.h
index d487919e18..4eab2ddf7d 100644
--- a/Source/cmGeneratorExpression.h
+++ b/Source/cmGeneratorExpression.h
@@ -64,6 +64,8 @@ public:
static std::string::size_type Find(const std::string &input);
+ static bool IsValidTargetName(const std::string &input);
+
private:
cmGeneratorExpression(const cmGeneratorExpression &);
void operator=(const cmGeneratorExpression &);
diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx
index 5d94718832..4779b1153e 100644
--- a/Source/cmGeneratorExpressionEvaluator.cxx
+++ b/Source/cmGeneratorExpressionEvaluator.cxx
@@ -333,10 +333,6 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
"$<TARGET_PROPERTY:...> expression requires one or two parameters");
return std::string();
}
- cmsys::RegularExpression targetNameValidator;
- // The ':' is supported to allow use with IMPORTED targets. At least
- // Qt 4 and 5 IMPORTED targets use ':' as the namespace delimiter.
- targetNameValidator.compile("^[A-Za-z0-9_.:-]+$");
cmsys::RegularExpression propertyNameValidator;
propertyNameValidator.compile("^[A-Za-z0-9_]+$");
@@ -372,7 +368,7 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
std::string targetName = parameters.front();
propertyName = parameters[1];
- if (!targetNameValidator.find(targetName.c_str()))
+ if (!cmGeneratorExpression::IsValidTargetName(targetName))
{
if (!propertyNameValidator.find(propertyName.c_str()))
{
@@ -867,10 +863,7 @@ struct TargetFilesystemArtifact : public cmGeneratorExpressionNode
// Lookup the referenced target.
std::string name = *parameters.begin();
- cmsys::RegularExpression targetValidator;
- // The ':' is supported to allow use with IMPORTED targets.
- targetValidator.compile("^[A-Za-z0-9_.:-]+$");
- if (!targetValidator.find(name.c_str()))
+ if (!cmGeneratorExpression::IsValidTargetName(name))
{
::reportError(context, content->GetOriginalExpression(),
"Expression syntax not recognized.");
diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx
index fab3306cca..9dd0e5be27 100644
--- a/Source/cmTargetLinkLibrariesCommand.cxx
+++ b/Source/cmTargetLinkLibrariesCommand.cxx
@@ -11,6 +11,8 @@
============================================================================*/
#include "cmTargetLinkLibrariesCommand.h"
+#include "cmGeneratorExpression.h"
+
const char* cmTargetLinkLibrariesCommand::LinkLibraryTypeNames[3] =
{
"general",
@@ -271,9 +273,8 @@ cmTargetLinkLibrariesCommand::HandleLibrary(const char* lib,
{
const bool isGenex = cmGeneratorExpression::Find(lib) != std::string::npos;
- cmsys::RegularExpression targetNameValidator;
- targetNameValidator.compile("^[A-Za-z0-9_.:-]+$");
- const bool potentialTargetName = targetNameValidator.find(lib);
+ const bool potentialTargetName
+ = cmGeneratorExpression::IsValidTargetName(lib);
if (potentialTargetName || isGenex)
{