Make CMake use gccfilter

此生再无相见时 提交于 2019-12-03 00:46:56
sakra

You can make CMake use gccfilter by pointing the RULE_LAUNCH_COMPILE property to a wrapper script which invokes gccfilter with the desired options.

Create an executable shell script named gccfilter_wrap in the outermost CMake project directory with the following contents:

#!/bin/sh
exec gccfilter -a -c "$@"

Be sure to set the file's executable bit. Then in your 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)

The generated makefile rules will then prefix each compiler invocation with the gccfilter_wrap script. Alternatively the RULE_LAUNCH_COMPILE property can also be set as a target property or as global property.

The RULE_LAUNCH_COMPILE property only works for Makefile-based CMake generators.


Edit by Thilo

This is how I finally solved the problem - basically a rephrased version of this solution:

# 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()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!