CPack per-component value for CPACK_PACKAGING_INSTALL_PREFIX when using RPM generator

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

CPack per-component value for CPACK_PACKAGING_INSTALL_PREFIX when using RPM generator

Sam Lunt
I am trying to set a per-component value for
CPACK_PACKAGING_INSTALL_PREFIX when using the RPM generator, but I
haven't been able to do so.

I would like to be able to:
1. Install using "make install" (or cmake --build ${BUILD_DIR}
--target install) and have CMAKE_INSTALL_PREFIX control the install
location
2. Generate an rpm file for each component such that the rpm is
relocatable (i.e. --prefix and --relocate are supported) and each
component has a different default installation location

The documentation for CPACK_RPM_<COMPONENT>_PACKAGE_PREFIX seems to
indicate that it is the correct way to set a per-component install
prefix, since it says that CPACK_RPM_<COMPONENT>_PACKAGE_PREFIX "May
be used to set per component CPACK_PACKAGING_INSTALL_PREFIX for
relocatable RPM packages." However, I am only able to successfully use
this if I provide an absolute path to the install command, but that
inhibits the use of CMAKE_INSTALL_PREFIX.

Here is a minimal example that illustrates the problem:

## start CMakeLists.txt
cmake_minimum_required(VERSION 3.8)

project(FooBar
    VERSION 0.1.0
)

add_executable(foo foo.cpp)
add_executable(bar bar.cpp)

include(GNUInstallDirs)
install(TARGETS foo
    DESTINATION "${CMAKE_INSTALL_BINDIR}"
    COMPONENT Foo_Comp
)

install(TARGETS bar
    DESTINATION "${CMAKE_INSTALL_BINDIR}"
    COMPONENT Bar_Comp
)

set(CPACK_PACKAGE_VERSION_MAJOR ${FooBar_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${FooBar_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${FooBar_VERSION_PATCH})

set(CPACK_PACKAGE_RELOCATABLE ON)
set(CPACK_PACKAGING_INSTALL_PREFIX "/tmp_dir/foobar")

set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_RPM_FOO_COMP_PACKAGE_PREFIX "/tmp_dir/foo")
set(CPACK_RPM_BAR_COMP_PACKAGE_PREFIX "/tmp_dir/bar")

include(CPack)
## end CMakeLists.txt

When the command "cmake ${SOURCE_DIR} -G "Unix Makefiles" && cmake
--build . && cpack -G RPM", the call to cpack generates the warnings:

CMake Warning (dev) at /usr/share/cmake/CPackRPM.cmake:999 (message):
  CPackRPM:Warning: Path /tmp_dir/foobar/bin/bar is not on one of the
  relocatable paths! Package will be partially relocatable.
Call Stack (most recent call first):
  /usr/share/cmake/Modules/CPackRPM.cmake:1841
(cpack_rpm_prepare_relocation_paths)
  /usr/share/cmake/Modules/CPackRPM.cmake:2690 (cpack_rpm_generate_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

CPackRPM: Will use GENERATED spec file:
/var/tmp/test_pack_prefix/build/_CPack_Packages/Linux/RPM/SPECS/foobar-Bar_Comp.spec
CMake Warning (dev) at /usr/share/cmake/Modules/CPackRPM.cmake:999 (message):
  CPackRPM:Warning: Path /tmp_dir/foobar/bin/foo is not on one of the
  relocatable paths! Package will be partially relocatable.
Call Stack (most recent call first):
  /usr/share/cmake/Modules/CPackRPM.cmake:1841
(cpack_rpm_prepare_relocation_paths)
  /usr/share/cmake/Modules/CPackRPM.cmake:2690 (cpack_rpm_generate_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

CPackRPM: Will use GENERATED spec file:
/var/tmp/test_pack_prefix/build/_CPack_Packages/Linux/RPM/SPECS/foobar-Foo_Comp.spec

The rpm installs the files to CPACK_PACKAGING_INSTALL_PREFIX if I
remove these lines (which prevents a per-component install location):
set(CPACK_RPM_FOO_COMP_PACKAGE_PREFIX "/tmp_dir/foo")
set(CPACK_RPM_BAR_COMP_PACKAGE_PREFIX "/tmp_dir/bar")

I can also prevent the warning by changing the install commands (but
then CMAKE_INSTALL_PREFIX is useless):
install(TARGETS foo
    DESTINATION "/tmp_dir/foo/${CMAKE_INSTALL_BINDIR}"
    COMPONENT Foo_Comp
)

install(TARGETS bar
    DESTINATION "/tmp_dir/bar/${CMAKE_INSTALL_BINDIR}"
    COMPONENT Bar_Comp
)

Is there any way to do what I'm trying to?
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: CPack per-component value for CPACK_PACKAGING_INSTALL_PREFIX when using RPM generator

Domen Vrankar
2018-01-03 22:40 GMT+01:00 Sam Lunt <[hidden email]>:
I am trying to set a per-component value for
CPACK_PACKAGING_INSTALL_PREFIX when using the RPM generator, but I
haven't been able to do so.

I would like to be able to:
1. Install using "make install" (or cmake --build ${BUILD_DIR}
--target install) and have CMAKE_INSTALL_PREFIX control the install
location
2. Generate an rpm file for each component such that the rpm is
relocatable (i.e. --prefix and --relocate are supported) and each
component has a different default installation location

The documentation for CPACK_RPM_<COMPONENT>_PACKAGE_PREFIX seems to
indicate that it is the correct way to set a per-component install
prefix, since it says that CPACK_RPM_<COMPONENT>_PACKAGE_PREFIX "May
be used to set per component CPACK_PACKAGING_INSTALL_PREFIX for
relocatable RPM packages." However, I am only able to successfully use
this if I provide an absolute path to the install command, but that
inhibits the use of CMAKE_INSTALL_PREFIX.

How about using CPACK_RPM_RELOCATION_PATHS?

install(DIRECTORY DESTINATION ${CMAKE_INSTALL_LIBDIR}/some_dir COMPONENT libraries)
set(CPACK_RPM_RELOCATION_PATHS "${CMAKE_INSTALL_INCLUDEDIR}"
  "${CMAKE_INSTALL_LIBDIR}")

You specify all the relocation paths for all components and if one or more of them are found during package generation that path is written to the package as a relocation path.
You can also use https://cmake.org/cmake/help/v3.10/module/CPackRPM.html#variable:CPACK_RPM_NO_INSTALL_PREFIX_RELOCATION to discard CPACK_PACKAGING_INSTALL_PREFIX as a relocation path.

This feature can also (is prefered to) be used in combination with GNUInstallDirs module (https://cmake.org/cmake/help/v3.10/module/GNUInstallDirs.html?highlight=gnuinstalldirs):

include(GNUInstallDirs)

Regards,
Domen

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: CPack per-component value for CPACK_PACKAGING_INSTALL_PREFIX when using RPM generator

Sam Lunt
Hi Domen,

Thanks for the reply, but that doesn't seem to work for me. I modified
my example to add this function call:

list(APPEND CPACK_RPM_RELOCATION_PATHS
    ${CPACK_PACKAGING_INSTALL_PREFIX}
)

that silences the warnings, but it still prepends the
CPACK_PACKAGING_INSTALL_PREFIX when generating the RPM files, while I
want it to prepend CPACK_RPM_<COMPONENT>_PACKAGE_PREFIX.

So if I call "rpm -qlp FooBar-0.1.0-Linux-Bar_Comp.rpm", it outputs:
/tmp_dir/foobar
/tmp_dir/foobar/bin
/tmp_dir/foobar/bin/bar

(CPACK_PACKAGING_INSTALL_PREFIX = /tmp_dir/foobar)

I want it to output:

/tmp_dir/bar
/tmp_dir/bar/bin
/tmp_dir/bar/bin/bar

(CPACK_RPM_BAR_COMP_PACKAGE_PREFIX = /tmp_dir/bar)

It seems like cpack is prepending the CPACK_PACKAGING_INSTALL_PREFIX
to any relative paths before actually calling the CPackRPM.cmake
module, so by the time CPackRPM sees the paths, it is seeing
/tmp_dir/foobar/bin/bar and /tmp_dir/foobar/bin/foo, while I want it
to see /tmp_dir/bar/bin/bar and /tmp_dir/foo/bin/foo. Maybe there is
no way to achieve this currently?

Thanks,
Sam

On Thu, Jan 4, 2018 at 1:51 PM, Domen Vrankar <[hidden email]> wrote:

> 2018-01-03 22:40 GMT+01:00 Sam Lunt <[hidden email]>:
>>
>> I am trying to set a per-component value for
>> CPACK_PACKAGING_INSTALL_PREFIX when using the RPM generator, but I
>> haven't been able to do so.
>>
>> I would like to be able to:
>> 1. Install using "make install" (or cmake --build ${BUILD_DIR}
>> --target install) and have CMAKE_INSTALL_PREFIX control the install
>> location
>> 2. Generate an rpm file for each component such that the rpm is
>> relocatable (i.e. --prefix and --relocate are supported) and each
>> component has a different default installation location
>>
>> The documentation for CPACK_RPM_<COMPONENT>_PACKAGE_PREFIX seems to
>> indicate that it is the correct way to set a per-component install
>> prefix, since it says that CPACK_RPM_<COMPONENT>_PACKAGE_PREFIX "May
>> be used to set per component CPACK_PACKAGING_INSTALL_PREFIX for
>> relocatable RPM packages." However, I am only able to successfully use
>> this if I provide an absolute path to the install command, but that
>> inhibits the use of CMAKE_INSTALL_PREFIX.
>
>
> How about using CPACK_RPM_RELOCATION_PATHS?
> https://cmake.org/cmake/help/v3.10/module/CPackRPM.html#variable:CPACK_RPM_RELOCATION_PATHS
>
> install(DIRECTORY DESTINATION ${CMAKE_INSTALL_LIBDIR}/some_dir COMPONENT
> libraries)
> set(CPACK_RPM_RELOCATION_PATHS "${CMAKE_INSTALL_INCLUDEDIR}"
>   "${CMAKE_INSTALL_LIBDIR}")
>
> You specify all the relocation paths for all components and if one or more
> of them are found during package generation that path is written to the
> package as a relocation path.
> You can also use
> https://cmake.org/cmake/help/v3.10/module/CPackRPM.html#variable:CPACK_RPM_NO_INSTALL_PREFIX_RELOCATION
> to discard CPACK_PACKAGING_INSTALL_PREFIX as a relocation path.
>
> This feature can also (is prefered to) be used in combination with
> GNUInstallDirs module
> (https://cmake.org/cmake/help/v3.10/module/GNUInstallDirs.html?highlight=gnuinstalldirs):
>
> include(GNUInstallDirs)
>
> Regards,
> Domen
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: CPack per-component value for CPACK_PACKAGING_INSTALL_PREFIX when using RPM generator

Domen Vrankar
2018-01-04 22:42 GMT+01:00 Sam Lunt <[hidden email]>:
Hi Domen,

Thanks for the reply, but that doesn't seem to work for me. I modified
my example to add this function call:

list(APPEND CPACK_RPM_RELOCATION_PATHS
    ${CPACK_PACKAGING_INSTALL_PREFIX}
)

The documentation states that CPACK_PACKAGING_INSTALL_PREFIX is prepended so the way you are using it not how it is supposed to be used.

With your example above I'd do something like this:

include(GNUInstallDirs)
install(TARGETS foo
    DESTINATION "${CMAKE_INSTALL_BINDIR}"
    COMPONENT Foo_Comp
)

install(TARGETS bar
    DESTINATION "a/b/c"
    COMPONENT Bar_Comp
)

list(APPEND CPACK_RPM_RELOCATION_PATHS
    "${CMAKE_INSTALL_BINDIR}" "a/b/c"
)

set(CPACK_PACKAGING_INSTALL_PREFIX "/")

This will make "/", "/${CMAKE_INSTALL_BINDIR}" and "/a/b/c" relocatable (and if you want to skip / just set CPACK_PACKAGING_INSTALL_PREFIX).

There was a bug in older versions of CPack that CPACK_PACKAGING_INSTALL_PREFIX could not be set to / (it was fixed by this commit https://gitlab.kitware.com/cmake/cmake/merge_requests/583/diffs in CMake 3.9 so you can backport it if you want to as it is a small change to CPackRPM.cmake file).
 

that silences the warnings, but it still prepends the
CPACK_PACKAGING_INSTALL_PREFIX when generating the RPM files, while I
want it to prepend CPACK_RPM_<COMPONENT>_PACKAGE_PREFIX.

So if I call "rpm -qlp FooBar-0.1.0-Linux-Bar_Comp.rpm", it outputs:
/tmp_dir/foobar
/tmp_dir/foobar/bin
/tmp_dir/foobar/bin/bar

(CPACK_PACKAGING_INSTALL_PREFIX = /tmp_dir/foobar)

I want it to output:

/tmp_dir/bar
/tmp_dir/bar/bin
/tmp_dir/bar/bin/bar

(CPACK_RPM_BAR_COMP_PACKAGE_PREFIX = /tmp_dir/bar)

It seems like cpack is prepending the CPACK_PACKAGING_INSTALL_PREFIX
to any relative paths before actually calling the CPackRPM.cmake
module, so by the time CPackRPM sees the paths, it is seeing
/tmp_dir/foobar/bin/bar and /tmp_dir/foobar/bin/foo, while I want it
to see /tmp_dir/bar/bin/bar and /tmp_dir/foo/bin/foo. Maybe there is
no way to achieve this currently?

What you are trying to achieve seems odd to me particularly since your rpms will be relocatable so why would you want to create the structure of /some_dir/bar_dir/bin/repeated_bar_dir instead of /bin/bar or /tmp_dir/bin/bar with either / for the first case or /tmp_dir for the second case being relocatable?

Regards,
Domen

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake