From ae38a70d1efb71405635fbb9982b3b48671fa4dd Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Tue, 26 Mar 2019 00:35:23 +0000 Subject: [PATCH] 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 --- CMakeLists.txt | 26 +++++++++++++++++++++++--- src/wx/CMakeLists.txt | 15 ++++++++++----- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5275d009..12755e50 100644 --- a/CMakeLists.txt +++ b/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) diff --git a/src/wx/CMakeLists.txt b/src/wx/CMakeLists.txt index fbd99529..9befa5c1 100644 --- a/src/wx/CMakeLists.txt +++ b/src/wx/CMakeLists.txt @@ -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)