Просмотр исходного кода

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.
Matthew Woehlke 3 лет назад
Родитель
Сommit
f976800577

+ 5 - 2
Source/cmTryCompileCommand.cxx

@@ -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,

+ 4 - 2
Source/cmTryRunCommand.cxx

@@ -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,

+ 1 - 1
Tests/RunCMake/try_compile/NoArgs-stderr.txt

@@ -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\)

+ 1 - 1
Tests/RunCMake/try_compile/OneArg-stderr.txt

@@ -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\)

+ 1 - 1
Tests/RunCMake/try_compile/TwoArgs-stderr.txt

@@ -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\)