CPackWiX: Add support for CPACK_CREATE_DESKTOP_LINKS

This commit is contained in:
Timo Rothenpieler 2014-02-04 18:40:45 +01:00 committed by Nils Gladitz
parent d582809497
commit b78d74de64
4 changed files with 121 additions and 3 deletions

View File

@ -174,7 +174,7 @@
# create Start Menu shortcuts. For example, setting this to the list # create Start Menu shortcuts. For example, setting this to the list
# ccmake;CMake will create a shortcut named "CMake" that will execute the # ccmake;CMake will create a shortcut named "CMake" that will execute the
# installed executable ccmake. Not all CPack generators use it (at least # installed executable ccmake. Not all CPack generators use it (at least
# NSIS and OSXX11 do). # NSIS, WIX and OSXX11 do).
# #
# .. variable:: CPACK_STRIP_FILES # .. variable:: CPACK_STRIP_FILES
# #
@ -261,6 +261,8 @@
# .. variable:: CPACK_CREATE_DESKTOP_LINKS # .. variable:: CPACK_CREATE_DESKTOP_LINKS
# #
# List of desktop links to create. # List of desktop links to create.
# Each desktop link requires a corresponding start menu shortcut
# as created by :variable:`CPACK_PACKAGE_EXECUTABLES`.
#============================================================================= #=============================================================================
# Copyright 2006-2009 Kitware, Inc. # Copyright 2006-2009 Kitware, Inc.

View File

@ -31,6 +31,12 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
cmCPackWIXGenerator::cmCPackWIXGenerator():
HasDesktopShortcuts(false)
{
}
int cmCPackWIXGenerator::InitializeInternal() int cmCPackWIXGenerator::InitializeInternal()
{ {
componentPackageMethod = ONE_PACKAGE; componentPackageMethod = ONE_PACKAGE;
@ -519,6 +525,11 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles()
CreateStartMenuFolder(directoryDefinitions); CreateStartMenuFolder(directoryDefinitions);
} }
if(this->HasDesktopShortcuts)
{
CreateDesktopFolder(directoryDefinitions);
}
directoryDefinitions.EndElement("Directory"); directoryDefinitions.EndElement("Directory");
directoryDefinitions.EndElement("Fragment"); directoryDefinitions.EndElement("Fragment");
@ -733,10 +744,20 @@ bool cmCPackWIXGenerator::AddComponentsToFeature(
} }
} }
std::vector<std::string> cpackPackageDesktopLinksList;
const char *cpackPackageDesktopLinks =
GetOption("CPACK_CREATE_DESKTOP_LINKS");
if(cpackPackageDesktopLinks)
{
cmSystemTools::ExpandListArgument(cpackPackageDesktopLinks,
cpackPackageDesktopLinksList);
}
AddDirectoryAndFileDefinitons( AddDirectoryAndFileDefinitons(
rootPath, "INSTALL_ROOT", rootPath, "INSTALL_ROOT",
directoryDefinitions, fileDefinitions, featureDefinitions, directoryDefinitions, fileDefinitions, featureDefinitions,
cpackPackageExecutablesList, shortcutMap); cpackPackageExecutablesList, cpackPackageDesktopLinksList,
shortcutMap);
featureDefinitions.EndElement("FeatureRef"); featureDefinitions.EndElement("FeatureRef");
@ -750,6 +771,8 @@ bool cmCPackWIXGenerator::CreateStartMenuShortcuts(
cmWIXSourceWriter& fileDefinitions, cmWIXSourceWriter& fileDefinitions,
cmWIXSourceWriter& featureDefinitions) cmWIXSourceWriter& featureDefinitions)
{ {
bool thisHasDesktopShortcuts = false;
featureDefinitions.BeginElement("FeatureRef"); featureDefinitions.BeginElement("FeatureRef");
featureDefinitions.AddAttribute("Id", featureId); featureDefinitions.AddAttribute("Id", featureId);
@ -797,6 +820,11 @@ bool cmCPackWIXGenerator::CreateStartMenuShortcuts(
fileDefinitions.AddAttribute("WorkingDirectory", fileDefinitions.AddAttribute("WorkingDirectory",
shortcut.workingDirectoryId); shortcut.workingDirectoryId);
fileDefinitions.EndElement("Shortcut"); fileDefinitions.EndElement("Shortcut");
if (shortcut.desktop)
{
thisHasDesktopShortcuts = true;
}
} }
if(cpackComponentName.empty()) if(cpackComponentName.empty())
@ -805,7 +833,8 @@ bool cmCPackWIXGenerator::CreateStartMenuShortcuts(
} }
fileDefinitions.BeginElement("RemoveFolder"); fileDefinitions.BeginElement("RemoveFolder");
fileDefinitions.AddAttribute("Id", "PROGRAM_MENU_FOLDER" + idSuffix); fileDefinitions.AddAttribute("Id",
"CM_REMOVE_PROGRAM_MENU_FOLDER" + idSuffix);
fileDefinitions.AddAttribute("On", "uninstall"); fileDefinitions.AddAttribute("On", "uninstall");
fileDefinitions.EndElement("RemoveFolder"); fileDefinitions.EndElement("RemoveFolder");
@ -836,6 +865,56 @@ bool cmCPackWIXGenerator::CreateStartMenuShortcuts(
featureDefinitions.AddAttribute("Id", componentId); featureDefinitions.AddAttribute("Id", componentId);
featureDefinitions.EndElement("ComponentRef"); featureDefinitions.EndElement("ComponentRef");
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;
std::string shortcutId = std::string("CM_DS") + id;
std::string fileId = std::string("CM_F") + id;
fileDefinitions.BeginElement("Shortcut");
fileDefinitions.AddAttribute("Id", shortcutId);
fileDefinitions.AddAttribute("Name", shortcut.textLabel);
std::string target = "[#" + fileId + "]";
fileDefinitions.AddAttribute("Target", target);
fileDefinitions.AddAttribute("WorkingDirectory",
shortcut.workingDirectoryId);
fileDefinitions.EndElement("Shortcut");
}
fileDefinitions.BeginElement("RegistryValue");
fileDefinitions.AddAttribute("Root", "HKCU");
fileDefinitions.AddAttribute("Key", registryKey);
fileDefinitions.AddAttribute("Name", valueName + "_desktop");
fileDefinitions.AddAttribute("Type", "integer");
fileDefinitions.AddAttribute("Value", "1");
fileDefinitions.AddAttribute("KeyPath", "yes");
fileDefinitions.EndElement("RegistryValue");
fileDefinitions.EndElement("Component");
fileDefinitions.EndElement("DirectoryRef");
featureDefinitions.BeginElement("ComponentRef");
featureDefinitions.AddAttribute("Id", componentId);
featureDefinitions.EndElement("ComponentRef");
}
featureDefinitions.EndElement("FeatureRef"); featureDefinitions.EndElement("FeatureRef");
return true; return true;
@ -908,6 +987,7 @@ void cmCPackWIXGenerator::AddDirectoryAndFileDefinitons(
cmWIXSourceWriter& fileDefinitions, cmWIXSourceWriter& fileDefinitions,
cmWIXSourceWriter& featureDefinitions, cmWIXSourceWriter& featureDefinitions,
const std::vector<std::string>& packageExecutables, const std::vector<std::string>& packageExecutables,
const std::vector<std::string>& desktopExecutables,
shortcut_map_t& shortcutMap) shortcut_map_t& shortcutMap)
{ {
cmsys::Directory dir; cmsys::Directory dir;
@ -943,6 +1023,7 @@ void cmCPackWIXGenerator::AddDirectoryAndFileDefinitons(
fileDefinitions, fileDefinitions,
featureDefinitions, featureDefinitions,
packageExecutables, packageExecutables,
desktopExecutables,
shortcutMap); shortcutMap);
ApplyPatchFragment(subDirectoryId, directoryDefinitions); ApplyPatchFragment(subDirectoryId, directoryDefinitions);
@ -995,6 +1076,15 @@ void cmCPackWIXGenerator::AddDirectoryAndFileDefinitons(
cmWIXShortcut &shortcut = shortcutMap[id]; cmWIXShortcut &shortcut = shortcutMap[id];
shortcut.textLabel= textLabel; shortcut.textLabel= textLabel;
shortcut.workingDirectoryId = directoryId; shortcut.workingDirectoryId = directoryId;
if(desktopExecutables.size() &&
std::find(desktopExecutables.begin(),
desktopExecutables.end(),
executableName)
!= desktopExecutables.end())
{
shortcut.desktop = true;
}
} }
} }
} }
@ -1232,6 +1322,15 @@ void cmCPackWIXGenerator::CreateStartMenuFolder(
directoryDefinitions.EndElement("Directory"); directoryDefinitions.EndElement("Directory");
} }
void cmCPackWIXGenerator::CreateDesktopFolder(
cmWIXSourceWriter& directoryDefinitions)
{
directoryDefinitions.BeginElement("Directory");
directoryDefinitions.AddAttribute("Id", "DesktopFolder");
directoryDefinitions.AddAttribute("Name", "Desktop");
directoryDefinitions.EndElement("Directory");
}
void cmCPackWIXGenerator::LoadPatchFragments(const std::string& patchFilePath) void cmCPackWIXGenerator::LoadPatchFragments(const std::string& patchFilePath)
{ {
cmWIXPatchParser parser(Fragments, Logger); cmWIXPatchParser parser(Fragments, Logger);

View File

@ -22,8 +22,13 @@
struct cmWIXShortcut struct cmWIXShortcut
{ {
cmWIXShortcut()
:desktop(false)
{}
std::string textLabel; std::string textLabel;
std::string workingDirectoryId; std::string workingDirectoryId;
bool desktop;
}; };
class cmWIXSourceWriter; class cmWIXSourceWriter;
@ -36,6 +41,8 @@ class cmCPackWIXGenerator : public cmCPackGenerator
public: public:
cmCPackTypeMacro(cmCPackWIXGenerator, cmCPackGenerator); cmCPackTypeMacro(cmCPackWIXGenerator, cmCPackGenerator);
cmCPackWIXGenerator();
protected: protected:
virtual int InitializeInternal(); virtual int InitializeInternal();
@ -133,6 +140,7 @@ private:
cmWIXSourceWriter& fileDefinitions, cmWIXSourceWriter& fileDefinitions,
cmWIXSourceWriter& featureDefinitions, cmWIXSourceWriter& featureDefinitions,
const std::vector<std::string>& pkgExecutables, const std::vector<std::string>& pkgExecutables,
const std::vector<std::string>& desktopExecutables,
shortcut_map_t& shortcutMap); shortcut_map_t& shortcutMap);
bool RequireOption(const std::string& name, std::string& value) const; bool RequireOption(const std::string& name, std::string& value) const;
@ -165,6 +173,8 @@ private:
void CreateStartMenuFolder(cmWIXSourceWriter& directoryDefinitions); void CreateStartMenuFolder(cmWIXSourceWriter& directoryDefinitions);
void CreateDesktopFolder(cmWIXSourceWriter& directoryDefinitions);
void LoadPatchFragments(const std::string& patchFilePath); void LoadPatchFragments(const std::string& patchFilePath);
void ApplyPatchFragment(const std::string& id, cmWIXSourceWriter& writer); void ApplyPatchFragment(const std::string& id, cmWIXSourceWriter& writer);
@ -180,6 +190,8 @@ private:
extension_set_t LightExtensions; extension_set_t LightExtensions;
cmWIXPatchParser::fragment_map_t Fragments; cmWIXPatchParser::fragment_map_t Fragments;
bool HasDesktopShortcuts;
}; };
#endif #endif

View File

@ -49,6 +49,11 @@ set(CPACK_PACKAGE_EXECUTABLES
"my-other-app" "Second CPack WiX Test" "my-other-app" "Second CPack WiX Test"
) )
set(CPACK_CREATE_DESKTOP_LINKS
"my-libapp"
"my-other-app"
)
set(CPACK_WIX_PATCH_FILE "${CMAKE_CURRENT_SOURCE_DIR}/patch.xml") set(CPACK_WIX_PATCH_FILE "${CMAKE_CURRENT_SOURCE_DIR}/patch.xml")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/license.txt") set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/license.txt")