Explorar el Código

CPack/DMG: Do not use CPACK_RESOURCE_FILE_LICENSE for SLA by default

Since macOS 12.0 deprecated the tools needed to attach a SLA to a
`.dmg`, we should no longer do this by default.  Add a policy to
change the default to off.

Fixes: #22978
Brad King hace 3 años
padre
commit
b760828d3f

+ 2 - 2
Help/cpack_gen/dmg.rst

@@ -65,8 +65,8 @@ on macOS:
 
  In a CMake project that uses the :module:`CPack` module to generate
  ``CPackConfig.cmake``, ``CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE``
- is automatically enabled by default if it is not set and
- :variable:`CPACK_RESOURCE_FILE_LICENSE` is set to a non-default value.
+ must be explicitly enabled by the project to activate the SLA.
+ See policy :policy:`CMP0133`.
 
  .. note::
 

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

@@ -58,6 +58,7 @@ Policies Introduced by CMake 3.24
 .. toctree::
    :maxdepth: 1
 
+   CMP0133: The CPack module disables SLA by default in the CPack DragNDrop Generator. </policy/CMP0133>
    CMP0132: Do not set compiler environment variables on first run. </policy/CMP0132>
    CMP0131: LINK_LIBRARIES supports the LINK_ONLY generator expression. </policy/CMP0131>
    CMP0130: while() diagnoses condition evaluation errors. </policy/CMP0130>

+ 32 - 0
Help/policy/CMP0133.rst

@@ -0,0 +1,32 @@
+CMP0133
+-------
+
+.. versionadded:: 3.24
+
+The :module:`CPack` module disables SLA by default in the
+:cpack_gen:`CPack DragNDrop Generator`.
+
+The :cpack_gen:`CPack DragNDrop Generator` in CMake 3.22 and below attach a
+Software License Agreement (SLA) to ``.dmg`` files using the file specified
+by :variable:`CPACK_RESOURCE_FILE_LICENSE`, if set to a non-default value.
+macOS 12.0 deprecated the tools used to do this, so CMake 3.23 added
+the :variable:`CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE` option to
+control the behavior.  CMake 3.23 enables that option by default for
+compatibility with older versions. CMake 3.24 and above prefer to *not*
+enable the :variable:`CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE` option by
+default. This policy provides compatibility with projects that have not
+been updated to account for the lack of a SLA in their ``.dmg`` packages.
+
+The ``OLD`` behavior for this policy is to enable
+:variable:`CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE` by default.
+The ``NEW`` behavior for this policy is to not enable it by default.
+
+This policy was introduced in CMake version 3.24.  Use the
+:command:`cmake_policy` command to set this policy to ``OLD`` or ``NEW``
+explicitly. Unlike many policies, CMake version |release| does *not* warn
+by default when this policy is not set and simply uses ``OLD`` behavior.
+See documentation of the
+:variable:`CMAKE_POLICY_WARNING_CMP0133 <CMAKE_POLICY_WARNING_CMP<NNNN>>`
+variable to control the warning.
+
+.. include:: DEPRECATED.txt

+ 6 - 0
Help/release/dev/cpack-dmg-sla.rst

@@ -0,0 +1,6 @@
+cpack-dmg-sla
+-------------
+
+* The :module:`CPack` module no longer enables the SLA by default in the
+  :cpack_gen:`CPack DragNDrop Generator`.  See policy :policy:`CMP0133`
+  and the :variable:`CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE` variable.

+ 2 - 0
Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst

@@ -36,6 +36,8 @@ only for the policies that do not warn by default:
   policy :policy:`CMP0128`.
 * ``CMAKE_POLICY_WARNING_CMP0129`` controls the warning for
   policy :policy:`CMP0129`.
+* ``CMAKE_POLICY_WARNING_CMP0133`` controls the warning for
+  policy :policy:`CMP0133`.
 
 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 - 2
Modules/CPack.cmake

@@ -817,8 +817,20 @@ _cpack_set_default(CPACK_NSIS_INSTALLER_ICON_CODE "")
 _cpack_set_default(CPACK_NSIS_INSTALLER_MUI_ICON_CODE "")
 
 # DragNDrop specific variables
-if(CPACK_RESOURCE_FILE_LICENSE AND NOT CPACK_RESOURCE_FILE_LICENSE STREQUAL "${CMAKE_ROOT}/Templates/CPack.GenericLicense.txt")
-  _cpack_set_default(CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE ON)
+if(NOT DEFINED CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE
+    AND CPACK_RESOURCE_FILE_LICENSE AND NOT CPACK_RESOURCE_FILE_LICENSE STREQUAL "${CMAKE_ROOT}/Templates/CPack.GenericLicense.txt")
+  cmake_policy(GET CMP0133 _CPack_CMP0133)
+  if(NOT "x${_CPack_CMP0133}x" STREQUAL "xNEWx")
+    if(NOT "x${_CPack_CMP0133}x" STREQUAL "xOLDx" AND CMAKE_POLICY_WARNING_CMP0133)
+      cmake_policy(GET_WARNING CMP0133 _CMP0133_warning)
+      message(AUTHOR_WARNING
+        "${_CMP0133_warning}\n"
+        "For compatibility, CMake will enable the SLA in the CPack DragNDrop Generator."
+        )
+    endif()
+    _cpack_set_default(CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE ON)
+  endif()
+  unset(_CPack_CMP0133)
 endif()
 
 # WiX specific variables

+ 5 - 1
Source/cmPolicies.h

@@ -396,7 +396,11 @@ class cmMakefile;
          24, 0, cmPolicies::WARN)                                             \
   SELECT(POLICY, CMP0132,                                                     \
          "Do not set compiler environment variables on first run", 3, 24, 0,  \
-         cmPolicies::WARN)
+         cmPolicies::WARN)                                                    \
+  SELECT(POLICY, CMP0133,                                                     \
+         "The CPack module disables SLA by default in the CPack DragNDrop "   \
+         "Generator.",                                                        \
+         3, 24, 0, cmPolicies::WARN)
 
 #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
 #define CM_FOR_EACH_POLICY_ID(POLICY)                                         \

+ 3 - 0
Tests/RunCMake/CPackConfig/CMP0133-NEW-check.cmake

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

+ 2 - 0
Tests/RunCMake/CPackConfig/CMP0133-NEW.cmake

@@ -0,0 +1,2 @@
+set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_LIST_DIR}/SLA.txt")
+cmake_policy(SET CMP0133 NEW)

+ 3 - 0
Tests/RunCMake/CPackConfig/CMP0133-WARN-check.cmake

@@ -0,0 +1,3 @@
+include(${RunCMake_SOURCE_DIR}/check.cmake)
+
+test_variable(CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE "ON")

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

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

+ 2 - 0
Tests/RunCMake/CPackConfig/CMP0133-WARN.cmake

@@ -0,0 +1,2 @@
+set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_LIST_DIR}/SLA.txt")
+set(CMAKE_POLICY_WARNING_CMP0133 1)

+ 1 - 1
Tests/RunCMake/CPackConfig/CMakeLists.txt

@@ -1,6 +1,6 @@
 cmake_minimum_required(VERSION 3.3)
 
 project(${RunCMake_TEST})
-include(${RunCMake_TEST}.cmake)
+include(${RunCMake_TEST}.cmake NO_POLICY_SCOPE)
 
 include(CPack)

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

@@ -1,5 +1,7 @@
 include(RunCMake)
 
+run_cmake(CMP0133-NEW)
+run_cmake(CMP0133-WARN)
 run_cmake(Simple)
 run_cmake(Default)
 run_cmake(Special)

+ 4 - 0
Tests/RunCMake/CPackConfig/SLA.txt

@@ -0,0 +1,4 @@
+Example License File
+--------------------
+
+This is an example license file for a DMG.