diff options
Diffstat (limited to 'Source/CPack')
84 files changed, 10380 insertions, 5993 deletions
diff --git a/Source/CPack/IFW/cmCPackIFWCommon.cxx b/Source/CPack/IFW/cmCPackIFWCommon.cxx new file mode 100644 index 000000000..e8f05bd50 --- /dev/null +++ b/Source/CPack/IFW/cmCPackIFWCommon.cxx @@ -0,0 +1,137 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmCPackIFWCommon.h" + +#include "cmCPackGenerator.h" +#include "cmCPackIFWGenerator.h" +#include "cmCPackLog.h" // IWYU pragma: keep +#include "cmSystemTools.h" +#include "cmTimestamp.h" +#include "cmVersionConfig.h" +#include "cmXMLWriter.h" + +#include <sstream> +#include <utility> +#include <vector> + +cmCPackIFWCommon::cmCPackIFWCommon() + : Generator(CM_NULLPTR) +{ +} + +const char* cmCPackIFWCommon::GetOption(const std::string& op) const +{ + return this->Generator ? this->Generator->cmCPackGenerator::GetOption(op) + : CM_NULLPTR; +} + +bool cmCPackIFWCommon::IsOn(const std::string& op) const +{ + return this->Generator ? this->Generator->cmCPackGenerator::IsOn(op) : false; +} + +bool cmCPackIFWCommon::IsSetToOff(const std::string& op) const +{ + return this->Generator ? this->Generator->cmCPackGenerator::IsSetToOff(op) + : false; +} + +bool cmCPackIFWCommon::IsSetToEmpty(const std::string& op) const +{ + return this->Generator ? this->Generator->cmCPackGenerator::IsSetToEmpty(op) + : false; +} + +bool cmCPackIFWCommon::IsVersionLess(const char* version) +{ + if (!this->Generator) { + return false; + } + + return cmSystemTools::VersionCompare( + cmSystemTools::OP_LESS, this->Generator->FrameworkVersion.data(), version); +} + +bool cmCPackIFWCommon::IsVersionGreater(const char* version) +{ + if (!this->Generator) { + return false; + } + + return cmSystemTools::VersionCompare( + cmSystemTools::OP_GREATER, this->Generator->FrameworkVersion.data(), + version); +} + +bool cmCPackIFWCommon::IsVersionEqual(const char* version) +{ + if (!this->Generator) { + return false; + } + + return cmSystemTools::VersionCompare( + cmSystemTools::OP_EQUAL, this->Generator->FrameworkVersion.data(), + version); +} + +void cmCPackIFWCommon::ExpandListArgument( + const std::string& arg, std::map<std::string, std::string>& argsOut) +{ + std::vector<std::string> args; + cmSystemTools::ExpandListArgument(arg, args, false); + if (args.empty()) { + return; + } + + std::size_t i = 0; + std::size_t c = args.size(); + if (c % 2) { + argsOut[""] = args[i]; + ++i; + } + + --c; + for (; i < c; i += 2) { + argsOut[args[i]] = args[i + 1]; + } +} + +void cmCPackIFWCommon::ExpandListArgument( + const std::string& arg, std::multimap<std::string, std::string>& argsOut) +{ + std::vector<std::string> args; + cmSystemTools::ExpandListArgument(arg, args, false); + if (args.empty()) { + return; + } + + std::size_t i = 0; + std::size_t c = args.size(); + if (c % 2) { + argsOut.insert(std::pair<std::string, std::string>("", args[i])); + ++i; + } + + --c; + for (; i < c; i += 2) { + argsOut.insert(std::pair<std::string, std::string>(args[i], args[i + 1])); + } +} + +void cmCPackIFWCommon::WriteGeneratedByToStrim(cmXMLWriter& xout) +{ + if (!this->Generator) { + return; + } + + std::ostringstream comment; + comment << "Generated by CPack " << CMake_VERSION << " IFW generator " + << "for QtIFW "; + if (this->IsVersionEqual("1.9.9")) { + comment << "less 2.0"; + } else { + comment << this->Generator->FrameworkVersion; + } + comment << " tools at " << cmTimestamp().CurrentTime("", true); + xout.Comment(comment.str().c_str()); +} diff --git a/Source/CPack/IFW/cmCPackIFWCommon.h b/Source/CPack/IFW/cmCPackIFWCommon.h new file mode 100644 index 000000000..354d84966 --- /dev/null +++ b/Source/CPack/IFW/cmCPackIFWCommon.h @@ -0,0 +1,81 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmCPackIFWCommon_h +#define cmCPackIFWCommon_h + +#include "cmConfigure.h" // IWYU pragma: keep + +#include <map> +#include <string> + +class cmCPackIFWGenerator; +class cmXMLWriter; + +/** \class cmCPackIFWCommon + * \brief A base class for CPack IFW generator implementation subclasses + */ +class cmCPackIFWCommon +{ +public: + // Constructor + + /** + * Construct Part + */ + cmCPackIFWCommon(); + +public: + // Internal implementation + + const char* GetOption(const std::string& op) const; + bool IsOn(const std::string& op) const; + bool IsSetToOff(const std::string& op) const; + bool IsSetToEmpty(const std::string& op) const; + + /** + * Compare \a version with QtIFW framework version + */ + bool IsVersionLess(const char* version); + + /** + * Compare \a version with QtIFW framework version + */ + bool IsVersionGreater(const char* version); + + /** + * Compare \a version with QtIFW framework version + */ + bool IsVersionEqual(const char* version); + + /** Expand the list argument containing the map of the key-value pairs. + * If the number of elements is odd, then the first value is used as the + * default value with an empty key. + * Any values with the same keys will be permanently overwritten. + */ + static void ExpandListArgument(const std::string& arg, + std::map<std::string, std::string>& argsOut); + + /** Expand the list argument containing the multimap of the key-value pairs. + * If the number of elements is odd, then the first value is used as the + * default value with an empty key. + */ + static void ExpandListArgument( + const std::string& arg, std::multimap<std::string, std::string>& argsOut); + + cmCPackIFWGenerator* Generator; + +protected: + void WriteGeneratedByToStrim(cmXMLWriter& xout); +}; + +#define cmCPackIFWLogger(logType, msg) \ + do { \ + std::ostringstream cmCPackLog_msg; \ + cmCPackLog_msg << msg; \ + if (Generator) { \ + Generator->Logger->Log(cmCPackLog::LOG_##logType, __FILE__, __LINE__, \ + cmCPackLog_msg.str().c_str()); \ + } \ + } while (false) + +#endif // cmCPackIFWCommon_h diff --git a/Source/CPack/IFW/cmCPackIFWGenerator.cxx b/Source/CPack/IFW/cmCPackIFWGenerator.cxx new file mode 100644 index 000000000..226ea0a29 --- /dev/null +++ b/Source/CPack/IFW/cmCPackIFWGenerator.cxx @@ -0,0 +1,560 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmCPackIFWGenerator.h" + +#include "cmCPackComponentGroup.h" +#include "cmCPackGenerator.h" +#include "cmCPackIFWCommon.h" +#include "cmCPackIFWInstaller.h" +#include "cmCPackIFWPackage.h" +#include "cmCPackIFWRepository.h" +#include "cmCPackLog.h" // IWYU pragma: keep +#include "cmGeneratedFileStream.h" +#include "cmSystemTools.h" + +#include <sstream> +#include <utility> + +cmCPackIFWGenerator::cmCPackIFWGenerator() +{ + this->Generator = this; +} + +cmCPackIFWGenerator::~cmCPackIFWGenerator() +{ +} + +int cmCPackIFWGenerator::PackageFiles() +{ + cmCPackIFWLogger(OUTPUT, "- Configuration" << std::endl); + + // Installer configuragion + this->Installer.GenerateInstallerFile(); + + // Packages configuration + this->Installer.GeneratePackageFiles(); + + std::string ifwTLD = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); + std::string ifwTmpFile = ifwTLD; + ifwTmpFile += "/IFWOutput.log"; + + // Run repogen + if (!this->Installer.RemoteRepositories.empty()) { + std::string ifwCmd = this->RepoGen; + + if (this->IsVersionLess("2.0.0")) { + ifwCmd += " -c " + this->toplevel + "/config/config.xml"; + } + + ifwCmd += " -p " + this->toplevel + "/packages"; + + if (!this->PkgsDirsVector.empty()) { + for (std::vector<std::string>::iterator it = + this->PkgsDirsVector.begin(); + it != this->PkgsDirsVector.end(); ++it) { + ifwCmd += " -p " + *it; + } + } + + if (!this->OnlineOnly && !this->DownloadedPackages.empty()) { + ifwCmd += " -i "; + std::set<cmCPackIFWPackage*>::iterator it = + this->DownloadedPackages.begin(); + ifwCmd += (*it)->Name; + ++it; + while (it != this->DownloadedPackages.end()) { + ifwCmd += "," + (*it)->Name; + ++it; + } + } + ifwCmd += " " + this->toplevel + "/repository"; + cmCPackIFWLogger(VERBOSE, "Execute: " << ifwCmd << std::endl); + std::string output; + int retVal = 1; + cmCPackIFWLogger(OUTPUT, "- Generate repository" << std::endl); + bool res = cmSystemTools::RunSingleCommand(ifwCmd.c_str(), &output, + &output, &retVal, CM_NULLPTR, + this->GeneratorVerbose, 0); + if (!res || retVal) { + cmGeneratedFileStream ofs(ifwTmpFile.c_str()); + ofs << "# Run command: " << ifwCmd << std::endl + << "# Output:" << std::endl + << output << std::endl; + cmCPackIFWLogger(ERROR, "Problem running IFW command: " + << ifwCmd << std::endl + << "Please check " << ifwTmpFile << " for errors" + << std::endl); + return 0; + } + + if (!this->Repository.RepositoryUpdate.empty() && + !this->Repository.PatchUpdatesXml()) { + cmCPackIFWLogger(WARNING, "Problem patch IFW \"Updates\" " + << "file: " + << this->toplevel + "/repository/Updates.xml" + << std::endl); + } + + cmCPackIFWLogger(OUTPUT, "- repository: " << this->toplevel + << "/repository generated" + << std::endl); + } + + // Run binary creator + { + std::string ifwCmd = this->BinCreator; + ifwCmd += " -c " + this->toplevel + "/config/config.xml"; + + if (!this->Installer.Resources.empty()) { + ifwCmd += " -r "; + std::vector<std::string>::iterator it = + this->Installer.Resources.begin(); + std::string path = this->toplevel + "/resources/"; + ifwCmd += path + *it; + ++it; + while (it != this->Installer.Resources.end()) { + ifwCmd += "," + path + *it; + ++it; + } + } + + ifwCmd += " -p " + this->toplevel + "/packages"; + + if (!this->PkgsDirsVector.empty()) { + for (std::vector<std::string>::iterator it = + this->PkgsDirsVector.begin(); + it != this->PkgsDirsVector.end(); ++it) { + ifwCmd += " -p " + *it; + } + } + + if (this->OnlineOnly) { + ifwCmd += " --online-only"; + } else if (!this->DownloadedPackages.empty() && + !this->Installer.RemoteRepositories.empty()) { + ifwCmd += " -e "; + std::set<cmCPackIFWPackage*>::iterator it = + this->DownloadedPackages.begin(); + ifwCmd += (*it)->Name; + ++it; + while (it != this->DownloadedPackages.end()) { + ifwCmd += "," + (*it)->Name; + ++it; + } + } else if (!this->DependentPackages.empty()) { + ifwCmd += " -i "; + // Binary + std::set<cmCPackIFWPackage*>::iterator bit = + this->BinaryPackages.begin(); + while (bit != this->BinaryPackages.end()) { + ifwCmd += (*bit)->Name + ","; + ++bit; + } + // Depend + DependenceMap::iterator it = this->DependentPackages.begin(); + ifwCmd += it->second.Name; + ++it; + while (it != this->DependentPackages.end()) { + ifwCmd += "," + it->second.Name; + ++it; + } + } + // TODO: set correct name for multipackages + if (!this->packageFileNames.empty()) { + ifwCmd += " " + this->packageFileNames[0]; + } else { + ifwCmd += " installer"; + } + cmCPackIFWLogger(VERBOSE, "Execute: " << ifwCmd << std::endl); + std::string output; + int retVal = 1; + cmCPackIFWLogger(OUTPUT, "- Generate package" << std::endl); + bool res = cmSystemTools::RunSingleCommand(ifwCmd.c_str(), &output, + &output, &retVal, CM_NULLPTR, + this->GeneratorVerbose, 0); + if (!res || retVal) { + cmGeneratedFileStream ofs(ifwTmpFile.c_str()); + ofs << "# Run command: " << ifwCmd << std::endl + << "# Output:" << std::endl + << output << std::endl; + cmCPackIFWLogger(ERROR, "Problem running IFW command: " + << ifwCmd << std::endl + << "Please check " << ifwTmpFile << " for errors" + << std::endl); + return 0; + } + } + + return 1; +} + +const char* cmCPackIFWGenerator::GetPackagingInstallPrefix() +{ + const char* defPrefix = this->cmCPackGenerator::GetPackagingInstallPrefix(); + + std::string tmpPref = defPrefix ? defPrefix : ""; + + if (this->Components.empty()) { + tmpPref += "packages/" + this->GetRootPackageName() + "/data"; + } + + this->SetOption("CPACK_IFW_PACKAGING_INSTALL_PREFIX", tmpPref.c_str()); + + return this->GetOption("CPACK_IFW_PACKAGING_INSTALL_PREFIX"); +} + +const char* cmCPackIFWGenerator::GetOutputExtension() +{ + return this->ExecutableSuffix.c_str(); +} + +int cmCPackIFWGenerator::InitializeInternal() +{ + // Search Qt Installer Framework tools + + const std::string BinCreatorOpt = "CPACK_IFW_BINARYCREATOR_EXECUTABLE"; + const std::string RepoGenOpt = "CPACK_IFW_REPOGEN_EXECUTABLE"; + const std::string FrameworkVersionOpt = "CPACK_IFW_FRAMEWORK_VERSION"; + + if (!this->IsSet(BinCreatorOpt) || !this->IsSet(RepoGenOpt) || + !this->IsSet(FrameworkVersionOpt)) { + this->ReadListFile("CPackIFW.cmake"); + } + + // Look 'binarycreator' executable (needs) + + const char* BinCreatorStr = this->GetOption(BinCreatorOpt); + if (!BinCreatorStr || cmSystemTools::IsNOTFOUND(BinCreatorStr)) { + this->BinCreator = ""; + } else { + this->BinCreator = BinCreatorStr; + } + + if (this->BinCreator.empty()) { + cmCPackIFWLogger(ERROR, "Cannot find QtIFW compiler \"binarycreator\": " + "likely it is not installed, or not in your PATH" + << std::endl); + return 0; + } + + // Look 'repogen' executable (optional) + + const char* RepoGenStr = this->GetOption(RepoGenOpt); + if (!RepoGenStr || cmSystemTools::IsNOTFOUND(RepoGenStr)) { + this->RepoGen = ""; + } else { + this->RepoGen = RepoGenStr; + } + + // Framework version + if (const char* FrameworkVersionSrt = this->GetOption(FrameworkVersionOpt)) { + this->FrameworkVersion = FrameworkVersionSrt; + } else { + this->FrameworkVersion = "1.9.9"; + } + + // Variables that Change Behavior + + // Resolve duplicate names + this->ResolveDuplicateNames = + this->IsOn("CPACK_IFW_RESOLVE_DUPLICATE_NAMES"); + + // Additional packages dirs + this->PkgsDirsVector.clear(); + if (const char* dirs = this->GetOption("CPACK_IFW_PACKAGES_DIRECTORIES")) { + cmSystemTools::ExpandListArgument(dirs, this->PkgsDirsVector); + } + + // Installer + this->Installer.Generator = this; + this->Installer.ConfigureFromOptions(); + + // Repository + this->Repository.Generator = this; + this->Repository.Name = "Unspecified"; + if (const char* site = this->GetOption("CPACK_DOWNLOAD_SITE")) { + this->Repository.Url = site; + this->Installer.RemoteRepositories.push_back(&this->Repository); + } + + // Repositories + if (const char* RepoAllStr = this->GetOption("CPACK_IFW_REPOSITORIES_ALL")) { + std::vector<std::string> RepoAllVector; + cmSystemTools::ExpandListArgument(RepoAllStr, RepoAllVector); + for (std::vector<std::string>::iterator rit = RepoAllVector.begin(); + rit != RepoAllVector.end(); ++rit) { + this->GetRepository(*rit); + } + } + + if (const char* ifwDownloadAll = this->GetOption("CPACK_IFW_DOWNLOAD_ALL")) { + this->OnlineOnly = cmSystemTools::IsOn(ifwDownloadAll); + } else if (const char* cpackDownloadAll = + this->GetOption("CPACK_DOWNLOAD_ALL")) { + this->OnlineOnly = cmSystemTools::IsOn(cpackDownloadAll); + } else { + this->OnlineOnly = false; + } + + if (!this->Installer.RemoteRepositories.empty() && this->RepoGen.empty()) { + cmCPackIFWLogger(ERROR, + "Cannot find QtIFW repository generator \"repogen\": " + "likely it is not installed, or not in your PATH" + << std::endl); + return 0; + } + + // Executable suffix + if (const char* optExeSuffix = this->GetOption("CMAKE_EXECUTABLE_SUFFIX")) { + this->ExecutableSuffix = optExeSuffix; + if (this->ExecutableSuffix.empty()) { + std::string sysName(this->GetOption("CMAKE_SYSTEM_NAME")); + if (sysName == "Linux") { + this->ExecutableSuffix = ".run"; + } + } + } else { + this->ExecutableSuffix = this->cmCPackGenerator::GetOutputExtension(); + } + + return this->Superclass::InitializeInternal(); +} + +std::string cmCPackIFWGenerator::GetComponentInstallDirNameSuffix( + const std::string& componentName) +{ + const std::string prefix = "packages/"; + const std::string suffix = "/data"; + + if (this->componentPackageMethod == this->ONE_PACKAGE) { + return std::string(prefix + this->GetRootPackageName() + suffix); + } + + return prefix + + this->GetComponentPackageName(&this->Components[componentName]) + suffix; +} + +cmCPackComponent* cmCPackIFWGenerator::GetComponent( + const std::string& projectName, const std::string& componentName) +{ + ComponentsMap::iterator cit = this->Components.find(componentName); + if (cit != this->Components.end()) { + return &(cit->second); + } + + cmCPackComponent* component = + this->cmCPackGenerator::GetComponent(projectName, componentName); + if (!component) { + return component; + } + + std::string name = this->GetComponentPackageName(component); + PackagesMap::iterator pit = this->Packages.find(name); + if (pit != this->Packages.end()) { + return component; + } + + cmCPackIFWPackage* package = &this->Packages[name]; + package->Name = name; + package->Generator = this; + if (package->ConfigureFromComponent(component)) { + package->Installer = &this->Installer; + this->Installer.Packages.insert( + std::pair<std::string, cmCPackIFWPackage*>(name, package)); + this->ComponentPackages.insert( + std::pair<cmCPackComponent*, cmCPackIFWPackage*>(component, package)); + if (component->IsDownloaded) { + this->DownloadedPackages.insert(package); + } else { + this->BinaryPackages.insert(package); + } + } else { + this->Packages.erase(name); + cmCPackIFWLogger(ERROR, "Cannot configure package \"" + << name << "\" for component \"" << component->Name + << "\"" << std::endl); + } + + return component; +} + +cmCPackComponentGroup* cmCPackIFWGenerator::GetComponentGroup( + const std::string& projectName, const std::string& groupName) +{ + cmCPackComponentGroup* group = + this->cmCPackGenerator::GetComponentGroup(projectName, groupName); + if (!group) { + return group; + } + + std::string name = this->GetGroupPackageName(group); + PackagesMap::iterator pit = this->Packages.find(name); + if (pit != this->Packages.end()) { + return group; + } + + cmCPackIFWPackage* package = &this->Packages[name]; + package->Name = name; + package->Generator = this; + if (package->ConfigureFromGroup(group)) { + package->Installer = &this->Installer; + this->Installer.Packages.insert( + std::pair<std::string, cmCPackIFWPackage*>(name, package)); + this->GroupPackages.insert( + std::pair<cmCPackComponentGroup*, cmCPackIFWPackage*>(group, package)); + this->BinaryPackages.insert(package); + } else { + this->Packages.erase(name); + cmCPackIFWLogger(ERROR, "Cannot configure package \"" + << name << "\" for component group \"" << group->Name + << "\"" << std::endl); + } + return group; +} + +enum cmCPackGenerator::CPackSetDestdirSupport +cmCPackIFWGenerator::SupportsSetDestdir() const +{ + return cmCPackGenerator::SETDESTDIR_SHOULD_NOT_BE_USED; +} + +bool cmCPackIFWGenerator::SupportsAbsoluteDestination() const +{ + return false; +} + +bool cmCPackIFWGenerator::SupportsComponentInstallation() const +{ + return true; +} + +bool cmCPackIFWGenerator::IsOnePackage() const +{ + return this->componentPackageMethod == cmCPackGenerator::ONE_PACKAGE; +} + +std::string cmCPackIFWGenerator::GetRootPackageName() +{ + // Default value + std::string name = "root"; + if (const char* optIFW_PACKAGE_GROUP = + this->GetOption("CPACK_IFW_PACKAGE_GROUP")) { + // Configure from root group + cmCPackIFWPackage package; + package.Generator = this; + package.ConfigureFromGroup(optIFW_PACKAGE_GROUP); + name = package.Name; + } else if (const char* optIFW_PACKAGE_NAME = + this->GetOption("CPACK_IFW_PACKAGE_NAME")) { + // Configure from root package name + name = optIFW_PACKAGE_NAME; + } else if (const char* optPACKAGE_NAME = + this->GetOption("CPACK_PACKAGE_NAME")) { + // Configure from package name + name = optPACKAGE_NAME; + } + return name; +} + +std::string cmCPackIFWGenerator::GetGroupPackageName( + cmCPackComponentGroup* group) const +{ + std::string name; + if (!group) { + return name; + } + if (cmCPackIFWPackage* package = this->GetGroupPackage(group)) { + return package->Name; + } + const char* option = + this->GetOption("CPACK_IFW_COMPONENT_GROUP_" + + cmsys::SystemTools::UpperCase(group->Name) + "_NAME"); + name = option ? option : group->Name; + if (group->ParentGroup) { + cmCPackIFWPackage* package = this->GetGroupPackage(group->ParentGroup); + bool dot = !this->ResolveDuplicateNames; + if (dot && name.substr(0, package->Name.size()) == package->Name) { + dot = false; + } + if (dot) { + name = package->Name + "." + name; + } + } + return name; +} + +std::string cmCPackIFWGenerator::GetComponentPackageName( + cmCPackComponent* component) const +{ + std::string name; + if (!component) { + return name; + } + if (cmCPackIFWPackage* package = this->GetComponentPackage(component)) { + return package->Name; + } + std::string prefix = "CPACK_IFW_COMPONENT_" + + cmsys::SystemTools::UpperCase(component->Name) + "_"; + const char* option = this->GetOption(prefix + "NAME"); + name = option ? option : component->Name; + if (component->Group) { + cmCPackIFWPackage* package = this->GetGroupPackage(component->Group); + if ((this->componentPackageMethod == + cmCPackGenerator::ONE_PACKAGE_PER_GROUP) || + this->IsOn(prefix + "COMMON")) { + return package->Name; + } + bool dot = !this->ResolveDuplicateNames; + if (dot && name.substr(0, package->Name.size()) == package->Name) { + dot = false; + } + if (dot) { + name = package->Name + "." + name; + } + } + return name; +} + +cmCPackIFWPackage* cmCPackIFWGenerator::GetGroupPackage( + cmCPackComponentGroup* group) const +{ + std::map<cmCPackComponentGroup*, cmCPackIFWPackage*>::const_iterator pit = + this->GroupPackages.find(group); + return pit != this->GroupPackages.end() ? pit->second : CM_NULLPTR; +} + +cmCPackIFWPackage* cmCPackIFWGenerator::GetComponentPackage( + cmCPackComponent* component) const +{ + std::map<cmCPackComponent*, cmCPackIFWPackage*>::const_iterator pit = + this->ComponentPackages.find(component); + return pit != this->ComponentPackages.end() ? pit->second : CM_NULLPTR; +} + +cmCPackIFWRepository* cmCPackIFWGenerator::GetRepository( + const std::string& repositoryName) +{ + RepositoriesMap::iterator rit = this->Repositories.find(repositoryName); + if (rit != this->Repositories.end()) { + return &(rit->second); + } + + cmCPackIFWRepository* repository = &this->Repositories[repositoryName]; + repository->Name = repositoryName; + repository->Generator = this; + if (repository->ConfigureFromOptions()) { + if (repository->Update == cmCPackIFWRepository::None) { + this->Installer.RemoteRepositories.push_back(repository); + } else { + this->Repository.RepositoryUpdate.push_back(repository); + } + } else { + this->Repositories.erase(repositoryName); + repository = CM_NULLPTR; + cmCPackIFWLogger(WARNING, "Invalid repository \"" + << repositoryName << "\"" + << " configuration. Repository will be skipped." + << std::endl); + } + return repository; +} diff --git a/Source/CPack/IFW/cmCPackIFWGenerator.h b/Source/CPack/IFW/cmCPackIFWGenerator.h new file mode 100644 index 000000000..8348ceeec --- /dev/null +++ b/Source/CPack/IFW/cmCPackIFWGenerator.h @@ -0,0 +1,152 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmCPackIFWGenerator_h +#define cmCPackIFWGenerator_h + +#include "cmConfigure.h" // IWYU pragma: keep + +#include "cmCPackComponentGroup.h" +#include "cmCPackGenerator.h" +#include "cmCPackIFWCommon.h" +#include "cmCPackIFWInstaller.h" +#include "cmCPackIFWPackage.h" +#include "cmCPackIFWRepository.h" + +#include <map> +#include <set> +#include <string> +#include <vector> + +/** \class cmCPackIFWGenerator + * \brief A generator for Qt Installer Framework tools + * + * http://qt-project.org/doc/qtinstallerframework/index.html + */ +class cmCPackIFWGenerator : public cmCPackGenerator, public cmCPackIFWCommon +{ +public: + cmCPackTypeMacro(cmCPackIFWGenerator, cmCPackGenerator); + + typedef std::map<std::string, cmCPackIFWPackage> PackagesMap; + typedef std::map<std::string, cmCPackIFWRepository> RepositoriesMap; + typedef std::map<std::string, cmCPackComponent> ComponentsMap; + typedef std::map<std::string, cmCPackComponentGroup> ComponentGoupsMap; + typedef std::map<std::string, cmCPackIFWPackage::DependenceStruct> + DependenceMap; + + using cmCPackIFWCommon::GetOption; + using cmCPackIFWCommon::IsOn; + using cmCPackIFWCommon::IsSetToOff; + using cmCPackIFWCommon::IsSetToEmpty; + + /** + * Construct IFW generator + */ + cmCPackIFWGenerator(); + + /** + * Destruct IFW generator + */ + ~cmCPackIFWGenerator() CM_OVERRIDE; + +protected: + // cmCPackGenerator reimplementation + + /** + * @brief Initialize generator + * @return 0 on failure + */ + int InitializeInternal() CM_OVERRIDE; + int PackageFiles() CM_OVERRIDE; + const char* GetPackagingInstallPrefix() CM_OVERRIDE; + + /** + * @brief Extension of binary installer + * @return Executable suffix or value from default implementation + */ + const char* GetOutputExtension() CM_OVERRIDE; + + std::string GetComponentInstallDirNameSuffix( + const std::string& componentName) CM_OVERRIDE; + + /** + * @brief Get Component + * @param projectName Project name + * @param componentName Component name + * + * This method calls the base implementation. + * + * @return Pointer to component + */ + cmCPackComponent* GetComponent(const std::string& projectName, + const std::string& componentName) CM_OVERRIDE; + + /** + * @brief Get group of component + * @param projectName Project name + * @param groupName Component group name + * + * This method calls the base implementation. + * + * @return Pointer to component group + */ + cmCPackComponentGroup* GetComponentGroup( + const std::string& projectName, const std::string& groupName) CM_OVERRIDE; + + enum cmCPackGenerator::CPackSetDestdirSupport SupportsSetDestdir() const + CM_OVERRIDE; + bool SupportsAbsoluteDestination() const CM_OVERRIDE; + bool SupportsComponentInstallation() const CM_OVERRIDE; + +protected: + // Methods + + bool IsOnePackage() const; + + std::string GetRootPackageName(); + + std::string GetGroupPackageName(cmCPackComponentGroup* group) const; + std::string GetComponentPackageName(cmCPackComponent* component) const; + + cmCPackIFWPackage* GetGroupPackage(cmCPackComponentGroup* group) const; + cmCPackIFWPackage* GetComponentPackage(cmCPackComponent* component) const; + + cmCPackIFWRepository* GetRepository(const std::string& repositoryName); + +protected: + // Data + + friend class cmCPackIFWPackage; + friend class cmCPackIFWCommon; + friend class cmCPackIFWInstaller; + friend class cmCPackIFWRepository; + + // Installer + cmCPackIFWInstaller Installer; + // Repository + cmCPackIFWRepository Repository; + // Collection of packages + PackagesMap Packages; + // Collection of repositories + RepositoriesMap Repositories; + // Collection of binary packages + std::set<cmCPackIFWPackage*> BinaryPackages; + // Collection of downloaded packages + std::set<cmCPackIFWPackage*> DownloadedPackages; + // Dependent packages + DependenceMap DependentPackages; + std::map<cmCPackComponent*, cmCPackIFWPackage*> ComponentPackages; + std::map<cmCPackComponentGroup*, cmCPackIFWPackage*> GroupPackages; + +private: + std::string RepoGen; + std::string BinCreator; + std::string FrameworkVersion; + std::string ExecutableSuffix; + + bool OnlineOnly; + bool ResolveDuplicateNames; + std::vector<std::string> PkgsDirsVector; +}; + +#endif diff --git a/Source/CPack/IFW/cmCPackIFWInstaller.cxx b/Source/CPack/IFW/cmCPackIFWInstaller.cxx new file mode 100644 index 000000000..288e924e5 --- /dev/null +++ b/Source/CPack/IFW/cmCPackIFWInstaller.cxx @@ -0,0 +1,500 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmCPackIFWInstaller.h" + +#include "cmCPackIFWCommon.h" +#include "cmCPackIFWGenerator.h" +#include "cmCPackIFWPackage.h" +#include "cmCPackIFWRepository.h" +#include "cmCPackLog.h" // IWYU pragma: keep +#include "cmGeneratedFileStream.h" +#include "cmSystemTools.h" +#include "cmXMLParser.h" +#include "cmXMLWriter.h" + +#include <sstream> +#include <stddef.h> +#include <utility> + +cmCPackIFWInstaller::cmCPackIFWInstaller() +{ +} + +void cmCPackIFWInstaller::printSkippedOptionWarning( + const std::string& optionName, const std::string& optionValue) +{ + cmCPackIFWLogger( + WARNING, "Option " + << optionName << " is set to \"" << optionValue + << "\" but will be skipped because the specified file does not exist." + << std::endl); +} + +void cmCPackIFWInstaller::ConfigureFromOptions() +{ + // Name; + if (const char* optIFW_PACKAGE_NAME = + this->GetOption("CPACK_IFW_PACKAGE_NAME")) { + this->Name = optIFW_PACKAGE_NAME; + } else if (const char* optPACKAGE_NAME = + this->GetOption("CPACK_PACKAGE_NAME")) { + this->Name = optPACKAGE_NAME; + } else { + this->Name = "Your package"; + } + + // Title; + if (const char* optIFW_PACKAGE_TITLE = + this->GetOption("CPACK_IFW_PACKAGE_TITLE")) { + this->Title = optIFW_PACKAGE_TITLE; + } else if (const char* optPACKAGE_DESCRIPTION_SUMMARY = + this->GetOption("CPACK_PACKAGE_DESCRIPTION_SUMMARY")) { + this->Title = optPACKAGE_DESCRIPTION_SUMMARY; + } else { + this->Title = "Your package description"; + } + + // Version; + if (const char* option = this->GetOption("CPACK_PACKAGE_VERSION")) { + this->Version = option; + } else { + this->Version = "1.0.0"; + } + + // Publisher + if (const char* optIFW_PACKAGE_PUBLISHER = + this->GetOption("CPACK_IFW_PACKAGE_PUBLISHER")) { + this->Publisher = optIFW_PACKAGE_PUBLISHER; + } else if (const char* optPACKAGE_VENDOR = + GetOption("CPACK_PACKAGE_VENDOR")) { + this->Publisher = optPACKAGE_VENDOR; + } + + // ProductUrl + if (const char* option = this->GetOption("CPACK_IFW_PRODUCT_URL")) { + this->ProductUrl = option; + } + + // ApplicationIcon + if (const char* option = this->GetOption("CPACK_IFW_PACKAGE_ICON")) { + if (cmSystemTools::FileExists(option)) { + this->InstallerApplicationIcon = option; + } else { + this->printSkippedOptionWarning("CPACK_IFW_PACKAGE_ICON", option); + } + } + + // WindowIcon + if (const char* option = this->GetOption("CPACK_IFW_PACKAGE_WINDOW_ICON")) { + if (cmSystemTools::FileExists(option)) { + this->InstallerWindowIcon = option; + } else { + this->printSkippedOptionWarning("CPACK_IFW_PACKAGE_WINDOW_ICON", option); + } + } + + // Logo + if (const char* option = this->GetOption("CPACK_IFW_PACKAGE_LOGO")) { + if (cmSystemTools::FileExists(option)) { + this->Logo = option; + } else { + this->printSkippedOptionWarning("CPACK_IFW_PACKAGE_LOGO", option); + } + } + + // Watermark + if (const char* option = this->GetOption("CPACK_IFW_PACKAGE_WATERMARK")) { + if (cmSystemTools::FileExists(option)) { + this->Watermark = option; + } else { + this->printSkippedOptionWarning("CPACK_IFW_PACKAGE_WATERMARK", option); + } + } + + // Banner + if (const char* option = this->GetOption("CPACK_IFW_PACKAGE_BANNER")) { + if (cmSystemTools::FileExists(option)) { + this->Banner = option; + } else { + this->printSkippedOptionWarning("CPACK_IFW_PACKAGE_BANNER", option); + } + } + + // Background + if (const char* option = this->GetOption("CPACK_IFW_PACKAGE_BACKGROUND")) { + if (cmSystemTools::FileExists(option)) { + this->Background = option; + } else { + this->printSkippedOptionWarning("CPACK_IFW_PACKAGE_BACKGROUND", option); + } + } + + // WizardStyle + if (const char* option = this->GetOption("CPACK_IFW_PACKAGE_WIZARD_STYLE")) { + // Setting the user value in any case + this->WizardStyle = option; + // Check known values + if (this->WizardStyle != "Modern" && this->WizardStyle != "Aero" && + this->WizardStyle != "Mac" && this->WizardStyle != "Classic") { + cmCPackIFWLogger( + WARNING, "Option CPACK_IFW_PACKAGE_WIZARD_STYLE has unknown value \"" + << option << "\". Expected values are: Modern, Aero, Mac, Classic." + << std::endl); + } + } + + // WizardDefaultWidth + if (const char* option = + this->GetOption("CPACK_IFW_PACKAGE_WIZARD_DEFAULT_WIDTH")) { + this->WizardDefaultWidth = option; + } + + // WizardDefaultHeight + if (const char* option = + this->GetOption("CPACK_IFW_PACKAGE_WIZARD_DEFAULT_HEIGHT")) { + this->WizardDefaultHeight = option; + } + + // TitleColor + if (const char* option = this->GetOption("CPACK_IFW_PACKAGE_TITLE_COLOR")) { + this->TitleColor = option; + } + + // Start menu + if (const char* optIFW_START_MENU_DIR = + this->GetOption("CPACK_IFW_PACKAGE_START_MENU_DIRECTORY")) { + this->StartMenuDir = optIFW_START_MENU_DIR; + } else { + this->StartMenuDir = Name; + } + + // Default target directory for installation + if (const char* optIFW_TARGET_DIRECTORY = + this->GetOption("CPACK_IFW_TARGET_DIRECTORY")) { + this->TargetDir = optIFW_TARGET_DIRECTORY; + } else if (const char* optPACKAGE_INSTALL_DIRECTORY = + this->GetOption("CPACK_PACKAGE_INSTALL_DIRECTORY")) { + this->TargetDir = "@ApplicationsDir@/"; + this->TargetDir += optPACKAGE_INSTALL_DIRECTORY; + } else { + this->TargetDir = "@RootDir@/usr/local"; + } + + // Default target directory for installation with administrator rights + if (const char* option = + this->GetOption("CPACK_IFW_ADMIN_TARGET_DIRECTORY")) { + this->AdminTargetDir = option; + } + + // Maintenance tool + if (const char* optIFW_MAINTENANCE_TOOL = + this->GetOption("CPACK_IFW_PACKAGE_MAINTENANCE_TOOL_NAME")) { + this->MaintenanceToolName = optIFW_MAINTENANCE_TOOL; + } + + // Maintenance tool ini file + if (const char* optIFW_MAINTENANCE_TOOL_INI = + this->GetOption("CPACK_IFW_PACKAGE_MAINTENANCE_TOOL_INI_FILE")) { + this->MaintenanceToolIniFile = optIFW_MAINTENANCE_TOOL_INI; + } + + // Allow non-ASCII characters + if (this->GetOption("CPACK_IFW_PACKAGE_ALLOW_NON_ASCII_CHARACTERS")) { + if (this->IsOn("CPACK_IFW_PACKAGE_ALLOW_NON_ASCII_CHARACTERS")) { + this->AllowNonAsciiCharacters = "true"; + } else { + this->AllowNonAsciiCharacters = "false"; + } + } + + // Space in path + if (this->GetOption("CPACK_IFW_PACKAGE_ALLOW_SPACE_IN_PATH")) { + if (this->IsOn("CPACK_IFW_PACKAGE_ALLOW_SPACE_IN_PATH")) { + this->AllowSpaceInPath = "true"; + } else { + this->AllowSpaceInPath = "false"; + } + } + + // Control script + if (const char* optIFW_CONTROL_SCRIPT = + this->GetOption("CPACK_IFW_PACKAGE_CONTROL_SCRIPT")) { + this->ControlScript = optIFW_CONTROL_SCRIPT; + } + + // Resources + if (const char* optIFW_PACKAGE_RESOURCES = + this->GetOption("CPACK_IFW_PACKAGE_RESOURCES")) { + this->Resources.clear(); + cmSystemTools::ExpandListArgument(optIFW_PACKAGE_RESOURCES, + this->Resources); + } +} + +/** \class cmCPackIFWResourcesParser + * \brief Helper class that parse resources form .qrc (Qt) + */ +class cmCPackIFWResourcesParser : public cmXMLParser +{ +public: + cmCPackIFWResourcesParser(cmCPackIFWInstaller* i) + : installer(i) + , file(false) + { + this->path = i->Directory + "/resources"; + } + + bool ParseResource(size_t r) + { + this->hasFiles = false; + this->hasErrors = false; + + this->basePath = + cmSystemTools::GetFilenamePath(this->installer->Resources[r]); + + this->ParseFile(this->installer->Resources[r].data()); + + return this->hasFiles && !this->hasErrors; + } + + cmCPackIFWInstaller* installer; + bool file, hasFiles, hasErrors; + std::string path, basePath; + +protected: + void StartElement(const std::string& name, const char** /*atts*/) CM_OVERRIDE + { + this->file = name == "file"; + if (file) { + this->hasFiles = true; + } + } + + void CharacterDataHandler(const char* data, int length) CM_OVERRIDE + { + if (this->file) { + std::string content(data, data + length); + content = cmSystemTools::TrimWhitespace(content); + std::string source = this->basePath + "/" + content; + std::string destination = this->path + "/" + content; + if (!cmSystemTools::CopyFileIfDifferent(source.data(), + destination.data())) { + this->hasErrors = true; + } + } + } + + void EndElement(const std::string& /*name*/) CM_OVERRIDE {} +}; + +void cmCPackIFWInstaller::GenerateInstallerFile() +{ + // Lazy directory initialization + if (this->Directory.empty() && this->Generator) { + this->Directory = this->Generator->toplevel; + } + + // Output stream + cmGeneratedFileStream fout((this->Directory + "/config/config.xml").data()); + cmXMLWriter xout(fout); + + xout.StartDocument(); + + WriteGeneratedByToStrim(xout); + + xout.StartElement("Installer"); + + xout.Element("Name", this->Name); + xout.Element("Version", this->Version); + xout.Element("Title", this->Title); + + if (!this->Publisher.empty()) { + xout.Element("Publisher", this->Publisher); + } + + if (!this->ProductUrl.empty()) { + xout.Element("ProductUrl", this->ProductUrl); + } + + // ApplicationIcon + if (!this->InstallerApplicationIcon.empty()) { + std::string name = + cmSystemTools::GetFilenameName(this->InstallerApplicationIcon); + std::string path = this->Directory + "/config/" + name; + name = cmSystemTools::GetFilenameWithoutExtension(name); + cmsys::SystemTools::CopyFileIfDifferent(this->InstallerApplicationIcon, + path); + xout.Element("InstallerApplicationIcon", name); + } + + // WindowIcon + if (!this->InstallerWindowIcon.empty()) { + std::string name = + cmSystemTools::GetFilenameName(this->InstallerWindowIcon); + std::string path = this->Directory + "/config/" + name; + cmsys::SystemTools::CopyFileIfDifferent(this->InstallerWindowIcon, path); + xout.Element("InstallerWindowIcon", name); + } + + // Logo + if (!this->Logo.empty()) { + std::string name = cmSystemTools::GetFilenameName(this->Logo); + std::string path = this->Directory + "/config/" + name; + cmsys::SystemTools::CopyFileIfDifferent(this->Logo, path); + xout.Element("Logo", name); + } + + // Banner + if (!this->Banner.empty()) { + std::string name = cmSystemTools::GetFilenameName(this->Banner); + std::string path = this->Directory + "/config/" + name; + cmsys::SystemTools::CopyFileIfDifferent(this->Banner, path); + xout.Element("Banner", name); + } + + // Watermark + if (!this->Watermark.empty()) { + std::string name = cmSystemTools::GetFilenameName(this->Watermark); + std::string path = this->Directory + "/config/" + name; + cmsys::SystemTools::CopyFileIfDifferent(this->Watermark, path); + xout.Element("Watermark", name); + } + + // Background + if (!this->Background.empty()) { + std::string name = cmSystemTools::GetFilenameName(this->Background); + std::string path = this->Directory + "/config/" + name; + cmsys::SystemTools::CopyFileIfDifferent(this->Background, path); + xout.Element("Background", name); + } + + // WizardStyle + if (!this->WizardStyle.empty()) { + xout.Element("WizardStyle", this->WizardStyle); + } + + // WizardDefaultWidth + if (!this->WizardDefaultWidth.empty()) { + xout.Element("WizardDefaultWidth", this->WizardDefaultWidth); + } + + // WizardDefaultHeight + if (!this->WizardDefaultHeight.empty()) { + xout.Element("WizardDefaultHeight", this->WizardDefaultHeight); + } + + // TitleColor + if (!this->TitleColor.empty()) { + xout.Element("TitleColor", this->TitleColor); + } + + // Start menu + if (!this->IsVersionLess("2.0")) { + xout.Element("StartMenuDir", this->StartMenuDir); + } + + // Target dir + if (!this->TargetDir.empty()) { + xout.Element("TargetDir", this->TargetDir); + } + + // Admin target dir + if (!this->AdminTargetDir.empty()) { + xout.Element("AdminTargetDir", this->AdminTargetDir); + } + + // Remote repositories + if (!this->RemoteRepositories.empty()) { + xout.StartElement("RemoteRepositories"); + for (RepositoriesVector::iterator rit = this->RemoteRepositories.begin(); + rit != this->RemoteRepositories.end(); ++rit) { + (*rit)->WriteRepositoryConfig(xout); + } + xout.EndElement(); + } + + // Maintenance tool + if (!this->IsVersionLess("2.0") && !this->MaintenanceToolName.empty()) { + xout.Element("MaintenanceToolName", this->MaintenanceToolName); + } + + // Maintenance tool ini file + if (!this->IsVersionLess("2.0") && !this->MaintenanceToolIniFile.empty()) { + xout.Element("MaintenanceToolIniFile", this->MaintenanceToolIniFile); + } + + // Different allows + if (this->IsVersionLess("2.0")) { + // CPack IFW default policy + xout.Comment("CPack IFW default policy for QtIFW less 2.0"); + xout.Element("AllowNonAsciiCharacters", "true"); + xout.Element("AllowSpaceInPath", "true"); + } else { + if (!this->AllowNonAsciiCharacters.empty()) { + xout.Element("AllowNonAsciiCharacters", this->AllowNonAsciiCharacters); + } + if (!this->AllowSpaceInPath.empty()) { + xout.Element("AllowSpaceInPath", this->AllowSpaceInPath); + } + } + + // Control script (copy to config dir) + if (!this->IsVersionLess("2.0") && !this->ControlScript.empty()) { + std::string name = cmSystemTools::GetFilenameName(this->ControlScript); + std::string path = this->Directory + "/config/" + name; + cmsys::SystemTools::CopyFileIfDifferent(this->ControlScript, path); + xout.Element("ControlScript", name); + } + + // Resources (copy to resources dir) + if (!this->Resources.empty()) { + std::vector<std::string> resources; + cmCPackIFWResourcesParser parser(this); + for (size_t i = 0; i < this->Resources.size(); i++) { + if (parser.ParseResource(i)) { + std::string name = cmSystemTools::GetFilenameName(this->Resources[i]); + std::string path = this->Directory + "/resources/" + name; + cmsys::SystemTools::CopyFileIfDifferent(this->Resources[i], path); + resources.push_back(name); + } else { + cmCPackIFWLogger(WARNING, "Can't copy resources from \"" + << this->Resources[i] + << "\". Resource will be skipped." << std::endl); + } + } + this->Resources = resources; + } + + xout.EndElement(); + xout.EndDocument(); +} + +void cmCPackIFWInstaller::GeneratePackageFiles() +{ + if (this->Packages.empty() || this->Generator->IsOnePackage()) { + // Generate default package + cmCPackIFWPackage package; + package.Generator = this->Generator; + package.Installer = this; + // Check package group + if (const char* option = this->GetOption("CPACK_IFW_PACKAGE_GROUP")) { + package.ConfigureFromGroup(option); + std::string forcedOption = "CPACK_IFW_COMPONENT_GROUP_" + + cmsys::SystemTools::UpperCase(option) + "_FORCED_INSTALLATION"; + if (!GetOption(forcedOption)) { + package.ForcedInstallation = "true"; + } + } else { + package.ConfigureFromOptions(); + } + package.GeneratePackageFile(); + return; + } + + // Generate packages meta information + for (PackagesMap::iterator pit = this->Packages.begin(); + pit != this->Packages.end(); ++pit) { + cmCPackIFWPackage* package = pit->second; + package->GeneratePackageFile(); + } +} diff --git a/Source/CPack/IFW/cmCPackIFWInstaller.h b/Source/CPack/IFW/cmCPackIFWInstaller.h new file mode 100644 index 000000000..b635f4222 --- /dev/null +++ b/Source/CPack/IFW/cmCPackIFWInstaller.h @@ -0,0 +1,129 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmCPackIFWInstaller_h +#define cmCPackIFWInstaller_h + +#include "cmConfigure.h" // IWYU pragma: keep + +#include "cmCPackIFWCommon.h" + +#include <map> +#include <string> +#include <vector> + +class cmCPackIFWPackage; +class cmCPackIFWRepository; + +/** \class cmCPackIFWInstaller + * \brief A binary installer to be created CPack IFW generator + */ +class cmCPackIFWInstaller : public cmCPackIFWCommon +{ +public: + // Types + + typedef std::map<std::string, cmCPackIFWPackage*> PackagesMap; + typedef std::vector<cmCPackIFWRepository*> RepositoriesVector; + +public: + // Constructor + + /** + * Construct installer + */ + cmCPackIFWInstaller(); + +public: + // Configuration + + /// Name of the product being installed + std::string Name; + + /// Version number of the product being installed + std::string Version; + + /// Name of the installer as displayed on the title bar + std::string Title; + + /// Publisher of the software (as shown in the Windows Control Panel) + std::string Publisher; + + /// URL to a page that contains product information on your web site + std::string ProductUrl; + + /// Filename for a custom installer icon + std::string InstallerApplicationIcon; + + /// Filename for a custom window icon + std::string InstallerWindowIcon; + + /// Filename for a logo + std::string Logo; + + /// Filename for a watermark + std::string Watermark; + + /// Filename for a banner + std::string Banner; + + /// Filename for a background + std::string Background; + + /// Wizard style name + std::string WizardStyle; + + /// Wizard width + std::string WizardDefaultWidth; + + /// Wizard height + std::string WizardDefaultHeight; + + /// Title color + std::string TitleColor; + + /// Name of the default program group in the Windows Start menu + std::string StartMenuDir; + + /// Default target directory for installation + std::string TargetDir; + + /// Default target directory for installation with administrator rights + std::string AdminTargetDir; + + /// Filename of the generated maintenance tool + std::string MaintenanceToolName; + + /// Filename for the configuration of the generated maintenance tool + std::string MaintenanceToolIniFile; + + /// Set to true if the installation path can contain non-ASCII characters + std::string AllowNonAsciiCharacters; + + /// Set to false if the installation path cannot contain space characters + std::string AllowSpaceInPath; + + /// Filename for a custom installer control script + std::string ControlScript; + + /// List of resources to include in the installer binary + std::vector<std::string> Resources; + +public: + // Internal implementation + + void ConfigureFromOptions(); + + void GenerateInstallerFile(); + + void GeneratePackageFiles(); + + PackagesMap Packages; + RepositoriesVector RemoteRepositories; + std::string Directory; + +protected: + void printSkippedOptionWarning(const std::string& optionName, + const std::string& optionValue); +}; + +#endif // cmCPackIFWInstaller_h diff --git a/Source/CPack/IFW/cmCPackIFWPackage.cxx b/Source/CPack/IFW/cmCPackIFWPackage.cxx new file mode 100644 index 000000000..c5311c31c --- /dev/null +++ b/Source/CPack/IFW/cmCPackIFWPackage.cxx @@ -0,0 +1,690 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmCPackIFWPackage.h" + +#include "cmCPackComponentGroup.h" +#include "cmCPackIFWCommon.h" +#include "cmCPackIFWGenerator.h" +#include "cmCPackIFWInstaller.h" +#include "cmCPackLog.h" // IWYU pragma: keep +#include "cmGeneratedFileStream.h" +#include "cmSystemTools.h" +#include "cmTimestamp.h" +#include "cmXMLWriter.h" + +#include <map> +#include <sstream> +#include <stddef.h> +#include <utility> + +//---------------------------------------------------------- CompareStruct --- +cmCPackIFWPackage::CompareStruct::CompareStruct() + : Type(cmCPackIFWPackage::CompareNone) +{ +} + +//------------------------------------------------------- DependenceStruct --- +cmCPackIFWPackage::DependenceStruct::DependenceStruct() +{ +} + +cmCPackIFWPackage::DependenceStruct::DependenceStruct( + const std::string& dependence) +{ + // Search compare section + size_t pos = std::string::npos; + if ((pos = dependence.find("<=")) != std::string::npos) { + this->Compare.Type = cmCPackIFWPackage::CompareLessOrEqual; + this->Compare.Value = dependence.substr(pos + 2); + } else if ((pos = dependence.find(">=")) != std::string::npos) { + this->Compare.Type = cmCPackIFWPackage::CompareGreaterOrEqual; + this->Compare.Value = dependence.substr(pos + 2); + } else if ((pos = dependence.find('<')) != std::string::npos) { + this->Compare.Type = cmCPackIFWPackage::CompareLess; + this->Compare.Value = dependence.substr(pos + 1); + } else if ((pos = dependence.find('=')) != std::string::npos) { + this->Compare.Type = cmCPackIFWPackage::CompareEqual; + this->Compare.Value = dependence.substr(pos + 1); + } else if ((pos = dependence.find('>')) != std::string::npos) { + this->Compare.Type = cmCPackIFWPackage::CompareGreater; + this->Compare.Value = dependence.substr(pos + 1); + } else if ((pos = dependence.find('-')) != std::string::npos) { + this->Compare.Type = cmCPackIFWPackage::CompareNone; + this->Compare.Value = dependence.substr(pos + 1); + } + size_t dashPos = dependence.find('-'); + if (dashPos != std::string::npos) { + pos = dashPos; + } + this->Name = + pos == std::string::npos ? dependence : dependence.substr(0, pos); +} + +std::string cmCPackIFWPackage::DependenceStruct::NameWithCompare() const +{ + if (this->Compare.Type == cmCPackIFWPackage::CompareNone) { + return this->Name; + } + + std::string result = this->Name; + + if (this->Compare.Type != cmCPackIFWPackage::CompareNone || + !this->Compare.Value.empty()) { + result += "-"; + } + + if (this->Compare.Type == cmCPackIFWPackage::CompareLessOrEqual) { + result += "<="; + } else if (this->Compare.Type == cmCPackIFWPackage::CompareGreaterOrEqual) { + result += ">="; + } else if (this->Compare.Type == cmCPackIFWPackage::CompareLess) { + result += "<"; + } else if (this->Compare.Type == cmCPackIFWPackage::CompareEqual) { + result += "="; + } else if (this->Compare.Type == cmCPackIFWPackage::CompareGreater) { + result += ">"; + } + + result += this->Compare.Value; + + return result; +} + +//------------------------------------------------------ cmCPackIFWPackage --- +cmCPackIFWPackage::cmCPackIFWPackage() + : Installer(CM_NULLPTR) +{ +} + +std::string cmCPackIFWPackage::GetComponentName(cmCPackComponent* component) +{ + if (!component) { + return ""; + } + const char* option = + this->GetOption("CPACK_IFW_COMPONENT_" + + cmsys::SystemTools::UpperCase(component->Name) + "_NAME"); + return option ? option : component->Name; +} + +void cmCPackIFWPackage::DefaultConfiguration() +{ + this->DisplayName.clear(); + this->Description.clear(); + this->Version = ""; + this->ReleaseDate = ""; + this->Script = ""; + this->Licenses.clear(); + this->UserInterfaces.clear(); + this->Translations.clear(); + this->SortingPriority = ""; + this->UpdateText = ""; + this->Default = ""; + this->Essential = ""; + this->Virtual = ""; + this->ForcedInstallation = ""; + this->RequiresAdminRights = ""; +} + +// Defaul configuration (all in one package) +int cmCPackIFWPackage::ConfigureFromOptions() +{ + // Restore defaul configuration + this->DefaultConfiguration(); + + // Name + this->Name = this->Generator->GetRootPackageName(); + + // Display name + if (const char* option = this->GetOption("CPACK_PACKAGE_NAME")) { + this->DisplayName[""] = option; + } else { + this->DisplayName[""] = "Your package"; + } + + // Description + if (const char* option = + this->GetOption("CPACK_PACKAGE_DESCRIPTION_SUMMARY")) { + this->Description[""] = option; + } else { + this->Description[""] = "Your package description"; + } + + // Version + if (const char* option = this->GetOption("CPACK_PACKAGE_VERSION")) { + this->Version = option; + } else { + this->Version = "1.0.0"; + } + + this->ForcedInstallation = "true"; + + return 1; +} + +int cmCPackIFWPackage::ConfigureFromComponent(cmCPackComponent* component) +{ + if (!component) { + return 0; + } + + // Restore defaul configuration + this->DefaultConfiguration(); + + std::string prefix = "CPACK_IFW_COMPONENT_" + + cmsys::SystemTools::UpperCase(component->Name) + "_"; + + // Display name + this->DisplayName[""] = component->DisplayName; + + // Description + this->Description[""] = component->Description; + + // Version + if (const char* optVERSION = this->GetOption(prefix + "VERSION")) { + this->Version = optVERSION; + } else if (const char* optPACKAGE_VERSION = + this->GetOption("CPACK_PACKAGE_VERSION")) { + this->Version = optPACKAGE_VERSION; + } else { + this->Version = "1.0.0"; + } + + // Script + if (const char* option = this->GetOption(prefix + "SCRIPT")) { + this->Script = option; + } + + // User interfaces + if (const char* option = this->GetOption(prefix + "USER_INTERFACES")) { + this->UserInterfaces.clear(); + cmSystemTools::ExpandListArgument(option, this->UserInterfaces); + } + + // CMake dependencies + if (!component->Dependencies.empty()) { + std::vector<cmCPackComponent*>::iterator dit; + for (dit = component->Dependencies.begin(); + dit != component->Dependencies.end(); ++dit) { + this->Dependencies.insert(this->Generator->ComponentPackages[*dit]); + } + } + + // Licenses + if (const char* option = this->GetOption(prefix + "LICENSES")) { + this->Licenses.clear(); + cmSystemTools::ExpandListArgument(option, this->Licenses); + if (this->Licenses.size() % 2 != 0) { + cmCPackIFWLogger( + WARNING, + prefix << "LICENSES" + << " should contain pairs of <display_name> and <file_path>." + << std::endl); + this->Licenses.clear(); + } + } + + // Priority + if (const char* option = this->GetOption(prefix + "PRIORITY")) { + this->SortingPriority = option; + cmCPackIFWLogger( + WARNING, "The \"PRIORITY\" option is set " + << "for component \"" << component->Name << "\", but there option is " + << "deprecated. Please use \"SORTING_PRIORITY\" option instead." + << std::endl); + } + + // Default + this->Default = component->IsDisabledByDefault ? "false" : "true"; + + // Essential + if (this->IsOn(prefix + "ESSENTIAL")) { + this->Essential = "true"; + } + + // Virtual + this->Virtual = component->IsHidden ? "true" : ""; + + // ForcedInstallation + this->ForcedInstallation = component->IsRequired ? "true" : "false"; + + return this->ConfigureFromPrefix(prefix); +} + +int cmCPackIFWPackage::ConfigureFromGroup(cmCPackComponentGroup* group) +{ + if (!group) { + return 0; + } + + // Restore defaul configuration + this->DefaultConfiguration(); + + std::string prefix = "CPACK_IFW_COMPONENT_GROUP_" + + cmsys::SystemTools::UpperCase(group->Name) + "_"; + + this->DisplayName[""] = group->DisplayName; + this->Description[""] = group->Description; + + // Version + if (const char* optVERSION = this->GetOption(prefix + "VERSION")) { + this->Version = optVERSION; + } else if (const char* optPACKAGE_VERSION = + this->GetOption("CPACK_PACKAGE_VERSION")) { + this->Version = optPACKAGE_VERSION; + } else { + this->Version = "1.0.0"; + } + + // Script + if (const char* option = this->GetOption(prefix + "SCRIPT")) { + this->Script = option; + } + + // User interfaces + if (const char* option = this->GetOption(prefix + "USER_INTERFACES")) { + this->UserInterfaces.clear(); + cmSystemTools::ExpandListArgument(option, this->UserInterfaces); + } + + // Licenses + if (const char* option = this->GetOption(prefix + "LICENSES")) { + this->Licenses.clear(); + cmSystemTools::ExpandListArgument(option, this->Licenses); + if (this->Licenses.size() % 2 != 0) { + cmCPackIFWLogger( + WARNING, + prefix << "LICENSES" + << " should contain pairs of <display_name> and <file_path>." + << std::endl); + this->Licenses.clear(); + } + } + + // Priority + if (const char* option = this->GetOption(prefix + "PRIORITY")) { + this->SortingPriority = option; + cmCPackIFWLogger( + WARNING, "The \"PRIORITY\" option is set " + << "for component group \"" << group->Name + << "\", but there option is " + << "deprecated. Please use \"SORTING_PRIORITY\" option instead." + << std::endl); + } + + return this->ConfigureFromPrefix(prefix); +} + +int cmCPackIFWPackage::ConfigureFromGroup(const std::string& groupName) +{ + // Group configuration + + cmCPackComponentGroup group; + std::string prefix = + "CPACK_COMPONENT_GROUP_" + cmsys::SystemTools::UpperCase(groupName) + "_"; + + if (const char* option = this->GetOption(prefix + "DISPLAY_NAME")) { + group.DisplayName = option; + } else { + group.DisplayName = group.Name; + } + + if (const char* option = this->GetOption(prefix + "DESCRIPTION")) { + group.Description = option; + } + group.IsBold = this->IsOn(prefix + "BOLD_TITLE"); + group.IsExpandedByDefault = this->IsOn(prefix + "EXPANDED"); + + // Package configuration + + group.Name = groupName; + + if (Generator) { + this->Name = this->Generator->GetGroupPackageName(&group); + } else { + this->Name = group.Name; + } + + return this->ConfigureFromGroup(&group); +} + +// Common options for components and groups +int cmCPackIFWPackage::ConfigureFromPrefix(const std::string& prefix) +{ + // Temporary variable for full option name + std::string option; + + // Display name + option = prefix + "DISPLAY_NAME"; + if (this->IsSetToEmpty(option)) { + this->DisplayName.clear(); + } else if (const char* value = this->GetOption(option)) { + this->ExpandListArgument(value, this->DisplayName); + } + + // Description + option = prefix + "DESCRIPTION"; + if (this->IsSetToEmpty(option)) { + this->Description.clear(); + } else if (const char* value = this->GetOption(option)) { + this->ExpandListArgument(value, this->Description); + } + + // Release date + option = prefix + "RELEASE_DATE"; + if (this->IsSetToEmpty(option)) { + this->ReleaseDate.clear(); + } else if (const char* value = this->GetOption(option)) { + this->ReleaseDate = value; + } + + // Sorting priority + option = prefix + "SORTING_PRIORITY"; + if (this->IsSetToEmpty(option)) { + this->SortingPriority.clear(); + } else if (const char* value = this->GetOption(option)) { + this->SortingPriority = value; + } + + // Update text + option = prefix + "UPDATE_TEXT"; + if (this->IsSetToEmpty(option)) { + this->UpdateText.clear(); + } else if (const char* value = this->GetOption(option)) { + this->UpdateText = value; + } + + // Translations + option = prefix + "TRANSLATIONS"; + if (this->IsSetToEmpty(option)) { + this->Translations.clear(); + } else if (const char* value = this->GetOption(option)) { + this->Translations.clear(); + cmSystemTools::ExpandListArgument(value, this->Translations); + } + + // QtIFW dependencies + std::vector<std::string> deps; + option = prefix + "DEPENDS"; + if (const char* value = this->GetOption(option)) { + cmSystemTools::ExpandListArgument(value, deps); + } + option = prefix + "DEPENDENCIES"; + if (const char* value = this->GetOption(option)) { + cmSystemTools::ExpandListArgument(value, deps); + } + for (std::vector<std::string>::iterator dit = deps.begin(); + dit != deps.end(); ++dit) { + DependenceStruct dep(*dit); + if (this->Generator->Packages.count(dep.Name)) { + cmCPackIFWPackage& depPkg = this->Generator->Packages[dep.Name]; + dep.Name = depPkg.Name; + } + bool hasDep = this->Generator->DependentPackages.count(dep.Name) > 0; + DependenceStruct& depRef = this->Generator->DependentPackages[dep.Name]; + if (!hasDep) { + depRef = dep; + } + this->AlienDependencies.insert(&depRef); + } + + // Automatic dependency on + option = prefix + "AUTO_DEPEND_ON"; + if (this->IsSetToEmpty(option)) { + this->AlienAutoDependOn.clear(); + } else if (const char* value = this->GetOption(option)) { + std::vector<std::string> depsOn; + cmSystemTools::ExpandListArgument(value, depsOn); + for (std::vector<std::string>::iterator dit = depsOn.begin(); + dit != depsOn.end(); ++dit) { + DependenceStruct dep(*dit); + if (this->Generator->Packages.count(dep.Name)) { + cmCPackIFWPackage& depPkg = this->Generator->Packages[dep.Name]; + dep.Name = depPkg.Name; + } + bool hasDep = this->Generator->DependentPackages.count(dep.Name) > 0; + DependenceStruct& depRef = this->Generator->DependentPackages[dep.Name]; + if (!hasDep) { + depRef = dep; + } + this->AlienAutoDependOn.insert(&depRef); + } + } + + // Visibility + option = prefix + "VIRTUAL"; + if (this->IsSetToEmpty(option)) { + this->Virtual.clear(); + } else if (this->IsOn(option)) { + this->Virtual = "true"; + } + + // Default selection + option = prefix + "DEFAULT"; + if (this->IsSetToEmpty(option)) { + this->Default.clear(); + } else if (const char* value = this->GetOption(option)) { + std::string lowerValue = cmsys::SystemTools::LowerCase(value); + if (lowerValue == "true") { + this->Default = "true"; + } else if (lowerValue == "false") { + this->Default = "false"; + } else if (lowerValue == "script") { + this->Default = "script"; + } else { + this->Default = value; + } + } + + // Forsed installation + option = prefix + "FORCED_INSTALLATION"; + if (this->IsSetToEmpty(option)) { + this->ForcedInstallation.clear(); + } else if (this->IsOn(option)) { + this->ForcedInstallation = "true"; + } else if (this->IsSetToOff(option)) { + this->ForcedInstallation = "false"; + } + + // Requires admin rights + option = prefix + "REQUIRES_ADMIN_RIGHTS"; + if (this->IsSetToEmpty(option)) { + this->RequiresAdminRights.clear(); + } else if (this->IsOn(option)) { + this->RequiresAdminRights = "true"; + } else if (this->IsSetToOff(option)) { + this->RequiresAdminRights = "false"; + } + + return 1; +} + +void cmCPackIFWPackage::GeneratePackageFile() +{ + // Lazy directory initialization + if (this->Directory.empty()) { + if (this->Installer) { + this->Directory = this->Installer->Directory + "/packages/" + this->Name; + } else if (this->Generator) { + this->Directory = this->Generator->toplevel + "/packages/" + this->Name; + } + } + + // Output stream + cmGeneratedFileStream fout((this->Directory + "/meta/package.xml").data()); + cmXMLWriter xout(fout); + + xout.StartDocument(); + + WriteGeneratedByToStrim(xout); + + xout.StartElement("Package"); + + // DisplayName (with translations) + for (std::map<std::string, std::string>::iterator it = + this->DisplayName.begin(); + it != this->DisplayName.end(); ++it) { + xout.StartElement("DisplayName"); + if (!it->first.empty()) { + xout.Attribute("xml:lang", it->first); + } + xout.Content(it->second); + xout.EndElement(); + } + + // Description (with translations) + for (std::map<std::string, std::string>::iterator it = + this->Description.begin(); + it != this->Description.end(); ++it) { + xout.StartElement("Description"); + if (!it->first.empty()) { + xout.Attribute("xml:lang", it->first); + } + xout.Content(it->second); + xout.EndElement(); + } + + // Update text + if (!this->UpdateText.empty()) { + xout.Element("UpdateText", this->UpdateText); + } + + xout.Element("Name", this->Name); + xout.Element("Version", this->Version); + + if (!this->ReleaseDate.empty()) { + xout.Element("ReleaseDate", this->ReleaseDate); + } else { + xout.Element("ReleaseDate", cmTimestamp().CurrentTime("%Y-%m-%d", true)); + } + + // Script (copy to meta dir) + if (!this->Script.empty()) { + std::string name = cmSystemTools::GetFilenameName(this->Script); + std::string path = this->Directory + "/meta/" + name; + cmsys::SystemTools::CopyFileIfDifferent(this->Script, path); + xout.Element("Script", name); + } + + // User Interfaces (copy to meta dir) + std::vector<std::string> userInterfaces = UserInterfaces; + for (size_t i = 0; i < userInterfaces.size(); i++) { + std::string name = cmSystemTools::GetFilenameName(userInterfaces[i]); + std::string path = this->Directory + "/meta/" + name; + cmsys::SystemTools::CopyFileIfDifferent(userInterfaces[i], path); + userInterfaces[i] = name; + } + if (!userInterfaces.empty()) { + xout.StartElement("UserInterfaces"); + for (size_t i = 0; i < userInterfaces.size(); i++) { + xout.Element("UserInterface", userInterfaces[i]); + } + xout.EndElement(); + } + + // Translations (copy to meta dir) + std::vector<std::string> translations = Translations; + for (size_t i = 0; i < translations.size(); i++) { + std::string name = cmSystemTools::GetFilenameName(translations[i]); + std::string path = this->Directory + "/meta/" + name; + cmsys::SystemTools::CopyFileIfDifferent(translations[i], path); + translations[i] = name; + } + if (!translations.empty()) { + xout.StartElement("Translations"); + for (size_t i = 0; i < translations.size(); i++) { + xout.Element("Translation", translations[i]); + } + xout.EndElement(); + } + + // Dependencies + std::set<DependenceStruct> compDepSet; + for (std::set<DependenceStruct*>::iterator ait = + this->AlienDependencies.begin(); + ait != this->AlienDependencies.end(); ++ait) { + compDepSet.insert(*(*ait)); + } + for (std::set<cmCPackIFWPackage*>::iterator it = this->Dependencies.begin(); + it != this->Dependencies.end(); ++it) { + compDepSet.insert(DependenceStruct((*it)->Name)); + } + // Write dependencies + if (!compDepSet.empty()) { + std::ostringstream dependencies; + std::set<DependenceStruct>::iterator it = compDepSet.begin(); + dependencies << it->NameWithCompare(); + ++it; + while (it != compDepSet.end()) { + dependencies << "," << it->NameWithCompare(); + ++it; + } + xout.Element("Dependencies", dependencies.str()); + } + + // Automatic dependency on + std::set<DependenceStruct> compAutoDepSet; + for (std::set<DependenceStruct*>::iterator ait = + this->AlienAutoDependOn.begin(); + ait != this->AlienAutoDependOn.end(); ++ait) { + compAutoDepSet.insert(*(*ait)); + } + // Write automatic dependency on + if (!compAutoDepSet.empty()) { + std::ostringstream dependencies; + std::set<DependenceStruct>::iterator it = compAutoDepSet.begin(); + dependencies << it->NameWithCompare(); + ++it; + while (it != compAutoDepSet.end()) { + dependencies << "," << it->NameWithCompare(); + ++it; + } + xout.Element("AutoDependOn", dependencies.str()); + } + + // Licenses (copy to meta dir) + std::vector<std::string> licenses = this->Licenses; + for (size_t i = 1; i < licenses.size(); i += 2) { + std::string name = cmSystemTools::GetFilenameName(licenses[i]); + std::string path = this->Directory + "/meta/" + name; + cmsys::SystemTools::CopyFileIfDifferent(licenses[i], path); + licenses[i] = name; + } + if (!licenses.empty()) { + xout.StartElement("Licenses"); + for (size_t i = 0; i < licenses.size(); i += 2) { + xout.StartElement("License"); + xout.Attribute("name", licenses[i]); + xout.Attribute("file", licenses[i + 1]); + xout.EndElement(); + } + xout.EndElement(); + } + + if (!this->ForcedInstallation.empty()) { + xout.Element("ForcedInstallation", this->ForcedInstallation); + } + + if (!this->RequiresAdminRights.empty()) { + xout.Element("RequiresAdminRights", this->RequiresAdminRights); + } + + if (!this->Virtual.empty()) { + xout.Element("Virtual", this->Virtual); + } else if (!this->Default.empty()) { + xout.Element("Default", this->Default); + } + + // Essential + if (!this->Essential.empty()) { + xout.Element("Essential", this->Essential); + } + + // Priority + if (!this->SortingPriority.empty()) { + xout.Element("SortingPriority", this->SortingPriority); + } + + xout.EndElement(); + xout.EndDocument(); +} diff --git a/Source/CPack/IFW/cmCPackIFWPackage.h b/Source/CPack/IFW/cmCPackIFWPackage.h new file mode 100644 index 000000000..cec59b03c --- /dev/null +++ b/Source/CPack/IFW/cmCPackIFWPackage.h @@ -0,0 +1,147 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmCPackIFWPackage_h +#define cmCPackIFWPackage_h + +#include "cmConfigure.h" // IWYU pragma: keep + +#include "cmCPackIFWCommon.h" + +#include <map> +#include <set> +#include <string> +#include <vector> + +class cmCPackComponent; +class cmCPackComponentGroup; +class cmCPackIFWInstaller; + +/** \class cmCPackIFWPackage + * \brief A single component to be installed by CPack IFW generator + */ +class cmCPackIFWPackage : public cmCPackIFWCommon +{ +public: + // Types + + enum CompareTypes + { + CompareNone = 0x0, + CompareEqual = 0x1, + CompareLess = 0x2, + CompareLessOrEqual = 0x3, + CompareGreater = 0x4, + CompareGreaterOrEqual = 0x5 + }; + + struct CompareStruct + { + CompareStruct(); + + unsigned int Type; + std::string Value; + }; + + struct DependenceStruct + { + DependenceStruct(); + DependenceStruct(const std::string& dependence); + + std::string Name; + CompareStruct Compare; + + std::string NameWithCompare() const; + + bool operator<(const DependenceStruct& other) const + { + return Name < other.Name; + } + }; + +public: + // [Con|De]structor + + /** + * Construct package + */ + cmCPackIFWPackage(); + +public: + // Configuration + + /// Human-readable name of the component + std::map<std::string, std::string> DisplayName; + + /// Human-readable description of the component + std::map<std::string, std::string> Description; + + /// Version number of the component + std::string Version; + + /// Date when this component version was released + std::string ReleaseDate; + + /// Domain-like identification for this component + std::string Name; + + /// File name of a script being loaded + std::string Script; + + /// List of license agreements to be accepted by the installing user + std::vector<std::string> Licenses; + + /// List of pages to load + std::vector<std::string> UserInterfaces; + + /// List of translation files to load + std::vector<std::string> Translations; + + /// Priority of the component in the tree + std::string SortingPriority; + + /// Description added to the component description + std::string UpdateText; + + /// Set to true to preselect the component in the installer + std::string Default; + + /// Marks the package as essential to force a restart of the MaintenanceTool + std::string Essential; + + /// Set to true to hide the component from the installer + std::string Virtual; + + /// Determines that the package must always be installed + std::string ForcedInstallation; + + /// Package needs to be installed with elevated permissions + std::string RequiresAdminRights; + +public: + // Internal implementation + + std::string GetComponentName(cmCPackComponent* component); + + void DefaultConfiguration(); + + int ConfigureFromOptions(); + int ConfigureFromComponent(cmCPackComponent* component); + int ConfigureFromGroup(cmCPackComponentGroup* group); + int ConfigureFromGroup(const std::string& groupName); + int ConfigureFromPrefix(const std::string& prefix); + + void GeneratePackageFile(); + + // Pointer to installer + cmCPackIFWInstaller* Installer; + // Collection of dependencies + std::set<cmCPackIFWPackage*> Dependencies; + // Collection of unresolved dependencies + std::set<DependenceStruct*> AlienDependencies; + // Collection of unresolved automatic dependency on + std::set<DependenceStruct*> AlienAutoDependOn; + // Patch to package directory + std::string Directory; +}; + +#endif // cmCPackIFWPackage_h diff --git a/Source/CPack/IFW/cmCPackIFWRepository.cxx b/Source/CPack/IFW/cmCPackIFWRepository.cxx new file mode 100644 index 000000000..b115db057 --- /dev/null +++ b/Source/CPack/IFW/cmCPackIFWRepository.cxx @@ -0,0 +1,288 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmCPackIFWRepository.h" + +#include "cmCPackIFWGenerator.h" +#include "cmGeneratedFileStream.h" +#include "cmSystemTools.h" +#include "cmXMLParser.h" +#include "cmXMLWriter.h" + +#include <stddef.h> + +cmCPackIFWRepository::cmCPackIFWRepository() + : Update(cmCPackIFWRepository::None) +{ +} + +bool cmCPackIFWRepository::IsValid() const +{ + bool valid = true; + + switch (this->Update) { + case cmCPackIFWRepository::None: + valid = !this->Url.empty(); + break; + case cmCPackIFWRepository::Add: + valid = !this->Url.empty(); + break; + case cmCPackIFWRepository::Remove: + valid = !this->Url.empty(); + break; + case cmCPackIFWRepository::Replace: + valid = !this->OldUrl.empty() && !this->NewUrl.empty(); + break; + } + + return valid; +} + +bool cmCPackIFWRepository::ConfigureFromOptions() +{ + // Name; + if (this->Name.empty()) { + return false; + } + + std::string prefix = + "CPACK_IFW_REPOSITORY_" + cmsys::SystemTools::UpperCase(this->Name) + "_"; + + // Update + if (this->IsOn(prefix + "ADD")) { + this->Update = cmCPackIFWRepository::Add; + } else if (IsOn(prefix + "REMOVE")) { + this->Update = cmCPackIFWRepository::Remove; + } else if (IsOn(prefix + "REPLACE")) { + this->Update = cmCPackIFWRepository::Replace; + } else { + this->Update = cmCPackIFWRepository::None; + } + + // Url + if (const char* url = this->GetOption(prefix + "URL")) { + this->Url = url; + } else { + this->Url = ""; + } + + // Old url + if (const char* oldUrl = this->GetOption(prefix + "OLD_URL")) { + this->OldUrl = oldUrl; + } else { + this->OldUrl = ""; + } + + // New url + if (const char* newUrl = this->GetOption(prefix + "NEW_URL")) { + this->NewUrl = newUrl; + } else { + this->NewUrl = ""; + } + + // Enabled + if (this->IsOn(prefix + "DISABLED")) { + this->Enabled = "0"; + } else { + this->Enabled = ""; + } + + // Username + if (const char* username = this->GetOption(prefix + "USERNAME")) { + this->Username = username; + } else { + this->Username = ""; + } + + // Password + if (const char* password = this->GetOption(prefix + "PASSWORD")) { + this->Password = password; + } else { + this->Password = ""; + } + + // DisplayName + if (const char* displayName = this->GetOption(prefix + "DISPLAY_NAME")) { + this->DisplayName = displayName; + } else { + this->DisplayName = ""; + } + + return this->IsValid(); +} + +/** \class cmCPackeIFWUpdatesPatcher + * \brief Helper class that parses and patch Updates.xml file (QtIFW) + */ +class cmCPackeIFWUpdatesPatcher : public cmXMLParser +{ +public: + cmCPackeIFWUpdatesPatcher(cmCPackIFWRepository* r, cmXMLWriter& x) + : repository(r) + , xout(x) + , patched(false) + { + } + + cmCPackIFWRepository* repository; + cmXMLWriter& xout; + bool patched; + +protected: + void StartElement(const std::string& name, const char** atts) CM_OVERRIDE + { + this->xout.StartElement(name); + this->StartFragment(atts); + } + + void StartFragment(const char** atts) + { + for (size_t i = 0; atts[i]; i += 2) { + const char* key = atts[i]; + const char* value = atts[i + 1]; + this->xout.Attribute(key, value); + } + } + + void EndElement(const std::string& name) CM_OVERRIDE + { + if (name == "Updates" && !this->patched) { + this->repository->WriteRepositoryUpdates(this->xout); + this->patched = true; + } + this->xout.EndElement(); + if (this->patched) { + return; + } + if (name == "Checksum") { + this->repository->WriteRepositoryUpdates(this->xout); + this->patched = true; + } + } + + void CharacterDataHandler(const char* data, int length) CM_OVERRIDE + { + std::string content(data, data + length); + if (content == "" || content == " " || content == " " || + content == "\n") { + return; + } + this->xout.Content(content); + } +}; + +bool cmCPackIFWRepository::PatchUpdatesXml() +{ + // Lazy directory initialization + if (this->Directory.empty() && this->Generator) { + this->Directory = this->Generator->toplevel; + } + + // Filenames + std::string updatesXml = this->Directory + "/repository/Updates.xml"; + std::string updatesPatchXml = + this->Directory + "/repository/UpdatesPatch.xml"; + + // Output stream + cmGeneratedFileStream fout(updatesPatchXml.data()); + cmXMLWriter xout(fout); + + xout.StartDocument(); + + this->WriteGeneratedByToStrim(xout); + + // Patch + { + cmCPackeIFWUpdatesPatcher patcher(this, xout); + patcher.ParseFile(updatesXml.data()); + } + + xout.EndDocument(); + + fout.Close(); + + return cmSystemTools::RenameFile(updatesPatchXml.data(), updatesXml.data()); +} + +void cmCPackIFWRepository::WriteRepositoryConfig(cmXMLWriter& xout) +{ + xout.StartElement("Repository"); + + // Url + xout.Element("Url", this->Url); + // Enabled + if (!this->Enabled.empty()) { + xout.Element("Enabled", this->Enabled); + } + // Username + if (!this->Username.empty()) { + xout.Element("Username", this->Username); + } + // Password + if (!this->Password.empty()) { + xout.Element("Password", this->Password); + } + // DisplayName + if (!this->DisplayName.empty()) { + xout.Element("DisplayName", this->DisplayName); + } + + xout.EndElement(); +} + +void cmCPackIFWRepository::WriteRepositoryUpdate(cmXMLWriter& xout) +{ + xout.StartElement("Repository"); + + switch (this->Update) { + case cmCPackIFWRepository::None: + break; + case cmCPackIFWRepository::Add: + xout.Attribute("action", "add"); + break; + case cmCPackIFWRepository::Remove: + xout.Attribute("action", "remove"); + break; + case cmCPackIFWRepository::Replace: + xout.Attribute("action", "replace"); + break; + } + + // Url + if (this->Update == cmCPackIFWRepository::Add || + this->Update == cmCPackIFWRepository::Remove) { + xout.Attribute("url", this->Url); + } else if (Update == cmCPackIFWRepository::Replace) { + xout.Attribute("oldUrl", this->OldUrl); + xout.Attribute("newUrl", this->NewUrl); + } + // Enabled + if (!this->Enabled.empty()) { + xout.Attribute("enabled", this->Enabled); + } + // Username + if (!this->Username.empty()) { + xout.Attribute("username", this->Username); + } + // Password + if (!this->Password.empty()) { + xout.Attribute("password", this->Password); + } + // DisplayName + if (!this->DisplayName.empty()) { + xout.Attribute("displayname", this->DisplayName); + } + + xout.EndElement(); +} + +void cmCPackIFWRepository::WriteRepositoryUpdates(cmXMLWriter& xout) +{ + if (!this->RepositoryUpdate.empty()) { + xout.StartElement("RepositoryUpdate"); + for (RepositoriesVector::iterator rit = this->RepositoryUpdate.begin(); + rit != this->RepositoryUpdate.end(); ++rit) { + (*rit)->WriteRepositoryUpdate(xout); + } + xout.EndElement(); + } +} diff --git a/Source/CPack/IFW/cmCPackIFWRepository.h b/Source/CPack/IFW/cmCPackIFWRepository.h new file mode 100644 index 000000000..227cfae7a --- /dev/null +++ b/Source/CPack/IFW/cmCPackIFWRepository.h @@ -0,0 +1,88 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmCPackIFWRepository_h +#define cmCPackIFWRepository_h + +#include "cmConfigure.h" // IWYU pragma: keep + +#include "cmCPackIFWCommon.h" + +#include <string> +#include <vector> + +class cmXMLWriter; + +/** \class cmCPackIFWRepository + * \brief A remote repository to be created CPack IFW generator + */ +class cmCPackIFWRepository : public cmCPackIFWCommon +{ +public: + // Types + + enum Action + { + None, + Add, + Remove, + Replace + }; + + typedef std::vector<cmCPackIFWRepository*> RepositoriesVector; + +public: + // Constructor + + /** + * Construct repository + */ + cmCPackIFWRepository(); + +public: + // Configuration + + /// Internal repository name + std::string Name; + + /// Optional update action + Action Update; + + /// Is points to a list of available components + std::string Url; + + /// Is points to a list that will replaced + std::string OldUrl; + + /// Is points to a list that will replace to + std::string NewUrl; + + /// With "0" disabling this repository + std::string Enabled; + + /// Is used as user on a protected repository + std::string Username; + + /// Is password to use on a protected repository + std::string Password; + + /// Is optional string to display instead of the URL + std::string DisplayName; + +public: + // Internal implementation + + bool IsValid() const; + + bool ConfigureFromOptions(); + + bool PatchUpdatesXml(); + + void WriteRepositoryConfig(cmXMLWriter& xout); + void WriteRepositoryUpdate(cmXMLWriter& xout); + void WriteRepositoryUpdates(cmXMLWriter& xout); + + RepositoriesVector RepositoryUpdate; + std::string Directory; +}; + +#endif // cmCPackIFWRepository_h diff --git a/Source/CPack/OSXScriptLauncher.cxx b/Source/CPack/OSXScriptLauncher.cxx index a9842c1df..b48bf1214 100644 --- a/Source/CPack/OSXScriptLauncher.cxx +++ b/Source/CPack/OSXScriptLauncher.cxx @@ -1,90 +1,76 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ -#include <cmsys/SystemTools.hxx> -#include <cmsys/Process.h> -#include <cmsys/ios/fstream> -#include <cmsys/ios/iostream> +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmsys/FStream.hxx" +#include "cmsys/Process.h" +#include "cmsys/SystemTools.hxx" +#include <iostream> +#include <stddef.h> +#include <string> +#include <vector> #include <CoreFoundation/CoreFoundation.h> // For the PATH_MAX constant #include <sys/syslimits.h> -#define DebugError(x) \ - ofs << x << cmsys_ios::endl; \ - cmsys_ios::cout << x << cmsys_ios::endl +#define DebugError(x) \ + ofs << x << std::endl; \ + std::cout << x << std::endl int main(int argc, char* argv[]) { - //if ( cmsys::SystemTools::FileExists( - cmsys_stl::string cwd = cmsys::SystemTools::GetCurrentWorkingDirectory(); - cmsys_ios::ofstream ofs("/tmp/output.txt"); + // if ( cmsys::SystemTools::FileExists( + cmsys::ofstream ofs("/tmp/output.txt"); CFStringRef fileName; CFBundleRef appBundle; CFURLRef scriptFileURL; - UInt8 *path; + UInt8* path; - //get CF URL for script - if (! (appBundle = CFBundleGetMainBundle())) - { + // get CF URL for script + if (!(appBundle = CFBundleGetMainBundle())) { DebugError("Cannot get main bundle"); return 1; - } + } fileName = CFSTR("RuntimeScript"); - if (! (scriptFileURL = CFBundleCopyResourceURL(appBundle, fileName, NULL, - NULL))) - { + if (!(scriptFileURL = + CFBundleCopyResourceURL(appBundle, fileName, NULL, NULL))) { DebugError("CFBundleCopyResourceURL failed"); return 1; - } + } - //create path string - if (! (path = new UInt8[PATH_MAX])) - { + // create path string + if (!(path = new UInt8[PATH_MAX])) { return 1; - } + } - //get the file system path of the url as a cstring - //in an encoding suitable for posix apis - if ( CFURLGetFileSystemRepresentation(scriptFileURL, true, path, - PATH_MAX) == false) - { + // get the file system path of the url as a cstring + // in an encoding suitable for posix apis + if (CFURLGetFileSystemRepresentation(scriptFileURL, true, path, PATH_MAX) == + false) { DebugError("CFURLGetFileSystemRepresentation failed"); return 1; - } + } - //dispose of the CF variable + // dispose of the CF variable CFRelease(scriptFileURL); - cmsys_stl::string fullScriptPath = reinterpret_cast<char*>(path); - delete [] path; - + std::string fullScriptPath = reinterpret_cast<char*>(path); + delete[] path; - if (! cmsys::SystemTools::FileExists(fullScriptPath.c_str())) - { + if (!cmsys::SystemTools::FileExists(fullScriptPath.c_str())) { return 1; - } + } - cmsys_stl::string scriptDirectory = cmsys::SystemTools::GetFilenamePath( - fullScriptPath); - ofs << fullScriptPath.c_str() << cmsys_ios::endl; - cmsys_stl::vector<const char*> args; + std::string scriptDirectory = + cmsys::SystemTools::GetFilenamePath(fullScriptPath); + ofs << fullScriptPath << std::endl; + std::vector<const char*> args; args.push_back(fullScriptPath.c_str()); int cc; - for ( cc = 1; cc < argc; ++ cc ) - { + for (cc = 1; cc < argc; ++cc) { args.push_back(argv[cc]); - } + } args.push_back(0); cmsysProcess* cp = cmsysProcess_New(); @@ -97,49 +83,36 @@ int main(int argc, char* argv[]) std::vector<char> tempOutput; char* data; int length; - while(cmsysProcess_WaitForData(cp, &data, &length, 0)) - { + while (cmsysProcess_WaitForData(cp, &data, &length, 0)) { // Translate NULL characters in the output into valid text. - // Visual Studio 7 puts these characters in the output of its - // build process. - for(int i=0; i < length; ++i) - { - if(data[i] == '\0') - { + for (int i = 0; i < length; ++i) { + if (data[i] == '\0') { data[i] = ' '; - } } - cmsys_ios::cout.write(data, length); } + std::cout.write(data, length); + } cmsysProcess_WaitForExit(cp, 0); bool result = true; - if(cmsysProcess_GetState(cp) == cmsysProcess_State_Exited) - { - if ( cmsysProcess_GetExitValue(cp) != 0 ) - { + if (cmsysProcess_GetState(cp) == cmsysProcess_State_Exited) { + if (cmsysProcess_GetExitValue(cp) != 0) { result = false; - } } - else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Exception) - { + } else if (cmsysProcess_GetState(cp) == cmsysProcess_State_Exception) { const char* exception_str = cmsysProcess_GetExceptionString(cp); std::cerr << exception_str << std::endl; result = false; - } - else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Error) - { + } else if (cmsysProcess_GetState(cp) == cmsysProcess_State_Error) { const char* error_str = cmsysProcess_GetErrorString(cp); std::cerr << error_str << std::endl; result = false; - } - else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Expired) - { + } else if (cmsysProcess_GetState(cp) == cmsysProcess_State_Expired) { const char* error_str = "Process terminated due to timeout\n"; std::cerr << error_str << std::endl; result = false; - } + } cmsysProcess_Delete(cp); diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.cxx b/Source/CPack/WiX/cmCPackWIXGenerator.cxx index cc9dec7b8..274dfd0ce 100644 --- a/Source/CPack/WiX/cmCPackWIXGenerator.cxx +++ b/Source/CPack/WiX/cmCPackWIXGenerator.cxx @@ -1,110 +1,130 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2012 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCPackWIXGenerator.h" -#include <cmSystemTools.h> -#include <cmGeneratedFileStream.h> -#include <CPack/cmCPackLog.h> -#include <CPack/cmCPackComponentGroup.h> - -#include "cmWIXSourceWriter.h" +#include "cmCPackComponentGroup.h" +#include "cmCPackLog.h" +#include "cmCryptoHash.h" +#include "cmGeneratedFileStream.h" +#include "cmInstalledFile.h" +#include "cmSystemTools.h" +#include "cmUuid.h" +#include <algorithm> + +#include "cmWIXDirectoriesSourceWriter.h" +#include "cmWIXFeaturesSourceWriter.h" +#include "cmWIXFilesSourceWriter.h" #include "cmWIXRichTextFormatWriter.h" +#include "cmWIXSourceWriter.h" -#include <cmsys/SystemTools.hxx> -#include <cmsys/Directory.hxx> +#include "cmsys/Directory.hxx" +#include "cmsys/Encoding.hxx" +#include "cmsys/FStream.hxx" +#include "cmsys/SystemTools.hxx" #include <rpc.h> // for GUID generation +cmCPackWIXGenerator::cmCPackWIXGenerator() + : Patch(0) + , ComponentGuidType(cmWIXSourceWriter::WIX_GENERATED_GUID) +{ +} + +cmCPackWIXGenerator::~cmCPackWIXGenerator() +{ + if (this->Patch) { + delete this->Patch; + } +} + int cmCPackWIXGenerator::InitializeInternal() { componentPackageMethod = ONE_PACKAGE; + this->Patch = new cmWIXPatch(this->Logger); return this->Superclass::InitializeInternal(); } -bool cmCPackWIXGenerator::RunWiXCommand(const std::string& command) +bool cmCPackWIXGenerator::RunWiXCommand(std::string const& command) { - std::string cpackTopLevel; - if(!RequireOption("CPACK_TOPLEVEL_DIRECTORY", cpackTopLevel)) - { - return false; - } + std::string logFileName = this->CPackTopLevel + "/wix.log"; - std::string logFileName = cpackTopLevel + "/wix.log"; - - cmCPackLogger(cmCPackLog::LOG_DEBUG, - "Running WiX command: " << command << std::endl); + cmCPackLogger(cmCPackLog::LOG_DEBUG, "Running WiX command: " << command + << std::endl); std::string output; int returnValue = 0; bool status = cmSystemTools::RunSingleCommand(command.c_str(), &output, - &returnValue, 0, cmSystemTools::OUTPUT_NONE); + &output, &returnValue, 0, + cmSystemTools::OUTPUT_NONE); - std::ofstream logFile(logFileName.c_str(), std::ios::app); + cmsys::ofstream logFile(logFileName.c_str(), std::ios::app); logFile << command << std::endl; logFile << output; logFile.close(); - if(!status || returnValue) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Problem running WiX candle. " - "Please check '" << logFileName << "' for errors." << std::endl); + if (!status || returnValue) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running WiX candle. " + "Please check '" + << logFileName << "' for errors." << std::endl); return false; - } + } return true; } -bool cmCPackWIXGenerator::RunCandleCommand( - const std::string& sourceFile, const std::string& objectFile) +bool cmCPackWIXGenerator::RunCandleCommand(std::string const& sourceFile, + std::string const& objectFile) { std::string executable; - if(!RequireOption("CPACK_WIX_CANDLE_EXECUTABLE", executable)) - { + if (!RequireOption("CPACK_WIX_CANDLE_EXECUTABLE", executable)) { return false; - } + } - std::stringstream command; + std::ostringstream command; command << QuotePath(executable); command << " -nologo"; command << " -arch " << GetArchitecture(); command << " -out " << QuotePath(objectFile); + + for (extension_set_t::const_iterator i = CandleExtensions.begin(); + i != CandleExtensions.end(); ++i) { + command << " -ext " << QuotePath(*i); + } + + AddCustomFlags("CPACK_WIX_CANDLE_EXTRA_FLAGS", command); + command << " " << QuotePath(sourceFile); return RunWiXCommand(command.str()); } -bool cmCPackWIXGenerator::RunLightCommand(const std::string& objectFiles) +bool cmCPackWIXGenerator::RunLightCommand(std::string const& objectFiles) { std::string executable; - if(!RequireOption("CPACK_WIX_LIGHT_EXECUTABLE", executable)) - { + if (!RequireOption("CPACK_WIX_LIGHT_EXECUTABLE", executable)) { return false; - } + } - std::stringstream command; + std::ostringstream command; command << QuotePath(executable); command << " -nologo"; command << " -out " << QuotePath(packageFileNames.at(0)); - command << " -ext WixUIExtension"; + + for (extension_set_t::const_iterator i = this->LightExtensions.begin(); + i != this->LightExtensions.end(); ++i) { + command << " -ext " << QuotePath(*i); + } + const char* const cultures = GetOption("CPACK_WIX_CULTURES"); - if(cultures) - { + if (cultures) { command << " -cultures:" << cultures; - } + } + + AddCustomFlags("CPACK_WIX_LIGHT_EXTRA_FLAGS", command); + command << " " << objectFiles; return RunWiXCommand(command.str()); @@ -112,114 +132,193 @@ bool cmCPackWIXGenerator::RunLightCommand(const std::string& objectFiles) int cmCPackWIXGenerator::PackageFiles() { - if(!PackageFilesImpl() || cmSystemTools::GetErrorOccuredFlag()) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Fatal WiX Generator Error" << std::endl); + if (!PackageFilesImpl() || cmSystemTools::GetErrorOccuredFlag()) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Fatal WiX Generator Error" + << std::endl); return false; - } + } return true; } bool cmCPackWIXGenerator::InitializeWiXConfiguration() { - if(!ReadListFile("CPackWIX.cmake")) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error while executing CPackWIX.cmake" << std::endl); + if (!ReadListFile("CPackWIX.cmake")) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Error while executing CPackWIX.cmake" + << std::endl); return false; - } + } - if(GetOption("CPACK_WIX_PRODUCT_GUID") == 0) - { + if (GetOption("CPACK_WIX_PRODUCT_GUID") == 0) { std::string guid = GenerateGUID(); SetOption("CPACK_WIX_PRODUCT_GUID", guid.c_str()); cmCPackLogger(cmCPackLog::LOG_VERBOSE, - "CPACK_WIX_PRODUCT_GUID implicitly set to " << guid << " . " - << std::endl); - } + "CPACK_WIX_PRODUCT_GUID implicitly set to " << guid << " . " + << std::endl); + } - if(GetOption("CPACK_WIX_UPGRADE_GUID") == 0) - { + if (GetOption("CPACK_WIX_UPGRADE_GUID") == 0) { std::string guid = GenerateGUID(); SetOption("CPACK_WIX_UPGRADE_GUID", guid.c_str()); - cmCPackLogger(cmCPackLog::LOG_WARNING, - "CPACK_WIX_UPGRADE_GUID implicitly set to " << guid << " . " - "Please refer to the documentation on how and why " - "you might want to set this explicitly." << std::endl); - } + cmCPackLogger( + cmCPackLog::LOG_WARNING, "CPACK_WIX_UPGRADE_GUID implicitly set to " + << guid << " . " + "Please refer to the documentation on how and why " + "you might want to set this explicitly." + << std::endl); + } - std::string cpackTopLevel; - if(!RequireOption("CPACK_TOPLEVEL_DIRECTORY", cpackTopLevel)) - { + if (!RequireOption("CPACK_TOPLEVEL_DIRECTORY", this->CPackTopLevel)) { return false; - } + } - if(GetOption("CPACK_WIX_LICENSE_RTF") == 0) - { - std::string licenseFilename = cpackTopLevel + "/License.rtf"; + if (GetOption("CPACK_WIX_LICENSE_RTF") == 0) { + std::string licenseFilename = this->CPackTopLevel + "/License.rtf"; SetOption("CPACK_WIX_LICENSE_RTF", licenseFilename.c_str()); - if(!CreateLicenseFile()) - { + if (!CreateLicenseFile()) { return false; + } + } + + if (GetOption("CPACK_PACKAGE_VENDOR") == 0) { + std::string defaultVendor = "Humanity"; + SetOption("CPACK_PACKAGE_VENDOR", defaultVendor.c_str()); + + cmCPackLogger(cmCPackLog::LOG_VERBOSE, + "CPACK_PACKAGE_VENDOR implicitly set to " + << defaultVendor << " . " << std::endl); + } + + if (GetOption("CPACK_WIX_UI_REF") == 0) { + std::string defaultRef = "WixUI_InstallDir"; + + if (!this->Components.empty()) { + defaultRef = "WixUI_FeatureTree"; + } + + SetOption("CPACK_WIX_UI_REF", defaultRef.c_str()); + } + + const char* packageContact = GetOption("CPACK_PACKAGE_CONTACT"); + if (packageContact != 0 && GetOption("CPACK_WIX_PROPERTY_ARPCONTACT") == 0) { + SetOption("CPACK_WIX_PROPERTY_ARPCONTACT", packageContact); + } + + CollectExtensions("CPACK_WIX_EXTENSIONS", this->CandleExtensions); + CollectExtensions("CPACK_WIX_CANDLE_EXTENSIONS", this->CandleExtensions); + + this->LightExtensions.insert("WixUIExtension"); + CollectExtensions("CPACK_WIX_EXTENSIONS", this->LightExtensions); + CollectExtensions("CPACK_WIX_LIGHT_EXTENSIONS", this->LightExtensions); + + const char* patchFilePath = GetOption("CPACK_WIX_PATCH_FILE"); + if (patchFilePath) { + std::vector<std::string> patchFilePaths; + cmSystemTools::ExpandListArgument(patchFilePath, patchFilePaths); + + for (size_t i = 0; i < patchFilePaths.size(); ++i) { + if (!this->Patch->LoadFragments(patchFilePaths[i])) { + return false; } } + } + + // if install folder is supposed to be set absolutely, the default + // component guid "*" cannot be used + if (cmSystemTools::IsOn(GetOption("CPACK_WIX_SKIP_PROGRAM_FOLDER"))) { + this->ComponentGuidType = cmWIXSourceWriter::CMAKE_GENERATED_GUID; + } return true; } bool cmCPackWIXGenerator::PackageFilesImpl() { - if(!InitializeWiXConfiguration()) - { + if (!InitializeWiXConfiguration()) { return false; - } + } - if(!CreateWiXVariablesIncludeFile()) - { - return false; - } + CreateWiXVariablesIncludeFile(); + CreateWiXPropertiesIncludeFile(); + CreateWiXProductFragmentIncludeFile(); - if(!CreateWiXSourceFiles()) - { + if (!CreateWiXSourceFiles()) { return false; + } + + AppendUserSuppliedExtraSources(); + + std::set<std::string> usedBaseNames; + + std::ostringstream objectFiles; + for (size_t i = 0; i < this->WixSources.size(); ++i) { + std::string const& sourceFilename = this->WixSources[i]; + + std::string baseName = + cmSystemTools::GetFilenameWithoutLastExtension(sourceFilename); + + unsigned int counter = 0; + std::string uniqueBaseName = baseName; + + while (usedBaseNames.find(uniqueBaseName) != usedBaseNames.end()) { + std::ostringstream tmp; + tmp << baseName << ++counter; + uniqueBaseName = tmp.str(); } - std::stringstream objectFiles; - for(size_t i = 0; i < wixSources.size(); ++i) - { - const std::string& sourceFilename = wixSources[i]; + usedBaseNames.insert(uniqueBaseName); std::string objectFilename = - cmSystemTools::GetFilenameWithoutExtension(sourceFilename) + ".wixobj"; + this->CPackTopLevel + "/" + uniqueBaseName + ".wixobj"; - if(!RunCandleCommand(sourceFilename, objectFilename)) - { + if (!RunCandleCommand(sourceFilename, objectFilename)) { return false; - } + } objectFiles << " " << QuotePath(objectFilename); - } + } + + AppendUserSuppliedExtraObjects(objectFiles); return RunLightCommand(objectFiles.str()); } -bool cmCPackWIXGenerator::CreateWiXVariablesIncludeFile() +void cmCPackWIXGenerator::AppendUserSuppliedExtraSources() { - std::string cpackTopLevel; - if(!RequireOption("CPACK_TOPLEVEL_DIRECTORY", cpackTopLevel)) - { - return false; - } + const char* cpackWixExtraSources = GetOption("CPACK_WIX_EXTRA_SOURCES"); + if (!cpackWixExtraSources) + return; - std::string includeFilename = - cpackTopLevel + "/cpack_variables.wxi"; + cmSystemTools::ExpandListArgument(cpackWixExtraSources, this->WixSources); +} + +void cmCPackWIXGenerator::AppendUserSuppliedExtraObjects(std::ostream& stream) +{ + const char* cpackWixExtraObjects = GetOption("CPACK_WIX_EXTRA_OBJECTS"); + if (!cpackWixExtraObjects) + return; + + std::vector<std::string> expandedExtraObjects; + + cmSystemTools::ExpandListArgument(cpackWixExtraObjects, + expandedExtraObjects); + + for (size_t i = 0; i < expandedExtraObjects.size(); ++i) { + stream << " " << QuotePath(expandedExtraObjects[i]); + } +} + +void cmCPackWIXGenerator::CreateWiXVariablesIncludeFile() +{ + std::string includeFilename = this->CPackTopLevel + "/cpack_variables.wxi"; + + cmWIXSourceWriter includeFile(this->Logger, includeFilename, + this->ComponentGuidType, + cmWIXSourceWriter::INCLUDE_ELEMENT_ROOT); - cmWIXSourceWriter includeFile(Logger, includeFilename, true); CopyDefinition(includeFile, "CPACK_WIX_PRODUCT_GUID"); CopyDefinition(includeFile, "CPACK_WIX_UPGRADE_GUID"); CopyDefinition(includeFile, "CPACK_PACKAGE_VENDOR"); @@ -230,250 +329,476 @@ bool cmCPackWIXGenerator::CreateWiXVariablesIncludeFile() CopyDefinition(includeFile, "CPACK_WIX_UI_BANNER"); CopyDefinition(includeFile, "CPACK_WIX_UI_DIALOG"); SetOptionIfNotSet("CPACK_WIX_PROGRAM_MENU_FOLDER", - GetOption("CPACK_PACKAGE_NAME")); + GetOption("CPACK_PACKAGE_NAME")); CopyDefinition(includeFile, "CPACK_WIX_PROGRAM_MENU_FOLDER"); + CopyDefinition(includeFile, "CPACK_WIX_UI_REF"); +} - return true; +void cmCPackWIXGenerator::CreateWiXPropertiesIncludeFile() +{ + std::string includeFilename = this->CPackTopLevel + "/properties.wxi"; + + cmWIXSourceWriter includeFile(this->Logger, includeFilename, + this->ComponentGuidType, + cmWIXSourceWriter::INCLUDE_ELEMENT_ROOT); + + std::string prefix = "CPACK_WIX_PROPERTY_"; + std::vector<std::string> options = GetOptions(); + + for (size_t i = 0; i < options.size(); ++i) { + std::string const& name = options[i]; + + if (name.length() > prefix.length() && + name.substr(0, prefix.length()) == prefix) { + std::string id = name.substr(prefix.length()); + std::string value = GetOption(name.c_str()); + + includeFile.BeginElement("Property"); + includeFile.AddAttribute("Id", id); + includeFile.AddAttribute("Value", value); + includeFile.EndElement("Property"); + } + } + + if (GetOption("CPACK_WIX_PROPERTY_ARPINSTALLLOCATION") == 0) { + includeFile.BeginElement("Property"); + includeFile.AddAttribute("Id", "INSTALL_ROOT"); + includeFile.AddAttribute("Secure", "yes"); + + includeFile.BeginElement("RegistrySearch"); + includeFile.AddAttribute("Id", "FindInstallLocation"); + includeFile.AddAttribute("Root", "HKLM"); + includeFile.AddAttribute( + "Key", "Software\\Microsoft\\Windows\\" + "CurrentVersion\\Uninstall\\[WIX_UPGRADE_DETECTED]"); + includeFile.AddAttribute("Name", "InstallLocation"); + includeFile.AddAttribute("Type", "raw"); + includeFile.EndElement("RegistrySearch"); + includeFile.EndElement("Property"); + + includeFile.BeginElement("SetProperty"); + includeFile.AddAttribute("Id", "ARPINSTALLLOCATION"); + includeFile.AddAttribute("Value", "[INSTALL_ROOT]"); + includeFile.AddAttribute("After", "CostFinalize"); + includeFile.EndElement("SetProperty"); + } } -void cmCPackWIXGenerator::CopyDefinition( - cmWIXSourceWriter &source, const std::string &name) +void cmCPackWIXGenerator::CreateWiXProductFragmentIncludeFile() +{ + std::string includeFilename = this->CPackTopLevel + "/product_fragment.wxi"; + + cmWIXSourceWriter includeFile(this->Logger, includeFilename, + this->ComponentGuidType, + cmWIXSourceWriter::INCLUDE_ELEMENT_ROOT); + + this->Patch->ApplyFragment("#PRODUCT", includeFile); +} + +void cmCPackWIXGenerator::CopyDefinition(cmWIXSourceWriter& source, + std::string const& name) { const char* value = GetOption(name.c_str()); - if(value) - { + if (value) { AddDefinition(source, name, value); - } + } } void cmCPackWIXGenerator::AddDefinition(cmWIXSourceWriter& source, - const std::string& name, const std::string& value) + std::string const& name, + std::string const& value) { - std::stringstream tmp; + std::ostringstream tmp; tmp << name << "=\"" << value << '"'; - source.AddProcessingInstruction("define", - cmWIXSourceWriter::WindowsCodepageToUtf8(tmp.str())); + source.AddProcessingInstruction("define", tmp.str()); } bool cmCPackWIXGenerator::CreateWiXSourceFiles() { - std::string cpackTopLevel; - if(!RequireOption("CPACK_TOPLEVEL_DIRECTORY", cpackTopLevel)) - { - return false; - } - + // if install folder is supposed to be set absolutely, the default + // component guid "*" cannot be used std::string directoryDefinitionsFilename = - cpackTopLevel + "/directories.wxs"; + this->CPackTopLevel + "/directories.wxs"; - wixSources.push_back(directoryDefinitionsFilename); + this->WixSources.push_back(directoryDefinitionsFilename); - cmWIXSourceWriter directoryDefinitions(Logger, directoryDefinitionsFilename); + cmWIXDirectoriesSourceWriter directoryDefinitions( + this->Logger, directoryDefinitionsFilename, this->ComponentGuidType); directoryDefinitions.BeginElement("Fragment"); + std::string installRoot; + if (!RequireOption("CPACK_PACKAGE_INSTALL_DIRECTORY", installRoot)) { + return false; + } + directoryDefinitions.BeginElement("Directory"); directoryDefinitions.AddAttribute("Id", "TARGETDIR"); directoryDefinitions.AddAttribute("Name", "SourceDir"); - directoryDefinitions.BeginElement("Directory"); - if(GetArchitecture() == "x86") - { - directoryDefinitions.AddAttribute("Id", "ProgramFilesFolder"); - } - else - { - directoryDefinitions.AddAttribute("Id", "ProgramFiles64Folder"); - } + size_t installRootSize = + directoryDefinitions.BeginInstallationPrefixDirectory(GetRootFolderId(), + installRoot); - std::vector<std::string> install_root; + std::string fileDefinitionsFilename = this->CPackTopLevel + "/files.wxs"; - std::string tmp; - if(!RequireOption("CPACK_PACKAGE_INSTALL_DIRECTORY", tmp)) - { - return false; - } + this->WixSources.push_back(fileDefinitionsFilename); - cmSystemTools::SplitPath(tmp.c_str(), install_root); + cmWIXFilesSourceWriter fileDefinitions(this->Logger, fileDefinitionsFilename, + this->ComponentGuidType); - if(!install_root.empty() && install_root.back().empty()) - { - install_root.pop_back(); - } + fileDefinitions.BeginElement("Fragment"); + + std::string featureDefinitionsFilename = + this->CPackTopLevel + "/features.wxs"; - for(size_t i = 1; i < install_root.size(); ++i) - { - directoryDefinitions.BeginElement("Directory"); + this->WixSources.push_back(featureDefinitionsFilename); - if(i == install_root.size() - 1) - { - directoryDefinitions.AddAttribute("Id", "INSTALL_ROOT"); - } - else - { - std::stringstream ss; - ss << "INSTALL_PREFIX_" << i; - directoryDefinitions.AddAttribute("Id", ss.str()); - } + cmWIXFeaturesSourceWriter featureDefinitions( + this->Logger, featureDefinitionsFilename, this->ComponentGuidType); + + featureDefinitions.BeginElement("Fragment"); + + featureDefinitions.BeginElement("Feature"); + featureDefinitions.AddAttribute("Id", "ProductFeature"); + featureDefinitions.AddAttribute("Display", "expand"); + featureDefinitions.AddAttribute("Absent", "disallow"); + featureDefinitions.AddAttribute("ConfigurableDirectory", "INSTALL_ROOT"); - directoryDefinitions.AddAttribute("Name", install_root[i]); + std::string cpackPackageName; + if (!RequireOption("CPACK_PACKAGE_NAME", cpackPackageName)) { + return false; } - size_t directoryCounter = 0; - size_t fileCounter = 0; + std::string featureTitle = cpackPackageName; + if (const char* title = GetOption("CPACK_WIX_ROOT_FEATURE_TITLE")) { + featureTitle = title; + } + featureDefinitions.AddAttribute("Title", featureTitle); + if (const char* desc = GetOption("CPACK_WIX_ROOT_FEATURE_DESCRIPTION")) { + featureDefinitions.AddAttribute("Description", desc); + } + featureDefinitions.AddAttribute("Level", "1"); + this->Patch->ApplyFragment("#PRODUCTFEATURE", featureDefinitions); - std::string fileDefinitionsFilename = - cpackTopLevel + "/files.wxs"; + const char* package = GetOption("CPACK_WIX_CMAKE_PACKAGE_REGISTRY"); + if (package) { + featureDefinitions.CreateCMakePackageRegistryEntry( + package, GetOption("CPACK_WIX_UPGRADE_GUID")); + } - wixSources.push_back(fileDefinitionsFilename); + if (!CreateFeatureHierarchy(featureDefinitions)) { + return false; + } - cmWIXSourceWriter fileDefinitions(Logger, fileDefinitionsFilename); - fileDefinitions.BeginElement("Fragment"); + featureDefinitions.EndElement("Feature"); - std::string featureDefinitionsFilename = - cpackTopLevel +"/features.wxs"; + std::set<cmWIXShortcuts::Type> emittedShortcutTypes; - wixSources.push_back(featureDefinitionsFilename); + cmWIXShortcuts globalShortcuts; + if (Components.empty()) { + AddComponentsToFeature(toplevel, "ProductFeature", directoryDefinitions, + fileDefinitions, featureDefinitions, + globalShortcuts); - cmWIXSourceWriter featureDefinitions(Logger, featureDefinitionsFilename); - featureDefinitions.BeginElement("Fragment"); + globalShortcuts.AddShortcutTypes(emittedShortcutTypes); + } else { + for (std::map<std::string, cmCPackComponent>::const_iterator i = + this->Components.begin(); + i != this->Components.end(); ++i) { + cmCPackComponent const& component = i->second; - featureDefinitions.BeginElement("Feature"); - featureDefinitions.AddAttribute("Id", "ProductFeature"); - featureDefinitions.AddAttribute("Title", Name); - featureDefinitions.AddAttribute("Level", "1"); - featureDefinitions.EndElement(); + std::string componentPath = toplevel; + componentPath += "/"; + componentPath += component.Name; - featureDefinitions.BeginElement("FeatureRef"); - featureDefinitions.AddAttribute("Id", "ProductFeature"); + std::string componentFeatureId = "CM_C_" + component.Name; - const char *cpackPackageExecutables = GetOption("CPACK_PACKAGE_EXECUTABLES"); - std::vector<std::string> cpackPkgExecutables; - std::string regKey; - if ( cpackPackageExecutables ) - { - cmSystemTools::ExpandListArgument(cpackPackageExecutables, - cpackPkgExecutables); - if ( cpackPkgExecutables.size() % 2 != 0 ) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "CPACK_PACKAGE_EXECUTABLES should contain pairs of <executable> and " - "<icon name>." << std::endl); - cpackPkgExecutables.clear(); - } + cmWIXShortcuts featureShortcuts; + AddComponentsToFeature(componentPath, componentFeatureId, + directoryDefinitions, fileDefinitions, + featureDefinitions, featureShortcuts); - const char *cpackVendor = GetOption("CPACK_PACKAGE_VENDOR"); - const char *cpackPkgName = GetOption("CPACK_PACKAGE_NAME"); - if (!cpackVendor || !cpackPkgName) - { - cmCPackLogger(cmCPackLog::LOG_WARNING, "CPACK_PACKAGE_VENDOR and " - "CPACK_PACKAGE_NAME must be defined for shortcut creation" << std::endl); - cpackPkgExecutables.clear(); - } - else - { - regKey = std::string("Software/") + cpackVendor + "/" + cpackPkgName; + featureShortcuts.AddShortcutTypes(emittedShortcutTypes); + + if (!CreateShortcuts(component.Name, componentFeatureId, + featureShortcuts, false, fileDefinitions, + featureDefinitions)) { + return false; } } + } - std::vector<std::string> dirIdExecutables; - AddDirectoryAndFileDefinitons( - toplevel, "INSTALL_ROOT", - directoryDefinitions, fileDefinitions, featureDefinitions, - directoryCounter, fileCounter, cpackPkgExecutables, dirIdExecutables); - - directoryDefinitions.EndElement(); - directoryDefinitions.EndElement(); - - if (dirIdExecutables.size() > 0 && dirIdExecutables.size() % 3 == 0) - { - fileDefinitions.BeginElement("DirectoryRef"); - fileDefinitions.AddAttribute("Id", "PROGRAM_MENU_FOLDER"); - fileDefinitions.BeginElement("Component"); - fileDefinitions.AddAttribute("Id", "SHORTCUT"); - fileDefinitions.AddAttribute("Guid", "*"); - - std::vector<std::string>::iterator it; - for ( it = dirIdExecutables.begin() ; - it != dirIdExecutables.end(); - ++it) - { - std::string fileName = *it++; - std::string iconName = *it++; - std::string directoryId = *it; - - fileDefinitions.BeginElement("Shortcut"); - std::string shortcutName = fileName; // the iconName is mor likely to contain blanks early on - std::string::size_type const dotPos = shortcutName.find('.'); - if(std::string::npos == dotPos) - { shortcutName = shortcutName.substr(0, dotPos); } - fileDefinitions.AddAttribute("Id", "SHORTCUT_" + shortcutName); - fileDefinitions.AddAttribute("Name", iconName); - std::string target = "[" + directoryId + "]" + fileName; - fileDefinitions.AddAttribute("Target", target); - fileDefinitions.AddAttribute("WorkingDirectory", directoryId); - fileDefinitions.EndElement(); - } - fileDefinitions.BeginElement("Shortcut"); - fileDefinitions.AddAttribute("Id", "UNINSTALL"); - std::string pkgName = GetOption("CPACK_PACKAGE_NAME"); - fileDefinitions.AddAttribute("Name", "Uninstall " + pkgName); - fileDefinitions.AddAttribute("Description", "Uninstalls " + pkgName); - fileDefinitions.AddAttribute("Target", "[SystemFolder]msiexec.exe"); - fileDefinitions.AddAttribute("Arguments", "/x [ProductCode]"); - fileDefinitions.EndElement(); - fileDefinitions.BeginElement("RemoveFolder"); - fileDefinitions.AddAttribute("Id", "PROGRAM_MENU_FOLDER"); - fileDefinitions.AddAttribute("On", "uninstall"); - fileDefinitions.EndElement(); - fileDefinitions.BeginElement("RegistryValue"); - fileDefinitions.AddAttribute("Root", "HKCU"); - fileDefinitions.AddAttribute("Key", regKey); - fileDefinitions.AddAttribute("Name", "installed"); - fileDefinitions.AddAttribute("Type", "integer"); - fileDefinitions.AddAttribute("Value", "1"); - fileDefinitions.AddAttribute("KeyPath", "yes"); - - featureDefinitions.BeginElement("ComponentRef"); - featureDefinitions.AddAttribute("Id", "SHORTCUT"); - featureDefinitions.EndElement(); - directoryDefinitions.BeginElement("Directory"); - directoryDefinitions.AddAttribute("Id", "ProgramMenuFolder"); - directoryDefinitions.BeginElement("Directory"); - directoryDefinitions.AddAttribute("Id", "PROGRAM_MENU_FOLDER"); - const char *startMenuFolder = GetOption("CPACK_WIX_PROGRAM_MENU_FOLDER"); - directoryDefinitions.AddAttribute("Name", startMenuFolder); - } - - featureDefinitions.EndElement(); - featureDefinitions.EndElement(); - fileDefinitions.EndElement(); - directoryDefinitions.EndElement(); + bool emitUninstallShortcut = + emittedShortcutTypes.find(cmWIXShortcuts::START_MENU) != + emittedShortcutTypes.end(); + + if (!CreateShortcuts(std::string(), "ProductFeature", globalShortcuts, + emitUninstallShortcut, fileDefinitions, + featureDefinitions)) { + return false; + } + + featureDefinitions.EndElement("Fragment"); + fileDefinitions.EndElement("Fragment"); + + directoryDefinitions.EndInstallationPrefixDirectory(installRootSize); + + if (emittedShortcutTypes.find(cmWIXShortcuts::START_MENU) != + emittedShortcutTypes.end()) { + directoryDefinitions.EmitStartMenuFolder( + GetOption("CPACK_WIX_PROGRAM_MENU_FOLDER")); + } + + if (emittedShortcutTypes.find(cmWIXShortcuts::DESKTOP) != + emittedShortcutTypes.end()) { + directoryDefinitions.EmitDesktopFolder(); + } + + if (emittedShortcutTypes.find(cmWIXShortcuts::STARTUP) != + emittedShortcutTypes.end()) { + directoryDefinitions.EmitStartupFolder(); + } + + directoryDefinitions.EndElement("Directory"); + directoryDefinitions.EndElement("Fragment"); + + if (!GenerateMainSourceFileFromTemplate()) { + return false; + } + + return this->Patch->CheckForUnappliedFragments(); +} + +std::string cmCPackWIXGenerator::GetRootFolderId() const +{ + if (cmSystemTools::IsOn(GetOption("CPACK_WIX_SKIP_PROGRAM_FOLDER"))) { + return ""; + } + + std::string result = "ProgramFiles<64>Folder"; + + const char* rootFolderId = GetOption("CPACK_WIX_ROOT_FOLDER_ID"); + if (rootFolderId) { + result = rootFolderId; + } + if (GetArchitecture() == "x86") { + cmSystemTools::ReplaceString(result, "<64>", ""); + } else { + cmSystemTools::ReplaceString(result, "<64>", "64"); + } + + return result; +} + +bool cmCPackWIXGenerator::GenerateMainSourceFileFromTemplate() +{ std::string wixTemplate = FindTemplate("WIX.template.in"); - if(GetOption("CPACK_WIX_TEMPLATE") != 0) - { + if (GetOption("CPACK_WIX_TEMPLATE") != 0) { wixTemplate = GetOption("CPACK_WIX_TEMPLATE"); - } - if(wixTemplate.empty()) - { + } + + if (wixTemplate.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Could not find CPack WiX template file WIX.template.in" << std::endl); + "Could not find CPack WiX template file WIX.template.in" + << std::endl); return false; - } + } - std::string mainSourceFilePath = cpackTopLevel + "/main.wxs"; + std::string mainSourceFilePath = this->CPackTopLevel + "/main.wxs"; - if(!ConfigureFile(wixTemplate.c_str(), mainSourceFilePath .c_str())) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Failed creating '" << mainSourceFilePath << - "'' from template." << std::endl); + if (!ConfigureFile(wixTemplate.c_str(), mainSourceFilePath.c_str())) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Failed creating '" + << mainSourceFilePath << "'' from template." << std::endl); return false; + } + + this->WixSources.push_back(mainSourceFilePath); + + return true; +} + +bool cmCPackWIXGenerator::CreateFeatureHierarchy( + cmWIXFeaturesSourceWriter& featureDefinitions) +{ + for (std::map<std::string, cmCPackComponentGroup>::const_iterator i = + ComponentGroups.begin(); + i != ComponentGroups.end(); ++i) { + cmCPackComponentGroup const& group = i->second; + if (group.ParentGroup == 0) { + featureDefinitions.EmitFeatureForComponentGroup(group, *this->Patch); + } + } + + for (std::map<std::string, cmCPackComponent>::const_iterator i = + this->Components.begin(); + i != this->Components.end(); ++i) { + cmCPackComponent const& component = i->second; + + if (!component.Group) { + featureDefinitions.EmitFeatureForComponent(component, *this->Patch); + } + } + + return true; +} + +bool cmCPackWIXGenerator::AddComponentsToFeature( + std::string const& rootPath, std::string const& featureId, + cmWIXDirectoriesSourceWriter& directoryDefinitions, + cmWIXFilesSourceWriter& fileDefinitions, + cmWIXFeaturesSourceWriter& featureDefinitions, cmWIXShortcuts& shortcuts) +{ + featureDefinitions.BeginElement("FeatureRef"); + featureDefinitions.AddAttribute("Id", featureId); + + std::vector<std::string> cpackPackageExecutablesList; + const char* cpackPackageExecutables = GetOption("CPACK_PACKAGE_EXECUTABLES"); + if (cpackPackageExecutables) { + cmSystemTools::ExpandListArgument(cpackPackageExecutables, + cpackPackageExecutablesList); + if (cpackPackageExecutablesList.size() % 2 != 0) { + cmCPackLogger( + cmCPackLog::LOG_ERROR, + "CPACK_PACKAGE_EXECUTABLES should contain pairs of <executable> and " + "<text label>." + << std::endl); + return false; + } + } + + std::vector<std::string> cpackPackageDesktopLinksList; + const char* cpackPackageDesktopLinks = + GetOption("CPACK_CREATE_DESKTOP_LINKS"); + if (cpackPackageDesktopLinks) { + cmSystemTools::ExpandListArgument(cpackPackageDesktopLinks, + cpackPackageDesktopLinksList); + } + + AddDirectoryAndFileDefinitions( + rootPath, "INSTALL_ROOT", directoryDefinitions, fileDefinitions, + featureDefinitions, cpackPackageExecutablesList, + cpackPackageDesktopLinksList, shortcuts); + + featureDefinitions.EndElement("FeatureRef"); + + return true; +} + +bool cmCPackWIXGenerator::CreateShortcuts( + std::string const& cpackComponentName, std::string const& featureId, + cmWIXShortcuts const& shortcuts, bool emitUninstallShortcut, + cmWIXFilesSourceWriter& fileDefinitions, + cmWIXFeaturesSourceWriter& featureDefinitions) +{ + if (!shortcuts.empty(cmWIXShortcuts::START_MENU)) { + if (!this->CreateShortcutsOfSpecificType( + cmWIXShortcuts::START_MENU, cpackComponentName, featureId, "", + shortcuts, emitUninstallShortcut, fileDefinitions, + featureDefinitions)) { + return false; + } + } + + if (!shortcuts.empty(cmWIXShortcuts::DESKTOP)) { + if (!this->CreateShortcutsOfSpecificType( + cmWIXShortcuts::DESKTOP, cpackComponentName, featureId, "DESKTOP", + shortcuts, false, fileDefinitions, featureDefinitions)) { + return false; } + } - wixSources.push_back(mainSourceFilePath); + if (!shortcuts.empty(cmWIXShortcuts::STARTUP)) { + if (!this->CreateShortcutsOfSpecificType( + cmWIXShortcuts::STARTUP, cpackComponentName, featureId, "STARTUP", + shortcuts, false, fileDefinitions, featureDefinitions)) { + return false; + } + } + + return true; +} + +bool cmCPackWIXGenerator::CreateShortcutsOfSpecificType( + cmWIXShortcuts::Type type, std::string const& cpackComponentName, + std::string const& featureId, std::string const& idPrefix, + cmWIXShortcuts const& shortcuts, bool emitUninstallShortcut, + cmWIXFilesSourceWriter& fileDefinitions, + cmWIXFeaturesSourceWriter& featureDefinitions) +{ + std::string directoryId; + switch (type) { + case cmWIXShortcuts::START_MENU: + directoryId = "PROGRAM_MENU_FOLDER"; + break; + case cmWIXShortcuts::DESKTOP: + directoryId = "DesktopFolder"; + break; + case cmWIXShortcuts::STARTUP: + directoryId = "StartupFolder"; + break; + default: + return false; + } + + featureDefinitions.BeginElement("FeatureRef"); + featureDefinitions.AddAttribute("Id", featureId); + + std::string cpackVendor; + if (!RequireOption("CPACK_PACKAGE_VENDOR", cpackVendor)) { + return false; + } + + std::string cpackPackageName; + if (!RequireOption("CPACK_PACKAGE_NAME", cpackPackageName)) { + return false; + } + + std::string idSuffix; + if (!cpackComponentName.empty()) { + idSuffix += "_"; + idSuffix += cpackComponentName; + } + + std::string componentId = "CM_SHORTCUT"; + if (idPrefix.size()) { + componentId += "_" + idPrefix; + } + + componentId += idSuffix; + + fileDefinitions.BeginElement("DirectoryRef"); + fileDefinitions.AddAttribute("Id", directoryId); + + fileDefinitions.BeginElement("Component"); + fileDefinitions.AddAttribute("Id", componentId); + fileDefinitions.AddAttribute( + "Guid", fileDefinitions.CreateGuidFromComponentId(componentId)); + + this->Patch->ApplyFragment(componentId, fileDefinitions); + + std::string registryKey = + std::string("Software\\") + cpackVendor + "\\" + cpackPackageName; + + shortcuts.EmitShortcuts(type, registryKey, cpackComponentName, + fileDefinitions); + + if (type == cmWIXShortcuts::START_MENU) { + fileDefinitions.EmitRemoveFolder("CM_REMOVE_PROGRAM_MENU_FOLDER" + + idSuffix); + } + + if (emitUninstallShortcut) { + fileDefinitions.EmitUninstallShortcut(cpackPackageName); + } + + fileDefinitions.EndElement("Component"); + fileDefinitions.EndElement("DirectoryRef"); + + featureDefinitions.EmitComponentRef(componentId); + featureDefinitions.EndElement("FeatureRef"); return true; } @@ -481,162 +806,162 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles() bool cmCPackWIXGenerator::CreateLicenseFile() { std::string licenseSourceFilename; - if(!RequireOption("CPACK_RESOURCE_FILE_LICENSE", licenseSourceFilename)) - { + if (!RequireOption("CPACK_RESOURCE_FILE_LICENSE", licenseSourceFilename)) { return false; - } + } std::string licenseDestinationFilename; - if(!RequireOption("CPACK_WIX_LICENSE_RTF", licenseDestinationFilename)) - { + if (!RequireOption("CPACK_WIX_LICENSE_RTF", licenseDestinationFilename)) { return false; - } + } std::string extension = GetRightmostExtension(licenseSourceFilename); - if(extension == ".rtf") - { - cmSystemTools::CopyAFile( - licenseSourceFilename.c_str(), - licenseDestinationFilename.c_str()); - } - else if(extension == ".txt") - { + if (extension == ".rtf") { + cmSystemTools::CopyAFile(licenseSourceFilename.c_str(), + licenseDestinationFilename.c_str()); + } else if (extension == ".txt") { cmWIXRichTextFormatWriter rtfWriter(licenseDestinationFilename); - std::ifstream licenseSource(licenseSourceFilename.c_str()); + cmsys::ifstream licenseSource(licenseSourceFilename.c_str()); std::string line; - while(std::getline(licenseSource, line)) - { + while (std::getline(licenseSource, line)) { rtfWriter.AddText(line); rtfWriter.AddText("\n"); - } } - else - { + } else { cmCPackLogger(cmCPackLog::LOG_ERROR, - "unsupported WiX License file extension '" << - extension << "'" << std::endl); + "unsupported WiX License file extension '" + << extension << "'" << std::endl); return false; - } + } return true; } -void cmCPackWIXGenerator::AddDirectoryAndFileDefinitons( - const std::string& topdir, - const std::string& directoryId, - cmWIXSourceWriter& directoryDefinitions, - cmWIXSourceWriter& fileDefinitions, - cmWIXSourceWriter& featureDefinitions, - size_t& directoryCounter, - size_t& fileCounter, - const std::vector<std::string>& pkgExecutables, - std::vector<std::string>& dirIdExecutables) +void cmCPackWIXGenerator::AddDirectoryAndFileDefinitions( + std::string const& topdir, std::string const& directoryId, + cmWIXDirectoriesSourceWriter& directoryDefinitions, + cmWIXFilesSourceWriter& fileDefinitions, + cmWIXFeaturesSourceWriter& featureDefinitions, + std::vector<std::string> const& packageExecutables, + std::vector<std::string> const& desktopExecutables, + cmWIXShortcuts& shortcuts) { cmsys::Directory dir; dir.Load(topdir.c_str()); - for(size_t i = 0; i < dir.GetNumberOfFiles(); ++i) - { + std::string relativeDirectoryPath = + cmSystemTools::RelativePath(toplevel.c_str(), topdir.c_str()); + + if (relativeDirectoryPath.empty()) { + relativeDirectoryPath = "."; + } + + cmInstalledFile const* directoryInstalledFile = this->GetInstalledFile( + this->RelativePathWithoutComponentPrefix(relativeDirectoryPath)); + + bool emptyDirectory = dir.GetNumberOfFiles() == 2; + bool createDirectory = false; + + if (emptyDirectory) { + createDirectory = true; + } + + if (directoryInstalledFile) { + if (directoryInstalledFile->HasProperty("CPACK_WIX_ACL")) { + createDirectory = true; + } + } + + if (createDirectory) { + std::string componentId = fileDefinitions.EmitComponentCreateFolder( + directoryId, GenerateGUID(), directoryInstalledFile); + featureDefinitions.EmitComponentRef(componentId); + } + + if (emptyDirectory) { + return; + } + + for (size_t i = 0; i < dir.GetNumberOfFiles(); ++i) { std::string fileName = dir.GetFile(static_cast<unsigned long>(i)); - if(fileName == "." || fileName == "..") - { + if (fileName == "." || fileName == "..") { continue; - } + } std::string fullPath = topdir + "/" + fileName; - if(cmSystemTools::FileIsDirectory(fullPath.c_str())) - { - std::stringstream tmp; - tmp << "DIR_ID_" << ++directoryCounter; - std::string subDirectoryId = tmp.str(); + std::string relativePath = + cmSystemTools::RelativePath(toplevel.c_str(), fullPath.c_str()); + + std::string id = PathToId(relativePath); + + if (cmSystemTools::FileIsDirectory(fullPath.c_str())) { + std::string subDirectoryId = std::string("CM_D") + id; directoryDefinitions.BeginElement("Directory"); directoryDefinitions.AddAttribute("Id", subDirectoryId); directoryDefinitions.AddAttribute("Name", fileName); + this->Patch->ApplyFragment(subDirectoryId, directoryDefinitions); + + AddDirectoryAndFileDefinitions( + fullPath, subDirectoryId, directoryDefinitions, fileDefinitions, + featureDefinitions, packageExecutables, desktopExecutables, shortcuts); + + directoryDefinitions.EndElement("Directory"); + } else { + cmInstalledFile const* installedFile = this->GetInstalledFile( + this->RelativePathWithoutComponentPrefix(relativePath)); - AddDirectoryAndFileDefinitons( - fullPath, subDirectoryId, - directoryDefinitions, - fileDefinitions, - featureDefinitions, - directoryCounter, - fileCounter, - pkgExecutables, - dirIdExecutables); - directoryDefinitions.EndElement(); + if (installedFile) { + shortcuts.CreateFromProperties(id, directoryId, *installedFile); } - else - { - std::stringstream tmp; - tmp << "_ID_" << ++fileCounter; - std::string idSuffix = tmp.str(); - - std::string componentId = std::string("CMP") + idSuffix; - std::string fileId = std::string("FILE") + idSuffix; - - fileDefinitions.BeginElement("DirectoryRef"); - fileDefinitions.AddAttribute("Id", directoryId); - - fileDefinitions.BeginElement("Component"); - fileDefinitions.AddAttribute("Id", componentId); - fileDefinitions.AddAttribute("Guid", "*"); - - fileDefinitions.BeginElement("File"); - fileDefinitions.AddAttribute("Id", fileId); - fileDefinitions.AddAttribute("Source", fullPath); - fileDefinitions.AddAttribute("KeyPath", "yes"); - - fileDefinitions.EndElement(); - fileDefinitions.EndElement(); - fileDefinitions.EndElement(); - - featureDefinitions.BeginElement("ComponentRef"); - featureDefinitions.AddAttribute("Id", componentId); - featureDefinitions.EndElement(); - - std::vector<std::string>::const_iterator it; - for (it = pkgExecutables.begin() ; - it != pkgExecutables.end() ; - ++it) - { - std::string execName = *it++; - std::string iconName = *it; + + std::string componentId = fileDefinitions.EmitComponentFile( + directoryId, id, fullPath, *(this->Patch), installedFile); + + featureDefinitions.EmitComponentRef(componentId); + + for (size_t j = 0; j < packageExecutables.size(); ++j) { + std::string const& executableName = packageExecutables[j++]; + std::string const& textLabel = packageExecutables[j]; if (cmSystemTools::LowerCase(fileName) == - cmSystemTools::LowerCase(execName) + ".exe") - { - dirIdExecutables.push_back(fileName); - dirIdExecutables.push_back(iconName); - dirIdExecutables.push_back(directoryId); + cmSystemTools::LowerCase(executableName) + ".exe") { + cmWIXShortcut shortcut; + shortcut.label = textLabel; + shortcut.workingDirectoryId = directoryId; + shortcuts.insert(cmWIXShortcuts::START_MENU, id, shortcut); + + if (!desktopExecutables.empty() && + std::find(desktopExecutables.begin(), desktopExecutables.end(), + executableName) != desktopExecutables.end()) { + shortcuts.insert(cmWIXShortcuts::DESKTOP, id, shortcut); } } } } + } } -bool cmCPackWIXGenerator::RequireOption( - const std::string& name, std::string &value) const +bool cmCPackWIXGenerator::RequireOption(std::string const& name, + std::string& value) const { const char* tmp = GetOption(name.c_str()); - if(tmp) - { + if (tmp) { value = tmp; return true; - } - else - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Required variable " << name << " not set" << std::endl); + } else { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Required variable " + << name << " not set" << std::endl); return false; - } + } } std::string cmCPackWIXGenerator::GetArchitecture() const @@ -644,14 +969,11 @@ std::string cmCPackWIXGenerator::GetArchitecture() const std::string void_p_size; RequireOption("CPACK_WIX_SIZEOF_VOID_P", void_p_size); - if(void_p_size == "8") - { + if (void_p_size == "8") { return "x64"; - } - else - { + } else { return "x86"; - } + } } std::string cmCPackWIXGenerator::GenerateGUID() @@ -659,30 +981,174 @@ std::string cmCPackWIXGenerator::GenerateGUID() UUID guid; UuidCreate(&guid); - unsigned char *tmp = 0; - UuidToString(&guid, &tmp); + unsigned short* tmp = 0; + UuidToStringW(&guid, &tmp); - std::string result(reinterpret_cast<char*>(tmp)); - RpcStringFree(&tmp); + std::string result = + cmsys::Encoding::ToNarrow(reinterpret_cast<wchar_t*>(tmp)); + RpcStringFreeW(&tmp); return cmSystemTools::UpperCase(result); } -std::string cmCPackWIXGenerator::QuotePath(const std::string& path) +std::string cmCPackWIXGenerator::QuotePath(std::string const& path) { return std::string("\"") + path + '"'; } std::string cmCPackWIXGenerator::GetRightmostExtension( - const std::string& filename) + std::string const& filename) { std::string extension; std::string::size_type i = filename.rfind("."); - if(i != std::string::npos) - { + if (i != std::string::npos) { extension = filename.substr(i); - } + } return cmSystemTools::LowerCase(extension); } + +std::string cmCPackWIXGenerator::PathToId(std::string const& path) +{ + id_map_t::const_iterator i = PathToIdMap.find(path); + if (i != PathToIdMap.end()) + return i->second; + + std::string id = CreateNewIdForPath(path); + return id; +} + +std::string cmCPackWIXGenerator::CreateNewIdForPath(std::string const& path) +{ + std::vector<std::string> components; + cmSystemTools::SplitPath(path.c_str(), components, false); + + size_t replacementCount = 0; + + std::string identifier; + std::string currentComponent; + + for (size_t i = 1; i < components.size(); ++i) { + if (i != 1) + identifier += '.'; + + currentComponent = + NormalizeComponentForId(components[i], replacementCount); + + identifier += currentComponent; + } + + std::string idPrefix = "P"; + size_t replacementPercent = replacementCount * 100 / identifier.size(); + if (replacementPercent > 33 || identifier.size() > 60) { + identifier = CreateHashedId(path, currentComponent); + idPrefix = "H"; + } + + std::ostringstream result; + result << idPrefix << "_" << identifier; + + size_t ambiguityCount = ++IdAmbiguityCounter[identifier]; + + if (ambiguityCount > 999) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Error while trying to generate a unique Id for '" + << path << "'" << std::endl); + + return std::string(); + } else if (ambiguityCount > 1) { + result << "_" << ambiguityCount; + } + + std::string resultString = result.str(); + + PathToIdMap[path] = resultString; + + return resultString; +} + +std::string cmCPackWIXGenerator::CreateHashedId( + std::string const& path, std::string const& normalizedFilename) +{ + cmCryptoHash sha1(cmCryptoHash::AlgoSHA1); + std::string const hash = sha1.HashString(path); + + std::string identifier; + identifier += hash.substr(0, 7) + "_"; + + const size_t maxFileNameLength = 52; + if (normalizedFilename.length() > maxFileNameLength) { + identifier += normalizedFilename.substr(0, maxFileNameLength - 3); + identifier += "..."; + } else { + identifier += normalizedFilename; + } + + return identifier; +} + +std::string cmCPackWIXGenerator::NormalizeComponentForId( + std::string const& component, size_t& replacementCount) +{ + std::string result; + result.resize(component.size()); + + for (size_t i = 0; i < component.size(); ++i) { + char c = component[i]; + if (IsLegalIdCharacter(c)) { + result[i] = c; + } else { + result[i] = '_'; + ++replacementCount; + } + } + + return result; +} + +bool cmCPackWIXGenerator::IsLegalIdCharacter(char c) +{ + return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || + (c >= 'A' && c <= 'Z') || c == '_' || c == '.'; +} + +void cmCPackWIXGenerator::CollectExtensions(std::string const& variableName, + extension_set_t& extensions) +{ + const char* variableContent = GetOption(variableName.c_str()); + if (!variableContent) + return; + + std::vector<std::string> list; + cmSystemTools::ExpandListArgument(variableContent, list); + extensions.insert(list.begin(), list.end()); +} + +void cmCPackWIXGenerator::AddCustomFlags(std::string const& variableName, + std::ostream& stream) +{ + const char* variableContent = GetOption(variableName.c_str()); + if (!variableContent) + return; + + std::vector<std::string> list; + cmSystemTools::ExpandListArgument(variableContent, list); + + for (std::vector<std::string>::const_iterator i = list.begin(); + i != list.end(); ++i) { + stream << " " << QuotePath(*i); + } +} + +std::string cmCPackWIXGenerator::RelativePathWithoutComponentPrefix( + std::string const& path) +{ + if (this->Components.empty()) { + return path; + } + + std::string::size_type pos = path.find('/'); + + return path.substr(pos + 1); +} diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.h b/Source/CPack/WiX/cmCPackWIXGenerator.h index aaccf9d46..b2633a7f9 100644 --- a/Source/CPack/WiX/cmCPackWIXGenerator.h +++ b/Source/CPack/WiX/cmCPackWIXGenerator.h @@ -1,24 +1,20 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2012 Kitware, Inc. - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #ifndef cmCPackWIXGenerator_h #define cmCPackWIXGenerator_h -#include <CPack/cmCPackGenerator.h> +#include "cmCPackGenerator.h" + +#include "cmWIXPatch.h" +#include "cmWIXShortcut.h" -#include <string> #include <map> +#include <string> class cmWIXSourceWriter; +class cmWIXDirectoriesSourceWriter; +class cmWIXFilesSourceWriter; +class cmWIXFeaturesSourceWriter; /** \class cmCPackWIXGenerator * \brief A generator for WIX files @@ -28,78 +24,136 @@ class cmCPackWIXGenerator : public cmCPackGenerator public: cmCPackTypeMacro(cmCPackWIXGenerator, cmCPackGenerator); + cmCPackWIXGenerator(); + ~cmCPackWIXGenerator(); + protected: virtual int InitializeInternal(); virtual int PackageFiles(); - virtual const char* GetOutputExtension() - { - return ".msi"; - } + virtual const char* GetOutputExtension() { return ".msi"; } virtual enum CPackSetDestdirSupport SupportsSetDestdir() const - { + { return SETDESTDIR_UNSUPPORTED; - } + } - virtual bool SupportsAbsoluteDestination() const - { - return false; - } + virtual bool SupportsAbsoluteDestination() const { return false; } - virtual bool SupportsComponentInstallation() const - { - return false; - } + virtual bool SupportsComponentInstallation() const { return true; } private: + typedef std::map<std::string, std::string> id_map_t; + typedef std::map<std::string, size_t> ambiguity_map_t; + typedef std::set<std::string> extension_set_t; + bool InitializeWiXConfiguration(); bool PackageFilesImpl(); - bool CreateWiXVariablesIncludeFile(); + void CreateWiXVariablesIncludeFile(); - void CopyDefinition( - cmWIXSourceWriter &source, const std::string &name); + void CreateWiXPropertiesIncludeFile(); - void AddDefinition(cmWIXSourceWriter& source, - const std::string& name, const std::string& value); + void CreateWiXProductFragmentIncludeFile(); + + void CopyDefinition(cmWIXSourceWriter& source, std::string const& name); + + void AddDefinition(cmWIXSourceWriter& source, std::string const& name, + std::string const& value); bool CreateWiXSourceFiles(); - bool CreateLicenseFile(); + std::string GetRootFolderId() const; + + bool GenerateMainSourceFileFromTemplate(); - bool RunWiXCommand(const std::string& command); + bool CreateFeatureHierarchy(cmWIXFeaturesSourceWriter& featureDefinitions); - bool RunCandleCommand( - const std::string& sourceFile, const std::string& objectFile); + bool AddComponentsToFeature( + std::string const& rootPath, std::string const& featureId, + cmWIXDirectoriesSourceWriter& directoryDefinitions, + cmWIXFilesSourceWriter& fileDefinitions, + cmWIXFeaturesSourceWriter& featureDefinitions, cmWIXShortcuts& shortcuts); - bool RunLightCommand(const std::string& objectFiles); + bool CreateShortcuts(std::string const& cpackComponentName, + std::string const& featureId, + cmWIXShortcuts const& shortcuts, + bool emitUninstallShortcut, + cmWIXFilesSourceWriter& fileDefinitions, + cmWIXFeaturesSourceWriter& featureDefinitions); - void AddDirectoryAndFileDefinitons(const std::string& topdir, - const std::string& directoryId, - cmWIXSourceWriter& directoryDefinitions, - cmWIXSourceWriter& fileDefinitions, - cmWIXSourceWriter& featureDefinitions, - size_t& directoryCounter, - size_t& fileCounter, - const std::vector<std::string>& pkgExecutables, - std::vector<std::string>& dirIdExecutables - ); + bool CreateShortcutsOfSpecificType( + cmWIXShortcuts::Type type, std::string const& cpackComponentName, + std::string const& featureId, std::string const& idPrefix, + cmWIXShortcuts const& shortcuts, bool emitUninstallShortcut, + cmWIXFilesSourceWriter& fileDefinitions, + cmWIXFeaturesSourceWriter& featureDefinitions); + + void AppendUserSuppliedExtraSources(); + + void AppendUserSuppliedExtraObjects(std::ostream& stream); + + bool CreateLicenseFile(); + bool RunWiXCommand(std::string const& command); - bool RequireOption(const std::string& name, std::string& value) const; + bool RunCandleCommand(std::string const& sourceFile, + std::string const& objectFile); + + bool RunLightCommand(std::string const& objectFiles); + + void AddDirectoryAndFileDefinitions( + std::string const& topdir, std::string const& directoryId, + cmWIXDirectoriesSourceWriter& directoryDefinitions, + cmWIXFilesSourceWriter& fileDefinitions, + cmWIXFeaturesSourceWriter& featureDefinitions, + std::vector<std::string> const& packageExecutables, + std::vector<std::string> const& desktopExecutables, + cmWIXShortcuts& shortcuts); + + bool RequireOption(std::string const& name, std::string& value) const; std::string GetArchitecture() const; static std::string GenerateGUID(); - static std::string QuotePath(const std::string& path); + static std::string QuotePath(std::string const& path); + + static std::string GetRightmostExtension(std::string const& filename); + + std::string PathToId(std::string const& path); + + std::string CreateNewIdForPath(std::string const& path); + + static std::string CreateHashedId(std::string const& path, + std::string const& normalizedFilename); + + std::string NormalizeComponentForId(std::string const& component, + size_t& replacementCount); + + static bool IsLegalIdCharacter(char c); + + void CollectExtensions(std::string const& variableName, + extension_set_t& extensions); + + void AddCustomFlags(std::string const& variableName, std::ostream& stream); + + std::string RelativePathWithoutComponentPrefix(std::string const& path); + + std::vector<std::string> WixSources; + id_map_t PathToIdMap; + ambiguity_map_t IdAmbiguityCounter; + + extension_set_t CandleExtensions; + extension_set_t LightExtensions; + + std::string CPackTopLevel; - static std::string GetRightmostExtension(const std::string& filename); + cmWIXPatch* Patch; - std::vector<std::string> wixSources; + cmWIXSourceWriter::GuidType ComponentGuidType; }; #endif diff --git a/Source/CPack/WiX/cmWIXAccessControlList.cxx b/Source/CPack/WiX/cmWIXAccessControlList.cxx new file mode 100644 index 000000000..744a93298 --- /dev/null +++ b/Source/CPack/WiX/cmWIXAccessControlList.cxx @@ -0,0 +1,126 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmWIXAccessControlList.h" + +#include "cmCPackGenerator.h" + +#include "cmSystemTools.h" + +cmWIXAccessControlList::cmWIXAccessControlList( + cmCPackLog* logger, cmInstalledFile const& installedFile, + cmWIXSourceWriter& sourceWriter) + : Logger(logger) + , InstalledFile(installedFile) + , SourceWriter(sourceWriter) +{ +} + +bool cmWIXAccessControlList::Apply() +{ + std::vector<std::string> entries; + this->InstalledFile.GetPropertyAsList("CPACK_WIX_ACL", entries); + + for (size_t i = 0; i < entries.size(); ++i) { + this->CreatePermissionElement(entries[i]); + } + + return true; +} + +void cmWIXAccessControlList::CreatePermissionElement(std::string const& entry) +{ + std::string::size_type pos = entry.find('='); + if (pos == std::string::npos) { + this->ReportError(entry, "Did not find mandatory '='"); + return; + } + + std::string user_and_domain = entry.substr(0, pos); + std::string permission_string = entry.substr(pos + 1); + + pos = user_and_domain.find('@'); + std::string user; + std::string domain; + if (pos != std::string::npos) { + user = user_and_domain.substr(0, pos); + domain = user_and_domain.substr(pos + 1); + } else { + user = user_and_domain; + } + + std::vector<std::string> permissions = + cmSystemTools::tokenize(permission_string, ","); + + this->SourceWriter.BeginElement("Permission"); + this->SourceWriter.AddAttribute("User", user); + if (!domain.empty()) { + this->SourceWriter.AddAttribute("Domain", domain); + } + for (size_t i = 0; i < permissions.size(); ++i) { + this->EmitBooleanAttribute(entry, + cmSystemTools::TrimWhitespace(permissions[i])); + } + this->SourceWriter.EndElement("Permission"); +} + +void cmWIXAccessControlList::ReportError(std::string const& entry, + std::string const& message) +{ + cmCPackLogger(cmCPackLog::LOG_ERROR, "Failed processing ACL entry '" + << entry << "': " << message << std::endl); +} + +bool cmWIXAccessControlList::IsBooleanAttribute(std::string const& name) +{ + static const char* validAttributes[] = { + /* clang-format needs this comment to break after the opening brace */ + "Append", + "ChangePermission", + "CreateChild", + "CreateFile", + "CreateLink", + "CreateSubkeys", + "Delete", + "DeleteChild", + "EnumerateSubkeys", + "Execute", + "FileAllRights", + "GenericAll", + "GenericExecute", + "GenericRead", + "GenericWrite", + "Notify", + "Read", + "ReadAttributes", + "ReadExtendedAttributes", + "ReadPermission", + "SpecificRightsAll", + "Synchronize", + "TakeOwnership", + "Traverse", + "Write", + "WriteAttributes", + "WriteExtendedAttributes", + 0 + }; + + size_t i = 0; + while (validAttributes[i]) { + if (name == validAttributes[i++]) + return true; + } + + return false; +} + +void cmWIXAccessControlList::EmitBooleanAttribute(std::string const& entry, + std::string const& name) +{ + if (!this->IsBooleanAttribute(name)) { + std::ostringstream message; + message << "Unknown boolean attribute '" << name << "'"; + this->ReportError(entry, message.str()); + } + + this->SourceWriter.AddAttribute(name, "yes"); +} diff --git a/Source/CPack/WiX/cmWIXAccessControlList.h b/Source/CPack/WiX/cmWIXAccessControlList.h new file mode 100644 index 000000000..2a23f2f37 --- /dev/null +++ b/Source/CPack/WiX/cmWIXAccessControlList.h @@ -0,0 +1,34 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmWIXAccessControlList_h +#define cmWIXAccessControlList_h + +#include "cmWIXSourceWriter.h" + +#include "cmCPackLog.h" +#include "cmInstalledFile.h" + +class cmWIXAccessControlList +{ +public: + cmWIXAccessControlList(cmCPackLog* logger, + cmInstalledFile const& installedFile, + cmWIXSourceWriter& sourceWriter); + + bool Apply(); + +private: + void CreatePermissionElement(std::string const& entry); + + void ReportError(std::string const& entry, std::string const& message); + + bool IsBooleanAttribute(std::string const& name); + + void EmitBooleanAttribute(std::string const& entry, std::string const& name); + + cmCPackLog* Logger; + cmInstalledFile const& InstalledFile; + cmWIXSourceWriter& SourceWriter; +}; + +#endif diff --git a/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx new file mode 100644 index 000000000..975dffb4f --- /dev/null +++ b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx @@ -0,0 +1,82 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmWIXDirectoriesSourceWriter.h" + +cmWIXDirectoriesSourceWriter::cmWIXDirectoriesSourceWriter( + cmCPackLog* logger, std::string const& filename, GuidType componentGuidType) + : cmWIXSourceWriter(logger, filename, componentGuidType) +{ +} + +void cmWIXDirectoriesSourceWriter::EmitStartMenuFolder( + std::string const& startMenuFolder) +{ + BeginElement("Directory"); + AddAttribute("Id", "ProgramMenuFolder"); + + BeginElement("Directory"); + AddAttribute("Id", "PROGRAM_MENU_FOLDER"); + AddAttribute("Name", startMenuFolder); + EndElement("Directory"); + + EndElement("Directory"); +} + +void cmWIXDirectoriesSourceWriter::EmitDesktopFolder() +{ + BeginElement("Directory"); + AddAttribute("Id", "DesktopFolder"); + AddAttribute("Name", "Desktop"); + EndElement("Directory"); +} + +void cmWIXDirectoriesSourceWriter::EmitStartupFolder() +{ + BeginElement("Directory"); + AddAttribute("Id", "StartupFolder"); + AddAttribute("Name", "Startup"); + EndElement("Directory"); +} + +size_t cmWIXDirectoriesSourceWriter::BeginInstallationPrefixDirectory( + std::string const& programFilesFolderId, + std::string const& installRootString) +{ + size_t offset = 1; + if (!programFilesFolderId.empty()) { + BeginElement("Directory"); + AddAttribute("Id", programFilesFolderId); + offset = 0; + } + + std::vector<std::string> installRoot; + + cmSystemTools::SplitPath(installRootString.c_str(), installRoot); + + if (!installRoot.empty() && installRoot.back().empty()) { + installRoot.pop_back(); + } + + for (size_t i = 1; i < installRoot.size(); ++i) { + BeginElement("Directory"); + + if (i == installRoot.size() - 1) { + AddAttribute("Id", "INSTALL_ROOT"); + } else { + std::ostringstream tmp; + tmp << "INSTALL_PREFIX_" << i; + AddAttribute("Id", tmp.str()); + } + + AddAttribute("Name", installRoot[i]); + } + + return installRoot.size() - offset; +} + +void cmWIXDirectoriesSourceWriter::EndInstallationPrefixDirectory(size_t size) +{ + for (size_t i = 0; i < size; ++i) { + EndElement("Directory"); + } +} diff --git a/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.h b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.h new file mode 100644 index 000000000..8233331a3 --- /dev/null +++ b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.h @@ -0,0 +1,34 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmWIXDirectoriesSourceWriter_h +#define cmWIXDirectoriesSourceWriter_h + +#include "cmWIXSourceWriter.h" + +#include "cmCPackGenerator.h" + +#include <string> + +/** \class cmWIXDirectoriesSourceWriter + * \brief Helper class to generate directories.wxs + */ +class cmWIXDirectoriesSourceWriter : public cmWIXSourceWriter +{ +public: + cmWIXDirectoriesSourceWriter(cmCPackLog* logger, std::string const& filename, + GuidType componentGuidType); + + void EmitStartMenuFolder(std::string const& startMenuFolder); + + void EmitDesktopFolder(); + + void EmitStartupFolder(); + + size_t BeginInstallationPrefixDirectory( + std::string const& programFilesFolderId, + std::string const& installRootString); + + void EndInstallationPrefixDirectory(size_t size); +}; + +#endif diff --git a/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx b/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx new file mode 100644 index 000000000..0be43776e --- /dev/null +++ b/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx @@ -0,0 +1,95 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmWIXFeaturesSourceWriter.h" + +cmWIXFeaturesSourceWriter::cmWIXFeaturesSourceWriter( + cmCPackLog* logger, std::string const& filename, GuidType componentGuidType) + : cmWIXSourceWriter(logger, filename, componentGuidType) +{ +} + +void cmWIXFeaturesSourceWriter::CreateCMakePackageRegistryEntry( + std::string const& package, std::string const& upgradeGuid) +{ + BeginElement("Component"); + AddAttribute("Id", "CM_PACKAGE_REGISTRY"); + AddAttribute("Directory", "TARGETDIR"); + AddAttribute("Guid", CreateGuidFromComponentId("CM_PACKAGE_REGISTRY")); + + std::string registryKey = + std::string("Software\\Kitware\\CMake\\Packages\\") + package; + + BeginElement("RegistryValue"); + AddAttribute("Root", "HKLM"); + AddAttribute("Key", registryKey); + AddAttribute("Name", upgradeGuid); + AddAttribute("Type", "string"); + AddAttribute("Value", "[INSTALL_ROOT]"); + AddAttribute("KeyPath", "yes"); + EndElement("RegistryValue"); + + EndElement("Component"); +} + +void cmWIXFeaturesSourceWriter::EmitFeatureForComponentGroup( + cmCPackComponentGroup const& group, cmWIXPatch& patch) +{ + BeginElement("Feature"); + AddAttribute("Id", "CM_G_" + group.Name); + + if (group.IsExpandedByDefault) { + AddAttribute("Display", "expand"); + } + + AddAttributeUnlessEmpty("Title", group.DisplayName); + AddAttributeUnlessEmpty("Description", group.Description); + + patch.ApplyFragment("CM_G_" + group.Name, *this); + + for (std::vector<cmCPackComponentGroup*>::const_iterator i = + group.Subgroups.begin(); + i != group.Subgroups.end(); ++i) { + EmitFeatureForComponentGroup(**i, patch); + } + + for (std::vector<cmCPackComponent*>::const_iterator i = + group.Components.begin(); + i != group.Components.end(); ++i) { + EmitFeatureForComponent(**i, patch); + } + + EndElement("Feature"); +} + +void cmWIXFeaturesSourceWriter::EmitFeatureForComponent( + cmCPackComponent const& component, cmWIXPatch& patch) +{ + BeginElement("Feature"); + AddAttribute("Id", "CM_C_" + component.Name); + + AddAttributeUnlessEmpty("Title", component.DisplayName); + AddAttributeUnlessEmpty("Description", component.Description); + + if (component.IsRequired) { + AddAttribute("Absent", "disallow"); + } + + if (component.IsHidden) { + AddAttribute("Display", "hidden"); + } + + if (component.IsDisabledByDefault) { + AddAttribute("Level", "2"); + } + + patch.ApplyFragment("CM_C_" + component.Name, *this); + + EndElement("Feature"); +} + +void cmWIXFeaturesSourceWriter::EmitComponentRef(std::string const& id) +{ + BeginElement("ComponentRef"); + AddAttribute("Id", id); + EndElement("ComponentRef"); +} diff --git a/Source/CPack/WiX/cmWIXFeaturesSourceWriter.h b/Source/CPack/WiX/cmWIXFeaturesSourceWriter.h new file mode 100644 index 000000000..e751ca719 --- /dev/null +++ b/Source/CPack/WiX/cmWIXFeaturesSourceWriter.h @@ -0,0 +1,32 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmWIXFeaturesSourceWriter_h +#define cmWIXFeaturesSourceWriter_h + +#include "cmWIXPatch.h" +#include "cmWIXSourceWriter.h" + +#include "cmCPackGenerator.h" + +/** \class cmWIXFeaturesSourceWriter + * \brief Helper class to generate features.wxs + */ +class cmWIXFeaturesSourceWriter : public cmWIXSourceWriter +{ +public: + cmWIXFeaturesSourceWriter(cmCPackLog* logger, std::string const& filename, + GuidType componentGuidType); + + void CreateCMakePackageRegistryEntry(std::string const& package, + std::string const& upgradeGuid); + + void EmitFeatureForComponentGroup(const cmCPackComponentGroup& group, + cmWIXPatch& patch); + + void EmitFeatureForComponent(const cmCPackComponent& component, + cmWIXPatch& patch); + + void EmitComponentRef(std::string const& id); +}; + +#endif diff --git a/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx b/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx new file mode 100644 index 000000000..b4cd1a3d6 --- /dev/null +++ b/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx @@ -0,0 +1,164 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmWIXFilesSourceWriter.h" + +#include "cmWIXAccessControlList.h" + +#include "cmInstalledFile.h" + +#include "cmSystemTools.h" +#include "cmUuid.h" + +#include "cm_sys_stat.h" + +cmWIXFilesSourceWriter::cmWIXFilesSourceWriter(cmCPackLog* logger, + std::string const& filename, + GuidType componentGuidType) + : cmWIXSourceWriter(logger, filename, componentGuidType) +{ +} + +void cmWIXFilesSourceWriter::EmitShortcut(std::string const& id, + cmWIXShortcut const& shortcut, + std::string const& shortcutPrefix, + size_t shortcutIndex) +{ + std::ostringstream shortcutId; + shortcutId << shortcutPrefix << id; + + if (shortcutIndex > 0) { + shortcutId << "_" << shortcutIndex; + } + + std::string fileId = std::string("CM_F") + id; + + BeginElement("Shortcut"); + AddAttribute("Id", shortcutId.str()); + AddAttribute("Name", shortcut.label); + std::string target = "[#" + fileId + "]"; + AddAttribute("Target", target); + AddAttribute("WorkingDirectory", shortcut.workingDirectoryId); + EndElement("Shortcut"); +} + +void cmWIXFilesSourceWriter::EmitRemoveFolder(std::string const& id) +{ + BeginElement("RemoveFolder"); + AddAttribute("Id", id); + AddAttribute("On", "uninstall"); + EndElement("RemoveFolder"); +} + +void cmWIXFilesSourceWriter::EmitInstallRegistryValue( + std::string const& registryKey, std::string const& cpackComponentName, + std::string const& suffix) +{ + std::string valueName; + if (!cpackComponentName.empty()) { + valueName = cpackComponentName + "_"; + } + + valueName += "installed"; + valueName += suffix; + + BeginElement("RegistryValue"); + AddAttribute("Root", "HKCU"); + AddAttribute("Key", registryKey); + AddAttribute("Name", valueName); + AddAttribute("Type", "integer"); + AddAttribute("Value", "1"); + AddAttribute("KeyPath", "yes"); + EndElement("RegistryValue"); +} + +void cmWIXFilesSourceWriter::EmitUninstallShortcut( + std::string const& packageName) +{ + BeginElement("Shortcut"); + AddAttribute("Id", "UNINSTALL"); + AddAttribute("Name", "Uninstall " + packageName); + AddAttribute("Description", "Uninstalls " + packageName); + AddAttribute("Target", "[SystemFolder]msiexec.exe"); + AddAttribute("Arguments", "/x [ProductCode]"); + EndElement("Shortcut"); +} + +std::string cmWIXFilesSourceWriter::EmitComponentCreateFolder( + std::string const& directoryId, std::string const& guid, + cmInstalledFile const* installedFile) +{ + std::string componentId = std::string("CM_C_EMPTY_") + directoryId; + + BeginElement("DirectoryRef"); + AddAttribute("Id", directoryId); + + BeginElement("Component"); + AddAttribute("Id", componentId); + AddAttribute("Guid", guid); + + BeginElement("CreateFolder"); + + if (installedFile) { + cmWIXAccessControlList acl(Logger, *installedFile, *this); + acl.Apply(); + } + + EndElement("CreateFolder"); + EndElement("Component"); + EndElement("DirectoryRef"); + + return componentId; +} + +std::string cmWIXFilesSourceWriter::EmitComponentFile( + std::string const& directoryId, std::string const& id, + std::string const& filePath, cmWIXPatch& patch, + cmInstalledFile const* installedFile) +{ + std::string componentId = std::string("CM_C") + id; + std::string fileId = std::string("CM_F") + id; + + std::string guid = CreateGuidFromComponentId(componentId); + + BeginElement("DirectoryRef"); + AddAttribute("Id", directoryId); + + BeginElement("Component"); + AddAttribute("Id", componentId); + AddAttribute("Guid", guid); + + if (installedFile) { + if (installedFile->GetPropertyAsBool("CPACK_NEVER_OVERWRITE")) { + AddAttribute("NeverOverwrite", "yes"); + } + if (installedFile->GetPropertyAsBool("CPACK_PERMANENT")) { + AddAttribute("Permanent", "yes"); + } + } + + patch.ApplyFragment(componentId, *this); + BeginElement("File"); + AddAttribute("Id", fileId); + AddAttribute("Source", filePath); + AddAttribute("KeyPath", "yes"); + + mode_t fileMode = 0; + cmSystemTools::GetPermissions(filePath.c_str(), fileMode); + + if (!(fileMode & S_IWRITE)) { + AddAttribute("ReadOnly", "yes"); + } + patch.ApplyFragment(fileId, *this); + + if (installedFile) { + cmWIXAccessControlList acl(Logger, *installedFile, *this); + acl.Apply(); + } + + EndElement("File"); + + EndElement("Component"); + EndElement("DirectoryRef"); + + return componentId; +} diff --git a/Source/CPack/WiX/cmWIXFilesSourceWriter.h b/Source/CPack/WiX/cmWIXFilesSourceWriter.h new file mode 100644 index 000000000..dc9c636d3 --- /dev/null +++ b/Source/CPack/WiX/cmWIXFilesSourceWriter.h @@ -0,0 +1,43 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmWIXFilesSourceWriter_h +#define cmWIXFilesSourceWriter_h + +#include "cmWIXSourceWriter.h" + +#include "cmWIXPatch.h" +#include "cmWIXShortcut.h" + +#include "cmCPackGenerator.h" + +/** \class cmWIXFilesSourceWriter + * \brief Helper class to generate files.wxs + */ +class cmWIXFilesSourceWriter : public cmWIXSourceWriter +{ +public: + cmWIXFilesSourceWriter(cmCPackLog* logger, std::string const& filename, + GuidType componentGuidType); + + void EmitShortcut(std::string const& id, cmWIXShortcut const& shortcut, + std::string const& shortcutPrefix, size_t shortcutIndex); + + void EmitRemoveFolder(std::string const& id); + + void EmitInstallRegistryValue(std::string const& registryKey, + std::string const& cpackComponentName, + std::string const& suffix); + + void EmitUninstallShortcut(std::string const& packageName); + + std::string EmitComponentCreateFolder(std::string const& directoryId, + std::string const& guid, + cmInstalledFile const* installedFile); + + std::string EmitComponentFile(std::string const& directoryId, + std::string const& id, + std::string const& filePath, cmWIXPatch& patch, + cmInstalledFile const* installedFile); +}; + +#endif diff --git a/Source/CPack/WiX/cmWIXPatch.cxx b/Source/CPack/WiX/cmWIXPatch.cxx new file mode 100644 index 000000000..287a644bb --- /dev/null +++ b/Source/CPack/WiX/cmWIXPatch.cxx @@ -0,0 +1,99 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmWIXPatch.h" + +#include "cmCPackGenerator.h" + +cmWIXPatch::cmWIXPatch(cmCPackLog* logger) + : Logger(logger) +{ +} + +bool cmWIXPatch::LoadFragments(std::string const& patchFilePath) +{ + cmWIXPatchParser parser(Fragments, Logger); + if (!parser.ParseFile(patchFilePath.c_str())) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Failed parsing XML patch file: '" + << patchFilePath << "'" << std::endl); + return false; + } + + return true; +} + +void cmWIXPatch::ApplyFragment(std::string const& id, + cmWIXSourceWriter& writer) +{ + cmWIXPatchParser::fragment_map_t::iterator i = Fragments.find(id); + if (i == Fragments.end()) + return; + + const cmWIXPatchElement& fragment = i->second; + for (cmWIXPatchElement::attributes_t::const_iterator attr_i = + fragment.attributes.begin(); + attr_i != fragment.attributes.end(); ++attr_i) { + writer.AddAttribute(attr_i->first, attr_i->second); + } + this->ApplyElementChildren(fragment, writer); + + Fragments.erase(i); +} + +void cmWIXPatch::ApplyElementChildren(const cmWIXPatchElement& element, + cmWIXSourceWriter& writer) +{ + for (cmWIXPatchElement::child_list_t::const_iterator j = + element.children.begin(); + j != element.children.end(); ++j) { + cmWIXPatchNode* node = *j; + + switch (node->type()) { + case cmWIXPatchNode::ELEMENT: + ApplyElement(dynamic_cast<const cmWIXPatchElement&>(*node), writer); + break; + case cmWIXPatchNode::TEXT: + writer.AddTextNode(dynamic_cast<const cmWIXPatchText&>(*node).text); + break; + } + } +} + +void cmWIXPatch::ApplyElement(const cmWIXPatchElement& element, + cmWIXSourceWriter& writer) +{ + writer.BeginElement(element.name); + + for (cmWIXPatchElement::attributes_t::const_iterator i = + element.attributes.begin(); + i != element.attributes.end(); ++i) { + writer.AddAttribute(i->first, i->second); + } + + this->ApplyElementChildren(element, writer); + + writer.EndElement(element.name); +} + +bool cmWIXPatch::CheckForUnappliedFragments() +{ + std::string fragmentList; + for (cmWIXPatchParser::fragment_map_t::const_iterator i = Fragments.begin(); + i != Fragments.end(); ++i) { + if (!fragmentList.empty()) { + fragmentList += ", "; + } + + fragmentList += "'"; + fragmentList += i->first; + fragmentList += "'"; + } + + if (!fragmentList.empty()) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Some XML patch fragments did not have matching IDs: " + << fragmentList << std::endl); + return false; + } + + return true; +} diff --git a/Source/CPack/WiX/cmWIXPatch.h b/Source/CPack/WiX/cmWIXPatch.h new file mode 100644 index 000000000..a4c9e714d --- /dev/null +++ b/Source/CPack/WiX/cmWIXPatch.h @@ -0,0 +1,37 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmWIXPatch_h +#define cmWIXPatch_h + +#include "cmWIXPatchParser.h" +#include "cmWIXSourceWriter.h" + +#include <string> + +/** \class cmWIXPatch + * \brief Class that maintains and applies patch fragments + */ +class cmWIXPatch +{ +public: + cmWIXPatch(cmCPackLog* logger); + + bool LoadFragments(std::string const& patchFilePath); + + void ApplyFragment(std::string const& id, cmWIXSourceWriter& writer); + + bool CheckForUnappliedFragments(); + +private: + void ApplyElementChildren(const cmWIXPatchElement& element, + cmWIXSourceWriter& writer); + + void ApplyElement(const cmWIXPatchElement& element, + cmWIXSourceWriter& writer); + + cmCPackLog* Logger; + + cmWIXPatchParser::fragment_map_t Fragments; +}; + +#endif diff --git a/Source/CPack/WiX/cmWIXPatchParser.cxx b/Source/CPack/WiX/cmWIXPatchParser.cxx new file mode 100644 index 000000000..0dcc74ae0 --- /dev/null +++ b/Source/CPack/WiX/cmWIXPatchParser.cxx @@ -0,0 +1,160 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmWIXPatchParser.h" + +#include "cmCPackGenerator.h" + +#include "cm_expat.h" + +cmWIXPatchNode::Type cmWIXPatchText::type() +{ + return cmWIXPatchNode::TEXT; +} + +cmWIXPatchNode::Type cmWIXPatchElement::type() +{ + return cmWIXPatchNode::ELEMENT; +} + +cmWIXPatchNode::~cmWIXPatchNode() +{ +} + +cmWIXPatchElement::~cmWIXPatchElement() +{ + for (child_list_t::iterator i = children.begin(); i != children.end(); ++i) { + delete *i; + } +} + +cmWIXPatchParser::cmWIXPatchParser(fragment_map_t& fragments, + cmCPackLog* logger) + : Logger(logger) + , State(BEGIN_DOCUMENT) + , Valid(true) + , Fragments(fragments) +{ +} + +void cmWIXPatchParser::StartElement(const std::string& name, const char** atts) +{ + if (State == BEGIN_DOCUMENT) { + if (name == "CPackWiXPatch") { + State = BEGIN_FRAGMENTS; + } else { + ReportValidationError("Expected root element 'CPackWiXPatch'"); + } + } else if (State == BEGIN_FRAGMENTS) { + if (name == "CPackWiXFragment") { + State = INSIDE_FRAGMENT; + StartFragment(atts); + } else { + ReportValidationError("Expected 'CPackWixFragment' element"); + } + } else if (State == INSIDE_FRAGMENT) { + cmWIXPatchElement& parent = *ElementStack.back(); + + cmWIXPatchElement* element = new cmWIXPatchElement; + parent.children.push_back(element); + + element->name = name; + + for (size_t i = 0; atts[i]; i += 2) { + std::string key = atts[i]; + std::string value = atts[i + 1]; + + element->attributes[key] = value; + } + + ElementStack.push_back(element); + } +} + +void cmWIXPatchParser::StartFragment(const char** attributes) +{ + cmWIXPatchElement* new_element = CM_NULLPTR; + /* find the id of for fragment */ + for (size_t i = 0; attributes[i]; i += 2) { + const std::string key = attributes[i]; + const std::string value = attributes[i + 1]; + + if (key == "Id") { + if (Fragments.find(value) != Fragments.end()) { + std::ostringstream tmp; + tmp << "Invalid reuse of 'CPackWixFragment' 'Id': " << value; + ReportValidationError(tmp.str()); + } + + new_element = &Fragments[value]; + ElementStack.push_back(new_element); + } + } + + /* add any additional attributes for the fragement */ + if (!new_element) { + ReportValidationError("No 'Id' specified for 'CPackWixFragment' element"); + } else { + for (size_t i = 0; attributes[i]; i += 2) { + const std::string key = attributes[i]; + const std::string value = attributes[i + 1]; + + if (key != "Id") { + new_element->attributes[key] = value; + } + } + } +} + +void cmWIXPatchParser::EndElement(const std::string& name) +{ + if (State == INSIDE_FRAGMENT) { + if (name == "CPackWiXFragment") { + State = BEGIN_FRAGMENTS; + ElementStack.clear(); + } else { + ElementStack.pop_back(); + } + } +} + +void cmWIXPatchParser::CharacterDataHandler(const char* data, int length) +{ + const char* whitespace = "\x20\x09\x0d\x0a"; + + if (State == INSIDE_FRAGMENT) { + cmWIXPatchElement& parent = *ElementStack.back(); + + std::string text(data, length); + + std::string::size_type first = text.find_first_not_of(whitespace); + std::string::size_type last = text.find_last_not_of(whitespace); + + if (first != std::string::npos && last != std::string::npos) { + cmWIXPatchText* text_node = new cmWIXPatchText; + text_node->text = text.substr(first, last - first + 1); + + parent.children.push_back(text_node); + } + } +} + +void cmWIXPatchParser::ReportError(int line, int column, const char* msg) +{ + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Error while processing XML patch file at " + << line << ":" << column << ": " << msg << std::endl); + Valid = false; +} + +void cmWIXPatchParser::ReportValidationError(std::string const& message) +{ + ReportError( + XML_GetCurrentLineNumber(static_cast<XML_Parser>(this->Parser)), + XML_GetCurrentColumnNumber(static_cast<XML_Parser>(this->Parser)), + message.c_str()); +} + +bool cmWIXPatchParser::IsValid() const +{ + return Valid; +} diff --git a/Source/CPack/WiX/cmWIXPatchParser.h b/Source/CPack/WiX/cmWIXPatchParser.h new file mode 100644 index 000000000..52c7e3524 --- /dev/null +++ b/Source/CPack/WiX/cmWIXPatchParser.h @@ -0,0 +1,90 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmCPackWIXPatchParser_h +#define cmCPackWIXPatchParser_h + +#include "cmCPackLog.h" + +#include "cmXMLParser.h" + +#include <map> +#include <vector> + +struct cmWIXPatchNode +{ + enum Type + { + TEXT, + ELEMENT + }; + + virtual ~cmWIXPatchNode(); + + virtual Type type() = 0; +}; + +struct cmWIXPatchText : public cmWIXPatchNode +{ + virtual Type type(); + + std::string text; +}; + +struct cmWIXPatchElement : cmWIXPatchNode +{ + virtual Type type(); + + ~cmWIXPatchElement(); + + typedef std::vector<cmWIXPatchNode*> child_list_t; + typedef std::map<std::string, std::string> attributes_t; + + std::string name; + child_list_t children; + attributes_t attributes; +}; + +/** \class cmWIXPatchParser + * \brief Helper class that parses XML patch files (CPACK_WIX_PATCH_FILE) + */ +class cmWIXPatchParser : public cmXMLParser +{ +public: + typedef std::map<std::string, cmWIXPatchElement> fragment_map_t; + + cmWIXPatchParser(fragment_map_t& Fragments, cmCPackLog* logger); + +private: + virtual void StartElement(const std::string& name, const char** atts); + + void StartFragment(const char** attributes); + + virtual void EndElement(const std::string& name); + + virtual void CharacterDataHandler(const char* data, int length); + + virtual void ReportError(int line, int column, const char* msg); + + void ReportValidationError(std::string const& message); + + bool IsValid() const; + + cmCPackLog* Logger; + + enum ParserState + { + BEGIN_DOCUMENT, + BEGIN_FRAGMENTS, + INSIDE_FRAGMENT + }; + + ParserState State; + + bool Valid; + + fragment_map_t& Fragments; + + std::vector<cmWIXPatchElement*> ElementStack; +}; + +#endif diff --git a/Source/CPack/WiX/cmWIXRichTextFormatWriter.cxx b/Source/CPack/WiX/cmWIXRichTextFormatWriter.cxx index 774c22c76..2c99a2284 100644 --- a/Source/CPack/WiX/cmWIXRichTextFormatWriter.cxx +++ b/Source/CPack/WiX/cmWIXRichTextFormatWriter.cxx @@ -1,22 +1,12 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2012 Kitware, Inc. - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmWIXRichTextFormatWriter.h" -#include <cmVersion.h> +#include "cmVersion.h" cmWIXRichTextFormatWriter::cmWIXRichTextFormatWriter( - const std::string& filename): - file(filename.c_str(), std::ios::binary) + std::string const& filename) + : File(filename.c_str(), std::ios::binary) { StartGroup(); WriteHeader(); @@ -29,48 +19,58 @@ cmWIXRichTextFormatWriter::~cmWIXRichTextFormatWriter() /* I haven't seen this in the RTF spec but * wordpad terminates its RTF like this */ - file << "\r\n"; - file.put(0); + File << "\r\n"; + File.put(0); } -void cmWIXRichTextFormatWriter::AddText(const std::string& text) +void cmWIXRichTextFormatWriter::AddText(std::string const& text) { typedef unsigned char rtf_byte_t; - for(size_t i = 0; i < text.size(); ++i) - { + for (size_t i = 0; i < text.size(); ++i) { rtf_byte_t c = rtf_byte_t(text[i]); - switch(c) - { - case '\\': - file << "\\\\"; - break; - case '{': - file << "\\{"; - break; - case '}': - file << "\\}"; - break; - case '\n': - file << "\\par\r\n"; - break; - case '\r': - continue; - default: - { - if(c <= 0x7F) - { - file << c; - } - else - { - file << "[NON-ASCII-" << int(c) << "]"; + switch (c) { + case '\\': + File << "\\\\"; + break; + case '{': + File << "\\{"; + break; + case '}': + File << "\\}"; + break; + case '\n': + File << "\\par\r\n"; + break; + case '\r': + continue; + default: { + if (c <= 0x7F) { + File << c; + } else { + if (c <= 0xC0) { + EmitInvalidCodepoint(c); + } else if (c < 0xE0 && i + 1 < text.size()) { + EmitUnicodeCodepoint((text[i + 1] & 0x3F) | ((c & 0x1F) << 6)); + i += 1; + } else if (c < 0xF0 && i + 2 < text.size()) { + EmitUnicodeCodepoint((text[i + 2] & 0x3F) | + ((text[i + 1] & 0x3F) << 6) | + ((c & 0xF) << 12)); + i += 2; + } else if (c < 0xF8 && i + 3 < text.size()) { + EmitUnicodeCodepoint( + (text[i + 3] & 0x3F) | ((text[i + 2] & 0x3F) << 6) | + ((text[i + 1] & 0x3F) << 12) | ((c & 0x7) << 18)); + i += 3; + } else { + EmitInvalidCodepoint(c); } } - break; - } + } break; } + } } void cmWIXRichTextFormatWriter::WriteHeader() @@ -82,6 +82,7 @@ void cmWIXRichTextFormatWriter::WriteHeader() ControlWord("deflang1031"); WriteFontTable(); + WriteColorTable(); WriteGenerator(); } @@ -99,11 +100,27 @@ void cmWIXRichTextFormatWriter::WriteFontTable() EndGroup(); } +void cmWIXRichTextFormatWriter::WriteColorTable() +{ + StartGroup(); + ControlWord("colortbl ;"); + ControlWord("red255"); + ControlWord("green0"); + ControlWord("blue0;"); + ControlWord("red0"); + ControlWord("green255"); + ControlWord("blue0;"); + ControlWord("red0"); + ControlWord("green0"); + ControlWord("blue255;"); + EndGroup(); +} + void cmWIXRichTextFormatWriter::WriteGenerator() { StartGroup(); NewControlWord("generator"); - file << " CPack WiX Generator (" << cmVersion::GetCMakeVersion() << ");"; + File << " CPack WiX Generator (" << cmVersion::GetCMakeVersion() << ");"; EndGroup(); } @@ -116,22 +133,54 @@ void cmWIXRichTextFormatWriter::WriteDocumentPrefix() ControlWord("fs20"); } -void cmWIXRichTextFormatWriter::ControlWord(const std::string& keyword) +void cmWIXRichTextFormatWriter::ControlWord(std::string const& keyword) { - file << "\\" << keyword; + File << "\\" << keyword; } -void cmWIXRichTextFormatWriter::NewControlWord(const std::string& keyword) +void cmWIXRichTextFormatWriter::NewControlWord(std::string const& keyword) { - file << "\\*\\" << keyword; + File << "\\*\\" << keyword; } void cmWIXRichTextFormatWriter::StartGroup() { - file.put('{'); + File.put('{'); } void cmWIXRichTextFormatWriter::EndGroup() { - file.put('}'); + File.put('}'); +} + +void cmWIXRichTextFormatWriter::EmitUnicodeCodepoint(int c) +{ + // Do not emit byte order mark (BOM) + if (c == 0xFEFF) { + return; + } else if (c <= 0xFFFF) { + EmitUnicodeSurrogate(c); + } else { + c -= 0x10000; + EmitUnicodeSurrogate(((c >> 10) & 0x3FF) + 0xD800); + EmitUnicodeSurrogate((c & 0x3FF) + 0xDC00); + } +} + +void cmWIXRichTextFormatWriter::EmitUnicodeSurrogate(int c) +{ + ControlWord("u"); + if (c <= 32767) { + File << c; + } else { + File << (c - 65536); + } + File << "?"; +} + +void cmWIXRichTextFormatWriter::EmitInvalidCodepoint(int c) +{ + ControlWord("cf1 "); + File << "[INVALID-BYTE-" << int(c) << "]"; + ControlWord("cf0 "); } diff --git a/Source/CPack/WiX/cmWIXRichTextFormatWriter.h b/Source/CPack/WiX/cmWIXRichTextFormatWriter.h index 10b67c39f..30df87814 100644 --- a/Source/CPack/WiX/cmWIXRichTextFormatWriter.h +++ b/Source/CPack/WiX/cmWIXRichTextFormatWriter.h @@ -1,19 +1,12 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2012 Kitware, Inc. - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #ifndef cmWIXRichTextFormatWriter_h #define cmWIXRichTextFormatWriter_h -#include <fstream> +#include "cmConfigure.h" + +#include "cmsys/FStream.hxx" +#include <string> /** \class cmWIXRichtTextFormatWriter * \brief Helper class to generate Rich Text Format (RTF) documents @@ -22,25 +15,31 @@ class cmWIXRichTextFormatWriter { public: - cmWIXRichTextFormatWriter(const std::string& filename); + cmWIXRichTextFormatWriter(std::string const& filename); ~cmWIXRichTextFormatWriter(); - void AddText(const std::string& text); + void AddText(std::string const& text); private: void WriteHeader(); void WriteFontTable(); + void WriteColorTable(); void WriteGenerator(); void WriteDocumentPrefix(); - void ControlWord(const std::string& keyword); - void NewControlWord(const std::string& keyword); + void ControlWord(std::string const& keyword); + void NewControlWord(std::string const& keyword); void StartGroup(); void EndGroup(); - std::ofstream file; + void EmitUnicodeCodepoint(int c); + void EmitUnicodeSurrogate(int c); + + void EmitInvalidCodepoint(int c); + + cmsys::ofstream File; }; #endif diff --git a/Source/CPack/WiX/cmWIXShortcut.cxx b/Source/CPack/WiX/cmWIXShortcut.cxx new file mode 100644 index 000000000..e5dea94c4 --- /dev/null +++ b/Source/CPack/WiX/cmWIXShortcut.cxx @@ -0,0 +1,105 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmWIXShortcut.h" + +#include "cmWIXFilesSourceWriter.h" + +void cmWIXShortcuts::insert(Type type, std::string const& id, + cmWIXShortcut const& shortcut) +{ + this->Shortcuts[type][id].push_back(shortcut); +} + +bool cmWIXShortcuts::empty(Type type) const +{ + return this->Shortcuts.find(type) == this->Shortcuts.end(); +} + +bool cmWIXShortcuts::EmitShortcuts( + Type type, std::string const& registryKey, + std::string const& cpackComponentName, + cmWIXFilesSourceWriter& fileDefinitions) const +{ + shortcut_type_map_t::const_iterator i = this->Shortcuts.find(type); + + if (i == this->Shortcuts.end()) { + return false; + } + + shortcut_id_map_t const& id_map = i->second; + + std::string shortcutPrefix; + std::string registrySuffix; + + switch (type) { + case START_MENU: + shortcutPrefix = "CM_S"; + break; + case DESKTOP: + shortcutPrefix = "CM_DS"; + registrySuffix = "_desktop"; + break; + case STARTUP: + shortcutPrefix = "CM_SS"; + registrySuffix = "_startup"; + break; + default: + return false; + } + + for (shortcut_id_map_t::const_iterator j = id_map.begin(); j != id_map.end(); + ++j) { + std::string const& id = j->first; + shortcut_list_t const& shortcutList = j->second; + + for (size_t shortcutListIndex = 0; shortcutListIndex < shortcutList.size(); + ++shortcutListIndex) { + cmWIXShortcut const& shortcut = shortcutList[shortcutListIndex]; + fileDefinitions.EmitShortcut(id, shortcut, shortcutPrefix, + shortcutListIndex); + } + } + + fileDefinitions.EmitInstallRegistryValue(registryKey, cpackComponentName, + registrySuffix); + + return true; +} + +void cmWIXShortcuts::AddShortcutTypes(std::set<Type>& types) +{ + for (shortcut_type_map_t::const_iterator i = this->Shortcuts.begin(); + i != this->Shortcuts.end(); ++i) { + types.insert(i->first); + } +} + +void cmWIXShortcuts::CreateFromProperties(std::string const& id, + std::string const& directoryId, + cmInstalledFile const& installedFile) +{ + CreateFromProperty("CPACK_START_MENU_SHORTCUTS", START_MENU, id, directoryId, + installedFile); + + CreateFromProperty("CPACK_DESKTOP_SHORTCUTS", DESKTOP, id, directoryId, + installedFile); + + CreateFromProperty("CPACK_STARTUP_SHORTCUTS", STARTUP, id, directoryId, + installedFile); +} + +void cmWIXShortcuts::CreateFromProperty(std::string const& propertyName, + Type type, std::string const& id, + std::string const& directoryId, + cmInstalledFile const& installedFile) +{ + std::vector<std::string> list; + installedFile.GetPropertyAsList(propertyName, list); + + for (size_t i = 0; i < list.size(); ++i) { + cmWIXShortcut shortcut; + shortcut.label = list[i]; + shortcut.workingDirectoryId = directoryId; + insert(type, id, shortcut); + } +} diff --git a/Source/CPack/WiX/cmWIXShortcut.h b/Source/CPack/WiX/cmWIXShortcut.h new file mode 100644 index 000000000..23ddc6a3f --- /dev/null +++ b/Source/CPack/WiX/cmWIXShortcut.h @@ -0,0 +1,60 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmWIXShortcut_h +#define cmWIXShortcut_h + +#include "cmInstalledFile.h" + +#include <map> +#include <set> +#include <string> +#include <vector> + +class cmWIXFilesSourceWriter; + +struct cmWIXShortcut +{ + std::string label; + std::string workingDirectoryId; +}; + +class cmWIXShortcuts +{ +public: + enum Type + { + START_MENU, + DESKTOP, + STARTUP + }; + + typedef std::vector<cmWIXShortcut> shortcut_list_t; + typedef std::map<std::string, shortcut_list_t> shortcut_id_map_t; + + void insert(Type type, std::string const& id, cmWIXShortcut const& shortcut); + + bool empty(Type type) const; + + bool EmitShortcuts(Type type, std::string const& registryKey, + std::string const& cpackComponentName, + cmWIXFilesSourceWriter& fileDefinitions) const; + + void AddShortcutTypes(std::set<Type>& types); + + void CreateFromProperties(std::string const& id, + std::string const& directoryId, + cmInstalledFile const& installedFile); + +private: + typedef std::map<Type, shortcut_id_map_t> shortcut_type_map_t; + + void CreateFromProperty(std::string const& propertyName, Type type, + std::string const& id, + std::string const& directoryId, + cmInstalledFile const& installedFile); + + shortcut_type_map_t Shortcuts; + shortcut_id_map_t EmptyIdMap; +}; + +#endif diff --git a/Source/CPack/WiX/cmWIXSourceWriter.cxx b/Source/CPack/WiX/cmWIXSourceWriter.cxx index af7ba807f..a86e28d1c 100644 --- a/Source/CPack/WiX/cmWIXSourceWriter.cxx +++ b/Source/CPack/WiX/cmWIXSourceWriter.cxx @@ -1,189 +1,184 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2012 Kitware, Inc. - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmWIXSourceWriter.h" -#include <CPack/cmCPackGenerator.h> +#include "cmCPackGenerator.h" + +#include "cmUuid.h" #include <windows.h> cmWIXSourceWriter::cmWIXSourceWriter(cmCPackLog* logger, - const std::string& filename, - bool isIncludeFile): - Logger(logger), - file(filename.c_str()), - state(DEFAULT) + std::string const& filename, + GuidType componentGuidType, + RootElementType rootElementType) + : Logger(logger) + , File(filename.c_str()) + , State(DEFAULT) + , SourceFilename(filename) + , ComponentGuidType(componentGuidType) { WriteXMLDeclaration(); - if(isIncludeFile) - { + if (rootElementType == INCLUDE_ELEMENT_ROOT) { BeginElement("Include"); - } - else - { + } else { BeginElement("Wix"); - } + } AddAttribute("xmlns", "http://schemas.microsoft.com/wix/2006/wi"); } cmWIXSourceWriter::~cmWIXSourceWriter() { - while(elements.size()) - { - EndElement(); - } + if (Elements.size() > 1) { + cmCPackLogger(cmCPackLog::LOG_ERROR, Elements.size() - 1 + << " WiX elements were still open when closing '" + << SourceFilename << "'" << std::endl); + return; + } + + EndElement(Elements.back()); } -void cmWIXSourceWriter::BeginElement(const std::string& name) +void cmWIXSourceWriter::BeginElement(std::string const& name) { - if(state == BEGIN) - { - file << ">"; - } + if (State == BEGIN) { + File << ">"; + } - file << "\n"; - Indent(elements.size()); - file << "<" << name; + File << "\n"; + Indent(Elements.size()); + File << "<" << name; - elements.push_back(name); - state = BEGIN; + Elements.push_back(name); + State = BEGIN; } -void cmWIXSourceWriter::EndElement() +void cmWIXSourceWriter::EndElement(std::string const& name) { - if(elements.empty()) - { + if (Elements.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "can not end WiX element with no open elements" << std::endl); + "can not end WiX element with no open elements in '" + << SourceFilename << "'" << std::endl); return; - } - - if(state == DEFAULT) - { - file << "\n"; - Indent(elements.size()-1); - file << "</" << elements.back() << ">"; - } - else - { - file << "/>"; - } + } - elements.pop_back(); - state = DEFAULT; + if (Elements.back() != name) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "WiX element <" + << Elements.back() << "> can not be closed by </" << name + << "> in '" << SourceFilename << "'" << std::endl); + return; + } + + if (State == DEFAULT) { + File << "\n"; + Indent(Elements.size() - 1); + File << "</" << Elements.back() << ">"; + } else { + File << "/>"; + } + + Elements.pop_back(); + State = DEFAULT; } -void cmWIXSourceWriter::AddProcessingInstruction( - const std::string& target, const std::string& content) +void cmWIXSourceWriter::AddTextNode(std::string const& text) { - if(state == BEGIN) - { - file << ">"; - } + if (State == BEGIN) { + File << ">"; + } - file << "\n"; - Indent(elements.size()); - file << "<?" << target << " " << content << "?>"; + if (Elements.empty()) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "can not add text without open WiX element in '" + << SourceFilename << "'" << std::endl); + return; + } - state = DEFAULT; + File << this->EscapeAttributeValue(text); + State = DEFAULT; } -void cmWIXSourceWriter::AddAttribute( - const std::string& key, const std::string& value) +void cmWIXSourceWriter::AddProcessingInstruction(std::string const& target, + std::string const& content) { - std::string utf8 = WindowsCodepageToUtf8(value); + if (State == BEGIN) { + File << ">"; + } - file << " " << key << "=\"" << EscapeAttributeValue(utf8) << '"'; + File << "\n"; + Indent(Elements.size()); + File << "<?" << target << " " << content << "?>"; + + State = DEFAULT; } -std::string cmWIXSourceWriter::WindowsCodepageToUtf8(const std::string& value) +void cmWIXSourceWriter::AddAttribute(std::string const& key, + std::string const& value) { - if(value.empty()) - { - return std::string(); - } - - int characterCount = MultiByteToWideChar( - CP_ACP, 0, value.c_str(), static_cast<int>(value.size()), 0, 0); - - if(characterCount == 0) - { - return std::string(); - } - - std::vector<wchar_t> utf16(characterCount); - - MultiByteToWideChar( - CP_ACP, 0, value.c_str(), static_cast<int>(value.size()), - &utf16[0], static_cast<int>(utf16.size())); - - int utf8ByteCount = WideCharToMultiByte( - CP_UTF8, 0, &utf16[0], static_cast<int>(utf16.size()), 0, 0, 0, 0); - - if(utf8ByteCount == 0) - { - return std::string(); - } - - std::vector<char> utf8(utf8ByteCount); - - WideCharToMultiByte(CP_UTF8, 0, &utf16[0], static_cast<int>(utf16.size()), - &utf8[0], static_cast<int>(utf8.size()), 0, 0); + File << " " << key << "=\"" << EscapeAttributeValue(value) << '"'; +} - return std::string(&utf8[0], utf8.size()); +void cmWIXSourceWriter::AddAttributeUnlessEmpty(std::string const& key, + std::string const& value) +{ + if (!value.empty()) { + AddAttribute(key, value); + } } +std::string cmWIXSourceWriter::CreateGuidFromComponentId( + std::string const& componentId) +{ + std::string guid = "*"; + if (this->ComponentGuidType == CMAKE_GENERATED_GUID) { + std::string md5 = cmSystemTools::ComputeStringMD5(componentId); + cmUuid uuid; + std::vector<unsigned char> ns; + guid = uuid.FromMd5(ns, md5); + } + return guid; +} void cmWIXSourceWriter::WriteXMLDeclaration() { - file << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl; + File << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl; } void cmWIXSourceWriter::Indent(size_t count) { - for(size_t i = 0; i < count; ++i) - { - file << " "; - } + for (size_t i = 0; i < count; ++i) { + File << " "; + } } -std::string cmWIXSourceWriter::EscapeAttributeValue( - const std::string& value) +std::string cmWIXSourceWriter::EscapeAttributeValue(std::string const& value) { std::string result; result.reserve(value.size()); char c = 0; - for(size_t i = 0 ; i < value.size(); ++i) - { + for (size_t i = 0; i < value.size(); ++i) { c = value[i]; - switch(c) - { - case '<': - result += "<"; - break; - case '&': - result +="&"; - break; - case '"': - result += """; - break; - default: - result += c; - break; - } + switch (c) { + case '<': + result += "<"; + break; + case '>': + result += ">"; + break; + case '&': + result += "&"; + break; + case '"': + result += """; + break; + default: + result += c; + break; } + } return result; } diff --git a/Source/CPack/WiX/cmWIXSourceWriter.h b/Source/CPack/WiX/cmWIXSourceWriter.h index 1dafc1ff2..4af1ed6ed 100644 --- a/Source/CPack/WiX/cmWIXSourceWriter.h +++ b/Source/CPack/WiX/cmWIXSourceWriter.h @@ -1,23 +1,14 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2012 Kitware, Inc. - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #ifndef cmWIXSourceWriter_h #define cmWIXSourceWriter_h -#include <vector> -#include <string> -#include <fstream> +#include "cmCPackLog.h" -#include <CPack/cmCPackLog.h> +#include "cmsys/FStream.hxx" + +#include <string> +#include <vector> /** \class cmWIXSourceWriter * \brief Helper class to generate XML WiX source files @@ -25,22 +16,42 @@ class cmWIXSourceWriter { public: - cmWIXSourceWriter(cmCPackLog* logger, - const std::string& filename, bool isIncludeFile = false); + enum GuidType + { + WIX_GENERATED_GUID, + CMAKE_GENERATED_GUID + }; + + enum RootElementType + { + WIX_ELEMENT_ROOT, + INCLUDE_ELEMENT_ROOT + }; + + cmWIXSourceWriter(cmCPackLog* logger, std::string const& filename, + GuidType componentGuidType, + RootElementType rootElementType = WIX_ELEMENT_ROOT); ~cmWIXSourceWriter(); - void BeginElement(const std::string& name); + void BeginElement(std::string const& name); + + void EndElement(std::string const& name); - void EndElement(); + void AddTextNode(std::string const& text); - void AddProcessingInstruction( - const std::string& target, const std::string& content); + void AddProcessingInstruction(std::string const& target, + std::string const& content); - void AddAttribute( - const std::string& key, const std::string& value); + void AddAttribute(std::string const& key, std::string const& value); - static std::string WindowsCodepageToUtf8(const std::string& value); + void AddAttributeUnlessEmpty(std::string const& key, + std::string const& value); + + std::string CreateGuidFromComponentId(std::string const& componentId); + +protected: + cmCPackLog* Logger; private: enum State @@ -53,15 +64,17 @@ private: void Indent(size_t count); - static std::string EscapeAttributeValue(const std::string& value); + static std::string EscapeAttributeValue(std::string const& value); - cmCPackLog* Logger; + cmsys::ofstream File; + + State State; - std::ofstream file; + std::vector<std::string> Elements; - State state; + std::string SourceFilename; - std::vector<std::string> elements; + GuidType ComponentGuidType; }; #endif diff --git a/Source/CPack/cmCPack7zGenerator.cxx b/Source/CPack/cmCPack7zGenerator.cxx new file mode 100644 index 000000000..f0c41a2a1 --- /dev/null +++ b/Source/CPack/cmCPack7zGenerator.cxx @@ -0,0 +1,15 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmCPack7zGenerator.h" + +#include "cmArchiveWrite.h" +#include "cmCPackArchiveGenerator.h" + +cmCPack7zGenerator::cmCPack7zGenerator() + : cmCPackArchiveGenerator(cmArchiveWrite::CompressNone, "7zip") +{ +} + +cmCPack7zGenerator::~cmCPack7zGenerator() +{ +} diff --git a/Source/CPack/cmCPack7zGenerator.h b/Source/CPack/cmCPack7zGenerator.h new file mode 100644 index 000000000..42a47810c --- /dev/null +++ b/Source/CPack/cmCPack7zGenerator.h @@ -0,0 +1,29 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmCPack7zGenerator_h +#define cmCPack7zGenerator_h + +#include "cmConfigure.h" + +#include "cmCPackArchiveGenerator.h" +#include "cmCPackGenerator.h" + +/** \class cmCPack7zGenerator + * \brief A generator for 7z files + */ +class cmCPack7zGenerator : public cmCPackArchiveGenerator +{ +public: + cmCPackTypeMacro(cmCPack7zGenerator, cmCPackArchiveGenerator); + + /** + * Construct generator + */ + cmCPack7zGenerator(); + ~cmCPack7zGenerator() CM_OVERRIDE; + +protected: + const char* GetOutputExtension() CM_OVERRIDE { return ".7z"; } +}; + +#endif diff --git a/Source/CPack/cmCPackArchiveGenerator.cxx b/Source/CPack/cmCPackArchiveGenerator.cxx index 6e7b8d7c8..575c94924 100644 --- a/Source/CPack/cmCPackArchiveGenerator.cxx +++ b/Source/CPack/cmCPackArchiveGenerator.cxx @@ -1,86 +1,91 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCPackArchiveGenerator.h" -#include "cmake.h" -#include "cmGlobalGenerator.h" -#include "cmLocalGenerator.h" -#include "cmSystemTools.h" -#include "cmMakefile.h" -#include "cmGeneratedFileStream.h" +#include "cmCPackComponentGroup.h" +#include "cmCPackGenerator.h" #include "cmCPackLog.h" -#include <errno.h> +#include "cmGeneratedFileStream.h" +#include "cmSystemTools.h" +#include "cmWorkingDirectory.h" -#include <cmsys/SystemTools.hxx> -#include <cmsys/Directory.hxx> -#include <cm_libarchive.h> +#include <map> +#include <ostream> +#include <utility> +#include <vector> -//---------------------------------------------------------------------- cmCPackArchiveGenerator::cmCPackArchiveGenerator(cmArchiveWrite::Compress t, - cmArchiveWrite::Type at) + std::string const& format) { this->Compress = t; - this->Archive = at; + this->ArchiveFormat = format; } -//---------------------------------------------------------------------- cmCPackArchiveGenerator::~cmCPackArchiveGenerator() { } -//---------------------------------------------------------------------- +std::string cmCPackArchiveGenerator::GetArchiveComponentFileName( + const std::string& component, bool isGroupName) +{ + std::string componentUpper(cmSystemTools::UpperCase(component)); + std::string packageFileName; + + if (this->IsSet("CPACK_ARCHIVE_" + componentUpper + "_FILE_NAME")) { + packageFileName += + this->GetOption("CPACK_ARCHIVE_" + componentUpper + "_FILE_NAME"); + } else if (this->IsSet("CPACK_ARCHIVE_FILE_NAME")) { + packageFileName += GetComponentPackageFileName( + this->GetOption("CPACK_ARCHIVE_FILE_NAME"), component, isGroupName); + } else { + packageFileName += GetComponentPackageFileName( + this->GetOption("CPACK_PACKAGE_FILE_NAME"), component, isGroupName); + } + + packageFileName += this->GetOutputExtension(); + + return packageFileName; +} + int cmCPackArchiveGenerator::InitializeInternal() { this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "1"); return this->Superclass::InitializeInternal(); } -//---------------------------------------------------------------------- -int cmCPackArchiveGenerator::addOneComponentToArchive(cmArchiveWrite& archive, - cmCPackComponent* component) +int cmCPackArchiveGenerator::addOneComponentToArchive( + cmArchiveWrite& archive, cmCPackComponent* component) { - cmCPackLogger(cmCPackLog::LOG_VERBOSE, " - packaging component: " - << component->Name - << std::endl); + cmCPackLogger(cmCPackLog::LOG_VERBOSE, + " - packaging component: " << component->Name << std::endl); // Add the files of this component to the archive std::string localToplevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY")); - localToplevel += "/"+ component->Name; - std::string dir = cmSystemTools::GetCurrentWorkingDirectory(); + localToplevel += "/" + component->Name; // Change to local toplevel - cmSystemTools::ChangeDirectory(localToplevel.c_str()); + cmWorkingDirectory workdir(localToplevel); std::string filePrefix; - if (this->IsOn("CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY")) - { + if (this->IsOn("CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY")) { filePrefix = this->GetOption("CPACK_PACKAGE_FILE_NAME"); filePrefix += "/"; - } + } + const char* installPrefix = + this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX"); + if (installPrefix && installPrefix[0] == '/' && installPrefix[1] != 0) { + // add to file prefix and remove the leading '/' + filePrefix += installPrefix + 1; + filePrefix += "/"; + } std::vector<std::string>::const_iterator fileIt; for (fileIt = component->Files.begin(); fileIt != component->Files.end(); - ++fileIt ) - { + ++fileIt) { std::string rp = filePrefix + *fileIt; - cmCPackLogger(cmCPackLog::LOG_DEBUG,"Adding file: " - << rp << std::endl); - archive.Add(rp); - if (!archive) - { + cmCPackLogger(cmCPackLog::LOG_DEBUG, "Adding file: " << rp << std::endl); + archive.Add(rp, 0, CM_NULLPTR, false); + if (!archive) { cmCPackLogger(cmCPackLog::LOG_ERROR, "ERROR while packaging files: " - << archive.GetError() - << std::endl); + << archive.GetError() << std::endl); return 0; - } } - // Go back to previous dir - cmSystemTools::ChangeDirectory(dir.c_str()); + } return 1; } @@ -89,226 +94,188 @@ int cmCPackArchiveGenerator::addOneComponentToArchive(cmArchiveWrite& archive, * an declare and open the associated * cmArchiveWrite 'archive' object. */ -#define DECLARE_AND_OPEN_ARCHIVE(filename,archive) \ -cmGeneratedFileStream gf; \ -gf.Open(filename.c_str(), false, true); \ -if (!GenerateHeader(&gf)) \ - { \ - cmCPackLogger(cmCPackLog::LOG_ERROR, \ - "Problem to generate Header for archive < " \ - << filename \ - << ">." << std::endl); \ - return 0; \ - } \ -cmArchiveWrite archive(gf,this->Compress, this->Archive); \ -if (!archive) \ - { \ - cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem to create archive < " \ - << filename \ - << ">. ERROR =" \ - << archive.GetError() \ - << std::endl); \ - return 0; \ +#define DECLARE_AND_OPEN_ARCHIVE(filename, archive) \ + cmGeneratedFileStream gf; \ + gf.Open((filename).c_str(), false, true); \ + if (!GenerateHeader(&gf)) { \ + cmCPackLogger(cmCPackLog::LOG_ERROR, \ + "Problem to generate Header for archive < " \ + << (filename) << ">." << std::endl); \ + return 0; \ + } \ + cmArchiveWrite archive(gf, this->Compress, this->ArchiveFormat); \ + if (!(archive)) { \ + cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem to create archive < " \ + << (filename) << ">. ERROR =" << (archive).GetError() \ + << std::endl); \ + return 0; \ } -//---------------------------------------------------------------------- int cmCPackArchiveGenerator::PackageComponents(bool ignoreGroup) { packageFileNames.clear(); // The default behavior is to have one package by component group // unless CPACK_COMPONENTS_IGNORE_GROUP is specified. - if (!ignoreGroup) - { + if (!ignoreGroup) { std::map<std::string, cmCPackComponentGroup>::iterator compGIt; - for (compGIt=this->ComponentGroups.begin(); - compGIt!=this->ComponentGroups.end(); ++compGIt) - { + for (compGIt = this->ComponentGroups.begin(); + compGIt != this->ComponentGroups.end(); ++compGIt) { cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Packaging component group: " - << compGIt->first - << std::endl); + << compGIt->first << std::endl); // Begin the archive for this group - std::string packageFileName= std::string(toplevel); - packageFileName += "/"+ - GetComponentPackageFileName(this->GetOption("CPACK_PACKAGE_FILE_NAME"), - compGIt->first, - true) - + this->GetOutputExtension(); + std::string packageFileName = std::string(toplevel) + "/" + + this->GetArchiveComponentFileName(compGIt->first, true); + // open a block in order to automatically close archive // at the end of the block { - DECLARE_AND_OPEN_ARCHIVE(packageFileName,archive); + DECLARE_AND_OPEN_ARCHIVE(packageFileName, archive); // now iterate over the component of this group std::vector<cmCPackComponent*>::iterator compIt; - for (compIt=(compGIt->second).Components.begin(); - compIt!=(compGIt->second).Components.end(); - ++compIt) - { + for (compIt = (compGIt->second).Components.begin(); + compIt != (compGIt->second).Components.end(); ++compIt) { // Add the files of this component to the archive - addOneComponentToArchive(archive,*compIt); - } + addOneComponentToArchive(archive, *compIt); + } } // add the generated package to package file names list packageFileNames.push_back(packageFileName); - } + } // Handle Orphan components (components not belonging to any groups) std::map<std::string, cmCPackComponent>::iterator compIt; - for (compIt=this->Components.begin(); - compIt!=this->Components.end(); ++compIt ) - { + for (compIt = this->Components.begin(); compIt != this->Components.end(); + ++compIt) { // Does the component belong to a group? - if (compIt->second.Group==NULL) - { - cmCPackLogger(cmCPackLog::LOG_VERBOSE, - "Component <" - << compIt->second.Name - << "> does not belong to any group, package it separately." - << std::endl); + if (compIt->second.Group == CM_NULLPTR) { + cmCPackLogger( + cmCPackLog::LOG_VERBOSE, "Component <" + << compIt->second.Name + << "> does not belong to any group, package it separately." + << std::endl); std::string localToplevel( - this->GetOption("CPACK_TEMPORARY_DIRECTORY") - ); + this->GetOption("CPACK_TEMPORARY_DIRECTORY")); std::string packageFileName = std::string(toplevel); - localToplevel += "/"+ compIt->first; - packageFileName += "/"+ - GetComponentPackageFileName(this->GetOption("CPACK_PACKAGE_FILE_NAME"), - compIt->first, - false) - + this->GetOutputExtension(); + localToplevel += "/" + compIt->first; + packageFileName += + "/" + this->GetArchiveComponentFileName(compIt->first, false); + { - DECLARE_AND_OPEN_ARCHIVE(packageFileName,archive); + DECLARE_AND_OPEN_ARCHIVE(packageFileName, archive); // Add the files of this component to the archive - addOneComponentToArchive(archive,&(compIt->second)); + addOneComponentToArchive(archive, &(compIt->second)); } // add the generated package to package file names list packageFileNames.push_back(packageFileName); - } } } + } // CPACK_COMPONENTS_IGNORE_GROUPS is set // We build 1 package per component - else - { + else { std::map<std::string, cmCPackComponent>::iterator compIt; - for (compIt=this->Components.begin(); - compIt!=this->Components.end(); ++compIt ) - { + for (compIt = this->Components.begin(); compIt != this->Components.end(); + ++compIt) { std::string localToplevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY")); std::string packageFileName = std::string(toplevel); - localToplevel += "/"+ compIt->first; - packageFileName += "/"+ - GetComponentPackageFileName(this->GetOption("CPACK_PACKAGE_FILE_NAME"), - compIt->first, - false) - + this->GetOutputExtension(); + localToplevel += "/" + compIt->first; + packageFileName += + "/" + this->GetArchiveComponentFileName(compIt->first, false); + { - DECLARE_AND_OPEN_ARCHIVE(packageFileName,archive); + DECLARE_AND_OPEN_ARCHIVE(packageFileName, archive); // Add the files of this component to the archive - addOneComponentToArchive(archive,&(compIt->second)); + addOneComponentToArchive(archive, &(compIt->second)); } // add the generated package to package file names list packageFileNames.push_back(packageFileName); - } } + } return 1; } -//---------------------------------------------------------------------- int cmCPackArchiveGenerator::PackageComponentsAllInOne() { // reset the package file names packageFileNames.clear(); packageFileNames.push_back(std::string(toplevel)); - packageFileNames[0] += "/" - +std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME")) - + this->GetOutputExtension(); + packageFileNames[0] += "/"; + + if (this->IsSet("CPACK_ARCHIVE_FILE_NAME")) { + packageFileNames[0] += this->GetOption("CPACK_ARCHIVE_FILE_NAME"); + } else { + packageFileNames[0] += this->GetOption("CPACK_PACKAGE_FILE_NAME"); + } + + packageFileNames[0] += this->GetOutputExtension(); + cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Packaging all groups in one package..." "(CPACK_COMPONENTS_ALL_GROUPS_IN_ONE_PACKAGE is set)" - << std::endl); - DECLARE_AND_OPEN_ARCHIVE(packageFileNames[0],archive); + << std::endl); + DECLARE_AND_OPEN_ARCHIVE(packageFileNames[0], archive); // The ALL COMPONENTS in ONE package case std::map<std::string, cmCPackComponent>::iterator compIt; - for (compIt=this->Components.begin();compIt!=this->Components.end(); - ++compIt ) - { + for (compIt = this->Components.begin(); compIt != this->Components.end(); + ++compIt) { // Add the files of this component to the archive - addOneComponentToArchive(archive,&(compIt->second)); - } + addOneComponentToArchive(archive, &(compIt->second)); + } // archive goes out of scope so it will finalized and closed. return 1; } -//---------------------------------------------------------------------- int cmCPackArchiveGenerator::PackageFiles() { - cmCPackLogger(cmCPackLog::LOG_DEBUG, "Toplevel: " - << toplevel << std::endl); + cmCPackLogger(cmCPackLog::LOG_DEBUG, "Toplevel: " << toplevel << std::endl); if (WantsComponentInstallation()) { // CASE 1 : COMPONENT ALL-IN-ONE package // If ALL COMPONENTS in ONE package has been requested // then the package file is unique and should be open here. - if (componentPackageMethod == ONE_PACKAGE) - { + if (componentPackageMethod == ONE_PACKAGE) { return PackageComponentsAllInOne(); - } + } // CASE 2 : COMPONENT CLASSICAL package(s) (i.e. not all-in-one) // There will be 1 package for each component group // however one may require to ignore component group and // in this case you'll get 1 package for each component. - else - { - return PackageComponents(componentPackageMethod == - ONE_PACKAGE_PER_COMPONENT); - } + return PackageComponents(componentPackageMethod == + ONE_PACKAGE_PER_COMPONENT); } // CASE 3 : NON COMPONENT package. - DECLARE_AND_OPEN_ARCHIVE(packageFileNames[0],archive); + DECLARE_AND_OPEN_ARCHIVE(packageFileNames[0], archive); std::vector<std::string>::const_iterator fileIt; - std::string dir = cmSystemTools::GetCurrentWorkingDirectory(); - cmSystemTools::ChangeDirectory(toplevel.c_str()); - for ( fileIt = files.begin(); fileIt != files.end(); ++ fileIt ) - { + cmWorkingDirectory workdir(toplevel); + for (fileIt = files.begin(); fileIt != files.end(); ++fileIt) { // Get the relative path to the file - std::string rp = cmSystemTools::RelativePath(toplevel.c_str(), - fileIt->c_str()); - archive.Add(rp); - if(!archive) - { + std::string rp = + cmSystemTools::RelativePath(toplevel.c_str(), fileIt->c_str()); + archive.Add(rp, 0, CM_NULLPTR, false); + if (!archive) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem while adding file< " - << *fileIt - << "> to archive <" - << packageFileNames[0] << "> .ERROR =" - << archive.GetError() - << std::endl); + << *fileIt << "> to archive <" << packageFileNames[0] + << "> .ERROR =" << archive.GetError() << std::endl); return 0; - } } - cmSystemTools::ChangeDirectory(dir.c_str()); + } // The destructor of cmArchiveWrite will close and finish the write return 1; } -//---------------------------------------------------------------------- -int cmCPackArchiveGenerator::GenerateHeader(std::ostream*) +int cmCPackArchiveGenerator::GenerateHeader(std::ostream* /*unused*/) { return 1; } -bool cmCPackArchiveGenerator::SupportsComponentInstallation() const { +bool cmCPackArchiveGenerator::SupportsComponentInstallation() const +{ // The Component installation support should only // be activated if explicitly requested by the user // (for backward compatibility reason) - if (IsOn("CPACK_ARCHIVE_COMPONENT_INSTALL")) - { - return true; - } - else - { - return false; - } + return IsOn("CPACK_ARCHIVE_COMPONENT_INSTALL"); } diff --git a/Source/CPack/cmCPackArchiveGenerator.h b/Source/CPack/cmCPackArchiveGenerator.h index 6411b1ebf..e7116c466 100644 --- a/Source/CPack/cmCPackArchiveGenerator.h +++ b/Source/CPack/cmCPackArchiveGenerator.h @@ -1,21 +1,17 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc. - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #ifndef cmCPackArchiveGenerator_h #define cmCPackArchiveGenerator_h +#include "cmConfigure.h" + #include "cmArchiveWrite.h" #include "cmCPackGenerator.h" +#include <iosfwd> +#include <string> + +class cmCPackComponent; /** \class cmCPackArchiveGenerator * \brief A generator base for libarchive generation. @@ -24,21 +20,27 @@ * */ class cmCPackArchiveGenerator : public cmCPackGenerator - { +{ public: - cmTypeMacro(cmCPackArchiveGenerator, cmCPackGenerator); + typedef cmCPackGenerator Superclass; /** * Construct generator */ - cmCPackArchiveGenerator(cmArchiveWrite::Compress, cmArchiveWrite::Type); - virtual ~cmCPackArchiveGenerator(); + cmCPackArchiveGenerator(cmArchiveWrite::Compress, std::string const& format); + ~cmCPackArchiveGenerator() CM_OVERRIDE; // Used to add a header to the archive virtual int GenerateHeader(std::ostream* os); // component support - virtual bool SupportsComponentInstallation() const; + bool SupportsComponentInstallation() const CM_OVERRIDE; + +private: + // get archive component filename + std::string GetArchiveComponentFileName(const std::string& component, + bool isGroupName); + protected: - virtual int InitializeInternal(); + int InitializeInternal() CM_OVERRIDE; /** * Add the files belonging to the specified component * to the provided (already opened) archive. @@ -54,7 +56,7 @@ protected: * method will call either PackageComponents or * PackageComponentsAllInOne. */ - int PackageFiles(); + int PackageFiles() CM_OVERRIDE; /** * The method used to package files when component * install is used. This will create one @@ -66,9 +68,9 @@ protected: * components will be put in a single installer. */ int PackageComponentsAllInOne(); - virtual const char* GetOutputExtension() = 0; + const char* GetOutputExtension() CM_OVERRIDE = 0; cmArchiveWrite::Compress Compress; - cmArchiveWrite::Type Archive; - }; + std::string ArchiveFormat; +}; #endif diff --git a/Source/CPack/cmCPackBundleGenerator.cxx b/Source/CPack/cmCPackBundleGenerator.cxx index 6c994f13f..d5389014a 100644 --- a/Source/CPack/cmCPackBundleGenerator.cxx +++ b/Source/CPack/cmCPackBundleGenerator.cxx @@ -1,48 +1,47 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmCPackBundleGenerator.h" - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ +#include <sstream> +#include <vector> -#include "cmCPackBundleGenerator.h" #include "cmCPackLog.h" #include "cmSystemTools.h" -#include <cmsys/RegularExpression.hxx> - -//---------------------------------------------------------------------- cmCPackBundleGenerator::cmCPackBundleGenerator() { } -//---------------------------------------------------------------------- cmCPackBundleGenerator::~cmCPackBundleGenerator() { } -//---------------------------------------------------------------------- int cmCPackBundleGenerator::InitializeInternal() { const char* name = this->GetOption("CPACK_BUNDLE_NAME"); - if(0 == name) - { + if (0 == name) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "CPACK_BUNDLE_NAME must be set to use the Bundle generator." - << std::endl); + "CPACK_BUNDLE_NAME must be set to use the Bundle generator." + << std::endl); return 0; + } + + if (this->GetOption("CPACK_BUNDLE_APPLE_CERT_APP")) { + const std::string codesign_path = cmSystemTools::FindProgram( + "codesign", std::vector<std::string>(), false); + + if (codesign_path.empty()) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot locate codesign command" + << std::endl); + return 0; } + this->SetOptionIfNotSet("CPACK_COMMAND_CODESIGN", codesign_path.c_str()); + } return this->Superclass::InitializeInternal(); } -//---------------------------------------------------------------------- const char* cmCPackBundleGenerator::GetPackagingInstallPrefix() { this->InstallPrefix = "/"; @@ -52,118 +51,129 @@ const char* cmCPackBundleGenerator::GetPackagingInstallPrefix() return this->InstallPrefix.c_str(); } -//---------------------------------------------------------------------- -int cmCPackBundleGenerator::PackageFiles() +int cmCPackBundleGenerator::ConstructBundle() { // Get required arguments ... const std::string cpack_bundle_name = this->GetOption("CPACK_BUNDLE_NAME") - ? this->GetOption("CPACK_BUNDLE_NAME") : ""; - if(cpack_bundle_name.empty()) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "CPACK_BUNDLE_NAME must be set." - << std::endl); + ? this->GetOption("CPACK_BUNDLE_NAME") + : ""; + if (cpack_bundle_name.empty()) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "CPACK_BUNDLE_NAME must be set." + << std::endl); return 0; - } + } const std::string cpack_bundle_plist = this->GetOption("CPACK_BUNDLE_PLIST") - ? this->GetOption("CPACK_BUNDLE_PLIST") : ""; - if(cpack_bundle_plist.empty()) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "CPACK_BUNDLE_PLIST must be set." - << std::endl); + ? this->GetOption("CPACK_BUNDLE_PLIST") + : ""; + if (cpack_bundle_plist.empty()) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "CPACK_BUNDLE_PLIST must be set." + << std::endl); return 0; - } + } const std::string cpack_bundle_icon = this->GetOption("CPACK_BUNDLE_ICON") - ? this->GetOption("CPACK_BUNDLE_ICON") : ""; - if(cpack_bundle_icon.empty()) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "CPACK_BUNDLE_ICON must be set." - << std::endl); + ? this->GetOption("CPACK_BUNDLE_ICON") + : ""; + if (cpack_bundle_icon.empty()) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "CPACK_BUNDLE_ICON must be set." + << std::endl); return 0; - } + } // Get optional arguments ... const std::string cpack_bundle_startup_command = this->GetOption("CPACK_BUNDLE_STARTUP_COMMAND") - ? this->GetOption("CPACK_BUNDLE_STARTUP_COMMAND") : ""; + ? this->GetOption("CPACK_BUNDLE_STARTUP_COMMAND") + : ""; // The staging directory contains everything that will end-up inside the // final disk image ... - cmOStringStream staging; + std::ostringstream staging; staging << toplevel; - cmOStringStream contents; - contents << staging.str() << "/" << cpack_bundle_name - << ".app/" << "Contents"; + std::ostringstream contents; + contents << staging.str() << "/" << cpack_bundle_name << ".app/" + << "Contents"; - cmOStringStream application; - application << contents.str() << "/" << "MacOS"; + std::ostringstream application; + application << contents.str() << "/" + << "MacOS"; - cmOStringStream resources; - resources << contents.str() << "/" << "Resources"; + std::ostringstream resources; + resources << contents.str() << "/" + << "Resources"; // Install a required, user-provided bundle metadata file ... - cmOStringStream plist_source; + std::ostringstream plist_source; plist_source << cpack_bundle_plist; - cmOStringStream plist_target; - plist_target << contents.str() << "/" << "Info.plist"; + std::ostringstream plist_target; + plist_target << contents.str() << "/" + << "Info.plist"; - if(!this->CopyFile(plist_source, plist_target)) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, + if (!this->CopyFile(plist_source, plist_target)) { + cmCPackLogger( + cmCPackLog::LOG_ERROR, "Error copying plist. Check the value of CPACK_BUNDLE_PLIST." - << std::endl); + << std::endl); return 0; - } + } // Install a user-provided bundle icon ... - cmOStringStream icon_source; + std::ostringstream icon_source; icon_source << cpack_bundle_icon; - cmOStringStream icon_target; + std::ostringstream icon_target; icon_target << resources.str() << "/" << cpack_bundle_name << ".icns"; - if(!this->CopyFile(icon_source, icon_target)) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, + if (!this->CopyFile(icon_source, icon_target)) { + cmCPackLogger( + cmCPackLog::LOG_ERROR, "Error copying bundle icon. Check the value of CPACK_BUNDLE_ICON." - << std::endl); + << std::endl); return 0; - } + } // Optionally a user-provided startup command (could be an // executable or a script) ... - if(!cpack_bundle_startup_command.empty()) - { - cmOStringStream command_source; + if (!cpack_bundle_startup_command.empty()) { + std::ostringstream command_source; command_source << cpack_bundle_startup_command; - cmOStringStream command_target; + std::ostringstream command_target; command_target << application.str() << "/" << cpack_bundle_name; - if(!this->CopyFile(command_source, command_target)) - { + if (!this->CopyFile(command_source, command_target)) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Error copying startup command. " " Check the value of CPACK_BUNDLE_STARTUP_COMMAND." - << std::endl); + << std::endl); return 0; - } + } cmSystemTools::SetPermissions(command_target.str().c_str(), 0777); - } + } + + return 1; +} + +int cmCPackBundleGenerator::PackageFiles() +{ + if (!this->ConstructBundle()) { + return 0; + } + + if (!this->SignBundle(toplevel)) { + return 0; + } return this->CreateDMG(toplevel, packageFileNames[0]); } @@ -172,3 +182,102 @@ bool cmCPackBundleGenerator::SupportsComponentInstallation() const { return false; } + +int cmCPackBundleGenerator::SignBundle(const std::string& src_dir) +{ + const std::string cpack_apple_cert_app = + this->GetOption("CPACK_BUNDLE_APPLE_CERT_APP") + ? this->GetOption("CPACK_BUNDLE_APPLE_CERT_APP") + : ""; + + // codesign the application. + if (!cpack_apple_cert_app.empty()) { + std::string output; + std::string bundle_path; + bundle_path = src_dir + "/"; + bundle_path += this->GetOption("CPACK_BUNDLE_NAME"); + bundle_path += ".app"; + + // A list of additional files to sign, ie. frameworks and plugins. + const std::string sign_parameter = + this->GetOption("CPACK_BUNDLE_APPLE_CODESIGN_PARAMETER") + ? this->GetOption("CPACK_BUNDLE_APPLE_CODESIGN_PARAMETER") + : "--deep -f"; + + const std::string sign_files = + this->GetOption("CPACK_BUNDLE_APPLE_CODESIGN_FILES") + ? this->GetOption("CPACK_BUNDLE_APPLE_CODESIGN_FILES") + : ""; + + std::vector<std::string> relFiles; + cmSystemTools::ExpandListArgument(sign_files, relFiles); + + // sign the files supplied by the user, ie. frameworks. + for (std::vector<std::string>::iterator it = relFiles.begin(); + it != relFiles.end(); ++it) { + std::ostringstream temp_sign_file_cmd; + temp_sign_file_cmd << this->GetOption("CPACK_COMMAND_CODESIGN"); + temp_sign_file_cmd << " " << sign_parameter << " -s \"" + << cpack_apple_cert_app; + temp_sign_file_cmd << "\" -i "; + temp_sign_file_cmd << this->GetOption("CPACK_APPLE_BUNDLE_ID"); + temp_sign_file_cmd << " \""; + temp_sign_file_cmd << bundle_path; + temp_sign_file_cmd << *it << "\""; + + if (!this->RunCommand(temp_sign_file_cmd, &output)) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Error signing file:" << bundle_path << *it << std::endl + << output << std::endl); + + return 0; + } + } + + // sign main binary + std::ostringstream temp_sign_binary_cmd; + temp_sign_binary_cmd << this->GetOption("CPACK_COMMAND_CODESIGN"); + temp_sign_binary_cmd << " " << sign_parameter << " -s \"" + << cpack_apple_cert_app; + temp_sign_binary_cmd << "\" \"" << bundle_path << "\""; + + if (!this->RunCommand(temp_sign_binary_cmd, &output)) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Error signing the application binary." << std::endl + << output + << std::endl); + + return 0; + } + + // sign app bundle + std::ostringstream temp_codesign_cmd; + temp_codesign_cmd << this->GetOption("CPACK_COMMAND_CODESIGN"); + temp_codesign_cmd << " " << sign_parameter << " -s \"" + << cpack_apple_cert_app << "\""; + if (this->GetOption("CPACK_BUNDLE_APPLE_ENTITLEMENTS")) { + temp_codesign_cmd << " --entitlements "; + temp_codesign_cmd << this->GetOption("CPACK_BUNDLE_APPLE_ENTITLEMENTS"); + } + temp_codesign_cmd << " \"" << bundle_path << "\""; + + if (!this->RunCommand(temp_codesign_cmd, &output)) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Error signing the application package." << std::endl + << output + << std::endl); + + return 0; + } + + cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Application has been codesigned" + << std::endl); + cmCPackLogger(cmCPackLog::LOG_VERBOSE, + (this->GetOption("CPACK_BUNDLE_APPLE_ENTITLEMENTS") + ? "with entitlement sandboxing" + : "without entitlement sandboxing") + << std::endl); + } + + return 1; +} diff --git a/Source/CPack/cmCPackBundleGenerator.h b/Source/CPack/cmCPackBundleGenerator.h index ed0187dd4..861fe4b09 100644 --- a/Source/CPack/cmCPackBundleGenerator.h +++ b/Source/CPack/cmCPackBundleGenerator.h @@ -1,19 +1,14 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc. - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #ifndef cmCPackBundleGenerator_h #define cmCPackBundleGenerator_h +#include "cmConfigure.h" + +#include <string> + #include "cmCPackDragNDropGenerator.h" +#include "cmCPackGenerator.h" /** \class cmCPackBundleGenerator * \brief A generator for OSX bundles @@ -29,10 +24,12 @@ public: virtual ~cmCPackBundleGenerator(); protected: - virtual int InitializeInternal(); - virtual const char* GetPackagingInstallPrefix(); - int PackageFiles(); - bool SupportsComponentInstallation() const; + int InitializeInternal() CM_OVERRIDE; + const char* GetPackagingInstallPrefix() CM_OVERRIDE; + int ConstructBundle(); + int SignBundle(const std::string& src_dir); + int PackageFiles() CM_OVERRIDE; + bool SupportsComponentInstallation() const CM_OVERRIDE; std::string InstallPrefix; }; diff --git a/Source/CPack/cmCPackComponentGroup.cxx b/Source/CPack/cmCPackComponentGroup.cxx index f93eca823..e39398ad5 100644 --- a/Source/CPack/cmCPackComponentGroup.cxx +++ b/Source/CPack/cmCPackComponentGroup.cxx @@ -1,44 +1,33 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCPackComponentGroup.h" + #include "cmSystemTools.h" -#include <vector> + #include <string> +#include <vector> -//---------------------------------------------------------------------- -unsigned long cmCPackComponent::GetInstalledSize(const char* installDir) const +unsigned long cmCPackComponent::GetInstalledSize( + const std::string& installDir) const { - if (this->TotalSize != 0) - { + if (this->TotalSize != 0) { return this->TotalSize; - } + } std::vector<std::string>::const_iterator fileIt; - for (fileIt = this->Files.begin(); fileIt != this->Files.end(); ++fileIt) - { + for (fileIt = this->Files.begin(); fileIt != this->Files.end(); ++fileIt) { std::string path = installDir; path += '/'; path += *fileIt; - this->TotalSize += cmSystemTools::FileLength(path.c_str()); - } + this->TotalSize += cmSystemTools::FileLength(path); + } return this->TotalSize; } -//---------------------------------------------------------------------- -unsigned long -cmCPackComponent::GetInstalledSizeInKbytes(const char* installDir) const +unsigned long cmCPackComponent::GetInstalledSizeInKbytes( + const std::string& installDir) const { unsigned long result = (GetInstalledSize(installDir) + 512) / 1024; - return result? result : 1; + return result ? result : 1; } diff --git a/Source/CPack/cmCPackComponentGroup.h b/Source/CPack/cmCPackComponentGroup.h index abae3724e..26d69ba68 100644 --- a/Source/CPack/cmCPackComponentGroup.h +++ b/Source/CPack/cmCPackComponentGroup.h @@ -1,19 +1,12 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc. - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #ifndef cmCPackComponentGroup_h #define cmCPackComponentGroup_h -#include "cmStandardIncludes.h" +#include "cmConfigure.h" + +#include <string> +#include <vector> class cmCPackComponentGroup; @@ -42,9 +35,15 @@ public: class cmCPackComponent { public: - cmCPackComponent() : Group(0), IsRequired(true), IsHidden(false), - IsDisabledByDefault(false), IsDownloaded(false), - TotalSize(0) { } + cmCPackComponent() + : Group(CM_NULLPTR) + , IsRequired(true) + , IsHidden(false) + , IsDisabledByDefault(false) + , IsDownloaded(false) + , TotalSize(0) + { + } /// The name of the component (used to reference the component). std::string Name; @@ -53,7 +52,7 @@ public: std::string DisplayName; /// The component group that contains this component (if any). - cmCPackComponentGroup *Group; + cmCPackComponentGroup* Group; /// Whether this component group must always be installed. bool IsRequired : 1; @@ -73,17 +72,21 @@ public: std::string Description; /// The installation types that this component is a part of. - std::vector<cmCPackInstallationType *> InstallationTypes; + std::vector<cmCPackInstallationType*> InstallationTypes; /// If IsDownloaded is true, the name of the archive file that /// contains the files that are part of this component. std::string ArchiveFile; + /// The file to pass to --component-plist when using the + /// productbuild generator. + std::string Plist; + /// The components that this component depends on. - std::vector<cmCPackComponent *> Dependencies; + std::vector<cmCPackComponent*> Dependencies; /// The components that depend on this component. - std::vector<cmCPackComponent *> ReverseDependencies; + std::vector<cmCPackComponent*> ReverseDependencies; /// The list of installed files that are part of this component. std::vector<std::string> Files; @@ -94,13 +97,13 @@ public: /// Get the total installed size of all of the files in this /// component, in bytes. installDir is the directory into which the /// component was installed. - unsigned long GetInstalledSize(const char* installDir) const; + unsigned long GetInstalledSize(const std::string& installDir) const; /// Identical to GetInstalledSize, but returns the result in /// kilobytes. - unsigned long GetInstalledSizeInKbytes(const char* installDir) const; + unsigned long GetInstalledSizeInKbytes(const std::string& installDir) const; - private: +private: mutable unsigned long TotalSize; }; @@ -110,7 +113,10 @@ public: class cmCPackComponentGroup { public: - cmCPackComponentGroup() : ParentGroup(0) { } + cmCPackComponentGroup() + : ParentGroup(CM_NULLPTR) + { + } /// The name of the group (used to reference the group). std::string Name; @@ -131,7 +137,7 @@ public: std::vector<cmCPackComponent*> Components; /// The parent group of this component group (if any). - cmCPackComponentGroup *ParentGroup; + cmCPackComponentGroup* ParentGroup; /// The subgroups of this group. std::vector<cmCPackComponentGroup*> Subgroups; diff --git a/Source/CPack/cmCPackConfigure.h.in b/Source/CPack/cmCPackConfigure.h.in index 3d7702e1a..8ac1661ec 100644 --- a/Source/CPack/cmCPackConfigure.h.in +++ b/Source/CPack/cmCPackConfigure.h.in @@ -1,11 +1,2 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ diff --git a/Source/CPack/cmCPackCygwinBinaryGenerator.cxx b/Source/CPack/cmCPackCygwinBinaryGenerator.cxx index 6605f16e0..2119f782b 100644 --- a/Source/CPack/cmCPackCygwinBinaryGenerator.cxx +++ b/Source/CPack/cmCPackCygwinBinaryGenerator.cxx @@ -1,38 +1,24 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCPackCygwinBinaryGenerator.h" -#include "cmake.h" +#include "cmCPackLog.h" +#include "cmGeneratedFileStream.h" #include "cmGlobalGenerator.h" -#include "cmLocalGenerator.h" -#include "cmSystemTools.h" #include "cmMakefile.h" -#include "cmGeneratedFileStream.h" -#include "cmCPackLog.h" +#include "cmSystemTools.h" +#include "cmake.h" -#include <cmsys/SystemTools.hxx> +#include "cmsys/SystemTools.hxx" -//---------------------------------------------------------------------- cmCPackCygwinBinaryGenerator::cmCPackCygwinBinaryGenerator() { } -//---------------------------------------------------------------------- cmCPackCygwinBinaryGenerator::~cmCPackCygwinBinaryGenerator() { } -//---------------------------------------------------------------------- int cmCPackCygwinBinaryGenerator::InitializeInternal() { this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/usr"); @@ -40,7 +26,6 @@ int cmCPackCygwinBinaryGenerator::InitializeInternal() return this->Superclass::InitializeInternal(); } -//---------------------------------------------------------------------- int cmCPackCygwinBinaryGenerator::PackageFiles() { std::string packageName = this->GetOption("CPACK_PACKAGE_NAME"); @@ -50,8 +35,7 @@ int cmCPackCygwinBinaryGenerator::PackageFiles() std::string manifest = "/usr/share/doc/"; manifest += packageName; manifest += "/MANIFEST"; - std::string manifestFile - = this->GetOption("CPACK_TEMPORARY_DIRECTORY"); + std::string manifestFile = this->GetOption("CPACK_TEMPORARY_DIRECTORY"); // Create a MANIFEST file that contains all of the files in // the tar file std::string tempdir = manifestFile; @@ -59,14 +43,13 @@ int cmCPackCygwinBinaryGenerator::PackageFiles() // create an extra scope to force the stream // to create the file before the super class is called { - cmGeneratedFileStream ofs(manifestFile.c_str()); - for(std::vector<std::string>::const_iterator i = files.begin(); - i != files.end(); ++i) - { - // remove the temp dir and replace with /usr - ofs << (*i).substr(tempdir.size()) << "\n"; + cmGeneratedFileStream ofs(manifestFile.c_str()); + for (std::vector<std::string>::const_iterator i = files.begin(); + i != files.end(); ++i) { + // remove the temp dir and replace with /usr + ofs << (*i).substr(tempdir.size()) << "\n"; } - ofs << manifest << "\n"; + ofs << manifest << "\n"; } // add the manifest file to the list of all files files.push_back(manifestFile); @@ -78,14 +61,13 @@ int cmCPackCygwinBinaryGenerator::PackageFiles() const char* cmCPackCygwinBinaryGenerator::GetOutputExtension() { this->OutputExtension = "-"; - const char* patchNumber =this->GetOption("CPACK_CYGWIN_PATCH_NUMBER"); - if(!patchNumber) - { + const char* patchNumber = this->GetOption("CPACK_CYGWIN_PATCH_NUMBER"); + if (!patchNumber) { patchNumber = "1"; cmCPackLogger(cmCPackLog::LOG_WARNING, "CPACK_CYGWIN_PATCH_NUMBER not specified using 1" - << std::endl); - } + << std::endl); + } this->OutputExtension += patchNumber; this->OutputExtension += ".tar.bz2"; return this->OutputExtension.c_str(); diff --git a/Source/CPack/cmCPackCygwinBinaryGenerator.h b/Source/CPack/cmCPackCygwinBinaryGenerator.h index 38f6df17d..58e80bda7 100644 --- a/Source/CPack/cmCPackCygwinBinaryGenerator.h +++ b/Source/CPack/cmCPackCygwinBinaryGenerator.h @@ -1,15 +1,5 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc. - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #ifndef cmCPackCygwinBinaryGenerator_h #define cmCPackCygwinBinaryGenerator_h @@ -28,6 +18,7 @@ public: */ cmCPackCygwinBinaryGenerator(); virtual ~cmCPackCygwinBinaryGenerator(); + protected: virtual int InitializeInternal(); int PackageFiles(); diff --git a/Source/CPack/cmCPackCygwinSourceGenerator.cxx b/Source/CPack/cmCPackCygwinSourceGenerator.cxx index f1e8539b9..2c289f668 100644 --- a/Source/CPack/cmCPackCygwinSourceGenerator.cxx +++ b/Source/CPack/cmCPackCygwinSourceGenerator.cxx @@ -1,58 +1,43 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCPackCygwinSourceGenerator.h" -#include "cmake.h" +#include "cmCPackLog.h" +#include "cmGeneratedFileStream.h" #include "cmGlobalGenerator.h" -#include "cmLocalGenerator.h" -#include "cmSystemTools.h" #include "cmMakefile.h" -#include "cmGeneratedFileStream.h" -#include "cmCPackLog.h" +#include "cmSystemTools.h" +#include "cmake.h" -#include <cmsys/SystemTools.hxx> +#include "cmsys/SystemTools.hxx" // Includes needed for implementation of RenameFile. This is not in // system tools because it is not implemented robustly enough to move // files across directories. #ifdef _WIN32 -# include <windows.h> -# include <sys/stat.h> +#include "cm_sys_stat.h" +#include <windows.h> #endif -//---------------------------------------------------------------------- cmCPackCygwinSourceGenerator::cmCPackCygwinSourceGenerator() { } -//---------------------------------------------------------------------- cmCPackCygwinSourceGenerator::~cmCPackCygwinSourceGenerator() { } -//---------------------------------------------------------------------- int cmCPackCygwinSourceGenerator::InitializeInternal() { this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0"); return this->Superclass::InitializeInternal(); } -//---------------------------------------------------------------------- int cmCPackCygwinSourceGenerator::PackageFiles() { // Create a tar file of the sources - std::string packageDirFileName - = this->GetOption("CPACK_TEMPORARY_DIRECTORY"); + std::string packageDirFileName = + this->GetOption("CPACK_TEMPORARY_DIRECTORY"); packageDirFileName += ".tar.bz2"; packageFileNames[0] = packageDirFileName; std::string output; @@ -60,10 +45,9 @@ int cmCPackCygwinSourceGenerator::PackageFiles() // to create tar.bz2 file with the list of source // files this->Compress = cmArchiveWrite::CompressBZip2; - if ( !this->cmCPackTarBZip2Generator::PackageFiles() ) - { + if (!this->cmCPackTarBZip2Generator::PackageFiles()) { return 0; - } + } // Now create a tar file that contains the above .tar.bz2 file // and the CPACK_CYGWIN_PATCH_FILE and CPACK_TOPLEVEL_DIRECTORY // files @@ -81,47 +65,41 @@ int cmCPackCygwinSourceGenerator::PackageFiles() // to the toplevel cpack temp dir // copy the patch file into place - if(!this->GetOption("CPACK_CYGWIN_PATCH_FILE")) - { + if (!this->GetOption("CPACK_CYGWIN_PATCH_FILE")) { cmCPackLogger(cmCPackLog::LOG_ERROR, "No patch file specified for cygwin sources."); return 0; - } - if(!cmSystemTools::CopyFileAlways( - this->GetOption("CPACK_CYGWIN_PATCH_FILE"), - this->GetOption("CPACK_TOPLEVEL_DIRECTORY"))) - { + } + if (!cmSystemTools::CopyFileAlways( + this->GetOption("CPACK_CYGWIN_PATCH_FILE"), + this->GetOption("CPACK_TOPLEVEL_DIRECTORY"))) { cmCPackLogger(cmCPackLog::LOG_ERROR, "problem copying: [" - << this->GetOption("CPACK_CYGWIN_PATCH_FILE") << "]\nto\n[" - << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "]\n"); + << this->GetOption("CPACK_CYGWIN_PATCH_FILE") << "]\nto\n[" + << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "]\n"); return 0; - } - if(!this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT")) - { + } + if (!this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT")) { cmCPackLogger(cmCPackLog::LOG_ERROR, "No build script specified for cygwin sources."); return 0; - } + } // copy the build script into place - if(!cmSystemTools::CopyFileAlways( - this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT"), - this->GetOption("CPACK_TOPLEVEL_DIRECTORY"))) - { + if (!cmSystemTools::CopyFileAlways( + this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT"), + this->GetOption("CPACK_TOPLEVEL_DIRECTORY"))) { cmCPackLogger(cmCPackLog::LOG_ERROR, "problem copying: " - << this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT") << "\nto\n" - << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "]\n"); + << this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT") << "\nto\n" + << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "]\n"); return 0; - } - std::string outerTarFile - = this->GetOption("CPACK_TEMPORARY_DIRECTORY"); + } + std::string outerTarFile = this->GetOption("CPACK_TEMPORARY_DIRECTORY"); outerTarFile += "-"; const char* patch = this->GetOption("CPACK_CYGWIN_PATCH_NUMBER"); - if(!patch) - { + if (!patch) { cmCPackLogger(cmCPackLog::LOG_WARNING, "CPACK_CYGWIN_PATCH_NUMBER" - << " not specified, defaulting to 1\n"); + << " not specified, defaulting to 1\n"); patch = "1"; - } + } outerTarFile += patch; outerTarFile += "-src.tar.bz2"; std::string tmpDir = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); @@ -131,8 +109,8 @@ int cmCPackCygwinSourceGenerator::PackageFiles() this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT")); std::string patchFile = tmpDir; patchFile += "/"; - patchFile += cmSystemTools::GetFilenameName( - this->GetOption("CPACK_CYGWIN_PATCH_FILE")); + patchFile += + cmSystemTools::GetFilenameName(this->GetOption("CPACK_CYGWIN_PATCH_FILE")); std::string file = cmSystemTools::GetFilenameName(compressOutFile); std::string sourceTar = cmSystemTools::GetFilenamePath(compressOutFile); @@ -151,10 +129,9 @@ int cmCPackCygwinSourceGenerator::PackageFiles() packageFileNames[0] = outerTarFile; /* update the toplevel dir */ toplevel = tmpDir; - if ( !this->cmCPackTarBZip2Generator::PackageFiles() ) - { + if (!this->cmCPackTarBZip2Generator::PackageFiles()) { return 0; - } + } return 1; } @@ -169,14 +146,12 @@ const char* cmCPackCygwinSourceGenerator::GetOutputExtension() { this->OutputExtension = "-"; const char* patch = this->GetOption("CPACK_CYGWIN_PATCH_NUMBER"); - if(!patch) - { + if (!patch) { cmCPackLogger(cmCPackLog::LOG_WARNING, "CPACK_CYGWIN_PATCH_NUMBER" - << " not specified, defaulting to 1\n"); + << " not specified, defaulting to 1\n"); patch = "1"; - } + } this->OutputExtension += patch; this->OutputExtension += "-src.tar.bz2"; return this->OutputExtension.c_str(); } - diff --git a/Source/CPack/cmCPackCygwinSourceGenerator.h b/Source/CPack/cmCPackCygwinSourceGenerator.h index 9d98a9b95..896de1d3e 100644 --- a/Source/CPack/cmCPackCygwinSourceGenerator.h +++ b/Source/CPack/cmCPackCygwinSourceGenerator.h @@ -1,15 +1,5 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc. - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #ifndef cmCPackCygwinSourceGenerator_h #define cmCPackCygwinSourceGenerator_h @@ -28,6 +18,7 @@ public: */ cmCPackCygwinSourceGenerator(); virtual ~cmCPackCygwinSourceGenerator(); + protected: const char* GetPackagingInstallPrefix(); virtual int InitializeInternal(); diff --git a/Source/CPack/cmCPackDebGenerator.cxx b/Source/CPack/cmCPackDebGenerator.cxx index 4494e8a18..af54fce33 100644 --- a/Source/CPack/cmCPackDebGenerator.cxx +++ b/Source/CPack/cmCPackDebGenerator.cxx @@ -1,25 +1,23 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCPackDebGenerator.h" -#include "cmSystemTools.h" -#include "cmMakefile.h" -#include "cmGeneratedFileStream.h" +#include "cmArchiveWrite.h" +#include "cmCPackComponentGroup.h" +#include "cmCPackGenerator.h" #include "cmCPackLog.h" +#include "cmGeneratedFileStream.h" +#include "cmSystemTools.h" +#include "cm_sys_stat.h" -#include <cmsys/SystemTools.hxx> -#include <cmsys/Glob.hxx> - -#include <limits.h> // USHRT_MAX +#include "cmsys/Glob.hxx" +#include <limits.h> +#include <map> +#include <ostream> +#include <set> +#include <stdio.h> +#include <string.h> +#include <utility> // NOTE: // A debian package .deb is simply an 'ar' archive. The only subtle difference @@ -27,91 +25,85 @@ // a GNU ar. // See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=161593 for more info // Therefore we provide our own implementation of a BSD-ar: -static int ar_append(const char*archive,const std::vector<std::string>& files); +static int ar_append(const char* archive, + const std::vector<std::string>& files); -//---------------------------------------------------------------------- cmCPackDebGenerator::cmCPackDebGenerator() { } -//---------------------------------------------------------------------- cmCPackDebGenerator::~cmCPackDebGenerator() { } -//---------------------------------------------------------------------- int cmCPackDebGenerator::InitializeInternal() { this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/usr"); - if (cmSystemTools::IsOff(this->GetOption("CPACK_SET_DESTDIR"))) - { + if (cmSystemTools::IsOff(this->GetOption("CPACK_SET_DESTDIR"))) { this->SetOption("CPACK_SET_DESTDIR", "I_ON"); - } + } return this->Superclass::InitializeInternal(); } -//---------------------------------------------------------------------- -int cmCPackDebGenerator::PackageOnePack(std::string initialTopLevel, - std::string packageName) - { +int cmCPackDebGenerator::PackageOnePack(std::string const& initialTopLevel, + std::string const& packageName) +{ int retval = 1; // Begin the archive for this pack std::string localToplevel(initialTopLevel); - std::string packageFileName( - cmSystemTools::GetParentDirectory(toplevel.c_str()) - ); + std::string packageFileName(cmSystemTools::GetParentDirectory(toplevel)); std::string outputFileName( - std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME")) - +"-"+packageName + this->GetOutputExtension() - ); + std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME")) + "-" + + packageName + this->GetOutputExtension()); - localToplevel += "/"+ packageName; + localToplevel += "/" + packageName; /* replace the TEMP DIRECTORY with the component one */ - this->SetOption("CPACK_TEMPORARY_DIRECTORY",localToplevel.c_str()); - packageFileName += "/"+ outputFileName; + this->SetOption("CPACK_TEMPORARY_DIRECTORY", localToplevel.c_str()); + packageFileName += "/" + outputFileName; /* replace proposed CPACK_OUTPUT_FILE_NAME */ - this->SetOption("CPACK_OUTPUT_FILE_NAME",outputFileName.c_str()); + this->SetOption("CPACK_OUTPUT_FILE_NAME", outputFileName.c_str()); /* replace the TEMPORARY package file name */ this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME", - packageFileName.c_str()); + packageFileName.c_str()); // Tell CPackDeb.cmake the name of the component GROUP. - this->SetOption("CPACK_DEB_PACKAGE_COMPONENT",packageName.c_str()); + this->SetOption("CPACK_DEB_PACKAGE_COMPONENT", packageName.c_str()); // Tell CPackDeb.cmake the path where the component is. std::string component_path = "/"; component_path += packageName; this->SetOption("CPACK_DEB_PACKAGE_COMPONENT_PART_PATH", component_path.c_str()); - if (!this->ReadListFile("CPackDeb.cmake")) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error while execution CPackDeb.cmake" << std::endl); + if (!this->ReadListFile("CPackDeb.cmake")) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Error while execution CPackDeb.cmake" + << std::endl); retval = 0; return retval; - } + } cmsys::Glob gl; - std::string findExpr(this->GetOption("WDIR")); + std::string findExpr(this->GetOption("GEN_WDIR")); findExpr += "/*"; gl.RecurseOn(); - if ( !gl.FindFiles(findExpr) ) - { + gl.SetRecurseListDirs(true); + if (!gl.FindFiles(findExpr)) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Cannot find any files in the installed directory" << std::endl); + "Cannot find any files in the installed directory" + << std::endl); return 0; - } + } packageFiles = gl.GetFiles(); int res = createDeb(); - if (res != 1) - { + if (res != 1) { retval = 0; - } + } // add the generated package to package file names list + packageFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); + packageFileName += "/"; + packageFileName += this->GetOption("GEN_CPACK_OUTPUT_FILE_NAME"); packageFileNames.push_back(packageFileName); return retval; } -//---------------------------------------------------------------------- int cmCPackDebGenerator::PackageComponents(bool ignoreGroup) { int retval = 1; @@ -122,461 +114,576 @@ int cmCPackDebGenerator::PackageComponents(bool ignoreGroup) // The default behavior is to have one package by component group // unless CPACK_COMPONENTS_IGNORE_GROUP is specified. - if (!ignoreGroup) - { + if (!ignoreGroup) { std::map<std::string, cmCPackComponentGroup>::iterator compGIt; - for (compGIt=this->ComponentGroups.begin(); - compGIt!=this->ComponentGroups.end(); ++compGIt) - { + for (compGIt = this->ComponentGroups.begin(); + compGIt != this->ComponentGroups.end(); ++compGIt) { cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Packaging component group: " - << compGIt->first - << std::endl); + << compGIt->first << std::endl); // Begin the archive for this group - retval &= PackageOnePack(initialTopLevel,compGIt->first); - } + retval &= PackageOnePack(initialTopLevel, compGIt->first); + } // Handle Orphan components (components not belonging to any groups) std::map<std::string, cmCPackComponent>::iterator compIt; - for (compIt=this->Components.begin(); - compIt!=this->Components.end(); ++compIt ) - { + for (compIt = this->Components.begin(); compIt != this->Components.end(); + ++compIt) { // Does the component belong to a group? - if (compIt->second.Group==NULL) - { - cmCPackLogger(cmCPackLog::LOG_VERBOSE, - "Component <" + if (compIt->second.Group == CM_NULLPTR) { + cmCPackLogger( + cmCPackLog::LOG_VERBOSE, "Component <" << compIt->second.Name << "> does not belong to any group, package it separately." << std::endl); // Begin the archive for this orphan component - retval &= PackageOnePack(initialTopLevel,compIt->first); - } + retval &= PackageOnePack(initialTopLevel, compIt->first); } } + } // CPACK_COMPONENTS_IGNORE_GROUPS is set // We build 1 package per component - else - { + else { std::map<std::string, cmCPackComponent>::iterator compIt; - for (compIt=this->Components.begin(); - compIt!=this->Components.end(); ++compIt ) - { - retval &= PackageOnePack(initialTopLevel,compIt->first); - } + for (compIt = this->Components.begin(); compIt != this->Components.end(); + ++compIt) { + retval &= PackageOnePack(initialTopLevel, compIt->first); } + } return retval; } //---------------------------------------------------------------------- -int cmCPackDebGenerator::PackageComponentsAllInOne() +int cmCPackDebGenerator::PackageComponentsAllInOne( + const std::string& compInstDirName) { int retval = 1; - std::string compInstDirName; /* Reset package file name list it will be populated during the * component packaging run*/ packageFileNames.clear(); std::string initialTopLevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY")); - compInstDirName = "ALL_COMPONENTS_IN_ONE"; - cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Packaging all groups in one package..." "(CPACK_COMPONENTS_ALL_[GROUPS_]IN_ONE_PACKAGE is set)" - << std::endl); + << std::endl); // The ALL GROUPS in ONE package case std::string localToplevel(initialTopLevel); - std::string packageFileName( - cmSystemTools::GetParentDirectory(toplevel.c_str()) - ); + std::string packageFileName(cmSystemTools::GetParentDirectory(toplevel)); std::string outputFileName( - std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME")) - + this->GetOutputExtension() - ); + std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME")) + + this->GetOutputExtension()); // all GROUP in one vs all COMPONENT in one - localToplevel += "/"+compInstDirName; + // if must be here otherwise non component paths have a trailing / while + // components don't + if (!compInstDirName.empty()) { + localToplevel += "/" + compInstDirName; + } /* replace the TEMP DIRECTORY with the component one */ - this->SetOption("CPACK_TEMPORARY_DIRECTORY",localToplevel.c_str()); - packageFileName += "/"+ outputFileName; + this->SetOption("CPACK_TEMPORARY_DIRECTORY", localToplevel.c_str()); + packageFileName += "/" + outputFileName; /* replace proposed CPACK_OUTPUT_FILE_NAME */ - this->SetOption("CPACK_OUTPUT_FILE_NAME",outputFileName.c_str()); + this->SetOption("CPACK_OUTPUT_FILE_NAME", outputFileName.c_str()); /* replace the TEMPORARY package file name */ this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME", - packageFileName.c_str()); - // Tell CPackDeb.cmake the path where the component is. - std::string component_path = "/"; - component_path += compInstDirName; - this->SetOption("CPACK_DEB_PACKAGE_COMPONENT_PART_PATH", - component_path.c_str()); - if (!this->ReadListFile("CPackDeb.cmake")) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error while execution CPackDeb.cmake" << std::endl); + packageFileName.c_str()); + + if (!compInstDirName.empty()) { + // Tell CPackDeb.cmake the path where the component is. + std::string component_path = "/"; + component_path += compInstDirName; + this->SetOption("CPACK_DEB_PACKAGE_COMPONENT_PART_PATH", + component_path.c_str()); + } + if (!this->ReadListFile("CPackDeb.cmake")) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Error while execution CPackDeb.cmake" + << std::endl); retval = 0; return retval; - } + } cmsys::Glob gl; - std::string findExpr(this->GetOption("WDIR")); + std::string findExpr(this->GetOption("GEN_WDIR")); findExpr += "/*"; gl.RecurseOn(); - if ( !gl.FindFiles(findExpr) ) - { + gl.SetRecurseListDirs(true); + if (!gl.FindFiles(findExpr)) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Cannot find any files in the installed directory" << std::endl); + "Cannot find any files in the installed directory" + << std::endl); return 0; - } + } packageFiles = gl.GetFiles(); int res = createDeb(); - if (res != 1) - { + if (res != 1) { retval = 0; - } + } // add the generated package to package file names list + packageFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); + packageFileName += "/"; + packageFileName += this->GetOption("GEN_CPACK_OUTPUT_FILE_NAME"); packageFileNames.push_back(packageFileName); return retval; } -//---------------------------------------------------------------------- int cmCPackDebGenerator::PackageFiles() { - int retval = -1; - /* Are we in the component packaging case */ if (WantsComponentInstallation()) { // CASE 1 : COMPONENT ALL-IN-ONE package // If ALL GROUPS or ALL COMPONENTS in ONE package has been requested // then the package file is unique and should be open here. - if (componentPackageMethod == ONE_PACKAGE) - { - return PackageComponentsAllInOne(); - } + if (componentPackageMethod == ONE_PACKAGE) { + return PackageComponentsAllInOne("ALL_COMPONENTS_IN_ONE"); + } // CASE 2 : COMPONENT CLASSICAL package(s) (i.e. not all-in-one) // There will be 1 package for each component group // however one may require to ignore component group and // in this case you'll get 1 package for each component. - else - { - return PackageComponents(componentPackageMethod == - ONE_PACKAGE_PER_COMPONENT); - } + return PackageComponents(componentPackageMethod == + ONE_PACKAGE_PER_COMPONENT); } // CASE 3 : NON COMPONENT package. - else - { - if (!this->ReadListFile("CPackDeb.cmake")) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error while execution CPackDeb.cmake" << std::endl); - retval = 0; - } - else - { - packageFiles = files; - return createDeb(); - } - } - return retval; + return PackageComponentsAllInOne(""); } int cmCPackDebGenerator::createDeb() { - const char* cmakeExecutable = this->GetOption("CMAKE_COMMAND"); - // debian-binary file - std::string dbfilename; - dbfilename += this->GetOption("WDIR"); - dbfilename += "/debian-binary"; - { // the scope is needed for cmGeneratedFileStream + const std::string strGenWDIR(this->GetOption("GEN_WDIR")); + const std::string dbfilename = strGenWDIR + "/debian-binary"; + { // the scope is needed for cmGeneratedFileStream cmGeneratedFileStream out(dbfilename.c_str()); out << "2.0"; out << std::endl; // required for valid debian package - } + } // control file - std::string ctlfilename; - ctlfilename = this->GetOption("WDIR"); - ctlfilename += "/control"; + std::string ctlfilename = strGenWDIR + "/control"; // debian policy enforce lower case for package name // mandatory entries: std::string debian_pkg_name = cmsys::SystemTools::LowerCase( - this->GetOption("CPACK_DEBIAN_PACKAGE_NAME") ); + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_NAME")); const char* debian_pkg_version = - this->GetOption("CPACK_DEBIAN_PACKAGE_VERSION"); + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_VERSION"); const char* debian_pkg_section = - this->GetOption("CPACK_DEBIAN_PACKAGE_SECTION"); + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_SECTION"); const char* debian_pkg_priority = - this->GetOption("CPACK_DEBIAN_PACKAGE_PRIORITY"); + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_PRIORITY"); const char* debian_pkg_arch = - this->GetOption("CPACK_DEBIAN_PACKAGE_ARCHITECTURE"); - const char* maintainer = this->GetOption("CPACK_DEBIAN_PACKAGE_MAINTAINER"); - const char* desc = this->GetOption("CPACK_DEBIAN_PACKAGE_DESCRIPTION"); + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_ARCHITECTURE"); + const char* maintainer = + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_MAINTAINER"); + const char* desc = this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_DESCRIPTION"); // optional entries - const char* debian_pkg_dep = this->GetOption("CPACK_DEBIAN_PACKAGE_DEPENDS"); + const char* debian_pkg_dep = + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_DEPENDS"); const char* debian_pkg_rec = - this->GetOption("CPACK_DEBIAN_PACKAGE_RECOMMENDS"); + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_RECOMMENDS"); const char* debian_pkg_sug = - this->GetOption("CPACK_DEBIAN_PACKAGE_SUGGESTS"); + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_SUGGESTS"); const char* debian_pkg_url = - this->GetOption("CPACK_DEBIAN_PACKAGE_HOMEPAGE"); + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_HOMEPAGE"); const char* debian_pkg_predep = - this->GetOption("CPACK_DEBIAN_PACKAGE_PREDEPENDS"); + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_PREDEPENDS"); const char* debian_pkg_enhances = - this->GetOption("CPACK_DEBIAN_PACKAGE_ENHANCES"); + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_ENHANCES"); const char* debian_pkg_breaks = - this->GetOption("CPACK_DEBIAN_PACKAGE_BREAKS"); + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_BREAKS"); const char* debian_pkg_conflicts = - this->GetOption("CPACK_DEBIAN_PACKAGE_CONFLICTS"); + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_CONFLICTS"); const char* debian_pkg_provides = - this->GetOption("CPACK_DEBIAN_PACKAGE_PROVIDES"); + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_PROVIDES"); const char* debian_pkg_replaces = - this->GetOption("CPACK_DEBIAN_PACKAGE_REPLACES"); + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_REPLACES"); + const char* debian_pkg_source = + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_SOURCE"); - { // the scope is needed for cmGeneratedFileStream + { // the scope is needed for cmGeneratedFileStream cmGeneratedFileStream out(ctlfilename.c_str()); out << "Package: " << debian_pkg_name << "\n"; out << "Version: " << debian_pkg_version << "\n"; out << "Section: " << debian_pkg_section << "\n"; out << "Priority: " << debian_pkg_priority << "\n"; out << "Architecture: " << debian_pkg_arch << "\n"; - if(debian_pkg_dep && *debian_pkg_dep) - { + if (debian_pkg_source && *debian_pkg_source) { + out << "Source: " << debian_pkg_source << "\n"; + } + if (debian_pkg_dep && *debian_pkg_dep) { out << "Depends: " << debian_pkg_dep << "\n"; - } - if(debian_pkg_rec && *debian_pkg_rec) - { + } + if (debian_pkg_rec && *debian_pkg_rec) { out << "Recommends: " << debian_pkg_rec << "\n"; - } - if(debian_pkg_sug && *debian_pkg_sug) - { + } + if (debian_pkg_sug && *debian_pkg_sug) { out << "Suggests: " << debian_pkg_sug << "\n"; - } - if(debian_pkg_url && *debian_pkg_url) - { + } + if (debian_pkg_url && *debian_pkg_url) { out << "Homepage: " << debian_pkg_url << "\n"; - } - if (debian_pkg_predep && *debian_pkg_predep) - { + } + if (debian_pkg_predep && *debian_pkg_predep) { out << "Pre-Depends: " << debian_pkg_predep << "\n"; - } - if (debian_pkg_enhances && *debian_pkg_enhances) - { + } + if (debian_pkg_enhances && *debian_pkg_enhances) { out << "Enhances: " << debian_pkg_enhances << "\n"; - } - if (debian_pkg_breaks && *debian_pkg_breaks) - { + } + if (debian_pkg_breaks && *debian_pkg_breaks) { out << "Breaks: " << debian_pkg_breaks << "\n"; - } - if (debian_pkg_conflicts && *debian_pkg_conflicts) - { + } + if (debian_pkg_conflicts && *debian_pkg_conflicts) { out << "Conflicts: " << debian_pkg_conflicts << "\n"; - } - if (debian_pkg_provides && *debian_pkg_provides) - { + } + if (debian_pkg_provides && *debian_pkg_provides) { out << "Provides: " << debian_pkg_provides << "\n"; - } - if (debian_pkg_replaces && *debian_pkg_replaces) - { + } + if (debian_pkg_replaces && *debian_pkg_replaces) { out << "Replaces: " << debian_pkg_replaces << "\n"; - } + } unsigned long totalSize = 0; { std::string dirName = this->GetOption("CPACK_TEMPORARY_DIRECTORY"); dirName += '/'; - for (std::vector<std::string>::const_iterator fileIt = - packageFiles.begin(); - fileIt != packageFiles.end(); ++ fileIt ) - { - totalSize += cmSystemTools::FileLength(fileIt->c_str()); - } + for (std::vector<std::string>::const_iterator fileIt = + packageFiles.begin(); + fileIt != packageFiles.end(); ++fileIt) { + totalSize += cmSystemTools::FileLength(*fileIt); + } } out << "Installed-Size: " << (totalSize + 1023) / 1024 << "\n"; out << "Maintainer: " << maintainer << "\n"; out << "Description: " << desc << "\n"; out << std::endl; + } + + const std::string shlibsfilename = strGenWDIR + "/shlibs"; + + const char* debian_pkg_shlibs = + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_SHLIBS"); + const bool gen_shibs = this->IsOn("CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS") && + debian_pkg_shlibs && *debian_pkg_shlibs; + if (gen_shibs) { + cmGeneratedFileStream out(shlibsfilename.c_str()); + out << debian_pkg_shlibs; + out << std::endl; + } + + const std::string postinst = strGenWDIR + "/postinst"; + const std::string postrm = strGenWDIR + "/postrm"; + if (this->IsOn("GEN_CPACK_DEBIAN_GENERATE_POSTINST")) { + cmGeneratedFileStream out(postinst.c_str()); + out << "#!/bin/sh\n\n" + "set -e\n\n" + "if [ \"$1\" = \"configure\" ]; then\n" + "\tldconfig\n" + "fi\n"; + } + if (this->IsOn("GEN_CPACK_DEBIAN_GENERATE_POSTRM")) { + cmGeneratedFileStream out(postrm.c_str()); + out << "#!/bin/sh\n\n" + "set -e\n\n" + "if [ \"$1\" = \"remove\" ]; then\n" + "\tldconfig\n" + "fi\n"; + } + + cmArchiveWrite::Compress tar_compression_type = cmArchiveWrite::CompressGZip; + const char* debian_compression_type = + this->GetOption("GEN_CPACK_DEBIAN_COMPRESSION_TYPE"); + if (!debian_compression_type) { + debian_compression_type = "gzip"; + } + + std::string compression_suffix; + if (!strcmp(debian_compression_type, "lzma")) { + compression_suffix = ".lzma"; + tar_compression_type = cmArchiveWrite::CompressLZMA; + } else if (!strcmp(debian_compression_type, "xz")) { + compression_suffix = ".xz"; + tar_compression_type = cmArchiveWrite::CompressXZ; + } else if (!strcmp(debian_compression_type, "bzip2")) { + compression_suffix = ".bz2"; + tar_compression_type = cmArchiveWrite::CompressBZip2; + } else if (!strcmp(debian_compression_type, "gzip")) { + compression_suffix = ".gz"; + tar_compression_type = cmArchiveWrite::CompressGZip; + } else if (!strcmp(debian_compression_type, "none")) { + compression_suffix = ""; + tar_compression_type = cmArchiveWrite::CompressNone; + } else { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Error unrecognized compression type: " + << debian_compression_type << std::endl); + } + + const char* debian_archive_type = + this->GetOption("GEN_CPACK_DEBIAN_ARCHIVE_TYPE"); + if (!debian_archive_type) { + debian_archive_type = "paxr"; + } + + std::string filename_data_tar = + strGenWDIR + "/data.tar" + compression_suffix; + + // atomic file generation for data.tar + { + cmGeneratedFileStream fileStream_data_tar; + fileStream_data_tar.Open(filename_data_tar.c_str(), false, true); + if (!fileStream_data_tar) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Error opening the file \"" + << filename_data_tar << "\" for writing" << std::endl); + return 0; } + cmArchiveWrite data_tar(fileStream_data_tar, tar_compression_type, + debian_archive_type); + + // uid/gid should be the one of the root user, and this root user has + // always uid/gid equal to 0. + data_tar.SetUIDAndGID(0u, 0u); + data_tar.SetUNAMEAndGNAME("root", "root"); + + // now add all directories which have to be compressed + // collect all top level install dirs for that + // e.g. /opt/bin/foo, /usr/bin/bar and /usr/bin/baz would + // give /usr and /opt + size_t topLevelLength = strGenWDIR.length(); + cmCPackLogger(cmCPackLog::LOG_DEBUG, "WDIR: \"" + << strGenWDIR << "\", length = " << topLevelLength + << std::endl); + std::set<std::string> orderedFiles; + + // we have to reconstruct the parent folders as well - std::string cmd; - if (NULL != this->GetOption("CPACK_DEBIAN_FAKEROOT_EXECUTABLE")) { - cmd += this->GetOption("CPACK_DEBIAN_FAKEROOT_EXECUTABLE"); - } - cmd += " \""; - cmd += cmakeExecutable; - cmd += "\" -E tar cfz data.tar.gz "; - - // now add all directories which have to be compressed - // collect all top level install dirs for that - // e.g. /opt/bin/foo, /usr/bin/bar and /usr/bin/baz would give /usr and /opt - size_t topLevelLength = std::string(this->GetOption("WDIR")).length(); - cmCPackLogger(cmCPackLog::LOG_DEBUG, "WDIR: \"" << this->GetOption("WDIR") - << "\", length = " << topLevelLength - << std::endl); - std::set<std::string> installDirs; for (std::vector<std::string>::const_iterator fileIt = - packageFiles.begin(); - fileIt != packageFiles.end(); ++ fileIt ) - { - cmCPackLogger(cmCPackLog::LOG_DEBUG, "FILEIT: \"" << *fileIt << "\"" - << std::endl); - std::string::size_type slashPos = fileIt->find('/', topLevelLength+1); - std::string relativeDir = fileIt->substr(topLevelLength, - slashPos - topLevelLength); - cmCPackLogger(cmCPackLog::LOG_DEBUG, "RELATIVEDIR: \"" << relativeDir - << "\"" << std::endl); - if (installDirs.find(relativeDir) == installDirs.end()) - { - installDirs.insert(relativeDir); - cmd += " ."; - cmd += relativeDir; + packageFiles.begin(); + fileIt != packageFiles.end(); ++fileIt) { + std::string currentPath = *fileIt; + while (currentPath != strGenWDIR) { + // the last one IS strGenWDIR, but we do not want this one: + // XXX/application/usr/bin/myprogram with GEN_WDIR=XXX/application + // should not add XXX/application + orderedFiles.insert(currentPath); + currentPath = cmSystemTools::CollapseCombinedPath(currentPath, ".."); } } - std::string output; - int retval = -1; - int res = cmSystemTools::RunSingleCommand(cmd.c_str(), &output, - &retval, this->GetOption("WDIR"), this->GeneratorVerbose, 0); - - if ( !res || retval ) - { - std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); - tmpFile += "/Deb.log"; - cmGeneratedFileStream ofs(tmpFile.c_str()); - ofs << "# Run command: " << cmd.c_str() << std::endl - << "# Working directory: " << toplevel << std::endl - << "# Output:" << std::endl - << output.c_str() << std::endl; - cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running tar command: " - << cmd.c_str() << std::endl - << "Please check " << tmpFile.c_str() << " for errors" << std::endl); - return 0; + for (std::set<std::string>::const_iterator fileIt = orderedFiles.begin(); + fileIt != orderedFiles.end(); ++fileIt) { + cmCPackLogger(cmCPackLog::LOG_DEBUG, "FILEIT: \"" << *fileIt << "\"" + << std::endl); + std::string::size_type slashPos = fileIt->find('/', topLevelLength + 1); + std::string relativeDir = + fileIt->substr(topLevelLength, slashPos - topLevelLength); + cmCPackLogger(cmCPackLog::LOG_DEBUG, "RELATIVEDIR: \"" + << relativeDir << "\"" << std::endl); + + // do not recurse because the loop will do it + if (!data_tar.Add(*fileIt, topLevelLength, ".", false)) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem adding file to tar:" + << std::endl + << "#top level directory: " << strGenWDIR << std::endl + << "#file: " << *fileIt << std::endl + << "#error:" << data_tar.GetError() << std::endl); + return 0; + } } + } // scope for file generation - std::string md5filename; - md5filename = this->GetOption("WDIR"); - md5filename += "/md5sums"; - - { // the scope is needed for cmGeneratedFileStream + std::string md5filename = strGenWDIR + "/md5sums"; + { + // the scope is needed for cmGeneratedFileStream cmGeneratedFileStream out(md5filename.c_str()); - std::vector<std::string>::const_iterator fileIt; -// std::string topLevelWithTrailingSlash = toplevel; + std::string topLevelWithTrailingSlash = - this->GetOption("CPACK_TEMPORARY_DIRECTORY"); + this->GetOption("CPACK_TEMPORARY_DIRECTORY"); topLevelWithTrailingSlash += '/'; - for ( fileIt = packageFiles.begin(); - fileIt != packageFiles.end(); ++ fileIt ) - { - cmd = "\""; - cmd += cmakeExecutable; - cmd += "\" -E md5sum \""; - cmd += *fileIt; - cmd += "\""; - //std::string output; - //int retVal = -1; - res = cmSystemTools::RunSingleCommand(cmd.c_str(), &output, - &retval, toplevel.c_str(), this->GeneratorVerbose, 0); + for (std::vector<std::string>::const_iterator fileIt = + packageFiles.begin(); + fileIt != packageFiles.end(); ++fileIt) { + // hash only regular files + if (cmSystemTools::FileIsDirectory(*fileIt) || + cmSystemTools::FileIsSymlink(*fileIt)) { + continue; + } + + char md5sum[33]; + if (!cmSystemTools::ComputeFileMD5(*fileIt, md5sum)) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem computing the md5 of " + << *fileIt << std::endl); + } + + md5sum[32] = 0; + + std::string output(md5sum); + output += " " + *fileIt + "\n"; // debian md5sums entries are like this: // 014f3604694729f3bf19263bac599765 usr/bin/ccmake // thus strip the full path (with the trailing slash) - cmSystemTools::ReplaceString(output, - topLevelWithTrailingSlash.c_str(), ""); + cmSystemTools::ReplaceString(output, topLevelWithTrailingSlash.c_str(), + ""); out << output; - } + } // each line contains a eol. // Do not end the md5sum file with yet another (invalid) + } + + std::string filename_control_tar = strGenWDIR + "/control.tar.gz"; + // atomic file generation for control.tar + { + cmGeneratedFileStream fileStream_control_tar; + fileStream_control_tar.Open(filename_control_tar.c_str(), false, true); + if (!fileStream_control_tar) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Error opening the file \"" + << filename_control_tar << "\" for writing" + << std::endl); + return 0; + } + cmArchiveWrite control_tar(fileStream_control_tar, + cmArchiveWrite::CompressGZip, + debian_archive_type); + + // sets permissions and uid/gid for the files + control_tar.SetUIDAndGID(0u, 0u); + control_tar.SetUNAMEAndGNAME("root", "root"); + + /* permissions are set according to + https://www.debian.org/doc/debian-policy/ch-files.html#s-permissions-owners + and + https://lintian.debian.org/tags/control-file-has-bad-permissions.html + */ + const mode_t permission644 = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; + const mode_t permissionExecute = S_IXUSR | S_IXGRP | S_IXOTH; + const mode_t permission755 = permission644 | permissionExecute; + + // for md5sum and control (that we have generated here), we use 644 + // (RW-R--R--) + // so that deb lintian doesn't warn about it + control_tar.SetPermissions(permission644); + + // adds control and md5sums + if (!control_tar.Add(md5filename, strGenWDIR.length(), ".") || + !control_tar.Add(strGenWDIR + "/control", strGenWDIR.length(), ".")) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Error adding file to tar:" + << std::endl + << "#top level directory: " << strGenWDIR << std::endl + << "#file: \"control\" or \"md5sums\"" << std::endl + << "#error:" << control_tar.GetError() << std::endl); + return 0; } - cmd = ""; - if (NULL != this->GetOption("CPACK_DEBIAN_FAKEROOT_EXECUTABLE")) - { - cmd = this->GetOption("CPACK_DEBIAN_FAKEROOT_EXECUTABLE"); + // adds generated shlibs file + if (gen_shibs) { + if (!control_tar.Add(shlibsfilename, strGenWDIR.length(), ".")) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Error adding file to tar:" + << std::endl + << "#top level directory: " << strGenWDIR << std::endl + << "#file: \"shlibs\"" << std::endl + << "#error:" << control_tar.GetError() << std::endl); + return 0; } - cmd += " \""; - cmd += cmakeExecutable; - cmd += "\" -E tar cfz control.tar.gz ./control ./md5sums"; - const char* controlExtra = - this->GetOption("CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA"); - if( controlExtra ) - { - std::vector<std::string> controlExtraList; - cmSystemTools::ExpandListArgument(controlExtra, controlExtraList); - for(std::vector<std::string>::iterator i = - controlExtraList.begin(); i != controlExtraList.end(); ++i) - { - std::string filenamename = - cmsys::SystemTools::GetFilenameName(i->c_str()); - std::string localcopy = this->GetOption("WDIR"); - localcopy += "/"; - localcopy += filenamename; - // if we can copy the file, it means it does exist, let's add it: - if( cmsys::SystemTools::CopyFileIfDifferent( - i->c_str(), localcopy.c_str()) ) - { - // debian is picky and need relative to ./ path in the tar.gz - cmd += " ./"; - cmd += filenamename; - } + } + + // adds LDCONFIG related files + if (this->IsOn("GEN_CPACK_DEBIAN_GENERATE_POSTINST")) { + control_tar.SetPermissions(permission755); + if (!control_tar.Add(postinst, strGenWDIR.length(), ".")) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Error adding file to tar:" + << std::endl + << "#top level directory: " << strGenWDIR << std::endl + << "#file: \"postinst\"" << std::endl + << "#error:" << control_tar.GetError() << std::endl); + return 0; } + control_tar.SetPermissions(permission644); } - res = cmSystemTools::RunSingleCommand(cmd.c_str(), &output, - &retval, this->GetOption("WDIR"), this->GeneratorVerbose, 0); - if ( !res || retval ) - { - std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); - tmpFile += "/Deb.log"; - cmGeneratedFileStream ofs(tmpFile.c_str()); - ofs << "# Run command: " << cmd.c_str() << std::endl - << "# Working directory: " << toplevel << std::endl - << "# Output:" << std::endl - << output.c_str() << std::endl; - cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running tar command: " - << cmd.c_str() << std::endl - << "Please check " << tmpFile.c_str() << " for errors" << std::endl); - return 0; + if (this->IsOn("GEN_CPACK_DEBIAN_GENERATE_POSTRM")) { + control_tar.SetPermissions(permission755); + if (!control_tar.Add(postrm, strGenWDIR.length(), ".")) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Error adding file to tar:" + << std::endl + << "#top level directory: " << strGenWDIR << std::endl + << "#file: \"postinst\"" << std::endl + << "#error:" << control_tar.GetError() << std::endl); + return 0; + } + control_tar.SetPermissions(permission644); } - // ar -r your-package-name.deb debian-binary control.tar.gz data.tar.gz + // for the other files, we use + // -either the original permission on the files + // -either a permission strictly defined by the Debian policies + const char* controlExtra = + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA"); + if (controlExtra) { + // permissions are now controlled by the original file permissions + + const bool permissionStrictPolicy = + this->IsSet("GEN_CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION"); + + static const char* strictFiles[] = { "config", "postinst", "postrm", + "preinst", "prerm" }; + std::set<std::string> setStrictFiles( + strictFiles, + strictFiles + sizeof(strictFiles) / sizeof(strictFiles[0])); + + // default + control_tar.ClearPermissions(); + + std::vector<std::string> controlExtraList; + cmSystemTools::ExpandListArgument(controlExtra, controlExtraList); + for (std::vector<std::string>::iterator i = controlExtraList.begin(); + i != controlExtraList.end(); ++i) { + std::string filenamename = cmsys::SystemTools::GetFilenameName(*i); + std::string localcopy = strGenWDIR + "/" + filenamename; + + if (permissionStrictPolicy) { + control_tar.SetPermissions(setStrictFiles.count(filenamename) + ? permission755 + : permission644); + } + + // if we can copy the file, it means it does exist, let's add it: + if (cmsys::SystemTools::CopyFileIfDifferent(*i, localcopy)) { + control_tar.Add(localcopy, strGenWDIR.length(), "."); + } + } + } + } + + // ar -r your-package-name.deb debian-binary control.tar.* data.tar.* // since debian packages require BSD ar (most Linux distros and even // FreeBSD and NetBSD ship GNU ar) we use a copy of OpenBSD ar here. std::vector<std::string> arFiles; - std::string topLevelString = this->GetOption("WDIR"); - topLevelString += "/"; + std::string topLevelString = strGenWDIR + "/"; arFiles.push_back(topLevelString + "debian-binary"); arFiles.push_back(topLevelString + "control.tar.gz"); - arFiles.push_back(topLevelString + "data.tar.gz"); - std::string outputFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); - outputFileName += "/"; - outputFileName += this->GetOption("CPACK_OUTPUT_FILE_NAME"); - res = ar_append(outputFileName.c_str(), arFiles); - if ( res!=0 ) - { - std::string tmpFile = this->GetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME"); + arFiles.push_back(topLevelString + "data.tar" + compression_suffix); + std::string outputFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); + outputFileName += "/"; + outputFileName += this->GetOption("GEN_CPACK_OUTPUT_FILE_NAME"); + int res = ar_append(outputFileName.c_str(), arFiles); + if (res != 0) { + std::string tmpFile = + this->GetOption("GEN_CPACK_TEMPORARY_PACKAGE_FILE_NAME"); tmpFile += "/Deb.log"; cmGeneratedFileStream ofs(tmpFile.c_str()); ofs << "# Problem creating archive using: " << res << std::endl; return 0; - } + } return 1; } bool cmCPackDebGenerator::SupportsComponentInstallation() const - { - if (IsOn("CPACK_DEB_COMPONENT_INSTALL")) - { - return true; - } - else - { - return false; - } - } +{ + return IsOn("CPACK_DEB_COMPONENT_INSTALL"); +} std::string cmCPackDebGenerator::GetComponentInstallDirNameSuffix( - const std::string& componentName) - { + const std::string& componentName) +{ if (componentPackageMethod == ONE_PACKAGE_PER_COMPONENT) { return componentName; } @@ -586,18 +693,13 @@ std::string cmCPackDebGenerator::GetComponentInstallDirNameSuffix( } // We have to find the name of the COMPONENT GROUP // the current COMPONENT belongs to. - std::string groupVar = "CPACK_COMPONENT_" + - cmSystemTools::UpperCase(componentName) + "_GROUP"; - if (NULL != GetOption(groupVar.c_str())) - { - return std::string(GetOption(groupVar.c_str())); - } - else - { - return componentName; - } + std::string groupVar = + "CPACK_COMPONENT_" + cmSystemTools::UpperCase(componentName) + "_GROUP"; + if (CM_NULLPTR != GetOption(groupVar)) { + return std::string(GetOption(groupVar)); } - + return componentName; +} // The following code is taken from OpenBSD ar: // http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ar/ @@ -640,65 +742,61 @@ std::string cmCPackDebGenerator::GetComponentInstallDirNameSuffix( * SUCH DAMAGE. */ -#include <sys/types.h> -#include <sys/stat.h> - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> - -#define ARMAG "!<arch>\n" /* ar "magic number" */ -#define SARMAG 8 /* strlen(ARMAG); */ +#define ARMAG "!<arch>\n" /* ar "magic number" */ +#define SARMAG 8 /* strlen(ARMAG); */ -#define AR_EFMT1 "#1/" /* extended format #1 */ -#define ARFMAG "`\n" +#define AR_EFMT1 "#1/" /* extended format #1 */ +#define ARFMAG "`\n" /* Header format strings. */ -#define HDR1 "%s%-13d%-12ld%-6u%-6u%-8o%-10lld%2s" -#define HDR2 "%-16.16s%-12ld%-6u%-6u%-8o%-10lld%2s" - -struct ar_hdr { - char ar_name[16]; /* name */ - char ar_date[12]; /* modification time */ - char ar_uid[6]; /* user id */ - char ar_gid[6]; /* group id */ - char ar_mode[8]; /* octal file permissions */ - char ar_size[10]; /* size in bytes */ - char ar_fmag[2]; /* consistency check */ +#define HDR1 "%s%-13d%-12ld%-6u%-6u%-8o%-10lld%2s" +#define HDR2 "%-16.16s%-12ld%-6u%-6u%-8o%-10lld%2s" + +struct ar_hdr +{ + char ar_name[16]; /* name */ + char ar_date[12]; /* modification time */ + char ar_uid[6]; /* user id */ + char ar_gid[6]; /* group id */ + char ar_mode[8]; /* octal file permissions */ + char ar_size[10]; /* size in bytes */ + char ar_fmag[2]; /* consistency check */ }; /* Set up file copy. */ -#define SETCF(from, fromname, to, toname, pad) { \ - cf.rFile = from; \ - cf.rname = fromname; \ - cf.wFile = to; \ - cf.wname = toname; \ - cf.flags = pad; \ -} +#define SETCF(from, fromname, to, toname, pad) \ + { \ + cf.rFile = from; \ + cf.rname = fromname; \ + cf.wFile = to; \ + cf.wname = toname; \ + cf.flags = pad; \ + } /* File copy structure. */ -typedef struct { - FILE* rFile; /* read file descriptor */ - const char *rname; /* read name */ - FILE* wFile; /* write file descriptor */ - const char *wname; /* write name */ -#define NOPAD 0x00 /* don't pad */ -#define WPAD 0x02 /* pad on writes */ - unsigned int flags; /* pad flags */ +typedef struct +{ + FILE* rFile; /* read file descriptor */ + const char* rname; /* read name */ + FILE* wFile; /* write file descriptor */ + const char* wname; /* write name */ +#define NOPAD 0x00 /* don't pad */ +#define WPAD 0x02 /* pad on writes */ + unsigned int flags; /* pad flags */ } CF; /* misc.c */ -static const char * ar_rname(const char *path) +static const char* ar_rname(const char* path) { - const char *ind = strrchr(path, '/'); - return (ind ) ? ind + 1 : path; + const char* ind = strrchr(path, '/'); + return (ind) ? ind + 1 : path; } /* archive.c */ typedef struct ar_hdr HDR; -static char ar_hb[sizeof(HDR) + 1]; /* real header */ +static char ar_hb[sizeof(HDR) + 1]; /* real header */ static size_t ar_already_written; @@ -715,80 +813,88 @@ static size_t ar_already_written; * because 16-bit word addressed copies were faster?) Anyhow, it should * have been ripped out long ago. */ -static int copy_ar(CF *cfp, off_t size) +static int copy_ar(CF* cfp, off_t size) { static char pad = '\n'; off_t sz = size; size_t nr, nw; - char buf[8*1024]; + char buf[8 * 1024]; - if (sz == 0) + if (sz == 0) { return 0; + } FILE* from = cfp->rFile; FILE* to = cfp->wFile; while (sz && - (nr = fread(buf, 1, sz < static_cast<off_t>(sizeof(buf)) - ? static_cast<size_t>(sz) : sizeof(buf), from )) - > 0) { + (nr = fread(buf, 1, sz < static_cast<off_t>(sizeof(buf)) + ? static_cast<size_t>(sz) + : sizeof(buf), + from)) > 0) { sz -= nr; - for (size_t off = 0; off < nr; nr -= off, off += nw) - if ((nw = fwrite(buf + off, 1, nr, to)) < nr) + for (size_t off = 0; off < nr; nr -= off, off += nw) { + if ((nw = fwrite(buf + off, 1, nr, to)) < nr) { return -1; + } } - if (sz) + } + if (sz) { return -2; + } - if (cfp->flags & WPAD && (size + ar_already_written) & 1 - && fwrite(&pad, 1, 1, to) != 1) + if (cfp->flags & WPAD && (size + ar_already_written) & 1 && + fwrite(&pad, 1, 1, to) != 1) { return -4; + } return 0; } /* put_arobj -- Write an archive member to a file. */ -static int put_arobj(CF *cfp, struct stat *sb) +static int put_arobj(CF* cfp, struct stat* sb) { int result = 0; - struct ar_hdr *hdr; + struct ar_hdr* hdr; - /* If passed an sb structure, reading a file from disk. Get stat(2) - * information, build a name and construct a header. (Files are named - * by their last component in the archive.) */ + /* If passed an sb structure, reading a file from disk. Get stat(2) + * information, build a name and construct a header. (Files are named + * by their last component in the archive.) */ const char* name = ar_rname(cfp->rname); (void)stat(cfp->rname, sb); - /* If not truncating names and the name is too long or contains - * a space, use extended format 1. */ + /* If not truncating names and the name is too long or contains + * a space, use extended format 1. */ size_t lname = strlen(name); uid_t uid = sb->st_uid; gid_t gid = sb->st_gid; if (uid > USHRT_MAX) { uid = USHRT_MAX; - } + } if (gid > USHRT_MAX) { gid = USHRT_MAX; - } - if (lname > sizeof(hdr->ar_name) || strchr(name, ' ')) - (void)sprintf(ar_hb, HDR1, AR_EFMT1, (int)lname, - (long int)sb->st_mtime, (unsigned)uid, (unsigned)gid, - sb->st_mode, (long long)sb->st_size + lname, ARFMAG); - else { - lname = 0; - (void)sprintf(ar_hb, HDR2, name, - (long int)sb->st_mtime, (unsigned)uid, (unsigned)gid, - sb->st_mode, (long long)sb->st_size, ARFMAG); - } - off_t size = sb->st_size; + } + if (lname > sizeof(hdr->ar_name) || strchr(name, ' ')) { + (void)sprintf(ar_hb, HDR1, AR_EFMT1, (int)lname, (long int)sb->st_mtime, + (unsigned)uid, (unsigned)gid, (unsigned)sb->st_mode, + (long long)sb->st_size + lname, ARFMAG); + } else { + lname = 0; + (void)sprintf(ar_hb, HDR2, name, (long int)sb->st_mtime, (unsigned)uid, + (unsigned)gid, (unsigned)sb->st_mode, (long long)sb->st_size, + ARFMAG); + } + off_t size = sb->st_size; - if (fwrite(ar_hb, 1, sizeof(HDR), cfp->wFile) != sizeof(HDR)) + if (fwrite(ar_hb, 1, sizeof(HDR), cfp->wFile) != sizeof(HDR)) { return -1; + } if (lname) { - if (fwrite(name, 1, lname, cfp->wFile) != lname) + if (fwrite(name, 1, lname, cfp->wFile) != lname) { return -2; - ar_already_written = lname; } + ar_already_written = lname; + } result = copy_ar(cfp, size); ar_already_written = 0; return result; @@ -800,42 +906,41 @@ static int put_arobj(CF *cfp, struct stat *sb) * Append files to the archive - modifies original archive or creates * a new archive if named archive does not exist. */ -static int ar_append(const char* archive,const std::vector<std::string>& files) +static int ar_append(const char* archive, + const std::vector<std::string>& files) { int eval = 0; - FILE* aFile = fopen(archive, "wb+"); - if (aFile!=NULL) { + FILE* aFile = cmSystemTools::Fopen(archive, "wb+"); + if (aFile != CM_NULLPTR) { fwrite(ARMAG, SARMAG, 1, aFile); if (fseek(aFile, 0, SEEK_END) != -1) { CF cf; struct stat sb; /* Read from disk, write to an archive; pad on write. */ - SETCF(NULL, 0, aFile, archive, WPAD); - for(std::vector<std::string>::const_iterator fileIt = files.begin(); - fileIt!=files.end(); ++fileIt) { + SETCF(CM_NULLPTR, CM_NULLPTR, aFile, archive, WPAD); + for (std::vector<std::string>::const_iterator fileIt = files.begin(); + fileIt != files.end(); ++fileIt) { const char* filename = fileIt->c_str(); - FILE* file = fopen(filename, "rb"); - if (file == NULL) { + FILE* file = cmSystemTools::Fopen(filename, "rb"); + if (file == CM_NULLPTR) { eval = -1; continue; - } + } cf.rFile = file; cf.rname = filename; int result = put_arobj(&cf, &sb); (void)fclose(file); - if (result!=0) { + if (result != 0) { eval = -2; break; - } } } - else { - eval = -3; - } - fclose(aFile); + } else { + eval = -3; } - else { + fclose(aFile); + } else { eval = -4; - } + } return eval; } diff --git a/Source/CPack/cmCPackDebGenerator.h b/Source/CPack/cmCPackDebGenerator.h index d678cfacf..e7cde1145 100644 --- a/Source/CPack/cmCPackDebGenerator.h +++ b/Source/CPack/cmCPackDebGenerator.h @@ -1,21 +1,15 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc. - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #ifndef cmCPackDebGenerator_h #define cmCPackDebGenerator_h +#include "cmConfigure.h" #include "cmCPackGenerator.h" +#include <string> +#include <vector> + /** \class cmCPackDebGenerator * \brief A generator for Debian packages * @@ -29,28 +23,29 @@ public: * Construct generator */ cmCPackDebGenerator(); - virtual ~cmCPackDebGenerator(); + ~cmCPackDebGenerator() CM_OVERRIDE; static bool CanGenerate() - { + { #ifdef __APPLE__ // on MacOS enable CPackDeb iff dpkg is found std::vector<std::string> locations; locations.push_back("/sw/bin"); // Fink locations.push_back("/opt/local/bin"); // MacPorts - return cmSystemTools::FindProgram("dpkg",locations) != "" ? true : false; + return cmSystemTools::FindProgram("dpkg", locations) != "" ? true : false; #else // legacy behavior on other systems return true; #endif - } + } protected: - virtual int InitializeInternal(); + int InitializeInternal() CM_OVERRIDE; /** * This method factors out the work done in component packaging case. */ - int PackageOnePack(std::string initialToplevel, std::string packageName); + int PackageOnePack(std::string const& initialToplevel, + std::string const& packageName); /** * The method used to package files when component * install is used. This will create one @@ -61,17 +56,16 @@ protected: * Special case of component install where all * components will be put in a single installer. */ - int PackageComponentsAllInOne(); - virtual int PackageFiles(); - virtual const char* GetOutputExtension() { return ".deb"; } - virtual bool SupportsComponentInstallation() const; - virtual std::string GetComponentInstallDirNameSuffix( - const std::string& componentName); + int PackageComponentsAllInOne(const std::string& compInstDirName); + int PackageFiles() CM_OVERRIDE; + const char* GetOutputExtension() CM_OVERRIDE { return ".deb"; } + bool SupportsComponentInstallation() const CM_OVERRIDE; + std::string GetComponentInstallDirNameSuffix( + const std::string& componentName) CM_OVERRIDE; private: int createDeb(); std::vector<std::string> packageFiles; - }; #endif diff --git a/Source/CPack/cmCPackDocumentMacros.cxx b/Source/CPack/cmCPackDocumentMacros.cxx deleted file mode 100644 index ddc75a4b4..000000000 --- a/Source/CPack/cmCPackDocumentMacros.cxx +++ /dev/null @@ -1,16 +0,0 @@ -#include "cmCPackDocumentMacros.h" - -void cmCPackDocumentMacros::GetMacrosDocumentation( - std::vector<cmDocumentationEntry>& ) -{ - // Commented-out example of use - // - // cmDocumentationEntry e("cpack_<macro>", - // "Brief Description" - // "which may be on several lines.", - // "Long description in pre-formatted format" - // " blah\n" - // " blah\n" - //); - //v.push_back(e); -} diff --git a/Source/CPack/cmCPackDocumentMacros.h b/Source/CPack/cmCPackDocumentMacros.h deleted file mode 100644 index 544f74f5f..000000000 --- a/Source/CPack/cmCPackDocumentMacros.h +++ /dev/null @@ -1,21 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ -#ifndef cmCPackDocumentMacros_h -#define cmCPackDocumentMacros_h -#include "cmStandardIncludes.h" -class cmCPackDocumentMacros -{ -public: - static void GetMacrosDocumentation(std::vector<cmDocumentationEntry>& v); -}; - -#endif diff --git a/Source/CPack/cmCPackDocumentVariables.cxx b/Source/CPack/cmCPackDocumentVariables.cxx deleted file mode 100644 index 8b16ae985..000000000 --- a/Source/CPack/cmCPackDocumentVariables.cxx +++ /dev/null @@ -1,122 +0,0 @@ -#include "cmCPackDocumentVariables.h" -#include "cmake.h" - -void cmCPackDocumentVariables::DefineVariables(cmake* cm) -{ - // Subsection: variables defined/used by cpack, - // which are common to all CPack generators - - cm->DefineProperty - ("CPACK_PACKAGING_INSTALL_PREFIX", cmProperty::VARIABLE, - "The prefix used in the built package.", - "Each CPack generator has a default value (like /usr)." - " This default value may" - " be overwritten from the CMakeLists.txt or the cpack command line" - " by setting an alternative value.\n" - "e.g. " - " set(CPACK_PACKAGING_INSTALL_PREFIX \"/opt\")\n" - "This is not the same purpose as CMAKE_INSTALL_PREFIX which" - " is used when installing from the build tree without building" - " a package." - "", false, - "Variables common to all CPack generators"); - - cm->DefineProperty - ("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", cmProperty::VARIABLE, - "Boolean toggle to include/exclude top level directory.", - "When preparing a package CPack installs the item under" - " the so-called top level directory. The purpose of" - " is to include (set to 1 or ON or TRUE) the top level directory" - " in the package or not (set to 0 or OFF or FALSE).\n" - "Each CPack generator has a built-in default value for this" - " variable. E.g. Archive generators (ZIP, TGZ, ...) includes" - " the top level whereas RPM or DEB don't. The user may override" - " the default value by setting this variable.\n" - "There is a similar variable " - "CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY " - "which may be used to override the behavior for the component" - " packaging case which may have different default value for" - " historical (now backward compatibility) reason.", false, - "Variables common to all CPack generators"); - - cm->DefineProperty - ("CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY", cmProperty::VARIABLE, - "Boolean toggle to include/exclude top level directory " - "(component case).", - "Similar usage as CPACK_INCLUDE_TOPLEVEL_DIRECTORY" - " but for the component case. " - "See CPACK_INCLUDE_TOPLEVEL_DIRECTORY documentation for" - " the detail.", false, - "Variables common to all CPack generators"); - - cm->DefineProperty - ("CPACK_SET_DESTDIR", cmProperty::VARIABLE, - "Boolean toggle to make CPack use DESTDIR mechanism when" - " packaging.", "DESTDIR means DESTination DIRectory." - " It is commonly used by makefile " - "users in order to install software at non-default location. It " - "is a basic relocation mechanism that should not be used on" - " Windows (see CMAKE_INSTALL_PREFIX documentation). " - "It is usually invoked like this:\n" - " make DESTDIR=/home/john install\n" - "which will install the concerned software using the" - " installation prefix, e.g. \"/usr/local\" prepended with " - "the DESTDIR value which finally gives \"/home/john/usr/local\"." - " When preparing a package, CPack first installs the items to be " - "packaged in a local (to the build tree) directory by using the " - "same DESTDIR mechanism. Nevertheless, if " - "CPACK_SET_DESTDIR is set then CPack will set DESTDIR before" - " doing the local install. The most noticeable difference is" - " that without CPACK_SET_DESTDIR, CPack uses " - "CPACK_PACKAGING_INSTALL_PREFIX as a prefix whereas with " - "CPACK_SET_DESTDIR set, CPack will use CMAKE_INSTALL_PREFIX as" - " a prefix.\n" - "Manually setting CPACK_SET_DESTDIR may help (or simply be" - " necessary) if some install rules uses absolute " - "DESTINATION (see CMake INSTALL command)." - " However, starting with" - " CPack/CMake 2.8.3 RPM and DEB installers tries to handle DESTDIR" - " automatically so that it is seldom necessary for the user to set" - " it.", false, - "Variables common to all CPack generators"); - - cm->DefineProperty - ("CPACK_INSTALL_SCRIPT", cmProperty::VARIABLE, - "Extra CMake script provided by the user.", - "If set this CMake script will be executed by CPack " - "during its local [CPack-private] installation " - "which is done right before packaging the files." - " The script is not called by e.g.: make install.", false, - "Variables common to all CPack generators"); - - cm->DefineProperty - ("CPACK_ABSOLUTE_DESTINATION_FILES", cmProperty::VARIABLE, - "List of files which have been installed using " - " an ABSOLUTE DESTINATION path.", - "This variable is a Read-Only variable which is set internally" - " by CPack during installation and before packaging using" - " CMAKE_ABSOLUTE_DESTINATION_FILES defined in cmake_install.cmake " - "scripts. The value can be used within CPack project configuration" - " file and/or CPack<GEN>.cmake file of <GEN> generator.", false, - "Variables common to all CPack generators"); - - cm->DefineProperty - ("CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION", cmProperty::VARIABLE, - "Ask CPack to warn each time a file with absolute INSTALL" - " DESTINATION is encountered.", - "This variable triggers the definition of " - "CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION when CPack runs" - " cmake_install.cmake scripts.", false, - "Variables common to all CPack generators"); - - cm->DefineProperty - ("CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION", cmProperty::VARIABLE, - "Ask CPack to error out as soon as a file with absolute INSTALL" - " DESTINATION is encountered.", - "The fatal error is emitted before the installation of " - "the offending file takes place. Some CPack generators, like NSIS," - "enforce this internally. " - "This variable triggers the definition of" - "CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION when CPack runs" - "Variables common to all CPack generators"); -} diff --git a/Source/CPack/cmCPackDocumentVariables.h b/Source/CPack/cmCPackDocumentVariables.h deleted file mode 100644 index e7971be13..000000000 --- a/Source/CPack/cmCPackDocumentVariables.h +++ /dev/null @@ -1,21 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ -#ifndef cmCPackDocumentVariables_h -#define cmCPackDocumentVariables_h -class cmake; -class cmCPackDocumentVariables -{ -public: - static void DefineVariables(cmake* cm); -}; - -#endif diff --git a/Source/CPack/cmCPackDragNDropGenerator.cxx b/Source/CPack/cmCPackDragNDropGenerator.cxx index d973c0134..d26d5bc1a 100644 --- a/Source/CPack/cmCPackDragNDropGenerator.cxx +++ b/Source/CPack/cmCPackDragNDropGenerator.cxx @@ -1,66 +1,70 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCPackDragNDropGenerator.h" + +#include "cmCPackGenerator.h" #include "cmCPackLog.h" -#include "cmSystemTools.h" #include "cmGeneratedFileStream.h" +#include "cmSystemTools.h" -#include <cmsys/RegularExpression.hxx> +#include "cmsys/FStream.hxx" +#include "cmsys/RegularExpression.hxx" +#include <algorithm> +#include <iomanip> +#include <map> +#include <stdlib.h> + +#include <CoreFoundation/CoreFoundation.h> + +#ifdef HAVE_CoreServices +// For the old LocaleStringToLangAndRegionCodes() function, to convert +// to the old Script Manager RegionCode values needed for the 'LPic' data +// structure used for generating multi-lingual SLAs. +#include <CoreServices/CoreServices.h> +#endif static const char* SLAHeader = -"data 'LPic' (5000) {\n" -" $\"0002 0011 0003 0001 0000 0000 0002 0000\"\n" -" $\"0008 0003 0000 0001 0004 0000 0004 0005\"\n" -" $\"0000 000E 0006 0001 0005 0007 0000 0007\"\n" -" $\"0008 0000 0047 0009 0000 0034 000A 0001\"\n" -" $\"0035 000B 0001 0020 000C 0000 0011 000D\"\n" -" $\"0000 005B 0004 0000 0033 000F 0001 000C\"\n" -" $\"0010 0000 000B 000E 0000\"\n" -"};\n" -"\n"; + "data 'LPic' (5000) {\n" + " $\"0002 0011 0003 0001 0000 0000 0002 0000\"\n" + " $\"0008 0003 0000 0001 0004 0000 0004 0005\"\n" + " $\"0000 000E 0006 0001 0005 0007 0000 0007\"\n" + " $\"0008 0000 0047 0009 0000 0034 000A 0001\"\n" + " $\"0035 000B 0001 0020 000C 0000 0011 000D\"\n" + " $\"0000 005B 0004 0000 0033 000F 0001 000C\"\n" + " $\"0010 0000 000B 000E 0000\"\n" + "};\n" + "\n"; static const char* SLASTREnglish = -"resource 'STR#' (5002, \"English\") {\n" -" {\n" -" \"English\",\n" -" \"Agree\",\n" -" \"Disagree\",\n" -" \"Print\",\n" -" \"Save...\",\n" -" \"You agree to the License Agreement terms when you click \"\n" -" \"the \\\"Agree\\\" button.\",\n" -" \"Software License Agreement\",\n" -" \"This text cannot be saved. This disk may be full or locked, " -"or the \"\n" -" \"file may be locked.\",\n" -" \"Unable to print. Make sure you have selected a printer.\"\n" -" }\n" -"};\n" -"\n"; - -//---------------------------------------------------------------------- + "resource 'STR#' (5002, \"English\") {\n" + " {\n" + " \"English\",\n" + " \"Agree\",\n" + " \"Disagree\",\n" + " \"Print\",\n" + " \"Save...\",\n" + " \"You agree to the License Agreement terms when you click \"\n" + " \"the \\\"Agree\\\" button.\",\n" + " \"Software License Agreement\",\n" + " \"This text cannot be saved. This disk may be full or locked, " + "or the \"\n" + " \"file may be locked.\",\n" + " \"Unable to print. Make sure you have selected a printer.\"\n" + " }\n" + "};\n" + "\n"; + cmCPackDragNDropGenerator::cmCPackDragNDropGenerator() + : singleLicense(false) { // default to one package file for components this->componentPackageMethod = ONE_PACKAGE; } -//---------------------------------------------------------------------- cmCPackDragNDropGenerator::~cmCPackDragNDropGenerator() { } -//---------------------------------------------------------------------- int cmCPackDragNDropGenerator::InitializeInternal() { // Starting with Xcode 4.3, look in "/Applications/Xcode.app" first: @@ -69,89 +73,125 @@ int cmCPackDragNDropGenerator::InitializeInternal() paths.push_back("/Applications/Xcode.app/Contents/Developer/Tools"); paths.push_back("/Developer/Tools"); - const std::string hdiutil_path = cmSystemTools::FindProgram("hdiutil", - std::vector<std::string>(), false); - if(hdiutil_path.empty()) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Cannot locate hdiutil command" - << std::endl); + const std::string hdiutil_path = + cmSystemTools::FindProgram("hdiutil", std::vector<std::string>(), false); + if (hdiutil_path.empty()) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot locate hdiutil command" + << std::endl); return 0; - } + } this->SetOptionIfNotSet("CPACK_COMMAND_HDIUTIL", hdiutil_path.c_str()); - const std::string setfile_path = cmSystemTools::FindProgram("SetFile", - paths, false); - if(setfile_path.empty()) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Cannot locate SetFile command" - << std::endl); + const std::string setfile_path = + cmSystemTools::FindProgram("SetFile", paths, false); + if (setfile_path.empty()) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot locate SetFile command" + << std::endl); return 0; - } + } this->SetOptionIfNotSet("CPACK_COMMAND_SETFILE", setfile_path.c_str()); - const std::string rez_path = cmSystemTools::FindProgram("Rez", - paths, false); - if(rez_path.empty()) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Cannot locate Rez command" - << std::endl); + const std::string rez_path = cmSystemTools::FindProgram("Rez", paths, false); + if (rez_path.empty()) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot locate Rez command" + << std::endl); return 0; - } + } this->SetOptionIfNotSet("CPACK_COMMAND_REZ", rez_path.c_str()); + if (this->IsSet("CPACK_DMG_SLA_DIR")) { + slaDirectory = this->GetOption("CPACK_DMG_SLA_DIR"); + if (!slaDirectory.empty() && this->IsSet("CPACK_RESOURCE_FILE_LICENSE")) { + std::string license_file = + this->GetOption("CPACK_RESOURCE_FILE_LICENSE"); + if (!license_file.empty() && + (license_file.find("CPack.GenericLicense.txt") == + std::string::npos)) { + cmCPackLogger( + cmCPackLog::LOG_OUTPUT, + "Both CPACK_DMG_SLA_DIR and CPACK_RESOURCE_FILE_LICENSE specified, " + "using CPACK_RESOURCE_FILE_LICENSE as a license for all languages." + << std::endl); + singleLicense = true; + } + } + if (!this->IsSet("CPACK_DMG_SLA_LANGUAGES")) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "CPACK_DMG_SLA_DIR set but no languages defined " + "(set CPACK_DMG_SLA_LANGUAGES)" + << std::endl); + return 0; + } + if (!cmSystemTools::FileExists(slaDirectory, false)) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "CPACK_DMG_SLA_DIR does not exist" + << std::endl); + return 0; + } + + std::vector<std::string> languages; + cmSystemTools::ExpandListArgument( + this->GetOption("CPACK_DMG_SLA_LANGUAGES"), languages); + if (languages.empty()) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "CPACK_DMG_SLA_LANGUAGES set but empty" << std::endl); + return 0; + } + for (size_t i = 0; i < languages.size(); ++i) { + std::string license = slaDirectory + "/" + languages[i] + ".license.txt"; + if (!singleLicense && !cmSystemTools::FileExists(license)) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Missing license file " + << languages[i] << ".license.txt" << std::endl); + return 0; + } + std::string menu = slaDirectory + "/" + languages[i] + ".menu.txt"; + if (!cmSystemTools::FileExists(menu)) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Missing menu file " + << languages[i] << ".menu.txt" << std::endl); + return 0; + } + } + } + return this->Superclass::InitializeInternal(); } -//---------------------------------------------------------------------- const char* cmCPackDragNDropGenerator::GetOutputExtension() { return ".dmg"; } -//---------------------------------------------------------------------- int cmCPackDragNDropGenerator::PackageFiles() { // gather which directories to make dmg files for // multiple directories occur if packaging components or groups separately // monolith - if(this->Components.empty()) - { + if (this->Components.empty()) { return this->CreateDMG(toplevel, packageFileNames[0]); - } + } // component install std::vector<std::string> package_files; std::map<std::string, cmCPackComponent>::iterator compIt; - for (compIt=this->Components.begin(); - compIt!=this->Components.end(); ++compIt ) - { + for (compIt = this->Components.begin(); compIt != this->Components.end(); + ++compIt) { std::string name = GetComponentInstallDirNameSuffix(compIt->first); package_files.push_back(name); - } + } std::sort(package_files.begin(), package_files.end()); - package_files.erase(std::unique(package_files.begin(), - package_files.end()), + package_files.erase(std::unique(package_files.begin(), package_files.end()), package_files.end()); - // loop to create dmg files packageFileNames.clear(); - for(size_t i=0; i<package_files.size(); i++) - { + for (size_t i = 0; i < package_files.size(); i++) { std::string full_package_name = std::string(toplevel) + std::string("/"); - if(package_files[i] == "ALL_IN_ONE") - { + if (package_files[i] == "ALL_IN_ONE") { full_package_name += this->GetOption("CPACK_PACKAGE_FILE_NAME"); - } - else - { + } else { full_package_name += package_files[i]; - } + } full_package_name += std::string(GetOutputExtension()); packageFileNames.push_back(full_package_name); @@ -159,385 +199,514 @@ int cmCPackDragNDropGenerator::PackageFiles() src_dir += "/"; src_dir += package_files[i]; - if(0 == this->CreateDMG(src_dir, full_package_name)) - { + if (0 == this->CreateDMG(src_dir, full_package_name)) { return 0; - } } + } return 1; } -//---------------------------------------------------------------------- -bool cmCPackDragNDropGenerator::CopyFile(cmOStringStream& source, - cmOStringStream& target) +bool cmCPackDragNDropGenerator::CopyFile(std::ostringstream& source, + std::ostringstream& target) { - if(!cmSystemTools::CopyFileIfDifferent( - source.str().c_str(), - target.str().c_str())) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error copying " - << source.str() - << " to " - << target.str() - << std::endl); + if (!cmSystemTools::CopyFileIfDifferent(source.str().c_str(), + target.str().c_str())) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Error copying " + << source.str() << " to " << target.str() << std::endl); return false; - } + } + + return true; +} + +bool cmCPackDragNDropGenerator::CreateEmptyFile(std::ostringstream& target, + size_t size) +{ + cmsys::ofstream fout(target.str().c_str(), std::ios::out | std::ios::binary); + if (!fout) { + return false; + } else { + // Seek to desired size - 1 byte + fout.seekp(size - 1, std::ios::beg); + char byte = 0; + // Write one byte to ensure file grows + fout.write(&byte, 1); + } return true; } -//---------------------------------------------------------------------- -bool cmCPackDragNDropGenerator::RunCommand(cmOStringStream& command, - std::string* output) +bool cmCPackDragNDropGenerator::RunCommand(std::ostringstream& command, + std::string* output) { int exit_code = 1; - bool result = cmSystemTools::RunSingleCommand( - command.str().c_str(), - output, - &exit_code, - 0, - this->GeneratorVerbose, - 0); + bool result = + cmSystemTools::RunSingleCommand(command.str().c_str(), output, output, + &exit_code, 0, this->GeneratorVerbose, 0); - if(!result || exit_code) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error executing: " - << command.str() - << std::endl); + if (!result || exit_code) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Error executing: " << command.str() + << std::endl); return false; - } + } return true; } -//---------------------------------------------------------------------- int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir, const std::string& output_file) { // Get optional arguments ... const std::string cpack_package_icon = this->GetOption("CPACK_PACKAGE_ICON") - ? this->GetOption("CPACK_PACKAGE_ICON") : ""; + ? this->GetOption("CPACK_PACKAGE_ICON") + : ""; const std::string cpack_dmg_volume_name = this->GetOption("CPACK_DMG_VOLUME_NAME") ? this->GetOption("CPACK_DMG_VOLUME_NAME") - : this->GetOption("CPACK_PACKAGE_FILE_NAME"); + : this->GetOption("CPACK_PACKAGE_FILE_NAME"); - const std::string cpack_dmg_format = - this->GetOption("CPACK_DMG_FORMAT") - ? this->GetOption("CPACK_DMG_FORMAT") : "UDZO"; + const std::string cpack_dmg_format = this->GetOption("CPACK_DMG_FORMAT") + ? this->GetOption("CPACK_DMG_FORMAT") + : "UDZO"; // Get optional arguments ... std::string cpack_license_file = - this->GetOption("CPACK_RESOURCE_FILE_LICENSE") ? - this->GetOption("CPACK_RESOURCE_FILE_LICENSE") : ""; + this->GetOption("CPACK_RESOURCE_FILE_LICENSE") + ? this->GetOption("CPACK_RESOURCE_FILE_LICENSE") + : ""; const std::string cpack_dmg_background_image = this->GetOption("CPACK_DMG_BACKGROUND_IMAGE") - ? this->GetOption("CPACK_DMG_BACKGROUND_IMAGE") : ""; + ? this->GetOption("CPACK_DMG_BACKGROUND_IMAGE") + : ""; - const std::string cpack_dmg_ds_store = - this->GetOption("CPACK_DMG_DS_STORE") - ? this->GetOption("CPACK_DMG_DS_STORE") : ""; + const std::string cpack_dmg_ds_store = this->GetOption("CPACK_DMG_DS_STORE") + ? this->GetOption("CPACK_DMG_DS_STORE") + : ""; + + const std::string cpack_dmg_languages = + this->GetOption("CPACK_DMG_SLA_LANGUAGES") + ? this->GetOption("CPACK_DMG_SLA_LANGUAGES") + : ""; + + const std::string cpack_dmg_ds_store_setup_script = + this->GetOption("CPACK_DMG_DS_STORE_SETUP_SCRIPT") + ? this->GetOption("CPACK_DMG_DS_STORE_SETUP_SCRIPT") + : ""; + + const bool cpack_dmg_disable_applications_symlink = + this->IsOn("CPACK_DMG_DISABLE_APPLICATIONS_SYMLINK"); // only put license on dmg if is user provided - if(!cpack_license_file.empty() && - cpack_license_file.find("CPack.GenericLicense.txt") != std::string::npos) - { + if (!cpack_license_file.empty() && + cpack_license_file.find("CPack.GenericLicense.txt") != + std::string::npos) { + cpack_license_file = ""; + } + + // use sla_dir if both sla_dir and license_file are set + if (!cpack_license_file.empty() && !slaDirectory.empty() && !singleLicense) { cpack_license_file = ""; } // The staging directory contains everything that will end-up inside the // final disk image ... - cmOStringStream staging; + std::ostringstream staging; staging << src_dir; // Add a symlink to /Applications so users can drag-and-drop the bundle - // into it - cmOStringStream application_link; - application_link << staging.str() << "/Applications"; - cmSystemTools::CreateSymlink("/Applications", - application_link.str().c_str()); + // into it unless this behaviour was disabled + if (!cpack_dmg_disable_applications_symlink) { + std::ostringstream application_link; + application_link << staging.str() << "/Applications"; + cmSystemTools::CreateSymlink("/Applications", application_link.str()); + } // Optionally add a custom volume icon ... - if(!cpack_package_icon.empty()) - { - cmOStringStream package_icon_source; + if (!cpack_package_icon.empty()) { + std::ostringstream package_icon_source; package_icon_source << cpack_package_icon; - cmOStringStream package_icon_destination; + std::ostringstream package_icon_destination; package_icon_destination << staging.str() << "/.VolumeIcon.icns"; - if(!this->CopyFile(package_icon_source, package_icon_destination)) - { + if (!this->CopyFile(package_icon_source, package_icon_destination)) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error copying disk volume icon. " + "Error copying disk volume icon. " "Check the value of CPACK_PACKAGE_ICON." - << std::endl); + << std::endl); return 0; - } } + } // Optionally add a custom .DS_Store file // (e.g. for setting background/layout) ... - if(!cpack_dmg_ds_store.empty()) - { - cmOStringStream package_settings_source; + if (!cpack_dmg_ds_store.empty()) { + std::ostringstream package_settings_source; package_settings_source << cpack_dmg_ds_store; - cmOStringStream package_settings_destination; + std::ostringstream package_settings_destination; package_settings_destination << staging.str() << "/.DS_Store"; - if(!this->CopyFile(package_settings_source, package_settings_destination)) - { + if (!this->CopyFile(package_settings_source, + package_settings_destination)) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error copying disk volume settings file. " + "Error copying disk volume settings file. " "Check the value of CPACK_DMG_DS_STORE." - << std::endl); + << std::endl); return 0; - } } + } // Optionally add a custom background image ... - if(!cpack_dmg_background_image.empty()) - { - cmOStringStream package_background_source; + // Make sure the background file type is the same as the custom image + // and that the file is hidden so it doesn't show up. + if (!cpack_dmg_background_image.empty()) { + const std::string extension = + cmSystemTools::GetFilenameLastExtension(cpack_dmg_background_image); + std::ostringstream package_background_source; package_background_source << cpack_dmg_background_image; - cmOStringStream package_background_destination; - package_background_destination << staging.str() << "/background.png"; + std::ostringstream package_background_destination; + package_background_destination << staging.str() + << "/.background/background" << extension; - if(!this->CopyFile(package_background_source, - package_background_destination)) - { + if (!this->CopyFile(package_background_source, + package_background_destination)) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error copying disk volume background image. " + "Error copying disk volume background image. " "Check the value of CPACK_DMG_BACKGROUND_IMAGE." - << std::endl); + << std::endl); return 0; - } + } + } - cmOStringStream temp_background_hiding_command; - temp_background_hiding_command << this->GetOption("CPACK_COMMAND_SETFILE"); - temp_background_hiding_command << " -a V \""; - temp_background_hiding_command << package_background_destination.str(); - temp_background_hiding_command << "\""; + bool remount_image = + !cpack_package_icon.empty() || !cpack_dmg_ds_store_setup_script.empty(); - if(!this->RunCommand(temp_background_hiding_command)) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error setting attributes on disk volume background image." - << std::endl); + std::string temp_image_format = "UDZO"; + + // Create 1 MB dummy padding file in staging area when we need to remount + // image, so we have enough space for storing changes ... + if (remount_image) { + std::ostringstream dummy_padding; + dummy_padding << staging.str() << "/.dummy-padding-file"; + if (!this->CreateEmptyFile(dummy_padding, 1048576)) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Error creating dummy padding file." + << std::endl); return 0; - } } + temp_image_format = "UDRW"; + } // Create a temporary read-write disk image ... std::string temp_image = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); temp_image += "/temp.dmg"; - cmOStringStream temp_image_command; + std::ostringstream temp_image_command; temp_image_command << this->GetOption("CPACK_COMMAND_HDIUTIL"); temp_image_command << " create"; temp_image_command << " -ov"; temp_image_command << " -srcfolder \"" << staging.str() << "\""; - temp_image_command << " -volname \"" - << cpack_dmg_volume_name << "\""; - temp_image_command << " -format UDRW"; + temp_image_command << " -volname \"" << cpack_dmg_volume_name << "\""; + temp_image_command << " -format " << temp_image_format; temp_image_command << " \"" << temp_image << "\""; - if(!this->RunCommand(temp_image_command)) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error generating temporary disk image." - << std::endl); + if (!this->RunCommand(temp_image_command)) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Error generating temporary disk image." << std::endl); return 0; - } + } - // Optionally set the custom icon flag for the image ... - if(!cpack_package_icon.empty()) - { - cmOStringStream temp_mount; + if (remount_image) { + // Store that we have a failure so that we always unmount the image + // before we exit. + bool had_error = false; - cmOStringStream attach_command; + std::ostringstream attach_command; attach_command << this->GetOption("CPACK_COMMAND_HDIUTIL"); attach_command << " attach"; attach_command << " \"" << temp_image << "\""; std::string attach_output; - if(!this->RunCommand(attach_command, &attach_output)) - { + if (!this->RunCommand(attach_command, &attach_output)) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error attaching temporary disk image." - << std::endl); + "Error attaching temporary disk image." << std::endl); return 0; - } + } cmsys::RegularExpression mountpoint_regex(".*(/Volumes/[^\n]+)\n.*"); mountpoint_regex.find(attach_output.c_str()); - temp_mount << mountpoint_regex.match(1); + std::string const temp_mount = mountpoint_regex.match(1); - cmOStringStream setfile_command; - setfile_command << this->GetOption("CPACK_COMMAND_SETFILE"); - setfile_command << " -a C"; - setfile_command << " \"" << temp_mount.str() << "\""; + // Remove dummy padding file so we have enough space on RW image ... + std::ostringstream dummy_padding; + dummy_padding << temp_mount << "/.dummy-padding-file"; + if (!cmSystemTools::RemoveFile(dummy_padding.str())) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Error removing dummy padding file." + << std::endl); - if(!this->RunCommand(setfile_command)) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error assigning custom icon to temporary disk image." - << std::endl); + had_error = true; + } - return 0; + // Optionally set the custom icon flag for the image ... + if (!had_error && !cpack_package_icon.empty()) { + std::ostringstream setfile_command; + setfile_command << this->GetOption("CPACK_COMMAND_SETFILE"); + setfile_command << " -a C"; + setfile_command << " \"" << temp_mount << "\""; + + if (!this->RunCommand(setfile_command)) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Error assigning custom icon to temporary disk image." + << std::endl); + + had_error = true; } + } + + // Optionally we can execute a custom apple script to generate + // the .DS_Store for the volume folder ... + if (!had_error && !cpack_dmg_ds_store_setup_script.empty()) { + std::ostringstream setup_script_command; + setup_script_command << "osascript" + << " \"" << cpack_dmg_ds_store_setup_script << "\"" + << " \"" << cpack_dmg_volume_name << "\""; + std::string error; + if (!this->RunCommand(setup_script_command, &error)) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Error executing custom script on disk image." + << std::endl + << error << std::endl); - cmOStringStream detach_command; + had_error = true; + } + } + + std::ostringstream detach_command; detach_command << this->GetOption("CPACK_COMMAND_HDIUTIL"); detach_command << " detach"; - detach_command << " \"" << temp_mount.str() << "\""; + detach_command << " \"" << temp_mount << "\""; - if(!this->RunCommand(detach_command)) - { + if (!this->RunCommand(detach_command)) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error detaching temporary disk image." - << std::endl); + "Error detaching temporary disk image." << std::endl); return 0; - } } - if(!cpack_license_file.empty()) - { + if (had_error) { + return 0; + } + } + + if (!cpack_license_file.empty() || !slaDirectory.empty()) { + // Use old hardcoded style if sla_dir is not set + bool oldStyle = slaDirectory.empty(); std::string sla_r = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); sla_r += "/sla.r"; - std::ifstream ifs; - ifs.open(cpack_license_file.c_str()); - if(ifs.is_open()) - { - cmGeneratedFileStream osf(sla_r.c_str()); - osf << "#include <CoreServices/CoreServices.r>\n\n"; - osf << SLAHeader; - osf << "\n"; - osf << "data 'TEXT' (5002, \"English\") {\n"; - while(ifs.good()) - { - std::string line; - std::getline(ifs, line); - // escape quotes - std::string::size_type pos = line.find('\"'); - while(pos != std::string::npos) + std::vector<std::string> languages; + if (!oldStyle) { + cmSystemTools::ExpandListArgument(cpack_dmg_languages, languages); + } + + cmGeneratedFileStream ofs(sla_r.c_str()); + ofs << "#include <CoreServices/CoreServices.r>\n\n"; + if (oldStyle) { + ofs << SLAHeader; + ofs << "\n"; + } else { + /* + * LPic Layout + * (https://github.com/pypt/dmg-add-license/blob/master/main.c) + * as far as I can tell (no official documentation seems to exist): + * struct LPic { + * uint16_t default_language; // points to a resid, defaulting to 0, + * // which is the first set language + * uint16_t length; + * struct { + * uint16_t language_code; + * uint16_t resid; + * uint16_t encoding; // Encoding from TextCommon.h, + * // forcing MacRoman (0) for now. Might need to + * // allow overwrite per license by user later + * } item[1]; + * } + */ + + // Create vector first for readability, then iterate to write to ofs + std::vector<uint16_t> header_data; + header_data.push_back(0); + header_data.push_back(languages.size()); + for (size_t i = 0; i < languages.size(); ++i) { + CFStringRef language_cfstring = CFStringCreateWithCString( + NULL, languages[i].c_str(), kCFStringEncodingUTF8); + CFStringRef iso_language = + CFLocaleCreateCanonicalLanguageIdentifierFromString( + NULL, language_cfstring); + if (!iso_language) { + cmCPackLogger(cmCPackLog::LOG_ERROR, languages[i] + << " is not a recognized language" << std::endl); + } + char* iso_language_cstr = (char*)malloc(65); + CFStringGetCString(iso_language, iso_language_cstr, 64, + kCFStringEncodingMacRoman); + LangCode lang = 0; + RegionCode region = 0; +#ifdef HAVE_CoreServices + OSStatus err = + LocaleStringToLangAndRegionCodes(iso_language_cstr, &lang, ®ion); + if (err != noErr) +#endif { - line.replace(pos, 1, "\\\""); - pos = line.find('\"', pos+2); + cmCPackLogger(cmCPackLog::LOG_ERROR, + "No language/region code available for " + << iso_language_cstr << std::endl); + free(iso_language_cstr); + return 0; } - // break up long lines to avoid Rez errors - std::vector<std::string> lines; - const size_t max_line_length = 512; - for(size_t i=0; i<line.size(); i+= max_line_length) - { - int line_length = max_line_length; - if(i+max_line_length > line.size()) - line_length = line.size()-i; - lines.push_back(line.substr(i, line_length)); - } +#ifdef HAVE_CoreServices + free(iso_language_cstr); + header_data.push_back(region); + header_data.push_back(i); + header_data.push_back(0); +#endif + } + ofs << "data 'LPic' (5000) {\n"; + ofs << std::hex << std::uppercase << std::setfill('0'); - for(size_t i=0; i<lines.size(); i++) - { - osf << " \"" << lines[i] << "\"\n"; - } - osf << " \"\\n\"\n"; + for (size_t i = 0; i < header_data.size(); ++i) { + if (i % 8 == 0) { + ofs << " $\""; + } + + ofs << std::setw(4) << header_data[i]; + + if (i % 8 == 7 || i == header_data.size() - 1) { + ofs << "\"\n"; + } else { + ofs << " "; + } } - osf << "};\n"; - osf << "\n"; - osf << SLASTREnglish; - ifs.close(); - osf.close(); + ofs << "};\n\n"; + // Reset ofs options + ofs << std::dec << std::nouppercase << std::setfill(' '); } - // convert to UDCO - std::string temp_udco = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); - temp_udco += "/temp-udco.dmg"; + bool have_write_license_error = false; + std::string error; - cmOStringStream udco_image_command; - udco_image_command << this->GetOption("CPACK_COMMAND_HDIUTIL"); - udco_image_command << " convert \"" << temp_image << "\""; - udco_image_command << " -format UDCO"; - udco_image_command << " -o \"" << temp_udco << "\""; + if (oldStyle) { + if (!this->WriteLicense(ofs, 0, "", cpack_license_file, &error)) { + have_write_license_error = true; + } + } else { + for (size_t i = 0; i < languages.size() && !have_write_license_error; + ++i) { + if (singleLicense) { + if (!this->WriteLicense(ofs, i + 5000, languages[i], + cpack_license_file, &error)) { + have_write_license_error = true; + } + } else { + if (!this->WriteLicense(ofs, i + 5000, languages[i], "", &error)) { + have_write_license_error = true; + } + } + } + } - std::string error; - if(!this->RunCommand(udco_image_command, &error)) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error converting to UDCO dmg for adding SLA." << std::endl - << error - << std::endl); + ofs.Close(); + + if (have_write_license_error) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Error writing license file to SLA." + << std::endl + << error << std::endl); return 0; + } + + if (temp_image_format != "UDZO") { + temp_image_format = "UDZO"; + // convert to UDZO to enable unflatten/flatten + std::string temp_udzo = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); + temp_udzo += "/temp-udzo.dmg"; + + std::ostringstream udco_image_command; + udco_image_command << this->GetOption("CPACK_COMMAND_HDIUTIL"); + udco_image_command << " convert \"" << temp_image << "\""; + udco_image_command << " -format UDZO"; + udco_image_command << " -ov -o \"" << temp_udzo << "\""; + + if (!this->RunCommand(udco_image_command, &error)) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Error converting to UDCO dmg for adding SLA." + << std::endl + << error << std::endl); + return 0; } + temp_image = temp_udzo; + } // unflatten dmg - cmOStringStream unflatten_command; + std::ostringstream unflatten_command; unflatten_command << this->GetOption("CPACK_COMMAND_HDIUTIL"); unflatten_command << " unflatten "; - unflatten_command << "\"" << temp_udco << "\""; + unflatten_command << "\"" << temp_image << "\""; - if(!this->RunCommand(unflatten_command, &error)) - { + if (!this->RunCommand(unflatten_command, &error)) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error unflattening dmg for adding SLA." << std::endl - << error - << std::endl); + "Error unflattening dmg for adding SLA." << std::endl + << error + << std::endl); return 0; - } + } // Rez the SLA - cmOStringStream embed_sla_command; + std::ostringstream embed_sla_command; embed_sla_command << this->GetOption("CPACK_COMMAND_REZ"); + const char* sysroot = this->GetOption("CPACK_OSX_SYSROOT"); + if (sysroot && sysroot[0] != '\0') { + embed_sla_command << " -isysroot \"" << sysroot << "\""; + } embed_sla_command << " \"" << sla_r << "\""; embed_sla_command << " -a -o "; - embed_sla_command << "\"" << temp_udco << "\""; + embed_sla_command << "\"" << temp_image << "\""; - if(!this->RunCommand(embed_sla_command, &error)) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error adding SLA." << std::endl - << error - << std::endl); + if (!this->RunCommand(embed_sla_command, &error)) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Error adding SLA." << std::endl + << error + << std::endl); return 0; - } + } // flatten dmg - cmOStringStream flatten_command; + std::ostringstream flatten_command; flatten_command << this->GetOption("CPACK_COMMAND_HDIUTIL"); flatten_command << " flatten "; - flatten_command << "\"" << temp_udco << "\""; + flatten_command << "\"" << temp_image << "\""; - if(!this->RunCommand(flatten_command, &error)) - { + if (!this->RunCommand(flatten_command, &error)) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error flattening dmg for adding SLA." << std::endl - << error - << std::endl); + "Error flattening dmg for adding SLA." << std::endl + << error + << std::endl); return 0; - } - - temp_image = temp_udco; + } } - // Create the final compressed read-only disk image ... - cmOStringStream final_image_command; + std::ostringstream final_image_command; final_image_command << this->GetOption("CPACK_COMMAND_HDIUTIL"); final_image_command << " convert \"" << temp_image << "\""; final_image_command << " -format "; @@ -546,14 +715,12 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir, final_image_command << " zlib-level=9"; final_image_command << " -o \"" << output_file << "\""; - if(!this->RunCommand(final_image_command)) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error compressing disk image." - << std::endl); + if (!this->RunCommand(final_image_command)) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Error compressing disk image." + << std::endl); return 0; - } + } return 1; } @@ -563,9 +730,8 @@ bool cmCPackDragNDropGenerator::SupportsComponentInstallation() const return true; } -std::string -cmCPackDragNDropGenerator::GetComponentInstallDirNameSuffix( - const std::string& componentName) +std::string cmCPackDragNDropGenerator::GetComponentInstallDirNameSuffix( + const std::string& componentName) { // we want to group components together that go in the same dmg package std::string package_file_name = this->GetOption("CPACK_PACKAGE_FILE_NAME"); @@ -577,27 +743,153 @@ cmCPackDragNDropGenerator::GetComponentInstallDirNameSuffix( // 3. ignore groups - if grouping is defined, it is ignored // and each component goes in its own package - if(this->componentPackageMethod == ONE_PACKAGE) - { + if (this->componentPackageMethod == ONE_PACKAGE) { return "ALL_IN_ONE"; - } + } - if(this->componentPackageMethod == ONE_PACKAGE_PER_GROUP) - { + if (this->componentPackageMethod == ONE_PACKAGE_PER_GROUP) { // We have to find the name of the COMPONENT GROUP // the current COMPONENT belongs to. - std::string groupVar = "CPACK_COMPONENT_" + - cmSystemTools::UpperCase(componentName) + "_GROUP"; - const char* _groupName = GetOption(groupVar.c_str()); - if (_groupName) - { + std::string groupVar = + "CPACK_COMPONENT_" + cmSystemTools::UpperCase(componentName) + "_GROUP"; + const char* _groupName = GetOption(groupVar); + if (_groupName) { std::string groupName = _groupName; - groupName = GetComponentPackageFileName(package_file_name, - groupName, true); + groupName = + GetComponentPackageFileName(package_file_name, groupName, true); return groupName; - } } + } return GetComponentPackageFileName(package_file_name, componentName, false); } + +bool cmCPackDragNDropGenerator::WriteLicense( + cmGeneratedFileStream& outputStream, int licenseNumber, + std::string licenseLanguage, std::string licenseFile, std::string* error) +{ + if (!licenseFile.empty() && !singleLicense) { + licenseNumber = 5002; + licenseLanguage = "English"; + } + + // License header + outputStream << "data 'TEXT' (" << licenseNumber << ", \"" << licenseLanguage + << "\") {\n"; + // License body + std::string actual_license = !licenseFile.empty() + ? licenseFile + : (slaDirectory + "/" + licenseLanguage + ".license.txt"); + cmsys::ifstream license_ifs; + license_ifs.open(actual_license.c_str()); + if (license_ifs.is_open()) { + while (license_ifs.good()) { + std::string line; + std::getline(license_ifs, line); + if (!line.empty()) { + EscapeQuotesAndBackslashes(line); + std::vector<std::string> lines; + if (!this->BreakLongLine(line, lines, error)) { + return false; + } + for (size_t i = 0; i < lines.size(); ++i) { + outputStream << " \"" << lines[i] << "\"\n"; + } + } + outputStream << " \"\\n\"\n"; + } + license_ifs.close(); + } + + // End of License + outputStream << "};\n\n"; + if (!licenseFile.empty() && !singleLicense) { + outputStream << SLASTREnglish; + } else { + // Menu header + outputStream << "resource 'STR#' (" << licenseNumber << ", \"" + << licenseLanguage << "\") {\n"; + outputStream << " {\n"; + + // Menu body + cmsys::ifstream menu_ifs; + menu_ifs.open( + (slaDirectory + "/" + licenseLanguage + ".menu.txt").c_str()); + if (menu_ifs.is_open()) { + size_t lines_written = 0; + while (menu_ifs.good()) { + // Lines written from original file, not from broken up lines + std::string line; + std::getline(menu_ifs, line); + if (!line.empty()) { + EscapeQuotesAndBackslashes(line); + std::vector<std::string> lines; + if (!this->BreakLongLine(line, lines, error)) { + return false; + } + for (size_t i = 0; i < lines.size(); ++i) { + std::string comma; + // We need a comma after every complete string, + // but not on the very last line + if (lines_written != 8 && i == lines.size() - 1) { + comma = ","; + } else { + comma = ""; + } + outputStream << " \"" << lines[i] << "\"" << comma << "\n"; + } + ++lines_written; + } + } + menu_ifs.close(); + } + + // End of menu + outputStream << " }\n"; + outputStream << "};\n"; + outputStream << "\n"; + } + + return true; +} + +bool cmCPackDragNDropGenerator::BreakLongLine(const std::string& line, + std::vector<std::string>& lines, + std::string* error) +{ + const size_t max_line_length = 512; + for (size_t i = 0; i < line.size(); i += max_line_length) { + size_t line_length = max_line_length; + if (i + line_length > line.size()) { + line_length = line.size() - i; + } else + while (line_length > 0 && line[i + line_length - 1] != ' ') { + line_length = line_length - 1; + } + + if (line_length == 0) { + *error = "Please make sure there are no words " + "(or character sequences not broken up by spaces or newlines) " + "in your license file which are more than 512 characters long."; + return false; + } + lines.push_back(line.substr(i, line_length)); + } + return true; +} + +void cmCPackDragNDropGenerator::EscapeQuotesAndBackslashes(std::string& line) +{ + std::string::size_type backslash_pos = line.find('\\'); + while (backslash_pos != std::string::npos) { + line.replace(backslash_pos, 1, "\\\\"); + backslash_pos = line.find('\\', backslash_pos + 2); + } + + std::string::size_type quote_pos = line.find('\"'); + while (quote_pos != std::string::npos) { + line.replace(quote_pos, 1, "\\\""); + quote_pos = line.find('\"', quote_pos + 2); + } +} diff --git a/Source/CPack/cmCPackDragNDropGenerator.h b/Source/CPack/cmCPackDragNDropGenerator.h index 808c61886..ae2cc173f 100644 --- a/Source/CPack/cmCPackDragNDropGenerator.h +++ b/Source/CPack/cmCPackDragNDropGenerator.h @@ -1,20 +1,19 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc. - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #ifndef cmCPackDragNDropGenerator_h #define cmCPackDragNDropGenerator_h +#include "cmConfigure.h" + +#include <sstream> +#include <stddef.h> +#include <string> +#include <vector> + #include "cmCPackGenerator.h" +class cmGeneratedFileStream; + /** \class cmCPackDragNDropGenerator * \brief A generator for OSX drag-n-drop installs */ @@ -27,21 +26,32 @@ public: virtual ~cmCPackDragNDropGenerator(); protected: - virtual int InitializeInternal(); - virtual const char* GetOutputExtension(); - int PackageFiles(); - bool SupportsComponentInstallation() const; - + int InitializeInternal() CM_OVERRIDE; + const char* GetOutputExtension() CM_OVERRIDE; + int PackageFiles() CM_OVERRIDE; + bool SupportsComponentInstallation() const CM_OVERRIDE; - bool CopyFile(cmOStringStream& source, cmOStringStream& target); - bool RunCommand(cmOStringStream& command, std::string* output = 0); + bool CopyFile(std::ostringstream& source, std::ostringstream& target); + bool CreateEmptyFile(std::ostringstream& target, size_t size); + bool RunCommand(std::ostringstream& command, std::string* output = 0); - std::string - GetComponentInstallDirNameSuffix(const std::string& componentName); + std::string GetComponentInstallDirNameSuffix( + const std::string& componentName) CM_OVERRIDE; int CreateDMG(const std::string& src_dir, const std::string& output_file); std::string InstallPrefix; + +private: + std::string slaDirectory; + bool singleLicense; + + bool WriteLicense(cmGeneratedFileStream& outputStream, int licenseNumber, + std::string licenseLanguage, std::string licenseFile, + std::string* error); + bool BreakLongLine(const std::string& line, std::vector<std::string>& lines, + std::string* error); + void EscapeQuotesAndBackslashes(std::string& line); }; #endif diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx index 3c685bd9d..d8e2753cf 100644 --- a/Source/CPack/cmCPackGenerator.cxx +++ b/Source/CPack/cmCPackGenerator.cxx @@ -1,124 +1,104 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCPackGenerator.h" -#include "cmMakefile.h" +#include "cmsys/FStream.hxx" +#include "cmsys/Glob.hxx" +#include "cmsys/RegularExpression.hxx" +#include <algorithm> +#include <utility> + +#include "cmCPackComponentGroup.h" #include "cmCPackLog.h" -#include "cmake.h" -#include "cmGlobalGenerator.h" -#include "cmLocalGenerator.h" +#include "cmCryptoHash.h" #include "cmGeneratedFileStream.h" -#include "cmCPackComponentGroup.h" +#include "cmGlobalGenerator.h" +#include "cmMakefile.h" +#include "cmStateSnapshot.h" +#include "cmWorkingDirectory.h" #include "cmXMLSafe.h" - -#include <cmsys/SystemTools.hxx> -#include <cmsys/Glob.hxx> -#include <algorithm> +#include "cm_auto_ptr.hxx" +#include "cmake.h" #if defined(__HAIKU__) -#include <StorageKit.h> +#include <FindDirectory.h> +#include <StorageDefs.h> #endif -//---------------------------------------------------------------------- cmCPackGenerator::cmCPackGenerator() { this->GeneratorVerbose = cmSystemTools::OUTPUT_NONE; - this->MakefileMap = 0; - this->Logger = 0; + this->MakefileMap = CM_NULLPTR; + this->Logger = CM_NULLPTR; this->componentPackageMethod = ONE_PACKAGE_PER_GROUP; } -//---------------------------------------------------------------------- cmCPackGenerator::~cmCPackGenerator() { - this->MakefileMap = 0; + this->MakefileMap = CM_NULLPTR; } -//---------------------------------------------------------------------- -void cmCPackGeneratorProgress(const char *msg, float prog, void* ptr) +void cmCPackGeneratorProgress(const char* msg, float prog, void* ptr) { cmCPackGenerator* self = static_cast<cmCPackGenerator*>(ptr); self->DisplayVerboseOutput(msg, prog); } -//---------------------------------------------------------------------- -void cmCPackGenerator::DisplayVerboseOutput(const char* msg, - float progress) +void cmCPackGenerator::DisplayVerboseOutput(const char* msg, float progress) { (void)progress; cmCPackLogger(cmCPackLog::LOG_VERBOSE, "" << msg << std::endl); } -//---------------------------------------------------------------------- int cmCPackGenerator::PrepareNames() { - cmCPackLogger(cmCPackLog::LOG_DEBUG, - "Create temp directory." << std::endl); + cmCPackLogger(cmCPackLog::LOG_DEBUG, "Create temp directory." << std::endl); // checks CPACK_SET_DESTDIR support - if (IsOn("CPACK_SET_DESTDIR")) - { - if (SETDESTDIR_UNSUPPORTED==SupportsSetDestdir()) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "CPACK_SET_DESTDIR is set to ON but the '" - << Name << "' generator does NOT support it." - << std::endl); - return 0; - } - else if (SETDESTDIR_SHOULD_NOT_BE_USED==SupportsSetDestdir()) - { - cmCPackLogger(cmCPackLog::LOG_WARNING, - "CPACK_SET_DESTDIR is set to ON but it is " - << "usually a bad idea to do that with '" - << Name << "' generator. Use at your own risk." - << std::endl); - } + if (IsOn("CPACK_SET_DESTDIR")) { + if (SETDESTDIR_UNSUPPORTED == SupportsSetDestdir()) { + cmCPackLogger( + cmCPackLog::LOG_ERROR, "CPACK_SET_DESTDIR is set to ON but the '" + << Name << "' generator does NOT support it." << std::endl); + return 0; + } + if (SETDESTDIR_SHOULD_NOT_BE_USED == SupportsSetDestdir()) { + cmCPackLogger(cmCPackLog::LOG_WARNING, + "CPACK_SET_DESTDIR is set to ON but it is " + << "usually a bad idea to do that with '" << Name + << "' generator. Use at your own risk." << std::endl); + } } std::string tempDirectory = this->GetOption("CPACK_PACKAGE_DIRECTORY"); tempDirectory += "/_CPack_Packages/"; const char* toplevelTag = this->GetOption("CPACK_TOPLEVEL_TAG"); - if ( toplevelTag ) - { + if (toplevelTag) { tempDirectory += toplevelTag; tempDirectory += "/"; - } + } tempDirectory += this->GetOption("CPACK_GENERATOR"); std::string topDirectory = tempDirectory; const char* pfname = this->GetOption("CPACK_PACKAGE_FILE_NAME"); - if(!pfname) - { + if (!pfname) { cmCPackLogger(cmCPackLog::LOG_ERROR, "CPACK_PACKAGE_FILE_NAME not specified" << std::endl); return 0; - } + } std::string outName = pfname; tempDirectory += "/" + outName; - if(!this->GetOutputExtension()) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "No output extension specified" << std::endl); + if (!this->GetOutputExtension()) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "No output extension specified" + << std::endl); return 0; - } + } outName += this->GetOutputExtension(); const char* pdir = this->GetOption("CPACK_PACKAGE_DIRECTORY"); - if(!pdir) - { + if (!pdir) { cmCPackLogger(cmCPackLog::LOG_ERROR, "CPACK_PACKAGE_DIRECTORY not specified" << std::endl); return 0; - } + } std::string destFile = pdir; this->SetOptionIfNotSet("CPACK_OUTPUT_FILE_PREFIX", destFile.c_str()); @@ -131,442 +111,408 @@ int cmCPackGenerator::PrepareNames() this->SetOptionIfNotSet("CPACK_TEMPORARY_PACKAGE_FILE_NAME", outFile.c_str()); this->SetOptionIfNotSet("CPACK_INSTALL_DIRECTORY", this->GetInstallPath()); - this->SetOptionIfNotSet("CPACK_NATIVE_INSTALL_DIRECTORY", + this->SetOptionIfNotSet( + "CPACK_NATIVE_INSTALL_DIRECTORY", cmsys::SystemTools::ConvertToOutputPath(this->GetInstallPath()).c_str()); this->SetOptionIfNotSet("CPACK_TEMPORARY_INSTALL_DIRECTORY", tempDirectory.c_str()); cmCPackLogger(cmCPackLog::LOG_DEBUG, - "Look for: CPACK_PACKAGE_DESCRIPTION_FILE" << std::endl); - const char* descFileName - = this->GetOption("CPACK_PACKAGE_DESCRIPTION_FILE"); - if ( descFileName ) - { - cmCPackLogger(cmCPackLog::LOG_DEBUG, - "Look for: " << descFileName << std::endl); - if ( !cmSystemTools::FileExists(descFileName) ) - { + "Look for: CPACK_PACKAGE_DESCRIPTION_FILE" << std::endl); + const char* descFileName = this->GetOption("CPACK_PACKAGE_DESCRIPTION_FILE"); + if (descFileName) { + cmCPackLogger(cmCPackLog::LOG_DEBUG, "Look for: " << descFileName + << std::endl); + if (!cmSystemTools::FileExists(descFileName)) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find description file name: [" - << descFileName << "]" << std::endl); + << descFileName << "]" << std::endl); return 0; - } - std::ifstream ifs(descFileName); - if ( !ifs ) - { + } + cmsys::ifstream ifs(descFileName); + if (!ifs) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Cannot open description file name: " << descFileName << std::endl); + "Cannot open description file name: " << descFileName + << std::endl); return 0; - } - cmOStringStream ostr; + } + std::ostringstream ostr; std::string line; cmCPackLogger(cmCPackLog::LOG_VERBOSE, - "Read description file: " << descFileName << std::endl); - while ( ifs && cmSystemTools::GetLineFromStream(ifs, line) ) - { + "Read description file: " << descFileName << std::endl); + while (ifs && cmSystemTools::GetLineFromStream(ifs, line)) { ostr << cmXMLSafe(line) << std::endl; - } - this->SetOptionIfNotSet("CPACK_PACKAGE_DESCRIPTION", ostr.str().c_str()); } - if ( !this->GetOption("CPACK_PACKAGE_DESCRIPTION") ) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, + this->SetOptionIfNotSet("CPACK_PACKAGE_DESCRIPTION", ostr.str().c_str()); + } + if (!this->GetOption("CPACK_PACKAGE_DESCRIPTION")) { + cmCPackLogger( + cmCPackLog::LOG_ERROR, "Project description not specified. Please specify " "CPACK_PACKAGE_DESCRIPTION or CPACK_PACKAGE_DESCRIPTION_FILE." - << std::endl); + << std::endl); return 0; + } + const char* algoSignature = this->GetOption("CPACK_PACKAGE_CHECKSUM"); + if (algoSignature) { + if (cmCryptoHash::New(algoSignature).get() == CM_NULLPTR) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot recognize algorithm: " + << algoSignature << std::endl); + return 0; } + } this->SetOptionIfNotSet("CPACK_REMOVE_TOPLEVEL_DIRECTORY", "1"); return 1; } -//---------------------------------------------------------------------- int cmCPackGenerator::InstallProject() { cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Install projects" << std::endl); this->CleanTemporaryDirectory(); - std::string bareTempInstallDirectory - = this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY"); + std::string bareTempInstallDirectory = + this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY"); std::string tempInstallDirectoryStr = bareTempInstallDirectory; - bool setDestDir = cmSystemTools::IsOn(this->GetOption("CPACK_SET_DESTDIR")) - | cmSystemTools::IsInternallyOn( - this->GetOption("CPACK_SET_DESTDIR")); - if (!setDestDir) - { + bool setDestDir = cmSystemTools::IsOn(this->GetOption("CPACK_SET_DESTDIR")) | + cmSystemTools::IsInternallyOn(this->GetOption("CPACK_SET_DESTDIR")); + if (!setDestDir) { tempInstallDirectoryStr += this->GetPackagingInstallPrefix(); - } + } const char* tempInstallDirectory = tempInstallDirectoryStr.c_str(); int res = 1; - if ( !cmsys::SystemTools::MakeDirectory(bareTempInstallDirectory.c_str())) - { + if (!cmsys::SystemTools::MakeDirectory(bareTempInstallDirectory.c_str())) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Problem creating temporary directory: " - << (tempInstallDirectory ? tempInstallDirectory : "(NULL)") - << std::endl); + "Problem creating temporary directory: " + << (tempInstallDirectory ? tempInstallDirectory : "(NULL)") + << std::endl); return 0; - } + } - if ( setDestDir ) - { + if (setDestDir) { std::string destDir = "DESTDIR="; destDir += tempInstallDirectory; - cmSystemTools::PutEnv(destDir.c_str()); - } - else - { + cmSystemTools::PutEnv(destDir); + } else { // Make sure there is no destdir cmSystemTools::PutEnv("DESTDIR="); - } + } // If the CPackConfig file sets CPACK_INSTALL_COMMANDS then run them // as listed - if ( !this->InstallProjectViaInstallCommands( - setDestDir, tempInstallDirectory) ) - { + if (!this->InstallProjectViaInstallCommands(setDestDir, + tempInstallDirectory)) { return 0; - } + } // If the CPackConfig file sets CPACK_INSTALL_SCRIPT then run them // as listed - if ( !this->InstallProjectViaInstallScript( - setDestDir, tempInstallDirectory) ) - { + if (!this->InstallProjectViaInstallScript(setDestDir, + 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 packaging - if ( !this->InstallProjectViaInstalledDirectories( - setDestDir, tempInstallDirectory) ) - { + if (!this->InstallProjectViaInstalledDirectories(setDestDir, + 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( - setDestDir, bareTempInstallDirectory.c_str()) ) - { + if (!this->InstallProjectViaInstallCMakeProjects(setDestDir, + bareTempInstallDirectory)) { return 0; - } + } - if ( setDestDir ) - { + if (setDestDir) { cmSystemTools::PutEnv("DESTDIR="); - } + } return res; } -//---------------------------------------------------------------------- int cmCPackGenerator::InstallProjectViaInstallCommands( - bool setDestDir, const char* tempInstallDirectory) + bool setDestDir, const std::string& tempInstallDirectory) { - (void) setDestDir; + (void)setDestDir; const char* installCommands = this->GetOption("CPACK_INSTALL_COMMANDS"); - if ( installCommands && *installCommands ) - { + if (installCommands && *installCommands) { std::string tempInstallDirectoryEnv = "CMAKE_INSTALL_PREFIX="; tempInstallDirectoryEnv += tempInstallDirectory; - cmSystemTools::PutEnv(tempInstallDirectoryEnv.c_str()); + cmSystemTools::PutEnv(tempInstallDirectoryEnv); std::vector<std::string> installCommandsVector; - cmSystemTools::ExpandListArgument(installCommands,installCommandsVector); + cmSystemTools::ExpandListArgument(installCommands, installCommandsVector); std::vector<std::string>::iterator it; - for ( it = installCommandsVector.begin(); - it != installCommandsVector.end(); - ++it ) - { - cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << it->c_str() - << std::endl); + for (it = installCommandsVector.begin(); it != installCommandsVector.end(); + ++it) { + cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << *it << std::endl); std::string output; int retVal = 1; - bool resB = cmSystemTools::RunSingleCommand(it->c_str(), &output, - &retVal, 0, this->GeneratorVerbose, 0); - if ( !resB || retVal ) - { + bool resB = + cmSystemTools::RunSingleCommand(it->c_str(), &output, &output, &retVal, + CM_NULLPTR, this->GeneratorVerbose, 0); + if (!resB || retVal) { std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); tmpFile += "/InstallOutput.log"; cmGeneratedFileStream ofs(tmpFile.c_str()); - ofs << "# Run command: " << it->c_str() << std::endl - << "# Output:" << std::endl - << output.c_str() << std::endl; - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Problem running install command: " << it->c_str() << std::endl - << "Please check " << tmpFile.c_str() << " for errors" - << std::endl); + ofs << "# Run command: " << *it << std::endl + << "# Output:" << std::endl + << output << std::endl; + cmCPackLogger( + cmCPackLog::LOG_ERROR, "Problem running install command: " + << *it << std::endl + << "Please check " << tmpFile << " for errors" << std::endl); return 0; - } } } + } return 1; } -//---------------------------------------------------------------------- int cmCPackGenerator::InstallProjectViaInstalledDirectories( - bool setDestDir, const char* tempInstallDirectory) + bool setDestDir, const std::string& tempInstallDirectory) { (void)setDestDir; (void)tempInstallDirectory; std::vector<cmsys::RegularExpression> ignoreFilesRegex; const char* cpackIgnoreFiles = this->GetOption("CPACK_IGNORE_FILES"); - if ( cpackIgnoreFiles ) - { + 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 ) - { + for (it = ignoreFilesRegexString.begin(); + it != ignoreFilesRegexString.end(); ++it) { cmCPackLogger(cmCPackLog::LOG_VERBOSE, - "Create ignore files regex for: " << it->c_str() << std::endl); + "Create ignore files regex for: " << *it << std::endl); ignoreFilesRegex.push_back(it->c_str()); - } } - const char* installDirectories - = this->GetOption("CPACK_INSTALLED_DIRECTORIES"); - if ( installDirectories && *installDirectories ) - { + } + const char* installDirectories = + this->GetOption("CPACK_INSTALLED_DIRECTORIES"); + if (installDirectories && *installDirectories) { std::vector<std::string> installDirectoriesVector; cmSystemTools::ExpandListArgument(installDirectories, - installDirectoriesVector); - if ( installDirectoriesVector.size() % 2 != 0 ) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, + installDirectoriesVector); + if (installDirectoriesVector.size() % 2 != 0) { + cmCPackLogger( + cmCPackLog::LOG_ERROR, "CPACK_INSTALLED_DIRECTORIES should contain pairs of <directory> and " "<subdirectory>. The <subdirectory> can be '.' to be installed in " - "the toplevel directory of installation." << std::endl); + "the toplevel directory of installation." + << std::endl); return 0; - } + } std::vector<std::string>::iterator it; - const char* tempDir = tempInstallDirectory; - for ( it = installDirectoriesVector.begin(); - it != installDirectoriesVector.end(); - ++it ) - { - std::list<std::pair<std::string,std::string> > symlinkedFiles; + const std::string& tempDir = tempInstallDirectory; + for (it = installDirectoriesVector.begin(); + it != installDirectoriesVector.end(); ++it) { + std::vector<std::pair<std::string, std::string> > symlinkedFiles; cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl); cmsys::Glob gl; - std::string top = it->c_str(); - it ++; - std::string subdir = it->c_str(); + std::string top = *it; + it++; + std::string subdir = *it; std::string findExpr = top; findExpr += "/*"; cmCPackLogger(cmCPackLog::LOG_OUTPUT, - "- Install directory: " << top << std::endl); + "- Install directory: " << top << std::endl); gl.RecurseOn(); - if ( !gl.FindFiles(findExpr) ) - { + gl.SetRecurseListDirs(true); + if (!gl.FindFiles(findExpr)) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Cannot find any files in the installed directory" << std::endl); + "Cannot find any files in the installed directory" + << std::endl); return 0; - } + } files = gl.GetFiles(); std::vector<std::string>::iterator gfit; std::vector<cmsys::RegularExpression>::iterator regIt; - for ( gfit = files.begin(); gfit != files.end(); ++ gfit ) - { + 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_VERBOSE, "Ignore file: " - << inFile.c_str() << std::endl); + std::string inFile = *gfit; + if (cmSystemTools::FileIsDirectory(*gfit)) { + inFile += '/'; + } + for (regIt = ignoreFilesRegex.begin(); regIt != ignoreFilesRegex.end(); + ++regIt) { + if (regIt->find(inFile.c_str())) { + cmCPackLogger(cmCPackLog::LOG_VERBOSE, + "Ignore file: " << inFile << std::endl); skip = true; - } } - if ( skip ) - { + } + if (skip) { continue; - } + } std::string filePath = tempDir; - filePath += "/" + subdir + "/" - + cmSystemTools::RelativePath(top.c_str(), gfit->c_str()); + filePath += "/" + subdir + "/" + + cmSystemTools::RelativePath(top.c_str(), gfit->c_str()); cmCPackLogger(cmCPackLog::LOG_DEBUG, "Copy file: " - << inFile.c_str() << " -> " << filePath.c_str() << std::endl); + << inFile << " -> " << filePath << std::endl); /* If the file is a symlink we will have to re-create it */ - if ( cmSystemTools::FileIsSymlink(inFile.c_str())) - { + if (cmSystemTools::FileIsSymlink(inFile)) { std::string targetFile; std::string inFileRelative = - cmSystemTools::RelativePath(top.c_str(),inFile.c_str()); - cmSystemTools::ReadSymlink(inFile.c_str(),targetFile); - symlinkedFiles.push_back(std::pair<std::string, - std::string>(targetFile,inFileRelative)); - } + cmSystemTools::RelativePath(top.c_str(), inFile.c_str()); + cmSystemTools::ReadSymlink(inFile, targetFile); + symlinkedFiles.push_back( + std::pair<std::string, std::string>(targetFile, inFileRelative)); + } /* If it is not a symlink then do a plain copy */ - else if (!( - cmSystemTools::CopyFileIfDifferent(inFile.c_str(),filePath.c_str()) - && - cmSystemTools::CopyFileTime(inFile.c_str(),filePath.c_str()) - ) ) - { + else if (!(cmSystemTools::CopyFileIfDifferent(inFile.c_str(), + filePath.c_str()) && + cmSystemTools::CopyFileTime(inFile.c_str(), + filePath.c_str()))) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying file: " - << inFile.c_str() << " -> " << filePath.c_str() << std::endl); + << inFile << " -> " << filePath << std::endl); return 0; - } } + } /* rebuild symlinks in the installed tree */ - if (symlinkedFiles.size()>0) - { - std::list< std::pair<std::string,std::string> >::iterator symlinkedIt; + if (!symlinkedFiles.empty()) { + std::vector<std::pair<std::string, std::string> >::iterator + symlinkedIt; std::string curDir = cmSystemTools::GetCurrentWorkingDirectory(); std::string goToDir = tempDir; - goToDir += "/"+subdir; - cmCPackLogger(cmCPackLog::LOG_DEBUG, - "Change dir to: " << goToDir <<std::endl); - cmSystemTools::ChangeDirectory(goToDir.c_str()); - for (symlinkedIt=symlinkedFiles.begin(); - symlinkedIt != symlinkedFiles.end(); - ++symlinkedIt) - { + goToDir += "/" + subdir; + cmCPackLogger(cmCPackLog::LOG_DEBUG, "Change dir to: " << goToDir + << std::endl); + cmWorkingDirectory workdir(goToDir); + for (symlinkedIt = symlinkedFiles.begin(); + symlinkedIt != symlinkedFiles.end(); ++symlinkedIt) { cmCPackLogger(cmCPackLog::LOG_DEBUG, "Will create a symlink: " - << symlinkedIt->second << "--> " - << symlinkedIt->first << std::endl); - if (!cmSystemTools::CreateSymlink((symlinkedIt->first).c_str(), - (symlinkedIt->second).c_str())) - { + << symlinkedIt->second << "--> " + << symlinkedIt->first << std::endl); + // make sure directory exists for symlink + std::string destDir = + cmSystemTools::GetFilenamePath(symlinkedIt->second); + if (!destDir.empty() && !cmSystemTools::MakeDirectory(destDir)) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot create dir: " + << destDir << "\nTrying to create symlink: " + << symlinkedIt->second << "--> " + << symlinkedIt->first << std::endl); + } + if (!cmSystemTools::CreateSymlink(symlinkedIt->first, + symlinkedIt->second)) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot create symlink: " << symlinkedIt->second << "--> " << symlinkedIt->first << std::endl); return 0; - } } - cmCPackLogger(cmCPackLog::LOG_DEBUG, "Going back to: " - << curDir <<std::endl); - cmSystemTools::ChangeDirectory(curDir.c_str()); } + cmCPackLogger(cmCPackLog::LOG_DEBUG, "Going back to: " << curDir + << std::endl); } } + } return 1; } -//---------------------------------------------------------------------- int cmCPackGenerator::InstallProjectViaInstallScript( - bool setDestDir, const char* tempInstallDirectory) + bool setDestDir, const std::string& tempInstallDirectory) { - const char* cmakeScripts - = this->GetOption("CPACK_INSTALL_SCRIPT"); - if ( cmakeScripts && *cmakeScripts ) - { - cmCPackLogger(cmCPackLog::LOG_OUTPUT, - "- Install scripts: " << cmakeScripts << std::endl); + const char* cmakeScripts = this->GetOption("CPACK_INSTALL_SCRIPT"); + if (cmakeScripts && *cmakeScripts) { + cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Install scripts: " << cmakeScripts + << std::endl); std::vector<std::string> cmakeScriptsVector; - cmSystemTools::ExpandListArgument(cmakeScripts, - cmakeScriptsVector); + cmSystemTools::ExpandListArgument(cmakeScripts, cmakeScriptsVector); std::vector<std::string>::iterator it; - for ( it = cmakeScriptsVector.begin(); - it != cmakeScriptsVector.end(); - ++it ) - { - std::string installScript = it->c_str(); + for (it = cmakeScriptsVector.begin(); it != cmakeScriptsVector.end(); + ++it) { + std::string installScript = *it; cmCPackLogger(cmCPackLog::LOG_OUTPUT, - "- Install script: " << installScript << std::endl); + "- Install script: " << installScript << std::endl); - if ( setDestDir ) - { + if (setDestDir) { // For DESTDIR based packaging, use the *project* CMAKE_INSTALL_PREFIX // underneath the tempInstallDirectory. The value of the project's // CMAKE_INSTALL_PREFIX is sent in here as the value of the // CPACK_INSTALL_PREFIX variable. std::string dir; - if (this->GetOption("CPACK_INSTALL_PREFIX")) - { + if (this->GetOption("CPACK_INSTALL_PREFIX")) { dir += this->GetOption("CPACK_INSTALL_PREFIX"); - } + } this->SetOption("CMAKE_INSTALL_PREFIX", dir.c_str()); - cmCPackLogger(cmCPackLog::LOG_DEBUG, + cmCPackLogger( + cmCPackLog::LOG_DEBUG, "- Using DESTDIR + CPACK_INSTALL_PREFIX... (this->SetOption)" - << std::endl); + << std::endl); cmCPackLogger(cmCPackLog::LOG_DEBUG, - "- Setting CMAKE_INSTALL_PREFIX to '" << dir << "'" << std::endl); - } - else - { - this->SetOption("CMAKE_INSTALL_PREFIX", tempInstallDirectory); + "- Setting CMAKE_INSTALL_PREFIX to '" << dir << "'" + << std::endl); + } else { + this->SetOption("CMAKE_INSTALL_PREFIX", tempInstallDirectory.c_str()); cmCPackLogger(cmCPackLog::LOG_DEBUG, - "- Using non-DESTDIR install... (this->SetOption)" << std::endl); + "- Using non-DESTDIR install... (this->SetOption)" + << std::endl); cmCPackLogger(cmCPackLog::LOG_DEBUG, - "- Setting CMAKE_INSTALL_PREFIX to '" << tempInstallDirectory - << "'" << std::endl); - } + "- Setting CMAKE_INSTALL_PREFIX to '" + << tempInstallDirectory << "'" << std::endl); + } this->SetOptionIfNotSet("CMAKE_CURRENT_BINARY_DIR", - tempInstallDirectory); + tempInstallDirectory.c_str()); this->SetOptionIfNotSet("CMAKE_CURRENT_SOURCE_DIR", - tempInstallDirectory); - int res = this->MakefileMap->ReadListFile(0, installScript.c_str()); - if ( cmSystemTools::GetErrorOccuredFlag() || !res ) - { + tempInstallDirectory.c_str()); + int res = this->MakefileMap->ReadListFile(installScript.c_str()); + if (cmSystemTools::GetErrorOccuredFlag() || !res) { return 0; - } } } + } return 1; } -//---------------------------------------------------------------------- int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( - bool setDestDir, const char* baseTempInstallDirectory) + bool setDestDir, const std::string& baseTempInstallDirectory) { - const char* cmakeProjects - = this->GetOption("CPACK_INSTALL_CMAKE_PROJECTS"); - const char* cmakeGenerator - = this->GetOption("CPACK_CMAKE_GENERATOR"); + const char* cmakeProjects = this->GetOption("CPACK_INSTALL_CMAKE_PROJECTS"); + const char* cmakeGenerator = this->GetOption("CPACK_CMAKE_GENERATOR"); std::string absoluteDestFiles; - if ( cmakeProjects && *cmakeProjects ) - { - if ( !cmakeGenerator ) - { + if (cmakeProjects && *cmakeProjects) { + if (!cmakeGenerator) { cmCPackLogger(cmCPackLog::LOG_ERROR, "CPACK_INSTALL_CMAKE_PROJECTS is specified, but " "CPACK_CMAKE_GENERATOR is not. CPACK_CMAKE_GENERATOR " "is required to install the project." - << std::endl); + << std::endl); return 0; - } + } std::vector<std::string> cmakeProjectsVector; - cmSystemTools::ExpandListArgument(cmakeProjects, - cmakeProjectsVector); + cmSystemTools::ExpandListArgument(cmakeProjects, cmakeProjectsVector); std::vector<std::string>::iterator it; - for ( it = cmakeProjectsVector.begin(); - it != cmakeProjectsVector.end(); - ++it ) - { - if ( it+1 == cmakeProjectsVector.end() || - it+2 == cmakeProjectsVector.end() || - it+3 == cmakeProjectsVector.end() ) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, + for (it = cmakeProjectsVector.begin(); it != cmakeProjectsVector.end(); + ++it) { + if (it + 1 == cmakeProjectsVector.end() || + it + 2 == cmakeProjectsVector.end() || + it + 3 == cmakeProjectsVector.end()) { + cmCPackLogger( + cmCPackLog::LOG_ERROR, "Not enough items on list: CPACK_INSTALL_CMAKE_PROJECTS. " "CPACK_INSTALL_CMAKE_PROJECTS should hold quadruplet of install " "directory, install project name, install component, and install " "subdirectory." - << std::endl); + << std::endl); return 0; - } - std::string installDirectory = it->c_str(); + } + std::string installDirectory = *it; ++it; - std::string installProjectName = it->c_str(); + std::string installProjectName = *it; ++it; - std::string installComponent = it->c_str(); + std::string installComponent = *it; ++it; - std::string installSubDirectory = it->c_str(); + std::string installSubDirectory = *it; std::string installFile = installDirectory + "/cmake_install.cmake"; std::vector<std::string> componentsVector; @@ -579,131 +525,115 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( * (this works at CPack time too) */ if (this->SupportsComponentInstallation() & - !(this->IsSet("CPACK_MONOLITHIC_INSTALL"))) - { + !(this->IsOn("CPACK_MONOLITHIC_INSTALL"))) { // Determine the installation types for this project (if provided). - std::string installTypesVar = "CPACK_" - + cmSystemTools::UpperCase(installComponent) + "_INSTALL_TYPES"; - const char *installTypes = this->GetOption(installTypesVar.c_str()); - if (installTypes && *installTypes) - { + std::string installTypesVar = "CPACK_" + + cmSystemTools::UpperCase(installComponent) + "_INSTALL_TYPES"; + const char* installTypes = this->GetOption(installTypesVar); + if (installTypes && *installTypes) { std::vector<std::string> installTypesVector; cmSystemTools::ExpandListArgument(installTypes, installTypesVector); std::vector<std::string>::iterator installTypeIt; for (installTypeIt = installTypesVector.begin(); - installTypeIt != installTypesVector.end(); - ++installTypeIt) - { - this->GetInstallationType(installProjectName.c_str(), - installTypeIt->c_str()); - } + installTypeIt != installTypesVector.end(); ++installTypeIt) { + this->GetInstallationType(installProjectName, *installTypeIt); } + } // Determine the set of components that will be used in this project - std::string componentsVar - = "CPACK_COMPONENTS_" + cmSystemTools::UpperCase(installComponent); - const char *components = this->GetOption(componentsVar.c_str()); - if (components && *components) - { + std::string componentsVar = + "CPACK_COMPONENTS_" + cmSystemTools::UpperCase(installComponent); + const char* components = this->GetOption(componentsVar); + if (components && *components) { cmSystemTools::ExpandListArgument(components, componentsVector); std::vector<std::string>::iterator compIt; for (compIt = componentsVector.begin(); - compIt != componentsVector.end(); - ++compIt) - { - GetComponent(installProjectName.c_str(), compIt->c_str()); - } - componentInstall = true; + compIt != componentsVector.end(); ++compIt) { + GetComponent(installProjectName, *compIt); } + componentInstall = true; } - if (componentsVector.empty()) - { + } + if (componentsVector.empty()) { componentsVector.push_back(installComponent); - } + } - const char* buildConfig = this->GetOption("CPACK_BUILD_CONFIG"); - cmGlobalGenerator* globalGenerator - = this->MakefileMap->GetCMakeInstance()->CreateGlobalGenerator( + const char* buildConfigCstr = this->GetOption("CPACK_BUILD_CONFIG"); + std::string buildConfig = buildConfigCstr ? buildConfigCstr : ""; + cmGlobalGenerator* globalGenerator = + this->MakefileMap->GetCMakeInstance()->CreateGlobalGenerator( cmakeGenerator); + if (!globalGenerator) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Specified package generator not found. " + "CPACK_CMAKE_GENERATOR value is invalid." + << std::endl); + return 0; + } // set the global flag for unix style paths on cmSystemTools as // soon as the generator is set. This allows gmake to be used // on windows. cmSystemTools::SetForceUnixPaths(globalGenerator->GetForceUnixPaths()); // Does this generator require pre-install? - if ( globalGenerator->GetPreinstallTargetName() ) - { - globalGenerator->FindMakeProgram(this->MakefileMap); - const char* cmakeMakeProgram - = this->MakefileMap->GetDefinition("CMAKE_MAKE_PROGRAM"); - std::string buildCommand - = globalGenerator->GenerateBuildCommand(cmakeMakeProgram, - installProjectName.c_str(), 0, 0, - globalGenerator->GetPreinstallTargetName(), - buildConfig, false, false); + if (const char* preinstall = + globalGenerator->GetPreinstallTargetName()) { + std::string buildCommand = globalGenerator->GenerateCMakeBuildCommand( + preinstall, buildConfig, "", false); cmCPackLogger(cmCPackLog::LOG_DEBUG, - "- Install command: " << buildCommand << std::endl); - cmCPackLogger(cmCPackLog::LOG_OUTPUT, - "- Run preinstall target for: " << installProjectName << std::endl); + "- Install command: " << buildCommand << std::endl); + cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Run preinstall target for: " + << installProjectName << std::endl); std::string output; int retVal = 1; - bool resB = - cmSystemTools::RunSingleCommand(buildCommand.c_str(), - &output, - &retVal, - installDirectory.c_str(), - this->GeneratorVerbose, 0); - if ( !resB || retVal ) - { + bool resB = cmSystemTools::RunSingleCommand( + buildCommand.c_str(), &output, &output, &retVal, + installDirectory.c_str(), this->GeneratorVerbose, 0); + if (!resB || retVal) { std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); tmpFile += "/PreinstallOutput.log"; cmGeneratedFileStream ofs(tmpFile.c_str()); - ofs << "# Run command: " << buildCommand.c_str() << std::endl - << "# Directory: " << installDirectory.c_str() << std::endl - << "# Output:" << std::endl - << output.c_str() << std::endl; - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Problem running install command: " << buildCommand.c_str() - << std::endl - << "Please check " << tmpFile.c_str() << " for errors" - << std::endl); + ofs << "# Run command: " << buildCommand << std::endl + << "# Directory: " << installDirectory << std::endl + << "# Output:" << std::endl + << output << std::endl; + cmCPackLogger( + cmCPackLog::LOG_ERROR, "Problem running install command: " + << buildCommand << std::endl + << "Please check " << tmpFile << " for errors" << std::endl); return 0; - } } + } delete globalGenerator; cmCPackLogger(cmCPackLog::LOG_OUTPUT, - "- Install project: " << installProjectName << std::endl); + "- Install project: " << installProjectName << std::endl); // Run the installation for each component std::vector<std::string>::iterator componentIt; for (componentIt = componentsVector.begin(); - componentIt != componentsVector.end(); - ++componentIt) - { + componentIt != componentsVector.end(); ++componentIt) { std::string tempInstallDirectory = baseTempInstallDirectory; installComponent = *componentIt; - if (componentInstall) - { - cmCPackLogger(cmCPackLog::LOG_OUTPUT, - "- Install component: " << installComponent - << std::endl); - } + if (componentInstall) { + cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Install component: " + << installComponent << std::endl); + } - cmake cm; + cmake cm(cmake::RoleScript); + cm.SetHomeDirectory(""); + cm.SetHomeOutputDirectory(""); + cm.GetCurrentSnapshot().SetDefaultDefinitions(); cm.AddCMakePaths(); cm.SetProgressCallback(cmCPackGeneratorProgress, this); - cmGlobalGenerator gg; - gg.SetCMakeInstance(&cm); - cmsys::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator()); - cmMakefile *mf = lg->GetMakefile(); - std::string realInstallDirectory = tempInstallDirectory; - if ( !installSubDirectory.empty() && installSubDirectory != "/" ) - { - realInstallDirectory += installSubDirectory; - } - if (componentInstall) - { + cmGlobalGenerator gg(&cm); + CM_AUTO_PTR<cmMakefile> mf( + new cmMakefile(&gg, cm.GetCurrentSnapshot())); + if (!installSubDirectory.empty() && installSubDirectory != "/" && + installSubDirectory != ".") { + tempInstallDirectory += installSubDirectory; + } + if (componentInstall) { tempInstallDirectory += "/"; // Some CPack generators would rather chose // the local installation directory suffix. @@ -713,20 +643,17 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( // one install directory for each component. tempInstallDirectory += GetComponentInstallDirNameSuffix(installComponent); - if (this->IsOn("CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY")) - { + if (this->IsOn("CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY")) { tempInstallDirectory += "/"; tempInstallDirectory += this->GetOption("CPACK_PACKAGE_FILE_NAME"); - } } + } - if (!setDestDir) - { + if (!setDestDir) { tempInstallDirectory += this->GetPackagingInstallPrefix(); - } + } - if ( setDestDir ) - { + if (setDestDir) { // For DESTDIR based packaging, use the *project* // CMAKE_INSTALL_PREFIX underneath the tempInstallDirectory. The // value of the project's CMAKE_INSTALL_PREFIX is sent in here as @@ -739,37 +666,32 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( // I know this is tricky and awkward but it's the price for // CPACK_SET_DESTDIR backward compatibility. if (cmSystemTools::IsInternallyOn( - this->GetOption("CPACK_SET_DESTDIR"))) - { + this->GetOption("CPACK_SET_DESTDIR"))) { this->SetOption("CPACK_INSTALL_PREFIX", this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX")); - } + } std::string dir; - if (this->GetOption("CPACK_INSTALL_PREFIX")) - { + if (this->GetOption("CPACK_INSTALL_PREFIX")) { dir += this->GetOption("CPACK_INSTALL_PREFIX"); - } + } mf->AddDefinition("CMAKE_INSTALL_PREFIX", dir.c_str()); cmCPackLogger( cmCPackLog::LOG_DEBUG, "- Using DESTDIR + CPACK_INSTALL_PREFIX... (mf->AddDefinition)" - << std::endl); + << std::endl); cmCPackLogger(cmCPackLog::LOG_DEBUG, "- Setting CMAKE_INSTALL_PREFIX to '" << dir << "'" - << std::endl); + << std::endl); // Make sure that DESTDIR + CPACK_INSTALL_PREFIX directory // exists: // - if (cmSystemTools::StringStartsWith(dir.c_str(), "/")) - { + if (cmSystemTools::StringStartsWith(dir.c_str(), "/")) { dir = tempInstallDirectory + dir; - } - else - { + } else { dir = tempInstallDirectory + "/" + dir; - } + } /* * We must re-set DESTDIR for each component * We must not add the CPACK_INSTALL_PREFIX part because @@ -781,274 +703,237 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( * - Because it was already used for component install * in order to put things in subdirs... */ - cmSystemTools::PutEnv( - (std::string("DESTDIR=")+tempInstallDirectory).c_str() - ); - cmCPackLogger(cmCPackLog::LOG_DEBUG, - "- Creating directory: '" << dir << "'" << std::endl); - - if ( !cmsys::SystemTools::MakeDirectory(dir.c_str())) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Problem creating temporary directory: " - << dir << std::endl); + cmSystemTools::PutEnv(std::string("DESTDIR=") + + tempInstallDirectory); + cmCPackLogger(cmCPackLog::LOG_DEBUG, "- Creating directory: '" + << dir << "'" << std::endl); + + if (!cmsys::SystemTools::MakeDirectory(dir.c_str())) { + cmCPackLogger( + cmCPackLog::LOG_ERROR, + "Problem creating temporary directory: " << dir << std::endl); return 0; - } } - else - { + } else { mf->AddDefinition("CMAKE_INSTALL_PREFIX", tempInstallDirectory.c_str()); - if ( !cmsys::SystemTools::MakeDirectory( - tempInstallDirectory.c_str())) - { + if (!cmsys::SystemTools::MakeDirectory( + tempInstallDirectory.c_str())) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem creating temporary directory: " - << tempInstallDirectory << std::endl); + << tempInstallDirectory << std::endl); return 0; - } + } cmCPackLogger(cmCPackLog::LOG_DEBUG, "- Using non-DESTDIR install... (mf->AddDefinition)" - << std::endl); + << std::endl); cmCPackLogger(cmCPackLog::LOG_DEBUG, "- Setting CMAKE_INSTALL_PREFIX to '" - << tempInstallDirectory - << "'" << std::endl); - } + << tempInstallDirectory << "'" << std::endl); + } - if ( buildConfig && *buildConfig ) - { - mf->AddDefinition("BUILD_TYPE", buildConfig); - } - std::string installComponentLowerCase - = cmSystemTools::LowerCase(installComponent); - if ( installComponentLowerCase != "all" ) - { + if (!buildConfig.empty()) { + mf->AddDefinition("BUILD_TYPE", buildConfig.c_str()); + } + std::string installComponentLowerCase = + cmSystemTools::LowerCase(installComponent); + if (installComponentLowerCase != "all") { mf->AddDefinition("CMAKE_INSTALL_COMPONENT", installComponent.c_str()); - } + } // strip on TRUE, ON, 1, one or several file names, but not on // FALSE, OFF, 0 and an empty string - if (!cmSystemTools::IsOff(this->GetOption("CPACK_STRIP_FILES"))) - { + if (!cmSystemTools::IsOff(this->GetOption("CPACK_STRIP_FILES"))) { mf->AddDefinition("CMAKE_INSTALL_DO_STRIP", "1"); - } + } // Remember the list of files before installation // of the current component (if we are in component install) const char* InstallPrefix = tempInstallDirectory.c_str(); std::vector<std::string> filesBefore; std::string findExpr(InstallPrefix); - if (componentInstall) - { + if (componentInstall) { cmsys::Glob glB; findExpr += "/*"; glB.RecurseOn(); + glB.SetRecurseListDirs(true); glB.FindFiles(findExpr); filesBefore = glB.GetFiles(); - std::sort(filesBefore.begin(),filesBefore.end()); - } + std::sort(filesBefore.begin(), filesBefore.end()); + } // If CPack was asked to warn on ABSOLUTE INSTALL DESTINATION // then forward request to cmake_install.cmake script - if (this->IsOn("CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION")) - { - mf->AddDefinition("CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION", - "1"); - } + if (this->IsOn("CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION")) { + mf->AddDefinition("CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION", "1"); + } // If current CPack generator does support // ABSOLUTE INSTALL DESTINATION or CPack has been asked for // then ask cmake_install.cmake script to error out // as soon as it occurs (before installing file) if (!SupportsAbsoluteDestination() || - this->IsOn("CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION")) - { - mf->AddDefinition("CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION", - "1"); - } + this->IsOn("CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION")) { + mf->AddDefinition("CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION", + "1"); + } // do installation - int res = mf->ReadListFile(0, installFile.c_str()); + int res = mf->ReadListFile(installFile.c_str()); // forward definition of CMAKE_ABSOLUTE_DESTINATION_FILES // to CPack (may be used by generators like CPack RPM or DEB) // in order to transparently handle ABSOLUTE PATH - if (mf->GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES")) - { - mf->AddDefinition("CPACK_ABSOLUTE_DESTINATION_FILES", - mf->GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES")); - } + if (mf->GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES")) { + mf->AddDefinition( + "CPACK_ABSOLUTE_DESTINATION_FILES", + mf->GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES")); + } // Now rebuild the list of files after installation // of the current component (if we are in component install) - if (componentInstall) - { + if (componentInstall) { cmsys::Glob glA; glA.RecurseOn(); + glA.SetRecurseListDirs(true); + glA.SetRecurseThroughSymlinks(false); glA.FindFiles(findExpr); std::vector<std::string> filesAfter = glA.GetFiles(); - std::sort(filesAfter.begin(),filesAfter.end()); + std::sort(filesAfter.begin(), filesAfter.end()); std::vector<std::string>::iterator diff; std::vector<std::string> result(filesAfter.size()); - diff = std::set_difference ( - filesAfter.begin(),filesAfter.end(), - filesBefore.begin(),filesBefore.end(), - result.begin()); + diff = std::set_difference(filesAfter.begin(), filesAfter.end(), + filesBefore.begin(), filesBefore.end(), + result.begin()); std::vector<std::string>::iterator fit; std::string localFileName; // Populate the File field of each component - for (fit=result.begin();fit!=diff;++fit) - { + for (fit = result.begin(); fit != diff; ++fit) { localFileName = - cmSystemTools::RelativePath(InstallPrefix, fit->c_str()); + cmSystemTools::RelativePath(InstallPrefix, fit->c_str()); localFileName = - localFileName.substr(localFileName.find_first_not_of('/'), - std::string::npos); + localFileName.substr(localFileName.find_first_not_of('/')); Components[installComponent].Files.push_back(localFileName); cmCPackLogger(cmCPackLog::LOG_DEBUG, "Adding file <" - <<localFileName<<"> to component <" - <<installComponent<<">"<<std::endl); - } + << localFileName << "> to component <" + << installComponent << ">" << std::endl); } + } - if (NULL !=mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")) { - if (absoluteDestFiles.length()>0) { - absoluteDestFiles +=";"; + if (CM_NULLPTR != + mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")) { + if (!absoluteDestFiles.empty()) { + absoluteDestFiles += ";"; } absoluteDestFiles += mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES"); cmCPackLogger(cmCPackLog::LOG_DEBUG, - "Got some ABSOLUTE DESTINATION FILES: " - << absoluteDestFiles << std::endl); + "Got some ABSOLUTE DESTINATION FILES: " + << absoluteDestFiles << std::endl); // define component specific var - if (componentInstall) - { + if (componentInstall) { std::string absoluteDestFileComponent = - std::string("CPACK_ABSOLUTE_DESTINATION_FILES") - + "_" + GetComponentInstallDirNameSuffix(installComponent); - if (NULL != this->GetOption(absoluteDestFileComponent.c_str())) - { - std::string absoluteDestFilesListComponent = - this->GetOption(absoluteDestFileComponent.c_str()); - absoluteDestFilesListComponent +=";"; - absoluteDestFilesListComponent += - mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES"); - this->SetOption(absoluteDestFileComponent.c_str(), - absoluteDestFilesListComponent.c_str()); - } - else - { - this->SetOption(absoluteDestFileComponent.c_str(), - mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")); - } + std::string("CPACK_ABSOLUTE_DESTINATION_FILES") + "_" + + GetComponentInstallDirNameSuffix(installComponent); + if (CM_NULLPTR != this->GetOption(absoluteDestFileComponent)) { + std::string absoluteDestFilesListComponent = + this->GetOption(absoluteDestFileComponent); + absoluteDestFilesListComponent += ";"; + absoluteDestFilesListComponent += + mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES"); + this->SetOption(absoluteDestFileComponent, + absoluteDestFilesListComponent.c_str()); + } else { + this->SetOption( + absoluteDestFileComponent, + mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")); } + } } - if ( cmSystemTools::GetErrorOccuredFlag() || !res ) - { + if (cmSystemTools::GetErrorOccuredFlag() || !res) { return 0; - } } } } + } this->SetOption("CPACK_ABSOLUTE_DESTINATION_FILES", absoluteDestFiles.c_str()); return 1; } -//---------------------------------------------------------------------- bool cmCPackGenerator::ReadListFile(const char* moduleName) { bool retval; std::string fullPath = this->MakefileMap->GetModulesFile(moduleName); - retval = this->MakefileMap->ReadListFile(0, fullPath.c_str()); + retval = this->MakefileMap->ReadListFile(fullPath.c_str()); // include FATAL_ERROR and ERROR in the return status - retval = retval && (! cmSystemTools::GetErrorOccuredFlag()); + retval = retval && (!cmSystemTools::GetErrorOccuredFlag()); return retval; } -//---------------------------------------------------------------------- -void cmCPackGenerator::SetOptionIfNotSet(const char* op, - const char* value) +void cmCPackGenerator::SetOptionIfNotSet(const std::string& op, + const char* value) { const char* def = this->MakefileMap->GetDefinition(op); - if ( def && *def ) - { + if (def && *def) { return; - } + } this->SetOption(op, value); } -//---------------------------------------------------------------------- -void cmCPackGenerator::SetOption(const char* op, const char* value) +void cmCPackGenerator::SetOption(const std::string& op, const char* value) { - if ( !op ) - { - return; - } - if ( !value ) - { + if (!value) { this->MakefileMap->RemoveDefinition(op); return; - } + } cmCPackLogger(cmCPackLog::LOG_DEBUG, this->GetNameOfClass() - << "::SetOption(" << op << ", " << value << ")" << std::endl); + << "::SetOption(" << op << ", " << value << ")" + << std::endl); this->MakefileMap->AddDefinition(op, value); } -//---------------------------------------------------------------------- int cmCPackGenerator::DoPackage() { - cmCPackLogger(cmCPackLog::LOG_OUTPUT, - "Create package using " << this->Name.c_str() << std::endl); + cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Create package using " << this->Name + << std::endl); // Prepare CPack internal name and check // values for many CPACK_xxx vars - if ( !this->PrepareNames() ) - { + if (!this->PrepareNames()) { return 0; - } + } // Digest Component grouping specification - if ( !this->PrepareGroupingKind() ) - { + if (!this->PrepareGroupingKind()) { 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::RepeatedRemoveDirectory(toplevelDirectory) ) - { + 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::RepeatedRemoveDirectory(toplevelDirectory)) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Problem removing toplevel directory: " - << toplevelDirectory - << std::endl); + "Problem removing toplevel directory: " + << toplevelDirectory << std::endl); return 0; - } } } - cmCPackLogger(cmCPackLog::LOG_DEBUG, - "About to install project " << std::endl); + } + cmCPackLogger(cmCPackLog::LOG_DEBUG, "About to install project " + << std::endl); - if ( !this->InstallProject() ) - { + if (!this->InstallProject()) { return 0; - } - cmCPackLogger(cmCPackLog::LOG_DEBUG, - "Done install project " << std::endl); - + } + cmCPackLogger(cmCPackLog::LOG_DEBUG, "Done install project " << std::endl); - const char* tempPackageFileName = this->GetOption( - "CPACK_TEMPORARY_PACKAGE_FILE_NAME"); - const char* packageFileName = this->GetOption("CPACK_OUTPUT_FILE_PATH"); + const char* tempPackageFileName = + this->GetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME"); const char* tempDirectory = this->GetOption("CPACK_TEMPORARY_DIRECTORY"); cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl); @@ -1056,28 +941,27 @@ int cmCPackGenerator::DoPackage() std::string findExpr = tempDirectory; findExpr += "/*"; gl.RecurseOn(); + gl.SetRecurseListDirs(true); gl.SetRecurseThroughSymlinks(false); - if ( !gl.FindFiles(findExpr) ) - { + if (!gl.FindFiles(findExpr)) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Cannot find any files in the packaging tree" << std::endl); + "Cannot find any files in the packaging tree" << std::endl); return 0; - } + } cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Create package" << std::endl); cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Package files to: " - << (tempPackageFileName ? tempPackageFileName : "(NULL)") << std::endl); - if ( cmSystemTools::FileExists(tempPackageFileName) ) - { + << (tempPackageFileName ? tempPackageFileName : "(NULL)") + << std::endl); + if (cmSystemTools::FileExists(tempPackageFileName)) { cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Remove old package file" - << std::endl); + << std::endl); cmSystemTools::RemoveFile(tempPackageFileName); - } - if ( cmSystemTools::IsOn(this->GetOption( - "CPACK_INCLUDE_TOPLEVEL_DIRECTORY")) ) - { + } + if (cmSystemTools::IsOn( + this->GetOption("CPACK_INCLUDE_TOPLEVEL_DIRECTORY"))) { tempDirectory = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); - } + } // The files to be installed files = gl.GetFiles(); @@ -1088,14 +972,17 @@ int cmCPackGenerator::DoPackage() * may update this during PackageFiles. * (either putting several names or updating the provided one) */ - packageFileNames.push_back(tempPackageFileName); + packageFileNames.push_back(tempPackageFileName ? tempPackageFileName : ""); toplevel = tempDirectory; - if ( !this->PackageFiles() || cmSystemTools::GetErrorOccuredFlag()) - { + if (!this->PackageFiles() || cmSystemTools::GetErrorOccuredFlag()) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem compressing the directory" - << std::endl); + << std::endl); return 0; - } + } + + /* Prepare checksum algorithm*/ + const char* algo = this->GetOption("CPACK_PACKAGE_CHECKSUM"); + CM_AUTO_PTR<cmCryptoHash> crypto = cmCryptoHash::New(algo ? algo : ""); /* * Copy the generated packages to final destination @@ -1104,64 +991,66 @@ int cmCPackGenerator::DoPackage() * (because the specific generator did 'normalize' it) */ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Copying final package(s) [" - <<packageFileNames.size() - <<"]:"<<std::endl); + << packageFileNames.size() << "]:" << std::endl); std::vector<std::string>::iterator it; /* now copy package one by one */ - for (it=packageFileNames.begin();it!=packageFileNames.end();++it) - { + for (it = packageFileNames.begin(); it != packageFileNames.end(); ++it) { std::string tmpPF(this->GetOption("CPACK_OUTPUT_FILE_PREFIX")); + std::string filename(cmSystemTools::GetFilenameName(*it)); tempPackageFileName = it->c_str(); - tmpPF += "/"+cmSystemTools::GetFilenameName(*it); - packageFileName = tmpPF.c_str(); + tmpPF += "/" + filename; + const char* packageFileName = tmpPF.c_str(); cmCPackLogger(cmCPackLog::LOG_DEBUG, "Copy final package(s): " - << (tempPackageFileName ? tempPackageFileName : "(NULL)" ) - << " to " - << (packageFileName ? packageFileName : "(NULL)") - << std::endl); - if ( !cmSystemTools::CopyFileIfDifferent(tempPackageFileName, - packageFileName) ) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying the package: " - << (tempPackageFileName ? tempPackageFileName : "(NULL)" ) - << " to " - << (packageFileName ? packageFileName : "(NULL)") - << std::endl); + << (tempPackageFileName ? tempPackageFileName : "(NULL)") + << " to " << (packageFileName ? packageFileName : "(NULL)") + << std::endl); + if (!cmSystemTools::CopyFileIfDifferent(tempPackageFileName, + packageFileName)) { + cmCPackLogger( + cmCPackLog::LOG_ERROR, "Problem copying the package: " + << (tempPackageFileName ? tempPackageFileName : "(NULL)") << " to " + << (packageFileName ? packageFileName : "(NULL)") << std::endl); return 0; - } + } cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- package: " - << packageFileName - << " generated." << std::endl); + << packageFileName << " generated." << std::endl); + + /* Generate checksum file */ + if (crypto.get() != CM_NULLPTR) { + std::string hashFile(this->GetOption("CPACK_OUTPUT_FILE_PREFIX")); + hashFile += + "/" + filename.substr(0, filename.rfind(this->GetOutputExtension())); + hashFile += "." + cmSystemTools::LowerCase(algo); + cmsys::ofstream outF(hashFile.c_str()); + if (!outF) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot create checksum file: " + << hashFile << std::endl); + return 0; + } + outF << crypto->HashFile(packageFileName) << " " << filename << "\n"; + cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- checksum file: " + << hashFile << " generated." << std::endl); } + } return 1; } -//---------------------------------------------------------------------- -int cmCPackGenerator::Initialize(const char* name, cmMakefile* mf) +int cmCPackGenerator::Initialize(const std::string& name, cmMakefile* mf) { this->MakefileMap = mf; this->Name = name; - if ( !this->SetCMakeRoot() ) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Cannot initialize the generator" << std::endl); - return 0; - } // set the running generator name this->SetOption("CPACK_GENERATOR", this->Name.c_str()); // Load the project specific config file - const char* config = - this->GetOption("CPACK_PROJECT_CONFIG_FILE"); - if(config) - { + const char* config = this->GetOption("CPACK_PROJECT_CONFIG_FILE"); + if (config) { mf->ReadListFile(config); - } + } int result = this->InitializeInternal(); - if (cmSystemTools::GetErrorOccuredFlag()) - { + if (cmSystemTools::GetErrorOccuredFlag()) { return 0; - } + } // If a generator subclass did not already set this option in its // InitializeInternal implementation, and the project did not already set @@ -1171,513 +1060,423 @@ int cmCPackGenerator::Initialize(const char* name, cmMakefile* mf) return result; } -//---------------------------------------------------------------------- int cmCPackGenerator::InitializeInternal() { return 1; } -//---------------------------------------------------------------------- -bool cmCPackGenerator::IsSet(const char* name) const +bool cmCPackGenerator::IsSet(const std::string& name) const { return this->MakefileMap->IsSet(name); } -//---------------------------------------------------------------------- -bool cmCPackGenerator::IsOn(const char* name) const +bool cmCPackGenerator::IsOn(const std::string& name) const { return cmSystemTools::IsOn(GetOption(name)); } -//---------------------------------------------------------------------- -const char* cmCPackGenerator::GetOption(const char* op) const +bool cmCPackGenerator::IsSetToOff(const std::string& op) const +{ + const char* ret = this->MakefileMap->GetDefinition(op); + if (ret && *ret) { + return cmSystemTools::IsOff(ret); + } + return false; +} + +bool cmCPackGenerator::IsSetToEmpty(const std::string& op) const { const char* ret = this->MakefileMap->GetDefinition(op); - if(!ret) - { + if (ret) { + return !*ret; + } + return false; +} + +const char* cmCPackGenerator::GetOption(const std::string& op) const +{ + const char* ret = this->MakefileMap->GetDefinition(op); + if (!ret) { cmCPackLogger(cmCPackLog::LOG_DEBUG, - "Warning, GetOption return NULL for: " - << op - << std::endl); - } + "Warning, GetOption return NULL for: " << op << std::endl); + } return ret; } -//---------------------------------------------------------------------- -int cmCPackGenerator::SetCMakeRoot() +std::vector<std::string> cmCPackGenerator::GetOptions() const { - // use the CMAKE_ROOT from cmake which should have been - // found by now - const char* root= - this->MakefileMap->GetDefinition("CMAKE_ROOT"); - - if(root) - { - this->CMakeRoot = root; - cmCPackLogger(cmCPackLog::LOG_DEBUG, "Looking for CMAKE_ROOT: " - << this->CMakeRoot.c_str() << std::endl); - this->SetOption("CMAKE_ROOT", this->CMakeRoot.c_str()); - return 1; - } - 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); - return 0; + return this->MakefileMap->GetDefinitions(); } -//---------------------------------------------------------------------- int cmCPackGenerator::PackageFiles() { return 0; } -//---------------------------------------------------------------------- const char* cmCPackGenerator::GetInstallPath() { - if ( !this->InstallPath.empty() ) - { + if (!this->InstallPath.empty()) { return this->InstallPath.c_str(); - } + } #if defined(_WIN32) && !defined(__CYGWIN__) - const char* prgfiles = cmsys::SystemTools::GetEnv("ProgramFiles"); - const char* sysDrive = cmsys::SystemTools::GetEnv("SystemDrive"); - if ( prgfiles ) - { + std::string prgfiles; + std::string sysDrive; + if (cmsys::SystemTools::GetEnv("ProgramFiles", prgfiles)) { this->InstallPath = prgfiles; - } - else if ( sysDrive ) - { + } else if (cmsys::SystemTools::GetEnv("SystemDrive", sysDrive)) { this->InstallPath = sysDrive; this->InstallPath += "/Program Files"; - } - else - { + } else { this->InstallPath = "c:/Program Files"; - } + } this->InstallPath += "/"; this->InstallPath += this->GetOption("CPACK_PACKAGE_NAME"); this->InstallPath += "-"; this->InstallPath += this->GetOption("CPACK_PACKAGE_VERSION"); #elif defined(__HAIKU__) - BPath dir; - if (find_directory(B_COMMON_DIRECTORY, &dir) == B_OK) - { - this->InstallPath = dir.Path(); - } - else - { - this->InstallPath = "/boot/common"; - } + char dir[B_PATH_NAME_LENGTH]; + if (find_directory(B_SYSTEM_DIRECTORY, -1, false, dir, sizeof(dir)) == + B_OK) { + this->InstallPath = dir; + } else { + this->InstallPath = "/boot/system"; + } #else this->InstallPath = "/usr/local/"; #endif return this->InstallPath.c_str(); } -//---------------------------------------------------------------------- const char* cmCPackGenerator::GetPackagingInstallPrefix() { cmCPackLogger(cmCPackLog::LOG_DEBUG, "GetPackagingInstallPrefix: '" - << this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX") << "'" << std::endl); + << this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX") << "'" + << std::endl); return this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX"); } -//---------------------------------------------------------------------- std::string cmCPackGenerator::FindTemplate(const char* name) { cmCPackLogger(cmCPackLog::LOG_DEBUG, "Look for template: " - << (name ? name : "(NULL)") << std::endl); + << (name ? name : "(NULL)") << std::endl); std::string ffile = this->MakefileMap->GetModulesFile(name); - cmCPackLogger(cmCPackLog::LOG_DEBUG, "Found template: " - << ffile.c_str() << std::endl); + cmCPackLogger(cmCPackLog::LOG_DEBUG, "Found template: " << ffile + << std::endl); return ffile; } -//---------------------------------------------------------------------- bool cmCPackGenerator::ConfigureString(const std::string& inString, - std::string& outString) + std::string& outString) { - this->MakefileMap->ConfigureString(inString, - outString, true, false); + this->MakefileMap->ConfigureString(inString, outString, true, false); return true; } -//---------------------------------------------------------------------- -bool cmCPackGenerator::ConfigureFile(const char* inName, - const char* outName, bool copyOnly /* = false */) +bool cmCPackGenerator::ConfigureFile(const char* inName, const char* outName, + bool copyOnly /* = false */) { - return this->MakefileMap->ConfigureFile(inName, outName, - copyOnly, true, false) == 1; + return this->MakefileMap->ConfigureFile(inName, outName, copyOnly, true, + false) == 1; } -//---------------------------------------------------------------------- int cmCPackGenerator::CleanTemporaryDirectory() { - std::string tempInstallDirectoryWithPostfix - = this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY"); + std::string tempInstallDirectoryWithPostfix = + this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY"); const char* tempInstallDirectory = tempInstallDirectoryWithPostfix.c_str(); - if(cmsys::SystemTools::FileExists(tempInstallDirectory)) - { + if (cmsys::SystemTools::FileExists(tempInstallDirectory)) { cmCPackLogger(cmCPackLog::LOG_OUTPUT, - "- Clean temporary : " - << tempInstallDirectory << std::endl); - if(!cmSystemTools::RepeatedRemoveDirectory(tempInstallDirectory)) - { + "- Clean temporary : " << tempInstallDirectory << std::endl); + if (!cmSystemTools::RepeatedRemoveDirectory(tempInstallDirectory)) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Problem removing temporary directory: " << - tempInstallDirectory - << std::endl); + "Problem removing temporary directory: " + << tempInstallDirectory << std::endl); return 0; - } } + } return 1; } -//---------------------------------------------------------------------- +cmInstalledFile const* cmCPackGenerator::GetInstalledFile( + std::string const& name) const +{ + cmake const* cm = this->MakefileMap->GetCMakeInstance(); + return cm->GetInstalledFile(name); +} + int cmCPackGenerator::PrepareGroupingKind() { // find a component package method specified by the user ComponentPackageMethod method = UNKNOWN_COMPONENT_PACKAGE_METHOD; - if(this->GetOption("CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE")) - { + if (this->GetOption("CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE")) { method = ONE_PACKAGE; - } + } - if(this->GetOption("CPACK_COMPONENTS_IGNORE_GROUPS")) - { + if (this->GetOption("CPACK_COMPONENTS_IGNORE_GROUPS")) { method = ONE_PACKAGE_PER_COMPONENT; - } + } - if(this->GetOption("CPACK_COMPONENTS_ONE_PACKAGE_PER_GROUP")) - { + if (this->GetOption("CPACK_COMPONENTS_ONE_PACKAGE_PER_GROUP")) { method = ONE_PACKAGE_PER_GROUP; - } + } std::string groupingType; // Second way to specify grouping - if (NULL != this->GetOption("CPACK_COMPONENTS_GROUPING")) { - groupingType = this->GetOption("CPACK_COMPONENTS_GROUPING"); + if (CM_NULLPTR != this->GetOption("CPACK_COMPONENTS_GROUPING")) { + groupingType = this->GetOption("CPACK_COMPONENTS_GROUPING"); } - if (groupingType.length()>0) - { - cmCPackLogger(cmCPackLog::LOG_VERBOSE, "[" - << this->Name << "]" - << " requested component grouping = "<< groupingType <<std::endl); - if (groupingType == "ALL_COMPONENTS_IN_ONE") - { + if (!groupingType.empty()) { + cmCPackLogger(cmCPackLog::LOG_VERBOSE, "[" + << this->Name << "]" + << " requested component grouping = " << groupingType + << std::endl); + if (groupingType == "ALL_COMPONENTS_IN_ONE") { method = ONE_PACKAGE; - } - else if (groupingType == "IGNORE") - { + } else if (groupingType == "IGNORE") { method = ONE_PACKAGE_PER_COMPONENT; - } - else if (groupingType == "ONE_PER_GROUP") - { + } else if (groupingType == "ONE_PER_GROUP") { method = ONE_PACKAGE_PER_GROUP; - } - else - { - cmCPackLogger(cmCPackLog::LOG_WARNING, "[" + } else { + cmCPackLogger( + cmCPackLog::LOG_WARNING, "[" << this->Name << "]" - << " requested component grouping type <"<< groupingType + << " requested component grouping type <" << groupingType << "> UNKNOWN not in (ALL_COMPONENTS_IN_ONE,IGNORE,ONE_PER_GROUP)" << std::endl); - } } + } // Some components were defined but NO group // fallback to default if not group based - if(method == ONE_PACKAGE_PER_GROUP && - this->ComponentGroups.empty() && !this->Components.empty()) - { - if(componentPackageMethod == ONE_PACKAGE) - { + if (method == ONE_PACKAGE_PER_GROUP && this->ComponentGroups.empty() && + !this->Components.empty()) { + if (componentPackageMethod == ONE_PACKAGE) { method = ONE_PACKAGE; - } - else - { + } else { method = ONE_PACKAGE_PER_COMPONENT; - } - cmCPackLogger(cmCPackLog::LOG_WARNING, "[" - << this->Name << "]" - << " One package per component group requested, " - << "but NO component groups exist: Ignoring component group." - << std::endl); } + cmCPackLogger( + cmCPackLog::LOG_WARNING, "[" + << this->Name << "]" + << " One package per component group requested, " + << "but NO component groups exist: Ignoring component group." + << std::endl); + } // if user specified packaging method, override the default packaging method - if(method != UNKNOWN_COMPONENT_PACKAGE_METHOD) - { + if (method != UNKNOWN_COMPONENT_PACKAGE_METHOD) { componentPackageMethod = method; - } + } - const char* method_names[] = - { - "ALL_COMPONENTS_IN_ONE", - "IGNORE_GROUPS", - "ONE_PER_GROUP" - }; + const char* method_names[] = { "ALL_COMPONENTS_IN_ONE", "IGNORE_GROUPS", + "ONE_PER_GROUP" }; - cmCPackLogger(cmCPackLog::LOG_VERBOSE, "[" - << this->Name << "]" - << " requested component grouping = " - << method_names[componentPackageMethod] - << std::endl); + cmCPackLogger(cmCPackLog::LOG_VERBOSE, "[" + << this->Name << "]" + << " requested component grouping = " + << method_names[componentPackageMethod] << std::endl); return 1; } -//---------------------------------------------------------------------- std::string cmCPackGenerator::GetComponentInstallDirNameSuffix( - const std::string& componentName) { + const std::string& componentName) +{ return componentName; } -//---------------------------------------------------------------------- std::string cmCPackGenerator::GetComponentPackageFileName( - const std::string& initialPackageFileName, - const std::string& groupOrComponentName, - bool isGroupName) { + const std::string& initialPackageFileName, + const std::string& groupOrComponentName, bool isGroupName) +{ /* * the default behavior is to use the * component [group] name as a suffix */ - std::string suffix="-"+groupOrComponentName; + std::string suffix = "-" + groupOrComponentName; /* check if we should use DISPLAY name */ - std::string dispNameVar = "CPACK_"+Name+"_USE_DISPLAY_NAME_IN_FILENAME"; - if (IsOn(dispNameVar.c_str())) - { + std::string dispNameVar = "CPACK_" + Name + "_USE_DISPLAY_NAME_IN_FILENAME"; + if (IsOn(dispNameVar)) { /* the component Group case */ - if (isGroupName) - { - std::string groupDispVar = "CPACK_COMPONENT_GROUP_" - + cmSystemTools::UpperCase(groupOrComponentName) + "_DISPLAY_NAME"; - const char* groupDispName = GetOption(groupDispVar.c_str()); - if (groupDispName) - { - suffix = "-"+std::string(groupDispName); - } + if (isGroupName) { + std::string groupDispVar = "CPACK_COMPONENT_GROUP_" + + cmSystemTools::UpperCase(groupOrComponentName) + "_DISPLAY_NAME"; + const char* groupDispName = GetOption(groupDispVar); + if (groupDispName) { + suffix = "-" + std::string(groupDispName); } + } /* the [single] component case */ - else - { - std::string dispVar = "CPACK_COMPONENT_" - + cmSystemTools::UpperCase(groupOrComponentName) + "_DISPLAY_NAME"; - const char* dispName = GetOption(dispVar.c_str()); - if(dispName) - { - suffix = "-"+std::string(dispName); - } - } + else { + std::string dispVar = "CPACK_COMPONENT_" + + cmSystemTools::UpperCase(groupOrComponentName) + "_DISPLAY_NAME"; + const char* dispName = GetOption(dispVar); + if (dispName) { + suffix = "-" + std::string(dispName); } + } + } return initialPackageFileName + suffix; } -//---------------------------------------------------------------------- enum cmCPackGenerator::CPackSetDestdirSupport cmCPackGenerator::SupportsSetDestdir() const { return cmCPackGenerator::SETDESTDIR_SUPPORTED; } -//---------------------------------------------------------------------- bool cmCPackGenerator::SupportsAbsoluteDestination() const { return true; } -//---------------------------------------------------------------------- bool cmCPackGenerator::SupportsComponentInstallation() const { return false; } -//---------------------------------------------------------------------- bool cmCPackGenerator::WantsComponentInstallation() const { - return (!IsOn("CPACK_MONOLITHIC_INSTALL") & SupportsComponentInstallation()); + return (!IsOn("CPACK_MONOLITHIC_INSTALL") && SupportsComponentInstallation() + // check that we have at least one group or component + && (!this->ComponentGroups.empty() || !this->Components.empty())); } -//---------------------------------------------------------------------- -cmCPackInstallationType* -cmCPackGenerator::GetInstallationType(const char *projectName, - const char *name) +cmCPackInstallationType* cmCPackGenerator::GetInstallationType( + const std::string& projectName, const std::string& name) { - (void) projectName; + (void)projectName; bool hasInstallationType = this->InstallationTypes.count(name) != 0; - cmCPackInstallationType *installType = &this->InstallationTypes[name]; - if (!hasInstallationType) - { + cmCPackInstallationType* installType = &this->InstallationTypes[name]; + if (!hasInstallationType) { // Define the installation type - std::string macroPrefix = "CPACK_INSTALL_TYPE_" - + cmsys::SystemTools::UpperCase(name); + std::string macroPrefix = + "CPACK_INSTALL_TYPE_" + cmsys::SystemTools::UpperCase(name); installType->Name = name; - const char* displayName - = this->GetOption((macroPrefix + "_DISPLAY_NAME").c_str()); - if (displayName && *displayName) - { + const char* displayName = this->GetOption(macroPrefix + "_DISPLAY_NAME"); + if (displayName && *displayName) { installType->DisplayName = displayName; - } - else - { + } else { installType->DisplayName = installType->Name; - } - - installType->Index = static_cast<unsigned>( - this->InstallationTypes.size()); } + + installType->Index = static_cast<unsigned>(this->InstallationTypes.size()); + } return installType; } -//---------------------------------------------------------------------- -cmCPackComponent* -cmCPackGenerator::GetComponent(const char *projectName, const char *name) +cmCPackComponent* cmCPackGenerator::GetComponent( + const std::string& projectName, const std::string& name) { bool hasComponent = this->Components.count(name) != 0; - cmCPackComponent *component = &this->Components[name]; - if (!hasComponent) - { + cmCPackComponent* component = &this->Components[name]; + if (!hasComponent) { // Define the component - std::string macroPrefix = "CPACK_COMPONENT_" - + cmsys::SystemTools::UpperCase(name); + std::string macroPrefix = + "CPACK_COMPONENT_" + cmsys::SystemTools::UpperCase(name); component->Name = name; - const char* displayName - = this->GetOption((macroPrefix + "_DISPLAY_NAME").c_str()); - if (displayName && *displayName) - { + const char* displayName = this->GetOption(macroPrefix + "_DISPLAY_NAME"); + if (displayName && *displayName) { component->DisplayName = displayName; - } - else - { + } else { component->DisplayName = component->Name; - } - component->IsHidden - = this->IsSet((macroPrefix + "_HIDDEN").c_str()); - component->IsRequired - = this->IsSet((macroPrefix + "_REQUIRED").c_str()); - component->IsDisabledByDefault - = this->IsSet((macroPrefix + "_DISABLED").c_str()); - component->IsDownloaded - = this->IsSet((macroPrefix + "_DOWNLOADED").c_str()) - || cmSystemTools::IsOn(this->GetOption("CPACK_DOWNLOAD_ALL")); - - const char* archiveFile = this->GetOption((macroPrefix + - "_ARCHIVE_FILE").c_str()); - if (archiveFile && *archiveFile) - { + } + component->IsHidden = this->IsOn(macroPrefix + "_HIDDEN"); + component->IsRequired = this->IsOn(macroPrefix + "_REQUIRED"); + component->IsDisabledByDefault = this->IsOn(macroPrefix + "_DISABLED"); + component->IsDownloaded = this->IsOn(macroPrefix + "_DOWNLOADED") || + cmSystemTools::IsOn(this->GetOption("CPACK_DOWNLOAD_ALL")); + + const char* archiveFile = this->GetOption(macroPrefix + "_ARCHIVE_FILE"); + if (archiveFile && *archiveFile) { component->ArchiveFile = archiveFile; - } + } + + const char* plist = this->GetOption(macroPrefix + "_PLIST"); + if (plist && *plist) { + component->Plist = plist; + } - const char* groupName = this->GetOption((macroPrefix + "_GROUP").c_str()); - if (groupName && *groupName) - { + const char* groupName = this->GetOption(macroPrefix + "_GROUP"); + if (groupName && *groupName) { component->Group = GetComponentGroup(projectName, groupName); component->Group->Components.push_back(component); - } - else - { - component->Group = 0; - } + } else { + component->Group = CM_NULLPTR; + } - const char* description - = this->GetOption((macroPrefix + "_DESCRIPTION").c_str()); - if (description && *description) - { + const char* description = this->GetOption(macroPrefix + "_DESCRIPTION"); + if (description && *description) { component->Description = description; - } + } // Determine the installation types. - const char *installTypes - = this->GetOption((macroPrefix + "_INSTALL_TYPES").c_str()); - if (installTypes && *installTypes) - { + const char* installTypes = this->GetOption(macroPrefix + "_INSTALL_TYPES"); + if (installTypes && *installTypes) { std::vector<std::string> installTypesVector; cmSystemTools::ExpandListArgument(installTypes, installTypesVector); std::vector<std::string>::iterator installTypesIt; for (installTypesIt = installTypesVector.begin(); - installTypesIt != installTypesVector.end(); - ++installTypesIt) - { + installTypesIt != installTypesVector.end(); ++installTypesIt) { component->InstallationTypes.push_back( - this->GetInstallationType(projectName, installTypesIt->c_str())); - } + this->GetInstallationType(projectName, *installTypesIt)); } + } // Determine the component dependencies. - const char *depends = this->GetOption((macroPrefix + "_DEPENDS").c_str()); - if (depends && *depends) - { + const char* depends = this->GetOption(macroPrefix + "_DEPENDS"); + if (depends && *depends) { std::vector<std::string> dependsVector; cmSystemTools::ExpandListArgument(depends, dependsVector); std::vector<std::string>::iterator dependIt; - for (dependIt = dependsVector.begin(); - dependIt != dependsVector.end(); - ++dependIt) - { - cmCPackComponent *child = GetComponent(projectName, - dependIt->c_str()); + for (dependIt = dependsVector.begin(); dependIt != dependsVector.end(); + ++dependIt) { + cmCPackComponent* child = GetComponent(projectName, *dependIt); component->Dependencies.push_back(child); child->ReverseDependencies.push_back(component); - } } } + } return component; } -//---------------------------------------------------------------------- -cmCPackComponentGroup* -cmCPackGenerator::GetComponentGroup(const char *projectName, const char *name) +cmCPackComponentGroup* cmCPackGenerator::GetComponentGroup( + const std::string& projectName, const std::string& name) { - (void) projectName; - std::string macroPrefix = "CPACK_COMPONENT_GROUP_" - + cmsys::SystemTools::UpperCase(name); + (void)projectName; + std::string macroPrefix = + "CPACK_COMPONENT_GROUP_" + cmsys::SystemTools::UpperCase(name); bool hasGroup = this->ComponentGroups.count(name) != 0; - cmCPackComponentGroup *group = &this->ComponentGroups[name]; - if (!hasGroup) - { + cmCPackComponentGroup* group = &this->ComponentGroups[name]; + if (!hasGroup) { // Define the group group->Name = name; - const char* displayName - = this->GetOption((macroPrefix + "_DISPLAY_NAME").c_str()); - if (displayName && *displayName) - { + const char* displayName = this->GetOption(macroPrefix + "_DISPLAY_NAME"); + if (displayName && *displayName) { group->DisplayName = displayName; - } - else - { + } else { group->DisplayName = group->Name; - } + } - const char* description - = this->GetOption((macroPrefix + "_DESCRIPTION").c_str()); - if (description && *description) - { + const char* description = this->GetOption(macroPrefix + "_DESCRIPTION"); + if (description && *description) { group->Description = description; - } - group->IsBold - = this->IsSet((macroPrefix + "_BOLD_TITLE").c_str()); - group->IsExpandedByDefault - = this->IsSet((macroPrefix + "_EXPANDED").c_str()); - const char* parentGroupName - = this->GetOption((macroPrefix + "_PARENT_GROUP").c_str()); - if (parentGroupName && *parentGroupName) - { + } + group->IsBold = this->IsOn(macroPrefix + "_BOLD_TITLE"); + group->IsExpandedByDefault = this->IsOn(macroPrefix + "_EXPANDED"); + const char* parentGroupName = + this->GetOption(macroPrefix + "_PARENT_GROUP"); + if (parentGroupName && *parentGroupName) { group->ParentGroup = GetComponentGroup(projectName, parentGroupName); group->ParentGroup->Subgroups.push_back(group); - } - else - { - group->ParentGroup = 0; - } + } else { + group->ParentGroup = CM_NULLPTR; } + } return group; } diff --git a/Source/CPack/cmCPackGenerator.h b/Source/CPack/cmCPackGenerator.h index 8fafef93d..45777fa05 100644 --- a/Source/CPack/cmCPackGenerator.h +++ b/Source/CPack/cmCPackGenerator.h @@ -1,66 +1,38 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc. - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #ifndef cmCPackGenerator_h #define cmCPackGenerator_h -#include "cmObject.h" -#include "cmSystemTools.h" +#include "cmConfigure.h" + #include <map> +#include <sstream> +#include <string> #include <vector> -#include "cmCPackComponentGroup.h" // cmCPackComponent and friends - // Forward declarations are insufficient since we use them in - // std::map data members below... - -#define cmCPackTypeMacro(class, superclass) \ - cmTypeMacro(class, superclass); \ - static cmCPackGenerator* CreateGenerator() { return new class; } - -#define cmCPackLogger(logType, msg) \ - do { \ - cmOStringStream cmCPackLog_msg; \ - cmCPackLog_msg << msg; \ - this->Logger->Log(logType, __FILE__, __LINE__,\ - cmCPackLog_msg.str().c_str());\ - } while ( 0 ) - -#ifdef cerr -# undef cerr -#endif -#define cerr no_cerr_use_cmCPack_Log - -#ifdef cout -# undef cout -#endif -#define cout no_cout_use_cmCPack_Log +#include "cmCPackComponentGroup.h" +#include "cmSystemTools.h" -class cmMakefile; class cmCPackLog; +class cmInstalledFile; +class cmMakefile; /** \class cmCPackGenerator * \brief A superclass of all CPack Generators * */ -class cmCPackGenerator : public cmObject +class cmCPackGenerator { public: - cmTypeMacro(cmCPackGenerator, cmObject); + virtual const char* GetNameOfClass() = 0; /** * If verbose then more information is printed out */ void SetVerbose(bool val) - { this->GeneratorVerbose = val ? - cmSystemTools::OUTPUT_MERGE : cmSystemTools::OUTPUT_NONE; } + { + this->GeneratorVerbose = + val ? cmSystemTools::OUTPUT_MERGE : cmSystemTools::OUTPUT_NONE; + } /** * Returns true if the generator may work on this system. @@ -90,7 +62,7 @@ public: /** * Initialize generator */ - int Initialize(const char* name, cmMakefile* mf); + int Initialize(const std::string& name, cmMakefile* mf); /** * Construct generator @@ -99,14 +71,14 @@ public: virtual ~cmCPackGenerator(); //! 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) const; - bool IsSet(const char* name) const; - bool IsOn(const char* name) const; - - //! Set all the variables - int SetCMakeRoot(); + void SetOption(const std::string& op, const char* value); + void SetOptionIfNotSet(const std::string& op, const char* value); + const char* GetOption(const std::string& op) const; + std::vector<std::string> GetOptions() const; + bool IsSet(const std::string& name) const; + bool IsOn(const std::string& name) const; + bool IsSetToOff(const std::string& op) const; + bool IsSetToEmpty(const std::string& op) const; //! Set the logger void SetLogger(cmCPackLog* log) { this->Logger = log; } @@ -130,8 +102,10 @@ protected: int CleanTemporaryDirectory(); + cmInstalledFile const* GetInstalledFile(std::string const& name) const; + virtual const char* GetOutputExtension() { return ".cpack"; } - virtual const char* GetOutputPostfix() { return 0; } + virtual const char* GetOutputPostfix() { return CM_NULLPTR; } /** * Prepare requested grouping kind from CPACK_xxx vars @@ -154,25 +128,25 @@ protected: * default is "componentName" */ virtual std::string GetComponentInstallDirNameSuffix( - const std::string& componentName); + const std::string& componentName); /** * CPack specific generator may mangle CPACK_PACKAGE_FILE_NAME * with CPACK_COMPONENT_xxxx_<NAME>_DISPLAY_NAME if * CPACK_<GEN>_USE_DISPLAY_NAME_IN_FILENAME is ON. - * @param[in] initialPackageFileName - * @param[in] groupOrComponentName - * @param[in] isGroupName + * @param[in] initialPackageFileName the initial package name to be mangled + * @param[in] groupOrComponentName the name of the group/component + * @param[in] isGroupName true if previous name refers to a group, + * false otherwise */ virtual std::string GetComponentPackageFileName( - const std::string& initialPackageFileName, - const std::string& groupOrComponentName, - bool isGroupName); + const std::string& initialPackageFileName, + const std::string& groupOrComponentName, bool isGroupName); /** * Package the list of files and/or components which * has been prepared by the beginning of DoPackage. - * @pre @ref toplevel has been filled-in + * @pre the @ref toplevel has been filled-in * @pre the list of file @ref files has been populated * @pre packageFileNames contains at least 1 entry * @post packageFileNames may have been updated and contains @@ -184,26 +158,26 @@ protected: virtual std::string FindTemplate(const char* name); virtual bool ConfigureFile(const char* inName, const char* outName, - bool copyOnly = false); + bool copyOnly = false); virtual bool ConfigureString(const std::string& input, std::string& output); virtual int InitializeInternal(); - //! Run install commands if specified virtual int InstallProjectViaInstallCommands( - bool setDestDir, const char* tempInstallDirectory); + bool setDestDir, const std::string& tempInstallDirectory); virtual int InstallProjectViaInstallScript( - bool setDestDir, const char* tempInstallDirectory); + bool setDestDir, const std::string& tempInstallDirectory); virtual int InstallProjectViaInstalledDirectories( - bool setDestDir, const char* tempInstallDirectory); + bool setDestDir, const std::string& tempInstallDirectory); virtual int InstallProjectViaInstallCMakeProjects( - bool setDestDir, const char* tempInstallDirectory); + bool setDestDir, const std::string& tempInstallDirectory); /** * The various level of support of * CPACK_SET_DESTDIR used by the generator. */ - enum CPackSetDestdirSupport { + enum CPackSetDestdirSupport + { /* the generator works with or without it */ SETDESTDIR_SUPPORTED, /* the generator works best if automatically handled */ @@ -246,12 +220,12 @@ protected: * @return true if component installation is supported and wanted. */ virtual bool WantsComponentInstallation() const; - virtual cmCPackInstallationType* GetInstallationType(const char *projectName, - const char* name); - virtual cmCPackComponent* GetComponent(const char *projectName, - const char* name); - virtual cmCPackComponentGroup* GetComponentGroup(const char *projectName, - const char* name); + virtual cmCPackInstallationType* GetInstallationType( + const std::string& projectName, const std::string& name); + virtual cmCPackComponent* GetComponent(const std::string& projectName, + const std::string& name); + virtual cmCPackComponentGroup* GetComponentGroup( + const std::string& projectName, const std::string& name); cmSystemTools::OutputOption GeneratorVerbose; std::string Name; @@ -284,10 +258,6 @@ protected: */ std::vector<std::string> files; - std::string CPackSelf; - std::string CMakeSelf; - std::string CMakeRoot; - std::map<std::string, cmCPackInstallationType> InstallationTypes; /** * The set of components. @@ -322,8 +292,23 @@ protected: ComponentPackageMethod componentPackageMethod; cmCPackLog* Logger; + private: cmMakefile* MakefileMap; }; +#define cmCPackTypeMacro(klass, superclass) \ + typedef superclass Superclass; \ + const char* GetNameOfClass() CM_OVERRIDE { return #klass; } \ + static cmCPackGenerator* CreateGenerator() { return new klass; } \ + class cmCPackTypeMacro_UseTrailingSemicolon + +#define cmCPackLogger(logType, msg) \ + do { \ + std::ostringstream cmCPackLog_msg; \ + cmCPackLog_msg << msg; \ + this->Logger->Log(logType, __FILE__, __LINE__, \ + cmCPackLog_msg.str().c_str()); \ + } while (false) + #endif diff --git a/Source/CPack/cmCPackGeneratorFactory.cxx b/Source/CPack/cmCPackGeneratorFactory.cxx index b36c2a2f8..31f48c7e3 100644 --- a/Source/CPack/cmCPackGeneratorFactory.cxx +++ b/Source/CPack/cmCPackGeneratorFactory.cxx @@ -1,196 +1,176 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCPackGeneratorFactory.h" +#include "cmConfigure.h" +#include <ostream> +#include <utility> + +#include "IFW/cmCPackIFWGenerator.h" +#include "cmAlgorithms.h" +#include "cmCPack7zGenerator.h" #include "cmCPackGenerator.h" +#include "cmCPackLog.h" +#include "cmCPackNSISGenerator.h" +#include "cmCPackSTGZGenerator.h" #include "cmCPackTGZGenerator.h" +#include "cmCPackTXZGenerator.h" #include "cmCPackTarBZip2Generator.h" #include "cmCPackTarCompressGenerator.h" #include "cmCPackZIPGenerator.h" -#include "cmCPackSTGZGenerator.h" -#include "cmCPackNSISGenerator.h" #ifdef __APPLE__ -# include "cmCPackDragNDropGenerator.h" -# include "cmCPackBundleGenerator.h" -# include "cmCPackPackageMakerGenerator.h" -# include "cmCPackOSXX11Generator.h" +#include "cmCPackBundleGenerator.h" +#include "cmCPackDragNDropGenerator.h" +#include "cmCPackOSXX11Generator.h" +#include "cmCPackPackageMakerGenerator.h" +#include "cmCPackProductBuildGenerator.h" #endif #ifdef __CYGWIN__ -# include "cmCPackCygwinBinaryGenerator.h" -# include "cmCPackCygwinSourceGenerator.h" +#include "cmCPackCygwinBinaryGenerator.h" +#include "cmCPackCygwinSourceGenerator.h" #endif -#if !defined(_WIN32) \ - && !defined(__QNXNTO__) && !defined(__BEOS__) && !defined(__HAIKU__) -# include "cmCPackDebGenerator.h" -# include "cmCPackRPMGenerator.h" +#if !defined(_WIN32) && !defined(__QNXNTO__) && !defined(__BEOS__) && \ + !defined(__HAIKU__) +#include "cmCPackDebGenerator.h" +#include "cmCPackRPMGenerator.h" #endif #ifdef _WIN32 -# include "WiX/cmCPackWIXGenerator.h" -#endif - -#include "cmCPackLog.h" - -#if defined(__BORLANDC__) -# pragma warn -8008 /* condition is always true */ +#include "WiX/cmCPackWIXGenerator.h" #endif -//---------------------------------------------------------------------- cmCPackGeneratorFactory::cmCPackGeneratorFactory() { - if (cmCPackTGZGenerator::CanGenerate()) - { + if (cmCPackTGZGenerator::CanGenerate()) { this->RegisterGenerator("TGZ", "Tar GZip compression", - cmCPackTGZGenerator::CreateGenerator); - } - if (cmCPackSTGZGenerator::CanGenerate()) - { + cmCPackTGZGenerator::CreateGenerator); + } + if (cmCPackTXZGenerator::CanGenerate()) { + this->RegisterGenerator("TXZ", "Tar XZ compression", + cmCPackTXZGenerator::CreateGenerator); + } + if (cmCPackSTGZGenerator::CanGenerate()) { this->RegisterGenerator("STGZ", "Self extracting Tar GZip compression", - cmCPackSTGZGenerator::CreateGenerator); - } - if (cmCPackNSISGenerator::CanGenerate()) - { + cmCPackSTGZGenerator::CreateGenerator); + } + if (cmCPackNSISGenerator::CanGenerate()) { this->RegisterGenerator("NSIS", "Null Soft Installer", - cmCPackNSISGenerator::CreateGenerator); + cmCPackNSISGenerator::CreateGenerator); this->RegisterGenerator("NSIS64", "Null Soft Installer (64-bit)", - cmCPackNSISGenerator::CreateGenerator64); - } + cmCPackNSISGenerator::CreateGenerator64); + } + if (cmCPackIFWGenerator::CanGenerate()) { + this->RegisterGenerator("IFW", "Qt Installer Framework", + cmCPackIFWGenerator::CreateGenerator); + } #ifdef __CYGWIN__ - if (cmCPackCygwinBinaryGenerator::CanGenerate()) - { + if (cmCPackCygwinBinaryGenerator::CanGenerate()) { this->RegisterGenerator("CygwinBinary", "Cygwin Binary Installer", cmCPackCygwinBinaryGenerator::CreateGenerator); - } - if (cmCPackCygwinSourceGenerator::CanGenerate()) - { + } + if (cmCPackCygwinSourceGenerator::CanGenerate()) { this->RegisterGenerator("CygwinSource", "Cygwin Source Installer", cmCPackCygwinSourceGenerator::CreateGenerator); - } + } #endif - if (cmCPackZIPGenerator::CanGenerate()) - { + if (cmCPackZIPGenerator::CanGenerate()) { this->RegisterGenerator("ZIP", "ZIP file format", - cmCPackZIPGenerator::CreateGenerator); - } + cmCPackZIPGenerator::CreateGenerator); + } + if (cmCPack7zGenerator::CanGenerate()) { + this->RegisterGenerator("7Z", "7-Zip file format", + cmCPack7zGenerator::CreateGenerator); + } #ifdef _WIN32 - if (cmCPackWIXGenerator::CanGenerate()) - { + if (cmCPackWIXGenerator::CanGenerate()) { this->RegisterGenerator("WIX", "MSI file format via WiX tools", - cmCPackWIXGenerator::CreateGenerator); - } + cmCPackWIXGenerator::CreateGenerator); + } #endif - if (cmCPackTarBZip2Generator::CanGenerate()) - { + if (cmCPackTarBZip2Generator::CanGenerate()) { this->RegisterGenerator("TBZ2", "Tar BZip2 compression", - cmCPackTarBZip2Generator::CreateGenerator); - } - if (cmCPackTarCompressGenerator::CanGenerate()) - { + cmCPackTarBZip2Generator::CreateGenerator); + } + if (cmCPackTarCompressGenerator::CanGenerate()) { this->RegisterGenerator("TZ", "Tar Compress compression", - cmCPackTarCompressGenerator::CreateGenerator); - } + cmCPackTarCompressGenerator::CreateGenerator); + } #ifdef __APPLE__ - if (cmCPackDragNDropGenerator::CanGenerate()) - { + if (cmCPackDragNDropGenerator::CanGenerate()) { this->RegisterGenerator("DragNDrop", "Mac OSX Drag And Drop", - cmCPackDragNDropGenerator::CreateGenerator); - } - if (cmCPackBundleGenerator::CanGenerate()) - { + cmCPackDragNDropGenerator::CreateGenerator); + } + if (cmCPackBundleGenerator::CanGenerate()) { this->RegisterGenerator("Bundle", "Mac OSX bundle", - cmCPackBundleGenerator::CreateGenerator); - } - if (cmCPackPackageMakerGenerator::CanGenerate()) - { + cmCPackBundleGenerator::CreateGenerator); + } + if (cmCPackPackageMakerGenerator::CanGenerate()) { this->RegisterGenerator("PackageMaker", "Mac OSX Package Maker installer", - cmCPackPackageMakerGenerator::CreateGenerator); - } - if (cmCPackOSXX11Generator::CanGenerate()) - { + cmCPackPackageMakerGenerator::CreateGenerator); + } + if (cmCPackOSXX11Generator::CanGenerate()) { this->RegisterGenerator("OSXX11", "Mac OSX X11 bundle", - cmCPackOSXX11Generator::CreateGenerator); - } + cmCPackOSXX11Generator::CreateGenerator); + } + if (cmCPackProductBuildGenerator::CanGenerate()) { + this->RegisterGenerator("productbuild", "Mac OSX pkg", + cmCPackProductBuildGenerator::CreateGenerator); + } #endif -#if !defined(_WIN32) \ - && !defined(__QNXNTO__) && !defined(__BEOS__) && !defined(__HAIKU__) - if (cmCPackDebGenerator::CanGenerate()) - { +#if !defined(_WIN32) && !defined(__QNXNTO__) && !defined(__BEOS__) && \ + !defined(__HAIKU__) + if (cmCPackDebGenerator::CanGenerate()) { this->RegisterGenerator("DEB", "Debian packages", - cmCPackDebGenerator::CreateGenerator); - } - if (cmCPackRPMGenerator::CanGenerate()) - { + cmCPackDebGenerator::CreateGenerator); + } + if (cmCPackRPMGenerator::CanGenerate()) { this->RegisterGenerator("RPM", "RPM packages", - cmCPackRPMGenerator::CreateGenerator); - } + cmCPackRPMGenerator::CreateGenerator); + } #endif } -//---------------------------------------------------------------------- cmCPackGeneratorFactory::~cmCPackGeneratorFactory() { - std::vector<cmCPackGenerator*>::iterator it; - for ( it = this->Generators.begin(); it != this->Generators.end(); ++ it ) - { - delete *it; - } + cmDeleteAll(this->Generators); } -//---------------------------------------------------------------------- -cmCPackGenerator* cmCPackGeneratorFactory::NewGenerator(const char* name) +cmCPackGenerator* cmCPackGeneratorFactory::NewGenerator( + const std::string& name) { cmCPackGenerator* gen = this->NewGeneratorInternal(name); - if ( !gen ) - { - return 0; - } + if (!gen) { + return CM_NULLPTR; + } this->Generators.push_back(gen); gen->SetLogger(this->Logger); return gen; } -//---------------------------------------------------------------------- cmCPackGenerator* cmCPackGeneratorFactory::NewGeneratorInternal( - const char* name) + const std::string& name) { - if ( !name ) - { - return 0; - } - cmCPackGeneratorFactory::t_GeneratorCreatorsMap::iterator it - = this->GeneratorCreators.find(name); - if ( it == this->GeneratorCreators.end() ) - { - return 0; - } + cmCPackGeneratorFactory::t_GeneratorCreatorsMap::iterator it = + this->GeneratorCreators.find(name); + if (it == this->GeneratorCreators.end()) { + return CM_NULLPTR; + } return (it->second)(); } -//---------------------------------------------------------------------- -void cmCPackGeneratorFactory::RegisterGenerator(const char* name, - const char* generatorDescription, +void cmCPackGeneratorFactory::RegisterGenerator( + const std::string& name, const char* generatorDescription, CreateGeneratorCall* createGenerator) { - if ( !name || !createGenerator ) - { + if (!createGenerator) { cmCPack_Log(this->Logger, cmCPackLog::LOG_ERROR, - "Cannot register generator" << std::endl); + "Cannot register generator" << std::endl); return; - } + } this->GeneratorCreators[name] = createGenerator; this->GeneratorDescriptions[name] = generatorDescription; } diff --git a/Source/CPack/cmCPackGeneratorFactory.h b/Source/CPack/cmCPackGeneratorFactory.h index dff2e49eb..7f633e473 100644 --- a/Source/CPack/cmCPackGeneratorFactory.h +++ b/Source/CPack/cmCPackGeneratorFactory.h @@ -1,56 +1,50 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc. - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #ifndef cmCPackGeneratorFactory_h #define cmCPackGeneratorFactory_h -#include "cmObject.h" +#include "cmConfigure.h" // IWYU pragma: keep + +#include <map> +#include <string> +#include <vector> -class cmCPackLog; class cmCPackGenerator; +class cmCPackLog; /** \class cmCPackGeneratorFactory * \brief A container for CPack generators * */ -class cmCPackGeneratorFactory : public cmObject +class cmCPackGeneratorFactory { public: - cmTypeMacro(cmCPackGeneratorFactory, cmObject); - cmCPackGeneratorFactory(); ~cmCPackGeneratorFactory(); //! Get the generator - cmCPackGenerator* NewGenerator(const char* name); + cmCPackGenerator* NewGenerator(const std::string& name); void DeleteGenerator(cmCPackGenerator* gen); typedef cmCPackGenerator* CreateGeneratorCall(); - void RegisterGenerator(const char* name, - const char* generatorDescription, - CreateGeneratorCall* createGenerator); + void RegisterGenerator(const std::string& name, + const char* generatorDescription, + CreateGeneratorCall* createGenerator); void SetLogger(cmCPackLog* logger) { this->Logger = logger; } - typedef std::map<cmStdString, cmStdString> DescriptionsMap; + typedef std::map<std::string, std::string> DescriptionsMap; const DescriptionsMap& GetGeneratorsList() const - { return this->GeneratorDescriptions; } + { + return this->GeneratorDescriptions; + } private: - cmCPackGenerator* NewGeneratorInternal(const char* name); + cmCPackGenerator* NewGeneratorInternal(const std::string& name); std::vector<cmCPackGenerator*> Generators; - typedef std::map<cmStdString, CreateGeneratorCall*> t_GeneratorCreatorsMap; + typedef std::map<std::string, CreateGeneratorCall*> t_GeneratorCreatorsMap; t_GeneratorCreatorsMap GeneratorCreators; DescriptionsMap GeneratorDescriptions; cmCPackLog* Logger; diff --git a/Source/CPack/cmCPackLog.cxx b/Source/CPack/cmCPackLog.cxx index 4e8bf0f4e..5c7123959 100644 --- a/Source/CPack/cmCPackLog.cxx +++ b/Source/CPack/cmCPackLog.cxx @@ -1,21 +1,13 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCPackLog.h" +#include "cmConfigure.h" +#include <iostream> + #include "cmGeneratedFileStream.h" #include "cmSystemTools.h" -//---------------------------------------------------------------------- cmCPackLog::cmCPackLog() { this->Verbose = false; @@ -24,57 +16,47 @@ cmCPackLog::cmCPackLog() this->NewLine = true; this->LastTag = cmCPackLog::NOTAG; -#undef cerr -#undef cout this->DefaultOutput = &std::cout; this->DefaultError = &std::cerr; - this->LogOutput = 0; + this->LogOutput = CM_NULLPTR; this->LogOutputCleanup = false; } -//---------------------------------------------------------------------- cmCPackLog::~cmCPackLog() { - this->SetLogOutputStream(0); + this->SetLogOutputStream(CM_NULLPTR); } -//---------------------------------------------------------------------- void cmCPackLog::SetLogOutputStream(std::ostream* os) { - if ( this->LogOutputCleanup && this->LogOutput ) - { + if (this->LogOutputCleanup && this->LogOutput) { delete this->LogOutput; - } + } this->LogOutputCleanup = false; this->LogOutput = os; } -//---------------------------------------------------------------------- bool cmCPackLog::SetLogOutputFile(const char* fname) { - cmGeneratedFileStream *cg = 0; - if ( fname ) - { + cmGeneratedFileStream* cg = CM_NULLPTR; + if (fname) { cg = new cmGeneratedFileStream(fname); - } - if ( cg && !*cg ) - { + } + if (cg && !*cg) { delete cg; - cg = 0; - } + cg = CM_NULLPTR; + } this->SetLogOutputStream(cg); - if ( !cg ) - { + if (!cg) { return false; - } + } this->LogOutputCleanup = true; return true; } -//---------------------------------------------------------------------- -void cmCPackLog::Log(int tag, const char* file, int line, - const char* msg, size_t length) +void cmCPackLog::Log(int tag, const char* file, int line, const char* msg, + size_t length) { // By default no logging bool display = false; @@ -82,144 +64,118 @@ void cmCPackLog::Log(int tag, const char* file, int line, // Display file and line number if debug bool useFileAndLine = this->Debug; - bool output = false; - bool debug = false; + bool output = false; + bool debug = false; bool warning = false; - bool error = false; + bool error = false; bool verbose = false; // When writing in file, add list of tags whenever tag changes. std::string tagString; bool needTagString = false; - if ( this->LogOutput && this->LastTag != tag ) - { + if (this->LogOutput && this->LastTag != tag) { needTagString = true; - } + } - if ( tag & LOG_OUTPUT ) - { + if (tag & LOG_OUTPUT) { output = true; display = true; - if ( needTagString ) - { - if ( tagString.size() > 0 ) { tagString += ","; } - tagString = "VERBOSE"; + if (needTagString) { + if (!tagString.empty()) { + tagString += ","; } + tagString = "VERBOSE"; } - if ( tag & LOG_WARNING ) - { + } + if (tag & LOG_WARNING) { warning = true; display = true; - if ( needTagString ) - { - if ( tagString.size() > 0 ) { tagString += ","; } - tagString = "WARNING"; + if (needTagString) { + if (!tagString.empty()) { + tagString += ","; } + tagString = "WARNING"; } - if ( tag & LOG_ERROR ) - { + } + if (tag & LOG_ERROR) { error = true; display = true; - if ( needTagString ) - { - if ( tagString.size() > 0 ) { tagString += ","; } - tagString = "ERROR"; + if (needTagString) { + if (!tagString.empty()) { + tagString += ","; } + tagString = "ERROR"; } - if ( tag & LOG_DEBUG && this->Debug ) - { + } + if (tag & LOG_DEBUG && this->Debug) { debug = true; display = true; - if ( needTagString ) - { - if ( tagString.size() > 0 ) { tagString += ","; } - tagString = "DEBUG"; + if (needTagString) { + if (!tagString.empty()) { + tagString += ","; } - useFileAndLine = true; + tagString = "DEBUG"; } - if ( tag & LOG_VERBOSE && this->Verbose ) - { + useFileAndLine = true; + } + if (tag & LOG_VERBOSE && this->Verbose) { verbose = true; display = true; - if ( needTagString ) - { - if ( tagString.size() > 0 ) { tagString += ","; } - tagString = "VERBOSE"; + if (needTagString) { + if (!tagString.empty()) { + tagString += ","; } + tagString = "VERBOSE"; } - if ( this->Quiet ) - { + } + if (this->Quiet) { display = false; + } + if (this->LogOutput) { + if (needTagString) { + *this->LogOutput << "[" << file << ":" << line << " " << tagString + << "] "; } - if ( this->LogOutput ) - { - if ( needTagString ) - { - *this->LogOutput << "[" << file << ":" << line << " " - << tagString << "] "; - } this->LogOutput->write(msg, length); - } + } this->LastTag = tag; - if ( !display ) - { + if (!display) { return; - } - if ( this->NewLine ) - { - if ( error && !this->ErrorPrefix.empty() ) - { - *this->DefaultError << this->ErrorPrefix.c_str(); - } - else if ( warning && !this->WarningPrefix.empty() ) - { - *this->DefaultError << this->WarningPrefix.c_str(); - } - else if ( output && !this->OutputPrefix.empty() ) - { - *this->DefaultOutput << this->OutputPrefix.c_str(); - } - else if ( verbose && !this->VerbosePrefix.empty() ) - { - *this->DefaultOutput << this->VerbosePrefix.c_str(); - } - else if ( debug && !this->DebugPrefix.empty() ) - { - *this->DefaultOutput << this->DebugPrefix.c_str(); - } - else if ( !this->Prefix.empty() ) - { - *this->DefaultOutput << this->Prefix.c_str(); - } - if ( useFileAndLine ) - { - if ( error || warning ) - { + } + if (this->NewLine) { + if (error && !this->ErrorPrefix.empty()) { + *this->DefaultError << this->ErrorPrefix; + } else if (warning && !this->WarningPrefix.empty()) { + *this->DefaultError << this->WarningPrefix; + } else if (output && !this->OutputPrefix.empty()) { + *this->DefaultOutput << this->OutputPrefix; + } else if (verbose && !this->VerbosePrefix.empty()) { + *this->DefaultOutput << this->VerbosePrefix; + } else if (debug && !this->DebugPrefix.empty()) { + *this->DefaultOutput << this->DebugPrefix; + } else if (!this->Prefix.empty()) { + *this->DefaultOutput << this->Prefix; + } + if (useFileAndLine) { + if (error || warning) { *this->DefaultError << file << ":" << line << " "; - } - else - { + } else { *this->DefaultOutput << file << ":" << line << " "; - } } } - if ( error || warning ) - { + } + if (error || warning) { this->DefaultError->write(msg, length); this->DefaultError->flush(); - } - else - { + } else { this->DefaultOutput->write(msg, length); this->DefaultOutput->flush(); - } - if ( msg[length-1] == '\n' || length > 2 ) - { + } + if (msg[length - 1] == '\n' || length > 2) { this->NewLine = true; - } + } - if ( error ) - { + if (error) { cmSystemTools::SetErrorOccured(); - } + } } diff --git a/Source/CPack/cmCPackLog.h b/Source/CPack/cmCPackLog.h index 812f1de27..10deda450 100644 --- a/Source/CPack/cmCPackLog.h +++ b/Source/CPack/cmCPackLog.h @@ -1,51 +1,33 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc. - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #ifndef cmCPackLog_h #define cmCPackLog_h -#include "cmObject.h" - -#define cmCPack_Log(ctSelf, logType, msg) \ - do { \ - cmOStringStream cmCPackLog_msg; \ - cmCPackLog_msg << msg; \ - (ctSelf)->Log(logType, __FILE__, __LINE__, cmCPackLog_msg.str().c_str());\ - } while ( 0 ) +#include "cmConfigure.h" // IWYU pragma: keep -#ifdef cerr -# undef cerr -#endif -#define cerr no_cerr_use_cmCPack_Log - -#ifdef cout -# undef cout -#endif -#define cout no_cout_use_cmCPack_Log +#include <ostream> +#include <string.h> +#include <string> +#define cmCPack_Log(ctSelf, logType, msg) \ + do { \ + std::ostringstream cmCPackLog_msg; \ + cmCPackLog_msg << msg; \ + (ctSelf)->Log(logType, __FILE__, __LINE__, cmCPackLog_msg.str().c_str()); \ + } while (false) /** \class cmCPackLog * \brief A container for CPack generators * */ -class cmCPackLog : public cmObject +class cmCPackLog { public: - cmTypeMacro(cmCPackLog, cmObject); - cmCPackLog(); ~cmCPackLog(); - enum __log_tags { + enum __log_tags + { NOTAG = 0, LOG_OUTPUT = 0x1, LOG_VERBOSE = 0x2, @@ -56,19 +38,19 @@ public: //! Various signatures for logging. void Log(const char* file, int line, const char* msg) - { + { this->Log(LOG_OUTPUT, file, line, msg); - } + } void Log(const char* file, int line, const char* msg, size_t length) - { + { this->Log(LOG_OUTPUT, file, line, msg, length); - } + } void Log(int tag, const char* file, int line, const char* msg) - { + { this->Log(tag, file, line, msg, strlen(msg)); - } + } void Log(int tag, const char* file, int line, const char* msg, - size_t length); + size_t length); //! Set Verbose void VerboseOn() { this->SetVerbose(true); } @@ -103,12 +85,12 @@ public: //! Set the various prefixes for the logging. SetPrefix sets the generic // prefix that overwrittes missing ones. - void SetPrefix(std::string pfx) { this->Prefix = pfx; } - void SetOutputPrefix(std::string pfx) { this->OutputPrefix = pfx; } - void SetVerbosePrefix(std::string pfx) { this->VerbosePrefix = pfx; } - void SetDebugPrefix(std::string pfx) { this->DebugPrefix = pfx; } - void SetWarningPrefix(std::string pfx) { this->WarningPrefix = pfx; } - void SetErrorPrefix(std::string pfx) { this->ErrorPrefix = pfx; } + void SetPrefix(std::string const& pfx) { this->Prefix = pfx; } + void SetOutputPrefix(std::string const& pfx) { this->OutputPrefix = pfx; } + void SetVerbosePrefix(std::string const& pfx) { this->VerbosePrefix = pfx; } + void SetDebugPrefix(std::string const& pfx) { this->DebugPrefix = pfx; } + void SetWarningPrefix(std::string const& pfx) { this->WarningPrefix = pfx; } + void SetErrorPrefix(std::string const& pfx) { this->ErrorPrefix = pfx; } private: bool Verbose; @@ -126,11 +108,11 @@ private: std::string WarningPrefix; std::string ErrorPrefix; - std::ostream *DefaultOutput; - std::ostream *DefaultError; + std::ostream* DefaultOutput; + std::ostream* DefaultError; std::string LogOutputFileName; - std::ostream *LogOutput; + std::ostream* LogOutput; // Do we need to cleanup log output stream bool LogOutputCleanup; }; @@ -139,13 +121,16 @@ class cmCPackLogWrite { public: cmCPackLogWrite(const char* data, size_t length) - : Data(data), Length(length) {} + : Data(data) + , Length(length) + { + } const char* Data; size_t Length; }; -inline std::ostream& operator<< (std::ostream& os, const cmCPackLogWrite& c) +inline std::ostream& operator<<(std::ostream& os, const cmCPackLogWrite& c) { os.write(c.Data, c.Length); os.flush(); diff --git a/Source/CPack/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx index 62bfa91d4..9697a3832 100644 --- a/Source/CPack/cmCPackNSISGenerator.cxx +++ b/Source/CPack/cmCPackNSISGenerator.cxx @@ -1,165 +1,176 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCPackNSISGenerator.h" -#include "cmGlobalGenerator.h" -#include "cmLocalGenerator.h" -#include "cmSystemTools.h" -#include "cmMakefile.h" -#include "cmGeneratedFileStream.h" -#include "cmCPackLog.h" #include "cmCPackComponentGroup.h" +#include "cmCPackGenerator.h" +#include "cmCPackLog.h" +#include "cmGeneratedFileStream.h" +#include "cmSystemTools.h" -#include <cmsys/SystemTools.hxx> -#include <cmsys/Glob.hxx> -#include <cmsys/Directory.hxx> -#include <cmsys/RegularExpression.hxx> +#include "cmsys/Directory.hxx" +#include "cmsys/RegularExpression.hxx" +#include <algorithm> +#include <map> +#include <sstream> +#include <stdlib.h> +#include <string.h> +#include <utility> /* NSIS uses different command line syntax on Windows and others */ #ifdef _WIN32 -# define NSIS_OPT "/" +#define NSIS_OPT "/" #else -# define NSIS_OPT "-" +#define NSIS_OPT "-" #endif -//---------------------------------------------------------------------- cmCPackNSISGenerator::cmCPackNSISGenerator(bool nsis64) { Nsis64 = nsis64; } -//---------------------------------------------------------------------- cmCPackNSISGenerator::~cmCPackNSISGenerator() { } -//---------------------------------------------------------------------- int cmCPackNSISGenerator::PackageFiles() { // TODO: Fix nsis to force out file name std::string nsisInFileName = this->FindTemplate("NSIS.template.in"); - if ( nsisInFileName.size() == 0 ) - { + if (nsisInFileName.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "CPack error: Could not find NSIS installer template file." - << std::endl); + "CPack error: Could not find NSIS installer template file." + << std::endl); return false; - } - std::string nsisInInstallOptions - = this->FindTemplate("NSIS.InstallOptions.ini.in"); - if ( nsisInInstallOptions.size() == 0 ) - { + } + std::string nsisInInstallOptions = + this->FindTemplate("NSIS.InstallOptions.ini.in"); + if (nsisInInstallOptions.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "CPack error: Could not find NSIS installer options file." - << std::endl); + "CPack error: Could not find NSIS installer options file." + << std::endl); return false; - } + } std::string nsisFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); std::string tmpFile = nsisFileName; tmpFile += "/NSISOutput.log"; std::string nsisInstallOptions = nsisFileName + "/NSIS.InstallOptions.ini"; nsisFileName += "/project.nsi"; - cmOStringStream str; + std::ostringstream str; std::vector<std::string>::const_iterator it; - for ( it = files.begin(); it != files.end(); ++ it ) - { - std::string fileN = cmSystemTools::RelativePath(toplevel.c_str(), - it->c_str()); - if (!this->Components.empty()) - { - // Strip off the component part of the path. - fileN = fileN.substr(fileN.find('/')+1, std::string::npos); + for (it = files.begin(); it != files.end(); ++it) { + std::string outputDir = "$INSTDIR"; + std::string fileN = + cmSystemTools::RelativePath(toplevel.c_str(), it->c_str()); + if (!this->Components.empty()) { + const std::string::size_type pos = fileN.find('/'); + + // Use the custom component install directory if we have one + if (pos != std::string::npos) { + const std::string componentName = fileN.substr(0, pos); + outputDir = CustomComponentInstallDirectory(componentName); + } else { + outputDir = CustomComponentInstallDirectory(fileN); } - cmSystemTools::ReplaceString(fileN, "/", "\\"); - str << " Delete \"$INSTDIR\\" << fileN.c_str() << "\"" << std::endl; + + // Strip off the component part of the path. + fileN = fileN.substr(pos + 1); } - cmCPackLogger(cmCPackLog::LOG_DEBUG, "Uninstall Files: " - << str.str().c_str() << std::endl); + std::replace(fileN.begin(), fileN.end(), '/', '\\'); + + str << " Delete \"" << outputDir << "\\" << fileN << "\"" << std::endl; + } + cmCPackLogger(cmCPackLog::LOG_DEBUG, "Uninstall Files: " << str.str() + << std::endl); this->SetOptionIfNotSet("CPACK_NSIS_DELETE_FILES", str.str().c_str()); std::vector<std::string> dirs; this->GetListOfSubdirectories(toplevel.c_str(), dirs); std::vector<std::string>::const_iterator sit; - cmOStringStream dstr; - for ( sit = dirs.begin(); sit != dirs.end(); ++ sit ) - { + std::ostringstream dstr; + for (sit = dirs.begin(); sit != dirs.end(); ++sit) { std::string componentName; - std::string fileN = cmSystemTools::RelativePath(toplevel.c_str(), - sit->c_str()); - if ( fileN.empty() ) - { + std::string fileN = + cmSystemTools::RelativePath(toplevel.c_str(), sit->c_str()); + if (fileN.empty()) { continue; - } - if (!Components.empty()) - { + } + if (!Components.empty()) { // If this is a component installation, strip off the component // part of the path. std::string::size_type slash = fileN.find('/'); - if (slash != std::string::npos) - { + if (slash != std::string::npos) { // If this is a component installation, determine which component it // is. componentName = fileN.substr(0, slash); // Strip off the component part of the path. - fileN = fileN.substr(slash+1, std::string::npos); - } + fileN = fileN.substr(slash + 1); } - cmSystemTools::ReplaceString(fileN, "/", "\\"); - dstr << " RMDir \"$INSTDIR\\" << fileN.c_str() << "\"" << std::endl; - if (!componentName.empty()) - { + } + std::replace(fileN.begin(), fileN.end(), '/', '\\'); + + const std::string componentOutputDir = + CustomComponentInstallDirectory(componentName); + + dstr << " RMDir \"" << componentOutputDir << "\\" << fileN << "\"" + << std::endl; + if (!componentName.empty()) { this->Components[componentName].Directories.push_back(fileN); - } } - cmCPackLogger(cmCPackLog::LOG_DEBUG, "Uninstall Dirs: " - << dstr.str().c_str() << std::endl); - this->SetOptionIfNotSet("CPACK_NSIS_DELETE_DIRECTORIES", - dstr.str().c_str()); - - cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " << nsisInFileName - << " to " << nsisFileName << std::endl); - if(this->IsSet("CPACK_NSIS_MUI_ICON") - || this->IsSet("CPACK_NSIS_MUI_UNIICON")) - { + } + cmCPackLogger(cmCPackLog::LOG_DEBUG, "Uninstall Dirs: " << dstr.str() + << std::endl); + this->SetOptionIfNotSet("CPACK_NSIS_DELETE_DIRECTORIES", dstr.str().c_str()); + + cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " + << nsisInFileName << " to " << nsisFileName << std::endl); + if (this->IsSet("CPACK_NSIS_MUI_ICON") || + this->IsSet("CPACK_NSIS_MUI_UNIICON")) { std::string installerIconCode; - if(this->IsSet("CPACK_NSIS_MUI_ICON")) - { + if (this->IsSet("CPACK_NSIS_MUI_ICON")) { installerIconCode += "!define MUI_ICON \""; installerIconCode += this->GetOption("CPACK_NSIS_MUI_ICON"); installerIconCode += "\"\n"; - } - if(this->IsSet("CPACK_NSIS_MUI_UNIICON")) - { + } + if (this->IsSet("CPACK_NSIS_MUI_UNIICON")) { installerIconCode += "!define MUI_UNICON \""; installerIconCode += this->GetOption("CPACK_NSIS_MUI_UNIICON"); installerIconCode += "\"\n"; - } + } this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_ICON_CODE", installerIconCode.c_str()); - } - if(this->IsSet("CPACK_PACKAGE_ICON")) - { + } + if (this->IsSet("CPACK_PACKAGE_ICON")) { std::string installerIconCode = "!define MUI_HEADERIMAGE_BITMAP \""; installerIconCode += this->GetOption("CPACK_PACKAGE_ICON"); installerIconCode += "\"\n"; this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_ICON_CODE", installerIconCode.c_str()); - } - - if(this->IsSet("CPACK_NSIS_MUI_FINISHPAGE_RUN")) - { + } + + if (this->IsSet("CPACK_NSIS_MUI_WELCOMEFINISHPAGE_BITMAP")) { + std::string installerBitmapCode = + "!define MUI_WELCOMEFINISHPAGE_BITMAP \""; + installerBitmapCode += + this->GetOption("CPACK_NSIS_MUI_WELCOMEFINISHPAGE_BITMAP"); + installerBitmapCode += "\"\n"; + this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_WELCOMEFINISH_CODE", + installerBitmapCode.c_str()); + } + + if (this->IsSet("CPACK_NSIS_MUI_UNWELCOMEFINISHPAGE_BITMAP")) { + std::string installerBitmapCode = + "!define MUI_UNWELCOMEFINISHPAGE_BITMAP \""; + installerBitmapCode += + this->GetOption("CPACK_NSIS_MUI_UNWELCOMEFINISHPAGE_BITMAP"); + installerBitmapCode += "\"\n"; + this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_UNWELCOMEFINISH_CODE", + installerBitmapCode.c_str()); + } + + if (this->IsSet("CPACK_NSIS_MUI_FINISHPAGE_RUN")) { std::string installerRunCode = "!define MUI_FINISHPAGE_RUN \"$INSTDIR\\"; installerRunCode += this->GetOption("CPACK_NSIS_EXECUTABLES_DIRECTORY"); installerRunCode += "\\"; @@ -167,11 +178,10 @@ int cmCPackNSISGenerator::PackageFiles() installerRunCode += "\"\n"; this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_FINISHPAGE_RUN_CODE", installerRunCode.c_str()); - } + } // Setup all of the component sections - if (this->Components.empty()) - { + if (this->Components.empty()) { this->SetOptionIfNotSet("CPACK_NSIS_INSTALLATION_TYPES", ""); this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_COMPONENTS_DESC", ""); this->SetOptionIfNotSet("CPACK_NSIS_PAGE_COMPONENTS", ""); @@ -180,9 +190,7 @@ int cmCPackNSISGenerator::PackageFiles() this->SetOptionIfNotSet("CPACK_NSIS_COMPONENT_SECTIONS", ""); this->SetOptionIfNotSet("CPACK_NSIS_COMPONENT_SECTION_LIST", ""); this->SetOptionIfNotSet("CPACK_NSIS_SECTION_SELECTED_VARS", ""); - } - else - { + } else { std::string componentCode; std::string sectionList; std::string selectedVarsList; @@ -190,71 +198,59 @@ int cmCPackNSISGenerator::PackageFiles() std::string groupDescriptions; std::string installTypesCode; std::string defines; - cmOStringStream macrosOut; + std::ostringstream macrosOut; bool anyDownloadedComponents = false; // Create installation types. The order is significant, so we first fill // in a vector based on the indices, and print them in that order. - std::vector<cmCPackInstallationType *> - installTypes(this->InstallationTypes.size()); + std::vector<cmCPackInstallationType*> installTypes( + this->InstallationTypes.size()); std::map<std::string, cmCPackInstallationType>::iterator installTypeIt; for (installTypeIt = this->InstallationTypes.begin(); - installTypeIt != this->InstallationTypes.end(); - ++installTypeIt) - { - installTypes[installTypeIt->second.Index-1] = &installTypeIt->second; - } - std::vector<cmCPackInstallationType *>::iterator installTypeIt2; + installTypeIt != this->InstallationTypes.end(); ++installTypeIt) { + installTypes[installTypeIt->second.Index - 1] = &installTypeIt->second; + } + std::vector<cmCPackInstallationType*>::iterator installTypeIt2; for (installTypeIt2 = installTypes.begin(); - installTypeIt2 != installTypes.end(); - ++installTypeIt2) - { + installTypeIt2 != installTypes.end(); ++installTypeIt2) { installTypesCode += "InstType \""; installTypesCode += (*installTypeIt2)->DisplayName; installTypesCode += "\"\n"; - } + } // Create installation groups first std::map<std::string, cmCPackComponentGroup>::iterator groupIt; for (groupIt = this->ComponentGroups.begin(); - groupIt != this->ComponentGroups.end(); - ++groupIt) - { - if (groupIt->second.ParentGroup == 0) - { + groupIt != this->ComponentGroups.end(); ++groupIt) { + if (groupIt->second.ParentGroup == CM_NULLPTR) { componentCode += this->CreateComponentGroupDescription(&groupIt->second, macrosOut); - } + } // Add the group description, if any. - if (!groupIt->second.Description.empty()) - { - groupDescriptions += " !insertmacro MUI_DESCRIPTION_TEXT ${" - + groupIt->first + "} \"" - + this->TranslateNewlines(groupIt->second.Description) + "\"\n"; - } + if (!groupIt->second.Description.empty()) { + groupDescriptions += " !insertmacro MUI_DESCRIPTION_TEXT ${" + + groupIt->first + "} \"" + + this->TranslateNewlines(groupIt->second.Description) + "\"\n"; } + } // Create the remaining components, which aren't associated with groups. std::map<std::string, cmCPackComponent>::iterator compIt; - for (compIt = this->Components.begin(); - compIt != this->Components.end(); - ++compIt) - { - if (compIt->second.Files.empty()) - { + for (compIt = this->Components.begin(); compIt != this->Components.end(); + ++compIt) { + if (compIt->second.Files.empty()) { // NSIS cannot cope with components that have no files. continue; - } + } anyDownloadedComponents = anyDownloadedComponents || compIt->second.IsDownloaded; - if (!compIt->second.Group) - { - componentCode - += this->CreateComponentDescription(&compIt->second, macrosOut); - } + if (!compIt->second.Group) { + componentCode += + this->CreateComponentDescription(&compIt->second, macrosOut); + } // Add this component to the various section lists. sectionList += " !insertmacro \"${MacroName}\" \""; @@ -264,41 +260,33 @@ int cmCPackNSISGenerator::PackageFiles() selectedVarsList += "Var " + compIt->first + "_was_installed\n"; // Add the component description, if any. - if (!compIt->second.Description.empty()) - { - componentDescriptions += " !insertmacro MUI_DESCRIPTION_TEXT ${" - + compIt->first + "} \"" - + this->TranslateNewlines(compIt->second.Description) + "\"\n"; - } + if (!compIt->second.Description.empty()) { + componentDescriptions += " !insertmacro MUI_DESCRIPTION_TEXT ${" + + compIt->first + "} \"" + + this->TranslateNewlines(compIt->second.Description) + "\"\n"; } + } componentCode += macrosOut.str(); - if (componentDescriptions.empty() && groupDescriptions.empty()) - { + if (componentDescriptions.empty() && groupDescriptions.empty()) { // Turn off the "Description" box this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_COMPONENTS_DESC", "!define MUI_COMPONENTSPAGE_NODESC"); - } - else - { - componentDescriptions = - "!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN\n" - + componentDescriptions - + groupDescriptions - + "!insertmacro MUI_FUNCTION_DESCRIPTION_END\n"; + } else { + componentDescriptions = "!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN\n" + + componentDescriptions + groupDescriptions + + "!insertmacro MUI_FUNCTION_DESCRIPTION_END\n"; this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_COMPONENTS_DESC", componentDescriptions.c_str()); - } + } - if (anyDownloadedComponents) - { + if (anyDownloadedComponents) { defines += "!define CPACK_USES_DOWNLOAD\n"; - if (cmSystemTools::IsOn(this->GetOption("CPACK_ADD_REMOVE"))) - { + if (cmSystemTools::IsOn(this->GetOption("CPACK_ADD_REMOVE"))) { defines += "!define CPACK_NSIS_ADD_REMOVE\n"; - } } + } this->SetOptionIfNotSet("CPACK_NSIS_INSTALLATION_TYPES", installTypesCode.c_str()); @@ -312,7 +300,7 @@ int cmCPackNSISGenerator::PackageFiles() this->SetOptionIfNotSet("CPACK_NSIS_SECTION_SELECTED_VARS", selectedVarsList.c_str()); this->SetOption("CPACK_NSIS_DEFINES", defines.c_str()); - } + } this->ConfigureFile(nsisInInstallOptions.c_str(), nsisInstallOptions.c_str()); @@ -320,479 +308,412 @@ int cmCPackNSISGenerator::PackageFiles() std::string nsisCmd = "\""; nsisCmd += this->GetOption("CPACK_INSTALLER_PROGRAM"); nsisCmd += "\" \"" + nsisFileName + "\""; - cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << nsisCmd.c_str() - << std::endl); + cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << nsisCmd << std::endl); std::string output; int retVal = 1; - bool res = cmSystemTools::RunSingleCommand(nsisCmd.c_str(), &output, - &retVal, 0, this->GeneratorVerbose, 0); - if ( !res || retVal ) - { + bool res = + cmSystemTools::RunSingleCommand(nsisCmd.c_str(), &output, &output, &retVal, + CM_NULLPTR, this->GeneratorVerbose, 0); + if (!res || retVal) { cmGeneratedFileStream ofs(tmpFile.c_str()); - ofs << "# Run command: " << nsisCmd.c_str() << std::endl - << "# Output:" << std::endl - << output.c_str() << std::endl; + ofs << "# Run command: " << nsisCmd << std::endl + << "# Output:" << std::endl + << output << std::endl; cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running NSIS command: " - << nsisCmd.c_str() << std::endl - << "Please check " << tmpFile.c_str() << " for errors" << std::endl); + << nsisCmd << std::endl + << "Please check " << tmpFile << " for errors" + << std::endl); return 0; - } + } return 1; } -//---------------------------------------------------------------------- int cmCPackNSISGenerator::InitializeInternal() { - if ( cmSystemTools::IsOn(this->GetOption( - "CPACK_INCLUDE_TOPLEVEL_DIRECTORY")) ) - { - cmCPackLogger(cmCPackLog::LOG_WARNING, + if (cmSystemTools::IsOn( + this->GetOption("CPACK_INCLUDE_TOPLEVEL_DIRECTORY"))) { + cmCPackLogger( + cmCPackLog::LOG_WARNING, "NSIS Generator cannot work with CPACK_INCLUDE_TOPLEVEL_DIRECTORY set. " "This option will be reset to 0 (for this generator only)." - << std::endl); - this->SetOption("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", 0); - } + << std::endl); + this->SetOption("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", CM_NULLPTR); + } cmCPackLogger(cmCPackLog::LOG_DEBUG, "cmCPackNSISGenerator::Initialize()" - << std::endl); + << std::endl); std::vector<std::string> path; std::string nsisPath; bool gotRegValue = false; #ifdef _WIN32 - if (Nsis64) - { - if ( !gotRegValue && cmsys::SystemTools::ReadRegistryValue( - "HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS\\Unicode", nsisPath, - cmsys::SystemTools::KeyWOW64_64) ) - { + if (Nsis64) { + if (!gotRegValue && cmsys::SystemTools::ReadRegistryValue( + "HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS\\Unicode", + nsisPath, cmsys::SystemTools::KeyWOW64_64)) { gotRegValue = true; - } - if ( !gotRegValue && cmsys::SystemTools::ReadRegistryValue( - "HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS", nsisPath, - cmsys::SystemTools::KeyWOW64_64) ) - { + } + if (!gotRegValue && cmsys::SystemTools::ReadRegistryValue( + "HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS", nsisPath, + cmsys::SystemTools::KeyWOW64_64)) { gotRegValue = true; - } } - if ( !gotRegValue && cmsys::SystemTools::ReadRegistryValue( - "HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS\\Unicode", nsisPath, - cmsys::SystemTools::KeyWOW64_32) ) - { + } + if (!gotRegValue && cmsys::SystemTools::ReadRegistryValue( + "HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS\\Unicode", + nsisPath, cmsys::SystemTools::KeyWOW64_32)) { gotRegValue = true; - } - if ( !gotRegValue && cmsys::SystemTools::ReadRegistryValue( - "HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS\\Unicode", nsisPath) ) - { + } + if (!gotRegValue && + cmsys::SystemTools::ReadRegistryValue( + "HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS\\Unicode", nsisPath)) { gotRegValue = true; - } - if ( !gotRegValue && cmsys::SystemTools::ReadRegistryValue( - "HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS", nsisPath, - cmsys::SystemTools::KeyWOW64_32) ) - { + } + if (!gotRegValue && cmsys::SystemTools::ReadRegistryValue( + "HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS", nsisPath, + cmsys::SystemTools::KeyWOW64_32)) { gotRegValue = true; - } - if ( !gotRegValue && cmsys::SystemTools::ReadRegistryValue( - "HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS", nsisPath) ) - { + } + if (!gotRegValue && cmsys::SystemTools::ReadRegistryValue( + "HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS", nsisPath)) { gotRegValue = true; - } + } - if (gotRegValue) - { + if (gotRegValue) { path.push_back(nsisPath); - } + } #endif nsisPath = cmSystemTools::FindProgram("makensis", path, false); - if ( nsisPath.empty() ) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, + if (nsisPath.empty()) { + cmCPackLogger( + cmCPackLog::LOG_ERROR, "Cannot find NSIS compiler makensis: likely it is not installed, " "or not in your PATH" - << std::endl); - - if (!gotRegValue) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Could not read NSIS registry value. This is usually caused by " - "NSIS not being installed. Please install NSIS from " - "http://nsis.sourceforge.net" - << std::endl); - } + << std::endl); + + if (!gotRegValue) { + cmCPackLogger( + cmCPackLog::LOG_ERROR, + "Could not read NSIS registry value. This is usually caused by " + "NSIS not being installed. Please install NSIS from " + "http://nsis.sourceforge.net" + << std::endl); + } return 0; - } + } std::string nsisCmd = "\"" + nsisPath + "\" " NSIS_OPT "VERSION"; - cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Test NSIS version: " - << nsisCmd.c_str() << std::endl); + cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Test NSIS version: " << nsisCmd + << std::endl); std::string output; int retVal = 1; - bool resS = cmSystemTools::RunSingleCommand(nsisCmd.c_str(), - &output, &retVal, 0, this->GeneratorVerbose, 0); + bool resS = + cmSystemTools::RunSingleCommand(nsisCmd.c_str(), &output, &output, &retVal, + CM_NULLPTR, this->GeneratorVerbose, 0); cmsys::RegularExpression versionRex("v([0-9]+.[0-9]+)"); cmsys::RegularExpression versionRexCVS("v(.*)\\.cvs"); - if ( !resS || retVal || - (!versionRex.find(output) && !versionRexCVS.find(output)) - ) - { + if (!resS || retVal || + (!versionRex.find(output) && !versionRexCVS.find(output))) { const char* topDir = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); std::string tmpFile = topDir ? topDir : "."; tmpFile += "/NSISOutput.log"; cmGeneratedFileStream ofs(tmpFile.c_str()); - ofs << "# Run command: " << nsisCmd.c_str() << std::endl - << "# Output:" << std::endl - << output.c_str() << std::endl; - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Problem checking NSIS version with command: " - << nsisCmd.c_str() << std::endl - << "Please check " << tmpFile.c_str() << " for errors" << std::endl); + ofs << "# Run command: " << nsisCmd << std::endl + << "# Output:" << std::endl + << output << std::endl; + cmCPackLogger( + cmCPackLog::LOG_ERROR, "Problem checking NSIS version with command: " + << nsisCmd << std::endl + << "Please check " << tmpFile << " for errors" << std::endl); return 0; - } - if ( versionRex.find(output)) - { + } + if (versionRex.find(output)) { double nsisVersion = atof(versionRex.match(1).c_str()); double minNSISVersion = 2.09; - cmCPackLogger(cmCPackLog::LOG_DEBUG, "NSIS Version: " - << nsisVersion << std::endl); - if ( nsisVersion < minNSISVersion ) - { + cmCPackLogger(cmCPackLog::LOG_DEBUG, "NSIS Version: " << nsisVersion + << std::endl); + if (nsisVersion < minNSISVersion) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "CPack requires NSIS Version 2.09 or greater. " - "NSIS found on the system was: " - << nsisVersion << std::endl); + "CPack requires NSIS Version 2.09 or greater. " + "NSIS found on the system was: " + << nsisVersion << std::endl); return 0; - } } - if ( versionRexCVS.find(output)) - { + } + if (versionRexCVS.find(output)) { // No version check for NSIS cvs build cmCPackLogger(cmCPackLog::LOG_DEBUG, "NSIS Version: CVS " - << versionRexCVS.match(1).c_str() << std::endl); - } + << versionRexCVS.match(1) << std::endl); + } this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", nsisPath.c_str()); this->SetOptionIfNotSet("CPACK_NSIS_EXECUTABLES_DIRECTORY", "bin"); - const char* cpackPackageExecutables - = this->GetOption("CPACK_PACKAGE_EXECUTABLES"); - const char* cpackPackageDeskTopLinks - = this->GetOption("CPACK_CREATE_DESKTOP_LINKS"); - const char* cpackNsisExecutablesDirectory - = this->GetOption("CPACK_NSIS_EXECUTABLES_DIRECTORY"); + const char* cpackPackageExecutables = + this->GetOption("CPACK_PACKAGE_EXECUTABLES"); + const char* cpackPackageDeskTopLinks = + this->GetOption("CPACK_CREATE_DESKTOP_LINKS"); + const char* cpackNsisExecutablesDirectory = + this->GetOption("CPACK_NSIS_EXECUTABLES_DIRECTORY"); std::vector<std::string> cpackPackageDesktopLinksVector; - if(cpackPackageDeskTopLinks) - { + if (cpackPackageDeskTopLinks) { cmCPackLogger(cmCPackLog::LOG_DEBUG, "CPACK_CREATE_DESKTOP_LINKS: " - << cpackPackageDeskTopLinks << std::endl); - - cmSystemTools:: - ExpandListArgument(cpackPackageDeskTopLinks, - cpackPackageDesktopLinksVector); - for(std::vector<std::string>::iterator i = - cpackPackageDesktopLinksVector.begin(); i != - cpackPackageDesktopLinksVector.end(); ++i) - { - cmCPackLogger(cmCPackLog::LOG_DEBUG, "CPACK_CREATE_DESKTOP_LINKS: " - << *i << std::endl); - } + << cpackPackageDeskTopLinks << std::endl); + + cmSystemTools::ExpandListArgument(cpackPackageDeskTopLinks, + cpackPackageDesktopLinksVector); + for (std::vector<std::string>::iterator i = + cpackPackageDesktopLinksVector.begin(); + i != cpackPackageDesktopLinksVector.end(); ++i) { + cmCPackLogger(cmCPackLog::LOG_DEBUG, + "CPACK_CREATE_DESKTOP_LINKS: " << *i << std::endl); } - else - { + } else { cmCPackLogger(cmCPackLog::LOG_DEBUG, "CPACK_CREATE_DESKTOP_LINKS: " - << "not set" << std::endl); - } + << "not set" << std::endl); + } - cmOStringStream str; - cmOStringStream deleteStr; + std::ostringstream str; + std::ostringstream deleteStr; - if ( cpackPackageExecutables ) - { + if (cpackPackageExecutables) { cmCPackLogger(cmCPackLog::LOG_DEBUG, "The cpackPackageExecutables: " - << cpackPackageExecutables << "." << std::endl); + << cpackPackageExecutables << "." << std::endl); std::vector<std::string> cpackPackageExecutablesVector; cmSystemTools::ExpandListArgument(cpackPackageExecutables, - cpackPackageExecutablesVector); - if ( cpackPackageExecutablesVector.size() % 2 != 0 ) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, + cpackPackageExecutablesVector); + if (cpackPackageExecutablesVector.size() % 2 != 0) { + cmCPackLogger( + cmCPackLog::LOG_ERROR, "CPACK_PACKAGE_EXECUTABLES should contain pairs of <executable> and " - "<icon name>." << std::endl); + "<icon name>." + << std::endl); return 0; - } + } std::vector<std::string>::iterator it; - for ( it = cpackPackageExecutablesVector.begin(); - it != cpackPackageExecutablesVector.end(); - ++it ) - { + for (it = cpackPackageExecutablesVector.begin(); + it != cpackPackageExecutablesVector.end(); ++it) { std::string execName = *it; - ++ it; + ++it; std::string linkName = *it; - str << " CreateShortCut \"$SMPROGRAMS\\$STARTMENU_FOLDER\\" - << linkName << ".lnk\" \"$INSTDIR\\" - << cpackNsisExecutablesDirectory << "\\" << execName << ".exe\"" - << std::endl; + str << " CreateShortCut \"$SMPROGRAMS\\$STARTMENU_FOLDER\\" << linkName + << ".lnk\" \"$INSTDIR\\" << cpackNsisExecutablesDirectory << "\\" + << execName << ".exe\"" << std::endl; deleteStr << " Delete \"$SMPROGRAMS\\$MUI_TEMP\\" << linkName - << ".lnk\"" << std::endl; + << ".lnk\"" << std::endl; // see if CPACK_CREATE_DESKTOP_LINK_ExeName is on // if so add a desktop link - if(cpackPackageDesktopLinksVector.size() && - std::find(cpackPackageDesktopLinksVector.begin(), - cpackPackageDesktopLinksVector.end(), - execName) - != cpackPackageDesktopLinksVector.end()) - { + if (!cpackPackageDesktopLinksVector.empty() && + std::find(cpackPackageDesktopLinksVector.begin(), + cpackPackageDesktopLinksVector.end(), + execName) != cpackPackageDesktopLinksVector.end()) { str << " StrCmp \"$INSTALL_DESKTOP\" \"1\" 0 +2\n"; - str << " CreateShortCut \"$DESKTOP\\" - << linkName << ".lnk\" \"$INSTDIR\\" - << cpackNsisExecutablesDirectory << "\\" << execName << ".exe\"" - << std::endl; + str << " CreateShortCut \"$DESKTOP\\" << linkName + << ".lnk\" \"$INSTDIR\\" << cpackNsisExecutablesDirectory << "\\" + << execName << ".exe\"" << std::endl; deleteStr << " StrCmp \"$INSTALL_DESKTOP\" \"1\" 0 +2\n"; - deleteStr << " Delete \"$DESKTOP\\" << linkName - << ".lnk\"" << std::endl; - } + deleteStr << " Delete \"$DESKTOP\\" << linkName << ".lnk\"" + << std::endl; } } + } this->CreateMenuLinks(str, deleteStr); this->SetOptionIfNotSet("CPACK_NSIS_CREATE_ICONS", str.str().c_str()); - this->SetOptionIfNotSet("CPACK_NSIS_DELETE_ICONS", - deleteStr.str().c_str()); + this->SetOptionIfNotSet("CPACK_NSIS_DELETE_ICONS", deleteStr.str().c_str()); this->SetOptionIfNotSet("CPACK_NSIS_COMPRESSOR", "lzma"); return this->Superclass::InitializeInternal(); } -//---------------------------------------------------------------------- -void cmCPackNSISGenerator::CreateMenuLinks( cmOStringStream& str, - cmOStringStream& deleteStr) +void cmCPackNSISGenerator::CreateMenuLinks(std::ostream& str, + std::ostream& deleteStr) { - const char* cpackMenuLinks - = this->GetOption("CPACK_NSIS_MENU_LINKS"); - if(!cpackMenuLinks) - { + const char* cpackMenuLinks = this->GetOption("CPACK_NSIS_MENU_LINKS"); + if (!cpackMenuLinks) { return; - } - cmCPackLogger(cmCPackLog::LOG_DEBUG, "The cpackMenuLinks: " - << cpackMenuLinks << "." << std::endl); + } + cmCPackLogger(cmCPackLog::LOG_DEBUG, + "The cpackMenuLinks: " << cpackMenuLinks << "." << std::endl); std::vector<std::string> cpackMenuLinksVector; - cmSystemTools::ExpandListArgument(cpackMenuLinks, - cpackMenuLinksVector); - if ( cpackMenuLinksVector.size() % 2 != 0 ) - { + cmSystemTools::ExpandListArgument(cpackMenuLinks, cpackMenuLinksVector); + if (cpackMenuLinksVector.size() % 2 != 0) { cmCPackLogger( cmCPackLog::LOG_ERROR, "CPACK_NSIS_MENU_LINKS should contain pairs of <shortcut target> and " - "<shortcut label>." << std::endl); + "<shortcut label>." + << std::endl); return; - } + } - cmsys::RegularExpression urlRegex; - urlRegex.compile("^(mailto:|(ftps?|https?|news)://).*$"); + static cmsys::RegularExpression urlRegex( + "^(mailto:|(ftps?|https?|news)://).*$"); std::vector<std::string>::iterator it; - for ( it = cpackMenuLinksVector.begin(); - it != cpackMenuLinksVector.end(); - ++it ) - { + for (it = cpackMenuLinksVector.begin(); it != cpackMenuLinksVector.end(); + ++it) { std::string sourceName = *it; const bool url = urlRegex.find(sourceName); // Convert / to \ in filenames, but not in urls: // - if(!url) - { - cmSystemTools::ReplaceString(sourceName, "/", "\\"); - } + if (!url) { + std::replace(sourceName.begin(), sourceName.end(), '/', '\\'); + } - ++ it; + ++it; std::string linkName = *it; - if(!url) - { - str << " CreateShortCut \"$SMPROGRAMS\\$STARTMENU_FOLDER\\" - << linkName << ".lnk\" \"$INSTDIR\\" << sourceName << "\"" - << std::endl; + if (!url) { + str << " CreateShortCut \"$SMPROGRAMS\\$STARTMENU_FOLDER\\" << linkName + << ".lnk\" \"$INSTDIR\\" << sourceName << "\"" << std::endl; deleteStr << " Delete \"$SMPROGRAMS\\$MUI_TEMP\\" << linkName << ".lnk\"" << std::endl; - } - else - { - str << " WriteINIStr \"$SMPROGRAMS\\$STARTMENU_FOLDER\\" - << linkName << ".url\" \"InternetShortcut\" \"URL\" \"" - << sourceName << "\"" + } else { + str << " WriteINIStr \"$SMPROGRAMS\\$STARTMENU_FOLDER\\" << linkName + << ".url\" \"InternetShortcut\" \"URL\" \"" << sourceName << "\"" << std::endl; deleteStr << " Delete \"$SMPROGRAMS\\$MUI_TEMP\\" << linkName << ".url\"" << std::endl; - } + } // see if CPACK_CREATE_DESKTOP_LINK_ExeName is on // if so add a desktop link std::string desktop = "CPACK_CREATE_DESKTOP_LINK_"; desktop += linkName; - if(this->IsSet(desktop.c_str())) - { + if (this->IsSet(desktop)) { str << " StrCmp \"$INSTALL_DESKTOP\" \"1\" 0 +2\n"; - str << " CreateShortCut \"$DESKTOP\\" - << linkName << ".lnk\" \"$INSTDIR\\" << sourceName << "\"" - << std::endl; + str << " CreateShortCut \"$DESKTOP\\" << linkName + << ".lnk\" \"$INSTDIR\\" << sourceName << "\"" << std::endl; deleteStr << " StrCmp \"$INSTALL_DESKTOP\" \"1\" 0 +2\n"; - deleteStr << " Delete \"$DESKTOP\\" << linkName - << ".lnk\"" << std::endl; - } + deleteStr << " Delete \"$DESKTOP\\" << linkName << ".lnk\"" + << std::endl; } + } } -//---------------------------------------------------------------------- -bool cmCPackNSISGenerator::GetListOfSubdirectories(const char* topdir, - std::vector<std::string>& dirs) +bool cmCPackNSISGenerator::GetListOfSubdirectories( + const char* topdir, std::vector<std::string>& dirs) { cmsys::Directory dir; dir.Load(topdir); - size_t fileNum; - for (fileNum = 0; fileNum < dir.GetNumberOfFiles(); ++fileNum) - { - if (strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)),".") && - strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)),"..")) - { - cmsys_stl::string fullPath = topdir; - fullPath += "/"; - fullPath += dir.GetFile(static_cast<unsigned long>(fileNum)); - if(cmsys::SystemTools::FileIsDirectory(fullPath.c_str()) && - !cmsys::SystemTools::FileIsSymlink(fullPath.c_str())) - { - if (!this->GetListOfSubdirectories(fullPath.c_str(), dirs)) - { + for (unsigned long i = 0; i < dir.GetNumberOfFiles(); ++i) { + const char* fileName = dir.GetFile(i); + if (strcmp(fileName, ".") != 0 && strcmp(fileName, "..") != 0) { + std::string const fullPath = + std::string(topdir).append("/").append(fileName); + if (cmsys::SystemTools::FileIsDirectory(fullPath) && + !cmsys::SystemTools::FileIsSymlink(fullPath)) { + if (!this->GetListOfSubdirectories(fullPath.c_str(), dirs)) { return false; - } } } } + } dirs.push_back(topdir); return true; } -//---------------------------------------------------------------------- enum cmCPackGenerator::CPackSetDestdirSupport cmCPackNSISGenerator::SupportsSetDestdir() const { return cmCPackGenerator::SETDESTDIR_SHOULD_NOT_BE_USED; } -//---------------------------------------------------------------------- bool cmCPackNSISGenerator::SupportsAbsoluteDestination() const { - return false; + return false; } -//---------------------------------------------------------------------- bool cmCPackNSISGenerator::SupportsComponentInstallation() const { - return true; + return true; } -//---------------------------------------------------------------------- -std::string -cmCPackNSISGenerator:: -CreateComponentDescription(cmCPackComponent *component, - cmOStringStream& macrosOut) +std::string cmCPackNSISGenerator::CreateComponentDescription( + cmCPackComponent* component, std::ostream& macrosOut) { // Basic description of the component std::string componentCode = "Section "; - if (component->IsDisabledByDefault) - { + if (component->IsDisabledByDefault) { componentCode += "/o "; - } + } componentCode += "\""; - if (component->IsHidden) - { + if (component->IsHidden) { componentCode += "-"; - } + } componentCode += component->DisplayName + "\" " + component->Name + "\n"; - if (component->IsRequired) - { + if (component->IsRequired) { componentCode += " SectionIn RO\n"; - } - else if (!component->InstallationTypes.empty()) - { - cmOStringStream out; - std::vector<cmCPackInstallationType *>::iterator installTypeIter; + } else if (!component->InstallationTypes.empty()) { + std::ostringstream out; + std::vector<cmCPackInstallationType*>::iterator installTypeIter; for (installTypeIter = component->InstallationTypes.begin(); installTypeIter != component->InstallationTypes.end(); - ++installTypeIter) - { + ++installTypeIter) { out << " " << (*installTypeIter)->Index; - } - componentCode += " SectionIn" + out.str() + "\n"; } - componentCode += " SetOutPath \"$INSTDIR\"\n"; + componentCode += " SectionIn" + out.str() + "\n"; + } + + const std::string componentOutputDir = + CustomComponentInstallDirectory(component->Name); + componentCode += " SetOutPath \"" + componentOutputDir + "\"\n"; // Create the actual installation commands - if (component->IsDownloaded) - { - if (component->ArchiveFile.empty()) - { + if (component->IsDownloaded) { + if (component->ArchiveFile.empty()) { // Compute the name of the archive. std::string packagesDir = this->GetOption("CPACK_TEMPORARY_DIRECTORY"); packagesDir += ".dummy"; - cmOStringStream out; - out << cmSystemTools::GetFilenameWithoutLastExtension(packagesDir) - << "-" << component->Name << ".zip"; + std::ostringstream out; + out << cmSystemTools::GetFilenameWithoutLastExtension(packagesDir) << "-" + << component->Name << ".zip"; component->ArchiveFile = out.str(); - } + } // Create the directory for the upload area const char* userUploadDirectory = this->GetOption("CPACK_UPLOAD_DIRECTORY"); std::string uploadDirectory; - if (userUploadDirectory && *userUploadDirectory) - { + if (userUploadDirectory && *userUploadDirectory) { uploadDirectory = userUploadDirectory; - } - else - { - uploadDirectory= this->GetOption("CPACK_PACKAGE_DIRECTORY"); + } else { + uploadDirectory = this->GetOption("CPACK_PACKAGE_DIRECTORY"); uploadDirectory += "/CPackUploads"; - } - if(!cmSystemTools::FileExists(uploadDirectory.c_str())) - { - if (!cmSystemTools::MakeDirectory(uploadDirectory.c_str())) - { + } + if (!cmSystemTools::FileExists(uploadDirectory.c_str())) { + if (!cmSystemTools::MakeDirectory(uploadDirectory.c_str())) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Unable to create NSIS upload directory " << uploadDirectory - << std::endl); + "Unable to create NSIS upload directory " + << uploadDirectory << std::endl); return ""; - } } + } // Remove the old archive, if one exists std::string archiveFile = uploadDirectory + '/' + component->ArchiveFile; cmCPackLogger(cmCPackLog::LOG_OUTPUT, - "- Building downloaded component archive: " - << archiveFile << std::endl); - if (cmSystemTools::FileExists(archiveFile.c_str(), true)) - { - if (!cmSystemTools::RemoveFile(archiveFile.c_str())) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Unable to remove archive file " << archiveFile - << std::endl); + "- Building downloaded component archive: " << archiveFile + << std::endl); + if (cmSystemTools::FileExists(archiveFile.c_str(), true)) { + if (!cmSystemTools::RemoveFile(archiveFile)) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Unable to remove archive file " + << archiveFile << std::endl); return ""; - } } + } // Find a ZIP program - if (!this->IsSet("ZIP_EXECUTABLE")) - { + if (!this->IsSet("ZIP_EXECUTABLE")) { this->ReadListFile("CPackZIP.cmake"); - if (!this->IsSet("ZIP_EXECUTABLE")) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Unable to find ZIP program" - << std::endl); + if (!this->IsSet("ZIP_EXECUTABLE")) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Unable to find ZIP program" + << std::endl); return ""; - } } + } // The directory where this component's files reside std::string dirName = this->GetOption("CPACK_TEMPORARY_DIRECTORY"); @@ -804,29 +725,25 @@ CreateComponentDescription(cmCPackComponent *component, // size of the installed component. std::string zipListFileName = this->GetOption("CPACK_TEMPORARY_DIRECTORY"); zipListFileName += "/winZip.filelist"; - bool needQuotesInFile - = cmSystemTools::IsOn(this->GetOption("CPACK_ZIP_NEED_QUOTES")); + bool needQuotesInFile = + cmSystemTools::IsOn(this->GetOption("CPACK_ZIP_NEED_QUOTES")); unsigned long totalSize = 0; { // the scope is needed for cmGeneratedFileStream cmGeneratedFileStream out(zipListFileName.c_str()); std::vector<std::string>::iterator fileIt; - for (fileIt = component->Files.begin(); - fileIt != component->Files.end(); - ++fileIt) - { - if ( needQuotesInFile ) - { + for (fileIt = component->Files.begin(); fileIt != component->Files.end(); + ++fileIt) { + if (needQuotesInFile) { out << "\""; - } + } out << *fileIt; - if ( needQuotesInFile ) - { + if (needQuotesInFile) { out << "\""; - } + } out << std::endl; - totalSize += cmSystemTools::FileLength((dirName + *fileIt).c_str()); - } + totalSize += cmSystemTools::FileLength(dirName + *fileIt); + } } // Build the archive in the upload area @@ -836,30 +753,30 @@ CreateComponentDescription(cmCPackComponent *component, zipListFileName.c_str()); std::string output; int retVal = -1; - int res = cmSystemTools::RunSingleCommand(cmd.c_str(), &output, &retVal, - dirName.c_str(), + int res = cmSystemTools::RunSingleCommand(cmd.c_str(), &output, &output, + &retVal, dirName.c_str(), cmSystemTools::OUTPUT_NONE, 0); - if ( !res || retVal ) - { + if (!res || retVal) { std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); tmpFile += "/CompressZip.log"; cmGeneratedFileStream ofs(tmpFile.c_str()); - ofs << "# Run command: " << cmd.c_str() << std::endl - << "# Output:" << std::endl - << output.c_str() << std::endl; + ofs << "# Run command: " << cmd << std::endl + << "# Output:" << std::endl + << output << std::endl; cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running zip command: " - << cmd.c_str() << std::endl - << "Please check " << tmpFile.c_str() << " for errors" << std::endl); + << cmd << std::endl + << "Please check " << tmpFile << " for errors" + << std::endl); return ""; } // Create the NSIS code to download this file on-the-fly. unsigned long totalSizeInKbytes = (totalSize + 512) / 1024; - if (totalSizeInKbytes == 0) - { + if (totalSizeInKbytes == 0) { totalSizeInKbytes = 1; - } - cmOStringStream out; + } + std::ostringstream out; + /* clang-format off */ out << " AddSize " << totalSizeInKbytes << "\n" << " Push \"" << component->ArchiveFile << "\"\n" << " Call DownloadFile\n" @@ -869,13 +786,12 @@ CreateComponentDescription(cmCPackComponent *component, " StrCmp $2 \"success\" +2 0\n" " MessageBox MB_OK \"Failed to unzip $2\"\n" " Delete $INSTDIR\\$0\n"; + /* clang-format on */ componentCode += out.str(); - } - else - { - componentCode += " File /r \"${INST_DIR}\\" + - component->Name + "\\*.*\"\n"; - } + } else { + componentCode += + " File /r \"${INST_DIR}\\" + component->Name + "\\*.*\"\n"; + } componentCode += "SectionEnd\n"; // Macro used to remove the component @@ -884,32 +800,24 @@ CreateComponentDescription(cmCPackComponent *component, << component->Name << "\n"; std::vector<std::string>::iterator pathIt; std::string path; - for (pathIt = component->Files.begin(); - pathIt != component->Files.end(); - ++pathIt) - { + for (pathIt = component->Files.begin(); pathIt != component->Files.end(); + ++pathIt) { path = *pathIt; - cmSystemTools::ReplaceString(path, "/", "\\"); - macrosOut << " Delete \"$INSTDIR\\" - << path.c_str() - << "\"\n"; - } + std::replace(path.begin(), path.end(), '/', '\\'); + macrosOut << " Delete \"" << componentOutputDir << "\\" << path << "\"\n"; + } for (pathIt = component->Directories.begin(); - pathIt != component->Directories.end(); - ++pathIt) - { + pathIt != component->Directories.end(); ++pathIt) { path = *pathIt; - cmSystemTools::ReplaceString(path, "/", "\\"); - macrosOut << " RMDir \"$INSTDIR\\" - << path.c_str() - << "\"\n"; - } + std::replace(path.begin(), path.end(), '/', '\\'); + macrosOut << " RMDir \"" << componentOutputDir << "\\" << path << "\"\n"; + } macrosOut << " noremove_" << component->Name << ":\n"; macrosOut << "!macroend\n"; // Macro used to select each of the components that this component // depends on. - std::set<cmCPackComponent *> visited; + std::set<cmCPackComponent*> visited; macrosOut << "!macro Select_" << component->Name << "_depends\n"; macrosOut << CreateSelectionDependenciesDescription(component, visited); macrosOut << "!macroend\n"; @@ -923,24 +831,19 @@ CreateComponentDescription(cmCPackComponent *component, return componentCode; } -//---------------------------------------------------------------------- -std::string cmCPackNSISGenerator::CreateSelectionDependenciesDescription - (cmCPackComponent *component, - std::set<cmCPackComponent *>& visited) +std::string cmCPackNSISGenerator::CreateSelectionDependenciesDescription( + cmCPackComponent* component, std::set<cmCPackComponent*>& visited) { // Don't visit a component twice - if (visited.count(component)) - { + if (visited.count(component)) { return std::string(); - } + } visited.insert(component); - cmOStringStream out; - std::vector<cmCPackComponent *>::iterator dependIt; + std::ostringstream out; + std::vector<cmCPackComponent*>::iterator dependIt; for (dependIt = component->Dependencies.begin(); - dependIt != component->Dependencies.end(); - ++dependIt) - { + dependIt != component->Dependencies.end(); ++dependIt) { // Write NSIS code to select this dependency out << " SectionGetFlags ${" << (*dependIt)->Name << "} $0\n"; out << " IntOp $0 $0 | ${SF_SELECTED}\n"; @@ -949,30 +852,24 @@ std::string cmCPackNSISGenerator::CreateSelectionDependenciesDescription << "_selected 0 + ${SF_SELECTED}\n"; // Recurse out << CreateSelectionDependenciesDescription(*dependIt, visited).c_str(); - } + } return out.str(); } - -//---------------------------------------------------------------------- -std::string cmCPackNSISGenerator::CreateDeselectionDependenciesDescription - (cmCPackComponent *component, - std::set<cmCPackComponent *>& visited) +std::string cmCPackNSISGenerator::CreateDeselectionDependenciesDescription( + cmCPackComponent* component, std::set<cmCPackComponent*>& visited) { // Don't visit a component twice - if (visited.count(component)) - { + if (visited.count(component)) { return std::string(); - } + } visited.insert(component); - cmOStringStream out; - std::vector<cmCPackComponent *>::iterator dependIt; + std::ostringstream out; + std::vector<cmCPackComponent*>::iterator dependIt; for (dependIt = component->ReverseDependencies.begin(); - dependIt != component->ReverseDependencies.end(); - ++dependIt) - { + dependIt != component->ReverseDependencies.end(); ++dependIt) { // Write NSIS code to deselect this dependency out << " SectionGetFlags ${" << (*dependIt)->Name << "} $0\n"; out << " IntOp $1 ${SF_SELECTED} ~\n"; @@ -981,62 +878,59 @@ std::string cmCPackNSISGenerator::CreateDeselectionDependenciesDescription out << " IntOp $" << (*dependIt)->Name << "_selected 0 + 0\n"; // Recurse - out << - CreateDeselectionDependenciesDescription(*dependIt, visited).c_str(); - } + out + << CreateDeselectionDependenciesDescription(*dependIt, visited).c_str(); + } return out.str(); } -//---------------------------------------------------------------------- -std::string -cmCPackNSISGenerator:: -CreateComponentGroupDescription(cmCPackComponentGroup *group, - cmOStringStream& macrosOut) +std::string cmCPackNSISGenerator::CreateComponentGroupDescription( + cmCPackComponentGroup* group, std::ostream& macrosOut) { - if (group->Components.empty() && group->Subgroups.empty()) - { + if (group->Components.empty() && group->Subgroups.empty()) { // Silently skip empty groups. NSIS doesn't support them. return std::string(); - } + } std::string code = "SectionGroup "; - if (group->IsExpandedByDefault) - { + if (group->IsExpandedByDefault) { code += "/e "; - } - if (group->IsBold) - { + } + if (group->IsBold) { code += "\"!" + group->DisplayName + "\" " + group->Name + "\n"; - } - else - { + } else { code += "\"" + group->DisplayName + "\" " + group->Name + "\n"; - } + } std::vector<cmCPackComponentGroup*>::iterator groupIt; for (groupIt = group->Subgroups.begin(); groupIt != group->Subgroups.end(); - ++groupIt) - { + ++groupIt) { code += this->CreateComponentGroupDescription(*groupIt, macrosOut); - } + } std::vector<cmCPackComponent*>::iterator comp; - for (comp = group->Components.begin(); - comp != group->Components.end(); - ++comp) - { - if ((*comp)->Files.empty()) - { + for (comp = group->Components.begin(); comp != group->Components.end(); + ++comp) { + if ((*comp)->Files.empty()) { continue; - } + } code += this->CreateComponentDescription(*comp, macrosOut); - } + } code += "SectionGroupEnd\n"; return code; } +std::string cmCPackNSISGenerator::CustomComponentInstallDirectory( + const std::string& componentName) +{ + const char* outputDir = + this->GetOption("CPACK_NSIS_" + componentName + "_INSTALL_DIRECTORY"); + const std::string componentOutputDir = (outputDir ? outputDir : "$INSTDIR"); + return componentOutputDir; +} + std::string cmCPackNSISGenerator::TranslateNewlines(std::string str) { cmSystemTools::ReplaceString(str, "\n", "$\\r$\\n"); diff --git a/Source/CPack/cmCPackNSISGenerator.h b/Source/CPack/cmCPackNSISGenerator.h index e46fbdab7..77be3256d 100644 --- a/Source/CPack/cmCPackNSISGenerator.h +++ b/Source/CPack/cmCPackNSISGenerator.h @@ -1,21 +1,19 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc. - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #ifndef cmCPackNSISGenerator_h #define cmCPackNSISGenerator_h +#include "cmConfigure.h" #include "cmCPackGenerator.h" + +#include <iosfwd> #include <set> +#include <string> +#include <vector> + +class cmCPackComponent; +class cmCPackComponentGroup; /** \class cmCPackNSISGenerator * \brief A generator for NSIS files @@ -28,54 +26,57 @@ public: cmCPackTypeMacro(cmCPackNSISGenerator, cmCPackGenerator); static cmCPackGenerator* CreateGenerator64() - { return new cmCPackNSISGenerator(true); } + { + return new cmCPackNSISGenerator(true); + } /** * Construct generator */ cmCPackNSISGenerator(bool nsis64 = false); - virtual ~cmCPackNSISGenerator(); + ~cmCPackNSISGenerator() CM_OVERRIDE; protected: - virtual int InitializeInternal(); - void CreateMenuLinks( cmOStringStream& str, - cmOStringStream& deleteStr); - int PackageFiles(); - virtual const char* GetOutputExtension() { return ".exe"; } - virtual const char* GetOutputPostfix() { return "win32"; } + int InitializeInternal() CM_OVERRIDE; + void CreateMenuLinks(std::ostream& str, std::ostream& deleteStr); + int PackageFiles() CM_OVERRIDE; + const char* GetOutputExtension() CM_OVERRIDE { return ".exe"; } + const char* GetOutputPostfix() CM_OVERRIDE { return "win32"; } bool GetListOfSubdirectories(const char* dir, - std::vector<std::string>& dirs); + std::vector<std::string>& dirs); - enum cmCPackGenerator::CPackSetDestdirSupport SupportsSetDestdir() const; - virtual bool SupportsAbsoluteDestination() const; - virtual bool SupportsComponentInstallation() const; + enum cmCPackGenerator::CPackSetDestdirSupport SupportsSetDestdir() const + CM_OVERRIDE; + bool SupportsAbsoluteDestination() const CM_OVERRIDE; + bool SupportsComponentInstallation() const CM_OVERRIDE; /// Produce a string that contains the NSIS code to describe a /// particular component. Any added macros will be emitted via /// macrosOut. - std::string - CreateComponentDescription(cmCPackComponent *component, - cmOStringStream& macrosOut); + std::string CreateComponentDescription(cmCPackComponent* component, + std::ostream& macrosOut); /// Produce NSIS code that selects all of the components that this component /// depends on, recursively. - std::string CreateSelectionDependenciesDescription - (cmCPackComponent *component, - std::set<cmCPackComponent *>& visited); + std::string CreateSelectionDependenciesDescription( + cmCPackComponent* component, std::set<cmCPackComponent*>& visited); /// Produce NSIS code that de-selects all of the components that are /// dependent on this component, recursively. - std::string CreateDeselectionDependenciesDescription - (cmCPackComponent *component, - std::set<cmCPackComponent *>& visited); + std::string CreateDeselectionDependenciesDescription( + cmCPackComponent* component, std::set<cmCPackComponent*>& visited); /// Produce a string that contains the NSIS code to describe a /// particular component group, including its components. Any /// added macros will be emitted via macrosOut. - std::string - CreateComponentGroupDescription(cmCPackComponentGroup *group, - cmOStringStream& macrosOut); + std::string CreateComponentGroupDescription(cmCPackComponentGroup* group, + std::ostream& macrosOut); + + /// Returns the custom install directory if available for the specified + /// component, otherwise $INSTDIR is returned. + std::string CustomComponentInstallDirectory( + const std::string& componentName); /// Translations any newlines found in the string into \\r\\n, so that the /// resulting string can be used within NSIS. diff --git a/Source/CPack/cmCPackOSXX11Generator.cxx b/Source/CPack/cmCPackOSXX11Generator.cxx index 76e15fb84..8ea88a87a 100644 --- a/Source/CPack/cmCPackOSXX11Generator.cxx +++ b/Source/CPack/cmCPackOSXX11Generator.cxx @@ -1,79 +1,60 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCPackOSXX11Generator.h" -#include "cmake.h" -#include "cmGlobalGenerator.h" -#include "cmLocalGenerator.h" -#include "cmSystemTools.h" -#include "cmMakefile.h" -#include "cmGeneratedFileStream.h" -#include "cmCPackLog.h" +#include <sstream> -#include <cmsys/SystemTools.hxx> -#include <cmsys/Glob.hxx> -#include <sys/stat.h> +#include "cmCPackGenerator.h" +#include "cmCPackLog.h" +#include "cmGeneratedFileStream.h" +#include "cmSystemTools.h" +#include "cm_sys_stat.h" -//---------------------------------------------------------------------- cmCPackOSXX11Generator::cmCPackOSXX11Generator() { } -//---------------------------------------------------------------------- cmCPackOSXX11Generator::~cmCPackOSXX11Generator() { } -//---------------------------------------------------------------------- int cmCPackOSXX11Generator::PackageFiles() { // TODO: Use toplevel ? // It is used! Is this an obsolete comment? - const char* cpackPackageExecutables - = this->GetOption("CPACK_PACKAGE_EXECUTABLES"); - if ( cpackPackageExecutables ) - { + const char* cpackPackageExecutables = + this->GetOption("CPACK_PACKAGE_EXECUTABLES"); + if (cpackPackageExecutables) { cmCPackLogger(cmCPackLog::LOG_DEBUG, "The cpackPackageExecutables: " - << cpackPackageExecutables << "." << std::endl); - cmOStringStream str; - cmOStringStream deleteStr; + << cpackPackageExecutables << "." << std::endl); + std::ostringstream str; + std::ostringstream deleteStr; std::vector<std::string> cpackPackageExecutablesVector; cmSystemTools::ExpandListArgument(cpackPackageExecutables, - cpackPackageExecutablesVector); - if ( cpackPackageExecutablesVector.size() % 2 != 0 ) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, + cpackPackageExecutablesVector); + if (cpackPackageExecutablesVector.size() % 2 != 0) { + cmCPackLogger( + cmCPackLog::LOG_ERROR, "CPACK_PACKAGE_EXECUTABLES should contain pairs of <executable> and " - "<icon name>." << std::endl); + "<icon name>." + << std::endl); return 0; - } + } std::vector<std::string>::iterator it; - for ( it = cpackPackageExecutablesVector.begin(); - it != cpackPackageExecutablesVector.end(); - ++it ) - { + for (it = cpackPackageExecutablesVector.begin(); + it != cpackPackageExecutablesVector.end(); ++it) { std::string cpackExecutableName = *it; - ++ it; + ++it; this->SetOptionIfNotSet("CPACK_EXECUTABLE_NAME", - cpackExecutableName.c_str()); - } + cpackExecutableName.c_str()); } + } // Disk image directories std::string diskImageDirectory = toplevel; - std::string diskImageBackgroundImageDir - = diskImageDirectory + "/.background"; - + std::string diskImageBackgroundImageDir = + diskImageDirectory + "/.background"; // App bundle directories std::string packageDirFileName = toplevel; @@ -93,48 +74,44 @@ int cmCPackOSXX11Generator::PackageFiles() const char* contDir = contentsDirectory.c_str(); const char* rsrcFile = resourceFileName.c_str(); const char* iconFile = this->GetOption("CPACK_PACKAGE_ICON"); - if ( iconFile ) - { - std::string iconFileName = cmsys::SystemTools::GetFilenameName( - iconFile); - if ( !cmSystemTools::FileExists(iconFile) ) - { + if (iconFile) { + std::string iconFileName = cmsys::SystemTools::GetFilenameName(iconFile); + if (!cmSystemTools::FileExists(iconFile)) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find icon file: " - << iconFile << ". Please check CPACK_PACKAGE_ICON setting." - << std::endl); + << iconFile + << ". Please check CPACK_PACKAGE_ICON setting." + << std::endl); return 0; - } + } std::string destFileName = resourcesDirectory + "/" + iconFileName; this->ConfigureFile(iconFile, destFileName.c_str(), true); this->SetOptionIfNotSet("CPACK_APPLE_GUI_ICON", iconFileName.c_str()); - } + } std::string applicationsLinkName = diskImageDirectory + "/Applications"; - cmSystemTools::CreateSymlink("/Applications", applicationsLinkName.c_str()); + cmSystemTools::CreateSymlink("/Applications", applicationsLinkName); - if ( - !this->CopyResourcePlistFile("VolumeIcon.icns", - diskImageDirectory.c_str(), - ".VolumeIcon.icns", true ) || - !this->CopyResourcePlistFile("DS_Store", diskImageDirectory.c_str(), - ".DS_Store", true ) || - !this->CopyResourcePlistFile("background.png", - diskImageBackgroundImageDir.c_str(), "background.png", true ) || - !this->CopyResourcePlistFile("RuntimeScript", dir) || - !this->CopyResourcePlistFile("OSXX11.Info.plist", contDir, - "Info.plist" ) || - !this->CopyResourcePlistFile("OSXX11.main.scpt", scrDir, - "main.scpt", true ) || - !this->CopyResourcePlistFile("OSXScriptLauncher.rsrc", dir, - rsrcFile, true) || - !this->CopyResourcePlistFile("OSXScriptLauncher", appdir, - this->GetOption("CPACK_PACKAGE_FILE_NAME"), true) - ) - { + if (!this->CopyResourcePlistFile("VolumeIcon.icns", diskImageDirectory, + ".VolumeIcon.icns", true) || + !this->CopyResourcePlistFile("DS_Store", diskImageDirectory, ".DS_Store", + true) || + !this->CopyResourcePlistFile("background.png", + diskImageBackgroundImageDir, + "background.png", true) || + !this->CopyResourcePlistFile("RuntimeScript", dir) || + !this->CopyResourcePlistFile("OSXX11.Info.plist", contDir, + "Info.plist") || + !this->CopyResourcePlistFile("OSXX11.main.scpt", scrDir, "main.scpt", + true) || + !this->CopyResourcePlistFile("OSXScriptLauncher.rsrc", dir, rsrcFile, + true) || + !this->CopyResourcePlistFile("OSXScriptLauncher", appdir, + this->GetOption("CPACK_PACKAGE_FILE_NAME"), + true)) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying the resource files" - << std::endl); + << std::endl); return 0; - } + } // Two of the files need to have execute permission, so ensure they do: std::string runTimeScript = dir; @@ -146,88 +123,81 @@ int cmCPackOSXX11Generator::PackageFiles() appScriptName += this->GetOption("CPACK_PACKAGE_FILE_NAME"); mode_t mode; - if (cmsys::SystemTools::GetPermissions(runTimeScript.c_str(), mode)) - { + if (cmsys::SystemTools::GetPermissions(runTimeScript.c_str(), mode)) { mode |= (S_IXUSR | S_IXGRP | S_IXOTH); cmsys::SystemTools::SetPermissions(runTimeScript.c_str(), mode); - cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Setting: " << runTimeScript - << " to permission: " << mode << std::endl); - } + cmCPackLogger(cmCPackLog::LOG_OUTPUT, + "Setting: " << runTimeScript << " to permission: " << mode + << std::endl); + } - if (cmsys::SystemTools::GetPermissions(appScriptName.c_str(), mode)) - { + if (cmsys::SystemTools::GetPermissions(appScriptName.c_str(), mode)) { mode |= (S_IXUSR | S_IXGRP | S_IXOTH); cmsys::SystemTools::SetPermissions(appScriptName.c_str(), mode); - cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Setting: " << appScriptName - << " to permission: " << mode << std::endl); - } + cmCPackLogger(cmCPackLog::LOG_OUTPUT, + "Setting: " << appScriptName << " to permission: " << mode + << std::endl); + } std::string output; std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); tmpFile += "/hdiutilOutput.log"; - cmOStringStream dmgCmd; + std::ostringstream dmgCmd; dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE") - << "\" create -ov -format UDZO -srcfolder \"" - << diskImageDirectory.c_str() + << "\" create -ov -format UDZO -srcfolder \"" << diskImageDirectory << "\" \"" << packageFileNames[0] << "\""; - cmCPackLogger(cmCPackLog::LOG_VERBOSE, - "Compress disk image using command: " - << dmgCmd.str().c_str() << std::endl); + cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Compress disk image using command: " + << dmgCmd.str() << std::endl); // since we get random dashboard failures with this one // try running it more than once int retVal = 1; int numTries = 10; bool res = false; - while(numTries > 0) - { - res = cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output, - &retVal, 0, - this->GeneratorVerbose, 0); - if ( res && !retVal ) - { + while (numTries > 0) { + res = + cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output, &output, + &retVal, 0, this->GeneratorVerbose, 0); + if (res && !retVal) { numTries = -1; break; - } + } cmSystemTools::Delay(500); numTries--; - } - if ( !res || retVal ) - { + } + if (!res || retVal) { cmGeneratedFileStream ofs(tmpFile.c_str()); - ofs << "# Run command: " << dmgCmd.str().c_str() << std::endl - << "# Output:" << std::endl - << output.c_str() << std::endl; + ofs << "# Run command: " << dmgCmd.str() << std::endl + << "# Output:" << std::endl + << output << std::endl; cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running hdiutil command: " - << dmgCmd.str().c_str() << std::endl - << "Please check " << tmpFile.c_str() << " for errors" << std::endl); + << dmgCmd.str() << std::endl + << "Please check " << tmpFile << " for errors" + << std::endl); return 0; - } + } return 1; } -//---------------------------------------------------------------------- int cmCPackOSXX11Generator::InitializeInternal() { - cmCPackLogger(cmCPackLog::LOG_DEBUG, - "cmCPackOSXX11Generator::Initialize()" << std::endl); + cmCPackLogger(cmCPackLog::LOG_DEBUG, "cmCPackOSXX11Generator::Initialize()" + << std::endl); std::vector<std::string> path; std::string pkgPath = cmSystemTools::FindProgram("hdiutil", path, false); - if ( pkgPath.empty() ) - { + if (pkgPath.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find hdiutil compiler" - << std::endl); + << std::endl); return 0; - } + } this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM_DISK_IMAGE", pkgPath.c_str()); return this->Superclass::InitializeInternal(); } -//---------------------------------------------------------------------- /* -bool cmCPackOSXX11Generator::CopyCreateResourceFile(const char* name) +bool cmCPackOSXX11Generator::CopyCreateResourceFile(const std::string& name) { std::string uname = cmSystemTools::UpperCase(name); std::string cpackVar = "CPACK_RESOURCE_FILE_" + uname; @@ -264,44 +234,40 @@ bool cmCPackOSXX11Generator::CopyCreateResourceFile(const char* name) cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " << (inFileName ? inFileName : "(NULL)") - << " to " << destFileName.c_str() << std::endl); + << " to " << destFileName << std::endl); this->ConfigureFile(inFileName, destFileName.c_str()); return true; } */ -//---------------------------------------------------------------------- -bool cmCPackOSXX11Generator::CopyResourcePlistFile(const char* name, - const char* dir, const char* outputFileName /* = 0 */, - bool copyOnly /* = false */) +bool cmCPackOSXX11Generator::CopyResourcePlistFile( + const std::string& name, const std::string& dir, + const char* outputFileName /* = 0 */, bool copyOnly /* = false */) { std::string inFName = "CPack."; inFName += name; inFName += ".in"; std::string inFileName = this->FindTemplate(inFName.c_str()); - if ( inFileName.empty() ) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find input file: " - << inFName << std::endl); + if (inFileName.empty()) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Cannot find input file: " << inFName << std::endl); return false; - } + } - if ( !outputFileName ) - { - outputFileName = name; - } + if (!outputFileName) { + outputFileName = name.c_str(); + } std::string destFileName = dir; destFileName += "/"; destFileName += outputFileName; cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " - << inFileName.c_str() << " to " << destFileName.c_str() << std::endl); + << inFileName << " to " << destFileName << std::endl); this->ConfigureFile(inFileName.c_str(), destFileName.c_str(), copyOnly); return true; } -//---------------------------------------------------------------------- const char* cmCPackOSXX11Generator::GetPackagingInstallPrefix() { this->InstallPrefix = "/"; diff --git a/Source/CPack/cmCPackOSXX11Generator.h b/Source/CPack/cmCPackOSXX11Generator.h index b7bd24396..0eebc6dd1 100644 --- a/Source/CPack/cmCPackOSXX11Generator.h +++ b/Source/CPack/cmCPackOSXX11Generator.h @@ -1,18 +1,12 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc. - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #ifndef cmCPackOSXX11Generator_h #define cmCPackOSXX11Generator_h +#include "cmConfigure.h" + +#include <string> + #include "cmCPackGenerator.h" /** \class cmCPackOSXX11Generator @@ -32,14 +26,16 @@ public: virtual ~cmCPackOSXX11Generator(); protected: - virtual int InitializeInternal(); - int PackageFiles(); - virtual const char* GetPackagingInstallPrefix(); - virtual const char* GetOutputExtension() { return ".dmg"; } - - //bool CopyCreateResourceFile(const char* name, const char* dir); - bool CopyResourcePlistFile(const char* name, const char* dir, - const char* outputFileName = 0, bool copyOnly = false); + virtual int InitializeInternal() CM_OVERRIDE; + int PackageFiles() CM_OVERRIDE; + const char* GetPackagingInstallPrefix() CM_OVERRIDE; + const char* GetOutputExtension() CM_OVERRIDE { return ".dmg"; } + + // bool CopyCreateResourceFile(const std::string& name, + // const std::string& dir); + bool CopyResourcePlistFile(const std::string& name, const std::string& dir, + const char* outputFileName = 0, + bool copyOnly = false); std::string InstallPrefix; }; diff --git a/Source/CPack/cmCPackPKGGenerator.cxx b/Source/CPack/cmCPackPKGGenerator.cxx new file mode 100644 index 000000000..70ae267fb --- /dev/null +++ b/Source/CPack/cmCPackPKGGenerator.cxx @@ -0,0 +1,352 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmCPackPKGGenerator.h" + +#include <vector> + +#include "cmCPackComponentGroup.h" +#include "cmCPackGenerator.h" +#include "cmCPackLog.h" +#include "cmSystemTools.h" +#include "cmXMLWriter.h" + +cmCPackPKGGenerator::cmCPackPKGGenerator() +{ + this->componentPackageMethod = ONE_PACKAGE; +} + +cmCPackPKGGenerator::~cmCPackPKGGenerator() +{ +} + +bool cmCPackPKGGenerator::SupportsComponentInstallation() const +{ + return true; +} + +int cmCPackPKGGenerator::InitializeInternal() +{ + cmCPackLogger(cmCPackLog::LOG_DEBUG, "cmCPackPKGGenerator::Initialize()" + << std::endl); + + return this->Superclass::InitializeInternal(); +} + +std::string cmCPackPKGGenerator::GetPackageName( + const cmCPackComponent& component) +{ + if (component.ArchiveFile.empty()) { + std::string packagesDir = this->GetOption("CPACK_TEMPORARY_DIRECTORY"); + packagesDir += ".dummy"; + std::ostringstream out; + out << cmSystemTools::GetFilenameWithoutLastExtension(packagesDir) << "-" + << component.Name << ".pkg"; + return out.str(); + } else { + return component.ArchiveFile + ".pkg"; + } +} + +void cmCPackPKGGenerator::WriteDistributionFile(const char* metapackageFile) +{ + std::string distributionTemplate = + this->FindTemplate("CPack.distribution.dist.in"); + if (distributionTemplate.empty()) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find input file: " + << distributionTemplate << std::endl); + return; + } + + std::string distributionFile = metapackageFile; + distributionFile += "/Contents/distribution.dist"; + + // Create the choice outline, which provides a tree-based view of + // the components in their groups. + std::ostringstream choiceOut; + cmXMLWriter xout(choiceOut, 1); + xout.StartElement("choices-outline"); + + // Emit the outline for the groups + std::map<std::string, cmCPackComponentGroup>::iterator groupIt; + for (groupIt = this->ComponentGroups.begin(); + groupIt != this->ComponentGroups.end(); ++groupIt) { + if (groupIt->second.ParentGroup == 0) { + CreateChoiceOutline(groupIt->second, xout); + } + } + + // Emit the outline for the non-grouped components + std::map<std::string, cmCPackComponent>::iterator compIt; + for (compIt = this->Components.begin(); compIt != this->Components.end(); + ++compIt) { + if (!compIt->second.Group) { + xout.StartElement("line"); + xout.Attribute("choice", compIt->first + "Choice"); + xout.Content(""); // Avoid self-closing tag. + xout.EndElement(); + } + } + if (!this->PostFlightComponent.Name.empty()) { + xout.StartElement("line"); + xout.Attribute("choice", PostFlightComponent.Name + "Choice"); + xout.Content(""); // Avoid self-closing tag. + xout.EndElement(); + } + xout.EndElement(); // choices-outline> + + // Create the actual choices + for (groupIt = this->ComponentGroups.begin(); + groupIt != this->ComponentGroups.end(); ++groupIt) { + CreateChoice(groupIt->second, xout); + } + for (compIt = this->Components.begin(); compIt != this->Components.end(); + ++compIt) { + CreateChoice(compIt->second, xout); + } + + if (!this->PostFlightComponent.Name.empty()) { + CreateChoice(PostFlightComponent, xout); + } + + this->SetOption("CPACK_PACKAGEMAKER_CHOICES", choiceOut.str().c_str()); + + // Create the distribution.dist file in the metapackage to turn it + // into a distribution package. + this->ConfigureFile(distributionTemplate.c_str(), distributionFile.c_str()); +} + +void cmCPackPKGGenerator::CreateChoiceOutline( + const cmCPackComponentGroup& group, cmXMLWriter& xout) +{ + xout.StartElement("line"); + xout.Attribute("choice", group.Name + "Choice"); + std::vector<cmCPackComponentGroup*>::const_iterator groupIt; + for (groupIt = group.Subgroups.begin(); groupIt != group.Subgroups.end(); + ++groupIt) { + CreateChoiceOutline(**groupIt, xout); + } + + std::vector<cmCPackComponent*>::const_iterator compIt; + for (compIt = group.Components.begin(); compIt != group.Components.end(); + ++compIt) { + xout.StartElement("line"); + xout.Attribute("choice", (*compIt)->Name + "Choice"); + xout.Content(""); // Avoid self-closing tag. + xout.EndElement(); + } + xout.EndElement(); +} + +void cmCPackPKGGenerator::CreateChoice(const cmCPackComponentGroup& group, + cmXMLWriter& xout) +{ + xout.StartElement("choice"); + xout.Attribute("id", group.Name + "Choice"); + xout.Attribute("title", group.DisplayName); + xout.Attribute("start_selected", "true"); + xout.Attribute("start_enabled", "true"); + xout.Attribute("start_visible", "true"); + if (!group.Description.empty()) { + xout.Attribute("description", group.Description); + } + xout.EndElement(); +} + +void cmCPackPKGGenerator::CreateChoice(const cmCPackComponent& component, + cmXMLWriter& xout) +{ + std::string packageId = "com."; + packageId += this->GetOption("CPACK_PACKAGE_VENDOR"); + packageId += '.'; + packageId += this->GetOption("CPACK_PACKAGE_NAME"); + packageId += '.'; + packageId += component.Name; + + xout.StartElement("choice"); + xout.Attribute("id", component.Name + "Choice"); + xout.Attribute("title", component.DisplayName); + xout.Attribute( + "start_selected", + component.IsDisabledByDefault && !component.IsRequired ? "false" : "true"); + xout.Attribute("start_enabled", component.IsRequired ? "false" : "true"); + xout.Attribute("start_visible", component.IsHidden ? "false" : "true"); + if (!component.Description.empty()) { + xout.Attribute("description", component.Description); + } + if (!component.Dependencies.empty() || + !component.ReverseDependencies.empty()) { + // The "selected" expression is evaluated each time any choice is + // selected, for all choices *except* the one that the user + // selected. A component is marked selected if it has been + // selected (my.choice.selected in Javascript) and all of the + // components it depends on have been selected (transitively) or + // if any of the components that depend on it have been selected + // (transitively). Assume that we have components A, B, C, D, and + // E, where each component depends on the previous component (B + // depends on A, C depends on B, D depends on C, and E depends on + // D). The expression we build for the component C will be + // my.choice.selected && B && A || D || E + // This way, selecting C will automatically select everything it depends + // on (B and A), while selecting something that depends on C--either D + // or E--will automatically cause C to get selected. + std::ostringstream selected("my.choice.selected"); + std::set<const cmCPackComponent*> visited; + AddDependencyAttributes(component, visited, selected); + visited.clear(); + AddReverseDependencyAttributes(component, visited, selected); + xout.Attribute("selected", selected.str()); + } + xout.StartElement("pkg-ref"); + xout.Attribute("id", packageId); + xout.EndElement(); // pkg-ref + xout.EndElement(); // choice + + // Create a description of the package associated with this + // component. + std::string relativePackageLocation = "Contents/Packages/"; + relativePackageLocation += this->GetPackageName(component); + + // Determine the installed size of the package. + std::string dirName = this->GetOption("CPACK_TEMPORARY_DIRECTORY"); + dirName += '/'; + dirName += component.Name; + dirName += this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX"); + unsigned long installedSize = component.GetInstalledSizeInKbytes(dirName); + + xout.StartElement("pkg-ref"); + xout.Attribute("id", packageId); + xout.Attribute("version", this->GetOption("CPACK_PACKAGE_VERSION")); + xout.Attribute("installKBytes", installedSize); + xout.Attribute("auth", "Admin"); + xout.Attribute("onConclusion", "None"); + if (component.IsDownloaded) { + xout.Content(this->GetOption("CPACK_DOWNLOAD_SITE")); + xout.Content(this->GetPackageName(component)); + } else { + xout.Content("file:./"); + xout.Content(relativePackageLocation); + } + xout.EndElement(); // pkg-ref +} + +void cmCPackPKGGenerator::AddDependencyAttributes( + const cmCPackComponent& component, + std::set<const cmCPackComponent*>& visited, std::ostringstream& out) +{ + if (visited.find(&component) != visited.end()) { + return; + } + visited.insert(&component); + + std::vector<cmCPackComponent*>::const_iterator dependIt; + for (dependIt = component.Dependencies.begin(); + dependIt != component.Dependencies.end(); ++dependIt) { + out << " && choices['" << (*dependIt)->Name << "Choice'].selected"; + AddDependencyAttributes(**dependIt, visited, out); + } +} + +void cmCPackPKGGenerator::AddReverseDependencyAttributes( + const cmCPackComponent& component, + std::set<const cmCPackComponent*>& visited, std::ostringstream& out) +{ + if (visited.find(&component) != visited.end()) { + return; + } + visited.insert(&component); + + std::vector<cmCPackComponent*>::const_iterator dependIt; + for (dependIt = component.ReverseDependencies.begin(); + dependIt != component.ReverseDependencies.end(); ++dependIt) { + out << " || choices['" << (*dependIt)->Name << "Choice'].selected"; + AddReverseDependencyAttributes(**dependIt, visited, out); + } +} + +bool cmCPackPKGGenerator::CopyCreateResourceFile(const std::string& name, + const std::string& dirName) +{ + std::string uname = cmSystemTools::UpperCase(name); + std::string cpackVar = "CPACK_RESOURCE_FILE_" + uname; + const char* inFileName = this->GetOption(cpackVar); + if (!inFileName) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "CPack option: " + << cpackVar.c_str() + << " not specified. It should point to " + << (!name.empty() ? name : "<empty>") << ".rtf, " << name + << ".html, or " << name << ".txt file" << std::endl); + return false; + } + if (!cmSystemTools::FileExists(inFileName)) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find " + << (!name.empty() ? name : "<empty>") + << " resource file: " << inFileName << std::endl); + return false; + } + std::string ext = cmSystemTools::GetFilenameLastExtension(inFileName); + if (ext != ".rtfd" && ext != ".rtf" && ext != ".html" && ext != ".txt") { + cmCPackLogger( + cmCPackLog::LOG_ERROR, "Bad file extension specified: " + << ext + << ". Currently only .rtfd, .rtf, .html, and .txt files allowed." + << std::endl); + return false; + } + + std::string destFileName = dirName; + destFileName += '/'; + destFileName += name + ext; + + // Set this so that distribution.dist gets the right name (without + // the path). + this->SetOption("CPACK_RESOURCE_FILE_" + uname + "_NOPATH", + (name + ext).c_str()); + + cmCPackLogger(cmCPackLog::LOG_VERBOSE, + "Configure file: " << (inFileName ? inFileName : "(NULL)") + << " to " << destFileName << std::endl); + this->ConfigureFile(inFileName, destFileName.c_str()); + return true; +} + +bool cmCPackPKGGenerator::CopyResourcePlistFile(const std::string& name, + const char* outName) +{ + if (!outName) { + outName = name.c_str(); + } + + std::string inFName = "CPack."; + inFName += name; + inFName += ".in"; + std::string inFileName = this->FindTemplate(inFName.c_str()); + if (inFileName.empty()) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Cannot find input file: " << inFName << std::endl); + return false; + } + + std::string destFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); + destFileName += "/"; + destFileName += outName; + + cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " + << inFileName << " to " << destFileName << std::endl); + this->ConfigureFile(inFileName.c_str(), destFileName.c_str()); + return true; +} + +int cmCPackPKGGenerator::CopyInstallScript(const std::string& resdir, + const std::string& script, + const std::string& name) +{ + std::string dst = resdir; + dst += "/"; + dst += name; + cmSystemTools::CopyFileAlways(script, dst); + cmSystemTools::SetPermissions(dst.c_str(), 0777); + cmCPackLogger(cmCPackLog::LOG_VERBOSE, + "copy script : " << script << "\ninto " << dst << std::endl); + + return 1; +} diff --git a/Source/CPack/cmCPackPKGGenerator.h b/Source/CPack/cmCPackPKGGenerator.h new file mode 100644 index 000000000..f873c5936 --- /dev/null +++ b/Source/CPack/cmCPackPKGGenerator.h @@ -0,0 +1,92 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmCPackPKGGenerator_h +#define cmCPackPKGGenerator_h + +#include "cmConfigure.h" + +#include <set> +#include <sstream> +#include <string> + +#include "cmCPackComponentGroup.h" +#include "cmCPackGenerator.h" + +class cmXMLWriter; + +/** \class cmCPackPKGGenerator + * \brief A generator for pkg files + * + */ +class cmCPackPKGGenerator : public cmCPackGenerator +{ +public: + cmCPackTypeMacro(cmCPackPKGGenerator, cmCPackGenerator); + + /** + * Construct generator + */ + cmCPackPKGGenerator(); + virtual ~cmCPackPKGGenerator(); + + bool SupportsComponentInstallation() const CM_OVERRIDE; + +protected: + int InitializeInternal() CM_OVERRIDE; + const char* GetOutputPostfix() CM_OVERRIDE { return "darwin"; } + + // Copies or creates the resource file with the given name to the + // package or package staging directory dirName. The variable + // CPACK_RESOURCE_FILE_${NAME} (where ${NAME} is the uppercased + // version of name) specifies the input file to use for this file, + // which will be configured via ConfigureFile. + bool CopyCreateResourceFile(const std::string& name, + const std::string& dirName); + bool CopyResourcePlistFile(const std::string& name, const char* outName = 0); + + int CopyInstallScript(const std::string& resdir, const std::string& script, + const std::string& name); + + // Retrieve the name of package file that will be generated for this + // component. The name is just the file name with extension, and + // does not include the subdirectory. + std::string GetPackageName(const cmCPackComponent& component); + + // Writes a distribution.dist file, which turns a metapackage into a + // full-fledged distribution. This file is used to describe + // inter-component dependencies. metapackageFile is the name of the + // metapackage for the distribution. Only valid for a + // component-based install. + void WriteDistributionFile(const char* metapackageFile); + + // Subroutine of WriteDistributionFile that writes out the + // dependency attributes for inter-component dependencies. + void AddDependencyAttributes(const cmCPackComponent& component, + std::set<const cmCPackComponent*>& visited, + std::ostringstream& out); + + // Subroutine of WriteDistributionFile that writes out the + // reverse dependency attributes for inter-component dependencies. + void AddReverseDependencyAttributes( + const cmCPackComponent& component, + std::set<const cmCPackComponent*>& visited, std::ostringstream& out); + + // Generates XML that encodes the hierarchy of component groups and + // their components in a form that can be used by distribution + // metapackages. + void CreateChoiceOutline(const cmCPackComponentGroup& group, + cmXMLWriter& xout); + + /// Create the "choice" XML element to describe a component group + /// for the installer GUI. + void CreateChoice(const cmCPackComponentGroup& group, cmXMLWriter& xout); + + /// Create the "choice" XML element to describe a component for the + /// installer GUI. + void CreateChoice(const cmCPackComponent& component, cmXMLWriter& xout); + + // The PostFlight component when creating a metapackage + cmCPackComponent PostFlightComponent; +}; + +#endif diff --git a/Source/CPack/cmCPackPackageMakerGenerator.cxx b/Source/CPack/cmCPackPackageMakerGenerator.cxx index c617a3e32..8db7cfb3d 100644 --- a/Source/CPack/cmCPackPackageMakerGenerator.cxx +++ b/Source/CPack/cmCPackPackageMakerGenerator.cxx @@ -1,166 +1,123 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCPackPackageMakerGenerator.h" -#include "cmake.h" -#include "cmGlobalGenerator.h" -#include "cmLocalGenerator.h" -#include "cmSystemTools.h" -#include "cmMakefile.h" -#include "cmGeneratedFileStream.h" +#include "cmsys/FStream.hxx" +#include "cmsys/RegularExpression.hxx" +#include <assert.h> +#include <map> +#include <sstream> +#include <stdio.h> +#include <stdlib.h> +#include <string> + #include "cmCPackComponentGroup.h" #include "cmCPackLog.h" +#include "cmGeneratedFileStream.h" +#include "cmSystemTools.h" +#include "cmXMLWriter.h" -#include <cmsys/SystemTools.hxx> -#include <cmsys/Glob.hxx> +static inline unsigned int getVersion(unsigned int major, unsigned int minor) +{ + assert(major < 256 && minor < 256); + return ((major & 0xFF) << 16 | minor); +} -//---------------------------------------------------------------------- cmCPackPackageMakerGenerator::cmCPackPackageMakerGenerator() { this->PackageMakerVersion = 0.0; - this->PackageCompatibilityVersion = 10.4; + this->PackageCompatibilityVersion = getVersion(10, 4); } -//---------------------------------------------------------------------- cmCPackPackageMakerGenerator::~cmCPackPackageMakerGenerator() { } -//---------------------------------------------------------------------- bool cmCPackPackageMakerGenerator::SupportsComponentInstallation() const { - return this->PackageCompatibilityVersion >= 10.4; + return this->PackageCompatibilityVersion >= getVersion(10, 4); } -//---------------------------------------------------------------------- -int cmCPackPackageMakerGenerator::CopyInstallScript(const char* resdir, - const char* script, - const char* name) -{ - std::string dst = resdir; - dst += "/"; - dst += name; - cmSystemTools::CopyFileAlways(script, dst.c_str()); - cmSystemTools::SetPermissions(dst.c_str(),0777); - cmCPackLogger(cmCPackLog::LOG_VERBOSE, - "copy script : " << script << "\ninto " << dst.c_str() << - std::endl); - - return 1; -} - -//---------------------------------------------------------------------- int cmCPackPackageMakerGenerator::PackageFiles() { // TODO: Use toplevel // It is used! Is this an obsolete comment? std::string resDir; // Where this package's resources will go. - std::string packageDirFileName - = this->GetOption("CPACK_TEMPORARY_DIRECTORY"); - if (this->Components.empty()) - { + std::string packageDirFileName = + this->GetOption("CPACK_TEMPORARY_DIRECTORY"); + if (this->Components.empty()) { packageDirFileName += ".pkg"; resDir = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); resDir += "/Resources"; - } - else - { + } else { packageDirFileName += ".mpkg"; - if ( !cmsys::SystemTools::MakeDirectory(packageDirFileName.c_str())) - { + if (!cmsys::SystemTools::MakeDirectory(packageDirFileName.c_str())) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "unable to create package directory " - << packageDirFileName << std::endl); - return 0; - } + "unable to create package directory " << packageDirFileName + << std::endl); + return 0; + } resDir = packageDirFileName; resDir += "/Contents"; - if ( !cmsys::SystemTools::MakeDirectory(resDir.c_str())) - { + if (!cmsys::SystemTools::MakeDirectory(resDir.c_str())) { cmCPackLogger(cmCPackLog::LOG_ERROR, "unable to create package subdirectory " << resDir - << std::endl); - return 0; - } + << std::endl); + return 0; + } resDir += "/Resources"; - if ( !cmsys::SystemTools::MakeDirectory(resDir.c_str())) - { + if (!cmsys::SystemTools::MakeDirectory(resDir.c_str())) { cmCPackLogger(cmCPackLog::LOG_ERROR, "unable to create package subdirectory " << resDir - << std::endl); - return 0; - } + << std::endl); + return 0; + } resDir += "/en.lproj"; - } + } const char* preflight = this->GetOption("CPACK_PREFLIGHT_SCRIPT"); const char* postflight = this->GetOption("CPACK_POSTFLIGHT_SCRIPT"); const char* postupgrade = this->GetOption("CPACK_POSTUPGRADE_SCRIPT"); - if(this->Components.empty()) - { + if (this->Components.empty()) { // Create directory structure std::string preflightDirName = resDir + "/PreFlight"; std::string postflightDirName = resDir + "/PostFlight"; // if preflight or postflight scripts not there create directories // of the same name, I think this makes it work - if(!preflight) - { - if ( !cmsys::SystemTools::MakeDirectory(preflightDirName.c_str())) - { + if (!preflight) { + if (!cmsys::SystemTools::MakeDirectory(preflightDirName.c_str())) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem creating installer directory: " - << preflightDirName.c_str() << std::endl); + << preflightDirName << std::endl); return 0; - } } - if(!postflight) - { - if ( !cmsys::SystemTools::MakeDirectory(postflightDirName.c_str())) - { + } + if (!postflight) { + if (!cmsys::SystemTools::MakeDirectory(postflightDirName.c_str())) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem creating installer directory: " - << postflightDirName.c_str() << std::endl); + << postflightDirName << std::endl); return 0; - } } + } // if preflight, postflight, or postupgrade are set // then copy them into the resource directory and make // them executable - if(preflight) - { - this->CopyInstallScript(resDir.c_str(), - preflight, - "preflight"); - } - if(postflight) - { - this->CopyInstallScript(resDir.c_str(), - postflight, - "postflight"); - } - if(postupgrade) - { - this->CopyInstallScript(resDir.c_str(), - postupgrade, - "postupgrade"); - } + if (preflight) { + this->CopyInstallScript(resDir, preflight, "preflight"); } - else if(postflight) - { + if (postflight) { + this->CopyInstallScript(resDir, postflight, "postflight"); + } + if (postupgrade) { + this->CopyInstallScript(resDir, postupgrade, "postupgrade"); + } + } else if (postflight) { // create a postflight component to house the script this->PostFlightComponent.Name = "PostFlight"; this->PostFlightComponent.DisplayName = "PostFlight"; @@ -169,121 +126,101 @@ int cmCPackPackageMakerGenerator::PackageFiles() // empty directory for pkg contents std::string packageDir = toplevel + "/" + PostFlightComponent.Name; - if (!cmsys::SystemTools::MakeDirectory(packageDir.c_str())) - { + if (!cmsys::SystemTools::MakeDirectory(packageDir.c_str())) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem creating component packages directory: " - << packageDir.c_str() << std::endl); + << packageDir << std::endl); return 0; - } + } // create package std::string packageFileDir = packageDirFileName + "/Contents/Packages/"; - if (!cmsys::SystemTools::MakeDirectory(packageFileDir.c_str())) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Problem creating component PostFlight Packages directory: " - << packageFileDir.c_str() << std::endl); + if (!cmsys::SystemTools::MakeDirectory(packageFileDir.c_str())) { + cmCPackLogger( + cmCPackLog::LOG_ERROR, + "Problem creating component PostFlight Packages directory: " + << packageFileDir << std::endl); return 0; - } - std::string packageFile = packageFileDir + - this->GetPackageName(PostFlightComponent); - if (!this->GenerateComponentPackage(packageFile.c_str(), - packageDir.c_str(), - PostFlightComponent)) - { + } + std::string packageFile = + packageFileDir + this->GetPackageName(PostFlightComponent); + if (!this->GenerateComponentPackage( + packageFile.c_str(), packageDir.c_str(), PostFlightComponent)) { return 0; - } + } // copy postflight script into resource directory of .pkg std::string resourceDir = packageFile + "/Contents/Resources"; - this->CopyInstallScript(resourceDir.c_str(), - postflight, - "postflight"); - } + this->CopyInstallScript(resourceDir, postflight, "postflight"); + } - if (!this->Components.empty()) - { + if (!this->Components.empty()) { // Create the directory where component packages will be built. std::string basePackageDir = packageDirFileName; basePackageDir += "/Contents/Packages"; - if (!cmsys::SystemTools::MakeDirectory(basePackageDir.c_str())) - { + if (!cmsys::SystemTools::MakeDirectory(basePackageDir.c_str())) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem creating component packages directory: " - << basePackageDir.c_str() << std::endl); + << basePackageDir << std::endl); return 0; - } + } // Create the directory where downloaded component packages will // be placed. const char* userUploadDirectory = this->GetOption("CPACK_UPLOAD_DIRECTORY"); std::string uploadDirectory; - if (userUploadDirectory && *userUploadDirectory) - { + if (userUploadDirectory && *userUploadDirectory) { uploadDirectory = userUploadDirectory; - } - else - { - uploadDirectory= this->GetOption("CPACK_PACKAGE_DIRECTORY"); + } else { + uploadDirectory = this->GetOption("CPACK_PACKAGE_DIRECTORY"); uploadDirectory += "/CPackUploads"; - } + } // Create packages for each component bool warnedAboutDownloadCompatibility = false; std::map<std::string, cmCPackComponent>::iterator compIt; for (compIt = this->Components.begin(); compIt != this->Components.end(); - ++compIt) - { + ++compIt) { std::string packageFile; - if (compIt->second.IsDownloaded) - { - if (this->PackageCompatibilityVersion >= 10.5 && - this->PackageMakerVersion >= 3.0) - { + if (compIt->second.IsDownloaded) { + if (this->PackageCompatibilityVersion >= getVersion(10, 5) && + this->PackageMakerVersion >= 3.0) { // Build this package within the upload directory. packageFile = uploadDirectory; - if(!cmSystemTools::FileExists(uploadDirectory.c_str())) - { - if (!cmSystemTools::MakeDirectory(uploadDirectory.c_str())) - { + if (!cmSystemTools::FileExists(uploadDirectory.c_str())) { + if (!cmSystemTools::MakeDirectory(uploadDirectory.c_str())) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Unable to create package upload directory " - << uploadDirectory << std::endl); + << uploadDirectory << std::endl); return 0; - } } } - else if (!warnedAboutDownloadCompatibility) - { - if (this->PackageCompatibilityVersion < 10.5) - { + } else if (!warnedAboutDownloadCompatibility) { + if (this->PackageCompatibilityVersion < getVersion(10, 5)) { cmCPackLogger( cmCPackLog::LOG_WARNING, "CPack warning: please set CPACK_OSX_PACKAGE_VERSION to 10.5 " "or greater enable downloaded packages. CPack will build a " "non-downloaded package." - << std::endl); - } + << std::endl); + } - if (this->PackageMakerVersion < 3) - { + if (this->PackageMakerVersion < 3) { cmCPackLogger(cmCPackLog::LOG_WARNING, - "CPack warning: unable to build downloaded " + "CPack warning: unable to build downloaded " "packages with PackageMaker versions prior " "to 3.0. CPack will build a non-downloaded package." - << std::endl); - } + << std::endl); + } warnedAboutDownloadCompatibility = true; - } } + } - if (packageFile.empty()) - { + if (packageFile.empty()) { // Build this package within the overall distribution // metapackage. packageFile = basePackageDir; @@ -291,7 +228,7 @@ int cmCPackPackageMakerGenerator::PackageFiles() // We're not downloading this component, even if the user // requested it. compIt->second.IsDownloaded = false; - } + } packageFile += '/'; packageFile += GetPackageName(compIt->second); @@ -299,106 +236,91 @@ int cmCPackPackageMakerGenerator::PackageFiles() std::string packageDir = toplevel; packageDir += '/'; packageDir += compIt->first; - if (!this->GenerateComponentPackage(packageFile.c_str(), - packageDir.c_str(), - compIt->second)) - { + if (!this->GenerateComponentPackage( + packageFile.c_str(), packageDir.c_str(), compIt->second)) { return 0; - } } } + } this->SetOption("CPACK_MODULE_VERSION_SUFFIX", ""); // Copy or create all of the resource files we need. - if ( !this->CopyCreateResourceFile("License", resDir.c_str()) - || !this->CopyCreateResourceFile("ReadMe", resDir.c_str()) - || !this->CopyCreateResourceFile("Welcome", resDir.c_str()) - || !this->CopyResourcePlistFile("Info.plist") - || !this->CopyResourcePlistFile("Description.plist") ) - { + if (!this->CopyCreateResourceFile("License", resDir) || + !this->CopyCreateResourceFile("ReadMe", resDir) || + !this->CopyCreateResourceFile("Welcome", resDir) || + !this->CopyResourcePlistFile("Info.plist") || + !this->CopyResourcePlistFile("Description.plist")) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying the resource files" - << std::endl); + << std::endl); return 0; - } + } - if (this->Components.empty()) - { + if (this->Components.empty()) { // Use PackageMaker to build the package. - cmOStringStream pkgCmd; + std::ostringstream pkgCmd; pkgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM") << "\" -build -p \"" << packageDirFileName << "\""; - if (this->Components.empty()) - { + if (this->Components.empty()) { pkgCmd << " -f \"" << this->GetOption("CPACK_TEMPORARY_DIRECTORY"); - } - else - { + } else { pkgCmd << " -mi \"" << this->GetOption("CPACK_TEMPORARY_DIRECTORY") << "/packages/"; - } + } pkgCmd << "\" -r \"" << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "/Resources\" -i \"" << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "/Info.plist\" -d \"" << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "/Description.plist\""; - if ( this->PackageMakerVersion > 2.0 ) - { + if (this->PackageMakerVersion > 2.0) { pkgCmd << " -v"; - } + } if (!RunPackageMaker(pkgCmd.str().c_str(), packageDirFileName.c_str())) return 0; - } - else - { + } else { // We have built the package in place. Generate the // distribution.dist file to describe it for the installer. WriteDistributionFile(packageDirFileName.c_str()); - } + } std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); tmpFile += "/hdiutilOutput.log"; - cmOStringStream dmgCmd; + std::ostringstream dmgCmd; dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE") - << "\" create -ov -format UDZO -srcfolder \"" << packageDirFileName - << "\" \"" << packageFileNames[0] << "\""; + << "\" create -ov -format UDZO -srcfolder \"" << packageDirFileName + << "\" \"" << packageFileNames[0] << "\""; std::string output; int retVal = 1; int numTries = 10; bool res = false; - while(numTries > 0) - { - res = cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output, - &retVal, 0, this->GeneratorVerbose, - 0); - if ( res && !retVal ) - { + while (numTries > 0) { + res = + cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output, &output, + &retVal, 0, this->GeneratorVerbose, 0); + if (res && !retVal) { numTries = -1; break; - } + } cmSystemTools::Delay(500); numTries--; - } - if ( !res || retVal ) - { + } + if (!res || retVal) { cmGeneratedFileStream ofs(tmpFile.c_str()); - ofs << "# Run command: " << dmgCmd.str().c_str() << std::endl - << "# Output:" << std::endl - << output.c_str() << std::endl; + ofs << "# Run command: " << dmgCmd.str() << std::endl + << "# Output:" << std::endl + << output << std::endl; cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running hdiutil command: " - << dmgCmd.str().c_str() << std::endl - << "Please check " << tmpFile.c_str() << " for errors" << std::endl); + << dmgCmd.str() << std::endl + << "Please check " << tmpFile << " for errors" + << std::endl); return 0; - } + } return 1; } -//---------------------------------------------------------------------- int cmCPackPackageMakerGenerator::InitializeInternal() { - cmCPackLogger(cmCPackLog::LOG_DEBUG, - "cmCPackPackageMakerGenerator::Initialize()" << std::endl); this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/usr"); // Starting with Xcode 4.3, PackageMaker is a separate app, and you @@ -415,42 +337,33 @@ int cmCPackPackageMakerGenerator::InitializeInternal() // If found, save result in the CPACK_INSTALLER_PROGRAM variable. std::vector<std::string> paths; - paths.push_back( - "/Applications/Xcode.app/Contents/Applications" - "/PackageMaker.app/Contents/MacOS"); - paths.push_back( - "/Applications/Utilities" - "/PackageMaker.app/Contents/MacOS"); - paths.push_back( - "/Applications" - "/PackageMaker.app/Contents/MacOS"); - paths.push_back( - "/Developer/Applications/Utilities" - "/PackageMaker.app/Contents/MacOS"); - paths.push_back( - "/Developer/Applications" - "/PackageMaker.app/Contents/MacOS"); + paths.push_back("/Applications/Xcode.app/Contents/Applications" + "/PackageMaker.app/Contents/MacOS"); + paths.push_back("/Applications/Utilities" + "/PackageMaker.app/Contents/MacOS"); + paths.push_back("/Applications" + "/PackageMaker.app/Contents/MacOS"); + paths.push_back("/Developer/Applications/Utilities" + "/PackageMaker.app/Contents/MacOS"); + paths.push_back("/Developer/Applications" + "/PackageMaker.app/Contents/MacOS"); std::string pkgPath; - const char *inst_program = this->GetOption("CPACK_INSTALLER_PROGRAM"); - if (inst_program && *inst_program) - { + const char* inst_program = this->GetOption("CPACK_INSTALLER_PROGRAM"); + if (inst_program && *inst_program) { pkgPath = inst_program; - } - else - { + } else { pkgPath = cmSystemTools::FindProgram("PackageMaker", paths, false); - if ( pkgPath.empty() ) - { + if (pkgPath.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find PackageMaker compiler" - << std::endl); + << std::endl); return 0; - } - this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", pkgPath.c_str()); } + this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", pkgPath.c_str()); + } // Get path to the real PackageMaker, not a symlink: - pkgPath = cmSystemTools::GetRealPath(pkgPath.c_str()); + pkgPath = cmSystemTools::GetRealPath(pkgPath); // Up from there to find the version.plist file in the "Contents" dir: std::string contents_dir; contents_dir = cmSystemTools::GetFilenamePath(pkgPath); @@ -458,179 +371,93 @@ int cmCPackPackageMakerGenerator::InitializeInternal() std::string versionFile = contents_dir + "/version.plist"; - if ( !cmSystemTools::FileExists(versionFile.c_str()) ) - { + if (!cmSystemTools::FileExists(versionFile.c_str())) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Cannot find PackageMaker compiler version file: " - << versionFile.c_str() - << std::endl); + "Cannot find PackageMaker compiler version file: " + << versionFile << std::endl); return 0; - } + } - std::ifstream ifs(versionFile.c_str()); - if ( !ifs ) - { + cmsys::ifstream ifs(versionFile.c_str()); + if (!ifs) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Cannot open PackageMaker compiler version file" << std::endl); + "Cannot open PackageMaker compiler version file" + << std::endl); return 0; - } + } // Check the PackageMaker version cmsys::RegularExpression rexKey("<key>CFBundleShortVersionString</key>"); cmsys::RegularExpression rexVersion("<string>([0-9]+.[0-9.]+)</string>"); std::string line; bool foundKey = false; - while ( cmSystemTools::GetLineFromStream(ifs, line) ) - { - if ( rexKey.find(line) ) - { + while (cmSystemTools::GetLineFromStream(ifs, line)) { + if (rexKey.find(line)) { foundKey = true; break; - } } - if ( !foundKey ) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, + } + if (!foundKey) { + cmCPackLogger( + cmCPackLog::LOG_ERROR, "Cannot find CFBundleShortVersionString in the PackageMaker compiler " - "version file" << std::endl); + "version file" + << std::endl); return 0; - } - if ( !cmSystemTools::GetLineFromStream(ifs, line) || - !rexVersion.find(line) ) - { + } + if (!cmSystemTools::GetLineFromStream(ifs, line) || !rexVersion.find(line)) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Problem reading the PackageMaker compiler version file: " - << versionFile.c_str() << std::endl); + "Problem reading the PackageMaker compiler version file: " + << versionFile << std::endl); return 0; - } + } this->PackageMakerVersion = atof(rexVersion.match(1).c_str()); - if ( this->PackageMakerVersion < 1.0 ) - { + if (this->PackageMakerVersion < 1.0) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Require PackageMaker 1.0 or higher" - << std::endl); + << std::endl); return 0; - } + } cmCPackLogger(cmCPackLog::LOG_DEBUG, "PackageMaker version is: " - << this->PackageMakerVersion << std::endl); + << this->PackageMakerVersion << std::endl); // Determine the package compatibility version. If it wasn't // specified by the user, we define it based on which features the // user requested. - const char *packageCompat = this->GetOption("CPACK_OSX_PACKAGE_VERSION"); - if (packageCompat && *packageCompat) - { - this->PackageCompatibilityVersion = atof(packageCompat); - } - else if (this->GetOption("CPACK_DOWNLOAD_SITE")) - { + const char* packageCompat = this->GetOption("CPACK_OSX_PACKAGE_VERSION"); + if (packageCompat && *packageCompat) { + unsigned int majorVersion = 10; + unsigned int minorVersion = 5; + int res = sscanf(packageCompat, "%u.%u", &majorVersion, &minorVersion); + if (res == 2) { + this->PackageCompatibilityVersion = + getVersion(majorVersion, minorVersion); + } + } else if (this->GetOption("CPACK_DOWNLOAD_SITE")) { this->SetOption("CPACK_OSX_PACKAGE_VERSION", "10.5"); - this->PackageCompatibilityVersion = 10.5; - } - else if (this->GetOption("CPACK_COMPONENTS_ALL")) - { + this->PackageCompatibilityVersion = getVersion(10, 5); + } else if (this->GetOption("CPACK_COMPONENTS_ALL")) { this->SetOption("CPACK_OSX_PACKAGE_VERSION", "10.4"); - this->PackageCompatibilityVersion = 10.4; - } - else - { + this->PackageCompatibilityVersion = getVersion(10, 4); + } else { this->SetOption("CPACK_OSX_PACKAGE_VERSION", "10.3"); - this->PackageCompatibilityVersion = 10.3; - } + this->PackageCompatibilityVersion = getVersion(10, 3); + } std::vector<std::string> no_paths; pkgPath = cmSystemTools::FindProgram("hdiutil", no_paths, false); - if ( pkgPath.empty() ) - { + if (pkgPath.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find hdiutil compiler" - << std::endl); + << std::endl); return 0; - } + } this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM_DISK_IMAGE", pkgPath.c_str()); return this->Superclass::InitializeInternal(); } -//---------------------------------------------------------------------- -bool cmCPackPackageMakerGenerator::CopyCreateResourceFile(const char* name, - const char* dirName) -{ - std::string uname = cmSystemTools::UpperCase(name); - std::string cpackVar = "CPACK_RESOURCE_FILE_" + uname; - const char* inFileName = this->GetOption(cpackVar.c_str()); - if ( !inFileName ) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, "CPack option: " << cpackVar.c_str() - << " not specified. It should point to " - << (name ? name : "(NULL)") - << ".rtf, " << name - << ".html, or " << name << ".txt file" << std::endl); - return false; - } - if ( !cmSystemTools::FileExists(inFileName) ) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find " - << (name ? name : "(NULL)") - << " resource file: " << inFileName << std::endl); - return false; - } - std::string ext = cmSystemTools::GetFilenameLastExtension(inFileName); - if ( ext != ".rtfd" && ext != ".rtf" && ext != ".html" && ext != ".txt" ) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, "Bad file extension specified: " - << ext << ". Currently only .rtfd, .rtf, .html, and .txt files allowed." - << std::endl); - return false; - } - - std::string destFileName = dirName; - destFileName += '/'; - destFileName += name + ext; - - // Set this so that distribution.dist gets the right name (without - // the path). - this->SetOption(("CPACK_RESOURCE_FILE_" + uname + "_NOPATH").c_str(), - (name + ext).c_str()); - - cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " - << (inFileName ? inFileName : "(NULL)") - << " to " << destFileName.c_str() << std::endl); - this->ConfigureFile(inFileName, destFileName.c_str()); - return true; -} - -bool cmCPackPackageMakerGenerator::CopyResourcePlistFile(const char* name, - const char* outName) -{ - if (!outName) - { - outName = name; - } - - std::string inFName = "CPack."; - inFName += name; - inFName += ".in"; - std::string inFileName = this->FindTemplate(inFName.c_str()); - if ( inFileName.empty() ) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find input file: " - << inFName << std::endl); - return false; - } - - std::string destFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); - destFileName += "/"; - destFileName += outName; - - cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " - << inFileName.c_str() << " to " << destFileName.c_str() << std::endl); - this->ConfigureFile(inFileName.c_str(), destFileName.c_str()); - return true; -} - -//---------------------------------------------------------------------- -bool cmCPackPackageMakerGenerator::RunPackageMaker(const char *command, - const char *packageFile) +bool cmCPackPackageMakerGenerator::RunPackageMaker(const char* command, + const char* packageFile) { std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); tmpFile += "/PackageMakerOutput.log"; @@ -638,100 +465,72 @@ bool cmCPackPackageMakerGenerator::RunPackageMaker(const char *command, cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << command << std::endl); std::string output; int retVal = 1; - bool res = cmSystemTools::RunSingleCommand(command, &output, &retVal, 0, - this->GeneratorVerbose, 0); + bool res = cmSystemTools::RunSingleCommand( + command, &output, &output, &retVal, 0, this->GeneratorVerbose, 0); cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Done running package maker" - << std::endl); - if ( !res || retVal ) - { + << std::endl); + if (!res || retVal) { cmGeneratedFileStream ofs(tmpFile.c_str()); ofs << "# Run command: " << command << std::endl - << "# Output:" << std::endl - << output.c_str() << std::endl; - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Problem running PackageMaker command: " << command - << std::endl << "Please check " << tmpFile.c_str() << " for errors" - << std::endl); + << "# Output:" << std::endl + << output << std::endl; + cmCPackLogger( + cmCPackLog::LOG_ERROR, "Problem running PackageMaker command: " + << command << std::endl + << "Please check " << tmpFile << " for errors" << std::endl); return false; - } + } // sometimes the command finishes but the directory is not yet // created, so try 10 times to see if it shows up int tries = 10; - while(tries > 0 && - !cmSystemTools::FileExists(packageFile)) - { + while (tries > 0 && !cmSystemTools::FileExists(packageFile)) { cmSystemTools::Delay(500); tries--; - } - if(!cmSystemTools::FileExists(packageFile)) - { - cmCPackLogger( - cmCPackLog::LOG_ERROR, - "Problem running PackageMaker command: " << command - << std::endl << "Package not created: " << packageFile - << std::endl); + } + if (!cmSystemTools::FileExists(packageFile)) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Problem running PackageMaker command: " + << command << std::endl + << "Package not created: " << packageFile << std::endl); return false; - } + } return true; } -//---------------------------------------------------------------------- -std::string -cmCPackPackageMakerGenerator::GetPackageName(const cmCPackComponent& component) -{ - if (component.ArchiveFile.empty()) - { - std::string packagesDir = this->GetOption("CPACK_TEMPORARY_DIRECTORY"); - packagesDir += ".dummy"; - cmOStringStream out; - out << cmSystemTools::GetFilenameWithoutLastExtension(packagesDir) - << "-" << component.Name << ".pkg"; - return out.str(); - } - else - { - return component.ArchiveFile + ".pkg"; - } -} - -//---------------------------------------------------------------------- -bool -cmCPackPackageMakerGenerator:: -GenerateComponentPackage(const char *packageFile, - const char *packageDir, - const cmCPackComponent& component) +bool cmCPackPackageMakerGenerator::GenerateComponentPackage( + const char* packageFile, const char* packageDir, + const cmCPackComponent& component) { - cmCPackLogger(cmCPackLog::LOG_OUTPUT, - "- Building component package: " << - packageFile << std::endl); + cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Building component package: " + << packageFile << std::endl); // The command that will be used to run PackageMaker - cmOStringStream pkgCmd; + std::ostringstream pkgCmd; - if (this->PackageCompatibilityVersion < 10.5 || - this->PackageMakerVersion < 3.0) - { + if (this->PackageCompatibilityVersion < getVersion(10, 5) || + this->PackageMakerVersion < 3.0) { // Create Description.plist and Info.plist files for normal Mac OS // X packages, which work on Mac OS X 10.3 and newer. std::string descriptionFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); descriptionFile += '/' + component.Name + "-Description.plist"; - std::ofstream out(descriptionFile.c_str()); - out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl - << "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\"" - << "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" << std::endl - << "<plist version=\"1.4\">" << std::endl - << "<dict>" << std::endl - << " <key>IFPkgDescriptionTitle</key>" << std::endl - << " <string>" << component.DisplayName << "</string>" << std::endl - << " <key>IFPkgDescriptionVersion</key>" << std::endl - << " <string>" << this->GetOption("CPACK_PACKAGE_VERSION") - << "</string>" << std::endl - << " <key>IFPkgDescriptionDescription</key>" << std::endl - << " <string>" + this->EscapeForXML(component.Description) - << "</string>" << std::endl - << "</dict>" << std::endl - << "</plist>" << std::endl; + cmsys::ofstream out(descriptionFile.c_str()); + cmXMLWriter xout(out); + xout.StartDocument(); + xout.Doctype("plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\"" + "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\""); + xout.StartElement("plist"); + xout.Attribute("version", "1.4"); + xout.StartElement("dict"); + xout.Element("key", "IFPkgDescriptionTitle"); + xout.Element("string", component.DisplayName); + xout.Element("key", "IFPkgDescriptionVersion"); + xout.Element("string", this->GetOption("CPACK_PACKAGE_VERSION")); + xout.Element("key", "IFPkgDescriptionDescription"); + xout.Element("string", component.Description); + xout.EndElement(); // dict + xout.EndElement(); // plist + xout.EndDocument(); out.close(); // Create the Info.plist file for this component @@ -741,20 +540,17 @@ GenerateComponentPackage(const char *packageFile, moduleVersionSuffix.c_str()); std::string infoFileName = component.Name; infoFileName += "-Info.plist"; - if (!this->CopyResourcePlistFile("Info.plist", infoFileName.c_str())) - { + if (!this->CopyResourcePlistFile("Info.plist", infoFileName.c_str())) { return false; - } + } pkgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM") << "\" -build -p \"" << packageFile << "\"" << " -f \"" << packageDir << "\"" - << " -i \"" << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") - << "/" << infoFileName << "\"" + << " -i \"" << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "/" + << infoFileName << "\"" << " -d \"" << descriptionFile << "\""; - } - else - { + } else { // Create a "flat" package on Mac OS X 10.5 and newer. Flat // packages are stored in a single file, rather than a directory // like normal packages, and can be downloaded by the installer @@ -769,270 +565,11 @@ GenerateComponentPackage(const char *packageFile, pkgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM") << "\" --root \"" << packageDir << "\"" - << " --id " << pkgId - << " --target " << this->GetOption("CPACK_OSX_PACKAGE_VERSION") - << " --out \"" << packageFile << "\""; - } + << " --id " << pkgId << " --target " + << this->GetOption("CPACK_OSX_PACKAGE_VERSION") << " --out \"" + << packageFile << "\""; + } // Run PackageMaker return RunPackageMaker(pkgCmd.str().c_str(), packageFile); } - -//---------------------------------------------------------------------- -void -cmCPackPackageMakerGenerator:: -WriteDistributionFile(const char* metapackageFile) -{ - std::string distributionTemplate - = this->FindTemplate("CPack.distribution.dist.in"); - if ( distributionTemplate.empty() ) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find input file: " - << distributionTemplate << std::endl); - return; - } - - std::string distributionFile = metapackageFile; - distributionFile += "/Contents/distribution.dist"; - - // Create the choice outline, which provides a tree-based view of - // the components in their groups. - cmOStringStream choiceOut; - choiceOut << "<choices-outline>" << std::endl; - - // Emit the outline for the groups - std::map<std::string, cmCPackComponentGroup>::iterator groupIt; - for (groupIt = this->ComponentGroups.begin(); - groupIt != this->ComponentGroups.end(); - ++groupIt) - { - if (groupIt->second.ParentGroup == 0) - { - CreateChoiceOutline(groupIt->second, choiceOut); - } - } - - // Emit the outline for the non-grouped components - std::map<std::string, cmCPackComponent>::iterator compIt; - for (compIt = this->Components.begin(); compIt != this->Components.end(); - ++compIt) - { - if (!compIt->second.Group) - { - choiceOut << "<line choice=\"" << compIt->first << "Choice\"></line>" - << std::endl; - } - } - if(!this->PostFlightComponent.Name.empty()) - { - choiceOut << "<line choice=\"" << PostFlightComponent.Name - << "Choice\"></line>" << std::endl; - } - choiceOut << "</choices-outline>" << std::endl; - - // Create the actual choices - for (groupIt = this->ComponentGroups.begin(); - groupIt != this->ComponentGroups.end(); - ++groupIt) - { - CreateChoice(groupIt->second, choiceOut); - } - for (compIt = this->Components.begin(); compIt != this->Components.end(); - ++compIt) - { - CreateChoice(compIt->second, choiceOut); - } - - if(!this->PostFlightComponent.Name.empty()) - { - CreateChoice(PostFlightComponent, choiceOut); - } - - this->SetOption("CPACK_PACKAGEMAKER_CHOICES", choiceOut.str().c_str()); - - // Create the distribution.dist file in the metapackage to turn it - // into a distribution package. - this->ConfigureFile(distributionTemplate.c_str(), - distributionFile.c_str()); -} - -//---------------------------------------------------------------------- -void -cmCPackPackageMakerGenerator:: -CreateChoiceOutline(const cmCPackComponentGroup& group, cmOStringStream& out) -{ - out << "<line choice=\"" << group.Name << "Choice\">" << std::endl; - std::vector<cmCPackComponentGroup*>::const_iterator groupIt; - for (groupIt = group.Subgroups.begin(); groupIt != group.Subgroups.end(); - ++groupIt) - { - CreateChoiceOutline(**groupIt, out); - } - - std::vector<cmCPackComponent*>::const_iterator compIt; - for (compIt = group.Components.begin(); compIt != group.Components.end(); - ++compIt) - { - out << " <line choice=\"" << (*compIt)->Name << "Choice\"></line>" - << std::endl; - } - out << "</line>" << std::endl; -} - -//---------------------------------------------------------------------- -void -cmCPackPackageMakerGenerator::CreateChoice(const cmCPackComponentGroup& group, - cmOStringStream& out) -{ - out << "<choice id=\"" << group.Name << "Choice\" " - << "title=\"" << group.DisplayName << "\" " - << "start_selected=\"true\" " - << "start_enabled=\"true\" " - << "start_visible=\"true\" "; - if (!group.Description.empty()) - { - out << "description=\"" << EscapeForXML(group.Description) - << "\""; - } - out << "></choice>" << std::endl; -} - -//---------------------------------------------------------------------- -void -cmCPackPackageMakerGenerator::CreateChoice(const cmCPackComponent& component, - cmOStringStream& out) -{ - std::string packageId = "com."; - packageId += this->GetOption("CPACK_PACKAGE_VENDOR"); - packageId += '.'; - packageId += this->GetOption("CPACK_PACKAGE_NAME"); - packageId += '.'; - packageId += component.Name; - - out << "<choice id=\"" << component.Name << "Choice\" " - << "title=\"" << component.DisplayName << "\" " - << "start_selected=\"" - << (component.IsDisabledByDefault && - !component.IsRequired? "false" : "true") - << "\" " - << "start_enabled=\"" - << (component.IsRequired? "false" : "true") - << "\" " - << "start_visible=\"" << (component.IsHidden? "false" : "true") << "\" "; - if (!component.Description.empty()) - { - out << "description=\"" << EscapeForXML(component.Description) - << "\" "; - } - if (!component.Dependencies.empty() || - !component.ReverseDependencies.empty()) - { - // The "selected" expression is evaluated each time any choice is - // selected, for all choices *except* the one that the user - // selected. A component is marked selected if it has been - // selected (my.choice.selected in Javascript) and all of the - // components it depends on have been selected (transitively) or - // if any of the components that depend on it have been selected - // (transitively). Assume that we have components A, B, C, D, and - // E, where each component depends on the previous component (B - // depends on A, C depends on B, D depends on C, and E depends on - // D). The expression we build for the component C will be - // my.choice.selected && B && A || D || E - // This way, selecting C will automatically select everything it depends - // on (B and A), while selecting something that depends on C--either D - // or E--will automatically cause C to get selected. - out << "selected=\"my.choice.selected"; - std::set<const cmCPackComponent *> visited; - AddDependencyAttributes(component, visited, out); - visited.clear(); - AddReverseDependencyAttributes(component, visited, out); - out << "\""; - } - out << ">" << std::endl; - out << " <pkg-ref id=\"" << packageId << "\"></pkg-ref>" << std::endl; - out << "</choice>" << std::endl; - - // Create a description of the package associated with this - // component. - std::string relativePackageLocation = "Contents/Packages/"; - relativePackageLocation += this->GetPackageName(component); - - // Determine the installed size of the package. - std::string dirName = this->GetOption("CPACK_TEMPORARY_DIRECTORY"); - dirName += '/'; - dirName += component.Name; - unsigned long installedSize - = component.GetInstalledSizeInKbytes(dirName.c_str()); - - out << "<pkg-ref id=\"" << packageId << "\" " - << "version=\"" << this->GetOption("CPACK_PACKAGE_VERSION") << "\" " - << "installKBytes=\"" << installedSize << "\" " - << "auth=\"Admin\" onConclusion=\"None\">"; - if (component.IsDownloaded) - { - out << this->GetOption("CPACK_DOWNLOAD_SITE") - << this->GetPackageName(component); - } - else - { - out << "file:./" << relativePackageLocation; - } - out << "</pkg-ref>" << std::endl; -} - -//---------------------------------------------------------------------- -void -cmCPackPackageMakerGenerator:: -AddDependencyAttributes(const cmCPackComponent& component, - std::set<const cmCPackComponent *>& visited, - cmOStringStream& out) -{ - if (visited.find(&component) != visited.end()) - { - return; - } - visited.insert(&component); - - std::vector<cmCPackComponent *>::const_iterator dependIt; - for (dependIt = component.Dependencies.begin(); - dependIt != component.Dependencies.end(); - ++dependIt) - { - out << " && choices['" << - (*dependIt)->Name << "Choice'].selected"; - AddDependencyAttributes(**dependIt, visited, out); - } -} - -//---------------------------------------------------------------------- -void -cmCPackPackageMakerGenerator:: -AddReverseDependencyAttributes(const cmCPackComponent& component, - std::set<const cmCPackComponent *>& visited, - cmOStringStream& out) -{ - if (visited.find(&component) != visited.end()) - { - return; - } - visited.insert(&component); - - std::vector<cmCPackComponent *>::const_iterator dependIt; - for (dependIt = component.ReverseDependencies.begin(); - dependIt != component.ReverseDependencies.end(); - ++dependIt) - { - out << " || choices['" << (*dependIt)->Name << "Choice'].selected"; - AddReverseDependencyAttributes(**dependIt, visited, out); - } -} - -//---------------------------------------------------------------------- -std::string cmCPackPackageMakerGenerator::EscapeForXML(std::string str) -{ - cmSystemTools::ReplaceString(str, "&", "&"); - cmSystemTools::ReplaceString(str, "<", "<"); - cmSystemTools::ReplaceString(str, ">", ">"); - cmSystemTools::ReplaceString(str, "\"", """); - return str; -} diff --git a/Source/CPack/cmCPackPackageMakerGenerator.h b/Source/CPack/cmCPackPackageMakerGenerator.h index ba3d968f6..62745152b 100644 --- a/Source/CPack/cmCPackPackageMakerGenerator.h +++ b/Source/CPack/cmCPackPackageMakerGenerator.h @@ -1,20 +1,12 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc. - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #ifndef cmCPackPackageMakerGenerator_h #define cmCPackPackageMakerGenerator_h +#include "cmConfigure.h" #include "cmCPackGenerator.h" +#include "cmCPackPKGGenerator.h" class cmCPackComponent; @@ -24,99 +16,38 @@ class cmCPackComponent; * http://developer.apple.com/documentation/Darwin * /Reference/ManPages/man1/packagemaker.1.html */ -class cmCPackPackageMakerGenerator : public cmCPackGenerator +class cmCPackPackageMakerGenerator : public cmCPackPKGGenerator { public: - cmCPackTypeMacro(cmCPackPackageMakerGenerator, cmCPackGenerator); + cmCPackTypeMacro(cmCPackPackageMakerGenerator, cmCPackPKGGenerator); /** * Construct generator */ cmCPackPackageMakerGenerator(); virtual ~cmCPackPackageMakerGenerator(); - - virtual bool SupportsComponentInstallation() const; + bool SupportsComponentInstallation() const CM_OVERRIDE; protected: - int CopyInstallScript(const char* resdir, - const char* script, - const char* name); - virtual int InitializeInternal(); - int PackageFiles(); - virtual const char* GetOutputExtension() { return ".dmg"; } - virtual const char* GetOutputPostfix() { return "darwin"; } - - // Copies or creates the resource file with the given name to the - // package or package staging directory dirName. The variable - // CPACK_RESOURCE_FILE_${NAME} (where ${NAME} is the uppercased - // version of name) specifies the input file to use for this file, - // which will be configured via ConfigureFile. - bool CopyCreateResourceFile(const char* name, const char *dirName); - bool CopyResourcePlistFile(const char* name, const char* outName = 0); + int InitializeInternal() CM_OVERRIDE; + int PackageFiles() CM_OVERRIDE; + const char* GetOutputExtension() CM_OVERRIDE { return ".dmg"; } // Run PackageMaker with the given command line, which will (if // successful) produce the given package file. Returns true if // PackageMaker succeeds, false otherwise. - bool RunPackageMaker(const char *command, const char *packageFile); - - // Retrieve the name of package file that will be generated for this - // component. The name is just the file name with extension, and - // does not include the subdirectory. - std::string GetPackageName(const cmCPackComponent& component); + bool RunPackageMaker(const char* command, const char* packageFile); // Generate a package in the file packageFile for the given // component. All of the files within this component are stored in // the directory packageDir. Returns true if successful, false // otherwise. - bool GenerateComponentPackage(const char *packageFile, - const char *packageDir, + bool GenerateComponentPackage(const char* packageFile, + const char* packageDir, const cmCPackComponent& component); - // Writes a distribution.dist file, which turns a metapackage into a - // full-fledged distribution. This file is used to describe - // inter-component dependencies. metapackageFile is the name of the - // metapackage for the distribution. Only valid for a - // component-based install. - void WriteDistributionFile(const char* metapackageFile); - - // Subroutine of WriteDistributionFile that writes out the - // dependency attributes for inter-component dependencies. - void AddDependencyAttributes(const cmCPackComponent& component, - std::set<const cmCPackComponent *>& visited, - cmOStringStream& out); - - // Subroutine of WriteDistributionFile that writes out the - // reverse dependency attributes for inter-component dependencies. - void - AddReverseDependencyAttributes(const cmCPackComponent& component, - std::set<const cmCPackComponent *>& visited, - cmOStringStream& out); - - // Generates XML that encodes the hierarchy of component groups and - // their components in a form that can be used by distribution - // metapackages. - void CreateChoiceOutline(const cmCPackComponentGroup& group, - cmOStringStream& out); - - /// Create the "choice" XML element to describe a component group - /// for the installer GUI. - void CreateChoice(const cmCPackComponentGroup& group, - cmOStringStream& out); - - /// Create the "choice" XML element to describe a component for the - /// installer GUI. - void CreateChoice(const cmCPackComponent& component, - cmOStringStream& out); - - // Escape the given string to make it usable as an XML attribute - // value. - std::string EscapeForXML(std::string str); - - // The PostFlight component when creating a metapackage - cmCPackComponent PostFlightComponent; - double PackageMakerVersion; - double PackageCompatibilityVersion; + unsigned int PackageCompatibilityVersion; }; #endif diff --git a/Source/CPack/cmCPackProductBuildGenerator.cxx b/Source/CPack/cmCPackProductBuildGenerator.cxx new file mode 100644 index 000000000..1389eaa5a --- /dev/null +++ b/Source/CPack/cmCPackProductBuildGenerator.cxx @@ -0,0 +1,258 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmCPackProductBuildGenerator.h" + +#include <map> +#include <sstream> +#include <stddef.h> + +#include "cmCPackComponentGroup.h" +#include "cmCPackLog.h" +#include "cmGeneratedFileStream.h" +#include "cmSystemTools.h" + +cmCPackProductBuildGenerator::cmCPackProductBuildGenerator() +{ + this->componentPackageMethod = ONE_PACKAGE; +} + +cmCPackProductBuildGenerator::~cmCPackProductBuildGenerator() +{ +} + +int cmCPackProductBuildGenerator::PackageFiles() +{ + // TODO: Use toplevel + // It is used! Is this an obsolete comment? + + std::string packageDirFileName = + this->GetOption("CPACK_TEMPORARY_DIRECTORY"); + + // Create the directory where component packages will be built. + std::string basePackageDir = packageDirFileName; + basePackageDir += "/Contents/Packages"; + if (!cmsys::SystemTools::MakeDirectory(basePackageDir.c_str())) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Problem creating component packages directory: " + << basePackageDir << std::endl); + return 0; + } + + if (!this->Components.empty()) { + std::map<std::string, cmCPackComponent>::iterator compIt; + for (compIt = this->Components.begin(); compIt != this->Components.end(); + ++compIt) { + std::string packageDir = toplevel; + packageDir += '/'; + packageDir += compIt->first; + if (!this->GenerateComponentPackage(basePackageDir, + GetPackageName(compIt->second), + packageDir, &compIt->second)) { + return 0; + } + } + } else { + if (!this->GenerateComponentPackage(basePackageDir, + this->GetOption("CPACK_PACKAGE_NAME"), + toplevel, NULL)) { + return 0; + } + } + + std::string resDir = packageDirFileName + "/Contents"; + + if (this->IsSet("CPACK_PRODUCTBUILD_RESOURCES_DIR")) { + std::string userResDir = + this->GetOption("CPACK_PRODUCTBUILD_RESOURCES_DIR"); + + if (!cmSystemTools::CopyADirectory(userResDir, resDir)) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying the resource files" + << std::endl); + return 0; + } + } + + // Copy or create all of the resource files we need. + if (!this->CopyCreateResourceFile("License", resDir) || + !this->CopyCreateResourceFile("ReadMe", resDir) || + !this->CopyCreateResourceFile("Welcome", resDir)) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Problem copying the License, ReadMe and Welcome files" + << std::endl); + return 0; + } + + // combine package(s) into a distribution + WriteDistributionFile(packageDirFileName.c_str()); + std::ostringstream pkgCmd; + + std::string version = this->GetOption("CPACK_PACKAGE_VERSION"); + std::string productbuild = this->GetOption("CPACK_COMMAND_PRODUCTBUILD"); + std::string identityName; + if (const char* n = this->GetOption("CPACK_PRODUCTBUILD_IDENTITY_NAME")) { + identityName = n; + } + std::string keychainPath; + if (const char* p = this->GetOption("CPACK_PRODUCTBUILD_KEYCHAIN_PATH")) { + keychainPath = p; + } + + pkgCmd << productbuild << " --distribution \"" << packageDirFileName + << "/Contents/distribution.dist\"" + << " --package-path \"" << packageDirFileName << "/Contents/Packages" + << "\"" + << " --resources \"" << resDir << "\"" + << " --version \"" << version << "\"" + << (identityName.empty() ? "" : " --sign \"" + identityName + "\"") + << (keychainPath.empty() ? "" + : " --keychain \"" + keychainPath + "\"") + << " \"" << packageFileNames[0] << "\""; + + // Run ProductBuild + return RunProductBuild(pkgCmd.str()); +} + +int cmCPackProductBuildGenerator::InitializeInternal() +{ + this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/Applications"); + + std::vector<std::string> no_paths; + std::string program = + cmSystemTools::FindProgram("pkgbuild", no_paths, false); + if (program.empty()) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find pkgbuild executable" + << std::endl); + return 0; + } + this->SetOptionIfNotSet("CPACK_COMMAND_PKGBUILD", program.c_str()); + + program = cmSystemTools::FindProgram("productbuild", no_paths, false); + if (program.empty()) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find productbuild executable" + << std::endl); + return 0; + } + this->SetOptionIfNotSet("CPACK_COMMAND_PRODUCTBUILD", program.c_str()); + + return this->Superclass::InitializeInternal(); +} + +bool cmCPackProductBuildGenerator::RunProductBuild(const std::string& command) +{ + std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); + tmpFile += "/ProductBuildOutput.log"; + + cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << command << std::endl); + std::string output, error_output; + int retVal = 1; + bool res = + cmSystemTools::RunSingleCommand(command.c_str(), &output, &error_output, + &retVal, 0, this->GeneratorVerbose, 0); + cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Done running command" << std::endl); + if (!res || retVal) { + cmGeneratedFileStream ofs(tmpFile.c_str()); + ofs << "# Run command: " << command << std::endl + << "# Output:" << std::endl + << output << std::endl; + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Problem running command: " << command << std::endl + << "Please check " << tmpFile + << " for errors" << std::endl); + return false; + } + return true; +} + +bool cmCPackProductBuildGenerator::GenerateComponentPackage( + const std::string& packageFileDir, const std::string& packageFileName, + const std::string& packageDir, const cmCPackComponent* component) +{ + std::string packageFile = packageFileDir; + packageFile += '/'; + packageFile += packageFileName; + + cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Building component package: " + << packageFile << std::endl); + + const char* comp_name = component ? component->Name.c_str() : NULL; + + const char* preflight = this->GetComponentScript("PREFLIGHT", comp_name); + const char* postflight = this->GetComponentScript("POSTFLIGHT", comp_name); + + std::string resDir = packageFileDir; + if (component) { + resDir += "/"; + resDir += component->Name; + } + std::string scriptDir = resDir + "/scripts"; + + if (!cmsys::SystemTools::MakeDirectory(scriptDir.c_str())) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Problem creating installer directory: " << scriptDir + << std::endl); + return 0; + } + + // if preflight, postflight, or postupgrade are set + // then copy them into the script directory and make + // them executable + if (preflight) { + this->CopyInstallScript(scriptDir, preflight, "preinstall"); + } + if (postflight) { + this->CopyInstallScript(scriptDir, postflight, "postinstall"); + } + + // The command that will be used to run ProductBuild + std::ostringstream pkgCmd; + + std::string pkgId = "com."; + pkgId += this->GetOption("CPACK_PACKAGE_VENDOR"); + pkgId += '.'; + pkgId += this->GetOption("CPACK_PACKAGE_NAME"); + if (component) { + pkgId += '.'; + pkgId += component->Name; + } + + std::string version = this->GetOption("CPACK_PACKAGE_VERSION"); + std::string pkgbuild = this->GetOption("CPACK_COMMAND_PKGBUILD"); + std::string identityName; + if (const char* n = this->GetOption("CPACK_PKGBUILD_IDENTITY_NAME")) { + identityName = n; + } + std::string keychainPath; + if (const char* p = this->GetOption("CPACK_PKGBUILD_KEYCHAIN_PATH")) { + keychainPath = p; + } + + pkgCmd << pkgbuild << " --root \"" << packageDir << "\"" + << " --identifier \"" << pkgId << "\"" + << " --scripts \"" << scriptDir << "\"" + << " --version \"" << version << "\"" + << " --install-location \"/\"" + << (identityName.empty() ? "" : " --sign \"" + identityName + "\"") + << (keychainPath.empty() ? "" + : " --keychain \"" + keychainPath + "\"") + << " \"" << packageFile << "\""; + + if (component && !component->Plist.empty()) { + pkgCmd << " --component-plist \"" << component->Plist << "\""; + } + + // Run ProductBuild + return RunProductBuild(pkgCmd.str()); +} + +const char* cmCPackProductBuildGenerator::GetComponentScript( + const char* script, const char* component_name) +{ + std::string scriptname = std::string("CPACK_") + script + "_"; + if (component_name) { + scriptname += cmSystemTools::UpperCase(component_name); + scriptname += "_"; + } + scriptname += "SCRIPT"; + + return this->GetOption(scriptname); +} diff --git a/Source/CPack/cmCPackProductBuildGenerator.h b/Source/CPack/cmCPackProductBuildGenerator.h new file mode 100644 index 000000000..12093a0e8 --- /dev/null +++ b/Source/CPack/cmCPackProductBuildGenerator.h @@ -0,0 +1,53 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmCPackProductBuildGenerator_h +#define cmCPackProductBuildGenerator_h + +#include "cmConfigure.h" + +#include <string> + +#include "cmCPackGenerator.h" +#include "cmCPackPKGGenerator.h" + +class cmCPackComponent; + +/** \class cmCPackProductBuildGenerator + * \brief A generator for ProductBuild files + * + */ +class cmCPackProductBuildGenerator : public cmCPackPKGGenerator +{ +public: + cmCPackTypeMacro(cmCPackProductBuildGenerator, cmCPackPKGGenerator); + + /** + * Construct generator + */ + cmCPackProductBuildGenerator(); + virtual ~cmCPackProductBuildGenerator(); + +protected: + int InitializeInternal() CM_OVERRIDE; + int PackageFiles() CM_OVERRIDE; + const char* GetOutputExtension() CM_OVERRIDE { return ".pkg"; } + + // Run ProductBuild with the given command line, which will (if + // successful) produce the given package file. Returns true if + // ProductBuild succeeds, false otherwise. + bool RunProductBuild(const std::string& command); + + // Generate a package in the file packageFile for the given + // component. All of the files within this component are stored in + // the directory packageDir. Returns true if successful, false + // otherwise. + bool GenerateComponentPackage(const std::string& packageFileDir, + const std::string& packageFileName, + const std::string& packageDir, + const cmCPackComponent* component); + + const char* GetComponentScript(const char* script, + const char* script_component); +}; + +#endif diff --git a/Source/CPack/cmCPackRPMGenerator.cxx b/Source/CPack/cmCPackRPMGenerator.cxx index 66a419405..8ec03c236 100644 --- a/Source/CPack/cmCPackRPMGenerator.cxx +++ b/Source/CPack/cmCPackRPMGenerator.cxx @@ -1,99 +1,103 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmCPackRPMGenerator.h" - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. +#include <algorithm> +#include <ctype.h> +#include <map> +#include <ostream> +#include <utility> +#include <vector> - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ -#include "cmCPackRPMGenerator.h" +#include "cmCPackComponentGroup.h" +#include "cmCPackGenerator.h" #include "cmCPackLog.h" #include "cmSystemTools.h" -//---------------------------------------------------------------------- cmCPackRPMGenerator::cmCPackRPMGenerator() { } -//---------------------------------------------------------------------- cmCPackRPMGenerator::~cmCPackRPMGenerator() { } -//---------------------------------------------------------------------- int cmCPackRPMGenerator::InitializeInternal() { this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/usr"); - if (cmSystemTools::IsOff(this->GetOption("CPACK_SET_DESTDIR"))) - { + if (cmSystemTools::IsOff(this->GetOption("CPACK_SET_DESTDIR"))) { this->SetOption("CPACK_SET_DESTDIR", "I_ON"); - } + } /* Replace space in CPACK_PACKAGE_NAME in order to avoid * rpmbuild scream on unwanted space in filename issue * Moreover RPM file do not usually embed space in filename */ if (this->GetOption("CPACK_PACKAGE_NAME")) { - std::string packageName=this->GetOption("CPACK_PACKAGE_NAME"); - cmSystemTools::ReplaceString(packageName," ","-"); - this->SetOption("CPACK_PACKAGE_NAME",packageName.c_str()); + std::string packageName = this->GetOption("CPACK_PACKAGE_NAME"); + std::replace(packageName.begin(), packageName.end(), ' ', '-'); + this->SetOption("CPACK_PACKAGE_NAME", packageName.c_str()); } /* same for CPACK_PACKAGE_FILE_NAME */ if (this->GetOption("CPACK_PACKAGE_FILE_NAME")) { - std::string packageName=this->GetOption("CPACK_PACKAGE_FILE_NAME"); - cmSystemTools::ReplaceString(packageName," ","-"); - this->SetOption("CPACK_PACKAGE_FILE_NAME",packageName.c_str()); + std::string packageName = this->GetOption("CPACK_PACKAGE_FILE_NAME"); + std::replace(packageName.begin(), packageName.end(), ' ', '-'); + this->SetOption("CPACK_PACKAGE_FILE_NAME", packageName.c_str()); } return this->Superclass::InitializeInternal(); } -//---------------------------------------------------------------------- -int cmCPackRPMGenerator::PackageOnePack(std::string initialToplevel, - std::string packageName) +void cmCPackRPMGenerator::AddGeneratedPackageNames() +{ + // add the generated packages to package file names list + std::string fileNames(this->GetOption("GEN_CPACK_OUTPUT_FILES")); + const char sep = ';'; + std::string::size_type pos1 = 0; + std::string::size_type pos2 = fileNames.find(sep, pos1 + 1); + while (pos2 != std::string::npos) { + packageFileNames.push_back(fileNames.substr(pos1, pos2 - pos1)); + pos1 = pos2 + 1; + pos2 = fileNames.find(sep, pos1 + 1); + } + packageFileNames.push_back(fileNames.substr(pos1, pos2 - pos1)); +} + +int cmCPackRPMGenerator::PackageOnePack(std::string const& initialToplevel, + std::string const& packageName) { int retval = 1; // Begin the archive for this pack std::string localToplevel(initialToplevel); - std::string packageFileName( - cmSystemTools::GetParentDirectory(toplevel.c_str()) - ); + std::string packageFileName(cmSystemTools::GetParentDirectory(toplevel)); std::string outputFileName( - GetComponentPackageFileName(this->GetOption("CPACK_PACKAGE_FILE_NAME"), - packageName, - true) - + this->GetOutputExtension() - ); + GetComponentPackageFileName(this->GetOption("CPACK_PACKAGE_FILE_NAME"), + packageName, true) + + this->GetOutputExtension()); - localToplevel += "/"+ packageName; + localToplevel += "/" + packageName; /* replace the TEMP DIRECTORY with the component one */ - this->SetOption("CPACK_TEMPORARY_DIRECTORY",localToplevel.c_str()); - packageFileName += "/"+ outputFileName; + this->SetOption("CPACK_TEMPORARY_DIRECTORY", localToplevel.c_str()); + packageFileName += "/" + outputFileName; /* replace proposed CPACK_OUTPUT_FILE_NAME */ - this->SetOption("CPACK_OUTPUT_FILE_NAME",outputFileName.c_str()); + this->SetOption("CPACK_OUTPUT_FILE_NAME", outputFileName.c_str()); /* replace the TEMPORARY package file name */ this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME", packageFileName.c_str()); // Tell CPackRPM.cmake the name of the component NAME. - this->SetOption("CPACK_RPM_PACKAGE_COMPONENT",packageName.c_str()); + this->SetOption("CPACK_RPM_PACKAGE_COMPONENT", packageName.c_str()); // Tell CPackRPM.cmake the path where the component is. std::string component_path = "/"; component_path += packageName; this->SetOption("CPACK_RPM_PACKAGE_COMPONENT_PART_PATH", component_path.c_str()); - if (!this->ReadListFile("CPackRPM.cmake")) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error while execution CPackRPM.cmake" << std::endl); + if (!this->ReadListFile("CPackRPM.cmake")) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Error while execution CPackRPM.cmake" + << std::endl); retval = 0; - } - // add the generated package to package file names list - packageFileNames.push_back(packageFileName); + } + return retval; } -//---------------------------------------------------------------------- int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup) { int retval = 1; @@ -102,165 +106,319 @@ int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup) packageFileNames.clear(); std::string initialTopLevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY")); - // The default behavior is to have one package by component group - // unless CPACK_COMPONENTS_IGNORE_GROUP is specified. - if (!ignoreGroup) - { - std::map<std::string, cmCPackComponentGroup>::iterator compGIt; - for (compGIt=this->ComponentGroups.begin(); - compGIt!=this->ComponentGroups.end(); ++compGIt) - { - cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Packaging component group: " - << compGIt->first - << std::endl); - retval &= PackageOnePack(initialTopLevel,compGIt->first); + const char* mainComponent = this->GetOption("CPACK_RPM_MAIN_COMPONENT"); + + if (this->IsOn("CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE") && + !this->IsOn("CPACK_RPM_DEBUGINFO_PACKAGE")) { + // check if we need to set CPACK_RPM_DEBUGINFO_PACKAGE because non of + // the components is setting per component debuginfo package variable + bool shouldSet = true; + + if (ignoreGroup) { + std::map<std::string, cmCPackComponent>::iterator compIt; + for (compIt = this->Components.begin(); compIt != this->Components.end(); + ++compIt) { + std::string component(compIt->first); + std::transform(component.begin(), component.end(), component.begin(), + ::toupper); + + if (this->IsOn("CPACK_RPM_" + compIt->first + "_DEBUGINFO_PACKAGE") || + this->IsOn("CPACK_RPM_" + component + "_DEBUGINFO_PACKAGE")) { + shouldSet = false; + break; + } } - // Handle Orphan components (components not belonging to any groups) - std::map<std::string, cmCPackComponent>::iterator compIt; - for (compIt=this->Components.begin(); - compIt!=this->Components.end(); ++compIt ) - { - // Does the component belong to a group? - if (compIt->second.Group==NULL) - { - cmCPackLogger(cmCPackLog::LOG_VERBOSE, - "Component <" - << compIt->second.Name - << "> does not belong to any group, package it separately." - << std::endl); - retval &= PackageOnePack(initialTopLevel,compIt->first); + } else { + std::map<std::string, cmCPackComponentGroup>::iterator compGIt; + for (compGIt = this->ComponentGroups.begin(); + compGIt != this->ComponentGroups.end(); ++compGIt) { + std::string component(compGIt->first); + std::transform(component.begin(), component.end(), component.begin(), + ::toupper); + + if (this->IsOn("CPACK_RPM_" + compGIt->first + "_DEBUGINFO_PACKAGE") || + this->IsOn("CPACK_RPM_" + component + "_DEBUGINFO_PACKAGE")) { + shouldSet = false; + break; } } + + if (shouldSet) { + std::map<std::string, cmCPackComponent>::iterator compIt; + for (compIt = this->Components.begin(); + compIt != this->Components.end(); ++compIt) { + // Does the component belong to a group? + if (compIt->second.Group == CM_NULLPTR) { + std::string component(compIt->first); + std::transform(component.begin(), component.end(), + component.begin(), ::toupper); + + if (this->IsOn("CPACK_RPM_" + compIt->first + + "_DEBUGINFO_PACKAGE") || + this->IsOn("CPACK_RPM_" + component + "_DEBUGINFO_PACKAGE")) { + shouldSet = false; + break; + } + } + } + } + } + + if (shouldSet) { + cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Setting " + << "CPACK_RPM_DEBUGINFO_PACKAGE because " + << "CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE is set but " + << " none of the " + << "CPACK_RPM_<component>_DEBUGINFO_PACKAGE variables " + << "are set." << std::endl); + this->SetOption("CPACK_RPM_DEBUGINFO_PACKAGE", "ON"); + } + } + + if (mainComponent) { + if (this->IsOn("CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE")) { + this->SetOption("GENERATE_SPEC_PARTS", "ON"); } - // CPACK_COMPONENTS_IGNORE_GROUPS is set - // We build 1 package per component - else - { - std::map<std::string, cmCPackComponent>::iterator compIt; - for (compIt=this->Components.begin(); - compIt!=this->Components.end(); ++compIt ) - { - retval &= PackageOnePack(initialTopLevel,compIt->first); + + std::string mainComponentUpper(mainComponent); + std::transform(mainComponentUpper.begin(), mainComponentUpper.end(), + mainComponentUpper.begin(), ::toupper); + + // The default behavior is to have one package by component group + // unless CPACK_COMPONENTS_IGNORE_GROUP is specified. + if (!ignoreGroup) { + std::map<std::string, cmCPackComponentGroup>::iterator mainCompGIt = + this->ComponentGroups.end(); + + std::map<std::string, cmCPackComponentGroup>::iterator compGIt; + for (compGIt = this->ComponentGroups.begin(); + compGIt != this->ComponentGroups.end(); ++compGIt) { + std::string component(compGIt->first); + std::transform(component.begin(), component.end(), component.begin(), + ::toupper); + + if (mainComponentUpper == component) { + // main component will be handled last + mainCompGIt = compGIt; + continue; + } + + cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Packaging component group: " + << compGIt->first << std::endl); + retval &= PackageOnePack(initialTopLevel, compGIt->first); + } + // Handle Orphan components (components not belonging to any groups) + std::map<std::string, cmCPackComponent>::iterator mainCompIt = + this->Components.end(); + std::map<std::string, cmCPackComponent>::iterator compIt; + for (compIt = this->Components.begin(); compIt != this->Components.end(); + ++compIt) { + // Does the component belong to a group? + if (compIt->second.Group == CM_NULLPTR) { + std::string component(compIt->first); + std::transform(component.begin(), component.end(), component.begin(), + ::toupper); + + if (mainComponentUpper == component) { + // main component will be handled last + mainCompIt = compIt; + continue; + } + + cmCPackLogger( + cmCPackLog::LOG_VERBOSE, "Component <" + << compIt->second.Name + << "> does not belong to any group, package it separately." + << std::endl); + retval &= PackageOnePack(initialTopLevel, compIt->first); + } + } + + if (retval) { + this->SetOption("GENERATE_SPEC_PARTS", "OFF"); + + if (mainCompGIt != this->ComponentGroups.end()) { + retval &= PackageOnePack(initialTopLevel, mainCompGIt->first); + } else if (mainCompIt != this->Components.end()) { + retval &= PackageOnePack(initialTopLevel, mainCompIt->first); + } else { + cmCPackLogger(cmCPackLog::LOG_ERROR, "CPACK_RPM_MAIN_COMPONENT set" + << " to non existing component.\n"); + retval = 0; + } } } + // CPACK_COMPONENTS_IGNORE_GROUPS is set + // We build 1 package per component + else { + std::map<std::string, cmCPackComponent>::iterator mainCompIt = + this->Components.end(); + + std::map<std::string, cmCPackComponent>::iterator compIt; + for (compIt = this->Components.begin(); compIt != this->Components.end(); + ++compIt) { + std::string component(compIt->first); + std::transform(component.begin(), component.end(), component.begin(), + ::toupper); + + if (mainComponentUpper == component) { + // main component will be handled last + mainCompIt = compIt; + continue; + } + + retval &= PackageOnePack(initialTopLevel, compIt->first); + } + + if (retval) { + this->SetOption("GENERATE_SPEC_PARTS", "OFF"); + + if (mainCompIt != this->Components.end()) { + retval &= PackageOnePack(initialTopLevel, mainCompIt->first); + } else { + cmCPackLogger(cmCPackLog::LOG_ERROR, "CPACK_RPM_MAIN_COMPONENT set" + << " to non existing component.\n"); + retval = 0; + } + } + } + } else if (!this->IsOn("CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE") || + this->Components.size() == 1) { + // The default behavior is to have one package by component group + // unless CPACK_COMPONENTS_IGNORE_GROUP is specified. + if (!ignoreGroup) { + std::map<std::string, cmCPackComponentGroup>::iterator compGIt; + for (compGIt = this->ComponentGroups.begin(); + compGIt != this->ComponentGroups.end(); ++compGIt) { + cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Packaging component group: " + << compGIt->first << std::endl); + retval &= PackageOnePack(initialTopLevel, compGIt->first); + } + // Handle Orphan components (components not belonging to any groups) + std::map<std::string, cmCPackComponent>::iterator compIt; + for (compIt = this->Components.begin(); compIt != this->Components.end(); + ++compIt) { + // Does the component belong to a group? + if (compIt->second.Group == CM_NULLPTR) { + cmCPackLogger( + cmCPackLog::LOG_VERBOSE, "Component <" + << compIt->second.Name + << "> does not belong to any group, package it separately." + << std::endl); + retval &= PackageOnePack(initialTopLevel, compIt->first); + } + } + } + // CPACK_COMPONENTS_IGNORE_GROUPS is set + // We build 1 package per component + else { + std::map<std::string, cmCPackComponent>::iterator compIt; + for (compIt = this->Components.begin(); compIt != this->Components.end(); + ++compIt) { + retval &= PackageOnePack(initialTopLevel, compIt->first); + } + } + } else { + cmCPackLogger( + cmCPackLog::LOG_ERROR, "CPACK_RPM_MAIN_COMPONENT not set but" + << " it is mandatory with CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE" + << " being set.\n"); + retval = 0; + } + + if (retval) { + AddGeneratedPackageNames(); + } + return retval; } -//---------------------------------------------------------------------- -int cmCPackRPMGenerator::PackageComponentsAllInOne() +int cmCPackRPMGenerator::PackageComponentsAllInOne( + const std::string& compInstDirName) { int retval = 1; - std::string compInstDirName; /* Reset package file name list it will be populated during the * component packaging run*/ packageFileNames.clear(); std::string initialTopLevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY")); - compInstDirName = "ALL_COMPONENTS_IN_ONE"; + if (this->IsOn("CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE")) { + this->SetOption("CPACK_RPM_DEBUGINFO_PACKAGE", "ON"); + } cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Packaging all groups in one package..." "(CPACK_COMPONENTS_ALL_[GROUPS_]IN_ONE_PACKAGE is set)" - << std::endl); + << std::endl); // The ALL GROUPS in ONE package case std::string localToplevel(initialTopLevel); - std::string packageFileName( - cmSystemTools::GetParentDirectory(toplevel.c_str()) - ); + std::string packageFileName(cmSystemTools::GetParentDirectory(toplevel)); std::string outputFileName( - std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME")) - + this->GetOutputExtension() - ); + std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME")) + + this->GetOutputExtension()); // all GROUP in one vs all COMPONENT in one - localToplevel += "/"+compInstDirName; + localToplevel += "/" + compInstDirName; /* replace the TEMP DIRECTORY with the component one */ - this->SetOption("CPACK_TEMPORARY_DIRECTORY",localToplevel.c_str()); - packageFileName += "/"+ outputFileName; + this->SetOption("CPACK_TEMPORARY_DIRECTORY", localToplevel.c_str()); + packageFileName += "/" + outputFileName; /* replace proposed CPACK_OUTPUT_FILE_NAME */ - this->SetOption("CPACK_OUTPUT_FILE_NAME",outputFileName.c_str()); + this->SetOption("CPACK_OUTPUT_FILE_NAME", outputFileName.c_str()); /* replace the TEMPORARY package file name */ this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME", - packageFileName.c_str()); - // Tell CPackRPM.cmake the path where the component is. - std::string component_path = "/"; - component_path += compInstDirName; - this->SetOption("CPACK_RPM_PACKAGE_COMPONENT_PART_PATH", - component_path.c_str()); - if (!this->ReadListFile("CPackRPM.cmake")) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error while execution CPackRPM.cmake" << std::endl); + packageFileName.c_str()); + + if (!compInstDirName.empty()) { + // Tell CPackRPM.cmake the path where the component is. + std::string component_path = "/"; + component_path += compInstDirName; + this->SetOption("CPACK_RPM_PACKAGE_COMPONENT_PART_PATH", + component_path.c_str()); + } + + if (this->ReadListFile("CPackRPM.cmake")) { + AddGeneratedPackageNames(); + } else { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Error while execution CPackRPM.cmake" + << std::endl); retval = 0; - } - // add the generated package to package file names list - packageFileNames.push_back(packageFileName); + } return retval; } -//---------------------------------------------------------------------- int cmCPackRPMGenerator::PackageFiles() { - int retval = 1; - - cmCPackLogger(cmCPackLog::LOG_DEBUG, "Toplevel: " - << toplevel << std::endl); + cmCPackLogger(cmCPackLog::LOG_DEBUG, "Toplevel: " << toplevel << std::endl); /* Are we in the component packaging case */ if (WantsComponentInstallation()) { // CASE 1 : COMPONENT ALL-IN-ONE package // If ALL COMPONENTS in ONE package has been requested // then the package file is unique and should be open here. - if (componentPackageMethod == ONE_PACKAGE) - { - return PackageComponentsAllInOne(); - } + if (componentPackageMethod == ONE_PACKAGE) { + return PackageComponentsAllInOne("ALL_COMPONENTS_IN_ONE"); + } // CASE 2 : COMPONENT CLASSICAL package(s) (i.e. not all-in-one) // There will be 1 package for each component group // however one may require to ignore component group and // in this case you'll get 1 package for each component. - else - { - return PackageComponents(componentPackageMethod == - ONE_PACKAGE_PER_COMPONENT); - } + return PackageComponents(componentPackageMethod == + ONE_PACKAGE_PER_COMPONENT); } // CASE 3 : NON COMPONENT package. - else - { - if (!this->ReadListFile("CPackRPM.cmake")) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error while execution CPackRPM.cmake" << std::endl); - retval = 0; - } - } - - if (!this->IsSet("RPMBUILD_EXECUTABLE")) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find rpmbuild" << std::endl); - retval = 0; - } - return retval; + return PackageComponentsAllInOne(""); } bool cmCPackRPMGenerator::SupportsComponentInstallation() const - { - if (IsOn("CPACK_RPM_COMPONENT_INSTALL")) - { - return true; - } - else - { - return false; - } - } +{ + return IsOn("CPACK_RPM_COMPONENT_INSTALL"); +} std::string cmCPackRPMGenerator::GetComponentInstallDirNameSuffix( - const std::string& componentName) - { + const std::string& componentName) +{ if (componentPackageMethod == ONE_PACKAGE_PER_COMPONENT) { return componentName; } @@ -270,14 +428,10 @@ std::string cmCPackRPMGenerator::GetComponentInstallDirNameSuffix( } // We have to find the name of the COMPONENT GROUP // the current COMPONENT belongs to. - std::string groupVar = "CPACK_COMPONENT_" + - cmSystemTools::UpperCase(componentName) + "_GROUP"; - if (NULL != GetOption(groupVar.c_str())) - { - return std::string(GetOption(groupVar.c_str())); - } - else - { - return componentName; - } + std::string groupVar = + "CPACK_COMPONENT_" + cmSystemTools::UpperCase(componentName) + "_GROUP"; + if (CM_NULLPTR != GetOption(groupVar)) { + return std::string(GetOption(groupVar)); } + return componentName; +} diff --git a/Source/CPack/cmCPackRPMGenerator.h b/Source/CPack/cmCPackRPMGenerator.h index a7722bc58..52cfc13ed 100644 --- a/Source/CPack/cmCPackRPMGenerator.h +++ b/Source/CPack/cmCPackRPMGenerator.h @@ -1,21 +1,14 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc. - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #ifndef cmCPackRPMGenerator_h #define cmCPackRPMGenerator_h +#include "cmConfigure.h" #include "cmCPackGenerator.h" +#include <string> + /** \class cmCPackRPMGenerator * \brief A generator for RPM packages * The idea of the CPack RPM generator is to use @@ -33,10 +26,10 @@ public: * Construct generator */ cmCPackRPMGenerator(); - virtual ~cmCPackRPMGenerator(); + ~cmCPackRPMGenerator() CM_OVERRIDE; static bool CanGenerate() - { + { #ifdef __APPLE__ // on MacOS enable CPackRPM iff rpmbuild is found std::vector<std::string> locations; @@ -47,15 +40,16 @@ public: // legacy behavior on other systems return true; #endif - } + } protected: - virtual int InitializeInternal(); - virtual int PackageFiles(); + int InitializeInternal() CM_OVERRIDE; + int PackageFiles() CM_OVERRIDE; /** * This method factors out the work done in component packaging case. */ - int PackageOnePack(std::string initialToplevel, std::string packageName); + int PackageOnePack(std::string const& initialToplevel, + std::string const& packageName); /** * The method used to package files when component * install is used. This will create one @@ -66,12 +60,13 @@ protected: * Special case of component install where all * components will be put in a single installer. */ - int PackageComponentsAllInOne(); - virtual const char* GetOutputExtension() { return ".rpm"; } - virtual bool SupportsComponentInstallation() const; - virtual std::string GetComponentInstallDirNameSuffix( - const std::string& componentName); + int PackageComponentsAllInOne(const std::string& compInstDirName); + const char* GetOutputExtension() CM_OVERRIDE { return ".rpm"; } + bool SupportsComponentInstallation() const CM_OVERRIDE; + std::string GetComponentInstallDirNameSuffix( + const std::string& componentName) CM_OVERRIDE; + void AddGeneratedPackageNames(); }; #endif diff --git a/Source/CPack/cmCPackSTGZGenerator.cxx b/Source/CPack/cmCPackSTGZGenerator.cxx index 9b6cf14df..c54161426 100644 --- a/Source/CPack/cmCPackSTGZGenerator.cxx +++ b/Source/CPack/cmCPackSTGZGenerator.cxx @@ -1,102 +1,81 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCPackSTGZGenerator.h" -#include "cmake.h" -#include "cmGlobalGenerator.h" -#include "cmLocalGenerator.h" -#include "cmSystemTools.h" -#include "cmMakefile.h" -#include "cmCPackLog.h" +#include "cmsys/FStream.hxx" +#include <sstream> +#include <stdio.h> +#include <string> +#include <vector> -#include <cmsys/ios/sstream> -#include <sys/types.h> -#include <sys/stat.h> +#include "cmCPackGenerator.h" +#include "cmCPackLog.h" +#include "cmSystemTools.h" +#include "cm_sys_stat.h" -//---------------------------------------------------------------------- cmCPackSTGZGenerator::cmCPackSTGZGenerator() { } -//---------------------------------------------------------------------- cmCPackSTGZGenerator::~cmCPackSTGZGenerator() { } -//---------------------------------------------------------------------- int cmCPackSTGZGenerator::InitializeInternal() { this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0"); std::string inFile = this->FindTemplate("CPack.STGZ_Header.sh.in"); - if ( inFile.empty() ) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find template file: " - << inFile.c_str() << std::endl); + if (inFile.empty()) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Cannot find template file: " << inFile << std::endl); return 0; - } + } this->SetOptionIfNotSet("CPACK_STGZ_HEADER_FILE", inFile.c_str()); this->SetOptionIfNotSet("CPACK_AT_SIGN", "@"); return this->Superclass::InitializeInternal(); } -//---------------------------------------------------------------------- int cmCPackSTGZGenerator::PackageFiles() { - bool retval = true; - if ( !this->Superclass::PackageFiles() ) - { + bool retval = true; + if (!this->Superclass::PackageFiles()) { return 0; - } + } /* TGZ generator (our Superclass) may * have generated several packages (component packaging) * so we must iterate over generated packages. */ - for (std::vector<std::string>::iterator it=packageFileNames.begin(); - it != packageFileNames.end(); ++it) - { + for (std::vector<std::string>::iterator it = packageFileNames.begin(); + it != packageFileNames.end(); ++it) { retval &= cmSystemTools::SetPermissions((*it).c_str(), -#if defined( _MSC_VER ) || defined( __MINGW32__ ) - S_IREAD | S_IWRITE | S_IEXEC -#elif defined( __BORLANDC__ ) - S_IRUSR | S_IWUSR | S_IXUSR +#if defined(_MSC_VER) || defined(__MINGW32__) + S_IREAD | S_IWRITE | S_IEXEC #else - S_IRUSR | S_IWUSR | S_IXUSR | - S_IRGRP | S_IWGRP | S_IXGRP | - S_IROTH | S_IWOTH | S_IXOTH + S_IRUSR | S_IWUSR | S_IXUSR | + S_IRGRP | S_IWGRP | S_IXGRP | + S_IROTH | S_IWOTH | S_IXOTH #endif - ); + ); } return retval; } -//---------------------------------------------------------------------- int cmCPackSTGZGenerator::GenerateHeader(std::ostream* os) { cmCPackLogger(cmCPackLog::LOG_DEBUG, "Writing header" << std::endl); - cmsys_ios::ostringstream str; + std::ostringstream str; int counter = 0; std::string inLicFile = this->GetOption("CPACK_RESOURCE_FILE_LICENSE"); std::string line; - std::ifstream ilfs(inLicFile.c_str()); + cmsys::ifstream ilfs(inLicFile.c_str()); std::string licenseText; - while ( cmSystemTools::GetLineFromStream(ilfs, line) ) - { + while (cmSystemTools::GetLineFromStream(ilfs, line)) { licenseText += line + "\n"; - } + } this->SetOptionIfNotSet("CPACK_RESOURCE_FILE_LICENSE_CONTENT", licenseText.c_str()); @@ -104,12 +83,11 @@ int cmCPackSTGZGenerator::GenerateHeader(std::ostream* os) // Create the header std::string inFile = this->GetOption("CPACK_STGZ_HEADER_FILE"); - std::ifstream ifs(inFile.c_str()); + cmsys::ifstream ifs(inFile.c_str()); std::string packageHeaderText; - while ( cmSystemTools::GetLineFromStream(ifs, line) ) - { + while (cmSystemTools::GetLineFromStream(ifs, line)) { packageHeaderText += line + "\n"; - } + } // Configure in the values std::string res; @@ -117,22 +95,20 @@ int cmCPackSTGZGenerator::GenerateHeader(std::ostream* os) // Count the lines const char* ptr = res.c_str(); - while ( *ptr ) - { - if ( *ptr == '\n' ) - { - counter ++; - } - ++ptr; + while (*ptr) { + if (*ptr == '\n') { + counter++; } - counter ++; - cmCPackLogger(cmCPackLog::LOG_DEBUG, - "Number of lines: " << counter << std::endl); + ++ptr; + } + counter++; + cmCPackLogger(cmCPackLog::LOG_DEBUG, "Number of lines: " << counter + << std::endl); char buffer[1024]; sprintf(buffer, "%d", counter); cmSystemTools::ReplaceString(res, headerLengthTag, buffer); // Write in file - *os << res.c_str(); + *os << res; return this->Superclass::GenerateHeader(os); } diff --git a/Source/CPack/cmCPackSTGZGenerator.h b/Source/CPack/cmCPackSTGZGenerator.h index ccceec806..8304e8076 100644 --- a/Source/CPack/cmCPackSTGZGenerator.h +++ b/Source/CPack/cmCPackSTGZGenerator.h @@ -1,21 +1,15 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc. - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #ifndef cmCPackSTGZGenerator_h #define cmCPackSTGZGenerator_h +#include "cmConfigure.h" +#include "cmCPackGenerator.h" #include "cmCPackTGZGenerator.h" +#include <iosfwd> + /** \class cmCPackSTGZGenerator * \brief A generator for Self extractable TGZ files * @@ -29,13 +23,13 @@ public: * Construct generator */ cmCPackSTGZGenerator(); - virtual ~cmCPackSTGZGenerator(); + ~cmCPackSTGZGenerator() CM_OVERRIDE; protected: - int PackageFiles(); - virtual int InitializeInternal(); - int GenerateHeader(std::ostream* os); - virtual const char* GetOutputExtension() { return ".sh"; } + int PackageFiles() CM_OVERRIDE; + int InitializeInternal() CM_OVERRIDE; + int GenerateHeader(std::ostream* os) CM_OVERRIDE; + const char* GetOutputExtension() CM_OVERRIDE { return ".sh"; } }; #endif diff --git a/Source/CPack/cmCPackTGZGenerator.cxx b/Source/CPack/cmCPackTGZGenerator.cxx index 509c7f80a..eaf8186fe 100644 --- a/Source/CPack/cmCPackTGZGenerator.cxx +++ b/Source/CPack/cmCPackTGZGenerator.cxx @@ -1,26 +1,15 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCPackTGZGenerator.h" -//---------------------------------------------------------------------- +#include "cmArchiveWrite.h" +#include "cmCPackArchiveGenerator.h" + cmCPackTGZGenerator::cmCPackTGZGenerator() - :cmCPackArchiveGenerator(cmArchiveWrite::CompressGZip, - cmArchiveWrite::TypeTAR) + : cmCPackArchiveGenerator(cmArchiveWrite::CompressGZip, "paxr") { } -//---------------------------------------------------------------------- cmCPackTGZGenerator::~cmCPackTGZGenerator() { } - diff --git a/Source/CPack/cmCPackTGZGenerator.h b/Source/CPack/cmCPackTGZGenerator.h index 3a9fc6b41..9426b3a01 100644 --- a/Source/CPack/cmCPackTGZGenerator.h +++ b/Source/CPack/cmCPackTGZGenerator.h @@ -1,19 +1,12 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc. - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #ifndef cmCPackTGZGenerator_h #define cmCPackTGZGenerator_h +#include "cmConfigure.h" + #include "cmCPackArchiveGenerator.h" +#include "cmCPackGenerator.h" /** \class cmCPackTGZGenerator * \brief A generator for TGZ files @@ -27,9 +20,10 @@ public: * Construct generator */ cmCPackTGZGenerator(); - virtual ~cmCPackTGZGenerator(); + ~cmCPackTGZGenerator() CM_OVERRIDE; + protected: - virtual const char* GetOutputExtension() { return ".tar.gz"; } + const char* GetOutputExtension() CM_OVERRIDE { return ".tar.gz"; } }; #endif diff --git a/Source/CPack/cmCPackTXZGenerator.cxx b/Source/CPack/cmCPackTXZGenerator.cxx new file mode 100644 index 000000000..e55e903e9 --- /dev/null +++ b/Source/CPack/cmCPackTXZGenerator.cxx @@ -0,0 +1,15 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmCPackTXZGenerator.h" + +#include "cmArchiveWrite.h" +#include "cmCPackArchiveGenerator.h" + +cmCPackTXZGenerator::cmCPackTXZGenerator() + : cmCPackArchiveGenerator(cmArchiveWrite::CompressXZ, "paxr") +{ +} + +cmCPackTXZGenerator::~cmCPackTXZGenerator() +{ +} diff --git a/Source/CPack/cmCPackTXZGenerator.h b/Source/CPack/cmCPackTXZGenerator.h new file mode 100644 index 000000000..3b96e2d78 --- /dev/null +++ b/Source/CPack/cmCPackTXZGenerator.h @@ -0,0 +1,29 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmCPackTXZGenerator_h +#define cmCPackTXZGenerator_h + +#include "cmConfigure.h" + +#include "cmCPackArchiveGenerator.h" +#include "cmCPackGenerator.h" + +/** \class cmCPackTXZGenerator + * \brief A generator for TXZ files + * + */ +class cmCPackTXZGenerator : public cmCPackArchiveGenerator +{ +public: + cmCPackTypeMacro(cmCPackTXZGenerator, cmCPackArchiveGenerator); + /** + * Construct generator + */ + cmCPackTXZGenerator(); + ~cmCPackTXZGenerator() CM_OVERRIDE; + +protected: + const char* GetOutputExtension() CM_OVERRIDE { return ".tar.xz"; } +}; + +#endif diff --git a/Source/CPack/cmCPackTarBZip2Generator.cxx b/Source/CPack/cmCPackTarBZip2Generator.cxx index ae73c3795..c7a3dd429 100644 --- a/Source/CPack/cmCPackTarBZip2Generator.cxx +++ b/Source/CPack/cmCPackTarBZip2Generator.cxx @@ -1,25 +1,15 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmCPackTarBZip2Generator.h" - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ +#include "cmArchiveWrite.h" +#include "cmCPackArchiveGenerator.h" -#include "cmCPackTarBZip2Generator.h" -//---------------------------------------------------------------------- cmCPackTarBZip2Generator::cmCPackTarBZip2Generator() - :cmCPackArchiveGenerator(cmArchiveWrite::CompressBZip2, - cmArchiveWrite::TypeTAR) + : cmCPackArchiveGenerator(cmArchiveWrite::CompressBZip2, "paxr") { } -//---------------------------------------------------------------------- cmCPackTarBZip2Generator::~cmCPackTarBZip2Generator() { } - diff --git a/Source/CPack/cmCPackTarBZip2Generator.h b/Source/CPack/cmCPackTarBZip2Generator.h index 74c244e5a..9b4b8f4ff 100644 --- a/Source/CPack/cmCPackTarBZip2Generator.h +++ b/Source/CPack/cmCPackTarBZip2Generator.h @@ -1,19 +1,12 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc. - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #ifndef cmCPackTarBZip2Generator_h #define cmCPackTarBZip2Generator_h +#include "cmConfigure.h" + #include "cmCPackArchiveGenerator.h" +#include "cmCPackGenerator.h" /** \class cmCPackTarBZip2Generator * \brief A generator for TarBZip2 files @@ -26,9 +19,10 @@ public: * Construct generator */ cmCPackTarBZip2Generator(); - virtual ~cmCPackTarBZip2Generator(); + ~cmCPackTarBZip2Generator() CM_OVERRIDE; + protected: - virtual const char* GetOutputExtension() { return ".tar.bz2"; } + const char* GetOutputExtension() CM_OVERRIDE { return ".tar.bz2"; } }; #endif diff --git a/Source/CPack/cmCPackTarCompressGenerator.cxx b/Source/CPack/cmCPackTarCompressGenerator.cxx index df294084c..0a7cd978c 100644 --- a/Source/CPack/cmCPackTarCompressGenerator.cxx +++ b/Source/CPack/cmCPackTarCompressGenerator.cxx @@ -1,26 +1,15 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCPackTarCompressGenerator.h" -//---------------------------------------------------------------------- +#include "cmArchiveWrite.h" +#include "cmCPackArchiveGenerator.h" + cmCPackTarCompressGenerator::cmCPackTarCompressGenerator() - :cmCPackArchiveGenerator(cmArchiveWrite::CompressCompress, - cmArchiveWrite::TypeTAR) + : cmCPackArchiveGenerator(cmArchiveWrite::CompressCompress, "paxr") { } -//---------------------------------------------------------------------- cmCPackTarCompressGenerator::~cmCPackTarCompressGenerator() { } - diff --git a/Source/CPack/cmCPackTarCompressGenerator.h b/Source/CPack/cmCPackTarCompressGenerator.h index 7ff9a0ade..381d6eb2f 100644 --- a/Source/CPack/cmCPackTarCompressGenerator.h +++ b/Source/CPack/cmCPackTarCompressGenerator.h @@ -1,19 +1,12 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc. - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #ifndef cmCPackTarCompressGenerator_h #define cmCPackTarCompressGenerator_h -#include "cmCPackTGZGenerator.h" +#include "cmConfigure.h" + +#include "cmCPackArchiveGenerator.h" +#include "cmCPackGenerator.h" /** \class cmCPackTarCompressGenerator * \brief A generator for TarCompress files @@ -26,10 +19,10 @@ public: * Construct generator */ cmCPackTarCompressGenerator(); - virtual ~cmCPackTarCompressGenerator(); + ~cmCPackTarCompressGenerator() CM_OVERRIDE; protected: - virtual const char* GetOutputExtension() { return ".tar.Z"; } + const char* GetOutputExtension() CM_OVERRIDE { return ".tar.Z"; } }; #endif diff --git a/Source/CPack/cmCPackZIPGenerator.cxx b/Source/CPack/cmCPackZIPGenerator.cxx index e6e4e77d0..6b77c363d 100644 --- a/Source/CPack/cmCPackZIPGenerator.cxx +++ b/Source/CPack/cmCPackZIPGenerator.cxx @@ -1,26 +1,15 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCPackZIPGenerator.h" -//---------------------------------------------------------------------- +#include "cmArchiveWrite.h" +#include "cmCPackArchiveGenerator.h" + cmCPackZIPGenerator::cmCPackZIPGenerator() - :cmCPackArchiveGenerator(cmArchiveWrite::CompressNone, - cmArchiveWrite::TypeZIP) + : cmCPackArchiveGenerator(cmArchiveWrite::CompressNone, "zip") { } -//---------------------------------------------------------------------- cmCPackZIPGenerator::~cmCPackZIPGenerator() { } - diff --git a/Source/CPack/cmCPackZIPGenerator.h b/Source/CPack/cmCPackZIPGenerator.h index 70e1a5fa8..00c872029 100644 --- a/Source/CPack/cmCPackZIPGenerator.h +++ b/Source/CPack/cmCPackZIPGenerator.h @@ -1,19 +1,12 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc. - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #ifndef cmCPackZIPGenerator_h #define cmCPackZIPGenerator_h +#include "cmConfigure.h" + #include "cmCPackArchiveGenerator.h" +#include "cmCPackGenerator.h" /** \class cmCPackZIPGenerator * \brief A generator for ZIP files @@ -27,10 +20,10 @@ public: * Construct generator */ cmCPackZIPGenerator(); - virtual ~cmCPackZIPGenerator(); + ~cmCPackZIPGenerator() CM_OVERRIDE; protected: - virtual const char* GetOutputExtension() { return ".zip"; } + const char* GetOutputExtension() CM_OVERRIDE { return ".zip"; } }; #endif diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index b18891858..a44bc3d68 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -1,184 +1,105 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ -#include "cmSystemTools.h" +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmConfigure.h" + +#include "cmsys/CommandLineArguments.hxx" +#include "cmsys/Encoding.hxx" +#include <iostream> +#include <map> +#include <sstream> +#include <stddef.h> +#include <string> +#include <utility> +#include <vector> + +#if defined(_WIN32) && defined(CMAKE_BUILD_WITH_CMAKE) +#include "cmsys/ConsoleBuf.hxx" +#endif -// Need these for documentation support. -#include "cmake.h" -#include "cmDocumentation.h" -#include "cmCPackDocumentVariables.h" -#include "cmCPackDocumentMacros.h" -#include "cmCPackGeneratorFactory.h" #include "cmCPackGenerator.h" -#include "cmake.h" +#include "cmCPackGeneratorFactory.h" +#include "cmCPackLog.h" +#include "cmDocumentation.h" +#include "cmDocumentationEntry.h" #include "cmGlobalGenerator.h" -#include "cmLocalGenerator.h" #include "cmMakefile.h" +#include "cmStateSnapshot.h" +#include "cmSystemTools.h" +#include "cm_auto_ptr.hxx" +#include "cmake.h" -#include "cmCPackLog.h" - -#include <cmsys/CommandLineArguments.hxx> -#include <cmsys/SystemTools.hxx> - -//---------------------------------------------------------------------------- -static const char * cmDocumentationName[][3] = -{ - {0, - " cpack - Packaging driver provided by CMake.", 0}, - {0,0,0} -}; - -//---------------------------------------------------------------------------- -static const char * cmDocumentationUsage[][3] = -{ - {0, - " cpack -G <generator> [options]", - 0}, - {0,0,0} +static const char* cmDocumentationName[][2] = { + { CM_NULLPTR, " cpack - Packaging driver provided by CMake." }, + { CM_NULLPTR, CM_NULLPTR } }; -//---------------------------------------------------------------------------- -static const char * cmDocumentationDescription[][3] = -{ - {0, - "The \"cpack\" executable is the CMake packaging program. " - "CMake-generated build trees created for projects that use " - "the INSTALL_* commands have packaging support. " - "This program will generate the package.", 0}, - CMAKE_STANDARD_INTRODUCTION, - {0,0,0} +static const char* cmDocumentationUsage[][2] = { + { CM_NULLPTR, " cpack -G <generator> [options]" }, + { CM_NULLPTR, CM_NULLPTR } }; -//---------------------------------------------------------------------------- -static const char * cmDocumentationOptions[][3] = -{ - {"-G <generator>", "Use the specified generator to generate package.", - "CPack may support multiple native packaging systems on certain " - "platforms. A generator is responsible for generating input files for " - "particular system and invoking that systems. Possible generator names " - "are specified in the Generators section." }, - {"-C <Configuration>", "Specify the project configuration", - "This option specifies the configuration that the project was build " - "with, for example 'Debug', 'Release'." }, - {"-D <var>=<value>", "Set a CPack variable.", \ - "Set a variable that can be used by the generator."}, \ - {"--config <config file>", "Specify the config file.", - "Specify the config file to use to create the package. By default " - "CPackConfig.cmake in the current directory will be used." }, - {"--verbose,-V","enable verbose output","Run cpack with verbose output."}, - {"--debug","enable debug output (for CPack developers)", - "Run cpack with debug output (for CPack developers)."}, - {"-P <package name>","override/define CPACK_PACKAGE_NAME", - "If the package name is not specified on cpack commmand line then" - "CPack.cmake defines it as CMAKE_PROJECT_NAME"}, - {"-R <package version>","override/define CPACK_PACKAGE_VERSION", - "If version is not specified on cpack command line then" - "CPack.cmake defines it from CPACK_PACKAGE_VERSION_[MAJOR|MINOR|PATCH]" - "look into CPack.cmake for detail"}, - {"-B <package directory>","override/define CPACK_PACKAGE_DIRECTORY", - "The directory where CPack will be doing its packaging work." - "The resulting package will be found there. Inside this directory" - "CPack creates '_CPack_Packages' sub-directory which is the" - "CPack temporary directory."}, - {"--vendor <vendor name>","override/define CPACK_PACKAGE_VENDOR", - "If vendor is not specified on cpack command line " - "(or inside CMakeLists.txt) then" - "CPack.cmake defines it with a default value"}, - {"--help-command cmd [file]", "Print help for a single command and exit.", - "Full documentation specific to the given command is displayed. " - "If a file is specified, the documentation is written into and the output " - "format is determined depending on the filename suffix. Supported are man " - "page, HTML, DocBook and plain text."}, - {"--help-command-list [file]", "List available commands and exit.", - "The list contains all commands for which help may be obtained by using " - "the --help-command argument followed by a command name. " - "If a file is specified, the documentation is written into and the output " - "format is determined depending on the filename suffix. Supported are man " - "page, HTML, DocBook and plain text."}, - {"--help-commands [file]", "Print help for all commands and exit.", - "Full documentation specific for all current command is displayed." - "If a file is specified, the documentation is written into and the output " - "format is determined depending on the filename suffix. Supported are man " - "page, HTML, DocBook and plain text."}, - {"--help-variable var [file]", - "Print help for a single variable and exit.", - "Full documentation specific to the given variable is displayed." - "If a file is specified, the documentation is written into and the output " - "format is determined depending on the filename suffix. Supported are man " - "page, HTML, DocBook and plain text."}, - {"--help-variable-list [file]", "List documented variables and exit.", - "The list contains all variables for which help may be obtained by using " - "the --help-variable argument followed by a variable name. If a file is " - "specified, the help is written into it." - "If a file is specified, the documentation is written into and the output " - "format is determined depending on the filename suffix. Supported are man " - "page, HTML, DocBook and plain text."}, - {"--help-variables [file]", "Print help for all variables and exit.", - "Full documentation for all variables is displayed." - "If a file is specified, the documentation is written into and the output " - "format is determined depending on the filename suffix. Supported are man " - "page, HTML, DocBook and plain text."}, - {0,0,0} +static const char* cmDocumentationOptions[][2] = { + { "-G <generator>", "Use the specified generator to generate package." }, + { "-C <Configuration>", "Specify the project configuration" }, + { "-D <var>=<value>", "Set a CPack variable." }, + { "--config <config file>", "Specify the config file." }, + { "--verbose,-V", "enable verbose output" }, + { "--debug", "enable debug output (for CPack developers)" }, + { "-P <package name>", "override/define CPACK_PACKAGE_NAME" }, + { "-R <package version>", "override/define CPACK_PACKAGE_VERSION" }, + { "-B <package directory>", "override/define CPACK_PACKAGE_DIRECTORY" }, + { "--vendor <vendor name>", "override/define CPACK_PACKAGE_VENDOR" }, + { CM_NULLPTR, CM_NULLPTR } }; -//---------------------------------------------------------------------------- -static const char * cmDocumentationSeeAlso[][3] = -{ - {0, "cmake", 0}, - {0, "ccmake", 0}, - {0, 0, 0} -}; - -//---------------------------------------------------------------------------- -int cpackUnknownArgument(const char*, void*) +int cpackUnknownArgument(const char* /*unused*/, void* /*unused*/) { return 1; } -//---------------------------------------------------------------------------- struct cpackDefinitions { - typedef std::map<cmStdString, cmStdString> MapType; + typedef std::map<std::string, std::string> MapType; MapType Map; - cmCPackLog *Log; + cmCPackLog* Log; }; -//---------------------------------------------------------------------------- int cpackDefinitionArgument(const char* argument, const char* cValue, - void* call_data) + void* call_data) { (void)argument; cpackDefinitions* def = static_cast<cpackDefinitions*>(call_data); std::string value = cValue; - size_t pos = value.find_first_of("="); - if ( pos == std::string::npos ) - { + size_t pos = value.find_first_of('='); + if (pos == std::string::npos) { cmCPack_Log(def->Log, cmCPackLog::LOG_ERROR, - "Please specify CPack definitions as: KEY=VALUE" << std::endl); + "Please specify CPack definitions as: KEY=VALUE" << std::endl); return 0; - } + } std::string key = value.substr(0, pos); value = value.c_str() + pos + 1; def->Map[key] = value; cmCPack_Log(def->Log, cmCPackLog::LOG_DEBUG, "Set CPack variable: " - << key.c_str() << " to \"" << value.c_str() << "\"" << std::endl); + << key << " to \"" << value << "\"" << std::endl); return 1; } - -//---------------------------------------------------------------------------- // this is CPack. -int main (int argc, char *argv[]) +int main(int argc, char const* const* argv) { - cmSystemTools::FindExecutableDirectory(argv[0]); +#if defined(_WIN32) && defined(CMAKE_BUILD_WITH_CMAKE) + // Replace streambuf so we can output Unicode to console + cmsys::ConsoleBuf::Manager consoleOut(std::cout); + consoleOut.SetUTF8Pipes(); + cmsys::ConsoleBuf::Manager consoleErr(std::cerr, true); + consoleErr.SetUTF8Pipes(); +#endif + cmsys::Encoding::CommandLineArguments args = + cmsys::Encoding::CommandLineArguments::Main(argc, argv); + argc = args.argc(); + argv = args.argv(); + + cmSystemTools::FindCMakeResources(argv[0]); cmCPackLog log; log.SetErrorPrefix("CPack Error: "); @@ -188,12 +109,12 @@ int main (int argc, char *argv[]) cmSystemTools::EnableMSVCDebugHook(); - if ( cmSystemTools::GetCurrentWorkingDirectory().size() == 0 ) - { + if (cmSystemTools::GetCurrentWorkingDirectory().empty()) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, - "Current working directory cannot be established." << std::endl); + "Current working directory cannot be established." + << std::endl); return 1; - } + } std::string generator; bool help = false; @@ -223,9 +144,9 @@ int main (int argc, char *argv[]) // Help arguments arg.AddArgument("--help", argT::NO_ARGUMENT, &help, "CPack help"); arg.AddArgument("--help-full", argT::SPACE_ARGUMENT, &helpFull, - "CPack help"); + "CPack help"); arg.AddArgument("--help-html", argT::SPACE_ARGUMENT, &helpHTML, - "CPack help"); + "CPack help"); arg.AddArgument("--help-man", argT::SPACE_ARGUMENT, &helpMAN, "CPack help"); arg.AddArgument("--version", argT::NO_ARGUMENT, &helpVersion, "CPack help"); @@ -233,61 +154,61 @@ int main (int argc, char *argv[]) arg.AddArgument("--verbose", argT::NO_ARGUMENT, &verbose, "-V"); arg.AddArgument("--debug", argT::NO_ARGUMENT, &debug, "-V"); arg.AddArgument("--config", argT::SPACE_ARGUMENT, &cpackConfigFile, - "CPack configuration file"); + "CPack configuration file"); arg.AddArgument("-C", argT::SPACE_ARGUMENT, &cpackBuildConfig, - "CPack build configuration"); - arg.AddArgument("-G", argT::SPACE_ARGUMENT, - &generator, "CPack generator"); - arg.AddArgument("-P", argT::SPACE_ARGUMENT, - &cpackProjectName, "CPack project name"); - arg.AddArgument("-R", argT::SPACE_ARGUMENT, - &cpackProjectVersion, "CPack project version"); - arg.AddArgument("-B", argT::SPACE_ARGUMENT, - &cpackProjectDirectory, "CPack project directory"); - arg.AddArgument("--patch", argT::SPACE_ARGUMENT, - &cpackProjectPatch, "CPack project patch"); - arg.AddArgument("--vendor", argT::SPACE_ARGUMENT, - &cpackProjectVendor, "CPack project vendor"); - arg.AddCallback("-D", argT::SPACE_ARGUMENT, - cpackDefinitionArgument, &definitions, "CPack Definitions"); + "CPack build configuration"); + arg.AddArgument("-G", argT::SPACE_ARGUMENT, &generator, "CPack generator"); + arg.AddArgument("-P", argT::SPACE_ARGUMENT, &cpackProjectName, + "CPack project name"); + arg.AddArgument("-R", argT::SPACE_ARGUMENT, &cpackProjectVersion, + "CPack project version"); + arg.AddArgument("-B", argT::SPACE_ARGUMENT, &cpackProjectDirectory, + "CPack project directory"); + arg.AddArgument("--patch", argT::SPACE_ARGUMENT, &cpackProjectPatch, + "CPack project patch"); + arg.AddArgument("--vendor", argT::SPACE_ARGUMENT, &cpackProjectVendor, + "CPack project vendor"); + arg.AddCallback("-D", argT::SPACE_ARGUMENT, cpackDefinitionArgument, + &definitions, "CPack Definitions"); arg.SetUnknownArgumentCallback(cpackUnknownArgument); // Parse command line int parsed = arg.Parse(); // Setup logging - if ( verbose ) - { + if (verbose) { log.SetVerbose(verbose); cmCPack_Log(&log, cmCPackLog::LOG_OUTPUT, "Enable Verbose" << std::endl); - } - if ( debug ) - { + } + if (debug) { log.SetDebug(debug); cmCPack_Log(&log, cmCPackLog::LOG_OUTPUT, "Enable Debug" << std::endl); - } + } cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, - "Read CPack config file: " << cpackConfigFile.c_str() << std::endl); - - cmake cminst; - cminst.RemoveUnscriptableCommands(); - cmGlobalGenerator cmgg; - cmgg.SetCMakeInstance(&cminst); - cmsys::auto_ptr<cmLocalGenerator> cmlg(cmgg.CreateLocalGenerator()); - cmMakefile* globalMF = cmlg->GetMakefile(); + "Read CPack config file: " << cpackConfigFile << std::endl); + + cmake cminst(cmake::RoleScript); + cminst.SetHomeDirectory(""); + cminst.SetHomeOutputDirectory(""); + cminst.GetCurrentSnapshot().SetDefaultDefinitions(); + cmGlobalGenerator cmgg(&cminst); + CM_AUTO_PTR<cmMakefile> globalMF( + new cmMakefile(&cmgg, cminst.GetCurrentSnapshot())); +#if defined(__CYGWIN__) + globalMF->AddDefinition("CMAKE_LEGACY_CYGWIN_WIN32", "0"); +#endif bool cpackConfigFileSpecified = true; - if ( cpackConfigFile.empty() ) - { + if (cpackConfigFile.empty()) { cpackConfigFile = cmSystemTools::GetCurrentWorkingDirectory(); cpackConfigFile += "/CPackConfig.cmake"; cpackConfigFileSpecified = false; - } + } cmCPackGeneratorFactory generators; generators.SetLogger(&log); - cmCPackGenerator* cpackGenerator = 0; + cmCPackGenerator* cpackGenerator = CM_NULLPTR; cmDocumentation doc; doc.addCPackStandardDocSections(); @@ -296,304 +217,219 @@ int main (int argc, char *argv[]) * should launch cpack using "cpackConfigFile" if it exists * in the current directory. */ - if((doc.CheckOptions(argc, argv,"-G")) && !(argc==1)) - { - help = true; - } - else - { - help = false; - } + help = doc.CheckOptions(argc, argv, "-G") && argc != 1; // This part is used for cpack documentation lookup as well. cminst.AddCMakePaths(); - if ( parsed && !help ) - { + if (parsed && !help) { // find out which system cpack is running on, so it can setup the search // paths, so FIND_XXX() commands can be used in scripts std::string systemFile = globalMF->GetModulesFile("CMakeDetermineSystem.cmake"); - if (!globalMF->ReadListFile(0, systemFile.c_str())) - { + if (!globalMF->ReadListFile(systemFile.c_str())) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, - "Error reading CMakeDetermineSystem.cmake" << std::endl); + "Error reading CMakeDetermineSystem.cmake" << std::endl); return 1; - } + } systemFile = globalMF->GetModulesFile("CMakeSystemSpecificInformation.cmake"); - if (!globalMF->ReadListFile(0, systemFile.c_str())) - { + if (!globalMF->ReadListFile(systemFile.c_str())) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, - "Error reading CMakeSystemSpecificInformation.cmake" << std::endl); + "Error reading CMakeSystemSpecificInformation.cmake" + << std::endl); return 1; - } + } - if ( cmSystemTools::FileExists(cpackConfigFile.c_str()) ) - { - cpackConfigFile = - cmSystemTools::CollapseFullPath(cpackConfigFile.c_str()); + if (!cpackBuildConfig.empty()) { + globalMF->AddDefinition("CPACK_BUILD_CONFIG", cpackBuildConfig.c_str()); + } + + if (cmSystemTools::FileExists(cpackConfigFile.c_str())) { + cpackConfigFile = cmSystemTools::CollapseFullPath(cpackConfigFile); cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, - "Read CPack configuration file: " << cpackConfigFile.c_str() - << std::endl); - if ( !globalMF->ReadListFile(0, cpackConfigFile.c_str()) ) - { + "Read CPack configuration file: " << cpackConfigFile + << std::endl); + if (!globalMF->ReadListFile(cpackConfigFile.c_str())) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, - "Problem reading CPack config file: \"" - << cpackConfigFile.c_str() << "\"" << std::endl); + "Problem reading CPack config file: \"" + << cpackConfigFile << "\"" << std::endl); return 1; - } } - else if ( cpackConfigFileSpecified ) - { + } else if (cpackConfigFileSpecified) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, - "Cannot find CPack config file: \"" << cpackConfigFile.c_str() - << "\"" << std::endl); + "Cannot find CPack config file: \"" << cpackConfigFile + << "\"" << std::endl); return 1; - } + } - if ( !generator.empty() ) - { + if (!generator.empty()) { globalMF->AddDefinition("CPACK_GENERATOR", generator.c_str()); - } - if ( !cpackProjectName.empty() ) - { + } + if (!cpackProjectName.empty()) { globalMF->AddDefinition("CPACK_PACKAGE_NAME", cpackProjectName.c_str()); - } - if ( !cpackProjectVersion.empty() ) - { + } + if (!cpackProjectVersion.empty()) { globalMF->AddDefinition("CPACK_PACKAGE_VERSION", - cpackProjectVersion.c_str()); - } - if ( !cpackProjectVendor.empty() ) - { + cpackProjectVersion.c_str()); + } + if (!cpackProjectVendor.empty()) { globalMF->AddDefinition("CPACK_PACKAGE_VENDOR", - cpackProjectVendor.c_str()); - } + cpackProjectVendor.c_str()); + } // if this is not empty it has been set on the command line // go for it. Command line override values set in config file. - if ( !cpackProjectDirectory.empty() ) - { + if (!cpackProjectDirectory.empty()) { globalMF->AddDefinition("CPACK_PACKAGE_DIRECTORY", cpackProjectDirectory.c_str()); - } + } // The value has not been set on the command line - else - { + else { // get a default value (current working directory) cpackProjectDirectory = cmsys::SystemTools::GetCurrentWorkingDirectory(); // use default value iff no value has been provided by the config file - if (!globalMF->IsSet("CPACK_PACKAGE_DIRECTORY")) - { + if (!globalMF->IsSet("CPACK_PACKAGE_DIRECTORY")) { globalMF->AddDefinition("CPACK_PACKAGE_DIRECTORY", cpackProjectDirectory.c_str()); - } - } - if ( !cpackBuildConfig.empty() ) - { - globalMF->AddDefinition("CPACK_BUILD_CONFIG", cpackBuildConfig.c_str()); } + } cpackDefinitions::MapType::iterator cdit; - for ( cdit = definitions.Map.begin(); - cdit != definitions.Map.end(); - ++cdit ) - { - globalMF->AddDefinition(cdit->first.c_str(), cdit->second.c_str()); - } + for (cdit = definitions.Map.begin(); cdit != definitions.Map.end(); + ++cdit) { + globalMF->AddDefinition(cdit->first, cdit->second.c_str()); + } const char* cpackModulesPath = globalMF->GetDefinition("CPACK_MODULE_PATH"); - if ( cpackModulesPath ) - { + if (cpackModulesPath) { globalMF->AddDefinition("CMAKE_MODULE_PATH", cpackModulesPath); - } + } const char* genList = globalMF->GetDefinition("CPACK_GENERATOR"); - if ( !genList ) - { - cmCPack_Log(&log, cmCPackLog::LOG_ERROR, - "CPack generator not specified" << std::endl); - parsed = 0; - } - else - { + if (!genList) { + cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "CPack generator not specified" + << std::endl); + } else { std::vector<std::string> generatorsVector; - cmSystemTools::ExpandListArgument(genList, - generatorsVector); + cmSystemTools::ExpandListArgument(genList, generatorsVector); std::vector<std::string>::iterator it; - for ( it = generatorsVector.begin(); - it != generatorsVector.end(); - ++it ) - { + for (it = generatorsVector.begin(); it != generatorsVector.end(); ++it) { const char* gen = it->c_str(); - cmMakefile newMF(*globalMF); - cmMakefile* mf = &newMF; + cmMakefile::ScopePushPop raii(globalMF.get()); + cmMakefile* mf = globalMF.get(); cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, - "Specified generator: " << gen << std::endl); - if ( parsed && !mf->GetDefinition("CPACK_PACKAGE_NAME") ) - { + "Specified generator: " << gen << std::endl); + if (parsed && !mf->GetDefinition("CPACK_PACKAGE_NAME")) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, - "CPack project name not specified" << std::endl); + "CPack project name not specified" << std::endl); parsed = 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")))) - { + 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); + "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 ) - { + } + if (parsed) { cpackGenerator = generators.NewGenerator(gen); - if ( !cpackGenerator ) - { + if (!cpackGenerator) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, - "Cannot initialize CPack generator: " - << gen << std::endl); + "Cannot initialize CPack generator: " << gen + << std::endl); parsed = 0; - } - if ( parsed && !cpackGenerator->Initialize(gen, mf) ) - { + } + if (parsed && !cpackGenerator->Initialize(gen, mf)) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, - "Cannot initialize the generator " << gen << std::endl); + "Cannot initialize the generator " << gen + << std::endl); parsed = 0; - } + } - if ( !mf->GetDefinition("CPACK_INSTALL_COMMANDS") && - !mf->GetDefinition("CPACK_INSTALLED_DIRECTORIES") && - !mf->GetDefinition("CPACK_INSTALL_CMAKE_PROJECTS") ) - { - cmCPack_Log(&log, cmCPackLog::LOG_ERROR, + 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; - } - if ( parsed ) - { -#ifdef _WIN32 - std::string comspec = "cmw9xcom.exe"; - cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str()); -#endif - + } + if (parsed) { const char* projName = mf->GetDefinition("CPACK_PACKAGE_NAME"); cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "Use generator: " - << cpackGenerator->GetNameOfClass() << std::endl); - cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "For project: " - << projName << std::endl); + << cpackGenerator->GetNameOfClass() << std::endl); + cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, + "For project: " << projName << std::endl); const char* projVersion = mf->GetDefinition("CPACK_PACKAGE_VERSION"); - if ( !projVersion ) - { - const char* projVersionMajor - = mf->GetDefinition("CPACK_PACKAGE_VERSION_MAJOR"); - const char* projVersionMinor - = mf->GetDefinition("CPACK_PACKAGE_VERSION_MINOR"); - const char* projVersionPatch - = mf->GetDefinition("CPACK_PACKAGE_VERSION_PATCH"); - cmOStringStream ostr; + if (!projVersion) { + const char* projVersionMajor = + mf->GetDefinition("CPACK_PACKAGE_VERSION_MAJOR"); + const char* projVersionMinor = + mf->GetDefinition("CPACK_PACKAGE_VERSION_MINOR"); + const char* projVersionPatch = + mf->GetDefinition("CPACK_PACKAGE_VERSION_PATCH"); + std::ostringstream ostr; ostr << projVersionMajor << "." << projVersionMinor << "." - << projVersionPatch; - mf->AddDefinition("CPACK_PACKAGE_VERSION", - ostr.str().c_str()); - } + << projVersionPatch; + mf->AddDefinition("CPACK_PACKAGE_VERSION", ostr.str().c_str()); + } int res = cpackGenerator->DoPackage(); - if ( !res ) - { + if (!res) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, - "Error when generating package: " << projName << std::endl); + "Error when generating package: " << projName + << std::endl); return 1; - } } } } } } + } /* In this case we are building the documentation object * instance in order to create appropriate structure * in order to satisfy the appropriate --help-xxx request */ - if ( help ) - { + if (help) { // Construct and print requested documentation. doc.SetName("cpack"); - doc.SetSection("Name",cmDocumentationName); - doc.SetSection("Usage",cmDocumentationUsage); - doc.SetSection("Description",cmDocumentationDescription); - doc.PrependSection("Options",cmDocumentationOptions); - - // statically (in C++ code) defined variables - cmCPackDocumentVariables::DefineVariables(&cminst); - - std::vector<cmDocumentationEntry> commands; - - std::string docedFile; - std::string docPath; - cmDocumentation::documentedModulesList_t docedModList; - - docedFile = globalMF->GetModulesFile("CPack.cmake"); - if (docedFile.length()!=0) - { - docPath = cmSystemTools::GetFilenamePath(docedFile.c_str()); - doc.getDocumentedModulesListInDir(docPath,"CPack*.cmake",docedModList); - } - - // parse the files for documentation. - cmDocumentation::documentedModulesList_t::iterator docedIt; - for (docedIt = docedModList.begin(); - docedIt!= docedModList.end(); ++docedIt) - { - doc.GetStructuredDocFromFile( - (docedIt->first).c_str(), - commands,&cminst); - } - - std::map<std::string,cmDocumentationSection *> propDocs; - cminst.GetPropertiesDocumentation(propDocs); - doc.SetSections(propDocs); - cminst.GetCommandDocumentation(commands,true,false); - // statically (in C++ code) defined macros/commands - cmCPackDocumentMacros::GetMacrosDocumentation(commands); - doc.SetSection("Commands",commands); + doc.SetSection("Name", cmDocumentationName); + doc.SetSection("Usage", cmDocumentationUsage); + doc.PrependSection("Options", cmDocumentationOptions); std::vector<cmDocumentationEntry> v; cmCPackGeneratorFactory::DescriptionsMap::const_iterator generatorIt; - for( generatorIt = generators.GetGeneratorsList().begin(); - generatorIt != generators.GetGeneratorsList().end(); - ++ 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 = ""; + e.Name = generatorIt->first; + e.Brief = generatorIt->second; v.push_back(e); - } - doc.SetSection("Generators",v); - - doc.SetSeeAlsoList(cmDocumentationSeeAlso); -#undef cout - return doc.PrintRequestedDocumentation(std::cout)? 0:1; -#define cout no_cout_use_cmCPack_Log } + doc.SetSection("Generators", v); - if (cmSystemTools::GetErrorOccuredFlag()) - { + return doc.PrintRequestedDocumentation(std::cout) ? 0 : 1; + } + + if (cmSystemTools::GetErrorOccuredFlag()) { return 1; - } + } return 0; } diff --git a/Source/CPack/cygwin.readme b/Source/CPack/cygwin.readme deleted file mode 100644 index c0cd4b913..000000000 --- a/Source/CPack/cygwin.readme +++ /dev/null @@ -1,69 +0,0 @@ -http://cygwin.com/setup.html - - -Need to produce two tar files: - -Source- - -- create subdirs -- copy src -- duplicate src -- configure files into duplicate src - CPack.cygwin-readme.in - CPack.cygwin-install.sh.in - CPack.setup.hint.in -- diff duplicate src and orig src -- write diff into toplevel -- create tar file call super class - -cmake-2.2.3-1 - - -1. a source release -cmake-2.2.3-2-src.tar.bz2 - -cmake-2.2.3-2.patch has cmake-2.2.3/CYGWIN-PATCHES/cmake.README cmake-2.2.3/CYGWIN-PATCHES/setup.hint -cmake-2.2.3-2.sh -> script to create cygwin release -cmake-2.2.3.tar.bz2 -> unmodified cmake sources for 2.2.3 - - - - - -2 a binary release -cmake-2.2.3-2.tar.bz2 - -normal binary release with use as the root of the tree: - -Here is the bootstrap command used: - - ${SOURCE_DIR}/bootstrap --prefix=/usr --datadir=/share/cmake-${VER} \ - --docdir=/share/doc/cmake-${VER} --mandir=/share/man - -CMAKE_DOC_DIR /share/doc/${PKG}-${VER} -CMAKE_MAN_DIR /share/man -CMAKE_DATA_DIR /share/${PKG}-${VER} - -Here is the directory stucture: - -usr/bin/cmake.exe -usr/share/doc/cmake-2.2.3/MANIFEST *** -usr/share/doc/Cygwin/cmake-2.2.3-2.README **** -usr/share/cmake-2.2.3/Modules - - - -usr/bin -usr/share/cmake-2.2.3/include -usr/share/cmake-2.2.3/Modules/Platform -usr/share/cmake-2.2.3/Modules -usr/share/cmake-2.2.3/Templates -usr/share/cmake-2.2.3 -usr/share/doc/cmake-2.2.3 -usr/share/doc/Cygwin -usr/share/doc -usr/share/man/man1 -usr/share/man -usr/share -usr - |