是否可以将安装后命令添加到由cmake生成的顶级Makefile? [英] Is it possible to add post-install commands to top level Makefile generated by cmake?

查看:294
本文介绍了是否可以将安装后命令添加到由cmake生成的顶级Makefile?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

cmake会为安装规则生成类似以下内容:

 #目标安装的特殊规则
install :preinstall
@ $(CMAKE_COMMAND)-E cmake_echo_color --switch = $(COLOR)--cyan安装项目...
/ usr / local / bin / cmake -P cmake_install.cmake
.PHONY:install


$ b $ p

我想要做的是在cmake_install后执行一些自定义命令.cmake被调用,因此它看起来像:

 #目标安装的特殊规则
install:preinstall
@ $(CMAKE_COMMAND)-E cmake_echo_color --switch = $(COLOR)--cyan安装项目...
/ usr / local / bin / cmake -P cmake_install.cmake
post_install_command_1
...
post_install_command_n
.PHONY:install

我可以做我想要使用add_custom_command(TARGET ... POST_BUILD ...)对于我们写的东西(6 - 10宏要更新)。但是,有一些第三方的东西,安装,我真的不想为所有的人添加POST_BUILD自定义命令(目前有19个项目有更多的,很难确定需要处理什么后建成而不是安装后)。我认为如果自定义命令只在一个地方使用(即作为安装处理的最后一部分),并且我知道他们将做所有必要的事情,那么维护会更容易。



有可能让cmake向顶层Makefile的安装规则添加命令吗?

解决方案

使用 SCRIPT 或 CODE /help/cmake-2-8-docs.html#command%3ainstall\">install 命令。如果您将必需的命令放在项目根目录中的脚本 PostInstall.cmake 中,请将以下调用添加到您最外面的 CMakeLists.txt

  install(SCRIPT$ {CMAKE_SOURCE_DIR} /PostInstall.cmake)

install 命令添加到 cmake_install.cmake 脚本,因此调用应该添加到 CMakeLists.txt 的结尾,以便在所有其他安装完成后运行。 / p>

cmake generates something like the following for the install rule:

# Special rule for the target install
install: preinstall
        @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
        /usr/local/bin/cmake -P cmake_install.cmake
.PHONY : install

What I want to do is have some custom commands executed after cmake_install.cmake is invoked so it looks something like:

# Special rule for the target install
install: preinstall
        @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
        /usr/local/bin/cmake -P cmake_install.cmake
        post_install_command_1
        ...
        post_install_command_n
.PHONY : install

I can do what I want using "add_custom_command(TARGET ... POST_BUILD ...)" for things that we have written (6 - 10 macros to update). However, there are a bunch of third-party things that get installed and I really don't want to add POST_BUILD custom commands for all of them (currently 19 projects with more to come and it can be tough to identify what needs to be processed after building instead of after installing). I think it would be much easier to maintain if the custom commands are only used in one place (i.e. as last part of install handling) and where I know they will do everything that is necessary.

Is it possible to get cmake to add commands to the top-level Makefile's install rule?

解决方案

You can use the SCRIPT or CODE variant of the install command. If you put the required commands in a script PostInstall.cmake in the project root directory, add the following call to your outermost CMakeLists.txt:

install (SCRIPT "${CMAKE_SOURCE_DIR}/PostInstall.cmake")

install commands are added to the cmake_install.cmake script in order, thus the call should be added to the end of the CMakeLists.txt to have it run after all other installations have completed.

这篇关于是否可以将安装后命令添加到由cmake生成的顶级Makefile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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