您可以使用 CMakegccfilter
通过指向规则_启动_编译 http://www.cmake.org/cmake/help/v2.8.10/cmake.html#prop_dir:RULE_LAUNCH_COMPILE属性到调用的包装器脚本gccfilter
与所需的选项。
创建一个名为的可执行 shell 脚本gccfilter_wrap
在最外层的CMake项目目录中包含以下内容:
#!/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)
然后,生成的 makefile 规则将为每个编译器调用添加前缀gccfilter_wrap
脚本。或者,RULE_LAUNCH_COMPILE
property 还可以设置为目标属性或全局属性。
The RULE_LAUNCH_COMPILE
属性仅适用于基于 Makefile 的 CMake 生成器。
蒂洛编辑
这就是我最终解决问题的方法 - 基本上是该解决方案的改写版本:
# 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()