cmake安装目标的运行脚本? [英] cmake run script for install target?

查看:227
本文介绍了cmake安装目标的运行脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,其中安装代码并不像复制某些文件那么简单。使用传统的Makefile,我将创建一个 make install 目标,该目标运行一系列shell命令来执行我需要的操作。

I have a project where "installing" the code is not quite as simple as just copying some files. With a traditional Makefile, I would just create a make install target that runs a series of shell commands to do what I need.

但是谷歌搜索并没有得到这样的例子(有些事情很接近,但是我认为不是。)。因此,基本上,我想要一个自定义命令,该命令取决于目标可执行文件,但不生成任何内容,并且运行不需要移植即可完成安装的脚本

But googling around has resulting in no examples of this (some things close, but not quite... i think). So basically, I want a custom command, that depends on the target executables, but produces nothing and runs a script that need not be portable to accomplish the "install"

任何人有这样的例子吗?

Anyone have any examples of something like this?

推荐答案

CMake的 install 命令允许用于自定义脚本。请参阅官方文档: 安装-自定义安装逻辑

CMake's install command allows for custom scripts. See the official documentation: install - Custom Installation Logic:


install([[SCRIPT <file>] [CODE <code>]]
        [COMPONENT <component>] [...])

SCRIPT表单将在安装过程中调用给定的CMake脚本文件。如果脚本文件名是相对路径,则将相对于当前源目录进行解释。 CODE表单将在安装过程中调用给定的CMake代码。将代码指定为双引号字符串内的单个参数。例如,代码

The SCRIPT form will invoke the given CMake script files during installation. If the script file name is a relative path it will be interpreted with respect to the current source directory. The CODE form will invoke the given CMake code during installation. Code is specified as a single argument inside a double-quoted string. For example, the code

install(CODE "MESSAGE(\"Sample install message.\")")

将在安装过程中显示一条消息。

will print a message during installation.

要运行自定义外壳脚本(或任何程序),请将 install(CODE ...) execute_process

To run custom shell script (or whatever program), combine install(CODE ...) with execute_process:

install(CODE "execute_process(COMMAND my_script.sh)")

这篇关于cmake安装目标的运行脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆