CPack archive changing destination directory permissions

I am trying to use the STGZ cpack generator to distribute my library via a shell script.
The library installs into /usr/local/lib/
When I run the cpack generated shell script with the /usr/local prefix, it changes the permissions of the /usr/local/lib directory to 755.
For various reasons the /usr/local/lib directory must have 775 permissions on the system.

I have set:

set(CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS
OWNER_READ
OWNER_WRITE
OWNER_EXECUTE
GROUP_READ
GROUP_WRITE
GROUP_EXECUTE
WORLD_READ
WORLD_EXECUTE
)
before including CPack, but that did not work.

This is the relevant code from my library:

set(CMAKE_INSTALL_PREFIX “/usr/local” CACHE PATH “Install path prefix” FORCE)
install(TARGETS mylib LIBRARY DESTINATION lib COMPONENT mylib
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
install(FILES ${PUBLIC_HEADERS} DESTINATION include COMPONENT mylib
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_WRITE WORLD_READ
)
cpack_add_component(mylib)

The same problem applies for the include files which are put in /usr/local/include.

How can I avoid changing the permissions of the install destination directories?
The fact that the permissions are being changed on these directories is also a problem because I need anyone in a specific group to be able to install these, but now the installation doesn’t work without sudo.

I have solved the problem of chaning permissions for now by setting umask 002 before running cpack, but would appreciate any better way to resolve this.

I still need to run the script with sudo because:

tar: lib: Cannot utime: Operation not permitted
tar: include: Cannot utime: Operation not permitted

And with pax:

pax: Access/modification time set failed on: include: Operation not permitted
pax: Access/modification time set failed on: lib: Operation not permitted

CMake generally just uses libarchive for these things; does this happen when using libarchive tooling directly as well?

I can’t speak to that, but I think there should be a way to pass extra flags to the extractor by specifying a env var, eg CPACK_EXTRACTOR_PARAMS.
That way we could pass flags to tar/pax which would prevent them from trying to set utime/mtime.

There is no other tool; CMake uses libarchive’s library API to extraction, so any flags need interpreted and passed as arguments to these APIs. If there’s a way to get libarchive to do what is intended, knowing what the API difference for that would help.

Alternatively, provide either instructions or a container where the problem can be reproduced and someone else can investigate when they get a chance.

I am talking about the shell script which is created to install (extract) the archive on the target system, not the archive itself. It has a variable which is set to pax or tar for the extraction process, but there is no way to pass additional options to it.
Eg. tar has the --touch and --no-overwrite-dir options which could potentially solve this problem.

https://gitlab.kitware.com/cmake/cmake/-/blame/master/Modules/Internal/CPack/CPack.STGZ_Header.sh.in#L139

I have added the m flag to tar here and rebuilt cmake, and the extraction works now.

Can you please file an issue about this?