init-repository: Route help output to stdout

CMake's message() writes to stderr, making it
unnecessarily cumbersome to pipe -help
output. Write output via a temp file and cmake -E cat to send it to
stdout instead.

Change-Id: I71710aeb503076586609a69cada94c8a5e30e3be
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Joerg Bornemann
2026-03-06 12:41:57 +01:00
parent 8bd36b1d0d
commit 09d858a0de

View File

@@ -5,6 +5,37 @@
# with renamed functions, because we need similar logic for init-repository, but
# we can't access qtbase before we clone it.
function(qt_ir_print_to_stdout text)
set(tmp_candidates
"${CMAKE_CURRENT_BINARY_DIR}"
"$ENV{TMPDIR}"
"$ENV{TEMP}"
"/tmp"
)
set(tmp "")
foreach(dir IN LISTS tmp_candidates)
if(dir STREQUAL "")
continue()
endif()
set(candidate "${dir}/.qt_configure_stdout_tmp")
execute_process(
COMMAND "${CMAKE_COMMAND}" -E touch "${candidate}"
RESULT_VARIABLE touch_result
)
if(touch_result EQUAL 0)
set(tmp "${candidate}")
break()
endif()
endforeach()
if(tmp STREQUAL "")
message("${text}") # last resort fallback (stderr)
return()
endif()
file(WRITE "${tmp}" "${text}")
execute_process(COMMAND "${CMAKE_COMMAND}" -E cat "${tmp}")
file(REMOVE "${tmp}")
endfunction()
# Call a function with the given arguments.
function(qt_ir_call_function func)
set(call_code "${func}(")
@@ -368,16 +399,17 @@ endfunction()
# Shows help for the command line options.
function(qt_ir_show_help)
set(help "")
set(help_file "${CMAKE_CURRENT_LIST_DIR}/QtIRHelp.txt")
if(EXISTS "${help_file}")
file(READ "${help_file}" content)
message("${content}")
string(APPEND help "${content}")
endif()
message([[
string(APPEND help [[
General Options:
-help, -h ............ Display this help screen
]])
qt_ir_print_to_stdout("${help}")
endfunction()
# Gets the unhandled command line args.