summaryrefslogtreecommitdiffstats
path: root/Source/cmake.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2006-04-27 01:31:39 (GMT)
committerBrad King <brad.king@kitware.com>2006-04-27 01:31:39 (GMT)
commit4494c29078d60618b2addb00b4e2bb02e3a2729b (patch)
tree7fc6a35ba1fa1899bbf2d8887662d26d388c7ed0 /Source/cmake.cxx
parent92ea0a077cc7f1be8caf9b38937cf5b6b02d15eb (diff)
downloadCMake-4494c29078d60618b2addb00b4e2bb02e3a2729b.zip
CMake-4494c29078d60618b2addb00b4e2bb02e3a2729b.tar.gz
CMake-4494c29078d60618b2addb00b4e2bb02e3a2729b.tar.bz2
ENH: Enabling color makefile support using cmsysTerminal_cfprintf. Support for color is automatically detected when messages are printed. Also made color scheme more readable on both black and white backgrounds. This option can be enabled by setting CMAKE_COLOR_MAKEFILE to true in the project.
Diffstat (limited to 'Source/cmake.cxx')
-rw-r--r--Source/cmake.cxx113
1 files changed, 113 insertions, 0 deletions
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 2c08ae3..a67ab15 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -24,6 +24,8 @@
#include "cmFileTimeComparison.h"
#include "cmGeneratedFileStream.h"
+#include <cmsys/Terminal.h>
+
#if defined(CMAKE_BUILD_WITH_CMAKE)
# include "cmDependsFortran.h" // For -E cmake_copy_f90_mod callback.
# include "cmVariableWatch.h"
@@ -1005,6 +1007,12 @@ int cmake::ExecuteCMakeCommand(std::vector<std::string>& args)
return 1;
}
+ // Internal CMake color makefile support.
+ else if (args[1] == "cmake_echo_color" )
+ {
+ return cmake::ExecuteEchoColor(args);
+ }
+
// Tar files
else if (args[1] == "tar" && args.size() > 3)
{
@@ -2344,3 +2352,108 @@ void cmake::GenerateGraphViz(const char* fileName)
str << "}" << std::endl;
}
+//----------------------------------------------------------------------------
+int cmake::ExecuteEchoColor(std::vector<std::string>& args)
+{
+ // The arguments are
+ // argv[0] == <cmake-executable>
+ // argv[1] == cmake_echo_color
+
+ // On some platforms (an MSYS prompt) cmsysTerminal may not be able
+ // to determine whether the stream is displayed on a tty. In this
+ // case it assumes no unless we tell it otherwise. Since we want
+ // color messages to be displayed for users we will assume yes.
+ // However, we can test for some situations when the answer is most
+ // likely no.
+ int assumeTTY = cmsysTerminal_Color_AssumeTTY;
+ if(cmSystemTools::GetEnv("DART_TEST_FROM_DART") ||
+ cmSystemTools::GetEnv("DASHBOARD_TEST_FROM_CTEST"))
+ {
+ // Avoid printing color escapes during dashboard builds.
+ assumeTTY = 0;
+ }
+
+ bool enabled = true;
+ int color = cmsysTerminal_Color_Normal;
+ bool newline = true;
+ for(unsigned int i=2; i < args.size(); ++i)
+ {
+ if(args[i].find("--switch=") == 0)
+ {
+ // Enable or disable color based on the switch value.
+ std::string value = args[i].substr(9);
+ if(!value.empty())
+ {
+ if(cmSystemTools::IsOn(value.c_str()))
+ {
+ enabled = true;
+ }
+ else
+ {
+ enabled = false;
+ }
+ }
+ }
+ else if(args[i] == "--normal")
+ {
+ color = cmsysTerminal_Color_Normal;
+ }
+ else if(args[i] == "--black")
+ {
+ color = cmsysTerminal_Color_ForegroundBlack;
+ }
+ else if(args[i] == "--red")
+ {
+ color = cmsysTerminal_Color_ForegroundRed;
+ }
+ else if(args[i] == "--green")
+ {
+ color = cmsysTerminal_Color_ForegroundGreen;
+ }
+ else if(args[i] == "--yellow")
+ {
+ color = cmsysTerminal_Color_ForegroundYellow;
+ }
+ else if(args[i] == "--blue")
+ {
+ color = cmsysTerminal_Color_ForegroundBlue;
+ }
+ else if(args[i] == "--magenta")
+ {
+ color = cmsysTerminal_Color_ForegroundMagenta;
+ }
+ else if(args[i] == "--cyan")
+ {
+ color = cmsysTerminal_Color_ForegroundCyan;
+ }
+ else if(args[i] == "--white")
+ {
+ color = cmsysTerminal_Color_ForegroundWhite;
+ }
+ else if(args[i] == "--bold")
+ {
+ color |= cmsysTerminal_Color_ForegroundBold;
+ }
+ else if(args[i] == "--no-newline")
+ {
+ newline = false;
+ }
+ else if(args[i] == "--newline")
+ {
+ newline = true;
+ }
+ else if(enabled)
+ {
+ // Color is enabled. Print with the current color.
+ cmsysTerminal_cfprintf(color | assumeTTY, stdout, "%s%s",
+ args[i].c_str(), newline? "\n" : "");
+ }
+ else
+ {
+ // Color is disabled. Print without color.
+ fprintf(stdout, "%s%s", args[i].c_str(), newline? "\n" : "");
+ }
+ }
+
+ return 0;
+}