BUG: Fix executing and help

This commit is contained in:
Andy Cedilnik 2006-07-27 11:55:34 -04:00
parent 0b196d1aef
commit 7e3310e6e5
1 changed files with 115 additions and 112 deletions

View File

@ -306,140 +306,143 @@ int main (int argc, char *argv[])
{ {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR, cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"CPack generator not specified" << std::endl); "CPack generator not specified" << std::endl);
return 1; parsed = 0;
} }
std::vector<std::string> generatorsVector; else
cmSystemTools::ExpandListArgument(genList,
generatorsVector);
std::vector<std::string>::iterator it;
for ( it = generatorsVector.begin();
it != generatorsVector.end();
++it )
{ {
const char* gen = it->c_str(); std::vector<std::string> generatorsVector;
cmMakefile newMF(*globalMF); cmSystemTools::ExpandListArgument(genList,
cmMakefile* mf = &newMF; generatorsVector);
std::vector<std::string>::iterator it;
for ( it = generatorsVector.begin();
it != generatorsVector.end();
++it )
{ {
cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, const char* gen = it->c_str();
"Specified generator: " << gen << std::endl); cmMakefile newMF(*globalMF);
if ( parsed && !mf->GetDefinition("CPACK_PACKAGE_NAME") ) cmMakefile* mf = &newMF;
{ {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR, cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE,
"CPack project name not specified" << std::endl); "Specified generator: " << gen << std::endl);
parsed = 0; if ( parsed && !mf->GetDefinition("CPACK_PACKAGE_NAME") )
}
if ( parsed && !(mf->GetDefinition("CPACK_PACKAGE_VERSION")
|| mf->GetDefinition("CPACK_PACKAGE_VERSION_MAJOR") &&
mf->GetDefinition("CPACK_PACKAGE_VERSION_MINOR")
&& mf->GetDefinition("CPACK_PACKAGE_VERSION_PATCH")) )
{
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"CPack project version not specified" << std::endl
<< "Specify CPACK_PACKAGE_VERSION, or "
"CPACK_PACKAGE_VERSION_MAJOR, "
"CPACK_PACKAGE_VERSION_MINOR, and CPACK_PACKAGE_VERSION_PATCH."
<< std::endl);
parsed = 0;
}
if ( parsed )
{
cpackGenerator = generators.NewGenerator(gen);
if ( !cpackGenerator )
{ {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR, cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Cannot initialize CPack generator: " "CPack project name not specified" << std::endl);
<< generator.c_str() << std::endl);
parsed = 0; parsed = 0;
} }
if ( parsed && !cpackGenerator->Initialize(gen, mf, argv[0]) ) if ( parsed && !(mf->GetDefinition("CPACK_PACKAGE_VERSION")
|| mf->GetDefinition("CPACK_PACKAGE_VERSION_MAJOR") &&
mf->GetDefinition("CPACK_PACKAGE_VERSION_MINOR")
&& mf->GetDefinition("CPACK_PACKAGE_VERSION_PATCH")) )
{ {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR, cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Cannot initialize the generator" << std::endl); "CPack project version not specified" << std::endl
parsed = 0; << "Specify CPACK_PACKAGE_VERSION, or "
} "CPACK_PACKAGE_VERSION_MAJOR, "
"CPACK_PACKAGE_VERSION_MINOR, and CPACK_PACKAGE_VERSION_PATCH."
if ( !mf->GetDefinition("CPACK_INSTALL_COMMANDS") &&
!mf->GetDefinition("CPACK_INSTALLED_DIRECTORIES") &&
!mf->GetDefinition("CPACK_INSTALL_CMAKE_PROJECTS") )
{
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Please specify build tree of the project that uses CMake "
"using CPACK_INSTALL_CMAKE_PROJECTS, specify "
"CPACK_INSTALL_COMMANDS, or specify "
"CPACK_INSTALLED_DIRECTORIES."
<< std::endl); << std::endl);
parsed = 0; parsed = 0;
} }
} if ( parsed )
} {
cpackGenerator = generators.NewGenerator(gen);
if ( !parsed || help ) if ( !cpackGenerator )
{ {
doc.CheckOptions(argc, argv); cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
// Construct and print requested documentation. "Cannot initialize CPack generator: "
doc.SetName("cpack"); << generator.c_str() << std::endl);
doc.SetNameSection(cmDocumentationName); parsed = 0;
doc.SetUsageSection(cmDocumentationUsage); }
doc.SetDescriptionSection(cmDocumentationDescription); if ( parsed && !cpackGenerator->Initialize(gen, mf, argv[0]) )
doc.SetOptionsSection(cmDocumentationOptions); {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
std::vector<cmDocumentationEntry> v; "Cannot initialize the generator" << std::endl);
cmCPackGenerators::DescriptionsMap::const_iterator generatorIt; parsed = 0;
for( generatorIt = generators.GetGeneratorsList().begin(); }
generatorIt != generators.GetGeneratorsList().end();
++ generatorIt )
{
cmDocumentationEntry e;
e.name = generatorIt->first.c_str();
e.brief = generatorIt->second.c_str();
e.full = "";
v.push_back(e);
}
cmDocumentationEntry empty = {0,0,0};
v.push_back(empty);
doc.SetGeneratorsSection(&v[0]);
doc.SetSeeAlsoList(cmDocumentationSeeAlso);
#undef cout
return doc.PrintRequestedDocumentation(std::cout)? 0:1;
#define cout no_cout_use_cmCPack_Log
}
if ( !mf->GetDefinition("CPACK_INSTALL_COMMANDS") &&
!mf->GetDefinition("CPACK_INSTALLED_DIRECTORIES") &&
!mf->GetDefinition("CPACK_INSTALL_CMAKE_PROJECTS") )
{
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Please specify build tree of the project that uses CMake "
"using CPACK_INSTALL_CMAKE_PROJECTS, specify "
"CPACK_INSTALL_COMMANDS, or specify "
"CPACK_INSTALLED_DIRECTORIES."
<< std::endl);
parsed = 0;
}
#ifdef _WIN32 #ifdef _WIN32
std::string comspec = "cmw9xcom.exe"; std::string comspec = "cmw9xcom.exe";
cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str()); cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
#endif #endif
const char* projName = mf->GetDefinition("CPACK_PACKAGE_NAME"); const char* projName = mf->GetDefinition("CPACK_PACKAGE_NAME");
cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "Use generator: " cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "Use generator: "
<< cpackGenerator->GetNameOfClass() << std::endl); << cpackGenerator->GetNameOfClass() << std::endl);
cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "For project: " cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "For project: "
<< projName << std::endl); << projName << std::endl);
const char* projVersion = mf->GetDefinition("CPACK_PACKAGE_VERSION"); const char* projVersion = mf->GetDefinition("CPACK_PACKAGE_VERSION");
if ( !projVersion ) if ( !projVersion )
{ {
const char* projVersionMajor const char* projVersionMajor
= mf->GetDefinition("CPACK_PACKAGE_VERSION_MAJOR"); = mf->GetDefinition("CPACK_PACKAGE_VERSION_MAJOR");
const char* projVersionMinor const char* projVersionMinor
= mf->GetDefinition("CPACK_PACKAGE_VERSION_MINOR"); = mf->GetDefinition("CPACK_PACKAGE_VERSION_MINOR");
const char* projVersionPatch const char* projVersionPatch
= mf->GetDefinition("CPACK_PACKAGE_VERSION_PATCH"); = mf->GetDefinition("CPACK_PACKAGE_VERSION_PATCH");
cmOStringStream ostr; cmOStringStream ostr;
ostr << projVersionMajor << "." << projVersionMinor << "." ostr << projVersionMajor << "." << projVersionMinor << "."
<< projVersionPatch; << projVersionPatch;
mf->AddDefinition("CPACK_PACKAGE_VERSION", ostr.str().c_str()); mf->AddDefinition("CPACK_PACKAGE_VERSION", ostr.str().c_str());
} }
int res = cpackGenerator->ProcessGenerator(); int res = cpackGenerator->ProcessGenerator();
if ( !res ) if ( !res )
{ {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR, cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Error when generating package: " << projName << std::endl); "Error when generating package: " << projName << std::endl);
return 1; return 1;
}
}
}
} }
} }
} }
if ( !parsed || help )
{
doc.CheckOptions(argc, argv);
// Construct and print requested documentation.
doc.SetName("cpack");
doc.SetNameSection(cmDocumentationName);
doc.SetUsageSection(cmDocumentationUsage);
doc.SetDescriptionSection(cmDocumentationDescription);
doc.SetOptionsSection(cmDocumentationOptions);
std::vector<cmDocumentationEntry> v;
cmCPackGenerators::DescriptionsMap::const_iterator generatorIt;
for( generatorIt = generators.GetGeneratorsList().begin();
generatorIt != generators.GetGeneratorsList().end();
++ generatorIt )
{
cmDocumentationEntry e;
e.name = generatorIt->first.c_str();
e.brief = generatorIt->second.c_str();
e.full = "";
v.push_back(e);
}
cmDocumentationEntry empty = {0,0,0};
v.push_back(empty);
doc.SetGeneratorsSection(&v[0]);
doc.SetSeeAlsoList(cmDocumentationSeeAlso);
#undef cout
return doc.PrintRequestedDocumentation(std::cout)? 0:1;
#define cout no_cout_use_cmCPack_Log
}
return 0; return 0;
} }