summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBill Hoffman <bill.hoffman@kitware.com>2002-04-03 21:14:06 (GMT)
committerBill Hoffman <bill.hoffman@kitware.com>2002-04-03 21:14:06 (GMT)
commitd42055b283496e3259a89db9aa9074f4169bcf34 (patch)
treea2f35c6fc56e7e313c6c091b2f4903b79d922822 /Source
parent1c73117b7add8578bfe1abc3db7de754496e2453 (diff)
downloadCMake-d42055b283496e3259a89db9aa9074f4169bcf34.zip
CMake-d42055b283496e3259a89db9aa9074f4169bcf34.tar.gz
CMake-d42055b283496e3259a89db9aa9074f4169bcf34.tar.bz2
ENH: fix more space problems, you can add args to the ExecProgram command separatly now
Diffstat (limited to 'Source')
-rw-r--r--Source/cmExecProgramCommand.cxx35
-rw-r--r--Source/cmExecProgramCommand.h6
-rw-r--r--Source/cmNMakeMakefileGenerator.cxx31
-rw-r--r--Source/cmSystemTools.cxx56
-rw-r--r--Source/cmSystemTools.h3
-rw-r--r--Source/cmaketest.cxx16
6 files changed, 100 insertions, 47 deletions
diff --git a/Source/cmExecProgramCommand.cxx b/Source/cmExecProgramCommand.cxx
index aea6950..7e1ad76 100644
--- a/Source/cmExecProgramCommand.cxx
+++ b/Source/cmExecProgramCommand.cxx
@@ -25,16 +25,45 @@ bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& args)
this->SetError("called with incorrect number of arguments");
return false;
}
+ std::string arguments;
+ bool doingargs = false;
+ int count = 0;
+ for(int i=0; i < args.size(); ++i)
+ {
+ if(doingargs)
+ {
+ arguments += args[i];
+ arguments += " ";
+ count++;
+ }
+ else if(args[i] == "ARGS")
+ {
+ count++;
+ doingargs = true;
+ }
+ }
+
+ std::string command;
+ if(arguments.size())
+ {
+ command = cmSystemTools::ConvertToOutputPath(args[0].c_str());
+ command += " ";
+ command += arguments;
+ }
+ else
+ {
+ command = args[0];
+ }
std::string output;
- if(args.size() == 2)
+ if(args.size() - count == 2)
{
cmSystemTools::MakeDirectory(args[1].c_str());
- cmSystemTools::RunCommand(args[0].c_str(), output,
+ cmSystemTools::RunCommand(command.c_str(), output,
cmSystemTools::ConvertToOutputPath(args[1].c_str()).c_str());
}
else
{
- cmSystemTools::RunCommand(args[0].c_str(), output);
+ cmSystemTools::RunCommand(command.c_str(), output);
}
return true;
}
diff --git a/Source/cmExecProgramCommand.h b/Source/cmExecProgramCommand.h
index 75f083e..01acc1b 100644
--- a/Source/cmExecProgramCommand.h
+++ b/Source/cmExecProgramCommand.h
@@ -64,7 +64,11 @@ public:
virtual const char* GetFullDocumentation()
{
return
- "EXEC_PROGRAM(Executable [Directory to run in])";
+ "EXEC_PROGRAM(Executable [Directory to run in] [ARGS arguments to executable])"
+ "The executable is run in the optionally specified Directory. The executable "
+ "can include arguments if it is double quoted, but it is better to use the "
+ "optional ARGS argument to specify arguments to the program. This is because "
+ "cmake will then be able to escape spaces in the Executable path.";
}
cmTypeMacro(cmExecProgramCommand, cmCommand);
diff --git a/Source/cmNMakeMakefileGenerator.cxx b/Source/cmNMakeMakefileGenerator.cxx
index f88b430..9e55a03 100644
--- a/Source/cmNMakeMakefileGenerator.cxx
+++ b/Source/cmNMakeMakefileGenerator.cxx
@@ -52,19 +52,14 @@ std::string cmNMakeMakefileGenerator::ShortPath(const char* path)
}
// if there are spaces then call GetShortPathName to get rid of them
- char *buffer = new char[strlen(path)+1];
- if(GetShortPathName(path, buffer,
- static_cast<int>(strlen(path)+1)) != 0)
- {
- ret = buffer;
- }
- else
+ if(!cmSystemTools::GetShortPath(path, ret))
{
// if GetShortPathName failed for some reason use
// ConvertToOutputPath instead which will at least escape the spaces
ret = this->ConvertToOutputPath(path);
+ return ret;
}
- delete [] buffer;
+ ret = this->ConvertToOutputPath(ret.c_str());
return ret;
}
@@ -161,37 +156,37 @@ void cmNMakeMakefileGenerator::OutputMakeVariables(std::ostream& fout)
m_Makefile->ExpandVariablesInString(replaceVars);
fout << replaceVars.c_str();
std::string ccommand = m_Makefile->GetDefinition("CCOMMAND_COMMAND");
- fout << "RM = " << this->ConvertToOutputPath(ccommand.c_str()) << " remove -f\n";
+ fout << "RM = " << this->ShortPath(ccommand.c_str()) << " remove -f\n";
std::string ccompiler = m_Makefile->GetDefinition("CMAKE_C_COMPILER");
fout << "CMAKE_C_COMPILER = "
- << this->ConvertToOutputPath(ccompiler.c_str()) << "\n";
+ << this->ShortPath(ccompiler.c_str()) << "\n";
std::string cxxcompiler = m_Makefile->GetDefinition("CMAKE_CXX_COMPILER");
fout << "CMAKE_CXX_COMPILER = "
- << this->ConvertToOutputPath(cxxcompiler.c_str()) << "\n";
+ << this->ShortPath(cxxcompiler.c_str()) << "\n";
std::string linker = m_Makefile->GetDefinition("CMAKE_LINKER");
fout << "CMAKE_LINKER = " <<
- this->ConvertToOutputPath(linker.c_str()) << "\n";
+ this->ShortPath(linker.c_str()) << "\n";
std::string lib_manager = m_Makefile->GetDefinition("CMAKE_LIBRARY_MANAGER");
fout << "CMAKE_LIBRARY_MANAGER = "
- << this->ConvertToOutputPath(lib_manager.c_str()) << "\n";
+ << this->ShortPath(lib_manager.c_str()) << "\n";
std::string cmakecommand = m_Makefile->GetDefinition("CMAKE_COMMAND");
fout << "CMAKE_COMMAND = "
- << this->ConvertToOutputPath(cmakecommand.c_str()) << "\n";
+ << this->ShortPath(cmakecommand.c_str()) << "\n";
fout << "CMAKE_CURRENT_SOURCE = "
- << ShortPath(m_Makefile->GetStartDirectory() )
+ << this->ShortPath(m_Makefile->GetStartDirectory() )
<< "\n";
fout << "CMAKE_CURRENT_BINARY = "
- << ShortPath(m_Makefile->GetStartOutputDirectory())
+ << this->ShortPath(m_Makefile->GetStartOutputDirectory())
<< "\n";
fout << "CMAKE_SOURCE_DIR = "
- << ShortPath(m_Makefile->GetHomeDirectory()) << "\n";
+ << this->ShortPath(m_Makefile->GetHomeDirectory()) << "\n";
fout << "CMAKE_BINARY_DIR = "
- << ShortPath(m_Makefile->GetHomeOutputDirectory() )
+ << this->ShortPath(m_Makefile->GetHomeOutputDirectory() )
<< "\n";
// Output Include paths
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 6a2a56b..0b05373 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -1275,20 +1275,13 @@ bool cmSystemTools::RunCommand(const char* command,
std::string shortCmd;
std::string cmd = quoted.match(1);
std::string args = quoted.match(2);
- char *buffer = new char[cmd.size()+1];
- if(GetShortPathName(cmd.c_str(), buffer,
- int(cmd.size())) != 0)
+ if(!cmSystemTools::GetShortPath(cmd.c_str(), shortCmd))
{
- shortCmd = buffer;
- shortCmd += " ";
- shortCmd += args;
- }
- else
- {
- cmSystemTools::Error("Could not get GetShortPathName for ",
- cmd.c_str());
+ cmSystemTools::Error("GetShortPath failed for " , cmd.c_str());
return false;
}
+ shortCmd += " ";
+ shortCmd += args;
return RunCommandViaSystem(shortCmd.c_str(), dir,
output, retVal, verbose);
}
@@ -1845,3 +1838,44 @@ void cmSystemTools::ExpandListArguments(std::vector<std::string> const& argument
}
}
}
+
+bool cmSystemTools::GetShortPath(const char* path, std::string& shortPath)
+{
+#if defined(WIN32) && !defined(__CYGWIN__)
+ const int size = int(strlen(path)) +1; // size of return
+ char *buffer = new char[size]; // create a buffer
+ buffer[0] = 0;
+ int ret = GetShortPathName(path, buffer, size);
+ if(buffer[0] == 0 || ret > size)
+ {
+ if(ret < size)
+ {
+ LPVOID lpMsgBuf;
+ FormatMessage(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ GetLastError(),
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+ (LPTSTR) &lpMsgBuf,
+ 0,
+ NULL
+ );
+ cmSystemTools::Error((LPCTSTR)lpMsgBuf);
+ LocalFree( lpMsgBuf );
+ }
+ cmSystemTools::Error("Unable to get a short path: ", path);
+ return false;
+ }
+ else
+ {
+ shortPath = buffer;
+ delete [] buffer;
+ return true;
+ }
+#else
+ shortPath = path;
+ return true;
+#endif
+}
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h
index 04ee977..62d5568 100644
--- a/Source/cmSystemTools.h
+++ b/Source/cmSystemTools.h
@@ -267,6 +267,9 @@ public:
static bool RunCommand(const char* command, std::string& output,
int &retVal, const char* directory = 0, bool verbose = true);
+ ///! for windows return the short path for the given path, unix just a pass through
+ static bool GetShortPath(const char* path, std::string& result);
+
///! change directory the the directory specified
static int ChangeDirectory(const char* dir);
diff --git a/Source/cmaketest.cxx b/Source/cmaketest.cxx
index 37a3d98..4f35bcf 100644
--- a/Source/cmaketest.cxx
+++ b/Source/cmaketest.cxx
@@ -157,13 +157,7 @@ int main (int argc, char **argv)
#if defined(_WIN32) && !defined(__CYGWIN__)
if(makeCommand.find(' ') != std::string::npos)
{
- char *buffer = new char[makeCommand.size()+1];
- if(GetShortPathName(makeCommand.c_str(), buffer,
- int(makeCommand.size()+1)) != 0)
- {
- makeCommand = buffer;
- }
- delete [] buffer;\
+ cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
}
#endif
makeCommand += " ";
@@ -177,13 +171,7 @@ int main (int argc, char **argv)
#if defined(_WIN32) && !defined(__CYGWIN__)
if(makeCommand.find(' ') != std::string::npos)
{
- char *buffer = new char[makeCommand.size()+1];
- if(GetShortPathName(makeCommand.c_str(), buffer,
- int(makeCommand.size()+1)) != 0)
- {
- makeCommand = buffer;
- }
- delete [] buffer;\
+ cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
}
#endif
makeCommand += " ";