CMakeLists.txt files cannot detect whether an interactive terminal is used nor whether ANSI color escapes are supported
It seems that there is no way with current CMake versions to detect in a CMakeLists.txt
whether an interactive terminal is used. In particular, this means there is no way to know whether ANSI color escapes can be used in custom messages, because CMake's own internal support for colors is also not available to CMakeLists.txt
files.
This used to work up to CMake 3.0:
# [ -t 2 ] tests whether stderr is interactive.
# The negation '!' is because for POSIX shells, 0 is true and 1 is false.
execute_process(COMMAND test ! -t 2 RESULT_VARIABLE IS_STDERR_INTERACTIVE)
but it stopped working with this commit: d7c69246 that went into CMake 3.1. (Now, this test always sees the non-interactive stderr that CMake sets up internally.)
See also the discussion under https://github.com/calamares/calamares/commit/f711d6e39cb777f1e156743e5a92cafe15b81ba1 – Calamares was hit by this silent behavior change.