cmWIXFeaturesSourceWriter.cxx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmWIXFeaturesSourceWriter.h"
  4. #include "cmStringAlgorithms.h"
  5. cmWIXFeaturesSourceWriter::cmWIXFeaturesSourceWriter(
  6. unsigned long wixVersion, cmCPackLog* logger, std::string const& filename,
  7. GuidType componentGuidType)
  8. : cmWIXSourceWriter(wixVersion, logger, filename, componentGuidType)
  9. {
  10. }
  11. void cmWIXFeaturesSourceWriter::CreateCMakePackageRegistryEntry(
  12. std::string const& package, std::string const& upgradeGuid)
  13. {
  14. BeginElement("Component");
  15. AddAttribute("Id", "CM_PACKAGE_REGISTRY");
  16. AddAttribute("Directory", "TARGETDIR");
  17. AddAttribute("Guid", CreateGuidFromComponentId("CM_PACKAGE_REGISTRY"));
  18. std::string registryKey =
  19. cmStrCat(R"(Software\Kitware\CMake\Packages\)", package);
  20. BeginElement("RegistryValue");
  21. AddAttribute("Root", "HKLM");
  22. AddAttribute("Key", registryKey);
  23. AddAttribute("Name", upgradeGuid);
  24. AddAttribute("Type", "string");
  25. AddAttribute("Value", "[INSTALL_ROOT]");
  26. AddAttribute("KeyPath", "yes");
  27. EndElement("RegistryValue");
  28. EndElement("Component");
  29. }
  30. void cmWIXFeaturesSourceWriter::EmitFeatureForComponentGroup(
  31. cmCPackComponentGroup const& group, cmWIXPatch& patch)
  32. {
  33. BeginElement("Feature");
  34. AddAttribute("Id", cmStrCat("CM_G_", group.Name));
  35. if (group.IsExpandedByDefault) {
  36. AddAttribute("Display", "expand");
  37. }
  38. AddAttributeUnlessEmpty("Title", group.DisplayName);
  39. AddAttributeUnlessEmpty("Description", group.Description);
  40. patch.ApplyFragment(cmStrCat("CM_G_", group.Name), *this);
  41. for (cmCPackComponentGroup* subgroup : group.Subgroups) {
  42. EmitFeatureForComponentGroup(*subgroup, patch);
  43. }
  44. for (cmCPackComponent* component : group.Components) {
  45. EmitFeatureForComponent(*component, patch);
  46. }
  47. EndElement("Feature");
  48. }
  49. void cmWIXFeaturesSourceWriter::EmitFeatureForComponent(
  50. cmCPackComponent const& component, cmWIXPatch& patch)
  51. {
  52. BeginElement("Feature");
  53. AddAttribute("Id", cmStrCat("CM_C_", component.Name));
  54. AddAttributeUnlessEmpty("Title", component.DisplayName);
  55. AddAttributeUnlessEmpty("Description", component.Description);
  56. if (component.IsRequired) {
  57. if (this->WixVersion >= 4) {
  58. AddAttribute("AllowAbsent", "no");
  59. } else {
  60. AddAttribute("Absent", "disallow");
  61. }
  62. }
  63. if (component.IsHidden) {
  64. AddAttribute("Display", "hidden");
  65. }
  66. if (component.IsDisabledByDefault) {
  67. AddAttribute("Level", "2");
  68. }
  69. patch.ApplyFragment(cmStrCat("CM_C_", component.Name), *this);
  70. EndElement("Feature");
  71. }
  72. void cmWIXFeaturesSourceWriter::EmitComponentRef(std::string const& id)
  73. {
  74. BeginElement("ComponentRef");
  75. AddAttribute("Id", id);
  76. EndElement("ComponentRef");
  77. }