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