mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-25 00:59:19 -06:00
Merge topic 'cps-more-metadata'
da97747dacCPS: Support additional metadataf224e131a5CPS: Refactor metadata handling7155903e53cmExportPackageInfoGenerator: Fix style Acked-by: Kitware Robot <kwrobot@kitware.com> Tested-by: buildbot <buildbot@kitware.com> Merge-request: !10856
This commit is contained in:
@@ -140,7 +140,9 @@ Exporting Targets to the |CPS|
|
||||
[COMPAT_VERSION <version>]
|
||||
[VERSION_SCHEMA <string>]]
|
||||
[DEFAULT_TARGETS <target>...]
|
||||
[DEFAULT_CONFIGURATIONS <config>...])
|
||||
[DEFAULT_CONFIGURATIONS <config>...]
|
||||
[DESCRIPTION <project-description-string>]
|
||||
[HOMEPAGE_URL <url-string>])
|
||||
|
||||
.. versionadded:: 4.1
|
||||
.. note::
|
||||
|
||||
@@ -1001,6 +1001,8 @@ Signatures
|
||||
[VERSION_SCHEMA <string>]]
|
||||
[DEFAULT_TARGETS <target>...]
|
||||
[DEFAULT_CONFIGURATIONS <config>...]
|
||||
[DESCRIPTION <project-description-string>]
|
||||
[HOMEPAGE_URL <url-string>]
|
||||
[PERMISSIONS <permission>...]
|
||||
[CONFIGURATIONS <config>...]
|
||||
[COMPONENT <component>]
|
||||
@@ -1057,6 +1059,17 @@ Signatures
|
||||
configurations exists. If not specified, CMake will fall back to the
|
||||
package's available configurations in an unspecified order.
|
||||
|
||||
``DESCRIPTION <project-description-string>``
|
||||
.. versionadded:: 4.1
|
||||
|
||||
An informational description of the project. It is recommended that this
|
||||
description is a relatively short string, usually no more than a few words.
|
||||
|
||||
``HOMEPAGE_URL <url-string>``
|
||||
.. versionadded:: 4.1
|
||||
|
||||
An informational canonical home URL for the project.
|
||||
|
||||
By default, if the specified ``<package-name>`` matches the current CMake
|
||||
:variable:`PROJECT_NAME`, package metadata will be inherited from the
|
||||
project. The ``PROJECT <project-name>`` option may be used to specify a
|
||||
|
||||
@@ -37,6 +37,8 @@ cmExportPackageInfoGenerator::cmExportPackageInfoGenerator(
|
||||
, PackageVersion(std::move(arguments.Version))
|
||||
, PackageVersionCompat(std::move(arguments.VersionCompat))
|
||||
, PackageVersionSchema(std::move(arguments.VersionSchema))
|
||||
, PackageDescription(std::move(arguments.Description))
|
||||
, PackageWebsite(std::move(arguments.Website))
|
||||
, DefaultTargets(std::move(arguments.DefaultTargets))
|
||||
, DefaultConfigurations(std::move(arguments.DefaultConfigs))
|
||||
{
|
||||
@@ -63,8 +65,18 @@ void cmExportPackageInfoGenerator::WritePackageInfo(
|
||||
}
|
||||
|
||||
namespace {
|
||||
bool SetProperty(Json::Value& object, std::string const& property,
|
||||
std::string const& value)
|
||||
{
|
||||
if (!value.empty()) {
|
||||
object[property] = value;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void buildArray(Json::Value& object, std::string const& property,
|
||||
void BuildArray(Json::Value& object, std::string const& property,
|
||||
T const& values)
|
||||
{
|
||||
if (!values.empty()) {
|
||||
@@ -105,20 +117,17 @@ Json::Value cmExportPackageInfoGenerator::GeneratePackageInfo() const
|
||||
package["name"] = this->GetPackageName();
|
||||
package["cps_version"] = std::string(kCPS_VERSION_STR);
|
||||
|
||||
if (!this->PackageVersion.empty()) {
|
||||
package["version"] = this->PackageVersion;
|
||||
if (!this->PackageVersionCompat.empty()) {
|
||||
package["compat_version"] = this->PackageVersionCompat;
|
||||
}
|
||||
if (!this->PackageVersionSchema.empty()) {
|
||||
package["version_schema"] = this->PackageVersionSchema;
|
||||
}
|
||||
if (SetProperty(package, "version", this->PackageVersion)) {
|
||||
SetProperty(package, "compat_version", this->PackageVersionCompat);
|
||||
SetProperty(package, "version_schema", this->PackageVersionSchema);
|
||||
}
|
||||
|
||||
buildArray(package, "default_components", this->DefaultTargets);
|
||||
buildArray(package, "configurations", this->DefaultConfigurations);
|
||||
BuildArray(package, "default_components", this->DefaultTargets);
|
||||
BuildArray(package, "configurations", this->DefaultConfigurations);
|
||||
|
||||
// TODO: description, website, license
|
||||
SetProperty(package, "description", this->PackageDescription);
|
||||
SetProperty(package, "website", this->PackageWebsite);
|
||||
// TODO: license
|
||||
|
||||
return package;
|
||||
}
|
||||
@@ -382,9 +391,9 @@ void cmExportPackageInfoGenerator::GenerateInterfaceLinkProperties(
|
||||
addLibraries(allowList["LINK_ONLY"], linkRequires);
|
||||
addLibraries(cmList{ interfaceLinkLibraries }, buildRequires);
|
||||
|
||||
buildArray(component, "requires", buildRequires);
|
||||
buildArray(component, "link_requires", linkRequires);
|
||||
buildArray(component, "link_libraries", linkLibraries);
|
||||
BuildArray(component, "requires", buildRequires);
|
||||
BuildArray(component, "link_requires", linkRequires);
|
||||
BuildArray(component, "link_libraries", linkLibraries);
|
||||
}
|
||||
|
||||
void cmExportPackageInfoGenerator::GenerateInterfaceCompileFeatures(
|
||||
@@ -412,7 +421,7 @@ void cmExportPackageInfoGenerator::GenerateInterfaceCompileFeatures(
|
||||
}
|
||||
}
|
||||
|
||||
buildArray(component, "compile_features", features);
|
||||
BuildArray(component, "compile_features", features);
|
||||
}
|
||||
|
||||
void cmExportPackageInfoGenerator::GenerateInterfaceCompileDefines(
|
||||
@@ -512,7 +521,7 @@ Json::Value cmExportPackageInfoGenerator::GenerateInterfaceConfigProperties(
|
||||
languages.emplace_back(std::move(ll));
|
||||
}
|
||||
}
|
||||
buildArray(component, "link_languages", languages);
|
||||
BuildArray(component, "link_languages", languages);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,8 @@ private:
|
||||
std::string const PackageVersion;
|
||||
std::string const PackageVersionCompat;
|
||||
std::string const PackageVersionSchema;
|
||||
std::string const PackageDescription;
|
||||
std::string const PackageWebsite;
|
||||
std::vector<std::string> DefaultTargets;
|
||||
std::vector<std::string> DefaultConfigurations;
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include <cm/string_view>
|
||||
|
||||
#include "cmExecutionStatus.h"
|
||||
#include "cmGeneratorExpression.h"
|
||||
#include "cmMakefile.h"
|
||||
@@ -118,17 +120,28 @@ bool cmPackageInfoArguments::SetMetadataFromProject(cmExecutionStatus& status)
|
||||
}
|
||||
|
||||
cmMakefile& mf = status.GetMakefile();
|
||||
if (this->Version.empty()) {
|
||||
cmValue const& version =
|
||||
mf.GetDefinition(cmStrCat(this->ProjectName, "_VERSION"_s));
|
||||
if (version) {
|
||||
this->Version = version;
|
||||
cmValue const& compatVersion =
|
||||
mf.GetDefinition(cmStrCat(this->ProjectName, "_COMPAT_VERSION"_s));
|
||||
if (compatVersion) {
|
||||
this->VersionCompat = compatVersion;
|
||||
}
|
||||
auto mapProjectValue = [&](std::string& arg, cm::string_view suffix) {
|
||||
cmValue const& projectValue =
|
||||
mf.GetDefinition(cmStrCat(this->ProjectName, '_', suffix));
|
||||
if (projectValue) {
|
||||
arg = *projectValue;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
if (this->Version.empty()) {
|
||||
if (mapProjectValue(this->Version, "VERSION"_s)) {
|
||||
mapProjectValue(this->VersionCompat, "COMPAT_VERSION"_s);
|
||||
}
|
||||
}
|
||||
|
||||
if (this->Description.empty()) {
|
||||
mapProjectValue(this->Description, "DESCRIPTION"_s);
|
||||
}
|
||||
|
||||
if (this->Website.empty()) {
|
||||
mapProjectValue(this->Website, "HOMEPAGE_URL"_s);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -56,6 +56,8 @@ public:
|
||||
ArgumentParser::NonEmpty<std::string> Version;
|
||||
ArgumentParser::NonEmpty<std::string> VersionCompat;
|
||||
ArgumentParser::NonEmpty<std::string> VersionSchema;
|
||||
ArgumentParser::NonEmpty<std::string> Description;
|
||||
ArgumentParser::NonEmpty<std::string> Website;
|
||||
ArgumentParser::NonEmpty<std::vector<std::string>> DefaultTargets;
|
||||
ArgumentParser::NonEmpty<std::vector<std::string>> DefaultConfigs;
|
||||
bool LowerCase = false;
|
||||
@@ -82,6 +84,8 @@ private:
|
||||
&cmPackageInfoArguments::DefaultTargets);
|
||||
Bind(self, parser, "DEFAULT_CONFIGURATIONS"_s,
|
||||
&cmPackageInfoArguments::DefaultConfigs);
|
||||
Bind(self, parser, "DESCRIPTION"_s, &cmPackageInfoArguments::Description);
|
||||
Bind(self, parser, "HOMEPAGE_URL"_s, &cmPackageInfoArguments::Website);
|
||||
|
||||
Bind(self, parser, "PROJECT"_s, &cmPackageInfoArguments::ProjectName);
|
||||
Bind(self, parser, "NO_PROJECT_METADATA"_s,
|
||||
|
||||
@@ -14,3 +14,6 @@ expect_value("${content}" "foo" "default_components" 0)
|
||||
expect_array("${content}" 2 "configurations")
|
||||
expect_value("${content}" "release" "configurations" 0)
|
||||
expect_value("${content}" "debug" "configurations" 1)
|
||||
|
||||
expect_value("${content}" "Sample package" "description")
|
||||
expect_value("${content}" "https://www.example.com/package/foo" "website")
|
||||
|
||||
@@ -8,4 +8,6 @@ export(
|
||||
COMPAT_VERSION 1.2.0
|
||||
DEFAULT_TARGETS foo
|
||||
DEFAULT_CONFIGURATIONS release debug
|
||||
DESCRIPTION "Sample package"
|
||||
HOMEPAGE_URL "https://www.example.com/package/foo"
|
||||
)
|
||||
|
||||
@@ -6,3 +6,5 @@ file(READ "${out_dir}/foo.cps" content)
|
||||
expect_value("${content}" "foo" "name")
|
||||
expect_missing("${content}" "version")
|
||||
expect_missing("${content}" "compat_version")
|
||||
expect_missing("${content}" "description")
|
||||
expect_missing("${content}" "website")
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
project(foo VERSION 1.2.3 COMPAT_VERSION 1.1.0)
|
||||
project(foo
|
||||
VERSION 1.2.3
|
||||
COMPAT_VERSION 1.1.0
|
||||
DESCRIPTION "Sample package"
|
||||
HOMEPAGE_URL "https://www.example.com/package/foo"
|
||||
)
|
||||
|
||||
add_library(foo INTERFACE)
|
||||
install(TARGETS foo EXPORT foo DESTINATION .)
|
||||
|
||||
@@ -6,13 +6,19 @@ file(READ "${out_dir}/foo.cps" content)
|
||||
expect_value("${content}" "foo" "name")
|
||||
expect_value("${content}" "1.2.3" "version")
|
||||
expect_value("${content}" "1.1.0" "compat_version")
|
||||
expect_value("${content}" "Sample package" "description")
|
||||
expect_value("${content}" "https://www.example.com/package/foo" "website")
|
||||
|
||||
file(READ "${out_dir}/test1.cps" content)
|
||||
expect_value("${content}" "test1" "name")
|
||||
expect_value("${content}" "1.2.3" "version")
|
||||
expect_value("${content}" "1.1.0" "compat_version")
|
||||
expect_value("${content}" "Sample package" "description")
|
||||
expect_value("${content}" "https://www.example.com/package/foo" "website")
|
||||
|
||||
file(READ "${out_dir}/test2.cps" content)
|
||||
expect_value("${content}" "test2" "name")
|
||||
expect_value("${content}" "1.4.7" "version")
|
||||
expect_missing("${content}" "compat_version")
|
||||
expect_value("${content}" "Don't inherit" "description")
|
||||
expect_value("${content}" "https://www.example.com/package/bar" "website")
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
project(foo VERSION 1.2.3 COMPAT_VERSION 1.1.0)
|
||||
project(foo
|
||||
VERSION 1.2.3
|
||||
COMPAT_VERSION 1.1.0
|
||||
DESCRIPTION "Sample package"
|
||||
HOMEPAGE_URL "https://www.example.com/package/foo"
|
||||
)
|
||||
|
||||
add_library(foo INTERFACE)
|
||||
install(TARGETS foo EXPORT foo DESTINATION .)
|
||||
@@ -22,4 +27,6 @@ export(
|
||||
PROJECT foo
|
||||
PACKAGE_INFO test2
|
||||
VERSION 1.4.7
|
||||
DESCRIPTION "Don't inherit"
|
||||
HOMEPAGE_URL "https://www.example.com/package/bar"
|
||||
)
|
||||
|
||||
@@ -14,3 +14,6 @@ expect_value("${content}" "foo" "default_components" 0)
|
||||
expect_array("${content}" 2 "configurations")
|
||||
expect_value("${content}" "release" "configurations" 0)
|
||||
expect_value("${content}" "debug" "configurations" 1)
|
||||
|
||||
expect_value("${content}" "Sample package" "description")
|
||||
expect_value("${content}" "https://www.example.com/package/foo" "website")
|
||||
|
||||
@@ -9,4 +9,6 @@ install(
|
||||
COMPAT_VERSION 1.2.0
|
||||
DEFAULT_TARGETS foo
|
||||
DEFAULT_CONFIGURATIONS release debug
|
||||
DESCRIPTION "Sample package"
|
||||
HOMEPAGE_URL "https://www.example.com/package/foo"
|
||||
)
|
||||
|
||||
@@ -6,3 +6,5 @@ file(READ "${out_dir}/foo.cps" content)
|
||||
expect_value("${content}" "foo" "name")
|
||||
expect_missing("${content}" "version")
|
||||
expect_missing("${content}" "compat_version")
|
||||
expect_missing("${content}" "description")
|
||||
expect_missing("${content}" "website")
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
project(foo VERSION 1.2.3 COMPAT_VERSION 1.1.0)
|
||||
project(foo
|
||||
VERSION 1.2.3
|
||||
COMPAT_VERSION 1.1.0
|
||||
DESCRIPTION "Sample package"
|
||||
HOMEPAGE_URL "https://www.example.com/package/foo"
|
||||
)
|
||||
|
||||
add_library(foo INTERFACE)
|
||||
install(TARGETS foo EXPORT foo DESTINATION .)
|
||||
|
||||
@@ -6,13 +6,19 @@ file(READ "${out_dir}/foo.cps" content)
|
||||
expect_value("${content}" "foo" "name")
|
||||
expect_value("${content}" "1.2.3" "version")
|
||||
expect_value("${content}" "1.1.0" "compat_version")
|
||||
expect_value("${content}" "Sample package" "description")
|
||||
expect_value("${content}" "https://www.example.com/package/foo" "website")
|
||||
|
||||
file(READ "${out_dir}/test1.cps" content)
|
||||
expect_value("${content}" "test1" "name")
|
||||
expect_value("${content}" "1.2.3" "version")
|
||||
expect_value("${content}" "1.1.0" "compat_version")
|
||||
expect_value("${content}" "Sample package" "description")
|
||||
expect_value("${content}" "https://www.example.com/package/foo" "website")
|
||||
|
||||
file(READ "${out_dir}/test2.cps" content)
|
||||
expect_value("${content}" "test2" "name")
|
||||
expect_value("${content}" "1.4.7" "version")
|
||||
expect_missing("${content}" "compat_version")
|
||||
expect_value("${content}" "Don't inherit" "description")
|
||||
expect_value("${content}" "https://www.example.com/package/bar" "website")
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
project(foo VERSION 1.2.3 COMPAT_VERSION 1.1.0)
|
||||
project(foo
|
||||
VERSION 1.2.3
|
||||
COMPAT_VERSION 1.1.0
|
||||
DESCRIPTION "Sample package"
|
||||
HOMEPAGE_URL "https://www.example.com/package/foo"
|
||||
)
|
||||
|
||||
add_library(foo INTERFACE)
|
||||
install(TARGETS foo EXPORT foo DESTINATION .)
|
||||
@@ -25,4 +30,6 @@ install(
|
||||
EXPORT foo
|
||||
PROJECT foo
|
||||
VERSION 1.4.7
|
||||
DESCRIPTION "Don't inherit"
|
||||
HOMEPAGE_URL "https://www.example.com/package/bar"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user