From dc0f3fb44fb9384438ece513c12d83a36e385802 Mon Sep 17 00:00:00 2001 From: Nils Gladitz Date: Fri, 20 Feb 2015 17:51:55 +0100 Subject: [PATCH 1/6] CPackWIX: Explicitly list CPack WIX headers for IDE convenience. --- Source/CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 69bc2a1b6..0b077d468 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -638,14 +638,24 @@ endif() if(WIN32) set(CPACK_SRCS ${CPACK_SRCS} CPack/WiX/cmCPackWIXGenerator.cxx + CPack/WiX/cmCPackWIXGenerator.h CPack/WiX/cmWIXAccessControlList.cxx + CPack/WiX/cmWIXAccessControlList.h CPack/WiX/cmWIXDirectoriesSourceWriter.cxx + CPack/WiX/cmWIXDirectoriesSourceWriter.h CPack/WiX/cmWIXFeaturesSourceWriter.cxx + CPack/WiX/cmWIXFeaturesSourceWriter.h CPack/WiX/cmWIXFilesSourceWriter.cxx + CPack/WiX/cmWIXFilesSourceWriter.h CPack/WiX/cmWIXPatch.cxx + CPack/WiX/cmWIXPatch.h CPack/WiX/cmWIXPatchParser.cxx + CPack/WiX/cmWIXPatchParser.h CPack/WiX/cmWIXRichTextFormatWriter.cxx + CPack/WiX/cmWIXRichTextFormatWriter.h + CPack/WiX/cmWIXShortcut.h CPack/WiX/cmWIXSourceWriter.cxx + CPack/WiX/cmWIXSourceWriter.h ) endif() From 53d7dafface62d40ea795456394f7ab1d5ee6712 Mon Sep 17 00:00:00 2001 From: Nils Gladitz Date: Sat, 21 Feb 2015 12:38:14 +0100 Subject: [PATCH 2/6] CPackWIX: Refactor start menu and desktop shortcut creation. --- Source/CMakeLists.txt | 1 + Source/CPack/WiX/cmCPackWIXGenerator.cxx | 189 ++++++++++---------- Source/CPack/WiX/cmCPackWIXGenerator.h | 26 ++- Source/CPack/WiX/cmWIXFilesSourceWriter.cxx | 31 +--- Source/CPack/WiX/cmWIXFilesSourceWriter.h | 19 +- Source/CPack/WiX/cmWIXShortcut.cxx | 86 +++++++++ Source/CPack/WiX/cmWIXShortcut.h | 49 ++++- 7 files changed, 250 insertions(+), 151 deletions(-) create mode 100644 Source/CPack/WiX/cmWIXShortcut.cxx diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 0b077d468..5b518b8f0 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -653,6 +653,7 @@ if(WIN32) CPack/WiX/cmWIXPatchParser.h CPack/WiX/cmWIXRichTextFormatWriter.cxx CPack/WiX/cmWIXRichTextFormatWriter.h + CPack/WiX/cmWIXShortcut.cxx CPack/WiX/cmWIXShortcut.h CPack/WiX/cmWIXSourceWriter.cxx CPack/WiX/cmWIXSourceWriter.h diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.cxx b/Source/CPack/WiX/cmCPackWIXGenerator.cxx index 11d5437e7..f18eaeb47 100644 --- a/Source/CPack/WiX/cmCPackWIXGenerator.cxx +++ b/Source/CPack/WiX/cmCPackWIXGenerator.cxx @@ -33,7 +33,6 @@ #include // for GUID generation cmCPackWIXGenerator::cmCPackWIXGenerator(): - HasDesktopShortcuts(false), Patch(0) { @@ -490,18 +489,16 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles() featureDefinitions.EndElement("Feature"); - bool hasShortcuts = false; + std::set emittedShortcutTypes; - shortcut_map_t globalShortcuts; + cmWIXShortcuts globalShortcuts; if(Components.empty()) { AddComponentsToFeature(toplevel, "ProductFeature", directoryDefinitions, fileDefinitions, featureDefinitions, globalShortcuts); - if(globalShortcuts.size()) - { - hasShortcuts = true; - } + + globalShortcuts.AddShortcutTypes(emittedShortcutTypes); } else { @@ -516,33 +513,29 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles() std::string componentFeatureId = "CM_C_" + component.Name; - shortcut_map_t featureShortcuts; + cmWIXShortcuts featureShortcuts; AddComponentsToFeature(componentPath, componentFeatureId, directoryDefinitions, fileDefinitions, featureDefinitions, featureShortcuts); - if(featureShortcuts.size()) - { - hasShortcuts = true; - } - if(featureShortcuts.size()) + featureShortcuts.AddShortcutTypes(emittedShortcutTypes); + + if(!CreateShortcuts(component.Name, componentFeatureId, + featureShortcuts, false, fileDefinitions, featureDefinitions)) { - if(!CreateStartMenuShortcuts(component.Name, componentFeatureId, - featureShortcuts, fileDefinitions, featureDefinitions)) - { - return false; - } + return false; } } } - if(hasShortcuts) + bool emitUninstallShortcut = emittedShortcutTypes.find( + cmWIXShortcuts::START_MENU) != emittedShortcutTypes.end(); + + if(!CreateShortcuts(std::string(), "ProductFeature", + globalShortcuts, emitUninstallShortcut, + fileDefinitions, featureDefinitions)) { - if(!CreateStartMenuShortcuts(std::string(), "ProductFeature", - globalShortcuts, fileDefinitions, featureDefinitions)) - { - return false; - } + return false; } featureDefinitions.EndElement("Fragment"); @@ -551,13 +544,15 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles() directoryDefinitions.EndInstallationPrefixDirectory( installRootSize); - if(hasShortcuts) + if(emittedShortcutTypes.find(cmWIXShortcuts::START_MENU) != + emittedShortcutTypes.end()) { directoryDefinitions.EmitStartMenuFolder( GetOption("CPACK_WIX_PROGRAM_MENU_FOLDER")); } - if(this->HasDesktopShortcuts) + if(emittedShortcutTypes.find(cmWIXShortcuts::DESKTOP) != + emittedShortcutTypes.end()) { directoryDefinitions.EmitDesktopFolder(); } @@ -649,7 +644,7 @@ bool cmCPackWIXGenerator::AddComponentsToFeature( cmWIXDirectoriesSourceWriter& directoryDefinitions, cmWIXFilesSourceWriter& fileDefinitions, cmWIXFeaturesSourceWriter& featureDefinitions, - shortcut_map_t& shortcutMap) + cmWIXShortcuts& shortcuts) { featureDefinitions.BeginElement("FeatureRef"); featureDefinitions.AddAttribute("Id", featureId); @@ -682,21 +677,68 @@ bool cmCPackWIXGenerator::AddComponentsToFeature( rootPath, "INSTALL_ROOT", directoryDefinitions, fileDefinitions, featureDefinitions, cpackPackageExecutablesList, cpackPackageDesktopLinksList, - shortcutMap); + shortcuts); featureDefinitions.EndElement("FeatureRef"); return true; } -bool cmCPackWIXGenerator::CreateStartMenuShortcuts( +bool cmCPackWIXGenerator::CreateShortcuts( std::string const& cpackComponentName, std::string const& featureId, - shortcut_map_t& shortcutMap, + cmWIXShortcuts const& shortcuts, + bool emitUninstallShortcut, cmWIXFilesSourceWriter& fileDefinitions, cmWIXFeaturesSourceWriter& featureDefinitions) { - bool thisHasDesktopShortcuts = false; + 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; + } + } + + 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; + default: + return false; + } featureDefinitions.BeginElement("FeatureRef"); featureDefinitions.AddAttribute("Id", featureId); @@ -720,80 +762,42 @@ bool cmCPackWIXGenerator::CreateStartMenuShortcuts( idSuffix += cpackComponentName; } - std::string componentId = "CM_SHORTCUT" + idSuffix; + std::string componentId = "CM_SHORTCUT"; + if(idPrefix.size()) + { + componentId += "_" + idPrefix; + } + + componentId += idSuffix; fileDefinitions.BeginElement("DirectoryRef"); - fileDefinitions.AddAttribute("Id", "PROGRAM_MENU_FOLDER"); + fileDefinitions.AddAttribute("Id", directoryId); fileDefinitions.BeginElement("Component"); fileDefinitions.AddAttribute("Id", componentId); fileDefinitions.AddAttribute("Guid", "*"); - for(shortcut_map_t::const_iterator - i = shortcutMap.begin(); i != shortcutMap.end(); ++i) + std::string registryKey = std::string("Software\\") + + cpackVendor + "\\" + cpackPackageName; + + shortcuts.EmitShortcuts(type, registryKey, + cpackComponentName, fileDefinitions); + + if(type == cmWIXShortcuts::START_MENU) { - std::string const& id = i->first; - cmWIXShortcut const& shortcut = i->second; - - fileDefinitions.EmitShortcut(id, shortcut, false); - - if(shortcut.desktop) - { - thisHasDesktopShortcuts = true; - } + fileDefinitions.EmitRemoveFolder( + "CM_REMOVE_PROGRAM_MENU_FOLDER" + idSuffix); } - if(cpackComponentName.empty()) + if(emitUninstallShortcut) { fileDefinitions.EmitUninstallShortcut(cpackPackageName); } - fileDefinitions.EmitRemoveFolder( - "CM_REMOVE_PROGRAM_MENU_FOLDER" + idSuffix); - - std::string registryKey = - std::string("Software\\") + cpackVendor + "\\" + cpackPackageName; - - fileDefinitions.EmitStartMenuShortcutRegistryValue( - registryKey, cpackComponentName); - fileDefinitions.EndElement("Component"); fileDefinitions.EndElement("DirectoryRef"); featureDefinitions.EmitComponentRef(componentId); - - if(thisHasDesktopShortcuts) - { - this->HasDesktopShortcuts = true; - componentId = "CM_DESKTOP_SHORTCUT" + idSuffix; - - fileDefinitions.BeginElement("DirectoryRef"); - fileDefinitions.AddAttribute("Id", "DesktopFolder"); - fileDefinitions.BeginElement("Component"); - fileDefinitions.AddAttribute("Id", componentId); - fileDefinitions.AddAttribute("Guid", "*"); - - for(shortcut_map_t::const_iterator - i = shortcutMap.begin(); i != shortcutMap.end(); ++i) - { - std::string const& id = i->first; - cmWIXShortcut const& shortcut = i->second; - - if (!shortcut.desktop) - continue; - - fileDefinitions.EmitShortcut(id, shortcut, true); - } - - fileDefinitions.EmitDesktopShortcutRegistryValue( - registryKey, cpackComponentName); - - fileDefinitions.EndElement("Component"); - fileDefinitions.EndElement("DirectoryRef"); - - featureDefinitions.EmitComponentRef(componentId); - } - featureDefinitions.EndElement("FeatureRef"); return true; @@ -854,7 +858,7 @@ void cmCPackWIXGenerator::AddDirectoryAndFileDefinitons( cmWIXFeaturesSourceWriter& featureDefinitions, const std::vector& packageExecutables, const std::vector& desktopExecutables, - shortcut_map_t& shortcutMap) + cmWIXShortcuts& shortcuts) { cmsys::Directory dir; dir.Load(topdir.c_str()); @@ -929,7 +933,7 @@ void cmCPackWIXGenerator::AddDirectoryAndFileDefinitons( featureDefinitions, packageExecutables, desktopExecutables, - shortcutMap); + shortcuts); this->Patch->ApplyFragment(subDirectoryId, directoryDefinitions); directoryDefinitions.EndElement("Directory"); @@ -952,9 +956,10 @@ void cmCPackWIXGenerator::AddDirectoryAndFileDefinitons( if(cmSystemTools::LowerCase(fileName) == cmSystemTools::LowerCase(executableName) + ".exe") { - cmWIXShortcut &shortcut = shortcutMap[id]; - shortcut.textLabel= textLabel; + cmWIXShortcut shortcut; + shortcut.label= textLabel; shortcut.workingDirectoryId = directoryId; + shortcuts.insert(cmWIXShortcuts::START_MENU, id, shortcut); if(desktopExecutables.size() && std::find(desktopExecutables.begin(), @@ -962,7 +967,7 @@ void cmCPackWIXGenerator::AddDirectoryAndFileDefinitons( executableName) != desktopExecutables.end()) { - shortcut.desktop = true; + shortcuts.insert(cmWIXShortcuts::DESKTOP, id, shortcut); } } } diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.h b/Source/CPack/WiX/cmCPackWIXGenerator.h index 703529703..d75c69d8d 100644 --- a/Source/CPack/WiX/cmCPackWIXGenerator.h +++ b/Source/CPack/WiX/cmCPackWIXGenerator.h @@ -65,7 +65,6 @@ protected: private: typedef std::map id_map_t; typedef std::map ambiguity_map_t; - typedef std::map shortcut_map_t; typedef std::set extension_set_t; bool InitializeWiXConfiguration(); @@ -99,12 +98,23 @@ private: cmWIXDirectoriesSourceWriter& directoryDefinitions, cmWIXFilesSourceWriter& fileDefinitions, cmWIXFeaturesSourceWriter& featureDefinitions, - shortcut_map_t& shortcutMap); + cmWIXShortcuts& shortcuts); - bool CreateStartMenuShortcuts( + bool CreateShortcuts( std::string const& cpackComponentName, std::string const& featureId, - shortcut_map_t& shortcutMap, + cmWIXShortcuts const& shortcuts, + bool emitUninstallShortcut, + cmWIXFilesSourceWriter& fileDefinitions, + cmWIXFeaturesSourceWriter& featureDefinitions); + + 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); @@ -126,9 +136,9 @@ private: cmWIXDirectoriesSourceWriter& directoryDefinitions, cmWIXFilesSourceWriter& fileDefinitions, cmWIXFeaturesSourceWriter& featureDefinitions, - const std::vector& pkgExecutables, - const std::vector& desktopExecutables, - shortcut_map_t& shortcutMap); + std::vector const& pkgExecutables, + std::vector const& desktopExecutables, + cmWIXShortcuts& shortcuts); bool RequireOption(std::string const& name, std::string& value) const; @@ -165,8 +175,6 @@ private: extension_set_t CandleExtensions; extension_set_t LightExtensions; - bool HasDesktopShortcuts; - std::string CPackTopLevel; cmWIXPatch* Patch; diff --git a/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx b/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx index 1adb06ade..ca3769974 100644 --- a/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx +++ b/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx @@ -1,6 +1,6 @@ /*============================================================================ CMake - Cross Platform Makefile Generator - Copyright 2014 Kitware, Inc. + Copyright 2014-2015 Kitware, Inc. Distributed under the OSI-approved BSD License (the "License"); see accompanying file Copyright.txt for details. @@ -28,18 +28,9 @@ cmWIXFilesSourceWriter::cmWIXFilesSourceWriter(cmCPackLog* logger, void cmWIXFilesSourceWriter::EmitShortcut( std::string const& id, cmWIXShortcut const& shortcut, - bool desktop) + std::string const& shortcutPrefix) { - std::string shortcutId; - - if(desktop) - { - shortcutId = "CM_DS"; - } - else - { - shortcutId = "CM_S"; - } + std::string shortcutId = shortcutPrefix; shortcutId += id; @@ -47,7 +38,7 @@ void cmWIXFilesSourceWriter::EmitShortcut( BeginElement("Shortcut"); AddAttribute("Id", shortcutId); - AddAttribute("Name", shortcut.textLabel); + AddAttribute("Name", shortcut.label); std::string target = "[#" + fileId + "]"; AddAttribute("Target", target); AddAttribute("WorkingDirectory", shortcut.workingDirectoryId); @@ -62,20 +53,6 @@ void cmWIXFilesSourceWriter::EmitRemoveFolder(std::string const& id) EndElement("RemoveFolder"); } -void cmWIXFilesSourceWriter::EmitStartMenuShortcutRegistryValue( - std::string const& registryKey, - std::string const& cpackComponentName) -{ - EmitInstallRegistryValue(registryKey, cpackComponentName, std::string()); -} - -void cmWIXFilesSourceWriter::EmitDesktopShortcutRegistryValue( - std::string const& registryKey, - std::string const& cpackComponentName) -{ - EmitInstallRegistryValue(registryKey, cpackComponentName, "_desktop"); -} - void cmWIXFilesSourceWriter::EmitInstallRegistryValue( std::string const& registryKey, std::string const& cpackComponentName, diff --git a/Source/CPack/WiX/cmWIXFilesSourceWriter.h b/Source/CPack/WiX/cmWIXFilesSourceWriter.h index b0a4af8f8..67808fb0c 100644 --- a/Source/CPack/WiX/cmWIXFilesSourceWriter.h +++ b/Source/CPack/WiX/cmWIXFilesSourceWriter.h @@ -1,6 +1,6 @@ /*============================================================================ CMake - Cross Platform Makefile Generator - Copyright 2014 Kitware, Inc. + Copyright 2014-2015 Kitware, Inc. Distributed under the OSI-approved BSD License (the "License"); see accompanying file Copyright.txt for details. @@ -31,17 +31,14 @@ public: void EmitShortcut( std::string const& id, cmWIXShortcut const& shortcut, - bool desktop); + std::string const& shortcutPrefix); void EmitRemoveFolder(std::string const& id); - void EmitStartMenuShortcutRegistryValue( + void EmitInstallRegistryValue( std::string const& registryKey, - std::string const& cpackComponentName); - - void EmitDesktopShortcutRegistryValue( - std::string const& registryKey, - std::string const& cpackComponentName); + std::string const& cpackComponentName, + std::string const& suffix); void EmitUninstallShortcut(std::string const& packageName); @@ -56,12 +53,6 @@ public: std::string const& filePath, cmWIXPatch &patch, cmInstalledFile const* installedFile); - -private: - void EmitInstallRegistryValue( - std::string const& registryKey, - std::string const& cpackComponentName, - std::string const& suffix); }; diff --git a/Source/CPack/WiX/cmWIXShortcut.cxx b/Source/CPack/WiX/cmWIXShortcut.cxx new file mode 100644 index 000000000..1c755ece0 --- /dev/null +++ b/Source/CPack/WiX/cmWIXShortcut.cxx @@ -0,0 +1,86 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2015 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. +============================================================================*/ + +#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; + 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(shortcut_list_t::const_iterator k = shortcutList.begin(); + k != shortcutList.end(); ++k) + { + cmWIXShortcut const& shortcut = *k; + fileDefinitions.EmitShortcut(id, shortcut, shortcutPrefix); + } + } + + fileDefinitions.EmitInstallRegistryValue( + registryKey, cpackComponentName, registrySuffix); + + return true; +} + +void cmWIXShortcuts::AddShortcutTypes(std::set& types) +{ + for(shortcut_type_map_t::const_iterator i = this->Shortcuts.begin(); + i != this->Shortcuts.end(); ++i) + { + types.insert(i->first); + } +} diff --git a/Source/CPack/WiX/cmWIXShortcut.h b/Source/CPack/WiX/cmWIXShortcut.h index 93095e03f..a18cbb34c 100644 --- a/Source/CPack/WiX/cmWIXShortcut.h +++ b/Source/CPack/WiX/cmWIXShortcut.h @@ -1,6 +1,6 @@ /*============================================================================ CMake - Cross Platform Makefile Generator - Copyright 2014 Kitware, Inc. + Copyright 2014-2015 Kitware, Inc. Distributed under the OSI-approved BSD License (the "License"); see accompanying file Copyright.txt for details. @@ -10,20 +10,51 @@ See the License for more information. ============================================================================*/ -#ifndef cmWIXFilesShortcut_h -#define cmWIXFilesShortcut_h +#ifndef cmWIXShortcut_h +#define cmWIXShortcut_h #include +#include +#include +#include + +class cmWIXFilesSourceWriter; struct cmWIXShortcut { - cmWIXShortcut() - :desktop(false) - {} - - std::string textLabel; + std::string label; std::string workingDirectoryId; - bool desktop; +}; + +class cmWIXShortcuts +{ +public: + enum Type + { + START_MENU, + DESKTOP + }; + + typedef std::vector shortcut_list_t; + typedef std::map 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& types); + +private: + typedef std::map shortcut_type_map_t; + + shortcut_type_map_t Shortcuts; + shortcut_id_map_t EmptyIdMap; }; #endif From 279605f560312aab4dfeef4cce1c8c67d4083b4e Mon Sep 17 00:00:00 2001 From: Nils Gladitz Date: Sat, 21 Feb 2015 17:30:31 +0100 Subject: [PATCH 3/6] CPackWIX: Add installed file properties for the creation of shortcuts. --- Help/manual/cmake-properties.7.rst | 2 + Help/prop_inst/CPACK_DESKTOP_SHORTCUTS.rst | 7 ++++ Help/prop_inst/CPACK_START_MENU_SHORTCUTS.rst | 7 ++++ Source/CPack/WiX/cmCPackWIXGenerator.cxx | 9 ++++- Source/CPack/WiX/cmCPackWIXGenerator.h | 2 +- Source/CPack/WiX/cmWIXFilesSourceWriter.cxx | 13 ++++-- Source/CPack/WiX/cmWIXFilesSourceWriter.h | 3 +- Source/CPack/WiX/cmWIXShortcut.cxx | 40 +++++++++++++++++-- Source/CPack/WiX/cmWIXShortcut.h | 12 ++++++ 9 files changed, 83 insertions(+), 12 deletions(-) create mode 100644 Help/prop_inst/CPACK_DESKTOP_SHORTCUTS.rst create mode 100644 Help/prop_inst/CPACK_START_MENU_SHORTCUTS.rst diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index 25f989f18..e3be39963 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/Help/manual/cmake-properties.7.rst @@ -320,8 +320,10 @@ Properties on Installed Files .. toctree:: :maxdepth: 1 + /prop_inst/CPACK_DESKTOP_SHORTCUTS.rst /prop_inst/CPACK_NEVER_OVERWRITE.rst /prop_inst/CPACK_PERMANENT.rst + /prop_inst/CPACK_START_MENU_SHORTCUTS.rst /prop_inst/CPACK_WIX_ACL.rst diff --git a/Help/prop_inst/CPACK_DESKTOP_SHORTCUTS.rst b/Help/prop_inst/CPACK_DESKTOP_SHORTCUTS.rst new file mode 100644 index 000000000..11f2c036c --- /dev/null +++ b/Help/prop_inst/CPACK_DESKTOP_SHORTCUTS.rst @@ -0,0 +1,7 @@ +CPACK_DESKTOP_SHORTCUTS +----------------------- + +Species a list of shortcut names that should be created on the Desktop +for this file. + +The property is currently only supported by the WIX generator. diff --git a/Help/prop_inst/CPACK_START_MENU_SHORTCUTS.rst b/Help/prop_inst/CPACK_START_MENU_SHORTCUTS.rst new file mode 100644 index 000000000..d30ea39fd --- /dev/null +++ b/Help/prop_inst/CPACK_START_MENU_SHORTCUTS.rst @@ -0,0 +1,7 @@ +CPACK_START_MENU_SHORTCUTS +-------------------------- + +Species a list of shortcut names that should be created in the Start Menu +for this file. + +The property is currently only supported by the WIX generator. diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.cxx b/Source/CPack/WiX/cmCPackWIXGenerator.cxx index f18eaeb47..c6daeda6c 100644 --- a/Source/CPack/WiX/cmCPackWIXGenerator.cxx +++ b/Source/CPack/WiX/cmCPackWIXGenerator.cxx @@ -856,8 +856,8 @@ void cmCPackWIXGenerator::AddDirectoryAndFileDefinitons( cmWIXDirectoriesSourceWriter& directoryDefinitions, cmWIXFilesSourceWriter& fileDefinitions, cmWIXFeaturesSourceWriter& featureDefinitions, - const std::vector& packageExecutables, - const std::vector& desktopExecutables, + std::vector const& packageExecutables, + std::vector const& desktopExecutables, cmWIXShortcuts& shortcuts) { cmsys::Directory dir; @@ -943,6 +943,11 @@ void cmCPackWIXGenerator::AddDirectoryAndFileDefinitons( cmInstalledFile const* installedFile = this->GetInstalledFile(relativePath); + if(installedFile) + { + shortcuts.CreateFromProperties(id, directoryId, *installedFile); + } + std::string componentId = fileDefinitions.EmitComponentFile( directoryId, id, fullPath, *(this->Patch), installedFile); diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.h b/Source/CPack/WiX/cmCPackWIXGenerator.h index d75c69d8d..d50160953 100644 --- a/Source/CPack/WiX/cmCPackWIXGenerator.h +++ b/Source/CPack/WiX/cmCPackWIXGenerator.h @@ -136,7 +136,7 @@ private: cmWIXDirectoriesSourceWriter& directoryDefinitions, cmWIXFilesSourceWriter& fileDefinitions, cmWIXFeaturesSourceWriter& featureDefinitions, - std::vector const& pkgExecutables, + std::vector const& packageExecutables, std::vector const& desktopExecutables, cmWIXShortcuts& shortcuts); diff --git a/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx b/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx index ca3769974..d4698a764 100644 --- a/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx +++ b/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx @@ -28,16 +28,21 @@ cmWIXFilesSourceWriter::cmWIXFilesSourceWriter(cmCPackLog* logger, void cmWIXFilesSourceWriter::EmitShortcut( std::string const& id, cmWIXShortcut const& shortcut, - std::string const& shortcutPrefix) + std::string const& shortcutPrefix, + size_t shortcutIndex) { - std::string shortcutId = shortcutPrefix; + std::stringstream shortcutId; + shortcutId << shortcutPrefix << id; - shortcutId += id; + if(shortcutIndex > 0) + { + shortcutId << "_" << shortcutIndex; + } std::string fileId = std::string("CM_F") + id; BeginElement("Shortcut"); - AddAttribute("Id", shortcutId); + AddAttribute("Id", shortcutId.str()); AddAttribute("Name", shortcut.label); std::string target = "[#" + fileId + "]"; AddAttribute("Target", target); diff --git a/Source/CPack/WiX/cmWIXFilesSourceWriter.h b/Source/CPack/WiX/cmWIXFilesSourceWriter.h index 67808fb0c..c48bc15ba 100644 --- a/Source/CPack/WiX/cmWIXFilesSourceWriter.h +++ b/Source/CPack/WiX/cmWIXFilesSourceWriter.h @@ -31,7 +31,8 @@ public: void EmitShortcut( std::string const& id, cmWIXShortcut const& shortcut, - std::string const& shortcutPrefix); + std::string const& shortcutPrefix, + size_t shortcutIndex); void EmitRemoveFolder(std::string const& id); diff --git a/Source/CPack/WiX/cmWIXShortcut.cxx b/Source/CPack/WiX/cmWIXShortcut.cxx index 1c755ece0..aef2b0826 100644 --- a/Source/CPack/WiX/cmWIXShortcut.cxx +++ b/Source/CPack/WiX/cmWIXShortcut.cxx @@ -62,11 +62,12 @@ bool cmWIXShortcuts::EmitShortcuts( std::string const& id = j->first; shortcut_list_t const& shortcutList = j->second; - for(shortcut_list_t::const_iterator k = shortcutList.begin(); - k != shortcutList.end(); ++k) + for(size_t shortcutListIndex = 0; + shortcutListIndex < shortcutList.size(); ++shortcutListIndex) { - cmWIXShortcut const& shortcut = *k; - fileDefinitions.EmitShortcut(id, shortcut, shortcutPrefix); + cmWIXShortcut const& shortcut = shortcutList[shortcutListIndex]; + fileDefinitions.EmitShortcut(id, shortcut, + shortcutPrefix, shortcutListIndex); } } @@ -84,3 +85,34 @@ void cmWIXShortcuts::AddShortcutTypes(std::set& types) 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); +} + +void cmWIXShortcuts::CreateFromProperty( + std::string const& propertyName, + Type type, + std::string const& id, + std::string const& directoryId, + cmInstalledFile const& installedFile) +{ + std::vector 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 index a18cbb34c..5e18bdd3a 100644 --- a/Source/CPack/WiX/cmWIXShortcut.h +++ b/Source/CPack/WiX/cmWIXShortcut.h @@ -18,6 +18,8 @@ #include #include +#include + class cmWIXFilesSourceWriter; struct cmWIXShortcut @@ -50,9 +52,19 @@ public: void AddShortcutTypes(std::set& types); + void CreateFromProperties(std::string const& id, + std::string const& directoryId, cmInstalledFile const& installedFile); + private: typedef std::map 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; }; From e6731f486e466ddd58550851fb935dbda7939cac Mon Sep 17 00:00:00 2001 From: Nils Gladitz Date: Sat, 21 Feb 2015 18:07:36 +0100 Subject: [PATCH 4/6] CPackWIX: Add new CPACK_STARTUP_SHORTCUTS property. --- Help/manual/cmake-properties.7.rst | 1 + Help/prop_inst/CPACK_STARTUP_SHORTCUTS.rst | 7 +++++++ Source/CPack/WiX/cmCPackWIXGenerator.cxx | 20 +++++++++++++++++++ .../WiX/cmWIXDirectoriesSourceWriter.cxx | 8 ++++++++ .../CPack/WiX/cmWIXDirectoriesSourceWriter.h | 2 ++ Source/CPack/WiX/cmWIXShortcut.cxx | 7 +++++++ Source/CPack/WiX/cmWIXShortcut.h | 3 ++- 7 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 Help/prop_inst/CPACK_STARTUP_SHORTCUTS.rst diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index e3be39963..19fdf23f3 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/Help/manual/cmake-properties.7.rst @@ -324,6 +324,7 @@ Properties on Installed Files /prop_inst/CPACK_NEVER_OVERWRITE.rst /prop_inst/CPACK_PERMANENT.rst /prop_inst/CPACK_START_MENU_SHORTCUTS.rst + /prop_inst/CPACK_STARTUP_SHORTCUTS.rst /prop_inst/CPACK_WIX_ACL.rst diff --git a/Help/prop_inst/CPACK_STARTUP_SHORTCUTS.rst b/Help/prop_inst/CPACK_STARTUP_SHORTCUTS.rst new file mode 100644 index 000000000..8a160223d --- /dev/null +++ b/Help/prop_inst/CPACK_STARTUP_SHORTCUTS.rst @@ -0,0 +1,7 @@ +CPACK_STARTUP_SHORTCUTS +----------------------- + +Species a list of shortcut names that should be created in the Startup folder +for this file. + +The property is currently only supported by the WIX generator. diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.cxx b/Source/CPack/WiX/cmCPackWIXGenerator.cxx index c6daeda6c..4b8daf827 100644 --- a/Source/CPack/WiX/cmCPackWIXGenerator.cxx +++ b/Source/CPack/WiX/cmCPackWIXGenerator.cxx @@ -557,6 +557,12 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles() directoryDefinitions.EmitDesktopFolder(); } + if(emittedShortcutTypes.find(cmWIXShortcuts::STARTUP) != + emittedShortcutTypes.end()) + { + directoryDefinitions.EmitStartupFolder(); + } + directoryDefinitions.EndElement("Directory"); directoryDefinitions.EndElement("Fragment"); @@ -714,6 +720,17 @@ bool cmCPackWIXGenerator::CreateShortcuts( } } + if(!shortcuts.empty(cmWIXShortcuts::STARTUP)) + { + if(!this->CreateShortcutsOfSpecificType(cmWIXShortcuts::STARTUP, + cpackComponentName, featureId, "STARTUP", + shortcuts, false, + fileDefinitions, featureDefinitions)) + { + return false; + } + } + return true; } @@ -736,6 +753,9 @@ bool cmCPackWIXGenerator::CreateShortcutsOfSpecificType( case cmWIXShortcuts::DESKTOP: directoryId = "DesktopFolder"; break; + case cmWIXShortcuts::STARTUP: + directoryId = "StartupFolder"; + break; default: return false; } diff --git a/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx index a93f89bae..7bd4315e5 100644 --- a/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx +++ b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx @@ -41,6 +41,14 @@ void cmWIXDirectoriesSourceWriter::EmitDesktopFolder() 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) diff --git a/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.h b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.h index f51fdb4bb..f8c816640 100644 --- a/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.h +++ b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.h @@ -32,6 +32,8 @@ public: void EmitDesktopFolder(); + void EmitStartupFolder(); + size_t BeginInstallationPrefixDirectory( std::string const& programFilesFolderId, std::string const& installRootString); diff --git a/Source/CPack/WiX/cmWIXShortcut.cxx b/Source/CPack/WiX/cmWIXShortcut.cxx index aef2b0826..d72187284 100644 --- a/Source/CPack/WiX/cmWIXShortcut.cxx +++ b/Source/CPack/WiX/cmWIXShortcut.cxx @@ -52,6 +52,10 @@ bool cmWIXShortcuts::EmitShortcuts( shortcutPrefix = "CM_DS"; registrySuffix = "_desktop"; break; + case STARTUP: + shortcutPrefix = "CM_SS"; + registrySuffix = "_startup"; + break; default: return false; } @@ -96,6 +100,9 @@ void cmWIXShortcuts::CreateFromProperties( CreateFromProperty("CPACK_DESKTOP_SHORTCUTS", DESKTOP, id, directoryId, installedFile); + + CreateFromProperty("CPACK_STARTUP_SHORTCUTS", + STARTUP, id, directoryId, installedFile); } void cmWIXShortcuts::CreateFromProperty( diff --git a/Source/CPack/WiX/cmWIXShortcut.h b/Source/CPack/WiX/cmWIXShortcut.h index 5e18bdd3a..5945e4367 100644 --- a/Source/CPack/WiX/cmWIXShortcut.h +++ b/Source/CPack/WiX/cmWIXShortcut.h @@ -34,7 +34,8 @@ public: enum Type { START_MENU, - DESKTOP + DESKTOP, + STARTUP }; typedef std::vector shortcut_list_t; From 135febf069e7ff5305a3729b81171933ec89dc90 Mon Sep 17 00:00:00 2001 From: Nils Gladitz Date: Sun, 22 Feb 2015 15:20:33 +0100 Subject: [PATCH 5/6] CPackWIX: Enhance CMake CPack WIX generated installer. --- CMakeCPackOptions.cmake.in | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/CMakeCPackOptions.cmake.in b/CMakeCPackOptions.cmake.in index 57ed4cafd..cc8f5e986 100644 --- a/CMakeCPackOptions.cmake.in +++ b/CMakeCPackOptions.cmake.in @@ -87,4 +87,26 @@ if("${CPACK_GENERATOR}" STREQUAL "WIX") if(patch MATCHES "^[0-9]+$" AND patch LESS 65535) set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}.${patch}") endif() + + set(CPACK_WIX_PROPERTY_ARPURLINFOABOUT "http://www.cmake.org") + + set(CPACK_WIX_PROPERTY_ARPCONTACT "@CPACK_PACKAGE_CONTACT@") + + set(CPACK_WIX_PROPERTY_ARPCOMMENTS + "CMake is a cross-platform, open-source build system." + ) + + set(CPACK_WIX_PRODUCT_ICON + "@CMake_SOURCE_DIR@/Utilities/Release/CMakeLogo.ico" + ) + + set_property(INSTALL "@CMAKE_DOC_DIR@/html/index.html" PROPERTY + CPACK_START_MENU_SHORTCUTS "CMake Documentation" + ) + + set_property(INSTALL "cmake.org.html" PROPERTY + CPACK_START_MENU_SHORTCUTS "CMake Web Site" + ) + + set(CPACK_WIX_LIGHT_EXTRA_FLAGS "-dcl:high") endif() From 6cc01c140245749bb6a6d5096b4a38f3f16fb776 Mon Sep 17 00:00:00 2001 From: Nils Gladitz Date: Mon, 23 Feb 2015 16:49:42 +0100 Subject: [PATCH 6/6] CPackWIX: Add release notes for the wix-shortcut-properties topic. --- Help/release/dev/wix-shortcut-properties.rst | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Help/release/dev/wix-shortcut-properties.rst diff --git a/Help/release/dev/wix-shortcut-properties.rst b/Help/release/dev/wix-shortcut-properties.rst new file mode 100644 index 000000000..bdd648565 --- /dev/null +++ b/Help/release/dev/wix-shortcut-properties.rst @@ -0,0 +1,9 @@ +wix-shortcut-properties +----------------------- + +* The CPack WIX generator learned the new + :prop_inst:`CPACK_START_MENU_SHORTCUTS`, + :prop_inst:`CPACK_DESKTOP_SHORTCUTS` and + :prop_inst:`CPACK_STARTUP_SHORTCUTS` installed file properties which can + be used to install shorcuts in the Start Menu, on the Desktop and + in the Startup Folder respectively.