CMake rpm 在 /etc/init.d 中安装文件

发布于 2024-12-20 11:49:16 字数 467 浏览 5 评论 0原文

我想安装一个文件 /etc/init.d 目录

我已经编写了代码,

INSTALL(FILES  ${CMAKE_SOURCE_DIR}/app/script/appd  DESTINATION /etc/init.d/appd)

但是当我使用 cmake 运行打包代码时出现错误

CMake Error at /home/vivek/workspace/app/build/standalone/cmake_install.cmake:54 (FILE):
  file cannot create directory: /etc/init.d/appd.  Maybe need
  administrative privileges.

How can I set cmake to install a file inside /etc/init.d directory ?

I want to install a file in
/etc/init.d directory

I have written code

INSTALL(FILES  ${CMAKE_SOURCE_DIR}/app/script/appd  DESTINATION /etc/init.d/appd)

but when I run packing code using cmake I get error

CMake Error at /home/vivek/workspace/app/build/standalone/cmake_install.cmake:54 (FILE):
  file cannot create directory: /etc/init.d/appd.  Maybe need
  administrative privileges.

How can I set cmake to install a file inside /etc/init.d directory ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吝吻 2024-12-27 11:49:16

您可以执行此操作,但您可能需要

set(CPACK_SET_DESTDIR ON)

显式设置: before:

include(CPack)

在 CMakeLists.txt 文件中 。 (您只需要对 CMake/CPack 上 2.8.3 之前的旧版本执行此操作)

您需要执行此操作的原因是您将完整路径名指定为已安装文件之一的 DESTINATION。为了在打包阶段正确执行此操作,CPack 需要在其“make install”调用中使用 DESTDIR 环境变量。

出于向后兼容性的原因,我们默认情况下不会自动执行此操作。

但是,这个错误在版本 2.8.3 中得到了修复,以便可以通过使用完整路径名的安装规则透明且自动地完成:

http://public.kitware.com/Bug/view.php?id=7000

希望您可以对 rpm 软件包使用 CPACK_SET_DESTDIR 为 ON,或者使用包含自动修复的更新版本的 CMake/CPack。

You can do this, but you may need to explicitly set:

set(CPACK_SET_DESTDIR ON)

prior to:

include(CPack)

in your CMakeLists.txt file. (You will need to do this only for older versions on CMake/CPack, prior to 2.8.3)

The reason you need to do this is that you are specifying a full path name as the DESTINATION of one of your installed files. In order to do that properly in the packing phase, CPack needs to use a DESTDIR environment variable in its "make install" call.

We didn't do this automatically by default for backwards compatibility reasons.

But then, this bug was fixed in version 2.8.3 so that it could be done transparently and automatically with install rules that use full path names:

http://public.kitware.com/Bug/view.php?id=7000

Hopefully, you can use either CPACK_SET_DESTDIR to ON for your rpm packages, OR use a more recent version of CMake/CPack that includes the automatic fix.

残花月 2024-12-27 11:49:16

你不能。您唯一能做的就是要求用户使用管理权限为您的应用运行 make install

另外,您可以尝试检测 sudo 命令和 add_custom_command() 的存在,这将使用 sudo 安装您的文件。

You can't. Only thing you can do is to ask user to run make install for your app with administrative priveleges.

Also, you can try detecting presense of sudo command and add_custom_command() which would install your files with sudo.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文