ENH: Start working on a method that abstracts generating of build command

This commit is contained in:
Andy Cedilnik 2005-04-28 18:18:54 -04:00
parent 7c5745ae95
commit cb3ea2328a
4 changed files with 27 additions and 77 deletions

View File

@ -67,23 +67,16 @@ void cmGlobalVisualStudio6Generator::GenerateConfigurations(cmMakefile* mf)
} }
} }
int cmGlobalVisualStudio6Generator::Build( std::string cmGlobalVisualStudio6Generator::GenerateBuildCommand(const char* makeProgram, const char *projectName, const char *targetName,
const char *, const char* config)
const char *bindir,
const char *projectName,
const char *targetName,
std::string *output,
const char *makeCommandCSTR,
const char *config,
bool clean)
{ {
// now build the test // now build the test
std::vector<std::string> mp; std::vector<std::string> mp;
mp.push_back("[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\6.0\\Setup;VsCommonDir]/MSDev98/Bin"); mp.push_back("[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\6.0\\Setup;VsCommonDir]/MSDev98/Bin");
cmSystemTools::ExpandRegistryValues(mp[0]); cmSystemTools::ExpandRegistryValues(mp[0]);
std::string originalCommand = makeCommandCSTR; std::string originalCommand = makeProgram;
std::string makeCommand = std::string makeCommand =
cmSystemTools::FindProgram(makeCommandCSTR, mp); cmSystemTools::FindProgram(makeProgram, mp);
if(makeCommand.size() == 0) if(makeCommand.size() == 0)
{ {
std::string e = "Generator cannot find Visual Studio 6 msdev program \""; std::string e = "Generator cannot find Visual Studio 6 msdev program \"";
@ -91,15 +84,10 @@ int cmGlobalVisualStudio6Generator::Build(
e += "\" specified by CMAKE_MAKE_PROGRAM cache entry. "; e += "\" specified by CMAKE_MAKE_PROGRAM cache entry. ";
e += "Please fix the setting."; e += "Please fix the setting.";
cmSystemTools::Error(e.c_str()); cmSystemTools::Error(e.c_str());
return 1; return "";
} }
makeCommand = cmSystemTools::ConvertToOutputPath(makeCommand.c_str()); makeCommand = cmSystemTools::ConvertToOutputPath(makeCommand.c_str());
/**
* Run an executable command and put the stdout in output.
*/
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
cmSystemTools::ChangeDirectory(bindir);
// if there are spaces in the makeCommand, assume a full path // if there are spaces in the makeCommand, assume a full path
// and convert it to a path with no spaces in it as the // and convert it to a path with no spaces in it as the
// RunSingleCommand does not like spaces // RunSingleCommand does not like spaces
@ -112,6 +100,12 @@ int cmGlobalVisualStudio6Generator::Build(
makeCommand += " "; makeCommand += " ";
makeCommand += projectName; makeCommand += projectName;
makeCommand += ".dsw /MAKE \""; makeCommand += ".dsw /MAKE \"";
bool clean = false;
if ( targetName && strcmp(targetName, "clean") == 0 )
{
clean = true;
targetName = "ALL_BUILD";
}
if (targetName && strlen(targetName)) if (targetName && strlen(targetName))
{ {
makeCommand += targetName; makeCommand += targetName;
@ -131,30 +125,13 @@ int cmGlobalVisualStudio6Generator::Build(
} }
if(clean) if(clean)
{ {
makeCommand += "\" /REBUILD"; makeCommand += "\" /CLEAN";
} }
else else
{ {
makeCommand += "\" /BUILD"; makeCommand += "\" /BUILD";
} }
int retVal; return makeCommand;
int timeout = cmGlobalGenerator::s_TryCompileTimeout;
if (!cmSystemTools::RunSingleCommand(makeCommand.c_str(), output,
&retVal, 0, false, timeout))
{
std::string e = "Error executing make program \"";
e += originalCommand;
e += "\" specified by CMAKE_MAKE_PROGRAM cache entry. ";
e += "The command string used was \"";
e += makeCommand.c_str();
e += "\".";
cmSystemTools::Error(e.c_str());
// return to the original directory
cmSystemTools::ChangeDirectory(cwd.c_str());
return 1;
}
cmSystemTools::ChangeDirectory(cwd.c_str());
return retVal;
} }
///! Create a local generator appropriate to this Global Generator ///! Create a local generator appropriate to this Global Generator

View File

@ -54,11 +54,8 @@ public:
* Try running cmake and building a file. This is used for dynalically * Try running cmake and building a file. This is used for dynalically
* loaded commands, not as part of the usual build process. * loaded commands, not as part of the usual build process.
*/ */
virtual int Build(const char *srcdir, const char *bindir, virtual std::string GenerateBuildCommand(const char* makeProgram,
const char *projectName, const char *targetName, const char *projectName, const char *targetName, const char* config);
std::string *output,
const char *makeProgram,
const char *config, bool clean);
/** /**
* Generate the all required files for building this project/tree. This * Generate the all required files for building this project/tree. This

View File

@ -43,28 +43,14 @@ void cmGlobalVisualStudio7Generator::EnableLanguage(std::vector<std::string>cons
this->cmGlobalGenerator::EnableLanguage(lang, mf); this->cmGlobalGenerator::EnableLanguage(lang, mf);
} }
int cmGlobalVisualStudio7Generator::Build( std::string cmGlobalVisualStudio7Generator::GenerateBuildCommand(const char* makeProgram, const char *projectName, const char *targetName, const char* config)
const char *,
const char *bindir,
const char *projectName,
const char *targetName,
std::string *output,
const char *makeCommandCSTR,
const char *config,
bool clean)
{ {
// now build the test // now build the test
std::string makeCommand = std::string makeCommand =
cmSystemTools::ConvertToOutputPath(makeCommandCSTR); cmSystemTools::ConvertToOutputPath(makeProgram);
std::string lowerCaseCommand = makeCommand; std::string lowerCaseCommand = makeCommand;
cmSystemTools::LowerCase(lowerCaseCommand); cmSystemTools::LowerCase(lowerCaseCommand);
/**
* Run an executable command and put the stdout in output.
*/
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
cmSystemTools::ChangeDirectory(bindir);
// if there are spaces in the makeCommand, assume a full path // if there are spaces in the makeCommand, assume a full path
// and convert it to a path with no spaces in it as the // and convert it to a path with no spaces in it as the
// RunSingleCommand does not like spaces // RunSingleCommand does not like spaces
@ -77,9 +63,15 @@ int cmGlobalVisualStudio7Generator::Build(
makeCommand += " "; makeCommand += " ";
makeCommand += projectName; makeCommand += projectName;
makeCommand += ".sln "; makeCommand += ".sln ";
bool clean = false;
if ( targetName && strcmp(targetName, "clean") == 0 )
{
clean = true;
targetName = "ALL_BUILD";
}
if(clean) if(clean)
{ {
makeCommand += "/rebuild "; makeCommand += "/clean";
} }
else else
{ {
@ -104,20 +96,7 @@ int cmGlobalVisualStudio7Generator::Build(
{ {
makeCommand += "ALL_BUILD"; makeCommand += "ALL_BUILD";
} }
return makeCommand;
int retVal;
int timeout = cmGlobalGenerator::s_TryCompileTimeout;
if (!cmSystemTools::RunSingleCommand(makeCommand.c_str(), output, &retVal,
0, false, timeout))
{
cmSystemTools::Error("Generator: execution of devenv failed.");
// return to the original directory
cmSystemTools::ChangeDirectory(cwd.c_str());
return 1;
}
*output += makeCommand;
cmSystemTools::ChangeDirectory(cwd.c_str());
return retVal;
} }
///! Create a local generator appropriate to this Global Generator ///! Create a local generator appropriate to this Global Generator

View File

@ -53,11 +53,8 @@ public:
* Try running cmake and building a file. This is used for dynalically * Try running cmake and building a file. This is used for dynalically
* loaded commands, not as part of the usual build process. * loaded commands, not as part of the usual build process.
*/ */
virtual int Build(const char *srcdir, const char *bindir, virtual std::string GenerateBuildCommand(const char* makeProgram,
const char *projectName, const char *targetName, const char *projectName, const char *targetName, const char* config);
std::string *output,
const char *makeProgram,
const char *config, bool clean);
/** /**
* Generate the all required files for building this project/tree. This * Generate the all required files for building this project/tree. This