summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Auxiliary/vim/syntax/cmake.vim1
-rw-r--r--Help/manual/cmake-variables.7.rst1
-rw-r--r--Help/release/dev/color-diagnostics.rst7
-rw-r--r--Help/variable/CMAKE_COLOR_DIAGNOSTICS.rst35
-rw-r--r--Modules/CMakeGenericSystem.cmake7
-rw-r--r--Modules/Compiler/Clang.cmake6
-rw-r--r--Modules/Compiler/GNU.cmake7
-rw-r--r--Source/cmGhsMultiTargetGenerator.cxx1
-rw-r--r--Source/cmLocalGenerator.cxx24
-rw-r--r--Source/cmLocalGenerator.h1
-rw-r--r--Source/cmLocalUnixMakefileGenerator3.cxx6
11 files changed, 92 insertions, 4 deletions
diff --git a/Auxiliary/vim/syntax/cmake.vim b/Auxiliary/vim/syntax/cmake.vim
index 381d97c..703144b 100644
--- a/Auxiliary/vim/syntax/cmake.vim
+++ b/Auxiliary/vim/syntax/cmake.vim
@@ -705,6 +705,7 @@ syn keyword cmakeVariable contained
\ CMAKE_CODEBLOCKS_COMPILER_ID
\ CMAKE_CODEBLOCKS_EXCLUDE_EXTERNAL_FILES
\ CMAKE_CODELITE_USE_TARGETS
+ \ CMAKE_COLOR_DIAGNOSTICS
\ CMAKE_COLOR_MAKEFILE
\ CMAKE_COMMAND
\ CMAKE_COMPILER_2005
diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst
index 86e4d4c..5f56f0d 100644
--- a/Help/manual/cmake-variables.7.rst
+++ b/Help/manual/cmake-variables.7.rst
@@ -172,6 +172,7 @@ Variables that Change Behavior
/variable/CMAKE_CODEBLOCKS_COMPILER_ID
/variable/CMAKE_CODEBLOCKS_EXCLUDE_EXTERNAL_FILES
/variable/CMAKE_CODELITE_USE_TARGETS
+ /variable/CMAKE_COLOR_DIAGNOSTICS
/variable/CMAKE_COLOR_MAKEFILE
/variable/CMAKE_CONFIGURATION_TYPES
/variable/CMAKE_DEPENDS_IN_PROJECT_ONLY
diff --git a/Help/release/dev/color-diagnostics.rst b/Help/release/dev/color-diagnostics.rst
new file mode 100644
index 0000000..7f64ba3
--- /dev/null
+++ b/Help/release/dev/color-diagnostics.rst
@@ -0,0 +1,7 @@
+color-diagnostics
+-----------------
+
+* The :variable:`CMAKE_COLOR_DIAGNOSTICS` variable was added to control
+ color diagnostics generated by compilers. This variable also controls
+ color buildsystem messages with :ref:`Makefile Generators`, replacing
+ :variable:`CMAKE_COLOR_MAKEFILE`.
diff --git a/Help/variable/CMAKE_COLOR_DIAGNOSTICS.rst b/Help/variable/CMAKE_COLOR_DIAGNOSTICS.rst
new file mode 100644
index 0000000..805467a
--- /dev/null
+++ b/Help/variable/CMAKE_COLOR_DIAGNOSTICS.rst
@@ -0,0 +1,35 @@
+CMAKE_COLOR_DIAGNOSTICS
+-----------------------
+
+.. versionadded:: 3.24
+
+Enable color diagnostics throughout.
+
+This variable uses three states: ``ON``, ``OFF`` and not defined.
+
+When not defined:
+
+* :ref:`Makefile Generators` initialize the :variable:`CMAKE_COLOR_MAKEFILE`
+ variable to ``ON``. It controls color buildsystem messages.
+
+* GNU/Clang compilers are not invoked with any color diagnostics flag.
+
+When ``ON``:
+
+* :ref:`Makefile Generators` produce color buildsystem messages by default.
+ :variable:`CMAKE_COLOR_MAKEFILE` is not initialized, but may be
+ explicitly set to ``OFF`` to disable color buildsystem messages.
+
+* GNU/Clang compilers are invoked with a flag enabling color diagnostics
+ (``-fcolor-diagnostics``).
+
+When ``OFF``:
+
+* :ref:`Makefile Generators` do not produce color buildsystem messages by
+ default. :variable:`CMAKE_COLOR_MAKEFILE` is not initialized, but may be
+ explicitly set to ``ON`` to enable color buildsystem messages.
+
+* GNU/Clang compilers are invoked with a flag disabling color diagnostics
+ (``-fno-color-diagnostics``).
+
+``CMAKE_COLOR_DIAGNOSTICS`` is not defined by default.
diff --git a/Modules/CMakeGenericSystem.cmake b/Modules/CMakeGenericSystem.cmake
index 9ae68c4..e54a028 100644
--- a/Modules/CMakeGenericSystem.cmake
+++ b/Modules/CMakeGenericSystem.cmake
@@ -48,10 +48,11 @@ set (CMAKE_SKIP_INSTALL_RPATH "NO" CACHE BOOL
set(CMAKE_VERBOSE_MAKEFILE FALSE CACHE BOOL "If this value is on, makefiles will be generated without the .SILENT directive, and all commands will be echoed to the console during the make. This is useful for debugging only. With Visual Studio IDE projects all commands are done without /nologo.")
if(CMAKE_GENERATOR MATCHES "Make")
- set(CMAKE_COLOR_MAKEFILE ON CACHE BOOL
- "Enable/Disable color output during build."
- )
+ if(NOT DEFINED CMAKE_COLOR_DIAGNOSTICS)
+ set(CMAKE_COLOR_MAKEFILE ON CACHE BOOL "Enable/Disable color output during build.")
+ endif()
mark_as_advanced(CMAKE_COLOR_MAKEFILE)
+
if(DEFINED CMAKE_RULE_MESSAGES)
set_property(GLOBAL PROPERTY RULE_MESSAGES ${CMAKE_RULE_MESSAGES})
endif()
diff --git a/Modules/Compiler/Clang.cmake b/Modules/Compiler/Clang.cmake
index f885eb0..df115d3 100644
--- a/Modules/Compiler/Clang.cmake
+++ b/Modules/Compiler/Clang.cmake
@@ -114,6 +114,12 @@ else()
endif()
set(CMAKE_${lang}_COMPILE_OPTIONS_USE_PCH -Xclang -include-pch -Xclang <PCH_FILE> -Xclang -include -Xclang <PCH_HEADER>)
set(CMAKE_${lang}_COMPILE_OPTIONS_CREATE_PCH -Xclang -emit-pch -Xclang -include -Xclang <PCH_HEADER> -x ${__pch_header_${lang}})
+
+ # '-fcolor-diagnostics' introduced since Clang 2.6
+ if(CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL 2.6)
+ set(CMAKE_${lang}_COMPILE_OPTIONS_COLOR_DIAGNOSTICS "-fcolor-diagnostics")
+ set(CMAKE_${lang}_COMPILE_OPTIONS_COLOR_DIAGNOSTICS_OFF "-fno-color-diagnostics")
+ endif()
endmacro()
endif()
diff --git a/Modules/Compiler/GNU.cmake b/Modules/Compiler/GNU.cmake
index 928e726..2eef532 100644
--- a/Modules/Compiler/GNU.cmake
+++ b/Modules/Compiler/GNU.cmake
@@ -119,4 +119,11 @@ macro(__compiler_gnu lang)
set(CMAKE_${lang}_COMPILE_OPTIONS_USE_PCH -include <PCH_HEADER>)
set(CMAKE_${lang}_COMPILE_OPTIONS_CREATE_PCH -x ${__pch_header_${lang}} -include <PCH_HEADER>)
endif()
+
+ # '-fdiagnostics-color=always' introduced since GCC 4.9
+ # https://gcc.gnu.org/gcc-4.9/changes.html
+ if(CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL 4.9)
+ set(CMAKE_${lang}_COMPILE_OPTIONS_COLOR_DIAGNOSTICS "-fdiagnostics-color=always")
+ set(CMAKE_${lang}_COMPILE_OPTIONS_COLOR_DIAGNOSTICS_OFF "-fno-diagnostics-color")
+ endif()
endmacro()
diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx
index 47cefae..85ce57f 100644
--- a/Source/cmGhsMultiTargetGenerator.cxx
+++ b/Source/cmGhsMultiTargetGenerator.cxx
@@ -187,6 +187,7 @@ void cmGhsMultiTargetGenerator::SetCompilerFlags(std::string const& config,
language, config);
this->LocalGenerator->AddVisibilityPresetFlags(
flags, this->GeneratorTarget, language);
+ this->LocalGenerator->AddColorDiagnosticsFlags(flags, language);
// Append old-style preprocessor definition flags.
if (this->Makefile->GetDefineFlags() != " ") {
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 3976c42..4fa7d4f 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -1609,6 +1609,7 @@ std::vector<BT<std::string>> cmLocalGenerator::GetTargetCompileFlags(
this->AddCMP0018Flags(compileFlags, target, lang, config);
this->AddVisibilityPresetFlags(compileFlags, target, lang);
+ this->AddColorDiagnosticsFlags(compileFlags, lang);
this->AppendFlags(compileFlags, mf->GetDefineFlags());
this->AppendFlags(compileFlags,
this->GetFrameworkFlags(lang, config, target));
@@ -2354,6 +2355,29 @@ void cmLocalGenerator::AddPositionIndependentFlags(std::string& flags,
}
}
+void cmLocalGenerator::AddColorDiagnosticsFlags(std::string& flags,
+ const std::string& lang)
+{
+ cmValue diag = this->Makefile->GetDefinition("CMAKE_COLOR_DIAGNOSTICS");
+ if (diag.IsSet()) {
+ std::string colorFlagName;
+ if (diag.IsOn()) {
+ colorFlagName =
+ cmStrCat("CMAKE_", lang, "_COMPILE_OPTIONS_COLOR_DIAGNOSTICS");
+ } else {
+ colorFlagName =
+ cmStrCat("CMAKE_", lang, "_COMPILE_OPTIONS_COLOR_DIAGNOSTICS_OFF");
+ }
+
+ std::vector<std::string> options;
+ this->Makefile->GetDefExpandList(colorFlagName, options);
+
+ for (std::string const& option : options) {
+ this->AppendFlagEscape(flags, option);
+ }
+ }
+}
+
void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
const std::string& var,
const std::string& config)
diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h
index 115a54a..436a29e 100644
--- a/Source/cmLocalGenerator.h
+++ b/Source/cmLocalGenerator.h
@@ -159,6 +159,7 @@ public:
cmGeneratorTarget const* target,
const std::string& lang,
const std::string& config);
+ void AddColorDiagnosticsFlags(std::string& flags, const std::string& lang);
//! Append flags to a string.
virtual void AppendFlags(std::string& flags,
const std::string& newFlags) const;
diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx
index 0f8cdca..ca5d41c 100644
--- a/Source/cmLocalUnixMakefileGenerator3.cxx
+++ b/Source/cmLocalUnixMakefileGenerator3.cxx
@@ -133,7 +133,11 @@ void cmLocalUnixMakefileGenerator3::Generate()
// Record whether some options are enabled to avoid checking many
// times later.
if (!this->GetGlobalGenerator()->GetCMakeInstance()->GetIsInTryCompile()) {
- this->ColorMakefile = this->Makefile->IsOn("CMAKE_COLOR_MAKEFILE");
+ if (this->Makefile->IsSet("CMAKE_COLOR_MAKEFILE")) {
+ this->ColorMakefile = this->Makefile->IsOn("CMAKE_COLOR_MAKEFILE");
+ } else {
+ this->ColorMakefile = this->Makefile->IsOn("CMAKE_COLOR_DIAGNOSTICS");
+ }
}
this->SkipPreprocessedSourceRules =
this->Makefile->IsOn("CMAKE_SKIP_PREPROCESSED_SOURCE_RULES");