一个CMake项目创建两个Debian软件包

时间:2016-07-11 07:40:40

标签: cmake cpack

我有一个类似的CMake项目:

-Project
|--ApplicationA
|     |---main.cpp
|     |---CMakeLists.txt
|--ApplicationB
|     |---main.cpp
|     |---CMakeLists.txt
|--CMakeLists.txt

我是否有可能跑步"制作套餐" (CPack)它将为ApplicationA创建一个Debian包,为ApplicationB创建一个?

2 个答案:

答案 0 :(得分:0)

您可以为install命令指定组件。 CMake Components

答案 1 :(得分:0)

我也在调查这个问题,但是很难找到信息,所以对于正在寻找这种解决方案的其他人来说,这就是我使用组件以及上面一个主要CMakeLists.txt的结构来完成它的方法。以及子目录中的其他两个CMakeLists.txt。对于这些Debian软件包,这仅是为了正确建立依赖关系(因此无需构建特定的cpp文件)。

对于我的解决方案,这是主目录中CMakeLists.txt的内容:

cmake_minimum_required(VERSION 3.7.2)

project(EVSE-PACKAGE-GENERATOR VERSION 3.0.0)

set(CPACK_COMPONENTS_ALL <COMPONENT_1> <COMPONENT_2>)
set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Maintainer")
set(CPACK_DEB_COMPONENT_INSTALL ON)
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "...")

add_subdirectory(subdirectory1) #In this case "ApplicationA"

add_subdirectory(subdirectory2) #In this case "ApplicationB"

include(CPack)

这些是component1(ApplicationA)的CMakeLists.txt:

cmake_minimum_required(VERSION a.b.c)

project(<COMPONENT_1> VERSION x.y.z)

set(CPACK_COMPONENT_<COMPONENT_1>_DESCRIPTION "Component 1 description" PARENT_SCOPE)
set(CPACK_DEBIAN_<COMPONENT_1>_PACKAGE_FILE_NAME "comp1name")
set(CPACK_DEBIAN_<COMPONENT_1>_PACKAGE_NAME "prefix-${CPACK_DEBIAN_<COMPONENT_1>_PACKAGE_FILE_NAME}" PARENT_SCOPE)
set(CPACK_DEBIAN_<COMPONENT_1>_PACKAGE_DEPENDS "..." PARENT_SCOPE)

set(CPACK_<COMPONENT_1>_PACKAGE_VERSION "${PROJECT_VERSION}${PROJECT_VERSION_PRERELEASE}")
set(CPACK_DEBIAN_<COMPONENT_1>_PACKAGE_ARCHITECTURE "...")

string(TOLOWER "prefix-${CPACK_DEBIAN_<COMPONENT_1>_PACKAGE_FILE_NAME}_${CPACK_<COMPONENT_1>_PACKAGE_VERSION}_${CPACK_DEBIAN_<COMPONENT_1>_PACKAGE_ARCHITECTURE}.deb" DEBIAN_<COMPONENT_1>_FILENAME_STRING )
set(CPACK_DEBIAN_<COMPONENT_1>_FILE_NAME ${DEBIAN_<COMPONENT_1>_FILENAME_STRING} PARENT_SCOPE )
set(CPACK_DEBIAN_<COMPONENT_1>_PACKAGE_CONTROL_STRICT_PERMISSION TRUE PARENT_SCOPE)

和组件2(应用程序B):

cmake_minimum_required(VERSION a.b.c)

project(<COMPONENT_2> VERSION x.y.z)

set(CPACK_COMPONENT_<COMPONENT_2>_DESCRIPTION "Component 2 description" PARENT_SCOPE)
set(CPACK_DEBIAN_<COMPONENT_2>_PACKAGE_FILE_NAME "comp2name")
set(CPACK_DEBIAN_<COMPONENT_2>_PACKAGE_NAME "prefix-${CPACK_DEBIAN_<COMPONENT_2>_PACKAGE_FILE_NAME}" PARENT_SCOPE)
set(CPACK_DEBIAN_<COMPONENT_2>_PACKAGE_DEPENDS "..." PARENT_SCOPE)

set(CPACK_<COMPONENT_2>_PACKAGE_VERSION "${PROJECT_VERSION}${PROJECT_VERSION_PRERELEASE}" )
set(CPACK_DEBIAN_<COMPONENT_2>_PACKAGE_ARCHITECTURE "..." )

string(TOLOWER "prefix-${CPACK_DEBIAN_<COMPONENT_2>_PACKAGE_FILE_NAME}_${CPACK_<COMPONENT_2>_PACKAGE_VERSION}_${CPACK_DEBIAN_<COMPONENT_2>_PACKAGE_ARCHITECTURE}.deb" DEBIAN_<COMPONENT_2>_FILENAME_STRING )
set(CPACK_DEBIAN_<COMPONENT_2>_FILE_NAME ${DEBIAN_<COMPONENT_2>_FILENAME_STRING} PARENT_SCOPE )
set(CPACK_DEBIAN_<COMPONENT_2>_PACKAGE_CONTROL_STRICT_PERMISSION_PACKAGE_CONTROL_STRICT_PERMISSION TRUE PARENT_SCOPE)

希望这会在将来对某人有所帮助。 另外,我还有其他一些资源可能对那些研究此问题或类似问题的人有所帮助:

The Ultimate guide to modern CMake

StackOverflow - Name and description of multiple debian packages with CMake and CPack

CPack: Create debian packge for each sub-project