使CMake使用gccfilter [英] Make CMake use gccfilter
问题描述
GCCFilter 是一个整洁的perl脚本,它允许对GCC的输出进行着色,从而使调试更加更有趣,更重要,更快。
您可以使用GCCFilter与CMake生成的Makefile,通过调用
gccfilter -a -c make
缺点:CMake状态信息的延迟输出,CMake命令中没有颜色是最明显的。
问题:有没有办法编写一些CMake模块, gccfilter
如果编译器 gcc
,检查 COLOR_CXX
设置(很容易到这里),然后告诉CMake将 gcc
替换为 gccfilter -a -c gcc
。
CMake提供变量 在最外层的CMake项目目录中创建名为 确保设置文件的可执行位。然后在 生成的makefile规则会在每个编译器调用之前 这是我终于解决了问题 - 基本上是这个解决方案的改写版本: GCCFilter is a neat perl script that allows to color the output of GCC and thus makes debugging much more fun and, more important, faster. You can use GCCFilter with a CMake generated Makefile by calling However, this approach has some drawbacks: Delayed output of CMake status infos, no color in the CMake commands are the most obvious. The question: Is there a way to write some CMake module that searches for CMake offers the variable You can make CMake use Create an executable shell script named Be sure to set the file's executable bit. Then in your The generated makefile rules will then prefix each compiler invocation with the The This is how I finally solved the problem - basically a rephrased version of this solution:
这篇关于使CMake使用gccfilter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! CMAKE_CXX_COMPILER
,但更改此变量将不允许CMake找到正确的包含路径等。在每次调用 gcc
之前加上 project()
命令之前是否有一些变量?您可以通过指向 gccfilter c>使用 gccfilter
,使CMake使用
gccfilter $ c的包装脚本中
gccfilter_wrap
的可执行shell脚本以下内容:
#!/ bin / sh
exec gccfilter -a -c$ @
CMakeLists.txt
中,在添加目标之前设置 RULE_LAUNCH_COMPILE
目录属性:
project(HelloWorld)
set_directory_properties(PROPERTIES RULE_LAUNCH_COMPILE
$ {PROJECT_SOURCE_DIR} / gccfilter_wrap)
add_executable(HelloWorld HelloWorld.cpp)
gccfilter_wrap
脚本。或者,也可以将 RULE_LAUNCH_COMPILE
属性设置为目标属性或全局属性。
RULE_LAUNCH_COMPILE
属性仅适用于基于Makefile的CMake生成器。
/ h2>
code>#GCCFilter,如果适用
if(CMAKE_COMPILER_IS_GNUCXX或CMAKE_COMPILER_IS_GNUCPP)
选项(COLOR_GCC使用GCCFilter来编译编译器输出消息ON)
设置(COLOR_GCC_OPTIONS-c -r -wCACHE STRING当输出着色被切换时传递给gccfilter的参数默认为-c -r -w。)
if(COLOR_GCC)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE$ { PROJECT_SOURCE_DIR} / cmake / gccfilter $ {COLOR_GCC_OPTIONS})
endif()
endif()
gccfilter -a -c make
gccfilter
if the compiler is gcc
, checks if, say COLOR_CXX
is set (rather easy up to here) and then tells CMake to replace all calls to gcc
by gccfilter -a -c gcc
. CMAKE_CXX_COMPILER
, but changing this one will disallow CMake to find correct include paths and the like. Is there some variable we may change after the project()
command that is prefixed before each call to gcc
?gccfilter
by pointing the RULE_LAUNCH_COMPILE property to a wrapper script which invokes gccfilter
with the desired options.gccfilter_wrap
in the outermost CMake project directory with the following contents:#!/bin/sh
exec gccfilter -a -c "$@"
CMakeLists.txt
, set the RULE_LAUNCH_COMPILE
directory property before adding targets:project (HelloWorld)
set_directory_properties(PROPERTIES RULE_LAUNCH_COMPILE
"${PROJECT_SOURCE_DIR}/gccfilter_wrap")
add_executable(HelloWorld HelloWorld.cpp)
gccfilter_wrap
script. Alternatively the RULE_LAUNCH_COMPILE
property can also be set as a target property or as global property.RULE_LAUNCH_COMPILE
property only works for Makefile-based CMake generators.
Edit by Thilo
# GCCFilter, if appliciable
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_GNUCPP)
option(COLOR_GCC "Use GCCFilter to color compiler output messages" ON)
set(COLOR_GCC_OPTIONS "-c -r -w" CACHE STRING "Arguments that are passed to gccfilter when output coloring is switchend on. Defaults to -c -r -w.")
if(COLOR_GCC)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${PROJECT_SOURCE_DIR}/cmake/gccfilter ${COLOR_GCC_OPTIONS}")
endif()
endif()