CPack具有自己的依赖项的多个包

时间:2015-10-20 15:27:35

标签: c++ linux cmake packages cpack

使用CPack和CMake创建两个debian软件包时遇到问题。我已经完成了here的示例,我确实设法创建了两个不同的debian包,但我希望每个包都有自己的依赖项。生成的CMakeLists.txt如下:

cmake_minimum_required(VERSION 2.8.0)
project(MyLib)

add_library(mylib mylib.cpp)

add_executable(mylibapp mylibapp.cpp)
target_link_libraries(mylibapp mylib)

install(TARGETS mylib 
  ARCHIVE
  DESTINATION ~/Downloads/ComponentExampleStart/lib
  COMPONENT libraries)

install(TARGETS mylibapp
  RUNTIME
  DESTINATION ~/Downloads/ComponentExampleStart/bin
  COMPONENT applications)

install(FILES mylib.h
  DESTINATION ~/Downloads/ComponentExampleStart/include
  COMPONENT headers)

file(WRITE dummy_main1.c "int main(int argc, char** argv){return 0;}")
add_executable(dummy_main1 dummy_main1.c)
INSTALL (FILES ${CMAKE_CURRENT_SOURCE_DIR}/dummy_main1 DESTINATION /tmp COMPONENT headers OPTIONAL PERMISSIONS OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE)

file(WRITE dummy_main2.c "int main(int argc, char** argv){return 0;}")
add_executable(dummy_main2 dummy_main2.c)
INSTALL (FILES ${CMAKE_CURRENT_SOURCE_DIR}/dummy_main2 DESTINATION /tmp COMPONENT mylibapp OPTIONAL PERMISSIONS OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE )

SET (CPACK_GENERATOR "DEB")
SET (CPACK_SOURCE_GENERATOR TGZ)
SET (CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
SET (CPACK_SET_DESTDIR "on")
set(CPACK_DEB_COMPONENT_INSTALL ON)
set(CPACK_PACKAGE_NAME "MyLib")
set(CPACK_PACKAGE_VENDOR "CMake.org")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MyLib - CPack Component Installation Example")
set(CPACK_PACKAGE_VERSION "1.0.0")
set(CPACK_PACKAGE_VERSION_MAJOR "1")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "0")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "CPack Component Example")
set(CPACK_COMPONENTS_ALL applications libraries headers)
set(CPACK_COMPONENT_APPLICATIONS_GROUP "Runtime")
set(CPACK_COMPONENT_LIBRARIES_GROUP "Development")
set(CPACK_COMPONENT_HEADERS_GROUP "Development")
set(CPACK_COMPONENT_LIBRARIES_DEPENDS "libxml2")
set(CPACK_COMPONENT_HEADERS_DEPENDS "libxml2")

set(CPACK_DEBIAN_PACKAGE_DEPENDS "libusb-1.0-0")
SET (CPACK_PACKAGE_CONTACT "Example ")
SET (CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}_${VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")

include(CPack)

注意 dummy_main1和dummy_main2使shlibdeps正常工作,因为每个包至少需要一个可执行文件。)

我的目标是创建两个具有不同依赖关系的不同debian包,比如说:

MyLib_1.0.0_amd64-Developers.deb --- depends on ---> libxml2
MyLib_1.0.0_amd64-Runtime.deb --- depends on ---> lubusb-1.0-0

但我没有找到CPACK宏来做到这一点。我已经阅读了很多论坛和文档,但我没有为我测试过工作。 CPACK_DEBIAN_PACKAGE_DEPENDS宏工作正常,但它为两个包设置了相同的依赖项。有没有办法实现我的目标?我正在使用CMake 2.8来做到这一点。

谢谢!

1 个答案:

答案 0 :(得分:1)

好吧,我终于设法隔离了依赖项。问题是我使用的CMake版本(2.8)。这可以使用CPack宏在最新版本(目前使用3.3)中完成:CPACK_DEBIAN__PACKAGE_DEPENDS