使用 CPack 在 Mac 上打包系统守护进程

Packing a system daemon on Mac with CPack

我正在尝试在 Mac 上创建系统范围的服务,使用 CMake 进行构建并使用 CPack 生成包。存储库很大,所以我创建了一个较小的版本来测试它。事实证明,我不知道如何打包具有绝对路径作为目的地的东西。

这是 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

如果我 运行 cpack 作为 root 生成的包是空的。

有人可以告诉我如何解决这个问题吗?

我使用3.13.0-rc2.

版本的CMake

解决这个问题的关键是将 CMAKE_INSTALL_PREFIX 指定为

set(CMAKE_INSTALL_PREFIX "/")

当你这样做时,你可以将 /var/ 中的路径安装为

install(PROGRAMS <binary>
        DESTINATION "../var")