ENH: Several cleanups and support for multiple generators
This commit is contained in:
parent
fbdac25f81
commit
e36ae0fcb8
|
@ -92,13 +92,13 @@ cpack_check_file_exists("${CPACK_RESOURCE_FILE_WELCOME}" "welcome resource")
|
|||
IF(NOT CPACK_GENERATOR)
|
||||
IF(UNIX)
|
||||
IF(APPLE)
|
||||
SET(CPACK_GENERATOR "PackageMaker")
|
||||
SET(CPACK_GENERATOR "PackageMaker;STGZ;TGZ")
|
||||
ELSE(APPLE)
|
||||
SET(CPACK_GENERATOR "STGZ")
|
||||
SET(CPACK_GENERATOR "STGZ;TGZ;TZ")
|
||||
ENDIF(APPLE)
|
||||
SET(CPACK_SOURCE_GENERATOR "TGZ")
|
||||
SET(CPACK_SOURCE_GENERATOR "TGZ;TZ")
|
||||
ELSE(UNIX)
|
||||
SET(CPACK_GENERATOR "NSIS")
|
||||
SET(CPACK_GENERATOR "NSIS;ZIP")
|
||||
SET(CPACK_SOURCE_GENERATOR "ZIP")
|
||||
ENDIF(UNIX)
|
||||
ENDIF(NOT CPACK_GENERATOR)
|
||||
|
|
|
@ -142,6 +142,7 @@ int cmCPackGenericGenerator::PrepareNames()
|
|||
{
|
||||
this->SetOptionIfNotSet("CPACK_STRIP_COMMAND", pkgPath.c_str());
|
||||
}
|
||||
this->SetOptionIfNotSet("CPACK_REMOVE_TOPLEVEL_DIRECTORY", "1");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -150,23 +151,6 @@ int cmCPackGenericGenerator::PrepareNames()
|
|||
int cmCPackGenericGenerator::InstallProject()
|
||||
{
|
||||
cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Install projects" << std::endl);
|
||||
std::vector<cmsys::RegularExpression> ignoreFilesRegex;
|
||||
const char* cpackIgnoreFiles = this->GetOption("CPACK_IGNORE_FILES");
|
||||
if ( cpackIgnoreFiles )
|
||||
{
|
||||
std::vector<std::string> ignoreFilesRegexString;
|
||||
cmSystemTools::ExpandListArgument(cpackIgnoreFiles,
|
||||
ignoreFilesRegexString);
|
||||
std::vector<std::string>::iterator it;
|
||||
for ( it = ignoreFilesRegexString.begin();
|
||||
it != ignoreFilesRegexString.end();
|
||||
++it )
|
||||
{
|
||||
cmCPackLogger(cmCPackLog::LOG_VERBOSE,
|
||||
"Create ignore files regex for: " << it->c_str() << std::endl);
|
||||
ignoreFilesRegex.push_back(it->c_str());
|
||||
}
|
||||
}
|
||||
this->CleanTemporaryDirectory();
|
||||
const char* tempInstallDirectory
|
||||
= this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
|
||||
|
@ -178,6 +162,7 @@ int cmCPackGenericGenerator::InstallProject()
|
|||
<< std::endl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool movable = true;
|
||||
if ( movable )
|
||||
{
|
||||
|
@ -193,6 +178,77 @@ int cmCPackGenericGenerator::InstallProject()
|
|||
|
||||
// If the CPackConfig file sets CPACK_INSTALL_COMMANDS then run them
|
||||
// as listed
|
||||
if ( !this->InstallProjectViaInstallCommands(movable, tempInstallDirectory) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// If the CPackConfig file sets CPACK_INSTALLED_DIRECTORIES
|
||||
// then glob it and copy it to CPACK_TEMPORARY_DIRECTORY
|
||||
// This is used in Source packageing
|
||||
if ( !this->InstallProjectViaInstalledDirectories(movable, tempInstallDirectory) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// If the project is a CMAKE project then run pre-install
|
||||
// and then read the cmake_install script to run it
|
||||
if ( !this->InstallProjectViaInstallCMakeProjects(movable, tempInstallDirectory) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( !movable )
|
||||
{
|
||||
cmSystemTools::PutEnv("DESTDIR=");
|
||||
}
|
||||
|
||||
const char* stripExecutable = this->GetOption("CPACK_STRIP_COMMAND");
|
||||
const char* stripFiles
|
||||
= this->GetOption("CPACK_STRIP_FILES");
|
||||
if ( stripFiles && *stripFiles && stripExecutable && *stripExecutable )
|
||||
{
|
||||
cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Strip files" << std::endl);
|
||||
std::vector<std::string> stripFilesVector;
|
||||
cmSystemTools::ExpandListArgument(stripFiles,
|
||||
stripFilesVector);
|
||||
std::vector<std::string>::iterator it;
|
||||
for ( it = stripFilesVector.begin();
|
||||
it != stripFilesVector.end();
|
||||
++it )
|
||||
{
|
||||
std::string fileName = tempInstallDirectory;
|
||||
fileName += "/" + *it;
|
||||
cmCPackLogger(cmCPackLog::LOG_VERBOSE,
|
||||
" Strip file: " << fileName.c_str()
|
||||
<< std::endl);
|
||||
std::string stripCommand = stripExecutable;
|
||||
stripCommand += " \"";
|
||||
stripCommand += fileName + "\"";
|
||||
int retVal = 1;
|
||||
std::string output;
|
||||
bool resB =
|
||||
cmSystemTools::RunSingleCommand(stripCommand.c_str(), &output,
|
||||
&retVal, 0,
|
||||
this->GeneratorVerbose, 0);
|
||||
if ( !resB || retVal )
|
||||
{
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
||||
"Problem running install command: " << stripCommand.c_str()
|
||||
<< std::endl
|
||||
<< "Error was: \"" << output.c_str() << "\""
|
||||
<< std::endl);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
int cmCPackGenericGenerator::InstallProjectViaInstallCommands(bool movable, const char* tempInstallDirectory)
|
||||
{
|
||||
const char* installCommands = this->GetOption("CPACK_INSTALL_COMMANDS");
|
||||
if ( installCommands && *installCommands )
|
||||
{
|
||||
|
@ -221,15 +277,33 @@ int cmCPackGenericGenerator::InstallProject()
|
|||
"Problem running install command: " << it->c_str() << std::endl
|
||||
<< "Please check " << tmpFile.c_str() << " for errors"
|
||||
<< std::endl);
|
||||
res = 0;
|
||||
break;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// If the CPackConfig file sets CPACK_INSTALLED_DIRECTORIES
|
||||
// then glob it and copy it to CPACK_TEMPORARY_DIRECTORY
|
||||
// This is used in Source packageing
|
||||
//----------------------------------------------------------------------
|
||||
int cmCPackGenericGenerator::InstallProjectViaInstalledDirectories(bool movable, const char* tempInstallDirectory)
|
||||
{
|
||||
std::vector<cmsys::RegularExpression> ignoreFilesRegex;
|
||||
const char* cpackIgnoreFiles = this->GetOption("CPACK_IGNORE_FILES");
|
||||
if ( cpackIgnoreFiles )
|
||||
{
|
||||
std::vector<std::string> ignoreFilesRegexString;
|
||||
cmSystemTools::ExpandListArgument(cpackIgnoreFiles,
|
||||
ignoreFilesRegexString);
|
||||
std::vector<std::string>::iterator it;
|
||||
for ( it = ignoreFilesRegexString.begin();
|
||||
it != ignoreFilesRegexString.end();
|
||||
++it )
|
||||
{
|
||||
cmCPackLogger(cmCPackLog::LOG_VERBOSE,
|
||||
"Create ignore files regex for: " << it->c_str() << std::endl);
|
||||
ignoreFilesRegex.push_back(it->c_str());
|
||||
}
|
||||
}
|
||||
const char* installDirectories
|
||||
= this->GetOption("CPACK_INSTALLED_DIRECTORIES");
|
||||
if ( installDirectories && *installDirectories )
|
||||
|
@ -304,9 +378,12 @@ int cmCPackGenericGenerator::InstallProject()
|
|||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// If the project is a CMAKE project then run pre-install
|
||||
// and then read the cmake_install script to run it
|
||||
//----------------------------------------------------------------------
|
||||
int cmCPackGenericGenerator::InstallProjectViaInstallCMakeProjects(bool movable, const char* tempInstallDirectory)
|
||||
{
|
||||
const char* cmakeProjects
|
||||
= this->GetOption("CPACK_INSTALL_CMAKE_PROJECTS");
|
||||
const char* cmakeGenerator
|
||||
|
@ -434,96 +511,14 @@ int cmCPackGenericGenerator::InstallProject()
|
|||
installComponent.c_str());
|
||||
}
|
||||
|
||||
res = mf->ReadListFile(0, installFile.c_str());
|
||||
if ( cmSystemTools::GetErrorOccuredFlag() )
|
||||
int res = mf->ReadListFile(0, installFile.c_str());
|
||||
if ( cmSystemTools::GetErrorOccuredFlag() || !res )
|
||||
{
|
||||
res = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ?????
|
||||
const char* binaryDirectories = this->GetOption("CPACK_BINARY_DIR");
|
||||
if ( binaryDirectories && !cmakeProjects )
|
||||
{
|
||||
std::vector<std::string> binaryDirectoriesVector;
|
||||
cmSystemTools::ExpandListArgument(binaryDirectories,
|
||||
binaryDirectoriesVector);
|
||||
std::vector<std::string>::iterator it;
|
||||
for ( it = binaryDirectoriesVector.begin();
|
||||
it != binaryDirectoriesVector.end();
|
||||
++it )
|
||||
{
|
||||
std::string installFile = it->c_str();
|
||||
installFile += "/cmake_install.cmake";
|
||||
cmake cm;
|
||||
cmGlobalGenerator gg;
|
||||
gg.SetCMakeInstance(&cm);
|
||||
std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
|
||||
lg->SetGlobalGenerator(&gg);
|
||||
cmMakefile *mf = lg->GetMakefile();
|
||||
if ( movable )
|
||||
{
|
||||
mf->AddDefinition("CMAKE_INSTALL_PREFIX", tempInstallDirectory);
|
||||
}
|
||||
const char* buildConfig = this->GetOption("CPACK_BUILD_CONFIG");
|
||||
if ( buildConfig && *buildConfig )
|
||||
{
|
||||
mf->AddDefinition("BUILD_TYPE", buildConfig);
|
||||
}
|
||||
|
||||
res = mf->ReadListFile(0, installFile.c_str());
|
||||
if ( cmSystemTools::GetErrorOccuredFlag() )
|
||||
{
|
||||
res = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( !movable )
|
||||
{
|
||||
cmSystemTools::PutEnv("DESTDIR=");
|
||||
}
|
||||
|
||||
const char* stripExecutable = this->GetOption("CPACK_STRIP_COMMAND");
|
||||
const char* stripFiles
|
||||
= this->GetOption("CPACK_STRIP_FILES");
|
||||
if ( stripFiles && *stripFiles && stripExecutable && *stripExecutable )
|
||||
{
|
||||
cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Strip files" << std::endl);
|
||||
std::vector<std::string> stripFilesVector;
|
||||
cmSystemTools::ExpandListArgument(stripFiles,
|
||||
stripFilesVector);
|
||||
std::vector<std::string>::iterator it;
|
||||
for ( it = stripFilesVector.begin();
|
||||
it != stripFilesVector.end();
|
||||
++it )
|
||||
{
|
||||
std::string fileName = tempInstallDirectory;
|
||||
fileName += "/" + *it;
|
||||
cmCPackLogger(cmCPackLog::LOG_VERBOSE,
|
||||
" Strip file: " << fileName.c_str()
|
||||
<< std::endl);
|
||||
std::string stripCommand = stripExecutable;
|
||||
stripCommand += " \"";
|
||||
stripCommand += fileName + "\"";
|
||||
int retVal = 1;
|
||||
std::string output;
|
||||
bool resB =
|
||||
cmSystemTools::RunSingleCommand(stripCommand.c_str(), &output,
|
||||
&retVal, 0,
|
||||
this->GeneratorVerbose, 0);
|
||||
if ( !resB || retVal )
|
||||
{
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
||||
"Problem running install command: " << stripCommand.c_str()
|
||||
<< std::endl
|
||||
<< "Error was: \"" << output.c_str() << "\""
|
||||
<< std::endl);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -557,10 +552,30 @@ void cmCPackGenericGenerator::SetOption(const char* op, const char* value)
|
|||
//----------------------------------------------------------------------
|
||||
int cmCPackGenericGenerator::ProcessGenerator()
|
||||
{
|
||||
cmCPackLogger(cmCPackLog::LOG_OUTPUT,
|
||||
"Create package using " << this->Name.c_str() << std::endl);
|
||||
|
||||
if ( !this->PrepareNames() )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if ( cmSystemTools::IsOn(this->GetOption("CPACK_REMOVE_TOPLEVEL_DIRECTORY")) )
|
||||
{
|
||||
const char* toplevelDirectory = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
|
||||
if ( cmSystemTools::FileExists(toplevelDirectory) )
|
||||
{
|
||||
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Remove toplevel directory: "
|
||||
<< toplevelDirectory << std::endl);
|
||||
if ( !cmSystemTools::RemoveADirectory(toplevelDirectory) )
|
||||
{
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
||||
"Problem removing toplevel directory: "
|
||||
<< toplevelDirectory
|
||||
<< std::endl);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( !this->InstallProject() )
|
||||
{
|
||||
return 0;
|
||||
|
@ -668,7 +683,7 @@ int cmCPackGenericGenerator::FindRunningCMake(const char* arg0)
|
|||
{
|
||||
failures.push_back(this->CPackSelf);
|
||||
cmOStringStream msg;
|
||||
msg << "CTEST can not find the command line program ctest.\n";
|
||||
msg << "CPack can not find the command line program ctest.\n";
|
||||
msg << " argv[0] = \"" << arg0 << "\"\n";
|
||||
msg << " Attempted paths:\n";
|
||||
std::vector<cmStdString>::iterator i;
|
||||
|
@ -676,7 +691,9 @@ int cmCPackGenericGenerator::FindRunningCMake(const char* arg0)
|
|||
{
|
||||
msg << " \"" << i->c_str() << "\"\n";
|
||||
}
|
||||
cmSystemTools::Error(msg.str().c_str());
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, msg.str().c_str()
|
||||
<< std::endl);
|
||||
return 0;
|
||||
}
|
||||
std::string dir;
|
||||
std::string file;
|
||||
|
@ -708,7 +725,7 @@ int cmCPackGenericGenerator::FindRunningCMake(const char* arg0)
|
|||
{
|
||||
failures.push_back(this->CMakeSelf);
|
||||
cmOStringStream msg;
|
||||
msg << "CTEST can not find the command line program cmake.\n";
|
||||
msg << "CPack can not find the command line program cmake.\n";
|
||||
msg << " argv[0] = \"" << arg0 << "\"\n";
|
||||
msg << " Attempted paths:\n";
|
||||
std::vector<cmStdString>::iterator i;
|
||||
|
@ -716,7 +733,9 @@ int cmCPackGenericGenerator::FindRunningCMake(const char* arg0)
|
|||
{
|
||||
msg << " \"" << i->c_str() << "\"\n";
|
||||
}
|
||||
cmSystemTools::Error(msg.str().c_str());
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, msg.str().c_str()
|
||||
<< std::endl);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
// do CMAKE_ROOT, look for the environment variable first
|
||||
|
@ -792,10 +811,12 @@ int cmCPackGenericGenerator::FindRunningCMake(const char* arg0)
|
|||
if (!cmSystemTools::FileExists(modules.c_str()))
|
||||
{
|
||||
// couldn't find modules
|
||||
cmSystemTools::Error("Could not find CMAKE_ROOT !!!\n"
|
||||
"CMake has most likely not been installed correctly.\n"
|
||||
"Modules directory not found in\n",
|
||||
cMakeRoot.c_str());
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
||||
"Could not find CMAKE_ROOT !!!" << std::endl
|
||||
<< "CMake has most likely not been installed correctly." << std::endl
|
||||
<<"Modules directory not found in" << std::endl
|
||||
<< cMakeRoot.c_str()
|
||||
<< std::endl);
|
||||
return 0;
|
||||
}
|
||||
this->CMakeRoot = cMakeRoot;
|
||||
|
|
|
@ -106,6 +106,15 @@ protected:
|
|||
virtual bool ConfigureString(const std::string& input, std::string& output);
|
||||
virtual int InitializeInternal();
|
||||
|
||||
|
||||
//! Run install commands if specified
|
||||
virtual int InstallProjectViaInstallCommands(
|
||||
bool movable, const char* tempInstallDirectory);
|
||||
virtual int InstallProjectViaInstalledDirectories(
|
||||
bool movable, const char* tempInstallDirectory);
|
||||
virtual int InstallProjectViaInstallCMakeProjects(
|
||||
bool movable, const char* tempInstallDirectory);
|
||||
|
||||
bool GeneratorVerbose;
|
||||
std::string Name;
|
||||
|
||||
|
|
|
@ -221,7 +221,7 @@ int main (int argc, char *argv[])
|
|||
cmGlobalGenerator cmgg;
|
||||
cmgg.SetCMakeInstance(&cminst);
|
||||
cmLocalGenerator* cmlg = cmgg.CreateLocalGenerator();
|
||||
cmMakefile* mf = cmlg->GetMakefile();
|
||||
cmMakefile* globalMF = cmlg->GetMakefile();
|
||||
|
||||
bool cpackConfigFileSpecified = true;
|
||||
if ( cpackConfigFile.empty() )
|
||||
|
@ -247,7 +247,10 @@ int main (int argc, char *argv[])
|
|||
{
|
||||
cpackConfigFile =
|
||||
cmSystemTools::CollapseFullPath(cpackConfigFile.c_str());
|
||||
if ( !mf->ReadListFile(0, cpackConfigFile.c_str()) )
|
||||
cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE,
|
||||
"Read CPack configuration file: " << cpackConfigFile.c_str()
|
||||
<< std::endl);
|
||||
if ( !globalMF->ReadListFile(0, cpackConfigFile.c_str()) )
|
||||
{
|
||||
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
|
||||
"Problem reding CPack config file: \""
|
||||
|
@ -265,44 +268,58 @@ int main (int argc, char *argv[])
|
|||
|
||||
if ( !generator.empty() )
|
||||
{
|
||||
mf->AddDefinition("CPACK_GENERATOR", generator.c_str());
|
||||
globalMF->AddDefinition("CPACK_GENERATOR", generator.c_str());
|
||||
}
|
||||
if ( !cpackProjectName.empty() )
|
||||
{
|
||||
mf->AddDefinition("CPACK_PACKAGE_NAME", cpackProjectName.c_str());
|
||||
globalMF->AddDefinition("CPACK_PACKAGE_NAME", cpackProjectName.c_str());
|
||||
}
|
||||
if ( !cpackProjectVersion.empty() )
|
||||
{
|
||||
mf->AddDefinition("CPACK_PACKAGE_VERSION", cpackProjectVersion.c_str());
|
||||
globalMF->AddDefinition("CPACK_PACKAGE_VERSION", cpackProjectVersion.c_str());
|
||||
}
|
||||
if ( !cpackProjectVendor.empty() )
|
||||
{
|
||||
mf->AddDefinition("CPACK_PACKAGE_VENDOR", cpackProjectVendor.c_str());
|
||||
globalMF->AddDefinition("CPACK_PACKAGE_VENDOR", cpackProjectVendor.c_str());
|
||||
}
|
||||
if ( !cpackProjectDirectory.empty() )
|
||||
{
|
||||
mf->AddDefinition("CPACK_PACKAGE_DIRECTORY",
|
||||
globalMF->AddDefinition("CPACK_PACKAGE_DIRECTORY",
|
||||
cpackProjectDirectory.c_str());
|
||||
}
|
||||
if ( !cpackBuildConfig.empty() )
|
||||
{
|
||||
mf->AddDefinition("CPACK_BUILD_CONFIG", cpackBuildConfig.c_str());
|
||||
globalMF->AddDefinition("CPACK_BUILD_CONFIG", cpackBuildConfig.c_str());
|
||||
}
|
||||
cpackDefinitions::MapType::iterator cdit;
|
||||
for ( cdit = definitions.Map.begin();
|
||||
cdit != definitions.Map.end();
|
||||
++cdit )
|
||||
{
|
||||
mf->AddDefinition(cdit->first.c_str(), cdit->second.c_str());
|
||||
globalMF->AddDefinition(cdit->first.c_str(), cdit->second.c_str());
|
||||
}
|
||||
|
||||
const char* gen = mf->GetDefinition("CPACK_GENERATOR");
|
||||
if ( !gen )
|
||||
const char* genList = globalMF->GetDefinition("CPACK_GENERATOR");
|
||||
if ( !genList )
|
||||
{
|
||||
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
|
||||
"CPack generator not specified" << std::endl);
|
||||
parsed = 0;
|
||||
}
|
||||
std::vector<std::string> generatorsVector;
|
||||
cmSystemTools::ExpandListArgument(genList,
|
||||
generatorsVector);
|
||||
std::vector<std::string>::iterator it;
|
||||
for ( it = generatorsVector.begin();
|
||||
it != generatorsVector.end();
|
||||
++it )
|
||||
{
|
||||
const char* gen = it->c_str();
|
||||
cmMakefile newMF(*globalMF);
|
||||
cmMakefile* mf = &newMF;
|
||||
{
|
||||
cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE,
|
||||
"Specified generator: " << gen << std::endl);
|
||||
if ( parsed && !mf->GetDefinition("CPACK_PACKAGE_NAME") )
|
||||
{
|
||||
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
|
||||
|
@ -417,6 +434,8 @@ int main (int argc, char *argv[])
|
|||
"Error when generating package: " << projName << std::endl);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue