我有多个CMake项目,每个项目都创建一个debian包。我一直在尝试创建一个顶级项目,在每个'子'项目上调用add_subdirectory()。所有子项目都会构建,但“make project”会创建一个包含上一个子项目规范的项目,并包含来自所有其他项目的文件。
基本上,每个集合(CPACK _...)都被下一个项目覆盖,直到最后一个项目和'install()'调用被累积。如何在使用顶级项目时分离包创建?
修改:添加了代码段。所有“孩子”项目都很相似。
# build a CPack driven installer package
if(CMAKE_BUILD_TYPE STREQUAL "release")
set(CPACK_STRIP_FILES TRUE)
endif()
set(CPACK_GENERATOR DEB)
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_VENDOR Acme)
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "acme <support@acme.com>")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Acme daemon")
message(STATUS "CPACK_PACKAGE_DESCRIPTION_SUMMARY: " ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(SYSTEM_PROCESSOR amd64)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm")
set(SYSTEM_PROCESSOR armhf)
else()
message(FATAL_ERROR "CMAKE_SYSTEM_PROCESSOR: " ${CMAKE_SYSTEM_PROCESSOR})
endif()
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${SYSTEM_PROCESSOR})
message(STATUS "CPACK_DEBIAN_PACKAGE_ARCHITECTURE: " ${CPACK_DEBIAN_PACKAGE_ARCHITECTURE})
include(InstallRequiredSystemLibraries)
set(CPACK_PACKAGE_VERSION_MAJOR ${${PROJECT_NAME}_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${${PROJECT_NAME}_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${${PROJECT_NAME}_VERSION_PATCH})
set(CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH})
set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CMAKE_SYSTEM_NAME}-${SYSTEM_PROCESSOR})
message(STATUS "CPACK_PACKAGE_FILE_NAME: " ${CPACK_PACKAGE_FILE_NAME})
set(CPACK_DEBIAN_PACKAGE_PRIORITY optional)
include(CPack)
答案 0 :(得分:1)
在每个子项目的CMakeLists.txt中,您可以设置CPACK_OUTPUT_CONFIG_FILE变量。 例如,对于Child_1项目,在其指定的cmake文件中指定:
set(CPACK_OUTPUT_CONFIG_FILE "${CMAKE_BINARY_DIR}/CPackConfigChild_1.cmake")
然后,在构建顶级项目之后,您可以执行以下操作:
cpack -G DEB --config CPackConfigChild_1.cmake
# the same for all other child projects