gpt4 book ai didi

cmake - CPack打包多包

转载 作者:行者123 更新时间:2023-12-04 15:58:37 29 4
gpt4 key购买 nike

如何使用 cpack 打包多个包。多包如下:

A.tar.gz
---bin/hello
---lib/libhello.a
---B.tar.gz
---bin/demo
---lib/libdemo.a

B.tar.gz 包含在 A.tar.gz 中

最佳答案

我能想到的一种解决方案是创建一个生成 B.tar.gz 的自定义目标。然后使用 install命令添加生成的 B.tar.gz .以下是示例 CMakeLists.txt我用来产生你想要的输出的文件。

cmake_minimum_required(VERSION 2.8)

project(pack_multiple_example)

# Create the custom command to tar up the files
# wanted in the B.tar.gz
set(B_OUTPUT "B.tar.gz")
add_custom_target(
${B_OUTPUT}
COMMAND tar -czf ${B_OUTPUT} demo libdemo.a
DEPENDS demo demo_exe
)
install(
FILES "${PROJECT_BINARY_DIR}/${B_OUTPUT}"
DESTINATION .
)

# Create libhello target
set(HELLOLIB_SRCS hellolib.c)
add_library(hello ${HELLOLIB_SRCS})
install(
TARGETS hello
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
COMPONENT hello
)

# Create hello binary target
set(HELLO_SRCS hello.c)
add_executable(hello_exe ${HELLO_SRCS})
# Auto-build the B.tar.gz when hello_exe changes
add_dependencies(hello_exe ${B_OUTPUT})
target_link_libraries(hello_exe hello)
# Set the output name since we use the 'hello' target name
# for the library target.
set_target_properties(hello_exe PROPERTIES OUTPUT_NAME hello)
install(
TARGETS hello_exe
RUNTIME DESTINATION bin
COMPONENT hello
)

# Create libdemo target
set(DEMOLIB_SRCS demolib.c)
add_library(demo ${DEMOLIB_SRCS})
# The install command below is commented out since the
# target output is packaged via the custom target above
#install(
# TARGETS demo
# ARCHIVE DESTINATION lib
# LIBRARY DESTINATION lib
# COMPONENT demo
# )

# Create demo binary target
set(DEMO_SRCS demo.c)
add_executable(demo_exe ${DEMO_SRCS})
target_link_libraries(demo_exe demo)
# Set the output name since we use the 'demo' target name
# for the library target.
set_target_properties(demo_exe PROPERTIES OUTPUT_NAME demo)
# The install command below is commented out since the
# target output is packaged via the custom target above
#install(
# TARGETS demo_exe
# RUNTIME DESTINATION bin
# COMPONENT demo
# )

set(CPACK_GENERATOR "TGZ")

include(CPack)

关于cmake - CPack打包多包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19698281/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com