mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-04 12:49:36 -06:00
cmExportCommand: Port to cmArgumentParser
This commit is contained in:
committed by
Kyle Edwards
parent
e6b6bb0618
commit
f5acecaa6f
@@ -2,10 +2,13 @@
|
|||||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||||
#include "cmExportCommand.h"
|
#include "cmExportCommand.h"
|
||||||
|
|
||||||
|
#include "cm_static_string_view.hxx"
|
||||||
#include "cmsys/RegularExpression.hxx"
|
#include "cmsys/RegularExpression.hxx"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include "cmArgumentParser.h"
|
||||||
#include "cmExportBuildAndroidMKGenerator.h"
|
#include "cmExportBuildAndroidMKGenerator.h"
|
||||||
#include "cmExportBuildFileGenerator.h"
|
#include "cmExportBuildFileGenerator.h"
|
||||||
#include "cmExportSetMap.h"
|
#include "cmExportSetMap.h"
|
||||||
@@ -18,6 +21,7 @@
|
|||||||
#include "cmSystemTools.h"
|
#include "cmSystemTools.h"
|
||||||
#include "cmTarget.h"
|
#include "cmTarget.h"
|
||||||
|
|
||||||
|
class cmExportSet;
|
||||||
class cmExecutionStatus;
|
class cmExecutionStatus;
|
||||||
|
|
||||||
#if defined(__HAIKU__)
|
#if defined(__HAIKU__)
|
||||||
@@ -25,19 +29,6 @@ class cmExecutionStatus;
|
|||||||
# include <StorageDefs.h>
|
# include <StorageDefs.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cmExportCommand::cmExportCommand()
|
|
||||||
: Targets(&Helper, "TARGETS")
|
|
||||||
, Append(&Helper, "APPEND", &ArgumentGroup)
|
|
||||||
, ExportSetName(&Helper, "EXPORT", &ArgumentGroup)
|
|
||||||
, Namespace(&Helper, "NAMESPACE", &ArgumentGroup)
|
|
||||||
, Filename(&Helper, "FILE", &ArgumentGroup)
|
|
||||||
, ExportOld(&Helper, "EXPORT_LINK_INTERFACE_LIBRARIES", &ArgumentGroup)
|
|
||||||
, AndroidMKFile(&Helper, "ANDROID_MK")
|
|
||||||
{
|
|
||||||
this->ExportSet = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// cmExportCommand
|
|
||||||
bool cmExportCommand::InitialPass(std::vector<std::string> const& args,
|
bool cmExportCommand::InitialPass(std::vector<std::string> const& args,
|
||||||
cmExecutionStatus&)
|
cmExecutionStatus&)
|
||||||
{
|
{
|
||||||
@@ -49,45 +40,62 @@ bool cmExportCommand::InitialPass(std::vector<std::string> const& args,
|
|||||||
if (args[0] == "PACKAGE") {
|
if (args[0] == "PACKAGE") {
|
||||||
return this->HandlePackage(args);
|
return this->HandlePackage(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Arguments
|
||||||
|
{
|
||||||
|
std::string ExportSetName;
|
||||||
|
std::vector<std::string> Targets;
|
||||||
|
std::string Namespace;
|
||||||
|
std::string Filename;
|
||||||
|
std::string AndroidMKFile;
|
||||||
|
bool Append = false;
|
||||||
|
bool ExportOld = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
auto parser = cmArgumentParser<Arguments>{}
|
||||||
|
.Bind("NAMESPACE"_s, &Arguments::Namespace)
|
||||||
|
.Bind("FILE"_s, &Arguments::Filename);
|
||||||
|
|
||||||
if (args[0] == "EXPORT") {
|
if (args[0] == "EXPORT") {
|
||||||
this->ExportSetName.Follows(nullptr);
|
parser.Bind("EXPORT"_s, &Arguments::ExportSetName);
|
||||||
this->ArgumentGroup.Follows(&this->ExportSetName);
|
|
||||||
} else {
|
} else {
|
||||||
this->Targets.Follows(nullptr);
|
parser.Bind("TARGETS"_s, &Arguments::Targets);
|
||||||
this->ArgumentGroup.Follows(&this->Targets);
|
parser.Bind("ANDROID_MK"_s, &Arguments::AndroidMKFile);
|
||||||
|
parser.Bind("APPEND"_s, &Arguments::Append);
|
||||||
|
parser.Bind("EXPORT_LINK_INTERFACE_LIBRARIES"_s, &Arguments::ExportOld);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> unknownArgs;
|
std::vector<std::string> unknownArgs;
|
||||||
this->Helper.Parse(&args, &unknownArgs);
|
Arguments const arguments = parser.Parse(args, &unknownArgs);
|
||||||
|
|
||||||
if (!unknownArgs.empty()) {
|
if (!unknownArgs.empty()) {
|
||||||
this->SetError("Unknown arguments.");
|
this->SetError("Unknown argument: \"" + unknownArgs.front() + "\".");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string fname;
|
std::string fname;
|
||||||
bool android = false;
|
bool android = false;
|
||||||
if (this->AndroidMKFile.WasFound()) {
|
if (!arguments.AndroidMKFile.empty()) {
|
||||||
fname = this->AndroidMKFile.GetString();
|
fname = arguments.AndroidMKFile;
|
||||||
android = true;
|
android = true;
|
||||||
}
|
}
|
||||||
if (!this->Filename.WasFound() && fname.empty()) {
|
if (arguments.Filename.empty() && fname.empty()) {
|
||||||
if (args[0] != "EXPORT") {
|
if (args[0] != "EXPORT") {
|
||||||
this->SetError("FILE <filename> option missing.");
|
this->SetError("FILE <filename> option missing.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
fname = this->ExportSetName.GetString() + ".cmake";
|
fname = arguments.ExportSetName + ".cmake";
|
||||||
} else if (fname.empty()) {
|
} else if (fname.empty()) {
|
||||||
// Make sure the file has a .cmake extension.
|
// Make sure the file has a .cmake extension.
|
||||||
if (cmSystemTools::GetFilenameLastExtension(this->Filename.GetCString()) !=
|
if (cmSystemTools::GetFilenameLastExtension(arguments.Filename) !=
|
||||||
".cmake") {
|
".cmake") {
|
||||||
std::ostringstream e;
|
std::ostringstream e;
|
||||||
e << "FILE option given filename \"" << this->Filename.GetString()
|
e << "FILE option given filename \"" << arguments.Filename
|
||||||
<< "\" which does not have an extension of \".cmake\".\n";
|
<< "\" which does not have an extension of \".cmake\".\n";
|
||||||
this->SetError(e.str());
|
this->SetError(e.str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
fname = this->Filename.GetString();
|
fname = arguments.Filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the file to write.
|
// Get the file to write.
|
||||||
@@ -109,33 +117,19 @@ bool cmExportCommand::InitialPass(std::vector<std::string> const& args,
|
|||||||
|
|
||||||
cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
|
cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
|
||||||
|
|
||||||
|
cmExportSet* ExportSet = nullptr;
|
||||||
if (args[0] == "EXPORT") {
|
if (args[0] == "EXPORT") {
|
||||||
if (this->Append.IsEnabled()) {
|
|
||||||
std::ostringstream e;
|
|
||||||
e << "EXPORT signature does not recognise the APPEND option.";
|
|
||||||
this->SetError(e.str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->ExportOld.IsEnabled()) {
|
|
||||||
std::ostringstream e;
|
|
||||||
e << "EXPORT signature does not recognise the "
|
|
||||||
"EXPORT_LINK_INTERFACE_LIBRARIES option.";
|
|
||||||
this->SetError(e.str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
cmExportSetMap& setMap = gg->GetExportSets();
|
cmExportSetMap& setMap = gg->GetExportSets();
|
||||||
std::string setName = this->ExportSetName.GetString();
|
auto const it = setMap.find(arguments.ExportSetName);
|
||||||
if (setMap.find(setName) == setMap.end()) {
|
if (it == setMap.end()) {
|
||||||
std::ostringstream e;
|
std::ostringstream e;
|
||||||
e << "Export set \"" << setName << "\" not found.";
|
e << "Export set \"" << arguments.ExportSetName << "\" not found.";
|
||||||
this->SetError(e.str());
|
this->SetError(e.str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this->ExportSet = setMap[setName];
|
ExportSet = it->second;
|
||||||
} else if (this->Targets.WasFound()) {
|
} else if (!arguments.Targets.empty()) {
|
||||||
for (std::string const& currentTarget : this->Targets.GetVector()) {
|
for (std::string const& currentTarget : arguments.Targets) {
|
||||||
if (this->Makefile->IsAlias(currentTarget)) {
|
if (this->Makefile->IsAlias(currentTarget)) {
|
||||||
std::ostringstream e;
|
std::ostringstream e;
|
||||||
e << "given ALIAS target \"" << currentTarget
|
e << "given ALIAS target \"" << currentTarget
|
||||||
@@ -159,7 +153,7 @@ bool cmExportCommand::InitialPass(std::vector<std::string> const& args,
|
|||||||
}
|
}
|
||||||
targets.push_back(currentTarget);
|
targets.push_back(currentTarget);
|
||||||
}
|
}
|
||||||
if (this->Append.IsEnabled()) {
|
if (arguments.Append) {
|
||||||
if (cmExportBuildFileGenerator* ebfg =
|
if (cmExportBuildFileGenerator* ebfg =
|
||||||
gg->GetExportedTargetsFile(fname)) {
|
gg->GetExportedTargetsFile(fname)) {
|
||||||
ebfg->AppendTargets(targets);
|
ebfg->AppendTargets(targets);
|
||||||
@@ -179,15 +173,15 @@ bool cmExportCommand::InitialPass(std::vector<std::string> const& args,
|
|||||||
ebfg = new cmExportBuildFileGenerator;
|
ebfg = new cmExportBuildFileGenerator;
|
||||||
}
|
}
|
||||||
ebfg->SetExportFile(fname.c_str());
|
ebfg->SetExportFile(fname.c_str());
|
||||||
ebfg->SetNamespace(this->Namespace.GetCString());
|
ebfg->SetNamespace(arguments.Namespace);
|
||||||
ebfg->SetAppendMode(this->Append.IsEnabled());
|
ebfg->SetAppendMode(arguments.Append);
|
||||||
if (this->ExportSet) {
|
if (ExportSet != nullptr) {
|
||||||
ebfg->SetExportSet(this->ExportSet);
|
ebfg->SetExportSet(ExportSet);
|
||||||
} else {
|
} else {
|
||||||
ebfg->SetTargets(targets);
|
ebfg->SetTargets(targets);
|
||||||
}
|
}
|
||||||
this->Makefile->AddExportBuildFileGenerator(ebfg);
|
this->Makefile->AddExportBuildFileGenerator(ebfg);
|
||||||
ebfg->SetExportOld(this->ExportOld.IsEnabled());
|
ebfg->SetExportOld(arguments.ExportOld);
|
||||||
|
|
||||||
// Compute the set of configurations exported.
|
// Compute the set of configurations exported.
|
||||||
std::vector<std::string> configurationTypes;
|
std::vector<std::string> configurationTypes;
|
||||||
@@ -198,7 +192,7 @@ bool cmExportCommand::InitialPass(std::vector<std::string> const& args,
|
|||||||
for (std::string const& ct : configurationTypes) {
|
for (std::string const& ct : configurationTypes) {
|
||||||
ebfg->AddConfiguration(ct);
|
ebfg->AddConfiguration(ct);
|
||||||
}
|
}
|
||||||
if (this->ExportSet) {
|
if (ExportSet != nullptr) {
|
||||||
gg->AddBuildExportExportSet(ebfg);
|
gg->AddBuildExportExportSet(ebfg);
|
||||||
} else {
|
} else {
|
||||||
gg->AddBuildExportSet(ebfg);
|
gg->AddBuildExportSet(ebfg);
|
||||||
|
|||||||
@@ -9,21 +9,12 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "cmCommand.h"
|
#include "cmCommand.h"
|
||||||
#include "cmCommandArgumentsHelper.h"
|
|
||||||
|
|
||||||
class cmExecutionStatus;
|
class cmExecutionStatus;
|
||||||
class cmExportSet;
|
|
||||||
|
|
||||||
/** \class cmExportLibraryDependenciesCommand
|
|
||||||
* \brief Add a test to the lists of tests to run.
|
|
||||||
*
|
|
||||||
* cmExportLibraryDependenciesCommand adds a test to the list of tests to run
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class cmExportCommand : public cmCommand
|
class cmExportCommand : public cmCommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cmExportCommand();
|
|
||||||
/**
|
/**
|
||||||
* This is a virtual constructor for the command.
|
* This is a virtual constructor for the command.
|
||||||
*/
|
*/
|
||||||
@@ -37,21 +28,6 @@ public:
|
|||||||
cmExecutionStatus& status) override;
|
cmExecutionStatus& status) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cmCommandArgumentsHelper Helper;
|
|
||||||
cmCommandArgumentGroup ArgumentGroup;
|
|
||||||
cmCAStringVector Targets;
|
|
||||||
cmCAEnabler Append;
|
|
||||||
cmCAString ExportSetName;
|
|
||||||
cmCAString Namespace;
|
|
||||||
cmCAString Filename;
|
|
||||||
cmCAEnabler ExportOld;
|
|
||||||
cmCAString AndroidMKFile;
|
|
||||||
|
|
||||||
cmExportSet* ExportSet;
|
|
||||||
|
|
||||||
friend class cmExportBuildFileGenerator;
|
|
||||||
std::string ErrorMessage;
|
|
||||||
|
|
||||||
bool HandlePackage(std::vector<std::string> const& args);
|
bool HandlePackage(std::vector<std::string> const& args);
|
||||||
void StorePackageRegistryWin(std::string const& package, const char* content,
|
void StorePackageRegistryWin(std::string const& package, const char* content,
|
||||||
const char* hash);
|
const char* hash);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
CMake Error at AppendExport.cmake:[0-9]+ \(export\):
|
CMake Error at AppendExport.cmake:[0-9]+ \(export\):
|
||||||
export EXPORT signature does not recognise the APPEND option.
|
export Unknown argument: "APPEND".
|
||||||
Call Stack \(most recent call first\):
|
Call Stack \(most recent call first\):
|
||||||
CMakeLists.txt:3 \(include\)
|
CMakeLists.txt:3 \(include\)
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
CMake Error at OldIface.cmake:[0-9]+ \(export\):
|
CMake Error at OldIface.cmake:[0-9]+ \(export\):
|
||||||
export EXPORT signature does not recognise the
|
export Unknown argument: "EXPORT_LINK_INTERFACE_LIBRARIES".
|
||||||
EXPORT_LINK_INTERFACE_LIBRARIES option.
|
|
||||||
Call Stack \(most recent call first\):
|
Call Stack \(most recent call first\):
|
||||||
CMakeLists.txt:3 \(include\)
|
CMakeLists.txt:3 \(include\)
|
||||||
|
|||||||
Reference in New Issue
Block a user