我想构建一个演示rpm包,它将一个文件复制到目标系统并执行一些前后脚本。 我设法创建了一个包。当我在目标系统上运行包时,我收到了警告"警告:包xxx意图为yyy plattform"。但没有复制文件。 有任何想法吗? 在我的代码/项目之后:
项目树:
myRpm/CMakeLists.txt
myRpm/install.txt
myRpm/post.py
myRpm/post.sh
myRpm/pre.py
myRpm/pre.sh
CMakeLists:
cmake_minimum_required (VERSION 2.8)
if(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
INCLUDE(InstallRequiredSystemLibraries)
set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1)
set(CPACK_PACKAGE_NAME "my test")
set(CPACK_PACKAGE_VENDOR "tets")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "fake rpm")
set(CPACK_PACKAGE_VERSION "6.6.6")
set(CPACK_PACKAGE_VERSION_MAJOR "6")
set(CPACK_PACKAGE_VERSION_MINOR "6")
set(CPACK_PACKAGE_VERSION_PATCH "6")
set(targetDestDir "myDir")
set(CPACK_GENERATOR "RPM")
install(
FILES "${CMAKE_CURRENT_SOURCE_DIR}/install.txt" "${CMAKE_CURRENT_SOURCE_DIR}/pre.py" "${CMAKE_CURRENT_SOURCE_DIR}/post.py"
DESTINATION "${targetDestDir}"
)
set(CPACK_RPM_PRE_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/pre.sh")
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/post.sh")
include(CPack)
endif()
答案 0 :(得分:1)
在为其他系统/发行版构建RPM时,CPACK_RPM_PACKAGE_ARCHITECTURE的值很重要。 以下代码应该有效:
cmake_minimum_required (VERSION 2.8)
if(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
INCLUDE(InstallRequiredSystemLibraries)
set(CMAKE_INSTALL_TMPDIR /tmp CACHE PATH "Output dir for tmp")
set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1)
set(CPACK_PACKAGE_NAME "mytest")
set(CPACK_PACKAGE_VENDOR "tets")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "fake rpm")
set(CPACK_PACKAGE_VERSION "6.6.6")
set(CPACK_PACKAGE_VERSION_MAJOR "6")
set(CPACK_PACKAGE_VERSION_MINOR "6")
set(CPACK_PACKAGE_VERSION_PATCH "6")
set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_PACKAGE_ARCHITECTURE "noarch")
set(targetDestDir ${CMAKE_INSTALL_TMPDIR})
install(
FILES "${CMAKE_CURRENT_SOURCE_DIR}/install.txt" "${CMAKE_CURRENT_SOURCE_DIR}/post.py"
DESTINATION "${targetDestDir}"
)
set(CPACK_RPM_PRE_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/pre.sh")
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/post.sh")
include(CPack)
endif()
注意: pre.sh和post.sh位于源的根目录中。在post.sh中调用post.py。