diff options
author | Bill Hoffman <bill.hoffman@kitware.com> | 2006-07-24 15:19:42 (GMT) |
---|---|---|
committer | Bill Hoffman <bill.hoffman@kitware.com> | 2006-07-24 15:19:42 (GMT) |
commit | ecf914e6975b75166df2a0f36744221fe3b80899 (patch) | |
tree | fed23def8dcd0943d806ffe158d32e145f26e3bb /Source/CPack | |
parent | 3776cfa0eb5bd7e6d6863b2e342aadc7739bf90f (diff) | |
download | CMake-ecf914e6975b75166df2a0f36744221fe3b80899.zip CMake-ecf914e6975b75166df2a0f36744221fe3b80899.tar.gz CMake-ecf914e6975b75166df2a0f36744221fe3b80899.tar.bz2 |
ENH: move changes from main tree to release branch
Diffstat (limited to 'Source/CPack')
-rw-r--r-- | Source/CPack/cmCPackGenericGenerator.cxx | 267 | ||||
-rw-r--r-- | Source/CPack/cmCPackGenericGenerator.h | 9 | ||||
-rw-r--r-- | Source/CPack/cpack.cxx | 53 |
3 files changed, 197 insertions, 132 deletions
diff --git a/Source/CPack/cmCPackGenericGenerator.cxx b/Source/CPack/cmCPackGenericGenerator.cxx index f4e51b3..fac48dc 100644 --- a/Source/CPack/cmCPackGenericGenerator.cxx +++ b/Source/CPack/cmCPackGenericGenerator.cxx @@ -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,83 @@ 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) +{ + (void)movable; + (void)tempInstallDirectory; const char* installCommands = this->GetOption("CPACK_INSTALL_COMMANDS"); if ( installCommands && *installCommands ) { @@ -221,15 +283,36 @@ 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) +{ + (void)movable; + (void)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 +387,13 @@ 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 +521,14 @@ int cmCPackGenericGenerator::InstallProject() installComponent.c_str()); } - res = mf->ReadListFile(0, installFile.c_str()); - if ( cmSystemTools::GetErrorOccuredFlag() ) - { - 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 ) + int res = mf->ReadListFile(0, installFile.c_str()); + if ( cmSystemTools::GetErrorOccuredFlag() || !res ) { - 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 +562,32 @@ 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 +695,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 +703,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 +737,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 +745,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 +823,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; diff --git a/Source/CPack/cmCPackGenericGenerator.h b/Source/CPack/cmCPackGenericGenerator.h index 87c486d..a5a0ef7 100644 --- a/Source/CPack/cmCPackGenericGenerator.h +++ b/Source/CPack/cmCPackGenericGenerator.h @@ -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; diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index 49f6a70..90421f9 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -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,60 @@ 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, @@ -316,7 +335,8 @@ int main (int argc, char *argv[]) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "CPack project version not specified" << std::endl - << "Specify CPACK_PACKAGE_VERSION, or CPACK_PACKAGE_VERSION_MAJOR, " + << "Specify CPACK_PACKAGE_VERSION, or " + "CPACK_PACKAGE_VERSION_MAJOR, " "CPACK_PACKAGE_VERSION_MINOR, and CPACK_PACKAGE_VERSION_PATCH." << std::endl); parsed = 0; @@ -343,9 +363,10 @@ int main (int argc, char *argv[]) !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." + "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; } @@ -416,6 +437,8 @@ int main (int argc, char *argv[]) cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "Error when generating package: " << projName << std::endl); return 1; + } + } } return 0; |