Skip to content
Permalink
Browse files

cmake: gcc/clang colors with ninja, fix warnings

Ninja requires `-fdiagnostics-color=always` instead of
`-fdiagnostics-color=auto` with gcc because it pipes output from the
compiler unlike regular makes.

Use `-fcolor-diagnostics` for clang, which also works correctly with
ninja to show colors.

Information for this taken from here:

https://medium.com/@alasher/colored-c-compiler-output-with-ninja-clang-gcc-10bfe7f2b949

Set all cmake policies in both the root `CMakeLists.txt` and
`src/wx/CMakeLists.txt` to silence warnings about unset policies from
cmake.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
  • Loading branch information...
rkitover committed Mar 26, 2019
1 parent 23fe13d commit ae38a70d1efb71405635fbb9982b3b48671fa4dd
Showing with 33 additions and 8 deletions.
  1. +23 −3 CMakeLists.txt
  2. +10 −5 src/wx/CMakeLists.txt
@@ -1,6 +1,11 @@
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW) # link to full path of libs
cmake_policy(SET CMP0005 NEW) # escapes in add_definitions
cmake_policy(SET CMP0077 NEW) # use vars for options

if(NOT CMAKE_VERSION VERSION_LESS 3.0)
cmake_policy(SET CMP0043 NEW) # for wxWidgets, use generator expressions
endif()
endif()

option(ENABLE_VCPKG "Use dependencies for Visual Studio from vcpkg" ON)
@@ -432,9 +437,24 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL Clang)
set(MY_C_FLAGS ${MY_C_FLAGS} -fopenmp)
endif()

check_cxx_compiler_flag(-fdiagnostics-color=auto COMPILER_COLOR_OUTPUT)
if(COMPILER_COLOR_OUTPUT)
add_compile_options(-fdiagnostics-color=auto)
if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
unset(COMPILER_COLOR_DIAGNOSTICS)
check_cxx_compiler_flag(-fdiagnostics-color=always COMPILER_COLOR_DIAGNOSTICS)
if(COMPILER_COLOR_DIAGNOSTICS)
add_compile_options(-fdiagnostics-color=always)
else()
unset(COMPILER_COLOR_DIAGNOSTICS)
check_cxx_compiler_flag(-fdiagnostics-color COMPILER_COLOR_DIAGNOSTICS)
if(COMPILER_COLOR_DIAGNOSTICS)
add_compile_options(-fdiagnostics-color)
endif()
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL Clang)
unset(COMPILER_COLOR_DIAGNOSTICS)
check_cxx_compiler_flag(-fcolor-diagnostics COMPILER_COLOR_DIAGNOSTICS)
if(COMPILER_COLOR_DIAGNOSTICS)
add_compile_options(-fcolor-diagnostics)
endif()
endif()

if(MINGW)
@@ -1,9 +1,14 @@
#Do not use this file directly. Always use the top level CMakeLists.txt file
# This build is much easier if we just do it here.
# Do not use this file directly. Always use the top level CMakeLists.txt file

IF(NOT CMAKE_VERSION VERSION_LESS 3.0)
cmake_policy(SET CMP0043 NEW) # for wxWidgets
ENDIF()
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW) # link to full path of libs
cmake_policy(SET CMP0005 NEW) # escapes in add_definitions
cmake_policy(SET CMP0077 NEW) # use vars for options

if(NOT CMAKE_VERSION VERSION_LESS 3.0)
cmake_policy(SET CMP0043 NEW) # for wxWidgets, use generator expressions
endif()
endif()

include(VbamFunctions)

0 comments on commit ae38a70

Please sign in to comment.
You can’t perform that action at this time.