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.
This commit is contained in:
parent
92ea0a077c
commit
4494c29078
|
@ -24,7 +24,7 @@ cmGlobalBorlandMakefileGenerator::cmGlobalBorlandMakefileGenerator()
|
|||
this->EmptyRuleHackDepends = "NUL";
|
||||
this->FindMakeProgramFile = "CMakeBorlandFindMake.cmake";
|
||||
this->ForceUnixPaths = false;
|
||||
this->ToolSupportsColorVT100 = false;
|
||||
this->ToolSupportsColor = true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -23,7 +23,7 @@ cmGlobalMSYSMakefileGenerator::cmGlobalMSYSMakefileGenerator()
|
|||
{
|
||||
this->FindMakeProgramFile = "CMakeMSYSFindMake.cmake";
|
||||
this->ForceUnixPaths = true;
|
||||
this->ToolSupportsColorVT100 = true;
|
||||
this->ToolSupportsColor = true;
|
||||
}
|
||||
|
||||
std::string
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -22,7 +22,7 @@ cmGlobalWatcomWMakeGenerator::cmGlobalWatcomWMakeGenerator()
|
|||
{
|
||||
this->FindMakeProgramFile = "CMakeFindWMake.cmake";
|
||||
this->ForceUnixPaths = false;
|
||||
this->ToolSupportsColorVT100 = false;
|
||||
this->ToolSupportsColor = true;
|
||||
this->EmptyCommandsHack = "@cd .";
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
113
Source/cmake.cxx
113
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;
|
||||
}
|
||||
|
|
|
@ -316,6 +316,8 @@ protected:
|
|||
|
||||
void GenerateGraphViz(const char* fileName);
|
||||
|
||||
static int ExecuteEchoColor(std::vector<std::string>& args);
|
||||
|
||||
cmVariableWatch* VariableWatch;
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue