summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2006-04-26 21:31:39 -0400
committerBrad King <brad.king@kitware.com>2006-04-26 21:31:39 -0400
commit4494c29078d60618b2addb00b4e2bb02e3a2729b (patch)
tree7fc6a35ba1fa1899bbf2d8887662d26d388c7ed0
parent92ea0a077cc7f1be8caf9b38937cf5b6b02d15eb (diff)
downloadcmake-4494c29078d60618b2addb00b4e2bb02e3a2729b.tar.gz
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.
-rw-r--r--Source/cmGlobalBorlandMakefileGenerator.cxx2
-rw-r--r--Source/cmGlobalGenerator.cxx2
-rw-r--r--Source/cmGlobalGenerator.h4
-rw-r--r--Source/cmGlobalKdevelopGenerator.cxx2
-rw-r--r--Source/cmGlobalMSYSMakefileGenerator.cxx2
-rw-r--r--Source/cmGlobalMinGWMakefileGenerator.cxx2
-rw-r--r--Source/cmGlobalNMakeMakefileGenerator.cxx2
-rw-r--r--Source/cmGlobalUnixMakefileGenerator3.cxx2
-rw-r--r--Source/cmGlobalWatcomWMakeGenerator.cxx2
-rw-r--r--Source/cmLocalUnixMakefileGenerator3.cxx65
-rw-r--r--Source/cmake.cxx113
-rw-r--r--Source/cmake.h2
12 files changed, 153 insertions, 47 deletions
diff --git a/Source/cmGlobalBorlandMakefileGenerator.cxx b/Source/cmGlobalBorlandMakefileGenerator.cxx
index e33c5185bb..b1efb700c8 100644
--- a/Source/cmGlobalBorlandMakefileGenerator.cxx
+++ b/Source/cmGlobalBorlandMakefileGenerator.cxx
@@ -24,7 +24,7 @@ cmGlobalBorlandMakefileGenerator::cmGlobalBorlandMakefileGenerator()
this->EmptyRuleHackDepends = "NUL";
this->FindMakeProgramFile = "CMakeBorlandFindMake.cmake";
this->ForceUnixPaths = false;
- this->ToolSupportsColorVT100 = false;
+ this->ToolSupportsColor = true;
}
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index c151ea4d45..3e46a48f7c 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -35,7 +35,7 @@ cmGlobalGenerator::cmGlobalGenerator()
this->ForceUnixPaths = false;
// By default do not try to support color.
- this->ToolSupportsColorVT100 = false;
+ this->ToolSupportsColor = false;
}
cmGlobalGenerator::~cmGlobalGenerator()
diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h
index 93251075c9..e8f2634341 100644
--- a/Source/cmGlobalGenerator.h
+++ b/Source/cmGlobalGenerator.h
@@ -127,7 +127,7 @@ public:
static int s_TryCompileTimeout;
bool GetForceUnixPaths() {return this->ForceUnixPaths;}
- bool GetToolSupportsColorVT100() { return this->ToolSupportsColorVT100; }
+ bool GetToolSupportsColor() { return this->ToolSupportsColor; }
///! return the language for the given extension
const char* GetLanguageFromExtension(const char* ext);
///! is an extension to be ignored
@@ -204,7 +204,7 @@ protected:
std::vector<std::string> depends, bool depends_on_all = false);
bool ForceUnixPaths;
- bool ToolSupportsColorVT100;
+ bool ToolSupportsColor;
cmStdString FindMakeProgramFile;
cmStdString ConfiguredFilesPath;
cmake *CMakeInstance;
diff --git a/Source/cmGlobalKdevelopGenerator.cxx b/Source/cmGlobalKdevelopGenerator.cxx
index 388ed135f0..43d64dc5fc 100644
--- a/Source/cmGlobalKdevelopGenerator.cxx
+++ b/Source/cmGlobalKdevelopGenerator.cxx
@@ -28,7 +28,7 @@ cmGlobalKdevelopGenerator::cmGlobalKdevelopGenerator()
// This type of makefile always requires unix style paths
this->ForceUnixPaths = true;
this->FindMakeProgramFile = "CMakeUnixFindMake.cmake";
- this->ToolSupportsColorVT100 = false;
+ this->ToolSupportsColor = false;
}
///! Create a local generator appropriate to this Global Generator
diff --git a/Source/cmGlobalMSYSMakefileGenerator.cxx b/Source/cmGlobalMSYSMakefileGenerator.cxx
index a94a1b5e96..98862df5f5 100644
--- a/Source/cmGlobalMSYSMakefileGenerator.cxx
+++ b/Source/cmGlobalMSYSMakefileGenerator.cxx
@@ -23,7 +23,7 @@ cmGlobalMSYSMakefileGenerator::cmGlobalMSYSMakefileGenerator()
{
this->FindMakeProgramFile = "CMakeMSYSFindMake.cmake";
this->ForceUnixPaths = true;
- this->ToolSupportsColorVT100 = true;
+ this->ToolSupportsColor = true;
}
std::string
diff --git a/Source/cmGlobalMinGWMakefileGenerator.cxx b/Source/cmGlobalMinGWMakefileGenerator.cxx
index e924ca040a..5ede97841f 100644
--- a/Source/cmGlobalMinGWMakefileGenerator.cxx
+++ b/Source/cmGlobalMinGWMakefileGenerator.cxx
@@ -22,7 +22,7 @@ cmGlobalMinGWMakefileGenerator::cmGlobalMinGWMakefileGenerator()
{
this->FindMakeProgramFile = "CMakeMinGWFindMake.cmake";
this->ForceUnixPaths = true;
- this->ToolSupportsColorVT100 = false;
+ this->ToolSupportsColor = true;
}
void cmGlobalMinGWMakefileGenerator::EnableLanguage(std::vector<std::string>const& l,
diff --git a/Source/cmGlobalNMakeMakefileGenerator.cxx b/Source/cmGlobalNMakeMakefileGenerator.cxx
index bd9952b299..3784a80f1b 100644
--- a/Source/cmGlobalNMakeMakefileGenerator.cxx
+++ b/Source/cmGlobalNMakeMakefileGenerator.cxx
@@ -22,7 +22,7 @@ cmGlobalNMakeMakefileGenerator::cmGlobalNMakeMakefileGenerator()
{
this->FindMakeProgramFile = "CMakeNMakeFindMake.cmake";
this->ForceUnixPaths = false;
- this->ToolSupportsColorVT100 = false;
+ this->ToolSupportsColor = true;
}
void cmGlobalNMakeMakefileGenerator::EnableLanguage(std::vector<std::string>const& l,
diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx
index 4efebaaf77..1a922935ef 100644
--- a/Source/cmGlobalUnixMakefileGenerator3.cxx
+++ b/Source/cmGlobalUnixMakefileGenerator3.cxx
@@ -26,7 +26,7 @@ cmGlobalUnixMakefileGenerator3::cmGlobalUnixMakefileGenerator3()
// This type of makefile always requires unix style paths
this->ForceUnixPaths = true;
this->FindMakeProgramFile = "CMakeUnixFindMake.cmake";
- this->ToolSupportsColorVT100 = true;
+ this->ToolSupportsColor = true;
}
void cmGlobalUnixMakefileGenerator3
diff --git a/Source/cmGlobalWatcomWMakeGenerator.cxx b/Source/cmGlobalWatcomWMakeGenerator.cxx
index a040484378..3e19c9e30f 100644
--- a/Source/cmGlobalWatcomWMakeGenerator.cxx
+++ b/Source/cmGlobalWatcomWMakeGenerator.cxx
@@ -22,7 +22,7 @@ cmGlobalWatcomWMakeGenerator::cmGlobalWatcomWMakeGenerator()
{
this->FindMakeProgramFile = "CMakeFindWMake.cmake";
this->ForceUnixPaths = false;
- this->ToolSupportsColorVT100 = false;
+ this->ToolSupportsColor = true;
this->EmptyCommandsHack = "@cd .";
}
diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx
index c62fa5a390..6b93a1d4e5 100644
--- a/Source/cmLocalUnixMakefileGenerator3.cxx
+++ b/Source/cmLocalUnixMakefileGenerator3.cxx
@@ -35,28 +35,6 @@
#include <memory> // auto_ptr
#include <queue>
-#define CMAKE_VT100_NORMAL "\33[0m"
-#define CMAKE_VT100_BOLD "\33[1m"
-#define CMAKE_VT100_UNDERLINE "\33[4m"
-#define CMAKE_VT100_BLINK "\33[5m"
-#define CMAKE_VT100_INVERSE "\33[7m"
-#define CMAKE_VT100_FRONT_BLACK "\33[30m"
-#define CMAKE_VT100_FRONT_RED "\33[31m"
-#define CMAKE_VT100_FRONT_GREEN "\33[32m"
-#define CMAKE_VT100_FRONT_YELLOW "\33[33m"
-#define CMAKE_VT100_FRONT_BLUE "\33[34m"
-#define CMAKE_VT100_FRONT_MAGENTA "\33[35m"
-#define CMAKE_VT100_FRONT_CYAN "\33[36m"
-#define CMAKE_VT100_FRONT_WHITE "\33[37m"
-#define CMAKE_VT100_BACK_BLACK "\33[40m"
-#define CMAKE_VT100_BACK_RED "\33[41m"
-#define CMAKE_VT100_BACK_GREEN "\33[42m"
-#define CMAKE_VT100_BACK_YELLOW "\33[43m"
-#define CMAKE_VT100_BACK_BLUE "\33[44m"
-#define CMAKE_VT100_BACK_MAGENTA "\33[45m"
-#define CMAKE_VT100_BACK_CYAN "\33[46m"
-#define CMAKE_VT100_BACK_WHITE "\33[47m"
-
//----------------------------------------------------------------------------
cmLocalUnixMakefileGenerator3::cmLocalUnixMakefileGenerator3()
{
@@ -876,32 +854,33 @@ cmLocalUnixMakefileGenerator3::AppendEcho(std::vector<std::string>& commands,
EchoColor color)
{
// Choose the color for the text.
- std::string prefix;
- if(this->GlobalGenerator->GetToolSupportsColorVT100() &&
+ std::string color_name;
+ if(this->GlobalGenerator->GetToolSupportsColor() &&
this->Makefile->IsOn("CMAKE_COLOR_MAKEFILE"))
{
+ // See cmake::ExecuteEchoColor in cmake.cxx for these options.
+ // This color set is readable on both black and white backgrounds.
switch(color)
{
case EchoNormal:
break;
case EchoDepend:
- prefix = CMAKE_VT100_FRONT_MAGENTA;
+ color_name = "--magenta --bold ";
break;
case EchoBuild:
- prefix = CMAKE_VT100_FRONT_GREEN;
+ color_name = "--green ";
break;
case EchoLink:
- prefix = CMAKE_VT100_FRONT_RED;
+ color_name = "--red --bold ";
break;
case EchoGenerate:
- prefix = CMAKE_VT100_FRONT_BLUE;
+ color_name = "--blue --bold ";
break;
case EchoGlobal:
- prefix = CMAKE_VT100_FRONT_CYAN;
+ color_name = "--cyan ";
break;
}
}
- std::string suffix = prefix.empty()? "" : CMAKE_VT100_NORMAL;
// Echo one line at a time.
std::string line;
@@ -914,16 +893,28 @@ cmLocalUnixMakefileGenerator3::AppendEcho(std::vector<std::string>& commands,
if(*c != '\0' || !line.empty())
{
// Add a command to echo this line.
- std::string cmd = "@echo ";
- if(this->EchoNeedsQuote)
+ std::string cmd;
+ if(color_name.empty())
{
- cmd += "\"";
+ // Use the native echo command.
+ cmd = "@echo ";
+ if(this->EchoNeedsQuote)
+ {
+ cmd += "\"";
+ }
+ cmd += line;
+ if(this->EchoNeedsQuote)
+ {
+ cmd += "\"";
+ }
}
- cmd += prefix;
- cmd += line;
- cmd += suffix;
- if(this->EchoNeedsQuote)
+ else
{
+ // Use cmake to echo the text in color.
+ cmd = "@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) ";
+ cmd += color_name;
+ cmd += "\"";
+ cmd += line;
cmd += "\"";
}
commands.push_back(cmd);
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 2c08ae3043..a67ab15538 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;
+}
diff --git a/Source/cmake.h b/Source/cmake.h
index ca3e0bcfbf..18d2587b8a 100644
--- a/Source/cmake.h
+++ b/Source/cmake.h
@@ -315,6 +315,8 @@ protected:
void CleanupCommandsAndMacros();
void GenerateGraphViz(const char* fileName);
+
+ static int ExecuteEchoColor(std::vector<std::string>& args);
cmVariableWatch* VariableWatch;