diff options
author | Brad King <brad.king@kitware.com> | 2016-09-20 12:40:49 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2016-09-20 12:40:49 (GMT) |
commit | 8d83c9d100b8952ec0793e4cb0e30d5b3ec8f164 (patch) | |
tree | 92737bee59500caf34982951f7f47ec4c80313a8 /Source | |
parent | 8b0f246694e5e7a7e71187204ba30ddcc537b32f (diff) | |
parent | b807cd9b54e4a9324ddd64281254b6fe80be5b24 (diff) | |
download | CMake-8d83c9d100b8952ec0793e4cb0e30d5b3ec8f164.zip CMake-8d83c9d100b8952ec0793e4cb0e30d5b3ec8f164.tar.gz CMake-8d83c9d100b8952ec0793e4cb0e30d5b3ec8f164.tar.bz2 |
Merge topic 'ifw-package-resources'
b807cd9b CPackIFW: Add 'cpack_ifw_add_package_resources' command
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CPack/IFW/cmCPackIFWGenerator.cxx | 13 | ||||
-rw-r--r-- | Source/CPack/IFW/cmCPackIFWInstaller.cxx | 84 | ||||
-rw-r--r-- | Source/CPack/IFW/cmCPackIFWInstaller.h | 3 |
3 files changed, 100 insertions, 0 deletions
diff --git a/Source/CPack/IFW/cmCPackIFWGenerator.cxx b/Source/CPack/IFW/cmCPackIFWGenerator.cxx index a6f1585..fa7e0aa 100644 --- a/Source/CPack/IFW/cmCPackIFWGenerator.cxx +++ b/Source/CPack/IFW/cmCPackIFWGenerator.cxx @@ -130,6 +130,19 @@ int cmCPackIFWGenerator::PackageFiles() { std::string ifwCmd = BinCreator; ifwCmd += " -c " + this->toplevel + "/config/config.xml"; + + if (!Installer.Resources.empty()) { + ifwCmd += " -r "; + std::vector<std::string>::iterator it = Installer.Resources.begin(); + std::string path = this->toplevel + "/resources/"; + ifwCmd += path + *it; + ++it; + while (it != Installer.Resources.end()) { + ifwCmd += "," + path + *it; + ++it; + } + } + ifwCmd += " -p " + this->toplevel + "/packages"; if (!PkgsDirsVector.empty()) { diff --git a/Source/CPack/IFW/cmCPackIFWInstaller.cxx b/Source/CPack/IFW/cmCPackIFWInstaller.cxx index 5a3efc9..aa609e2 100644 --- a/Source/CPack/IFW/cmCPackIFWInstaller.cxx +++ b/Source/CPack/IFW/cmCPackIFWInstaller.cxx @@ -13,11 +13,13 @@ #include "cmCPackIFWInstaller.h" #include "CPack/cmCPackGenerator.h" +#include "CPack/cmCPackLog.h" #include "cmCPackIFWGenerator.h" #include "cmCPackIFWPackage.h" #include "cmCPackIFWRepository.h" #include "cmGeneratedFileStream.h" #include "cmSystemTools.h" +#include "cmXMLParser.h" #include "cmXMLWriter.h" #include <cmConfigure.h> @@ -198,8 +200,70 @@ void cmCPackIFWInstaller::ConfigureFromOptions() this->GetOption("CPACK_IFW_PACKAGE_CONTROL_SCRIPT")) { ControlScript = optIFW_CONTROL_SCRIPT; } + + // Resources + if (const char* optIFW_PACKAGE_RESOURCES = + this->GetOption("CPACK_IFW_PACKAGE_RESOURCES")) { + Resources.clear(); + cmSystemTools::ExpandListArgument(optIFW_PACKAGE_RESOURCES, Resources); + } } +/** \class cmCPackIFWResourcesParser + * \brief Helper class that parse resources form .qrc (Qt) + */ +class cmCPackIFWResourcesParser : public cmXMLParser +{ +public: + cmCPackIFWResourcesParser(cmCPackIFWInstaller* i) + : installer(i) + , file(false) + { + path = i->Directory + "/resources"; + } + + bool ParseResource(size_t r) + { + hasFiles = false; + hasErrors = false; + + basePath = cmSystemTools::GetFilenamePath(installer->Resources[r].data()); + + ParseFile(installer->Resources[r].data()); + + return hasFiles && !hasErrors; + } + + cmCPackIFWInstaller* installer; + bool file, hasFiles, hasErrors; + std::string path, basePath; + +protected: + void StartElement(const std::string& name, const char** /*atts*/) CM_OVERRIDE + { + file = name == "file" ? true : false; + if (file) { + hasFiles = true; + } + } + + void CharacterDataHandler(const char* data, int length) CM_OVERRIDE + { + if (file) { + std::string content(data, data + length); + content = cmSystemTools::TrimWhitespace(content); + std::string source = basePath + "/" + content; + std::string destination = path + "/" + content; + if (!cmSystemTools::CopyFileIfDifferent(source.data(), + destination.data())) { + hasErrors = true; + } + } + } + + void EndElement(const std::string& /*name*/) CM_OVERRIDE {} +}; + void cmCPackIFWInstaller::GenerateInstallerFile() { // Lazy directory initialization @@ -315,6 +379,26 @@ void cmCPackIFWInstaller::GenerateInstallerFile() xout.Element("ControlScript", name); } + // Resources (copy to resources dir) + if (!Resources.empty()) { + std::vector<std::string> resources; + cmCPackIFWResourcesParser parser(this); + for (size_t i = 0; i < Resources.size(); i++) { + if (parser.ParseResource(i)) { + std::string name = cmSystemTools::GetFilenameName(Resources[i]); + std::string path = Directory + "/resources/" + name; + cmsys::SystemTools::CopyFileIfDifferent(Resources[i].data(), + path.data()); + resources.push_back(name); + } else { + cmCPackLogger(cmCPackLog::LOG_WARNING, "Can't copy resources from \"" + << Resources[i] << "\". Resource will be skipped." + << std::endl); + } + } + Resources = resources; + } + xout.EndElement(); xout.EndDocument(); } diff --git a/Source/CPack/IFW/cmCPackIFWInstaller.h b/Source/CPack/IFW/cmCPackIFWInstaller.h index f72d379..c9265ec 100644 --- a/Source/CPack/IFW/cmCPackIFWInstaller.h +++ b/Source/CPack/IFW/cmCPackIFWInstaller.h @@ -94,6 +94,9 @@ public: /// 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 |