在CMake中生成步骤后运行命令 [英] Run Command after generation step in CMake

查看:785
本文介绍了在CMake中生成步骤后运行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个命令行工具,应在CMake创建我的.sln文件后运行。有什么方法可以使用CMake吗?

I have a command line tool that should be run after CMake created my .sln-file. Is there any way to do that using CMake?

在CMakeLists.txt末尾使用execute_process(COMMAND ..)无济于事,因为这是在Configure之后执行的不过,在生成步骤中会创建.sln文件。

Using execute_process(COMMAND ..) at the end of the CMakeLists.txt does not help because this is executed after the Configure step, however, the .sln-file is created in the generation step.

非常感谢!

推荐答案

一种相当恐怖的方法是通过从cmake调用cmake,并在退出父脚本的过程中进行后生成的东西。

A rather horrifying way to do it is by calling cmake from cmake and doing the post-generate stuff on the way out of the parent script.

option(RECURSIVE_GENERATE "Recursive call to cmake" OFF)

if(NOT RECURSIVE_GENERATE)
    message(STATUS "Recursive generate started")
    execute_process(COMMAND ${CMAKE_COMMAND}
        -G "${CMAKE_GENERATOR}"
        -T "${CMAKE_GENERATOR_TOOLSET}"
        -A "${CMAKE_GENERATOR_PLATFORM}" 
        -DRECURSIVE_GENERATE:BOOL=ON 
        ${CMAKE_SOURCE_DIR})
    message(STATUS "Recursive generate done")

    # your post-generate steps here

    # exit without doing anything else, since it already happened
    return()
endif()

# The rest of the script is only processed by the executed cmake, as it 
# sees RECURSIVE_GENERATE true

# all your normal configuration, targets, etc go here

如果您需要使用命令行选项(例如 -DTHIS -DTHAT)的各种组合来调用cmake,此方法将无法正常工作,但对于许多项目来说可能是可接受的。它与持久缓存的变量(包括所有最初生成的cmake编译器检测)一起正常工作。

This method doesn't work well if you need to invoke cmake with various combinations of command line options like "-DTHIS -DTHAT", but is probably acceptable for many projects. It works fine with the persistently cached variables, including all the cmake compiler detection when they're initially generated.

这篇关于在CMake中生成步骤后运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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