CMake可以通过另一个程序过滤编译器输出 [英] CMake can I filter compiler output through another program
问题描述
我可以告诉CMake通过外部程序管道编译器和/或链接器的所有stderr输出,并显示在终端上的输出?
对于Makefile生成器,您可以通过为编译规则设置自定义启动器来对编译器输出应用过滤器。以下CMake列表文件描绘了必要的步骤:
cmake_minimum_required(VERSION 2.8)
pre>
project )
configure_file(
$ {PROJECT_SOURCE_DIR} /gcc_filter.sh.in
$ {PROJECT_BINARY_DIR} /gcc_filter.sh
@ONLY)
add_executable(Main Main.cpp)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE$ {PROJECT_BINARY_DIR} /gcc_filter.sh)
在项目根目录中添加以下shell脚本模板文件
gcc_filter.sh.in
:#!/ bin / sh
使用以下参数调用shell脚本
#$ CXX)$(CXX_DEFINES)$(CXX_FLAGS)-o OBJECT_FILE -c SOURCE_FILE
#调用编译器
exec$ @2& @ PROJECT_SOURCE_DIR @ / myfilter.sh
自定义启动程序规则调用的实际shell脚本是第一个使用CMake列表文件中的
configure_file
调用复制到项目二进制目录。必须设置文件gcc_filter.sh.in
的可执行位。 shell脚本将所有参数转发给编译器,然后将编译器输出管道到项目根目录中的另一个shell脚本myfilter.sh
:#!/ bin / sh
exec wc
b $ b示例
myfilter.sh
只是调用wc
,但更复杂的输出过滤上面的食谱。Can I tell CMake to pipe all stderr output from the compiler and/or linker through an external program and showing the output of that on the terminal instead?
解决方案For Makefile generators you can apply a filter to the compiler output by setting a custom launcher for compile rules. The following CMake list file sketches the necessary steps:
cmake_minimum_required(VERSION 2.8) project (Main) configure_file( "${PROJECT_SOURCE_DIR}/gcc_filter.sh.in" "${PROJECT_BINARY_DIR}/gcc_filter.sh" @ONLY) add_executable (Main Main.cpp) set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${PROJECT_BINARY_DIR}/gcc_filter.sh")
In the project root directory add the following shell script template file
gcc_filter.sh.in
:#!/bin/sh # shell script invoked with the following arguments # $(CXX) $(CXX_DEFINES) $(CXX_FLAGS) -o OBJECT_FILE -c SOURCE_FILE # invoke compiler exec "$@" 2>&1 | "@PROJECT_SOURCE_DIR@/myfilter.sh"
The actual shell script invoked by the custom launcher rule is first copied to the project binary directory with the
configure_file
call in the CMake list file. The executable bit of the filegcc_filter.sh.in
must be set. The shell script forwards all arguments to the compiler and then pipes the compiler output to another shell scriptmyfilter.sh
in the project root directory:#!/bin/sh exec wc
The example
myfilter.sh
just invokeswc
but more elaborate output filtering can be easily done using the above recipe.这篇关于CMake可以通过另一个程序过滤编译器输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!