浏览代码

FIX: fix the problem where a target is a single character and nmake gets confused and add a test for it

Bill Hoffman 21 年之前
父节点
当前提交
040f776885

+ 2 - 2
Source/cmLocalUnixMakefileGenerator.cxx

@@ -2587,7 +2587,7 @@ void cmLocalUnixMakefileGenerator::OutputMakeRule(std::ostream& fout,
   tgt = this->ConvertToMakeTarget(tgt.c_str());
   if(depends.empty())
     {
-    fout << tgt.c_str() << ":\n";
+    fout << tgt.c_str() << " :\n";
     }
   else
     {
@@ -2599,7 +2599,7 @@ void cmLocalUnixMakefileGenerator::OutputMakeRule(std::ostream& fout,
       replace = *dep;
       m_Makefile->ExpandVariablesInString(replace);
       replace = this->ConvertToMakeTarget(replace.c_str());
-      fout << tgt.c_str() << ": " << replace.c_str() << "\n";
+      fout << tgt.c_str() << " : " << replace.c_str() << "\n";
       }
     }
   

+ 6 - 3
Source/cmSystemTools.cxx

@@ -426,15 +426,18 @@ bool cmSystemTools::RunSingleCommand(
     {
     verbose = false;
     }
+  std::string argsTemp;
+  std::string program;
+  cmSystemTools::SplitProgramFromArgs(command, program, argsTemp);
+  std::vector<cmStdString> args = cmSystemTools::ParseArguments(argsTemp.c_str());
 
-  std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
-
-  if(args.size() < 1)
+  if(program.size() < 1)
     {
     return false;
     }
   
   std::vector<const char*> argv;
+  argv.push_back(program.c_str());
   for(std::vector<cmStdString>::const_iterator a = args.begin();
       a != args.end(); ++a)
     {

+ 1 - 1
Tests/Complex/Executable/CMakeLists.txt

@@ -11,7 +11,7 @@ LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source/kwsys)
 SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared)
 LINK_LIBRARIES(${COMPLEX_LIBS})
 
-
+ADD_EXECUTABLE(A A.cxx)
 ADD_EXECUTABLE(complex complex)
 ADD_EXECUTABLE(complex.file complex.file.cxx)
 IF (UNIX)

+ 28 - 0
Tests/Complex/Executable/complex.cxx

@@ -111,7 +111,35 @@ int main()
   lib += CMAKE_INTDIR;
   lib += "/";
 #endif
+  std::string exe = lib;
 
+  // Test a single character executable to test a: in makefiles
+  exe += "A";
+  exe += cmSystemTools::GetExecutableExtension();
+  int ret;
+  std::string errorMessage;
+  if(cmSystemTools::RunSingleCommand(exe.c_str(), 0, &ret))
+    {
+    if(ret != 10)
+      {
+      errorMessage += exe;
+      errorMessage += " did not return 10";
+      }
+    }
+  else
+    {
+    errorMessage += exe;
+    errorMessage += ": failed to run.";
+    }
+  if(errorMessage.size())
+    {
+    cmFailed(errorMessage.c_str());
+    }
+  else
+    {
+    cmPassed("run Single Character executable A returned 10 as expected.");
+    }
+  
   lib += cmDynamicLoader::LibPrefix();
   lib += "CMakeTestModule";
   lib += cmDynamicLoader::LibExtension();

+ 1 - 1
Tests/ComplexOneConfig/Executable/CMakeLists.txt

@@ -11,7 +11,7 @@ LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source/kwsys)
 SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared)
 LINK_LIBRARIES(${COMPLEX_LIBS})
 
-
+ADD_EXECUTABLE(A A.cxx)
 ADD_EXECUTABLE(complex complex)
 ADD_EXECUTABLE(complex.file complex.file.cxx)
 IF (UNIX)

+ 28 - 0
Tests/ComplexOneConfig/Executable/complex.cxx

@@ -111,7 +111,35 @@ int main()
   lib += CMAKE_INTDIR;
   lib += "/";
 #endif
+  std::string exe = lib;
 
+  // Test a single character executable to test a: in makefiles
+  exe += "A";
+  exe += cmSystemTools::GetExecutableExtension();
+  int ret;
+  std::string errorMessage;
+  if(cmSystemTools::RunSingleCommand(exe.c_str(), 0, &ret))
+    {
+    if(ret != 10)
+      {
+      errorMessage += exe;
+      errorMessage += " did not return 10";
+      }
+    }
+  else
+    {
+    errorMessage += exe;
+    errorMessage += ": failed to run.";
+    }
+  if(errorMessage.size())
+    {
+    cmFailed(errorMessage.c_str());
+    }
+  else
+    {
+    cmPassed("run Single Character executable A returned 10 as expected.");
+    }
+  
   lib += cmDynamicLoader::LibPrefix();
   lib += "CMakeTestModule";
   lib += cmDynamicLoader::LibExtension();

+ 1 - 1
Tests/ComplexRelativePaths/Executable/CMakeLists.txt

@@ -11,7 +11,7 @@ LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source/kwsys)
 SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared)
 LINK_LIBRARIES(${COMPLEX_LIBS})
 
-
+ADD_EXECUTABLE(A A.cxx)
 ADD_EXECUTABLE(complex complex)
 ADD_EXECUTABLE(complex.file complex.file.cxx)
 IF (UNIX)

+ 28 - 0
Tests/ComplexRelativePaths/Executable/complex.cxx

@@ -111,7 +111,35 @@ int main()
   lib += CMAKE_INTDIR;
   lib += "/";
 #endif
+  std::string exe = lib;
 
+  // Test a single character executable to test a: in makefiles
+  exe += "A";
+  exe += cmSystemTools::GetExecutableExtension();
+  int ret;
+  std::string errorMessage;
+  if(cmSystemTools::RunSingleCommand(exe.c_str(), 0, &ret))
+    {
+    if(ret != 10)
+      {
+      errorMessage += exe;
+      errorMessage += " did not return 10";
+      }
+    }
+  else
+    {
+    errorMessage += exe;
+    errorMessage += ": failed to run.";
+    }
+  if(errorMessage.size())
+    {
+    cmFailed(errorMessage.c_str());
+    }
+  else
+    {
+    cmPassed("run Single Character executable A returned 10 as expected.");
+    }
+  
   lib += cmDynamicLoader::LibPrefix();
   lib += "CMakeTestModule";
   lib += cmDynamicLoader::LibExtension();