[CMake] RPM package and relocation

Domen Vrankar domen.vrankar at gmail.com
Wed May 10 09:56:34 EDT 2017


>
> > set(INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/ssp-suite)
> > install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/ssp/" DESTINATION
> ${INSTALL_DIR})
>

Eric already covered this part - use relative paths instead ( no / at the
beginning).


> But I also need to execute a post script, which runs after installation. I
> added
>
> > set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/
> postinstall")
>
> to my CMakeLists.txt and in that script, I am using the RPM variable
> $RPM_INSTALL_PREFIX. But during installation, I get this error message
>
> > chmod: cannot access '/usr/usr/bin/startssp': No such file or directory
> > warning: %post(ssp-suite-7.1-1.x86_64) scriptlet failed, exit status 1
> > Non-fatal POSTIN scriptlet failure in rpm package ssp-suite-7.1-1.x86_64
>


Pre/postinstall scripts are outside what CPackRPM is handling automatically
but you can still use the relocation paths as supported by RPM.

Example for single relocation path:
set(CPACK_PACKAGING_INSTALL_PREFIX "/usr") # this will become the
relocation path - becomes first relocation path

Example for multiple relocation paths:
set(CPACK_RPM_RELOCATION_PATHS "etc/foo" "opt/bar") # two paths that will
be relocatable - etc will become first relocation path and opt the second
one
set(CPACK_RPM_NO_INSTALL_PREFIX_RELOCATION ON) # this will remove the
default /usr from relocation paths
set(CPACK_PACKAGING_INSTALL_PREFIX "/a") # relative paths will be prefixed
with /a - there is a bug that prevents you from using "/" only for
relocation paths so you might decide to patch CPackRPM.cmake yourself [1]
<https://gitlab.kitware.com/cmake/cmake/merge_requests/583/diffs>


Now for the postinstall script each relocation path becomes a variable in
RPM (RPM_INSTALL_PREFIX0 for first relocation path, RPM_INSTALL_PREFIX1 for
the second and so on) so what you have to do in your script is instead of
writing something like this:

chown someone:somegroup /etc/some_non_relocatable_path/some_file

you should write:

chown someone:somegroup
${RPM_INSTALL_PREFIX0}/some_non_relocatable_path/some_file

Regards,
Domen

[1] https://gitlab.kitware.com/cmake/cmake/merge_requests/583/diffs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170510/0ebc0aaa/attachment.html>


More information about the CMake mailing list