I’m trying to use CPACK_PRE_BUILD_SCRIPTS to filter out certain files from the staging directory before CPack begins packaging. The use case for this is that we call on an external package manager executable to copy binaries into our install directory. That’s done through install(CODE …).
Unfortunately, some of the binaries being copied into the install directory aren’t required or desired in the final package, such as test executables and other CI tools. I was hoping to use CPACK_PRE_BUILD_SCRIPTS to remove any unwanted files from the staging directory before CPack does it’s thing.
This is where my issue lies, the script I have that’s run for CPACK_PRE_BUILD_SCRIPTS doesn’t have it’s CMAKE_ variables initialised to what I’d expect. If I have the following pre-build script:
At the very least I was hoping that CMAKE_INSTALL_PREFIX would be initialised to the staging directory. Currently it’s not even set to what’s in my CMakeCache.
Is this expected behaviour for CPACK_PRE_BUILD_SCRIPTS?
Currently using CMake 3.19.3
Windows 10
Tried Visual Studio 2019 and Ninja CMake generators
Tried ZIP and NSIS CPack generators
You’re probably looking for $ENV{DESTDIR} which is what CPack uses to “inject” itself into the installation procedure. That said, not all of the variables are available.
I think you probably want to use components for the bits you want and then install only those components rather than trying to undo installation of some bits.
For every script, the following variables will be set: CMAKE_CURRENT_SOURCE_DIR, CMAKE_CURRENT_BINARY_DIR and CMAKE_INSTALL_PREFIX (which is set to the staging install directory)
I was hoping the same would apply to CPACK_PRE_BUILD_SCRIPTS since they seem to be related, but unfortunately not.
I have an alternative solution which doesn’t make use of CPACK_PRE_BUILD_SCRIPTS and instead just extends the code in the install(CODE …) mentioned above to include the same script as I would assign to CPACK_PRE_BUILD_SCRIPTS. In that case CMAKE_INSTALL_PREFIX will be initialised correctly to the staging directory.