本文介绍了如何添加取决于“ make install”的add_custom_target;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加一个名为 package的自定义目标,该目标取决于安装目标。
当我运行 make软件包时,它应该导致首先运行 make install ,然后运行我的自定义命令创建一个包。

I'd like to add a custom target named "package" which depends on install target.When I run make package it should cause first running make install and after that, running my custom command to create a package.

我尝试了以下 DEPENDS安装,但是它不起作用。

I have tried the following DEPENDS install but it does not work.

我收到错误消息:没有规则将目标 CMakeFiles / install.dir / all 设为目标, CMakeFiles / package.dir / all

I get error message: No rule to make target CMakeFiles/install.dir/all, needed by CMakeFiles/package.dir/all

install(FILES
        "module/module.pexe"
        "module/module.nmf"
        DESTINATION "./extension")

add_custom_target(package
    COMMAND "chromium-browser" "--pack-extension=./extension"
    DEPENDS install)

编辑::我尝试了 DEPENDS安装关键字和 add_dependencies(软件包安装),但它们都不起作用。

I tried DEPENDS install keyword and add_dependencies(package install) but neither of them works.

根据
无法将依赖项添加到诸如 install 之类的内置目标中或 test

According to http://public.kitware.com/Bug/view.php?id=8438it is not possible to add dependencies to built-in targets like install or test

推荐答案

您可以创建自定义目标,该目标将运行install和其他一些脚本

You can create custom target which will run install and some other script after.

例如,如果您有CMake脚本 MyScript。 cmake

For instance if you have a CMake script MyScript.cmake:

add_custom_target(
    MyInstall
    COMMAND
    "${CMAKE_COMMAND}" --build . --target install
    COMMAND
    "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_LIST_DIR}/MyScript.cmake"
    WORKING_DIRECTORY
    "${CMAKE_BINARY_DIR}"
)

您可以通过构建目标 MyInstall :

cmake --build /path/to/build/directory --target MyInstall



Python脚本



当然,您可以使用任何脚本语言。只要记住要对其他平台
保持礼貌(因此编写bash脚本可能是一个坏主意,因为它在Windows上不起作用)。

Python script

Of course you can use any scripting language. Just remember to be polite to other platforms(so probably it's a bad idea to write bash script, it will not work on windows).

例如python脚本 MyScript.py

For example python script MyScript.py:

find_package(PythonInterp 3.2 REQUIRED)

add_custom_target(
    MyInstall
    COMMAND
    "${CMAKE_COMMAND}" --build . --target install
    COMMAND
    "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_LIST_DIR}/MyScript.py"
    WORKING_DIRECTORY
    "${CMAKE_BINARY_DIR}"
)

这篇关于如何添加取决于“ make install”的add_custom_target;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 05:53