gpt4 book ai didi

cmake - cpack 组件级安装

转载 作者:行者123 更新时间:2023-12-01 21:12:18 25 4
gpt4 key购买 nike

对于附加到 CMake wiki 的示例 CMakeLists.txt。我还在下面添加了实际的 make 命令来创建基于组件的 TGZ。我很困惑,在文档中没有看到任何帮助。

CMakeLists.txt

cmake_minimum_required(VERSION 2.6.0 FATAL_ERROR)
project(MyLib)

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Install path prefix prepended on to install directories." FORCE)
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)

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")


add_library(mylib mylib.cpp)

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

install(TARGETS mylib
ARCHIVE
DESTINATION lib
COMPONENT libraries)
install(TARGETS mylibapp
RUNTIME
DESTINATION bin
COMPONENT applications)
install(FILES mylib.h
DESTINATION include
COMPONENT headers)

set(CPACK_COMPONENTS_ALL applications libraries headers)

set(CPACK_COMPONENT_APPLICATIONS_DISPLAY_NAME "MyLib Application")
set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ Headers")

set(CPACK_COMPONENT_APPLICATIONS_DESCRIPTION
"An extremely useful application that makes use of MyLib")
set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION
"Static libraries used to build programs with MyLib")
set(CPACK_COMPONENT_HEADERS_DESCRIPTION
"C/C++ header files for use with MyLib")


set(CPACK_GENERATOR "TGZ")
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
set(CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY OFF)
set(CPACK_SET_DESTDIR ON)
set(CPACK_PACKAGE_CONTACT "jhf")

# This must always be last!
include(CPack)

我有一个类似的 CMakeLists.txt,当我这样做时 make package ,我最终在 TGZ 中获得了我所有的二进制文件和库。如果我只需要一个带有上述 CMakeLists.txt 应用程序组件的 TGZ,那么 make package 命令应该是什么?

最佳答案

很简单。
只需将 CMAKE 变量 CPACK_COMPONENTS_ALL 设置为要出现在安装中的组件列表:

SET(CPACK_COMPONENTS_ALL applications) #only pack "applications" component

关于cmake - cpack 组件级安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16663955/

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