mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-19 19:43:23 +08:00
target_sources(): Enforce stricter requirements for FILE_SET name
Fixes: #23286
This commit is contained in:
@@ -91,7 +91,8 @@ Each ``target_sources(FILE_SET)`` entry starts with ``INTERFACE``, ``PUBLIC``, o
|
|||||||
``FILE_SET <set>``
|
``FILE_SET <set>``
|
||||||
|
|
||||||
A string representing the name of the file set to create or add to. This must
|
A string representing the name of the file set to create or add to. This must
|
||||||
not start with a capital letter, unless its name is ``HEADERS``.
|
contain only numbers, letters, and underscores, and must not start with a
|
||||||
|
capital letter or underscore, unless its name is ``HEADERS``.
|
||||||
|
|
||||||
``TYPE <type>``
|
``TYPE <type>``
|
||||||
|
|
||||||
|
@@ -7,6 +7,8 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "cmsys/RegularExpression.hxx"
|
||||||
|
|
||||||
#include "cmGeneratorExpression.h"
|
#include "cmGeneratorExpression.h"
|
||||||
#include "cmListFileCache.h"
|
#include "cmListFileCache.h"
|
||||||
#include "cmLocalGenerator.h"
|
#include "cmLocalGenerator.h"
|
||||||
@@ -149,3 +151,11 @@ void cmFileSet::EvaluateFileEntry(
|
|||||||
filesPerDir[relDir].push_back(file);
|
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);
|
||||||
|
}
|
||||||
|
@@ -56,6 +56,8 @@ public:
|
|||||||
const cmGeneratorTarget* target,
|
const cmGeneratorTarget* target,
|
||||||
cmGeneratorExpressionDAGChecker* dagChecker = nullptr) const;
|
cmGeneratorExpressionDAGChecker* dagChecker = nullptr) const;
|
||||||
|
|
||||||
|
static bool IsValidName(const std::string& name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string Name;
|
std::string Name;
|
||||||
std::string Type;
|
std::string Type;
|
||||||
|
@@ -215,9 +215,10 @@ bool TargetSourcesImpl::HandleFileSetMode(
|
|||||||
auto fileSet = this->Target->GetOrCreateFileSet(args.FileSet, type);
|
auto fileSet = this->Target->GetOrCreateFileSet(args.FileSet, type);
|
||||||
if (fileSet.second) {
|
if (fileSet.second) {
|
||||||
if (!isDefault) {
|
if (!isDefault) {
|
||||||
if (args.FileSet[0] >= 'A' && args.FileSet[0] <= 'Z') {
|
if (!cmFileSet::IsValidName(args.FileSet)) {
|
||||||
this->SetError(
|
this->SetError("Non-default file set name must contain only letters, "
|
||||||
"Non-default file set name must not start with a capital letter");
|
"numbers, and underscores, and must not start with a "
|
||||||
|
"capital letter or underscore");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
Tests/RunCMake/target_sources/FileSetBadName-result.txt
Normal file
1
Tests/RunCMake/target_sources/FileSetBadName-result.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
1
|
6
Tests/RunCMake/target_sources/FileSetBadName-stderr.txt
Normal file
6
Tests/RunCMake/target_sources/FileSetBadName-stderr.txt
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
^CMake Error at FileSetBadName\.cmake:[0-9]+ \(target_sources\):
|
||||||
|
target_sources Non-default file set name must contain only letters,
|
||||||
|
numbers, and underscores, and must not start with a capital letter or
|
||||||
|
underscore
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists\.txt:[0-9]+ \(include\)$
|
4
Tests/RunCMake/target_sources/FileSetBadName.cmake
Normal file
4
Tests/RunCMake/target_sources/FileSetBadName.cmake
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
enable_language(C)
|
||||||
|
|
||||||
|
add_library(lib1 STATIC empty.c)
|
||||||
|
target_sources(lib1 INTERFACE FILE_SET a+ TYPE HEADERS)
|
@@ -39,6 +39,7 @@ run_cmake(FileSetNoExistInterface)
|
|||||||
run_cmake(FileSetNoExistInstall)
|
run_cmake(FileSetNoExistInstall)
|
||||||
run_cmake(FileSetDirectories)
|
run_cmake(FileSetDirectories)
|
||||||
run_cmake(FileSetCustomTarget)
|
run_cmake(FileSetCustomTarget)
|
||||||
|
run_cmake(FileSetBadName)
|
||||||
|
|
||||||
set(RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0115=NEW)
|
set(RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0115=NEW)
|
||||||
run_cmake(FileSetFileNoExist)
|
run_cmake(FileSetFileNoExist)
|
||||||
|
Reference in New Issue
Block a user