使用cmake的预处理器后的自定义构建步骤 [英] custom build step after preprocessor with cmake

查看:284
本文介绍了使用cmake的预处理器后的自定义构建步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用cmake进行预处理后添加自定义构建步骤.

I'm trying to add a custom build step after the preprocessing using cmake.

在c ++预处理程序步骤之后,我想在每个经过预处理的源文件上调用python脚本以对其进行修改. 下面是一个Makefile示例:

After the c++ preprocessor step, I want to call a python script on each preprocessed source files to modify them. Here a Makefile example:

all : prog

#compilation step
prog: main.i
    gcc main.i -g -Wall -o prog 

#custom step
main.i: main.tmp
    ./my_script.py main.tmp > main.i

#only preprocessor step
main.tmp: main.c main.h
    gcc -E main.c > main.tmp

如何使用cmake做到这一点?该步骤应应用于项目的每个c或cpp文件.

how to achieve this with cmake ? The step should be applied on each c or cpp files of the project.

推荐答案

实际上,这必须手动完成: 我在生成预处理文件的位置添加了一个自定义目标:

Indeed, this had to be done manualy : I added a custom target where I generate the preprocessed files:

    add_custom_target(
    start_preprocessor 
    COMMAND make main.cpp.i 
    ..
    )

使用另一个自定义目标,我对main.cpp进行了备份,然后将main.cpp.i重命名为main.cpp.然后,我可以应用我的预处理过程.然后,还原源文件.

with another custom target, I make a backup of main.cpp and then rename main.cpp.i into main.cpp. I can then apply my preprocessing process. Afterwards, I restore the source files.

这篇关于使用cmake的预处理器后的自定义构建步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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