Skip to content

Commit

Permalink
Use the CMake path format when passing the CMAKE_PREFIX_PATH to ctest
Browse files Browse the repository at this point in the history
The generated 'CTestTestfile.cmake' file contains unescaped '\' symbols
in --build-options argument that causes an issue if the Windows path
format is used in CMAKE_PREFIX_PATH.

Change-Id: Ic03934fcb7bc6230cef72584fef81b01026d5f3b
Reviewed-by: Alexandru Croitor <[email protected]>
  • Loading branch information
semlanik committed Mar 23, 2022
1 parent ee15aa7 commit de582a2
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/corelib/Qt6CTestMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ foreach(_mod ${CMAKE_MODULES_UNDER_TEST})
message("CMAKE_${_mod}_MODULE_PATCH_VERSION: ${CMAKE_${_mod}_MODULE_PATCH_VERSION}")
endforeach()

# The function collects configuring options for the test projects generated by Qt cmake tests.
# Arguments:
# OUT_PREFIX_PATH <variable name>: stores the CMAKE_PREFIX_PATH value in the output variable.
function(_qt_internal_get_cmake_test_configure_options out_var)
cmake_parse_arguments(arg "" "OUT_PREFIX_PATH" "" ${ARGN})
set(option_list)

if (CMAKE_C_COMPILER AND NOT CMAKE_CROSSCOMPILING)
Expand Down Expand Up @@ -78,6 +82,18 @@ function(_qt_internal_get_cmake_test_configure_options out_var)
)
endforeach()

set(prefixes "")
foreach(prefix_path IN LISTS CMAKE_PREFIX_PATH)
file(TO_CMAKE_PATH "${prefix_path}" prefix_path)
list(APPEND prefixes "${prefix_path}")
endforeach()
if(arg_OUT_PREFIX_PATH)
set(${arg_OUT_PREFIX_PATH} "${prefixes}" PARENT_SCOPE)
endif()

string(REPLACE ";" "\;" prefixes "${prefixes}")
list(APPEND option_list "-DCMAKE_PREFIX_PATH=${prefixes}")

set(${out_var} "${option_list}" PARENT_SCOPE)
endfunction()

Expand Down Expand Up @@ -294,9 +310,6 @@ macro(_qt_internal_test_expect_pass _dir)
endif()
endif()

set(__expect_pass_prefixes "${CMAKE_PREFIX_PATH}")
string(REPLACE ";" "\;" __expect_pass_prefixes "${__expect_pass_prefixes}")

set(__expect_pass_build_dir "${CMAKE_CURRENT_BINARY_DIR}/${_dir}")
if(_ARGS_BUILD_DIR)
set(__expect_pass_build_dir "${CMAKE_CURRENT_BINARY_DIR}/${_ARGS_BUILD_DIR}")
Expand Down Expand Up @@ -341,7 +354,7 @@ macro(_qt_internal_test_expect_pass _dir)
--build-generator "${generator}"
--build-makeprogram "${make_program}"
${build_project}
--build-options "-DCMAKE_PREFIX_PATH=${__expect_pass_prefixes}" ${option_list}
--build-options "${option_list}"
${_ARGS_BUILD_OPTIONS} ${additional_configure_args}
${test_command}
)
Expand All @@ -357,7 +370,6 @@ macro(_qt_internal_test_expect_pass _dir)

unset(__expect_pass_source_dir)
unset(__expect_pass_build_dir)
unset(__expect_pass_prefixes)
endmacro()

# Checks if the build of the test project fails.
Expand All @@ -378,9 +390,12 @@ macro(_qt_internal_test_expect_build_fail _dir)
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/failbuild/${_dir}")
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/${_dir}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/failbuild/${_dir}")

set(__expect_fail_prefixes "")
_qt_internal_get_cmake_test_configure_options(option_list OUT_PREFIX_PATH __expect_fail_prefixes)

file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/failbuild/${_dir}/${_dir}/FindPackageHints.cmake"
"set(Qt6Tests_PREFIX_PATH \"${CMAKE_PREFIX_PATH}\")
list(APPEND CMAKE_PREFIX_PATH \"${CMAKE_PREFIX_PATH}\")
"set(Qt6Tests_PREFIX_PATH \"${__expect_fail_prefixes}\")
list(APPEND CMAKE_PREFIX_PATH \"${__expect_fail_prefixes}\")
")

file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/failbuild/${_dir}/CMakeLists.txt"
Expand All @@ -400,7 +415,6 @@ list(APPEND CMAKE_PREFIX_PATH \"${CMAKE_PREFIX_PATH}\")
"
)

_qt_internal_get_cmake_test_configure_options(option_list)
add_test(${testname} ${CMAKE_CTEST_COMMAND}
--build-and-test
"${CMAKE_CURRENT_BINARY_DIR}/failbuild/${_dir}"
Expand All @@ -409,8 +423,9 @@ list(APPEND CMAKE_PREFIX_PATH \"${CMAKE_PREFIX_PATH}\")
--build-generator "${CMAKE_GENERATOR}"
--build-makeprogram "${CMAKE_MAKE_PROGRAM}"
--build-project "${_dir}"
--build-options "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${option_list}
--build-options ${option_list}
)
unset(__expect_fail_prefixes)
endmacro()

function(_qt_internal_test_module_includes)
Expand Down Expand Up @@ -512,6 +527,6 @@ function(_qt_internal_test_module_includes)
--build-generator "${CMAKE_GENERATOR}"
--build-makeprogram "${CMAKE_MAKE_PROGRAM}"
--build-project module_includes
--build-options "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${option_list}
--build-options ${option_list}
)
endfunction()

0 comments on commit de582a2

Please sign in to comment.