File: ColorMessage.cmake

package info (click to toggle)
zynaddsubfx 3.0.6-7.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 65,848 kB
  • sloc: cpp: 124,436; ansic: 39,936; objc: 2,496; makefile: 1,369; python: 567; sh: 566; ruby: 178; javascript: 50
file content (68 lines) | stat: -rw-r--r-- 2,275 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#Very non-portable workaround to detect if the current cmake process is
#outputing to a valid looking terminal (on LINUX only)
if(EXISTS /proc/self/fd/1)
    get_filename_component(STDOUT /proc/self/fd/1 REALPATH)
else()
    set(STDOUT "INVALID")
endif()
if(EXISTS /proc/self/fd/2)
    get_filename_component(STDERR /proc/self/fd/2 REALPATH)
else()
    set(STDERR "INVALID")
endif()

string(FIND ${STDOUT} "tty" isTTYstdout)
string(FIND ${STDERR} "tty" isTTYstderr)
string(FIND ${STDOUT} "pts" isPTSstdout)
string(FIND ${STDERR} "pts" isPTSstderr)
if(((isTTYstdout GREATER 0) OR (isPTSstdout GREATER 0)) AND
    (isTTYstderr GREATER 0) OR (isPTSstdout GREATER 0))
    set(VALID_TTY TRUE)
else()
    set(VALID_TTY FALSE)
endif()

if(VALID_TTY)
    string(ASCII 27 Esc)
    set(ColorReset "${Esc}[m")
    set(ColorBold  "${Esc}[1m")
    set(Red         "${Esc}[31m")
    set(Green       "${Esc}[32m")
    set(Yellow      "${Esc}[33m")
    set(Blue        "${Esc}[34m")
    set(Magenta     "${Esc}[35m")
    set(Cyan        "${Esc}[36m")
    set(White       "${Esc}[37m")
    set(BoldRed     "${Esc}[1;31m")
    set(BoldGreen   "${Esc}[1;32m")
    set(BoldYellow  "${Esc}[1;33m")
    set(BoldBlue    "${Esc}[1;34m")
    set(BoldMagenta "${Esc}[1;35m")
    set(BoldCyan    "${Esc}[1;36m")
    set(BoldWhite   "${Esc}[1;37m")
endif()


# Module Based Off Of
# https://stackoverflow.com/questions/18968979/how-to-get-colorized-output-with-cmake
if(NOT DEFINED MESSAGE_REDEFINED)
    function(message)
        list(GET ARGV 0 MessageType)
        if(MessageType STREQUAL FATAL_ERROR OR MessageType STREQUAL SEND_ERROR)
            list(REMOVE_AT ARGV 0)
            _message(${MessageType} "${BoldRed}${ARGV}${ColorReset}")
        elseif(MessageType STREQUAL WARNING)
            list(REMOVE_AT ARGV 0)
            _message(${MessageType} "${BoldYellow}${ARGV}${ColorReset}")
        elseif(MessageType STREQUAL AUTHOR_WARNING)
            list(REMOVE_AT ARGV 0)
            _message(${MessageType} "${BoldCyan}${ARGV}${ColorReset}")
        elseif(MessageType STREQUAL STATUS)
            list(REMOVE_AT ARGV 0)
            _message(${MessageType} "${ARGV}")
        else()
            _message("${ARGV}")
        endif()
    endfunction()
    set(MESSAGE_REDEFINED TRUE)
endif()