Browse Source

ENH: better error checking for add library or executable with no source files

Ken Martin 20 years ago
parent
commit
cc6170c494
2 changed files with 14 additions and 1 deletions
  1. 6 0
      Source/cmAddExecutableCommand.cxx
  2. 8 1
      Source/cmAddLibraryCommand.cxx

+ 6 - 0
Source/cmAddExecutableCommand.cxx

@@ -49,6 +49,12 @@ bool cmAddExecutableCommand::InitialPass(std::vector<std::string> const& args)
       }
     }
 
+  if (s == args.end())
+    {
+    this->SetError("called with incorrect number of arguments, no sources provided");
+    return false;
+    }
+
   std::vector<std::string> srclists(s, args.end());
   cmTarget* tgt = m_Makefile->AddExecutable(exename.c_str(), srclists); 
   if ( use_win32 )

+ 8 - 1
Source/cmAddLibraryCommand.cxx

@@ -26,7 +26,8 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& args)
     }
   // Library type defaults to value of BUILD_SHARED_LIBS, if it exists,
   // otherwise it defaults to static library.
-  int shared = !cmSystemTools::IsOff(m_Makefile->GetDefinition("BUILD_SHARED_LIBS"));
+  int shared = 
+    !cmSystemTools::IsOff(m_Makefile->GetDefinition("BUILD_SHARED_LIBS"));
   
   std::vector<std::string>::const_iterator s = args.begin();
 
@@ -57,6 +58,12 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& args)
       }
     }
 
+  if (s == args.end())
+    {
+    this->SetError("called with incorrect number of arguments, no sources provided");
+    return false;
+    }
+
   std::vector<std::string> srclists;
   while (s != args.end()) 
     {