[CMake] 'make package': Is setting generators to different default paths possible?

Eric Noulard eric.noulard at gmail.com
Fri Mar 11 01:25:56 EST 2016


2016-03-10 23:41 GMT+01:00 Winfried <winkus4u at arcor.de>:

> It's possible to invoke several CPack generators with one call of 'make
> package' by configuring in CMakeLists.txt:
> set(CPACK_GENERATOR "STGZ;TGZ;TZ;RPM;DEB")
> So far, so good!
>
> A generated package can and shall be relocatable. In other words: You can
> determine at package install time, **where** in the file system the content
> of the package shall be installed to.
> If you install the package without an explicit target location, the default
> value is used. Each CPack generator has it's own individual predefined
> default value (/usr for RPM, ...).
> " This default value may be overwritten from the CMakeLists.txt or the
> cpack
> command line by setting an alternative value.
> e.g. set(CPACK_PACKAGING_INSTALL_PREFIX “/opt”) " ( ->doc of
> CPACK_PACKAGING_INSTALL_PREFIX)
>
> My question:
> It's not unusual that one package has different default locations for
> different distributions.
> So, is it possible to configure different default locations for RPM and
> DEB,
> so that one call of 'make package' can generate a .rpm package with default
> location '/opt/kde3' and a .deb package with default location
> '/usr/local/kde' ?
>

Yes it is.
The more general way to do that is to use a CPACK_PROJECT_CONFIG_FILE.
The specified file will be included **at CPack time** once **for each**
CPack generator
so that you check the currently running CPack generator and do whatever
specific setting
you want.


See documentation on how it works here:
 https://cmake.org/cmake/help/v3.0/module/CPack.html
and an example there:
http://stackoverflow.com/questions/30937317/cpack-cmake-different-installation-prefixes-per-cpack-generator


> My problem:
> When I tried set(CPACK_PACKAGING_INSTALL_PREFIX “/opt/kde3”), 'cmake
> -DCMAKE_INSTALL_PREFIX=/opt/kde3 ..' ran normal, but 'make package' aborted
> with an error messages (repeated several times):
>

[...]


>
>
> INCLUDE(CPack)
>
> Before trying set(CPACK_PACKAGING_INSTALL_PREFIX “/opt/kde3”) I tried
> set(CPACK_SET_DESTDIR "ON").
> Files in the package were in the right place but I was warned that the
> resulting .rpm package isn't relocatable anymore.
>

CPackRPM is playing with CPACK_SET_DESTDIR internally in order to be able
to build relocatable RPM whilst keeping the possibility to have absolutely
installed file
like /etc/whatever.conf.

So if you set CPACK_SET_DESTDIR to ON then CPackRPM stop being able to play
with that.

If you want to play gently with relocation and CPackRPM you can have a look
at:
CPACK_RPM_<COMPONENT>_PACKAGE_PREFIX
CPACK_RPM_RELOCATION_PATHS
CPACK_RPM_NO_INSTALL_PREFIX_RELOCATION
CPACK_RPM_NO_<COMPONENT>_INSTALL_PREFIX_RELOCATION
Again the best way to do generator specific config with CPack is to use
CPACK_PROJECT_CONFIG_FILE.

You'll find attached an excerpt of an outdated CMake tutorial (
https://github.com/TheErk/CMake-tutorial)
which explain when things takes place. This is important to notice that
CMake runs
way before CPack runs. Moreover CPack was designed to possibly be used
without CMake
so you can not always "program" things you want for CPack in your
CMakeLists.txt.

I hope this will help you to do what you want
-- 
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160311/f5d96034/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CMake-workflow-sumarized.pdf
Type: application/pdf
Size: 200640 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160311/f5d96034/attachment-0001.pdf>


More information about the CMake mailing list