I am using CPack module in CMake to generate the product installer on macOS. I am trying to install a 3rd party macOS installer package as a prerequisite to our product installer. I tried -
add_executable(
XYZ
IMPORTED
)
set_property(
TARGET XYZ PROPERTY
IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/import/redist/XYZ.pkg
)
install(
IMPORTED_RUNTIME_ARTIFACTS
XYZ
COMPONENT
XYZ
)
However, this doesn't install the XYZ.pkg though it is part of my final product installer pkg file. Is this the correct way to embed and install 3rd party installer package from my product package installer ?
Edit: Instead of executing the XYZ.pkg installer to install it's components, my product installer is copying it to my product's destination folder. I was expecting to chain the install instead.
Looking at CPack
IMPORTED_RUNTIME_ARTIFACTS, I see it is designed for copying files, not executing them. That means the approach you have taken will not execute theXYZ.pkgpackage installer, but will package it into your product's.pkginstaller.If you wish to chain installers, you would typically use a post-install script that is executed once your package is installed. That script would then run the
XYZ.pkginstaller.You can specify a post-install script (for instance,
postflight.sh+chmod 755) using theCPACK_POSTFLIGHT_SCRIPTvariable in CMake, as seen in this thread. Below is a simplified example.In your
CMakeLists.txt, set theCPACK_POSTFLIGHT_SCRIPTvariable to point to your script.Do copy the
XYZ.pkginto a location that thepostflight.shscript can reference, or modify thepostflight.shscript to locateXYZ.pkgappropriately.Once your package is installed, the
postflight.shscript should be executed, and it will run theXYZ.pkginstaller. That should achieve the chained installation behavior you are looking for.Indeed, manipulating the package directly provides a more "native" approach for handling macOS installer packages.
By altering the
distribution.xmland rebuilding the package usingproductbuild, you are essentially creating a "meta-package" that encompasses both your own product and the third-party dependency (XYZ.pkg). That ensures a more streamlined installation process and is generally more robust than relying on post-install scripts to install additional packages.The use of
pkgutilto expand thePRODUCT.pkgandproductbuildto reassemble it, along with the third-party package, is a particularly effective way to achieve this. That approach has the advantage of integrating tightly with the macOS installer system, making it more predictable and potentially less prone to errors compared to a script-based approach.