diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2023-06-08 04:02:13 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2023-06-08 15:05:11 (GMT) |
commit | 8195aa30269773732902029741fb8adfe13aa83d (patch) | |
tree | 33f795e6dcdcf548c989d15eab8d11f81aa5026a /Tests | |
parent | c01091d2cf786f361a47a2875ba73d05c1642488 (diff) | |
download | CMake-8195aa30269773732902029741fb8adfe13aa83d.zip CMake-8195aa30269773732902029741fb8adfe13aa83d.tar.gz CMake-8195aa30269773732902029741fb8adfe13aa83d.tar.bz2 |
Makefiles: quote `$(COLOR)` expansions
This handles the case where `COLOR` is set to some ANSI-like color
sequence in the ambient environment. These sequences tend to include `;`
which terminates the command and tries to use the next component
(typically an integer, possibly with a trailing `m`) with errors like:
/bin/sh: line 1: 2: command not found
/bin/sh: line 1: 255: command not found
/bin/sh: line 1: 221: command not found
/bin/sh: line 1: 255m: command not found
Also add a test that sets `COLOR` in the environment which affects the
generated Makefiles behavior.
See: https://discourse.cmake.org/t/cmake-failing-gcc-compiler-checks/8277
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/RunCMake/Color/DiagColorInEnv.cmake | 9 | ||||
-rw-r--r-- | Tests/RunCMake/Color/RunCMakeTest.cmake | 6 |
2 files changed, 15 insertions, 0 deletions
diff --git a/Tests/RunCMake/Color/DiagColorInEnv.cmake b/Tests/RunCMake/Color/DiagColorInEnv.cmake new file mode 100644 index 0000000..83c45e5 --- /dev/null +++ b/Tests/RunCMake/Color/DiagColorInEnv.cmake @@ -0,0 +1,9 @@ +if (CMAKE_GENERATOR MATCHES "Makefiles") + set(CMAKE_COLOR_DIAGNOSTICS 1) + set(EXPECT_COLOR 1) +endif () +include(DiagCommon.cmake) + +if(CMAKE_GENERATOR MATCHES "Makefiles" AND NOT DEFINED CMAKE_COLOR_MAKEFILE) + message(FATAL_ERROR "CMAKE_COLOR_MAKEFILE incorrectly undefined.") +endif() diff --git a/Tests/RunCMake/Color/RunCMakeTest.cmake b/Tests/RunCMake/Color/RunCMakeTest.cmake index bb62d4c..d2bc45a 100644 --- a/Tests/RunCMake/Color/RunCMakeTest.cmake +++ b/Tests/RunCMake/Color/RunCMakeTest.cmake @@ -12,3 +12,9 @@ endfunction() run_Diag(On -DCMAKE_COLOR_DIAGNOSTICS=ON) run_Diag(Off -DCMAKE_COLOR_DIAGNOSTICS=OFF) run_Diag(Default) + +# Test with `COLOR` in the ambient environment set to an ANSI-like color +# sequence. `$(COLOR)` is used in the Makefiles generator to control whether or +# not to do such color sequences itself. +set(ENV{COLOR} "[38;2;255;221;255m") +run_Diag(ColorInEnv) |