CMake, CPack, INSTALL(FILES...), "make package", and permission denied...

I have an open source project that is using CMake and CPack to build our distributables - deb, rpm, tarballs, and hopefully DMG and a Windows Installer in the future. Due to our various target platforms, we are stuck with CMake 3.5 for the time being (as it’s the provided version on those platforms). I’m working through adding some documentation files to our Linux builds (Deb, RPM, and tarballs for now) - man pages, authors file, etc. I initially did this using:

INSTALL(FILES “${PROJECT_SOURCE_DIR}/…/ChangeLog” TYPE DOC)

When I loaded it into our CI environment I discovered that I used something that does’t come into play until CMake 3.14 - the TYPE parameter as some of our environments failed to recognize the parameter. I’ve since updated to detect the CMake version and switch to the following:

INSTALL(FILES “${PROJECT_SOURCE_DIR}/…/ChangeLog” DESTINATION “/usr/share/myApplication/doc”)

However, now when I run “make package” I’m getting permission denied errors from CPACK as it seems it is trying to do a “make install” automatically before packaging the files. I’d really like to be able to get these files packages up; is there a way to do this without granting admin privileges? I’d rather not do “make install” to build the packages.

BTW - I’d love to be able to use a CMake variable for the destination instead of hard-coding one; but nothing was apparent while looking through the docs.

Please advise.

Use relative install destinations rather than absolute. Take a look at the GNUInstallDirs module, which has been around for quite a while and should still be available to you even with CMake 3.5. The new behavior introduced in CMake 3.14 follows it pretty closely.

The default absolute path of the base of the install is controlled by CMAKE_INSTALL_PREFIX (which defaults to /usr/local on Linux) and cpack overrides that to use a staging area when preparing the packages.

1 Like

Thanks! That perfectly did the trick!