gpt4 book ai didi

c++ - 为什么 include(CPack) 应该在每个项目包配置之后?

转载 作者:行者123 更新时间:2023-11-30 04:48:21 26 4
gpt4 key购买 nike

我正在试验 CMakeCPack 模块,结果有些困惑。我有包含在根 CMakeLists.txt 中的 CpackMylib.cmake。它看起来如下:

include(CPack)             #included on top
install (TARGETS mylib
LIBRARY
DESTINATION /usr/lib
COMPONENT mylib-all
)

install (DIRECTORY include/
DESTINATION /usr/include/mylib
COMPONENT mylib-all)
set(CPACK_PACKAGE_NAME "mylib")
set(CPACK_GENERATOR "DEB")

并且在运行 make package 时,它无法创建具有以下跟踪的包:

Run CPack packaging tool...
CPack: Create package using STGZ
CPack: Install projects
CPack: - Run preinstall target for: mylib
CPack: - Install project: mylib
CMake Error at /home/krjoff/mylib/cmake_install.cmake:55 (file):
file INSTALL cannot copy file "/home/krjoff/mylib/libmylib.so" to
"/usr/lib/mylib.so".


CMake Error at /home/krjoff/mylib/cmake_install.cmake:73 (file):
file INSTALL cannot set permissions on "/usr/include/mylib"


CPack Error: Error when generating package: mylib
Makefile:129: recipe for target 'package' failed
make: *** [package] Error 1

看起来它只是忽略了我放在 include(CPack) 之后的所有变量,并试图构建一些 STGZ 包并立即安装它。但是,如果我在完成所有配置后将 include(CPack) 放在 CpackMylib.cmake 的末尾,它就可以正常工作。

有人可以解释为什么有必要在所有配置设置之后放置 include(CPack) 吗?

最佳答案

CPack 应该是这样工作的。当您在 CMakeLists.txt包含它时,它会读取 its documentation 中列出的所有变量。像 CPACK_GENERATORCPACK_PACKAGE_NAME 并创建 package 目标,然后使用 make package 调用。

如果您在设置这些变量之前包含它,它们的值将被忽略。

Before including this CPack module in your CMakeLists.txt file, there are a variety of variables that can be set to customize the resulting installers. The most commonly-used variables are:

  • CPACK_PACKAGE_NAME
    The name of the package (or application). If not specified, it defaults to the project name.

  • CPACK_PACKAGE_VENDOR
    The name of the package vendor. (e.g., “Kitware”). The default is “Humanity”.

  • CPACK_PACKAGE_DIRECTORY
    The directory in which CPack is doing its packaging. If it is not set then this will default (internally) to the build dir. This variable may be defined in a CPack config file or from the cpack command line option -B. If set, the command line option overrides the value found in the config file.

  • ...

来源:CPack --- CMake

关于c++ - 为什么 include(CPack) 应该在每个项目包配置之后?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55867455/

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