Merge topic 'cps-read-default-license'

1d4fb4afa9 find_package: Respect CPS default_license

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !10897
This commit is contained in:
Brad King
2025-06-23 13:37:22 +00:00
committed by Kitware Robot
9 changed files with 84 additions and 31 deletions
+15 -4
View File
@@ -479,6 +479,14 @@ std::unique_ptr<cmPackageInfoReader> cmPackageInfoReader::Read(
}
}
// Check for a default license.
Json::Value const& defaultLicense = reader->Data["default_license"];
if (!defaultLicense.isNull()) {
reader->DefaultLicense = defaultLicense.asString();
} else if (parent) {
reader->DefaultLicense = parent->DefaultLicense;
}
return reader;
}
@@ -582,12 +590,14 @@ void cmPackageInfoReader::SetImportProperty(cmTarget* target,
}
}
void cmPackageInfoReader::SetMetaProperty(cmTarget* target,
cm::string_view property,
Json::Value const& value) const
void cmPackageInfoReader::SetMetaProperty(
cmTarget* target, cm::string_view property, Json::Value const& value,
std::string const& defaultValue) const
{
if (!value.isNull()) {
target->SetProperty(property.data(), value.asString());
} else if (!defaultValue.empty()) {
target->SetProperty(property.data(), defaultValue);
}
}
@@ -671,7 +681,8 @@ void cmPackageInfoReader::SetTargetProperties(
// Add other information.
if (configuration.empty()) {
this->SetMetaProperty(target, "SPDX_LICENSE"_s, data["license"]);
this->SetMetaProperty(target, "SPDX_LICENSE"_s, data["license"],
this->DefaultLicense);
}
}
+3 -1
View File
@@ -98,7 +98,8 @@ private:
cm::string_view configuration,
Json::Value const& value) const;
void SetMetaProperty(cmTarget* target, cm::string_view property,
Json::Value const& value) const;
Json::Value const& value,
std::string const& defaultValue = {}) const;
std::string ResolvePath(std::string path) const;
@@ -108,4 +109,5 @@ private:
std::map<std::string, cmTarget*> ComponentTargets;
std::vector<std::string> DefaultConfigurations;
std::string DefaultLicense;
};