为什么 include(CPack) 应该在每个项目包配置之后?
Why should include(CPack) go after the per project package configuration?
我正在试验 CMake
的 CPack
模块,结果有些混乱。我有 CpackMylib.cmake
包含在根 CMakeLists.txt
中。看起来如下:
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
。当你 include
它在你的 CMakeLists.txt
中时,它会读取 its documentation 中列出的所有变量,如 CPACK_GENERATOR
或 CPACK_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.
...
我正在试验 CMake
的 CPack
模块,结果有些混乱。我有 CpackMylib.cmake
包含在根 CMakeLists.txt
中。看起来如下:
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
。当你 include
它在你的 CMakeLists.txt
中时,它会读取 its documentation 中列出的所有变量,如 CPACK_GENERATOR
或 CPACK_PACKAGE_NAME
并创建 package
目标你然后用 make package
.
如果您在设置这些变量之前包含它,它们的值将被忽略。
Before including this
CPack
module in yourCMakeLists.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....