Browse Source

CPack/WIX: Generate perMachine installers by default

Add policy CMP0172 to set `CPACK_WIX_INSTALL_SCOPE` to `perMachine` by
default.  Follow up commit 60661f6770 (CPack/WiX: Make InstallScope
configurable, 2023-11-07, v3.29.0-rc1~413^2) and commit 614100dbf6
(CPack/WiX: Restore default (missing) InstallScope from 3.28 and lower,
2024-06-05, v3.30.0-rc1~7^2~1).

Issue: #20962
Issue: #26029
Brad King 1 year ago
parent
commit
d588e81ffb

+ 3 - 5
Help/cpack_gen/wix.rst

@@ -458,8 +458,7 @@ Windows using WiX.
    administrative privileges.  Start menu entries created by the
    installer are visible to all users.
 
-   This is the default if :variable:`CPACK_WIX_VERSION` is set to any
-   value other than ``3``.
+   This is the default.  See policy :policy:`CMP0172`.
 
  ``perUser``
    Not yet supported. This is reserved for future use.
@@ -467,9 +466,8 @@ Windows using WiX.
  ``NONE``
    Create an installer without any ``InstallScope`` attribute.
 
-   If :variable:`CPACK_WIX_VERSION` is not set, or is set to ``3``, this
-   value is the default to preserve compatibility with 3.28 and lower.
-   Otherwise, this value is not supported.
+   This is supported only if :variable:`CPACK_WIX_VERSION` is not set,
+   or is set to ``3``.
 
    .. deprecated:: 3.29
 

+ 1 - 0
Help/manual/cmake-policies.7.rst

@@ -57,6 +57,7 @@ Policies Introduced by CMake 3.31
 .. toctree::
    :maxdepth: 1
 
+   CMP0172: The CPack module enables per-machine installation by default in the CPack WIX Generator. </policy/CMP0172>
    CMP0171: 'codegen' is a reserved target name. </policy/CMP0171>
 
 Policies Introduced by CMake 3.30

+ 39 - 0
Help/policy/CMP0172.rst

@@ -0,0 +1,39 @@
+CMP0172
+-------
+
+.. versionadded:: 3.31
+
+The :module:`CPack` module enables per-machine installation by default
+in the :cpack_gen:`CPack WIX Generator`.
+
+The :cpack_gen:`CPack WIX Generator`'s :variable:`CPACK_WIX_INSTALL_SCOPE`
+option controls the scope of the generated Windows Installer package.
+When :variable:`CPACK_WIX_VERSION` is set to 4 or higher, the default scope
+is ``perMachine``.  However, when using WIX 3 the default scope is ``NONE``,
+and CPack does not set any ``InstallScope`` in the package specification.
+The resulting installer requires administrative privileges and installs
+into the system-wide ``ProgramFiles`` directory, but the start menu entry
+and uninstaller registration are created only for the current user.
+
+The :module:`CPack` module in CMake 3.30 and older does not specify any
+:variable:`CPACK_WIX_INSTALL_SCOPE` value by default, so CPack uses no
+installation scope by default with WIX 3.  CMake 3.31 and newer instead
+prefer to set :variable:`CPACK_WIX_INSTALL_SCOPE` to ``perMachine`` by
+default to make the behavior consistent across all WIX versions.  This
+policy provides compatibility for projects that have not been updated
+to expect ``perMachine`` behavior.
+
+The ``OLD`` behavior for this policy is to not set
+:variable:`CPACK_WIX_INSTALL_SCOPE` by default.  The ``NEW`` behavior for
+this policy is to set :variable:`CPACK_WIX_INSTALL_SCOPE` to ``perMachine``
+by default.
+
+.. |INTRODUCED_IN_CMAKE_VERSION| replace:: 3.31
+.. |WARNS_OR_DOES_NOT_WARN| replace:: does *not* warn by default
+.. include:: STANDARD_ADVICE.txt
+
+See documentation of the
+:variable:`CMAKE_POLICY_WARNING_CMP0172 <CMAKE_POLICY_WARNING_CMP<NNNN>>`
+variable to control the warning.
+
+.. include:: DEPRECATED.txt

+ 6 - 0
Help/release/dev/cpack-wix-per-machine.rst

@@ -0,0 +1,6 @@
+cpack-wix-per-machine
+---------------------
+
+* The :module:`CPack` module enables per-machine installation by default
+  in the :cpack_gen:`CPack WIX Generator`.  See policy :policy:`CMP0172`
+  and the :variable:`CPACK_WIX_INSTALL_SCOPE` variable.

+ 2 - 0
Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst

@@ -38,6 +38,8 @@ only for the policies that do not warn by default:
   policy :policy:`CMP0129`.
 * ``CMAKE_POLICY_WARNING_CMP0133`` controls the warning for
   policy :policy:`CMP0133`.
+* ``CMAKE_POLICY_WARNING_CMP0172`` controls the warning for
+  policy :policy:`CMP0172`.
 
 This variable should not be set by a project in CMake code.  Project
 developers running CMake may set this variable in their cache to

+ 14 - 0
Modules/CPack.cmake

@@ -885,6 +885,20 @@ endif()
 
 # WiX specific variables
 _cpack_set_default(CPACK_WIX_SIZEOF_VOID_P "${CMAKE_SIZEOF_VOID_P}")
+if(NOT DEFINED CPACK_WIX_INSTALL_SCOPE)
+  cmake_policy(GET CMP0172 _CPack_CMP0172)
+  if("x${_CPack_CMP0172}x" STREQUAL "xNEWx")
+    _cpack_set_default(CPACK_WIX_INSTALL_SCOPE perMachine)
+  elseif(NOT "x${_CPack_CMP0172}x" STREQUAL "xOLDx" AND CMAKE_POLICY_WARNING_CMP0172)
+    cmake_policy(GET_WARNING CMP0172 _CMP0172_warning)
+    message(AUTHOR_WARNING
+      "${_CMP0172_warning}\n"
+      "For compatibility, CMake will not enable per-machine installation by default in the CPack WIX Generator."
+      )
+    unset(_CMP0172_warning)
+  endif()
+  unset(_CPack_CMP0172)
+endif()
 
 # productbuild specific variables
 cmake_policy(GET CMP0161 _CPack_CMP0161)

+ 5 - 1
Source/cmPolicies.h

@@ -527,7 +527,11 @@ class cmMakefile;
          "FETCHCONTENT_FULLY_DISCONNECTED requirements are enforced.", 3, 30, \
          0, cmPolicies::WARN)                                                 \
   SELECT(POLICY, CMP0171, "'codegen' is a reserved target name.", 3, 31, 0,   \
-         cmPolicies::WARN)
+         cmPolicies::WARN)                                                    \
+  SELECT(POLICY, CMP0172,                                                     \
+         "The CPack module enables per-machine installation by default in "   \
+         "the CPack WIX Generator.",                                          \
+         3, 31, 0, cmPolicies::WARN)
 
 #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
 #define CM_FOR_EACH_POLICY_ID(POLICY)                                         \

+ 2 - 0
Tests/RunCMake/CPackConfig/CMP0172-NEW-check.cmake

@@ -0,0 +1,2 @@
+include(${RunCMake_SOURCE_DIR}/check.cmake)
+test_variable(CPACK_WIX_INSTALL_SCOPE "perMachine")

+ 1 - 0
Tests/RunCMake/CPackConfig/CMP0172-NEW.cmake

@@ -0,0 +1 @@
+cmake_policy(SET CMP0172 NEW)

+ 2 - 0
Tests/RunCMake/CPackConfig/CMP0172-OLD-check.cmake

@@ -0,0 +1,2 @@
+include(${RunCMake_SOURCE_DIR}/check.cmake)
+test_variable(CPACK_WIX_INSTALL_SCOPE "")

+ 2 - 0
Tests/RunCMake/CPackConfig/CMP0172-OLD.cmake

@@ -0,0 +1,2 @@
+set(CMAKE_POLICY_WARNING_CMP0172 1)
+cmake_policy(SET CMP0172 OLD)

+ 2 - 0
Tests/RunCMake/CPackConfig/CMP0172-WARN-check.cmake

@@ -0,0 +1,2 @@
+include(${RunCMake_SOURCE_DIR}/check.cmake)
+test_variable(CPACK_WIX_INSTALL_SCOPE "")

+ 12 - 0
Tests/RunCMake/CPackConfig/CMP0172-WARN-stderr.txt

@@ -0,0 +1,12 @@
+^CMake Warning \(dev\) at [^
+]*/Modules/CPack\.cmake:[0-9]+ \(message\):
+  Policy CMP0172 is not set: The CPack module enables per-machine
+  installation by default in the CPack WIX Generator\.  Run "cmake
+  --help-policy CMP0172" for policy details\.  Use the cmake_policy command to
+  set the policy and suppress this warning.
+
+  For compatibility, CMake will not enable per-machine installation by
+  default in the CPack WIX Generator\.
+Call Stack \(most recent call first\):
+  CMakeLists\.txt:[0-9]+ \(include\)
+This warning is for project developers\.  Use -Wno-dev to suppress it\.$

+ 1 - 0
Tests/RunCMake/CPackConfig/CMP0172-WARN.cmake

@@ -0,0 +1 @@
+set(CMAKE_POLICY_WARNING_CMP0172 1)

+ 3 - 0
Tests/RunCMake/CPackConfig/RunCMakeTest.cmake

@@ -5,6 +5,9 @@ run_cmake(CMP0133-WARN)
 run_cmake(CMP0161-NEW)
 run_cmake(CMP0161-OLD)
 run_cmake(CMP0161-WARN)
+run_cmake(CMP0172-NEW)
+run_cmake(CMP0172-OLD)
+run_cmake(CMP0172-WARN)
 run_cmake(Simple)
 run_cmake(Default)
 run_cmake(Special)