From 884d9de8b7d7201a4461711335ac10aae743777d Mon Sep 17 00:00:00 2001 From: Semyon Kolton Date: Tue, 15 Feb 2022 18:17:24 +0300 Subject: color: Introduce CMAKE_COLOR_DIAGNOSTICS variable Add a variable to control both makefile color messages and compiler color diagnostics. Fixes: #15502 --- Auxiliary/vim/syntax/cmake.vim | 1 + Help/manual/cmake-variables.7.rst | 1 + Help/release/dev/color-diagnostics.rst | 7 +++++++ Help/variable/CMAKE_COLOR_DIAGNOSTICS.rst | 35 +++++++++++++++++++++++++++++++ Modules/CMakeGenericSystem.cmake | 7 ++++--- Modules/Compiler/Clang.cmake | 6 ++++++ Modules/Compiler/GNU.cmake | 7 +++++++ Source/cmGhsMultiTargetGenerator.cxx | 1 + Source/cmLocalGenerator.cxx | 24 +++++++++++++++++++++ Source/cmLocalGenerator.h | 1 + Source/cmLocalUnixMakefileGenerator3.cxx | 6 +++++- 11 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 Help/release/dev/color-diagnostics.rst create mode 100644 Help/variable/CMAKE_COLOR_DIAGNOSTICS.rst 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 -Xclang -include -Xclang ) set(CMAKE_${lang}_COMPILE_OPTIONS_CREATE_PCH -Xclang -emit-pch -Xclang -include -Xclang -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 ) set(CMAKE_${lang}_COMPILE_OPTIONS_CREATE_PCH -x ${__pch_header_${lang}} -include ) 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> 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 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"); -- cgit v0.12 From 78adb1b952d92608e8de708084c8cdac69286616 Mon Sep 17 00:00:00 2001 From: Semyon Kolton Date: Wed, 16 Feb 2022 12:01:55 +0300 Subject: color: Add CMAKE_COLOR_DIAGNOSTICS environment variable --- Help/envvar/CMAKE_COLOR_DIAGNOSTICS.rst | 9 +++++++++ Help/manual/cmake-env-variables.7.rst | 1 + Help/release/dev/color-diagnostics.rst | 3 +++ Help/variable/CMAKE_COLOR_DIAGNOSTICS.rst | 4 +++- Modules/CMakeGenericSystem.cmake | 4 ++++ 5 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 Help/envvar/CMAKE_COLOR_DIAGNOSTICS.rst diff --git a/Help/envvar/CMAKE_COLOR_DIAGNOSTICS.rst b/Help/envvar/CMAKE_COLOR_DIAGNOSTICS.rst new file mode 100644 index 0000000..d3d0aa9 --- /dev/null +++ b/Help/envvar/CMAKE_COLOR_DIAGNOSTICS.rst @@ -0,0 +1,9 @@ +CMAKE_COLOR_DIAGNOSTICS +----------------------- + +.. versionadded:: 3.24 + +.. include:: ENV_VAR.txt + +Specifies a default value for the :variable:`CMAKE_COLOR_DIAGNOSTICS` variable +when there is no explicit value given on the first run. diff --git a/Help/manual/cmake-env-variables.7.rst b/Help/manual/cmake-env-variables.7.rst index 0799fdd..fc14262 100644 --- a/Help/manual/cmake-env-variables.7.rst +++ b/Help/manual/cmake-env-variables.7.rst @@ -31,6 +31,7 @@ Environment Variables that Control the Build /envvar/CMAKE_APPLE_SILICON_PROCESSOR /envvar/CMAKE_BUILD_PARALLEL_LEVEL /envvar/CMAKE_BUILD_TYPE + /envvar/CMAKE_COLOR_DIAGNOSTICS /envvar/CMAKE_CONFIGURATION_TYPES /envvar/CMAKE_CONFIG_TYPE /envvar/CMAKE_EXPORT_COMPILE_COMMANDS diff --git a/Help/release/dev/color-diagnostics.rst b/Help/release/dev/color-diagnostics.rst index 7f64ba3..8e0e225 100644 --- a/Help/release/dev/color-diagnostics.rst +++ b/Help/release/dev/color-diagnostics.rst @@ -5,3 +5,6 @@ color-diagnostics color diagnostics generated by compilers. This variable also controls color buildsystem messages with :ref:`Makefile Generators`, replacing :variable:`CMAKE_COLOR_MAKEFILE`. + + The :envvar:`CMAKE_COLOR_DIAGNOSTICS` environment was added to set + a default value for :variable:`CMAKE_COLOR_DIAGNOSTICS`. diff --git a/Help/variable/CMAKE_COLOR_DIAGNOSTICS.rst b/Help/variable/CMAKE_COLOR_DIAGNOSTICS.rst index 805467a..a72c9e1 100644 --- a/Help/variable/CMAKE_COLOR_DIAGNOSTICS.rst +++ b/Help/variable/CMAKE_COLOR_DIAGNOSTICS.rst @@ -32,4 +32,6 @@ When ``OFF``: * GNU/Clang compilers are invoked with a flag disabling color diagnostics (``-fno-color-diagnostics``). -``CMAKE_COLOR_DIAGNOSTICS`` is not defined by default. +If the :envvar:`CMAKE_COLOR_DIAGNOSTICS` environment variable is set, its +value is used. Otherwise, ``CMAKE_COLOR_DIAGNOSTICS`` is not defined by +default. diff --git a/Modules/CMakeGenericSystem.cmake b/Modules/CMakeGenericSystem.cmake index e54a028..cb105ed 100644 --- a/Modules/CMakeGenericSystem.cmake +++ b/Modules/CMakeGenericSystem.cmake @@ -47,6 +47,10 @@ 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(DEFINED ENV{CMAKE_COLOR_DIAGNOSTICS} AND NOT DEFINED CACHE{CMAKE_COLOR_DIAGNOSTICS}) + set(CMAKE_COLOR_DIAGNOSTICS $ENV{CMAKE_COLOR_DIAGNOSTICS} CACHE BOOL "Enable colored diagnostics throughout.") +endif() + if(CMAKE_GENERATOR MATCHES "Make") if(NOT DEFINED CMAKE_COLOR_DIAGNOSTICS) set(CMAKE_COLOR_MAKEFILE ON CACHE BOOL "Enable/Disable color output during build.") -- cgit v0.12 From 6ab9fbd43bfce25cf9ee71a81145a1e5f9dc4a12 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 8 Mar 2022 16:59:51 -0500 Subject: color: Add tests for CMAKE_COLOR_DIAGNOSTICS --- Tests/RunCMake/CMakeLists.txt | 3 +++ Tests/RunCMake/Color/CMakeLists.txt | 3 +++ Tests/RunCMake/Color/DiagCommon.cmake | 9 ++++++++ Tests/RunCMake/Color/DiagDefault.cmake | 8 +++++++ Tests/RunCMake/Color/DiagOff.cmake | 6 +++++ Tests/RunCMake/Color/DiagOn.cmake | 6 +++++ Tests/RunCMake/Color/RunCMakeTest.cmake | 14 ++++++++++++ Tests/RunCMake/Color/diag.c | 28 ++++++++++++++++++++++++ Tests/RunCMake/CommandLine/EnvColorDefault.cmake | 6 +++++ Tests/RunCMake/CommandLine/EnvColorOn-stdout.txt | 1 + Tests/RunCMake/CommandLine/EnvColorOn.cmake | 4 ++++ Tests/RunCMake/CommandLine/RunCMakeTest.cmake | 8 +++++++ 12 files changed, 96 insertions(+) create mode 100644 Tests/RunCMake/Color/CMakeLists.txt create mode 100644 Tests/RunCMake/Color/DiagCommon.cmake create mode 100644 Tests/RunCMake/Color/DiagDefault.cmake create mode 100644 Tests/RunCMake/Color/DiagOff.cmake create mode 100644 Tests/RunCMake/Color/DiagOn.cmake create mode 100644 Tests/RunCMake/Color/RunCMakeTest.cmake create mode 100644 Tests/RunCMake/Color/diag.c create mode 100644 Tests/RunCMake/CommandLine/EnvColorDefault.cmake create mode 100644 Tests/RunCMake/CommandLine/EnvColorOn-stdout.txt create mode 100644 Tests/RunCMake/CommandLine/EnvColorOn.cmake diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 652ea5c..7fc1aff 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -278,6 +278,9 @@ endif() add_RunCMake_test(CMakeDependentOption) add_RunCMake_test(CMakeRoleGlobalProperty) add_RunCMake_test(CMakeRelease -DCMake_TEST_JQ=${CMake_TEST_JQ}) +if(CMAKE_GENERATOR MATCHES "Make|Ninja") + add_RunCMake_test(Color) +endif() if(UNIX AND "${CMAKE_GENERATOR}" MATCHES "Unix Makefiles|Ninja") add_RunCMake_test(CompilerChange) endif() diff --git a/Tests/RunCMake/Color/CMakeLists.txt b/Tests/RunCMake/Color/CMakeLists.txt new file mode 100644 index 0000000..5ff8d3e --- /dev/null +++ b/Tests/RunCMake/Color/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.23) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/Color/DiagCommon.cmake b/Tests/RunCMake/Color/DiagCommon.cmake new file mode 100644 index 0000000..9a69317 --- /dev/null +++ b/Tests/RunCMake/Color/DiagCommon.cmake @@ -0,0 +1,9 @@ +enable_language(C) + +set(CMAKE_C_COMPILE_OPTIONS_COLOR_DIAGNOSTICS -DCOLOR_ON) +set(CMAKE_C_COMPILE_OPTIONS_COLOR_DIAGNOSTICS_OFF -DCOLOR_OFF) + +add_library(diag STATIC diag.c) +if(DEFINED EXPECT_COLOR) + target_compile_definitions(diag PRIVATE EXPECT_COLOR=${EXPECT_COLOR}) +endif() diff --git a/Tests/RunCMake/Color/DiagDefault.cmake b/Tests/RunCMake/Color/DiagDefault.cmake new file mode 100644 index 0000000..5add9dc --- /dev/null +++ b/Tests/RunCMake/Color/DiagDefault.cmake @@ -0,0 +1,8 @@ +include(DiagCommon.cmake) + +if(DEFINED CMAKE_COLOR_DIAGNOSTICS) + message(FATAL_ERROR "CMAKE_COLOR_DIAGNOSTICS incorrectly defined.") +endif() +if(CMAKE_GENERATOR MATCHES "Make" AND NOT DEFINED CMAKE_COLOR_MAKEFILE) + message(FATAL_ERROR "CMAKE_COLOR_MAKEFILE incorrectly not defined.") +endif() diff --git a/Tests/RunCMake/Color/DiagOff.cmake b/Tests/RunCMake/Color/DiagOff.cmake new file mode 100644 index 0000000..56657b0 --- /dev/null +++ b/Tests/RunCMake/Color/DiagOff.cmake @@ -0,0 +1,6 @@ +set(EXPECT_COLOR 0) +include(DiagCommon.cmake) + +if(DEFINED CMAKE_COLOR_MAKEFILE) + message(FATAL_ERROR "CMAKE_COLOR_MAKEFILE incorrectly defined.") +endif() diff --git a/Tests/RunCMake/Color/DiagOn.cmake b/Tests/RunCMake/Color/DiagOn.cmake new file mode 100644 index 0000000..fbb6c70 --- /dev/null +++ b/Tests/RunCMake/Color/DiagOn.cmake @@ -0,0 +1,6 @@ +set(EXPECT_COLOR 1) +include(DiagCommon.cmake) + +if(DEFINED CMAKE_COLOR_MAKEFILE) + message(FATAL_ERROR "CMAKE_COLOR_MAKEFILE incorrectly defined.") +endif() diff --git a/Tests/RunCMake/Color/RunCMakeTest.cmake b/Tests/RunCMake/Color/RunCMakeTest.cmake new file mode 100644 index 0000000..bb62d4c --- /dev/null +++ b/Tests/RunCMake/Color/RunCMakeTest.cmake @@ -0,0 +1,14 @@ +include(RunCMake) + +unset(ENV{CMAKE_COLOR_DIAGNOSTICS}) + +function(run_Diag case) + set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/Diag${case}-build") + run_cmake_with_options(Diag${case} ${ARGN}) + set(RunCMake_TEST_NO_CLEAN 1) + run_cmake_command(Diag${case}-build ${CMAKE_COMMAND} --build . --config Debug) +endfunction() + +run_Diag(On -DCMAKE_COLOR_DIAGNOSTICS=ON) +run_Diag(Off -DCMAKE_COLOR_DIAGNOSTICS=OFF) +run_Diag(Default) diff --git a/Tests/RunCMake/Color/diag.c b/Tests/RunCMake/Color/diag.c new file mode 100644 index 0000000..7ff8304 --- /dev/null +++ b/Tests/RunCMake/Color/diag.c @@ -0,0 +1,28 @@ +#ifdef EXPECT_COLOR +# if EXPECT_COLOR +# ifndef COLOR_ON +# error "COLOR_ON incorrectly not defined" +# endif +# ifdef COLOR_OFF +# error "COLOR_OFF incorrectly defined" +# endif +# else +# ifdef COLOR_ON +# error "COLOR_ON incorrectly defined" +# endif +# ifndef COLOR_OFF +# error "COLOR_OFF incorrectly not defined" +# endif +# endif +#else +# ifdef COLOR_ON +# error "COLOR_ON incorrectly defined" +# endif +# ifdef COLOR_OFF +# error "COLOR_OFF incorrectly defined" +# endif +#endif + +void diag(void) +{ +} diff --git a/Tests/RunCMake/CommandLine/EnvColorDefault.cmake b/Tests/RunCMake/CommandLine/EnvColorDefault.cmake new file mode 100644 index 0000000..dc4bc98 --- /dev/null +++ b/Tests/RunCMake/CommandLine/EnvColorDefault.cmake @@ -0,0 +1,6 @@ +if(DEFINED CMAKE_COLOR_DIAGNOSTICS) + message(FATAL_ERROR "CMAKE_COLOR_DIAGNOSTICS incorrectly defined.") +endif() +if(CMAKE_GENERATOR MATCHES "Make" AND NOT DEFINED CMAKE_COLOR_MAKEFILE) + message(FATAL_ERROR "CMAKE_COLOR_MAKEFILE incorrectly not defined.") +endif() diff --git a/Tests/RunCMake/CommandLine/EnvColorOn-stdout.txt b/Tests/RunCMake/CommandLine/EnvColorOn-stdout.txt new file mode 100644 index 0000000..885925e --- /dev/null +++ b/Tests/RunCMake/CommandLine/EnvColorOn-stdout.txt @@ -0,0 +1 @@ +-- CMAKE_COLOR_DIAGNOSTICS='ON' diff --git a/Tests/RunCMake/CommandLine/EnvColorOn.cmake b/Tests/RunCMake/CommandLine/EnvColorOn.cmake new file mode 100644 index 0000000..af1235d --- /dev/null +++ b/Tests/RunCMake/CommandLine/EnvColorOn.cmake @@ -0,0 +1,4 @@ +message(STATUS "CMAKE_COLOR_DIAGNOSTICS='${CMAKE_COLOR_DIAGNOSTICS}'") +if(DEFINED CMAKE_COLOR_MAKEFILE) + message(FATAL_ERROR "CMAKE_COLOR_MAKEFILE incorrectly defined.") +endif() diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index 50815a8..ef56ded 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -416,6 +416,14 @@ function(run_EnvironmentToolchain) endfunction() run_EnvironmentToolchain() +function(run_EnvironmentColor) + set(ENV{CMAKE_COLOR_DIAGNOSTICS} "ON") + run_cmake(EnvColorOn) + unset(ENV{CMAKE_COLOR_DIAGNOSTICS}) + run_cmake(EnvColorDefault) +endfunction() +run_EnvironmentColor() + if(RunCMake_GENERATOR STREQUAL "Ninja") # Use a single build tree for a few tests without cleaning. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Build-build) -- cgit v0.12