summaryrefslogtreecommitdiffstats
path: root/src/corelib/Qt6CTestMacros.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/Qt6CTestMacros.cmake')
-rw-r--r--src/corelib/Qt6CTestMacros.cmake215
1 files changed, 184 insertions, 31 deletions
diff --git a/src/corelib/Qt6CTestMacros.cmake b/src/corelib/Qt6CTestMacros.cmake
index 28a97f45f6..8722553cd0 100644
--- a/src/corelib/Qt6CTestMacros.cmake
+++ b/src/corelib/Qt6CTestMacros.cmake
@@ -1,3 +1,6 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
#
# W A R N I N G
# -------------
@@ -8,14 +11,9 @@
#
# We mean it.
-message("CMAKE_VERSION: ${CMAKE_VERSION}")
-message("CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
-message("CMAKE_MODULES_UNDER_TEST: ${CMAKE_MODULES_UNDER_TEST}")
-foreach(_mod ${CMAKE_MODULES_UNDER_TEST})
- message("CMAKE_${_mod}_MODULE_MAJOR_VERSION: ${CMAKE_${_mod}_MODULE_MAJOR_VERSION}")
- message("CMAKE_${_mod}_MODULE_MINOR_VERSION: ${CMAKE_${_mod}_MODULE_MINOR_VERSION}")
- message("CMAKE_${_mod}_MODULE_PATCH_VERSION: ${CMAKE_${_mod}_MODULE_PATCH_VERSION}")
-endforeach()
+message(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}")
+message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
+message(STATUS "CMAKE_MODULES_UNDER_TEST: ${CMAKE_MODULES_UNDER_TEST}")
# Generate a shell script wrapper that calls ninja with -v parameter.
# Upstream issue to allow specifying custom build tool options when using ctest's --build-and-test
@@ -144,22 +142,30 @@ 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()
+ _qt_internal_get_build_vars_for_external_projects(
+ PREFIXES_VAR prefixes
+ ADDITIONAL_PACKAGES_PREFIXES_VAR additional_prefixes
+ )
+
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}")
+ list(APPEND option_list "-DQT_ADDITIONAL_PACKAGES_PREFIX_PATH=${additional_prefixes}")
set(${out_var} "${option_list}" PARENT_SCOPE)
endfunction()
function(_qt_internal_set_up_test_run_environment testname)
+ set(no_value_options NO_PLUGIN_PATH)
+ set(single_value_options "")
+ set(multi_value_options "")
+ cmake_parse_arguments(PARSE_ARGV 1 arg
+ "${no_value_options}" "${single_value_options}" "${multi_value_options}"
+ )
+
# This is copy-pasted from qt_add_test and adapted to the standalone project case.
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
set(QT_PATH_SEPARATOR "\\;")
@@ -198,20 +204,20 @@ function(_qt_internal_set_up_test_run_environment testname)
set_property(TEST "${testname}" APPEND PROPERTY ENVIRONMENT "${test_env_path}")
set_property(TEST "${testname}" APPEND PROPERTY ENVIRONMENT "QT_TEST_RUNNING_IN_CTEST=1")
- # Add the install prefix to list of plugin paths when doing a prefix build
- if(NOT QT_INSTALL_DIR)
- foreach(install_prefix ${install_prefixes})
- list(APPEND plugin_paths "${install_prefix}/${INSTALL_PLUGINSDIR}")
- endforeach()
- endif()
-
- #TODO: Collect all paths from known repositories when performing a super
- # build.
- list(APPEND plugin_paths "${PROJECT_BINARY_DIR}/${INSTALL_PLUGINSDIR}")
- list(JOIN plugin_paths "${QT_PATH_SEPARATOR}" plugin_paths_joined)
- set_property(TEST "${testname}"
- APPEND PROPERTY ENVIRONMENT "QT_PLUGIN_PATH=${plugin_paths_joined}")
+ if(NOT arg_NO_PLUGIN_PATH)
+ # Add the install prefix to list of plugin paths when doing a prefix build
+ if(NOT QT_INSTALL_DIR)
+ foreach(install_prefix ${install_prefixes})
+ list(APPEND plugin_paths "${install_prefix}/${INSTALL_PLUGINSDIR}")
+ endforeach()
+ endif()
+ # TODO: Collect all paths from known repositories when performing a super build.
+ list(APPEND plugin_paths "${PROJECT_BINARY_DIR}/${INSTALL_PLUGINSDIR}")
+ list(JOIN plugin_paths "${QT_PATH_SEPARATOR}" plugin_paths_joined)
+ set_property(TEST "${testname}"
+ APPEND PROPERTY ENVIRONMENT "QT_PLUGIN_PATH=${plugin_paths_joined}")
+ endif()
endfunction()
# Checks if the test project can be built successfully. Arguments:
@@ -249,13 +255,21 @@ endfunction()
# TESTNAME: a custom test name to use instead of the one derived from the source directory name
#
# BUILD_OPTIONS: a list of -D style CMake definitions to pass to ctest's --build-options (which
-# are ultimately passed to the CMake invocation of the test project)
+# are ultimately passed to the CMake invocation of the test project). You may
+# escape semicolons inside the definitions using:
+# https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#bracket-argument
+# so the argument containing list will look as following:
+# -DLIST_ARGUMENT=item1[[;]]item2[[;]]...itemN.
macro(_qt_internal_test_expect_pass _dir)
+ if(WASM)
+ return()
+ endif()
set(_test_option_args
SIMULATE_IN_SOURCE
NO_CLEAN_STEP
NO_BUILD_PROJECT_ARG
NO_IOS_DEFAULT_ARGS
+ NO_RUN_ENVIRONMENT_PLUGIN_PATH
)
set(_test_single_args
BINARY
@@ -370,7 +384,7 @@ macro(_qt_internal_test_expect_pass _dir)
endif()
if(build_environment STREQUAL "ci"
AND osx_arch_count GREATER_EQUAL 2
- AND NOT QT_UIKIT_SDK
+ AND NOT QT_APPLE_SDK
AND NOT QT_NO_IOS_BUILD_ADJUSTMENT_IN_CI)
list(APPEND additional_configure_args
-DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_OSX_SYSROOT=iphonesimulator)
@@ -411,6 +425,8 @@ macro(_qt_internal_test_expect_pass _dir)
)
endif()
+ string(REPLACE "[[;]]" "\;" _ARGS_BUILD_OPTIONS "${_ARGS_BUILD_OPTIONS}")
+
_qt_internal_get_cmake_test_configure_options(option_list)
set(ctest_command_args
--build-and-test
@@ -422,23 +438,160 @@ macro(_qt_internal_test_expect_pass _dir)
--build-makeprogram "${make_program}"
${build_project}
--build-options "${option_list}"
- ${_ARGS_BUILD_OPTIONS} ${additional_configure_args}
+ "${_ARGS_BUILD_OPTIONS}" ${additional_configure_args}
${test_command}
)
add_test(${testname} ${CMAKE_CTEST_COMMAND} ${ctest_command_args})
if(_ARGS_SIMULATE_IN_SOURCE)
set_tests_properties(${testname} PROPERTIES
- FIXTURES_REQUIRED "${testname}SIMULATE_IN_SOURCE_FIXTURE")
+ FIXTURES_REQUIRED "${testname}SIMULATE_IN_SOURCE_FIXTURE"
+ )
endif()
+ set_tests_properties(${testname} PROPERTIES ENVIRONMENT "ASAN_OPTIONS=detect_leaks=0")
if(_ARGS_BINARY)
- _qt_internal_set_up_test_run_environment("${testname}")
+ set(run_env_args "")
+ if(_ARGS_NO_RUN_ENVIRONMENT_PLUGIN_PATH)
+ list(APPEND run_env_args NO_PLUGIN_PATH)
+ endif()
+ _qt_internal_set_up_test_run_environment("${testname}" ${run_env_args})
endif()
unset(__expect_pass_source_dir)
unset(__expect_pass_build_dir)
endmacro()
+# Checks if a qmake project can be built successfully. Arguments:
+#
+# TESTNAME: a custom test name to use instead of the one derived from the source directory name.
+# the name also applies to the generated build directory.
+#
+# QMAKE_OPTIONS: a list of variable assignments to pass to the qmake invocation.
+# e.g. CONFIG+=debug
+#
+# BUILD_ENVIRONMENT: a list of environment assignments to use when invoking the build tool
+function(_qt_internal_add_qmake_test dir_name)
+ set(test_option_args
+ )
+ set(test_single_args
+ TESTNAME
+ )
+ set(test_multi_args
+ QMAKE_OPTIONS
+ BUILD_ENVIRONMENT
+ )
+
+ # PARSE_ARGV parsing keeps ';' in ENVIRONMENT variables
+ cmake_parse_arguments(PARSE_ARGV 1 arg
+ "${test_option_args}"
+ "${test_single_args}"
+ "${test_multi_args}"
+ )
+
+ if(arg_TESTNAME)
+ set(testname "${arg_TESTNAME}")
+ else()
+ string(REGEX REPLACE "[/)(]" "_" testname "${dir_name}")
+ endif()
+
+ set(source_dir "${CMAKE_CURRENT_SOURCE_DIR}/${dir_name}")
+ if(arg_TESTNAME)
+ set(build_dir "${CMAKE_CURRENT_BINARY_DIR}/${arg_TESTNAME}")
+ else()
+ set(build_dir "${CMAKE_CURRENT_BINARY_DIR}/${dir_name}")
+ endif()
+
+ # Find the qmake binary or the wrapper qmake script when cross-compiling..
+ if(QtBase_BINARY_DIR AND NOT QT_BUILD_STANDALONE_TESTS)
+ set(qmake_dir "${QtBase_BINARY_DIR}/${INSTALL_BINDIR}")
+ else()
+ set(qmake_dir "${QT6_INSTALL_PREFIX}/${QT6_INSTALL_BINS}")
+ endif()
+
+ set(qmake_path "${qmake_dir}/qmake${CMAKE_EXECUTABLE_SUFFIX}")
+
+ set(qmake_args
+ "${source_dir}"
+ ${arg_QMAKE_OPTIONS}
+ )
+
+ # Try to choose an appropriate build tool.
+ if(ENV{QT_QMAKE_TEST_BUILD_TOOL})
+ set(build_tool "$ENV{QT_QMAKE_TEST_BUILD_TOOL}")
+ elseif(MSVC)
+ set(build_tool "nmake")
+ elseif(MINGW)
+ set(build_tool "mingw32-make")
+ else()
+ set(build_tool "make")
+ endif()
+
+ set(build_tool_args "")
+ if(ENV{QT_QMAKE_TEST_BUILD_TOOL_OPTIONS})
+ set(build_tool_args "$ENV{QT_QMAKE_TEST_BUILD_TOOL_OPTIONS}")
+ endif()
+
+ # Remove any stale build dir, and create a new one on each test rerun.
+ add_test(${testname}_remove_build_dir
+ ${CMAKE_COMMAND} -E remove_directory "${build_dir}"
+ )
+ set_tests_properties(${testname}_remove_build_dir PROPERTIES
+ FIXTURES_SETUP "${testname}_ensure_clean_build_dir"
+ )
+
+ add_test(${testname}_create_build_dir
+ ${CMAKE_COMMAND} -E make_directory "${build_dir}"
+ )
+ set_tests_properties(${testname}_create_build_dir PROPERTIES
+ FIXTURES_SETUP "${testname}_ensure_clean_build_dir"
+ )
+
+ set_tests_properties(${testname}_create_build_dir
+ PROPERTIES DEPENDS ${testname}_remove_build_dir)
+
+ # Add test to call qmake.
+ #
+ # We can't use the add_test(NAME) signature to set a working directory, because that breaks
+ # when calling ctest without a -C <config> using multi-config generators, and the CI calls
+ # ctest without -C, and we use Xcode when configuring tests for iOS, which is multi-config.
+ # The plain add_test signature does not have this issue.
+ # Work around this by using a wrapper script that sets a working directory and use the plain
+ # signature.
+ # Somewhat related issue https://gitlab.kitware.com/cmake/cmake/-/issues/20283
+ set(qmake_wrapper_file "${CMAKE_CURRENT_BINARY_DIR}/run_qmake_${testname}.cmake")
+ _qt_internal_create_command_script(
+ COMMAND "${qmake_path}" ${qmake_args}
+ COMMAND_ECHO STDOUT
+ OUTPUT_FILE "${qmake_wrapper_file}"
+ WORKING_DIRECTORY "${build_dir}"
+ )
+
+ add_test(${testname}_qmake "${CMAKE_COMMAND}" "-P" "${qmake_wrapper_file}")
+
+ set_tests_properties(${testname}_qmake PROPERTIES
+ DEPENDS ${testname}_create_build_dir
+ FIXTURES_REQUIRED "${testname}_ensure_clean_build_dir"
+ FIXTURES_SETUP "${testname}_configure_project"
+ )
+
+ # Add test to build the generated qmake project.
+ set(build_tool_wrapper_file "${CMAKE_CURRENT_BINARY_DIR}/run_build_${testname}.cmake")
+ _qt_internal_create_command_script(
+ COMMAND "${build_tool}" ${build_tool_args}
+ COMMAND_ECHO STDOUT
+ OUTPUT_FILE "${build_tool_wrapper_file}"
+ WORKING_DIRECTORY "${build_dir}"
+ ENVIRONMENT ${arg_BUILD_ENVIRONMENT}
+ )
+
+ add_test(${testname} "${CMAKE_COMMAND}" "-P" "${build_tool_wrapper_file}")
+
+ set_tests_properties(${testname} PROPERTIES
+ DEPENDS ${testname}_qmake
+ FIXTURES_REQUIRED "${testname}_ensure_clean_build_dir;${testname}_configure_project"
+ )
+endfunction()
+
# Checks if the build of the test project fails.
# This test passes if the test project fails either at the
# configuring or build steps.