At [QTCREATORBUG-30147] ERROR_VARIABLE from execute_process is not working as expected - Qt Bug Tracker we can see the following code:
cmake_minimum_required(VERSION 3.14)
project(QtCreatoCmakeBug)
unset(generated_files)
execute_process(COMMAND ${CMAKE_COMMAND}
-P ${CMAKE_CURRENT_SOURCE_DIR}/myScript.cmake
ERROR_VARIABLE error_output) # CMake writes messages to standard error.
string(STRIP "${error_output}" error_output)
list(LENGTH error_output error_output_len)
message("error_output list ${error_output} length: ${error_output_len}")
# Same list variable
set(my_file_list "myFile1.h;myFile1.cpp")
list(LENGTH my_file_list my_file_list_len)
message("my_file_list list ${my_file_list} length: ${my_file_list_len}")
with myScript.cmake
as:
cmake_minimum_required(VERSION 3.16)
message("myFile1.h;myFile1.cpp")
The length
is reported as 2 and 2 with Qt Creator 11, and 1 and 2 for Qt Creator 12.
This is due to the fact that Qt Creator 12 sets CLICOLOR_FORCE
to 1
which causes the CMake run via execute_process
to inject escape codes.
The output is actually:
e[0mmyFile1.h;myFile1.cppe[0m
The fix would be either use:
string(ASCII 27 Esc)
string(REPLACE "${Esc}[0m" "" error_output "${error_output}")
or set CLICOLOR_FORCE
to 0
for the CMake project in Qt Creator.
But what about fixing this at CMake level? I can think of two fixes:
string(STRIP "${error_output}" error_output)
would also strip the escape codeslist(LENGTH error_output error_output_len)
would ignore the escape codes- Ignore issue and fix it via documentation
Any thoughts?