Browse Source

CPack/DMG: Add explicit option to use CPACK_RESOURCE_FILE_LICENSE for SLA

Since macOS 12.0, the ``hdiutil udifrez`` and ``hdiutil udifderez``
commands to embed and extract resources in a disk image are deprecated.
The CPack DragNDrop Generator uses these to attach the SLA specified by
the `CPACK_RESOURCE_FILE_LICENSE` option.  Since that option is shared
by multiple CPack generators, we cannot deprecate it.  Instead, add an
explicit option to control the behavior.  This will give projects a way
to package on future macOS versions that remove the commands.

In order to provide a long-term transition away from attaching SLAs to
disk images, update `cpack` to default this behavior to OFF.  To retain
compatibility for CMake projects, teach the CPack module to default the
option to ON.  Later a policy can be added to change the default.

Issue: #22978
pull/347/head
Brad King 4 years ago
parent
commit
9e38bfa915
  1. 21
      Help/cpack_gen/dmg.rst
  2. 9
      Help/release/dev/cpack-dmg-sla.rst
  3. 5
      Modules/CPack.cmake
  4. 10
      Source/CPack/cmCPackDragNDropGenerator.cxx
  5. 1
      Tests/RunCMake/CPack/RunCMakeTest.cmake
  6. 4
      Tests/RunCMake/CPack/tests/DMG_SLA_OFF/Example.txt
  7. 2
      Tests/RunCMake/CPack/tests/DMG_SLA_OFF/ExpectedFiles.cmake
  8. 12
      Tests/RunCMake/CPack/tests/DMG_SLA_OFF/VerifyResult.cmake
  9. 3
      Tests/RunCMake/CPack/tests/DMG_SLA_OFF/test.cmake

21
Help/cpack_gen/dmg.rst

@ -54,6 +54,27 @@ on macOS:
Default behavior is to include a symlink to ``/Applications`` in the DMG.
Set this option to ``ON`` to avoid adding the symlink.
.. variable:: CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE
.. versionadded:: 3.23
Control whether :variable:`CPACK_RESOURCE_FILE_LICENSE`, if set to a
non-default value, is used as the license agreement provided when
mounting the DMG. If ``CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE`` is
not set, :manual:`cpack(1)` defaults to off.
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.
.. note::
This option was added in response to macOS 12.0's deprecation of
the ``hdiutil udifrez`` command to make its use optional.
CPack 3.22 and below always use :variable:`CPACK_RESOURCE_FILE_LICENSE`,
if set to a non-default value, as the DMG license.
.. variable:: CPACK_DMG_SLA_DIR
.. versionadded:: 3.5

9
Help/release/dev/cpack-dmg-sla.rst

@ -0,0 +1,9 @@
cpack-dmg-sla
-------------
* The :cpack_gen:`CPack DragNDrop Generator` no longer attaches
:variable:`CPACK_RESOURCE_FILE_LICENSE` as the license agreement in
the generated ``.dmg`` unless explicitly activated by a
:variable:`CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE` option.
In CMake projects, the :module:`CPack` module enables the option
by default for compatibility.

5
Modules/CPack.cmake

@ -805,6 +805,11 @@ _cpack_set_default(CPACK_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
_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)
endif()
# WiX specific variables
_cpack_set_default(CPACK_WIX_SIZEOF_VOID_P "${CMAKE_SIZEOF_VOID_P}")

10
Source/CPack/cmCPackDragNDropGenerator.cxx

@ -98,7 +98,9 @@ int cmCPackDragNDropGenerator::InitializeInternal()
if (this->IsSet("CPACK_DMG_SLA_DIR")) {
slaDirectory = this->GetOption("CPACK_DMG_SLA_DIR");
if (!slaDirectory.empty() && this->IsSet("CPACK_RESOURCE_FILE_LICENSE")) {
if (!slaDirectory.empty() &&
this->IsOn("CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE") &&
this->IsSet("CPACK_RESOURCE_FILE_LICENSE")) {
std::string license_file =
this->GetOption("CPACK_RESOURCE_FILE_LICENSE");
if (!license_file.empty() &&
@ -278,8 +280,10 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
: "HFS+";
// Get optional arguments ...
std::string cpack_license_file =
*this->GetOption("CPACK_RESOURCE_FILE_LICENSE");
std::string cpack_license_file;
if (this->IsOn("CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE")) {
cpack_license_file = *this->GetOption("CPACK_RESOURCE_FILE_LICENSE");
}
cmValue cpack_dmg_background_image =
this->GetOption("CPACK_DMG_BACKGROUND_IMAGE");

1
Tests/RunCMake/CPack/RunCMakeTest.cmake

@ -22,6 +22,7 @@ endif()
run_cpack_test(DIST "RPM.DIST" false "MONOLITHIC")
run_cpack_test(DMG_SLA "DragNDrop" false "MONOLITHIC")
run_cpack_test(DMG_SLA_FILE "DragNDrop" false "MONOLITHIC")
run_cpack_test(DMG_SLA_OFF "DragNDrop" false "MONOLITHIC")
run_cpack_test(EMPTY_DIR "RPM.EMPTY_DIR;DEB.EMPTY_DIR;TGZ" true "MONOLITHIC;COMPONENT")
run_cpack_test(VERSION "RPM.VERSION;DEB.VERSION" false "MONOLITHIC;COMPONENT")
run_cpack_test(EXTRA "DEB.EXTRA" false "COMPONENT")

4
Tests/RunCMake/CPack/tests/DMG_SLA_OFF/Example.txt

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

2
Tests/RunCMake/CPack/tests/DMG_SLA_OFF/ExpectedFiles.cmake

@ -0,0 +1,2 @@
set(EXPECTED_FILES_COUNT "1")
set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")

12
Tests/RunCMake/CPack/tests/DMG_SLA_OFF/VerifyResult.cmake

@ -0,0 +1,12 @@
set(dmg "${bin_dir}/${FOUND_FILE_1}")
execute_process(COMMAND hdiutil udifderez -xml "${dmg}" OUTPUT_VARIABLE out ERROR_VARIABLE err RESULT_VARIABLE res)
if(NOT res EQUAL 0)
string(REPLACE "\n" "\n " err " ${err}")
message(FATAL_ERROR "Running 'hdiutil udifderez -xml' on\n ${dmg}\nfailed with:\n${err}")
endif()
foreach(key "LPic" "STR#" "TEXT")
if(out MATCHES "<key>${key}</key>")
string(REPLACE "\n" "\n " out " ${out}")
message(FATAL_ERROR "error: running 'hdiutil udifderez -xml' on\n ${dmg}\nhas unexpected '${key}' key:\n${out}")
endif()
endforeach()

3
Tests/RunCMake/CPack/tests/DMG_SLA_OFF/test.cmake

@ -0,0 +1,3 @@
install(FILES CMakeLists.txt DESTINATION foo)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_LIST_DIR}/Example.txt")
set(CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE OFF)
Loading…
Cancel
Save