CMAKE_INSTALL_PREFIX in CPACK_PRE_BUILD_SCRIPTS

I had a look at the docs for DESTDIR and it doesn’t seem like I would be able to use it in this case as it wouldn’t work on Windows.

Unfortunately I don’t have the granular control to be able to use components.
Effectively what I’m doing is the following

install(CODE "execute_process(COMMAND an-executable-that-copies-binaries-into-install-folder)")

And that executable doesn’t provide the API to be able to filter what’s going to be copied.

The docs for CPACK_INSTALL_SCRIPTS state the following

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.