我正在尝试使用CMake进行构建并使用CPack生成软件包在Mac上创建系统范围的服务。存储库很大,因此我创建了一个较小的版本进行测试。事实证明,我不知道如何打包以绝对路径为目的地的东西。
这是CMake代码:
install(PROGRAMS ${CMAKE_BINARY_DIR}/hello
DESTINATION "/var/local/hello"
COMPONENT TS
)
install(PROGRAMS com.hello.world.plist
DESTINATION "/Library/LaunchDaemons/"
COMPONENT TS
)
这是cpack的输出
mac-mini-2:build melanoholly$ cpack ..
CPack: Create package using productbuild
CPack: Install projects
CPack: - Run preinstall target for: testingPack
CPack: - Install project: testingPack
CMake Error at /Users/salvobit/sandbox/cpack-example-mac-daemon/build/cmake_install.cmake:44 (file):
file cannot create directory: /var/local/hello. Maybe need administrative
privileges.
CMake Error at /Users/salvobit/sandbox/cpack-example-mac-daemon/build/cmake_install.cmake:56 (file):
file INSTALL cannot copy file
"/Users/salvobit/sandbox/cpack-example-mac-daemon/com.hello.world.plist" to
"/Library/LaunchDaemons/com.hello.world.plist".
CPack Error: Error when generating package: testingPack
如果我以root身份运行cpack
,则生成的包为空。
有人可以给我和想法解决这个问题吗?
我使用版本为 3.13.0-rc2 的CMake。
答案 0 :(得分:0)
解决此问题的关键是将CMAKE_INSTALL_PREFIX
指定为
set(CMAKE_INSTALL_PREFIX "/")
当您这样做时,可以将路径/var/
安装为
install(PROGRAMS <binary>
DESTINATION "../var")