Reputation: 191
I have a cmake project consisting of a set of executable files, independent of each other with two shared libraries. I want to pack each executable file into a deb package. As a result, I get one deb package with all programs and libs.
part of the source code:
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)
How to divide programs into different deb packages?
Upvotes: 8
Views: 1926
Reputation: 191
Well that's the answer
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")
and run in terminal
make package
Upvotes: 6