如何使用 cmake 构建 "file copy" RPM?

How to build a "file copy" RPM using cmake?

我想构建一个演示 rpm 包,它将一个文件复制到目标系统并执行一些预编译和 post 脚本。 我设法创建了一个包。当我 运行 目标系统上的包时,我收到了 e 警告 "warning: package xxx intend for yyy plattform"。但是没有文件被复制。 有任何想法吗? 之后我的 code/project:

项目树:

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()

CPACK_RPM_PACKAGE_ARCHITECTURE 的值在为其他 systems/distros 构建 RPM 时很重要。 以下代码应该有效:

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。