Browse Source

cmTarget: Do not mistake a preceding error for a CMP0049 failure

After calls to ProcessSourceItemCMP0049, check for an empty return
string to detect a failure instead of trusting GetErrorOccuredFlag.
The latter could have been left from a preceding non-fatal error.

Extend the RunCMake.Configure test to cover a case that exposed this
problem.
Brad King 11 years ago
parent
commit
b2282631f6

+ 7 - 5
Source/cmTarget.cxx

@@ -927,10 +927,13 @@ void cmTarget::AddSources(std::vector<std::string> const& srcs)
 
     if(!(src[0] == '$' && src[1] == '<'))
       {
-      filename = this->ProcessSourceItemCMP0049(filename);
-      if (cmSystemTools::GetErrorOccuredFlag())
+      if(!filename.empty())
         {
-        return;
+        filename = this->ProcessSourceItemCMP0049(filename);
+        if(filename.empty())
+          {
+          return;
+          }
         }
       this->Makefile->GetOrCreateSource(filename);
       }
@@ -998,8 +1001,7 @@ std::string cmTarget::ProcessSourceItemCMP0049(const std::string& s)
 cmSourceFile* cmTarget::AddSourceCMP0049(const std::string& s)
 {
   std::string src = this->ProcessSourceItemCMP0049(s);
-
-  if (cmSystemTools::GetErrorOccuredFlag())
+  if(!s.empty() && src.empty())
     {
     return 0;
     }

+ 1 - 0
Tests/RunCMake/Configure/CustomTargetAfterError-result.txt

@@ -0,0 +1 @@
+1

+ 9 - 0
Tests/RunCMake/Configure/CustomTargetAfterError-stderr.txt

@@ -0,0 +1,9 @@
+^CMake Error at CustomTargetAfterError.cmake:1 \(message\):
+  Error before add_custom_target
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
++
+CMake Error at CustomTargetAfterError.cmake:3 \(message\):
+  Error after add_custom_target
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)$

+ 3 - 0
Tests/RunCMake/Configure/CustomTargetAfterError.cmake

@@ -0,0 +1,3 @@
+message(SEND_ERROR "Error before add_custom_target")
+add_custom_target(foo COMMAND echo)
+message(SEND_ERROR "Error after add_custom_target")

+ 1 - 0
Tests/RunCMake/Configure/RunCMakeTest.cmake

@@ -1,5 +1,6 @@
 include(RunCMake)
 
+run_cmake(CustomTargetAfterError)
 run_cmake(ErrorLogs)
 run_cmake(FailCopyFileABI)