使用cmake创建多个Debian软件包

时间:2018-11-23 15:21:29

标签: cmake deb cpack

我有一个cmake项目,该项目由一组可执行文件组成,彼此独立,并带有两个共享库。我想将每个可执行文件打包到一个deb包中。 结果,我得到了一个包含所有程序和库的deb软件包。

部分源代码:

cmake_minimum_required (VERSION 3.12)

set (CPACK_GENERATOR "DEB")
set (CPACK_DEBIAN_PACKAGE_MAINTAINER "i am")
set (CPACK_DEB_COMPONENT_INSTALL 1)
include (CPack)

add_executable (module1 main.cpp)
install (TARGETS module1 
        RUNTIME DESTINATION bin 
        COMPONENT component1)

add_library (my_lib SHARED map.cpp templates.cpp)
add_executable (my_lib main.cpp utils.cpp)
target_link_libraries (module2 PUBLIC my_lib)

install(TARGETS module2 my_lib
        RUNTIME DESTINATION bin
        LIBRARY DESTINATION lib
        COMPONENT component2)

如何将程序分为不同的deb包?

1 个答案:

答案 0 :(得分:0)

这就是答案

set (CPACK_GENERATOR "DEB")
set (CPACK_DEBIAN_PACKAGE_MAINTAINER "Your name")
set (CPACK_DEB_COMPONENT_INSTALL ON)
include (CPack)

function (add_package TARGET_NAME TARGET_PATH DESCR)
    install(TARGETS "${TARGET_NAME}"
            DESTINATION "${TARGET_PATH}"
            COMPONENT "${TARGET_NAME}")

    cpack_add_component_group("${TARGET_NAME}")

    cpack_add_component("${TARGET_NAME}"
                        DISPLAY_NAME "${TARGET_NAME}"
                        DESCRIPTION "${DESCR}"
                        GROUP "${TARGET_NAME}"
                        INSTALL_TYPES Full)
endfunction ()

add_executable (my_program1 main.cpp)
add_package(my_program1 "bin" "Description")

add_executable (my_program2 main.cpp)
add_package(my_program2 "bin" "Description")

并在终端中运行

make package