Add cmake option for colored gcc >= 4.9 output #378

Merged
merged 3 commits into from Jun 14, 2016

Conversation

Projects
None yet
3 participants
@jakobj
Contributor

jakobj commented May 31, 2016

This PR adds and option for cmake that enables colored output of errors and warnings. works fine with gcc >= 4.9. Is is maybe necessary to prevent this from being set when using an incompatible compiler? If so, whats the best way to do this? I propose @tammoippen and @apeyser as reviewers.

cmake/ProcessOptions.cmake
+# add colored output from gcc
+if ( with-color )
+ if ( with-color STREQUAL "ON" )
+ set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=auto" )

This comment has been minimized.

@tammoippen

tammoippen Jun 1, 2016

Contributor

This is a GCC specific option, that is only fully supported for GCC >= 4.9. Older versions might choke:

g++-4.8 -fdiagnostics-color=auto -Wall -pedantic -c ...
g++-4.8: error: unrecognized command line option '-fdiagnostics-color=auto'

I would recommend to not have this as a user option, but always enable it, if possible (colors are cool and useful during coding), e.g. like this:

if ( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
  if ( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9")
    set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=auto" )
  endif ()
endif ()

And also do not forget to add the option for the C compiler (the checks are similar):

set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdiagnostics-color=auto" )
@tammoippen

tammoippen Jun 1, 2016

Contributor

This is a GCC specific option, that is only fully supported for GCC >= 4.9. Older versions might choke:

g++-4.8 -fdiagnostics-color=auto -Wall -pedantic -c ...
g++-4.8: error: unrecognized command line option '-fdiagnostics-color=auto'

I would recommend to not have this as a user option, but always enable it, if possible (colors are cool and useful during coding), e.g. like this:

if ( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
  if ( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9")
    set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=auto" )
  endif ()
endif ()

And also do not forget to add the option for the C compiler (the checks are similar):

set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdiagnostics-color=auto" )
Always enable gcc color output if possible
cmake now checks the compiler id and version and enables colored output
of warnings and errors if the compiler allows is (gcc >= 4.9). added flag also to cflags.
@jakobj

This comment has been minimized.

Show comment
Hide comment
@jakobj

jakobj Jun 3, 2016

Contributor

included @tammoippen's suggestions. thanks!

Contributor

jakobj commented Jun 3, 2016

included @tammoippen's suggestions. thanks!

@tammoippen

This comment has been minimized.

Show comment
Hide comment
@tammoippen

tammoippen Jun 9, 2016

Contributor

👍 from my side.

Contributor

tammoippen commented Jun 9, 2016

👍 from my side.

@heplesser

This comment has been minimized.

Show comment
Hide comment
@heplesser

heplesser Jun 10, 2016

Contributor

@jakobj Would you merge the latest changes from master, so that Travis can test properly, now that #391 is merged?

Contributor

heplesser commented Jun 10, 2016

@jakobj Would you merge the latest changes from master, so that Travis can test properly, now that #391 is merged?

@heplesser

This comment has been minimized.

Show comment
Hide comment
@heplesser

heplesser Jun 14, 2016

Contributor

👍 and merging!

Contributor

heplesser commented Jun 14, 2016

👍 and merging!

@heplesser heplesser merged commit a541cc3 into nest:master Jun 14, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment