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>
This commit is contained in:
Rafael Kitover 2019-03-26 00:35:23 +00:00
parent 23fe13d8fb
commit ae38a70d1e
No known key found for this signature in database
GPG Key ID: 08AB596679D86240
2 changed files with 33 additions and 8 deletions

View File

@ -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)

View File

@ -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)