mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-20 12:53:55 +08:00
cmExportCommand: Refactor export(EXPORT ... ) to use subparsers
This commit is contained in:
@@ -208,38 +208,65 @@ static bool HandleTargetsMode(std::vector<std::string> const& args,
|
|||||||
static bool HandleExportMode(std::vector<std::string> const& args,
|
static bool HandleExportMode(std::vector<std::string> const& args,
|
||||||
cmExecutionStatus& status)
|
cmExecutionStatus& status)
|
||||||
{
|
{
|
||||||
struct Arguments : cmPackageInfoArguments
|
struct ExportArguments
|
||||||
{
|
{
|
||||||
cm::optional<ArgumentParser::MaybeEmpty<std::vector<std::string>>> Targets;
|
|
||||||
ArgumentParser::NonEmpty<std::string> ExportSetName;
|
ArgumentParser::NonEmpty<std::string> ExportSetName;
|
||||||
ArgumentParser::NonEmpty<std::string> Namespace;
|
ArgumentParser::NonEmpty<std::string> Namespace;
|
||||||
ArgumentParser::NonEmpty<std::string> Filename;
|
ArgumentParser::NonEmpty<std::string> Filename;
|
||||||
ArgumentParser::NonEmpty<std::string> CxxModulesDirectory;
|
ArgumentParser::NonEmpty<std::string> CxxModulesDirectory;
|
||||||
std::vector<std::vector<std::string>> PackageDependencyArgs;
|
cm::optional<cmPackageInfoArguments> PackageInfo;
|
||||||
bool ExportPackageDependencies = false;
|
bool ExportPackageDependencies = false;
|
||||||
std::vector<std::vector<std::string>> TargetArgs;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
auto parser =
|
auto parser =
|
||||||
cmArgumentParser<Arguments>{}
|
cmArgumentParser<ExportArguments>{}
|
||||||
.Bind("EXPORT"_s, &Arguments::ExportSetName)
|
.Bind("EXPORT"_s, &ExportArguments::ExportSetName)
|
||||||
.Bind("NAMESPACE"_s, &Arguments::Namespace)
|
.Bind("NAMESPACE"_s, &ExportArguments::Namespace)
|
||||||
.Bind("FILE"_s, &Arguments::Filename)
|
.Bind("FILE"_s, &ExportArguments::Filename)
|
||||||
.Bind("CXX_MODULES_DIRECTORY"_s, &Arguments::CxxModulesDirectory);
|
.Bind("CXX_MODULES_DIRECTORY"_s, &ExportArguments::CxxModulesDirectory);
|
||||||
|
|
||||||
if (cmExperimental::HasSupportEnabled(
|
if (cmExperimental::HasSupportEnabled(
|
||||||
status.GetMakefile(),
|
status.GetMakefile(),
|
||||||
cmExperimental::Feature::ExportPackageDependencies)) {
|
cmExperimental::Feature::ExportPackageDependencies)) {
|
||||||
parser.Bind("EXPORT_PACKAGE_DEPENDENCIES"_s,
|
parser.Bind("EXPORT_PACKAGE_DEPENDENCIES"_s,
|
||||||
&Arguments::ExportPackageDependencies);
|
&ExportArguments::ExportPackageDependencies);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmArgumentParser<cmPackageInfoArguments> packageInfoParser;
|
||||||
|
cmPackageInfoArguments::Bind(packageInfoParser);
|
||||||
|
|
||||||
if (cmExperimental::HasSupportEnabled(
|
if (cmExperimental::HasSupportEnabled(
|
||||||
status.GetMakefile(), cmExperimental::Feature::ExportPackageInfo)) {
|
status.GetMakefile(), cmExperimental::Feature::ExportPackageInfo)) {
|
||||||
cmPackageInfoArguments::Bind(parser);
|
parser.BindSubParser("PACKAGE_INFO"_s, packageInfoParser,
|
||||||
|
&ExportArguments::PackageInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> unknownArgs;
|
std::vector<std::string> unknownArgs;
|
||||||
Arguments arguments = parser.Parse(args, &unknownArgs);
|
ExportArguments arguments = parser.Parse(args, &unknownArgs);
|
||||||
|
|
||||||
|
cmMakefile& mf = status.GetMakefile();
|
||||||
|
cmGlobalGenerator* gg = mf.GetGlobalGenerator();
|
||||||
|
|
||||||
|
if (arguments.PackageInfo) {
|
||||||
|
if (arguments.PackageInfo->PackageName.empty()) {
|
||||||
|
if (!arguments.PackageInfo->Check(status, false)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!arguments.Filename.empty()) {
|
||||||
|
status.SetError("PACKAGE_INFO and FILE are mutually exclusive.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!arguments.Namespace.empty()) {
|
||||||
|
status.SetError("PACKAGE_INFO and NAMESPACE are mutually exclusive.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!arguments.PackageInfo->Check(status) ||
|
||||||
|
!arguments.PackageInfo->SetMetadataFromProject(status)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!unknownArgs.empty()) {
|
if (!unknownArgs.empty()) {
|
||||||
status.SetError("EXPORT subcommand given unknown argument: \"" +
|
status.SetError("EXPORT subcommand given unknown argument: \"" +
|
||||||
@@ -247,40 +274,14 @@ static bool HandleExportMode(std::vector<std::string> const& args,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arguments.PackageName.empty()) {
|
|
||||||
if (!arguments.Check(status, false)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!arguments.Filename.empty()) {
|
|
||||||
status.SetError("PACKAGE_INFO and FILE are mutually exclusive.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!arguments.Namespace.empty()) {
|
|
||||||
status.SetError("PACKAGE_INFO and NAMESPACE are mutually exclusive.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!arguments.Check(status) ||
|
|
||||||
!arguments.SetMetadataFromProject(status)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string fname;
|
std::string fname;
|
||||||
bool cps = false;
|
|
||||||
if (arguments.Filename.empty()) {
|
if (arguments.Filename.empty()) {
|
||||||
if (args[0] != "EXPORT") {
|
if (arguments.PackageInfo) {
|
||||||
status.SetError("FILE <filename> option missing.");
|
fname = arguments.PackageInfo->GetPackageFileName();
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (arguments.PackageName.empty()) {
|
|
||||||
fname = arguments.ExportSetName + ".cmake";
|
|
||||||
} else {
|
} else {
|
||||||
fname = arguments.GetPackageFileName();
|
fname = arguments.ExportSetName + ".cmake";
|
||||||
cps = true;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Make sure the file has a .cmake extension.
|
|
||||||
if (cmSystemTools::GetFilenameLastExtension(arguments.Filename) !=
|
if (cmSystemTools::GetFilenameLastExtension(arguments.Filename) !=
|
||||||
".cmake") {
|
".cmake") {
|
||||||
std::ostringstream e;
|
std::ostringstream e;
|
||||||
@@ -292,9 +293,6 @@ static bool HandleExportMode(std::vector<std::string> const& args,
|
|||||||
fname = arguments.Filename;
|
fname = arguments.Filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmMakefile& mf = status.GetMakefile();
|
|
||||||
|
|
||||||
// Get the file to write.
|
|
||||||
if (cmSystemTools::FileIsFullPath(fname)) {
|
if (cmSystemTools::FileIsFullPath(fname)) {
|
||||||
if (!mf.CanIWriteThisFile(fname)) {
|
if (!mf.CanIWriteThisFile(fname)) {
|
||||||
std::ostringstream e;
|
std::ostringstream e;
|
||||||
@@ -309,8 +307,14 @@ static bool HandleExportMode(std::vector<std::string> const& args,
|
|||||||
fname = dir + "/" + fname;
|
fname = dir + "/" + fname;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<cmExportBuildFileGenerator::TargetExport> targets;
|
if (gg->GetExportedTargetsFile(fname)) {
|
||||||
cmGlobalGenerator* gg = mf.GetGlobalGenerator();
|
if (arguments.PackageInfo) {
|
||||||
|
status.SetError(cmStrCat("command already specified for the file "_s,
|
||||||
|
cmSystemTools::GetFilenameName(fname), '.'));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cmExportSet* exportSet = nullptr;
|
cmExportSet* exportSet = nullptr;
|
||||||
cmExportSetMap& setMap = gg->GetExportSets();
|
cmExportSetMap& setMap = gg->GetExportSets();
|
||||||
auto const it = setMap.find(arguments.ExportSetName);
|
auto const it = setMap.find(arguments.ExportSetName);
|
||||||
@@ -322,38 +326,11 @@ static bool HandleExportMode(std::vector<std::string> const& args,
|
|||||||
}
|
}
|
||||||
exportSet = &it->second;
|
exportSet = &it->second;
|
||||||
|
|
||||||
// if cmExportBuildFileGenerator is already defined for the file
|
|
||||||
// and APPEND is not specified, if CMP0103 is OLD ignore previous definition
|
|
||||||
// else raise an error
|
|
||||||
if (gg->GetExportedTargetsFile(fname)) {
|
|
||||||
if (cps) {
|
|
||||||
status.SetError(cmStrCat("command already specified for the file "_s,
|
|
||||||
cmSystemTools::GetFilenameName(fname), '.'));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
switch (mf.GetPolicyStatus(cmPolicies::CMP0103)) {
|
|
||||||
case cmPolicies::WARN:
|
|
||||||
mf.IssueMessage(
|
|
||||||
MessageType::AUTHOR_WARNING,
|
|
||||||
cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0103),
|
|
||||||
"\n"
|
|
||||||
"export() command already specified for the file\n ",
|
|
||||||
arguments.Filename, "\nDid you miss 'APPEND' keyword?"));
|
|
||||||
CM_FALLTHROUGH;
|
|
||||||
case cmPolicies::OLD:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
status.SetError(cmStrCat("command already specified for the file\n ",
|
|
||||||
arguments.Filename,
|
|
||||||
"\nDid you miss 'APPEND' keyword?"));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set up export file generation.
|
// Set up export file generation.
|
||||||
std::unique_ptr<cmExportBuildFileGenerator> ebfg = nullptr;
|
std::unique_ptr<cmExportBuildFileGenerator> ebfg = nullptr;
|
||||||
if (cps) {
|
if (arguments.PackageInfo) {
|
||||||
auto ebpg = cm::make_unique<cmExportBuildPackageInfoGenerator>(arguments);
|
auto ebpg = cm::make_unique<cmExportBuildPackageInfoGenerator>(
|
||||||
|
*arguments.PackageInfo);
|
||||||
ebfg = std::move(ebpg);
|
ebfg = std::move(ebpg);
|
||||||
} else {
|
} else {
|
||||||
auto ebcg = cm::make_unique<cmExportBuildCMakeConfigGenerator>();
|
auto ebcg = cm::make_unique<cmExportBuildCMakeConfigGenerator>();
|
||||||
@@ -367,8 +344,6 @@ static bool HandleExportMode(std::vector<std::string> const& args,
|
|||||||
if (exportSet) {
|
if (exportSet) {
|
||||||
ebfg->SetExportSet(exportSet);
|
ebfg->SetExportSet(exportSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute the set of configurations exported.
|
|
||||||
std::vector<std::string> configurationTypes =
|
std::vector<std::string> configurationTypes =
|
||||||
mf.GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
|
mf.GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
|
||||||
|
|
||||||
@@ -389,14 +364,8 @@ static bool HandleSetupMode(std::vector<std::string> const& args,
|
|||||||
struct SetupArguments
|
struct SetupArguments
|
||||||
{
|
{
|
||||||
ArgumentParser::NonEmpty<std::string> ExportSetName;
|
ArgumentParser::NonEmpty<std::string> ExportSetName;
|
||||||
ArgumentParser::NonEmpty<std::string> Namespace;
|
|
||||||
ArgumentParser::NonEmpty<std::string> Filename;
|
|
||||||
ArgumentParser::NonEmpty<std::string> AndroidMKFile;
|
|
||||||
ArgumentParser::NonEmpty<std::string> CxxModulesDirectory;
|
ArgumentParser::NonEmpty<std::string> CxxModulesDirectory;
|
||||||
bool Append = false;
|
|
||||||
bool ExportOld = false;
|
|
||||||
std::vector<std::vector<std::string>> PackageDependencyArgs;
|
std::vector<std::vector<std::string>> PackageDependencyArgs;
|
||||||
bool ExportPackageDependencies = false;
|
|
||||||
std::vector<std::vector<std::string>> TargetArgs;
|
std::vector<std::vector<std::string>> TargetArgs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -1,64 +1,64 @@
|
|||||||
CMake Error at BadArgs4\.cmake:[0-9]+ \(export\):
|
CMake Error at BadArgs4\.cmake:[0-9]+ \(export\):
|
||||||
export LOWER_CASE_FILE requires PACKAGE_INFO\.
|
export EXPORT subcommand given unknown argument: "LOWER_CASE_FILE".
|
||||||
Call Stack \(most recent call first\):
|
Call Stack \(most recent call first\):
|
||||||
CMakeLists\.txt:3 \(include\)
|
CMakeLists\.txt:3 \(include\)
|
||||||
|
|
||||||
|
|
||||||
CMake Error at BadArgs4\.cmake:[0-9]+ \(export\):
|
CMake Error at BadArgs4\.cmake:[0-9]+ \(export\):
|
||||||
export APPENDIX requires PACKAGE_INFO\.
|
export EXPORT subcommand given unknown argument: "APPENDIX".
|
||||||
Call Stack \(most recent call first\):
|
Call Stack \(most recent call first\):
|
||||||
CMakeLists\.txt:3 \(include\)
|
CMakeLists\.txt:3 \(include\)
|
||||||
|
|
||||||
|
|
||||||
CMake Error at BadArgs4\.cmake:[0-9]+ \(export\):
|
CMake Error at BadArgs4\.cmake:[0-9]+ \(export\):
|
||||||
export VERSION requires PACKAGE_INFO\.
|
export EXPORT subcommand given unknown argument: "VERSION".
|
||||||
Call Stack \(most recent call first\):
|
Call Stack \(most recent call first\):
|
||||||
CMakeLists\.txt:3 \(include\)
|
CMakeLists\.txt:3 \(include\)
|
||||||
|
|
||||||
|
|
||||||
CMake Error at BadArgs4\.cmake:[0-9]+ \(export\):
|
CMake Error at BadArgs4\.cmake:[0-9]+ \(export\):
|
||||||
export LICENSE requires PACKAGE_INFO\.
|
export EXPORT subcommand given unknown argument: "LICENSE".
|
||||||
Call Stack \(most recent call first\):
|
Call Stack \(most recent call first\):
|
||||||
CMakeLists\.txt:3 \(include\)
|
CMakeLists\.txt:3 \(include\)
|
||||||
|
|
||||||
|
|
||||||
CMake Error at BadArgs4\.cmake:[0-9]+ \(export\):
|
CMake Error at BadArgs4\.cmake:[0-9]+ \(export\):
|
||||||
export DEFAULT_LICENSE requires PACKAGE_INFO\.
|
export EXPORT subcommand given unknown argument: "DEFAULT_LICENSE".
|
||||||
Call Stack \(most recent call first\):
|
Call Stack \(most recent call first\):
|
||||||
CMakeLists\.txt:3 \(include\)
|
CMakeLists\.txt:3 \(include\)
|
||||||
|
|
||||||
|
|
||||||
CMake Error at BadArgs4\.cmake:[0-9]+ \(export\):
|
CMake Error at BadArgs4\.cmake:[0-9]+ \(export\):
|
||||||
export DESCRIPTION requires PACKAGE_INFO\.
|
export EXPORT subcommand given unknown argument: "DESCRIPTION".
|
||||||
Call Stack \(most recent call first\):
|
Call Stack \(most recent call first\):
|
||||||
CMakeLists\.txt:3 \(include\)
|
CMakeLists\.txt:3 \(include\)
|
||||||
|
|
||||||
|
|
||||||
CMake Error at BadArgs4\.cmake:[0-9]+ \(export\):
|
CMake Error at BadArgs4\.cmake:[0-9]+ \(export\):
|
||||||
export HOMEPAGE_URL requires PACKAGE_INFO\.
|
export EXPORT subcommand given unknown argument: "HOMEPAGE_URL".
|
||||||
Call Stack \(most recent call first\):
|
Call Stack \(most recent call first\):
|
||||||
CMakeLists\.txt:3 \(include\)
|
CMakeLists\.txt:3 \(include\)
|
||||||
|
|
||||||
|
|
||||||
CMake Error at BadArgs4\.cmake:[0-9]+ \(export\):
|
CMake Error at BadArgs4\.cmake:[0-9]+ \(export\):
|
||||||
export DEFAULT_TARGETS requires PACKAGE_INFO\.
|
export EXPORT subcommand given unknown argument: "DEFAULT_TARGETS".
|
||||||
Call Stack \(most recent call first\):
|
Call Stack \(most recent call first\):
|
||||||
CMakeLists\.txt:3 \(include\)
|
CMakeLists\.txt:3 \(include\)
|
||||||
|
|
||||||
|
|
||||||
CMake Error at BadArgs4\.cmake:[0-9]+ \(export\):
|
CMake Error at BadArgs4\.cmake:[0-9]+ \(export\):
|
||||||
export DEFAULT_CONFIGURATIONS requires PACKAGE_INFO\.
|
export EXPORT subcommand given unknown argument: "DEFAULT_CONFIGURATIONS".
|
||||||
Call Stack \(most recent call first\):
|
Call Stack \(most recent call first\):
|
||||||
CMakeLists\.txt:3 \(include\)
|
CMakeLists\.txt:3 \(include\)
|
||||||
|
|
||||||
|
|
||||||
CMake Error at BadArgs4\.cmake:[0-9]+ \(export\):
|
CMake Error at BadArgs4\.cmake:[0-9]+ \(export\):
|
||||||
export PROJECT requires PACKAGE_INFO\.
|
export EXPORT subcommand given unknown argument: "PROJECT".
|
||||||
Call Stack \(most recent call first\):
|
Call Stack \(most recent call first\):
|
||||||
CMakeLists\.txt:3 \(include\)
|
CMakeLists\.txt:3 \(include\)
|
||||||
|
|
||||||
|
|
||||||
CMake Error at BadArgs4\.cmake:[0-9]+ \(export\):
|
CMake Error at BadArgs4\.cmake:[0-9]+ \(export\):
|
||||||
export NO_PROJECT_METADATA requires PACKAGE_INFO\.
|
export EXPORT subcommand given unknown argument: "NO_PROJECT_METADATA".
|
||||||
Call Stack \(most recent call first\):
|
Call Stack \(most recent call first\):
|
||||||
CMakeLists\.txt:3 \(include\)
|
CMakeLists\.txt:3 \(include\)
|
||||||
|
@@ -18,15 +18,14 @@ export(
|
|||||||
# Test inheriting from a specified project.
|
# Test inheriting from a specified project.
|
||||||
export(
|
export(
|
||||||
EXPORT foo
|
EXPORT foo
|
||||||
PROJECT foo
|
PACKAGE_INFO test1 PROJECT foo
|
||||||
PACKAGE_INFO test1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Test that inheriting doesn't override explicitly specified metadata.
|
# Test that inheriting doesn't override explicitly specified metadata.
|
||||||
export(
|
export(
|
||||||
EXPORT foo
|
EXPORT foo
|
||||||
PROJECT foo
|
|
||||||
PACKAGE_INFO test2
|
PACKAGE_INFO test2
|
||||||
|
PROJECT foo
|
||||||
VERSION 1.4.7
|
VERSION 1.4.7
|
||||||
LICENSE "Apache-2.0"
|
LICENSE "Apache-2.0"
|
||||||
DESCRIPTION "Don't inherit"
|
DESCRIPTION "Don't inherit"
|
||||||
|
Reference in New Issue
Block a user