From c09c3c6bfadb41bd0b43082642ce76abbf02df06 Mon Sep 17 00:00:00 2001 From: Andy Cedilnik Date: Sat, 15 Apr 2006 13:02:18 -0400 Subject: ENH: Support for packaging source, several cleanups and more yeehaa... --- Modules/CPack.cmake | 51 ++++++++++++++---- Source/CPack/cmCPackGenericGenerator.cxx | 77 +++++++++++++++++++++++++-- Source/CPack/cmCPackGenericGenerator.h | 4 +- Source/CPack/cmCPackNSISGenerator.cxx | 13 ++--- Source/CPack/cmCPackNSISGenerator.h | 6 +-- Source/CPack/cmCPackPackageMakerGenerator.cxx | 9 +--- Source/CPack/cmCPackPackageMakerGenerator.h | 6 +-- Source/CPack/cmCPackSTGZGenerator.cxx | 7 +++ Source/CPack/cmCPackSTGZGenerator.h | 1 + Source/CPack/cmCPackTGZGenerator.cxx | 7 +++ Source/CPack/cmCPackTGZGenerator.h | 1 + Source/CPack/cmCPackZIPGenerator.cxx | 16 +++--- Source/CPack/cmCPackZIPGenerator.h | 5 +- 13 files changed, 150 insertions(+), 53 deletions(-) diff --git a/Modules/CPack.cmake b/Modules/CPack.cmake index 06313c7..2777dc1 100644 --- a/Modules/CPack.cmake +++ b/Modules/CPack.cmake @@ -3,6 +3,10 @@ SET(cpack_input_file "${CMAKE_ROOT}/Templates/CPackConfig.cmake.in") IF(EXISTS "${CMAKE_SOURCE_DIR}/CPackConfig.cmake.in") SET(cpack_input_file "${CMAKE_SOURCE_DIR}/CPackConfig.cmake.in") ENDIF(EXISTS "${CMAKE_SOURCE_DIR}/CPackConfig.cmake.in") +SET(cpack_source_input_file "${CMAKE_ROOT}/Templates/CPackConfig.cmake.in") +IF(EXISTS "${CMAKE_SOURCE_DIR}/CPackSourceConfig.cmake.in") + SET(cpack_source_input_file "${CMAKE_SOURCE_DIR}/CPackSourceConfig.cmake.in") +ENDIF(EXISTS "${CMAKE_SOURCE_DIR}/CPackSourceConfig.cmake.in") # Macro for setting values if a user did not overwrite them MACRO(cpack_set_if_not_set name value) @@ -11,6 +15,19 @@ MACRO(cpack_set_if_not_set name value) ENDIF(NOT DEFINED "${name}") ENDMACRO(cpack_set_if_not_set) +# Macro to encode variables for the configuration file +MACRO(cpack_encode_variables) + SET(_CPACK_OTHER_VARIABLES_) + GET_CMAKE_PROPERTY(res VARIABLES) + FOREACH(var ${res}) + IF("xxx${var}" MATCHES "xxxCPACK") + SET(_CPACK_OTHER_VARIABLES_ + "${_CPACK_OTHER_VARIABLES_}\nSET(${var} \"${${var}}\")") + ENDIF("xxx${var}" MATCHES "xxxCPACK") + ENDFOREACH(var ${res}) +ENDMACRO(cpack_encode_variables) + + # Set the package name cpack_set_if_not_set(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}") cpack_set_if_not_set(CPACK_PACKAGE_VERSION_MAJOR "0") @@ -61,24 +78,38 @@ IF(NOT CPACK_GENERATOR) ELSE(APPLE) SET(CPACK_GENERATOR "STGZ") ENDIF(APPLE) + SET(CPACK_SOURCE_GENERATOR "TGZ") ELSE(UNIX) SET(CPACK_GENERATOR "NSIS") + SET(CPACK_SOURCE_GENERATOR "ZIP") ENDIF(UNIX) ENDIF(NOT CPACK_GENERATOR) # Set some other variables -cpack_set_if_not_set(CPACK_BINARY_DIR "${CMAKE_BINARY_DIR}") cpack_set_if_not_set(CPACK_INSTALL_CMAKE_PROJECTS "${CMAKE_BINARY_DIR};${CMAKE_PROJECT_NAME};ALL;/") cpack_set_if_not_set(CPACK_CMAKE_GENERATOR "${CMAKE_GENERATOR}") +cpack_set_if_not_set(CPACK_TOPLEVEL_TAG "${CMAKE_SYSTEM_NAME}") + +cpack_encode_variables() +CONFIGURE_FILE("${cpack_input_file}" + "${CMAKE_BINARY_DIR}/CPackConfig.cmake" @ONLY IMMEDIATE) -SET(_CPACK_UNUSED_VARIABLES_) -GET_CMAKE_PROPERTY(res VARIABLES) -FOREACH(var ${res}) - IF("xxx${var}" MATCHES "xxxCPACK") - SET(_CPACK_OTHER_VARIABLES_ - "${_CPACK_OTHER_VARIABLES_}\nSET(${var} \"${${var}}\")") - ENDIF("xxx${var}" MATCHES "xxxCPACK") -ENDFOREACH(var ${res}) +# Generate source file +cpack_set_if_not_set(CPACK_SOURCE_INSTALLED_DIRECTORIES + "${CMAKE_SOURCE_DIR};/") +cpack_set_if_not_set(CPACK_SOURCE_TOPLEVEL_TAG "${CMAKE_SYSTEM_NAME}-Source") +cpack_set_if_not_set(CPACK_SOURCE_PACKAGE_FILE_NAME + "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}-Source") +cpack_set_if_not_set(CPACK_SOURCE_IGNORE_FILES + "/CVS/;/\\\\\\\\.svn/;\\\\\\\\.swp$;\\\\\\\\.#") +SET(CPACK_INSTALL_CMAKE_PROJECTS "${CPACK_SOURCE_INSTALL_CMAKE_PROJECTS}") +SET(CPACK_INSTALLED_DIRECTORIES "${CPACK_SOURCE_INSTALLED_DIRECTORIES}") +SET(CPACK_GENERATOR "${CPACK_SOURCE_GENERATOR}") +SET(CPACK_TOPLEVEL_TAG "${CPACK_SOURCE_TOPLEVEL_TAG}") +SET(CPACK_PACKAGE_FILE_NAME "${CPACK_SOURCE_PACKAGE_FILE_NAME}") +SET(CPACK_IGNORE_FILES "${CPACK_SOURCE_IGNORE_FILES}") -CONFIGURE_FILE("${cpack_input_file}" "${CMAKE_BINARY_DIR}/CPackConfig.cmake" @ONLY IMMEDIATE) +cpack_encode_variables() +CONFIGURE_FILE("${cpack_source_input_file}" + "${CMAKE_BINARY_DIR}/CPackSourceConfig.cmake" @ONLY IMMEDIATE) diff --git a/Source/CPack/cmCPackGenericGenerator.cxx b/Source/CPack/cmCPackGenericGenerator.cxx index a26f1e2..7d7975e 100644 --- a/Source/CPack/cmCPackGenericGenerator.cxx +++ b/Source/CPack/cmCPackGenericGenerator.cxx @@ -48,6 +48,12 @@ int cmCPackGenericGenerator::PrepareNames() this->SetOption("CPACK_GENERATOR", this->Name.c_str()); std::string tempDirectory = this->GetOption("CPACK_PACKAGE_DIRECTORY"); tempDirectory += "/_CPack_Packages/"; + const char* toplevelTag = this->GetOption("CPACK_TOPLEVEL_TAG"); + if ( toplevelTag ) + { + tempDirectory += toplevelTag; + tempDirectory += "/"; + } tempDirectory += this->GetOption("CPACK_GENERATOR"); std::string topDirectory = tempDirectory; @@ -120,6 +126,22 @@ int cmCPackGenericGenerator::PrepareNames() int cmCPackGenericGenerator::InstallProject() { cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Install projects" << std::endl); + std::vector ignoreFilesRegex; + const char* cpackIgnoreFiles = this->GetOption("CPACK_IGNORE_FILES"); + if ( cpackIgnoreFiles ) + { + std::vector ignoreFilesRegexString; + cmSystemTools::ExpandListArgument(cpackIgnoreFiles,ignoreFilesRegexString); + std::vector::iterator it; + for ( it = ignoreFilesRegexString.begin(); + it != ignoreFilesRegexString.end(); + ++it ) + { + cmCPackLogger(cmCPackLog::LOG_OUTPUT, + "Create ignore files regex for: " << it->c_str() << std::endl); + ignoreFilesRegex.push_back(it->c_str()); + } + } const char* tempInstallDirectory = this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY"); int res = 1; @@ -143,7 +165,7 @@ int cmCPackGenericGenerator::InstallProject() cmSystemTools::PutEnv(destDir.c_str()); } const char* installCommands = this->GetOption("CPACK_INSTALL_COMMANDS"); - if ( installCommands ) + if ( installCommands && *installCommands ) { std::vector installCommandsVector; cmSystemTools::ExpandListArgument(installCommands,installCommandsVector); @@ -177,7 +199,7 @@ int cmCPackGenericGenerator::InstallProject() } const char* installDirectories = this->GetOption("CPACK_INSTALLED_DIRECTORIES"); - if ( installDirectories ) + if ( installDirectories && *installDirectories ) { std::vector installDirectoriesVector; cmSystemTools::ExpandListArgument(installDirectories, @@ -203,6 +225,8 @@ int cmCPackGenericGenerator::InstallProject() std::string subdir = it->c_str(); std::string findExpr = toplevel; findExpr += "/*"; + cmCPackLogger(cmCPackLog::LOG_OUTPUT, + "- Install directory: " << toplevel << std::endl); gl.RecurseOn(); if ( !gl.FindFiles(findExpr) ) { @@ -212,12 +236,29 @@ int cmCPackGenericGenerator::InstallProject() } std::vector& files = gl.GetFiles(); std::vector::iterator gfit; + std::vector::iterator regIt; for ( gfit = files.begin(); gfit != files.end(); ++ gfit ) { + bool skip = false; + std::string &inFile = *gfit; + for ( regIt= ignoreFilesRegex.begin(); + regIt!= ignoreFilesRegex.end(); + ++ regIt) + { + if ( regIt->find(inFile.c_str()) ) + { + cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Ignore file: " + << inFile.c_str() << std::endl); + skip = true; + } + } + if ( skip ) + { + continue; + } std::string filePath = tempDir; filePath += "/" + subdir + "/" + cmSystemTools::RelativePath(toplevel.c_str(), gfit->c_str()); - std::string &inFile = *gfit; cmCPackLogger(cmCPackLog::LOG_DEBUG, "Copy file: " << inFile.c_str() << " -> " << filePath.c_str() << std::endl); if ( !cmSystemTools::CopyFileIfDifferent(inFile.c_str(), @@ -234,7 +275,7 @@ int cmCPackGenericGenerator::InstallProject() = this->GetOption("CPACK_INSTALL_CMAKE_PROJECTS"); const char* cmakeGenerator = this->GetOption("CPACK_CMAKE_GENERATOR"); - if ( cmakeProjects ) + if ( cmakeProjects && *cmakeProjects ) { if ( !cmakeGenerator ) { @@ -324,6 +365,11 @@ int cmCPackGenericGenerator::InstallProject() std::auto_ptr lg(gg.CreateLocalGenerator()); lg->SetGlobalGenerator(&gg); cmMakefile *mf = lg->GetMakefile(); + std::string realInstallDirectory = tempInstallDirectory; + if ( !installSubDirectory.empty() && installSubDirectory != "/" ) + { + realInstallDirectory += installSubDirectory; + } if ( movable ) { mf->AddDefinition("CMAKE_INSTALL_PREFIX", tempInstallDirectory); @@ -332,6 +378,12 @@ int cmCPackGenericGenerator::InstallProject() { mf->AddDefinition("BUILD_TYPE", buildConfig); } + std::string installComponentLowerCase + = cmSystemTools::LowerCase(installComponent); + if ( installComponentLowerCase != "all" ) + { + mf->AddDefinition("CMAKE_INSTALL_COMPONENT", installComponent.c_str()); + } res = mf->ReadListFile(0, installFile.c_str()); if ( cmSystemTools::GetErrorOccuredFlag() ) @@ -384,6 +436,17 @@ int cmCPackGenericGenerator::InstallProject() } //---------------------------------------------------------------------- +void cmCPackGenericGenerator::SetOptionIfNotSet(const char* op, + const char* value) +{ + if ( this->MakefileMap->GetDefinition(op) ) + { + return; + } + this->SetOption(op, value); +} + +//---------------------------------------------------------------------- void cmCPackGenericGenerator::SetOption(const char* op, const char* value) { if ( !op ) @@ -473,6 +536,12 @@ int cmCPackGenericGenerator::Initialize(const char* name, cmMakefile* mf) { this->MakefileMap = mf; this->Name = name; + return this->InitializeInternal(); +} + +//---------------------------------------------------------------------- +int cmCPackGenericGenerator::InitializeInternal() +{ return 1; } diff --git a/Source/CPack/cmCPackGenericGenerator.h b/Source/CPack/cmCPackGenericGenerator.h index f553f31..40e8740 100644 --- a/Source/CPack/cmCPackGenericGenerator.h +++ b/Source/CPack/cmCPackGenericGenerator.h @@ -68,7 +68,7 @@ public: /** * Initialize generator */ - virtual int Initialize(const char* name, cmMakefile* mf); + int Initialize(const char* name, cmMakefile* mf); /** * Construct generator @@ -78,6 +78,7 @@ public: //! Set and get the options void SetOption(const char* op, const char* value); + void SetOptionIfNotSet(const char* op, const char* value); const char* GetOption(const char* op); //! Set all the variables @@ -99,6 +100,7 @@ protected: virtual std::string FindTemplate(const char* name); virtual bool ConfigureFile(const char* inName, const char* outName); + virtual int InitializeInternal(); bool GeneratorVerbose; std::string Name; diff --git a/Source/CPack/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx index f4afea1..2f5363d 100644 --- a/Source/CPack/cmCPackNSISGenerator.cxx +++ b/Source/CPack/cmCPackNSISGenerator.cxx @@ -115,17 +115,14 @@ int cmCPackNSISGenerator::CompressFiles(const char* outFileName, } //---------------------------------------------------------------------- -int cmCPackNSISGenerator::Initialize(const char* name, cmMakefile* mf) +int cmCPackNSISGenerator::InitializeInternal() { - int res = this->Superclass::Initialize(name, mf); - if ( !res ) - { - return res; - } if ( cmSystemTools::IsOn(this->GetOption( "CPACK_INCLUDE_TOPLEVEL_DIRECTORY")) ) { - cmCPackLogger(cmCPackLog::LOG_ERROR, "NSIS Generator cannot work with CPACK_INCLUDE_TOPLEVEL_DIRECTORY. This option will be ignored." + cmCPackLogger(cmCPackLog::LOG_ERROR, + "NSIS Generator cannot work with CPACK_INCLUDE_TOPLEVEL_DIRECTORY. " + "This option will be ignored." << std::endl); this->SetOption("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", 0); } @@ -222,7 +219,7 @@ int cmCPackNSISGenerator::Initialize(const char* name, cmMakefile* mf) this->SetOption("CPACK_NSIS_DELETE_ICONS", deleteStr.str().c_str()); } - return res; + return this->Superclass::InitializeInternal(); } //---------------------------------------------------------------------- diff --git a/Source/CPack/cmCPackNSISGenerator.h b/Source/CPack/cmCPackNSISGenerator.h index c22f979..db3fd67 100644 --- a/Source/CPack/cmCPackNSISGenerator.h +++ b/Source/CPack/cmCPackNSISGenerator.h @@ -32,17 +32,13 @@ public: cmCPackTypeMacro(cmCPackNSISGenerator, cmCPackGenericGenerator); /** - * Initialize generator - */ - virtual int Initialize(const char* name, cmMakefile* mf); - - /** * Construct generator */ cmCPackNSISGenerator(); virtual ~cmCPackNSISGenerator(); protected: + virtual int InitializeInternal(); int CompressFiles(const char* outFileName, const char* toplevel, const std::vector& files); virtual const char* GetOutputExtension() { return "exe"; } diff --git a/Source/CPack/cmCPackPackageMakerGenerator.cxx b/Source/CPack/cmCPackPackageMakerGenerator.cxx index b667415..1d6cb35 100644 --- a/Source/CPack/cmCPackPackageMakerGenerator.cxx +++ b/Source/CPack/cmCPackPackageMakerGenerator.cxx @@ -137,13 +137,8 @@ int cmCPackPackageMakerGenerator::CompressFiles(const char* outFileName, } //---------------------------------------------------------------------- -int cmCPackPackageMakerGenerator::Initialize(const char* name, cmMakefile* mf) +int cmCPackPackageMakerGenerator::InitializeInternal() { - int res = this->Superclass::Initialize(name, mf); - if ( !res ) - { - return res; - } cmCPackLogger(cmCPackLog::LOG_DEBUG, "cmCPackPackageMakerGenerator::Initialize()" << std::endl); std::vector path; @@ -228,7 +223,7 @@ int cmCPackPackageMakerGenerator::Initialize(const char* name, cmMakefile* mf) } this->SetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE", pkgPath.c_str()); - return res; + return this->Superclass::InitializeInternal(); } //---------------------------------------------------------------------- diff --git a/Source/CPack/cmCPackPackageMakerGenerator.h b/Source/CPack/cmCPackPackageMakerGenerator.h index 56bdbb74..b7881de 100644 --- a/Source/CPack/cmCPackPackageMakerGenerator.h +++ b/Source/CPack/cmCPackPackageMakerGenerator.h @@ -33,17 +33,13 @@ public: cmCPackTypeMacro(cmCPackPackageMakerGenerator, cmCPackGenericGenerator); /** - * Initialize generator - */ - virtual int Initialize(const char* name, cmMakefile* mf); - - /** * Construct generator */ cmCPackPackageMakerGenerator(); virtual ~cmCPackPackageMakerGenerator(); protected: + virtual int InitializeInternal(); int CompressFiles(const char* outFileName, const char* toplevel, const std::vector& files); virtual const char* GetOutputExtension() { return "dmg"; } diff --git a/Source/CPack/cmCPackSTGZGenerator.cxx b/Source/CPack/cmCPackSTGZGenerator.cxx index 96c4453..1ce9935 100644 --- a/Source/CPack/cmCPackSTGZGenerator.cxx +++ b/Source/CPack/cmCPackSTGZGenerator.cxx @@ -36,6 +36,13 @@ cmCPackSTGZGenerator::~cmCPackSTGZGenerator() } //---------------------------------------------------------------------- +int cmCPackSTGZGenerator::InitializeInternal() +{ + this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0"); + return this->Superclass::InitializeInternal(); +} + +//---------------------------------------------------------------------- int cmCPackSTGZGenerator::GenerateHeader(std::ostream* os) { cmCPackLogger(cmCPackLog::LOG_DEBUG, "Writing header" << std::endl); diff --git a/Source/CPack/cmCPackSTGZGenerator.h b/Source/CPack/cmCPackSTGZGenerator.h index bf7dec8..050da9d 100644 --- a/Source/CPack/cmCPackSTGZGenerator.h +++ b/Source/CPack/cmCPackSTGZGenerator.h @@ -37,6 +37,7 @@ public: virtual ~cmCPackSTGZGenerator(); protected: + virtual int InitializeInternal(); int GenerateHeader(std::ostream* os); virtual const char* GetOutputExtension() { return "sh"; } }; diff --git a/Source/CPack/cmCPackTGZGenerator.cxx b/Source/CPack/cmCPackTGZGenerator.cxx index 4be3d43..1daaee9 100644 --- a/Source/CPack/cmCPackTGZGenerator.cxx +++ b/Source/CPack/cmCPackTGZGenerator.cxx @@ -179,6 +179,13 @@ int cmCPackTGZ_Data_Close(void *client_data) } //---------------------------------------------------------------------- +int cmCPackTGZGenerator::InitializeInternal() +{ + this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "1"); + return this->Superclass::InitializeInternal(); +} + +//---------------------------------------------------------------------- int cmCPackTGZGenerator::CompressFiles(const char* outFileName, const char* toplevel, const std::vector& files) { diff --git a/Source/CPack/cmCPackTGZGenerator.h b/Source/CPack/cmCPackTGZGenerator.h index a486a24..7dd5875 100644 --- a/Source/CPack/cmCPackTGZGenerator.h +++ b/Source/CPack/cmCPackTGZGenerator.h @@ -40,6 +40,7 @@ public: virtual ~cmCPackTGZGenerator(); protected: + virtual int InitializeInternal(); virtual int GenerateHeader(std::ostream* os); int CompressFiles(const char* outFileName, const char* toplevel, const std::vector& files); diff --git a/Source/CPack/cmCPackZIPGenerator.cxx b/Source/CPack/cmCPackZIPGenerator.cxx index 0781991..8297cc4 100644 --- a/Source/CPack/cmCPackZIPGenerator.cxx +++ b/Source/CPack/cmCPackZIPGenerator.cxx @@ -38,13 +38,9 @@ cmCPackZIPGenerator::~cmCPackZIPGenerator() } //---------------------------------------------------------------------- -int cmCPackZIPGenerator::Initialize(const char* name, cmMakefile* mf) +int cmCPackZIPGenerator::InitializeInternal() { - int res = this->Superclass::Initialize(name, mf); - if ( !res ) - { - return res; - } + this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "1"); std::vector path; std::string pkgPath = "c:/Program Files/WinZip"; path.push_back(pkgPath); @@ -68,7 +64,8 @@ int cmCPackZIPGenerator::Initialize(const char* name, cmMakefile* mf) pkgPath = cmSystemTools::FindProgram("zip", path, false); if ( pkgPath.empty() ) { - cmCPackLogger(cmCPackLog::LOG_DEBUG, "Cannot find unix ZIP" << std::endl); + cmCPackLogger(cmCPackLog::LOG_DEBUG, "Cannot find unix ZIP" + << std::endl); } else { @@ -83,9 +80,10 @@ int cmCPackZIPGenerator::Initialize(const char* name, cmMakefile* mf) return 0; } this->SetOption("CPACK_INSTALLER_PROGRAM", pkgPath.c_str()); - cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Found ZIP program: " << pkgPath.c_str() + cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Found ZIP program: " + << pkgPath.c_str() << std::endl); - return 1; + return this->Superclass::InitializeInternal(); } //---------------------------------------------------------------------- diff --git a/Source/CPack/cmCPackZIPGenerator.h b/Source/CPack/cmCPackZIPGenerator.h index 2bb75fe..640ef24 100644 --- a/Source/CPack/cmCPackZIPGenerator.h +++ b/Source/CPack/cmCPackZIPGenerator.h @@ -32,10 +32,6 @@ public: cmCPackTypeMacro(cmCPackZIPGenerator, cmCPackGenericGenerator); /** - * Initialize generator - */ - virtual int Initialize(const char* name, cmMakefile* mf); - /** * Construct generator */ cmCPackZIPGenerator(); @@ -49,6 +45,7 @@ public: }; protected: + virtual int InitializeInternal(); int CompressFiles(const char* outFileName, const char* toplevel, const std::vector& files); virtual const char* GetOutputExtension() { return "zip"; } -- cgit v0.12