gpt4 book ai didi

cmake - 如何使用CMake安装脚本?

转载 作者:行者123 更新时间:2023-12-04 22:41:41 27 4
gpt4 key购买 nike

我有一个构建多个可执行文件并安装它们的项目。对于可执行文件,相关的CMake代码为:

add_executable(foo "foo.cpp")
add_executable(bar "bar.cpp;qux.cpp")
install(TARGETS foo bar "/usr/bin")

然后,我创建一个.deb软件包,并在安装时可以从命令行运行 foobar。我想做这样的事情:
add_executable(foo "foo.cpp")
add_executable(bar "bar.cpp;qux.cpp")
add_script(hello "hello.sh")
install(TARGETS foo bar hello)

...以便 hello可从命令行执行。但是实际上并没有一个名为 add_script的CMake命令。我怎样才能做到这一点?

最佳答案

您可以使用

install(PROGRAMS hello.sh DESTINATION bin RENAME hello)

这将自动使您的脚本可执行。参见 the docs for install(FILES):

The PROGRAMS form is identical to the FILES form except that the default permissions for the installed file also include OWNER_EXECUTE, GROUP_EXECUTE, and WORLD_EXECUTE. This form is intended to install programs that are not targets, such as shell scripts.

关于cmake - 如何使用CMake安装脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46002990/

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