diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmFileSet.cxx | 10 | ||||
-rw-r--r-- | Source/cmFileSet.h | 2 | ||||
-rw-r--r-- | Source/cmTargetSourcesCommand.cxx | 7 |
3 files changed, 16 insertions, 3 deletions
diff --git a/Source/cmFileSet.cxx b/Source/cmFileSet.cxx index 08d56ba..2c06dc6 100644 --- a/Source/cmFileSet.cxx +++ b/Source/cmFileSet.cxx @@ -7,6 +7,8 @@ #include <utility> #include <vector> +#include "cmsys/RegularExpression.hxx" + #include "cmGeneratorExpression.h" #include "cmListFileCache.h" #include "cmLocalGenerator.h" @@ -149,3 +151,11 @@ void cmFileSet::EvaluateFileEntry( filesPerDir[relDir].push_back(file); } } + +bool cmFileSet::IsValidName(const std::string& name) +{ + static const cmsys::RegularExpression regex("^[a-z0-9][a-zA-Z0-9_]*$"); + + cmsys::RegularExpressionMatch match; + return regex.find(name.c_str(), match); +} diff --git a/Source/cmFileSet.h b/Source/cmFileSet.h index 5ee4a98..3aad75f 100644 --- a/Source/cmFileSet.h +++ b/Source/cmFileSet.h @@ -56,6 +56,8 @@ public: const cmGeneratorTarget* target, cmGeneratorExpressionDAGChecker* dagChecker = nullptr) const; + static bool IsValidName(const std::string& name); + private: std::string Name; std::string Type; diff --git a/Source/cmTargetSourcesCommand.cxx b/Source/cmTargetSourcesCommand.cxx index b425acb..954fbb5 100644 --- a/Source/cmTargetSourcesCommand.cxx +++ b/Source/cmTargetSourcesCommand.cxx @@ -215,9 +215,10 @@ bool TargetSourcesImpl::HandleFileSetMode( auto fileSet = this->Target->GetOrCreateFileSet(args.FileSet, type); if (fileSet.second) { if (!isDefault) { - if (args.FileSet[0] >= 'A' && args.FileSet[0] <= 'Z') { - this->SetError( - "Non-default file set name must not start with a capital letter"); + if (!cmFileSet::IsValidName(args.FileSet)) { + this->SetError("Non-default file set name must contain only letters, " + "numbers, and underscores, and must not start with a " + "capital letter or underscore"); return false; } } |