From 2ba5c37b3fed00ecc307b1d93780acd4a57695eb Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 25 Jun 2019 14:37:38 -0400 Subject: export: Restore support for empty TARGETS list Refactoring in commit f5acecaa6f (cmExportCommand: Port to cmArgumentParser, 2019-03-23, v3.15.0-rc1~270^2~3) broke the `export` command's support for specifying `TARGETS` with no entries. Fix it and add a test case. Fixes: #19415 --- Source/cmExportCommand.cxx | 11 +++++++++-- Tests/RunCMake/export/Empty.cmake | 1 + Tests/RunCMake/export/RunCMakeTest.cmake | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 Tests/RunCMake/export/Empty.cmake diff --git a/Source/cmExportCommand.cxx b/Source/cmExportCommand.cxx index 5b611c0..a849aa2 100644 --- a/Source/cmExportCommand.cxx +++ b/Source/cmExportCommand.cxx @@ -4,6 +4,8 @@ #include "cm_static_string_view.hxx" #include "cmsys/RegularExpression.hxx" + +#include #include #include #include @@ -66,7 +68,9 @@ bool cmExportCommand::InitialPass(std::vector const& args, } std::vector unknownArgs; - Arguments const arguments = parser.Parse(args, &unknownArgs); + std::vector keywordsMissingValue; + Arguments const arguments = + parser.Parse(args, &unknownArgs, &keywordsMissingValue); if (!unknownArgs.empty()) { this->SetError("Unknown argument: \"" + unknownArgs.front() + "\"."); @@ -128,7 +132,10 @@ bool cmExportCommand::InitialPass(std::vector const& args, return false; } ExportSet = it->second; - } else if (!arguments.Targets.empty()) { + } else if (!arguments.Targets.empty() || + std::find(keywordsMissingValue.begin(), + keywordsMissingValue.end(), + "TARGETS") != keywordsMissingValue.end()) { for (std::string const& currentTarget : arguments.Targets) { if (this->Makefile->IsAlias(currentTarget)) { std::ostringstream e; diff --git a/Tests/RunCMake/export/Empty.cmake b/Tests/RunCMake/export/Empty.cmake new file mode 100644 index 0000000..2198ddf --- /dev/null +++ b/Tests/RunCMake/export/Empty.cmake @@ -0,0 +1 @@ +export(TARGETS FILE targets.cmake) diff --git a/Tests/RunCMake/export/RunCMakeTest.cmake b/Tests/RunCMake/export/RunCMakeTest.cmake index 46bb1fc..97a0ca6 100644 --- a/Tests/RunCMake/export/RunCMakeTest.cmake +++ b/Tests/RunCMake/export/RunCMakeTest.cmake @@ -1,6 +1,7 @@ include(RunCMake) run_cmake(CustomTarget) +run_cmake(Empty) run_cmake(TargetNotFound) run_cmake(AppendExport) run_cmake(OldIface) -- cgit v0.12