mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 13:51:33 -06:00
add_custom_{command,target}: Fix crash on empty expanded command
Our custom command generation logic assumes that all command lines have
at least `argv0`. In `add_custom_{command,target}` we already check
that at least a `COMMAND` was given, but using `COMMAND_EXPAND_LISTS` in
combination with a generator expression that expands to an empty string
may produce an empty command line. In this case simply add an empty
string as a command to maintain our internal invariant.
Fixes: #17993
This commit is contained in:
@@ -40,6 +40,14 @@ cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc,
|
||||
argv.push_back(std::move(parsed_arg));
|
||||
}
|
||||
}
|
||||
|
||||
// Later code assumes at least one entry exists, but expanding
|
||||
// lists on an empty command may have left this empty.
|
||||
// FIXME: Should we define behavior for removing empty commands?
|
||||
if (argv.empty()) {
|
||||
argv.push_back(std::string());
|
||||
}
|
||||
|
||||
this->CommandLines.push_back(std::move(argv));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
add_custom_target(EmptyCustom COMMAND "" COMMAND_EXPAND_LISTS)
|
||||
@@ -1,5 +1,6 @@
|
||||
include(RunCMake)
|
||||
|
||||
run_cmake(CommandExpandsEmpty)
|
||||
run_cmake(NoArguments)
|
||||
run_cmake(BadTargetName)
|
||||
run_cmake(ByproductsNoCommand)
|
||||
|
||||
Reference in New Issue
Block a user