Make RunCMake compatible with CMake<3.18

Avoid using `cmake_language`.

Reverting commit:
67f97f5478

Pick-to: 6.8
Change-Id: I8311508c904cbc66aa663a0b62f861b7b056b526
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
(cherry picked from commit 3617409325fb3757d9126e72d4b852fa571f42f7)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Cristian Le 2025-03-07 18:20:08 +01:00 committed by Qt Cherry-pick Bot
parent 2886996de4
commit 477e9216f3

View File

@ -2,6 +2,8 @@
# file Copyright.txt or https://cmake.org/licensing for details. # file Copyright.txt or https://cmake.org/licensing for details.
# #
# Original file location was Tests/RunCMake/RunCMake.cmake # Original file location was Tests/RunCMake/RunCMake.cmake
#
# reverted https://gitlab.kitware.com/cmake/cmake/-/commit/67f97f54789413f47a0f03a36c3bb32518a2e922
foreach( foreach(
arg arg
@ -139,16 +141,12 @@ function(run_cmake test)
else() else()
set(RunCMake_TEST_OPTIONS "") set(RunCMake_TEST_OPTIONS "")
endif() endif()
if(NOT DEFINED RunCMake_TEST_RAW_ARGS)
set(RunCMake_TEST_RAW_ARGS "")
endif()
if(NOT RunCMake_TEST_COMMAND_WORKING_DIRECTORY) if(NOT RunCMake_TEST_COMMAND_WORKING_DIRECTORY)
set(RunCMake_TEST_COMMAND_WORKING_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") set(RunCMake_TEST_COMMAND_WORKING_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
endif() endif()
string(CONCAT _code [[execute_process( execute_process(
COMMAND ${RunCMake_TEST_COMMAND} COMMAND ${RunCMake_TEST_COMMAND}
${RunCMake_TEST_OPTIONS} ${RunCMake_TEST_OPTIONS}
]] "${RunCMake_TEST_RAW_ARGS}\n" [[
WORKING_DIRECTORY "${RunCMake_TEST_COMMAND_WORKING_DIRECTORY}" WORKING_DIRECTORY "${RunCMake_TEST_COMMAND_WORKING_DIRECTORY}"
OUTPUT_VARIABLE actual_stdout OUTPUT_VARIABLE actual_stdout
ERROR_VARIABLE ${actual_stderr_var} ERROR_VARIABLE ${actual_stderr_var}
@ -156,7 +154,7 @@ function(run_cmake test)
ENCODING UTF8 ENCODING UTF8
${maybe_timeout} ${maybe_timeout}
${maybe_input_file} ${maybe_input_file}
)]]) )
if(DEFINED ENV{PWD}) if(DEFINED ENV{PWD})
set(old_pwd "$ENV{PWD}") set(old_pwd "$ENV{PWD}")
else() else()
@ -164,7 +162,6 @@ function(run_cmake test)
endif() endif()
# Emulate a shell using this directory. # Emulate a shell using this directory.
set(ENV{PWD} "${RunCMake_TEST_COMMAND_WORKING_DIRECTORY}") set(ENV{PWD} "${RunCMake_TEST_COMMAND_WORKING_DIRECTORY}")
cmake_language(EVAL CODE "${_code}")
if(DEFINED old_pwd) if(DEFINED old_pwd)
set(ENV{PWD} "${old_pwd}") set(ENV{PWD} "${old_pwd}")
else() else()
@ -266,9 +263,6 @@ function(run_cmake test)
string(REPLACE ";" "\" \"" options "\"${RunCMake_TEST_OPTIONS}\"") string(REPLACE ";" "\" \"" options "\"${RunCMake_TEST_OPTIONS}\"")
string(APPEND command " ${options}") string(APPEND command " ${options}")
endif() endif()
if(RunCMake_TEST_RAW_ARGS)
string(APPEND command " ${RunCMake_TEST_RAW_ARGS}")
endif()
string(APPEND msg "Command was:\n command> ${command}\n") string(APPEND msg "Command was:\n command> ${command}\n")
endif() endif()
if(msg) if(msg)
@ -306,11 +300,6 @@ function(run_cmake_with_options test)
run_cmake(${test}) run_cmake(${test})
endfunction() endfunction()
function(run_cmake_with_raw_args test args)
set(RunCMake_TEST_RAW_ARGS "${args}")
run_cmake(${test})
endfunction()
function(ensure_files_match expected_file actual_file) function(ensure_files_match expected_file actual_file)
if(NOT EXISTS "${expected_file}") if(NOT EXISTS "${expected_file}")
message(FATAL_ERROR "Expected file does not exist:\n ${expected_file}") message(FATAL_ERROR "Expected file does not exist:\n ${expected_file}")