try_compile: More useful error if insufficient arguments

Tweak try_compile and try_run to give a more informative error (rather
than "unknown error") when given an insufficient number of arguments.
This commit is contained in:
Matthew Woehlke 2022-09-15 13:34:30 -04:00
parent 01a25d72c6
commit f976800577
5 changed files with 12 additions and 7 deletions

View File

@ -16,12 +16,15 @@
bool cmTryCompileCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
cmMakefile& mf = status.GetMakefile();
if (args.size() < 3) {
mf.IssueMessage(
MessageType::FATAL_ERROR,
"The try_compile() command requires at least 3 arguments.");
return false;
}
cmMakefile& mf = status.GetMakefile();
if (mf.GetCMakeInstance()->GetWorkingMode() == cmake::FIND_PACKAGE_MODE) {
mf.IssueMessage(
MessageType::FATAL_ERROR,

View File

@ -469,12 +469,14 @@ void TryRunCommandImpl::DoNotRunExecutable(
bool cmTryRunCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
cmMakefile& mf = status.GetMakefile();
if (args.size() < 4) {
mf.IssueMessage(MessageType::FATAL_ERROR,
"The try_run() command requires at least 4 arguments.");
return false;
}
cmMakefile& mf = status.GetMakefile();
if (mf.GetCMakeInstance()->GetWorkingMode() == cmake::FIND_PACKAGE_MODE) {
mf.IssueMessage(
MessageType::FATAL_ERROR,

View File

@ -1,4 +1,4 @@
CMake Error at NoArgs.cmake:[0-9]+ \(try_compile\):
try_compile unknown error.
The try_compile\(\) command requires at least 3 arguments.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -1,4 +1,4 @@
CMake Error at OneArg.cmake:[0-9]+ \(try_compile\):
try_compile unknown error.
The try_compile\(\) command requires at least 3 arguments.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -1,4 +1,4 @@
CMake Error at TwoArgs.cmake:[0-9]+ \(try_compile\):
try_compile unknown error.
The try_compile\(\) command requires at least 3 arguments.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)