summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2022-04-05 19:46:24 (GMT)
committerBen Boeckel <ben.boeckel@kitware.com>2022-04-25 18:29:17 (GMT)
commitd74f9599f6089e30f9bd175d00e5510f378ec935 (patch)
treecf09ce145a6217a8ac0665ed00f08693b1de9cc1
parent5da4fe30a994208bb188c347ac9d0e394498dcc2 (diff)
downloadCMake-d74f9599f6089e30f9bd175d00e5510f378ec935.zip
CMake-d74f9599f6089e30f9bd175d00e5510f378ec935.tar.gz
CMake-d74f9599f6089e30f9bd175d00e5510f378ec935.tar.bz2
cmTarget: require filesets to be of the right type
With new types being proposed for C++ modules, requiring filesets to be of the right type is now pertinent. No tests can be added yet as only `HEADERS` is supported right now.
-rw-r--r--Source/cmTarget.cxx95
1 files changed, 61 insertions, 34 deletions
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index fc4d9f4..a3746ab 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -220,16 +220,17 @@ public:
template <typename ValueType>
void AddDirectoryToFileSet(cmTarget* self, std::string const& fileSetName,
- ValueType value, cm::string_view description,
- bool clear);
+ ValueType value, cm::string_view fileSetType,
+ cm::string_view description, bool clear);
template <typename ValueType>
void AddPathToFileSet(cmTarget* self, std::string const& fileSetName,
- ValueType value, cm::string_view description,
- bool clear);
+ ValueType value, cm::string_view fileSetType,
+ cm::string_view description, bool clear);
cmValue GetFileSetDirectories(cmTarget const* self,
- std::string const& fileSetName) const;
- cmValue GetFileSetPaths(cmTarget const* self,
- std::string const& fileSetName) const;
+ std::string const& fileSetName,
+ cm::string_view fileSetType) const;
+ cmValue GetFileSetPaths(cmTarget const* self, std::string const& fileSetName,
+ cm::string_view fileSetType) const;
};
namespace {
@@ -1443,10 +1444,10 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value)
this->impl->LanguageStandardProperties.erase(prop);
}
} else if (prop == propHEADER_DIRS) {
- this->impl->AddDirectoryToFileSet(this, "HEADERS", value,
+ this->impl->AddDirectoryToFileSet(this, "HEADERS", value, "HEADERS"_s,
"The default header set"_s, true);
} else if (prop == propHEADER_SET) {
- this->impl->AddPathToFileSet(this, "HEADERS", value,
+ this->impl->AddPathToFileSet(this, "HEADERS", value, "HEADERS"_s,
"The default header set"_s, true);
} else if (cmHasLiteralPrefix(prop, "HEADER_DIRS_")) {
auto fileSetName = prop.substr(cmStrLen("HEADER_DIRS_"));
@@ -1456,8 +1457,8 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value)
return;
}
this->impl->AddDirectoryToFileSet(
- this, fileSetName, value, cmStrCat("Header set \"", fileSetName, "\""),
- true);
+ this, fileSetName, value, "HEADERS"_s,
+ cmStrCat("Header set \"", fileSetName, "\""), true);
} else if (cmHasLiteralPrefix(prop, "HEADER_SET_")) {
auto fileSetName = prop.substr(cmStrLen("HEADER_SET_"));
if (fileSetName.empty()) {
@@ -1465,7 +1466,7 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value)
"Header set name cannot be empty.");
return;
}
- this->impl->AddPathToFileSet(this, fileSetName, value,
+ this->impl->AddPathToFileSet(this, fileSetName, value, "HEADERS"_s,
cmStrCat("Header set \"", fileSetName, "\""),
true);
} else if (prop == propHEADER_SETS) {
@@ -1588,7 +1589,7 @@ void cmTarget::AppendProperty(const std::string& prop,
this->impl->Makefile->IssueMessage(
MessageType::FATAL_ERROR, prop + " property may not be appended.");
} else if (prop == "HEADER_DIRS") {
- this->impl->AddDirectoryToFileSet(this, "HEADERS", value,
+ this->impl->AddDirectoryToFileSet(this, "HEADERS", value, "HEADERS"_s,
"The default header set"_s, false);
} else if (cmHasLiteralPrefix(prop, "HEADER_DIRS_")) {
auto fileSetName = prop.substr(cmStrLen("HEADER_DIRS_"));
@@ -1598,10 +1599,10 @@ void cmTarget::AppendProperty(const std::string& prop,
return;
}
this->impl->AddDirectoryToFileSet(
- this, fileSetName, value, cmStrCat("Header set \"", fileSetName, "\""),
- false);
+ this, fileSetName, value, "HEADERS"_s,
+ cmStrCat("Header set \"", fileSetName, "\""), false);
} else if (prop == "HEADER_SET") {
- this->impl->AddPathToFileSet(this, "HEADERS", value,
+ this->impl->AddPathToFileSet(this, "HEADERS", value, "HEADERS"_s,
"The default header set"_s, false);
} else if (cmHasLiteralPrefix(prop, "HEADER_SET_")) {
auto fileSetName = prop.substr(cmStrLen("HEADER_SET_"));
@@ -1610,7 +1611,7 @@ void cmTarget::AppendProperty(const std::string& prop,
"Header set name cannot be empty.");
return;
}
- this->impl->AddPathToFileSet(this, fileSetName, value,
+ this->impl->AddPathToFileSet(this, fileSetName, value, "HEADERS"_s,
cmStrCat("Header set \"", fileSetName, "\""),
false);
} else if (prop == "HEADER_SETS") {
@@ -1637,11 +1638,9 @@ void cmTarget::SetProperty(const std::string& prop, cmValue value)
}
template <typename ValueType>
-void cmTargetInternals::AddDirectoryToFileSet(cmTarget* self,
- std::string const& fileSetName,
- ValueType value,
- cm::string_view description,
- bool clear)
+void cmTargetInternals::AddDirectoryToFileSet(
+ cmTarget* self, std::string const& fileSetName, ValueType value,
+ cm::string_view fileSetType, cm::string_view description, bool clear)
{
auto* fileSet = self->GetFileSet(fileSetName);
if (!fileSet) {
@@ -1650,6 +1649,13 @@ void cmTargetInternals::AddDirectoryToFileSet(cmTarget* self,
cmStrCat(description, "has not yet been created."));
return;
}
+ if (fileSet->GetType() != fileSetType) {
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
+ cmStrCat("File set \"", fileSetName,
+ "\" is not of type \"", fileSetType,
+ "\"."));
+ return;
+ }
if (clear) {
fileSet->ClearDirectoryEntries();
}
@@ -1660,11 +1666,9 @@ void cmTargetInternals::AddDirectoryToFileSet(cmTarget* self,
}
template <typename ValueType>
-void cmTargetInternals::AddPathToFileSet(cmTarget* self,
- std::string const& fileSetName,
- ValueType value,
- cm::string_view description,
- bool clear)
+void cmTargetInternals::AddPathToFileSet(
+ cmTarget* self, std::string const& fileSetName, ValueType value,
+ cm::string_view fileSetType, cm::string_view description, bool clear)
{
auto* fileSet = self->GetFileSet(fileSetName);
if (!fileSet) {
@@ -1673,6 +1677,13 @@ void cmTargetInternals::AddPathToFileSet(cmTarget* self,
cmStrCat(description, "has not yet been created."));
return;
}
+ if (fileSet->GetType() != fileSetType) {
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
+ cmStrCat("File set \"", fileSetName,
+ "\" is not of type \"", fileSetType,
+ "\"."));
+ return;
+ }
if (clear) {
fileSet->ClearFileEntries();
}
@@ -1683,24 +1694,40 @@ void cmTargetInternals::AddPathToFileSet(cmTarget* self,
}
cmValue cmTargetInternals::GetFileSetDirectories(
- cmTarget const* self, std::string const& fileSetName) const
+ cmTarget const* self, std::string const& fileSetName,
+ cm::string_view fileSetType) const
{
auto const* fileSet = self->GetFileSet(fileSetName);
if (!fileSet) {
return nullptr;
}
+ if (fileSet->GetType() != fileSetType) {
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
+ cmStrCat("File set \"", fileSetName,
+ "\" is not of type \"", fileSetType,
+ "\"."));
+ return nullptr;
+ }
static std::string output;
output = cmJoin(fileSet->GetDirectoryEntries(), ";"_s);
return cmValue(output);
}
-cmValue cmTargetInternals::GetFileSetPaths(
- cmTarget const* self, std::string const& fileSetName) const
+cmValue cmTargetInternals::GetFileSetPaths(cmTarget const* self,
+ std::string const& fileSetName,
+ cm::string_view fileSetType) const
{
auto const* fileSet = self->GetFileSet(fileSetName);
if (!fileSet) {
return nullptr;
}
+ if (fileSet->GetType() != fileSetType) {
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
+ cmStrCat("File set \"", fileSetName,
+ "\" is not of type \"", fileSetType,
+ "\"."));
+ return nullptr;
+ }
static std::string output;
output = cmJoin(fileSet->GetFileEntries(), ";"_s);
return cmValue(output);
@@ -2098,10 +2125,10 @@ cmValue cmTarget::GetProperty(const std::string& prop) const
.GetCurrentSource());
}
if (prop == propHEADER_DIRS) {
- return this->impl->GetFileSetDirectories(this, "HEADERS");
+ return this->impl->GetFileSetDirectories(this, "HEADERS", "HEADERS"_s);
}
if (prop == propHEADER_SET) {
- return this->impl->GetFileSetPaths(this, "HEADERS");
+ return this->impl->GetFileSetPaths(this, "HEADERS", "HEADERS"_s);
}
if (prop == propHEADER_SETS) {
std::vector<std::string> set_names;
@@ -2132,14 +2159,14 @@ cmValue cmTarget::GetProperty(const std::string& prop) const
if (fileSetName.empty()) {
return nullptr;
}
- return this->impl->GetFileSetDirectories(this, fileSetName);
+ return this->impl->GetFileSetDirectories(this, fileSetName, "HEADERS"_s);
}
if (cmHasLiteralPrefix(prop, "HEADER_SET_")) {
std::string fileSetName = prop.substr(cmStrLen("HEADER_SET_"));
if (fileSetName.empty()) {
return nullptr;
}
- return this->impl->GetFileSetPaths(this, fileSetName);
+ return this->impl->GetFileSetPaths(this, fileSetName, "HEADERS"_s);
}
cmValue retVal = this->impl->Properties.GetPropertyValue(prop);