[CMake] Colored diagnostic output for GCC 4.9 through Ninja

Robert Dailey rcdailey.lists at gmail.com
Wed Oct 28 12:52:53 EDT 2015


On Wed, Oct 28, 2015 at 11:20 AM, Robert Dailey
<rcdailey.lists at gmail.com> wrote:
> On Wed, Oct 28, 2015 at 11:19 AM, Robert Dailey
> <rcdailey.lists at gmail.com> wrote:
>> On Wed, Oct 28, 2015 at 9:03 AM, Miller Henry <MillerHenry at johndeere.com> wrote:
>>>
>>> I do something like this, which works for clang and should work for gcc 4.9 though I haven't tested it.   I haven't wrote the right way to do this which is to check if the terminal supports color before passing the flag in. I don't know what will happen on our e.g. CI system which doesn't support color.
>>>
>>> macro(AddCXXFlagIfSupported flag test)
>>>    CHECK_CXX_COMPILER_FLAG(${flag} ${test})
>>>    if( ${${test}} )
>>>       message("adding ${flag}")
>>>       set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
>>>    endif()
>>> endmacro()
>>>
>>> if("Ninja" STREQUAL ${CMAKE_GENERATOR})
>>>    AddCXXFlagIfSupported(-fcolor-diagnostics COMPILER_SUPPORTS_fcolor-diagnostics)
>>> endif()
>>>
>>> P.s. AddCXXFlagIfSupported ought to be in the default cmake distribution along with a lot or similar things
>>
>> Unfortunately your solution doesn't seem to work. I get the following output:
>>
>> [1/1] Re-running CMake...
>> -- Performing Test COMPILER_SUPPORTS_fcolor-diagnostics
>> -- Performing Test COMPILER_SUPPORTS_fcolor-diagnostics - Failed
>>
>> GCC 4.9 supports this I thought?
>
> I found the issue, the flag is diagnostics-color, not color-diagnostics.


Actually, even after getting this working, I still get no color output. :-(


More information about the CMake mailing list