From f95d03b3721369e3bd9e60c50f90405a617849cd Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Thu, 1 Jul 2021 17:49:31 +0200 Subject: [PATCH] CMake: Allow specifying custom build directories for CMake autotests It's useful when one project needs to be configured multiple times in different directories without overlapping CMakeCache.txt files, due to differing options passed during configuration. Pick-to: 6.2 Change-Id: Id2969e989824f980fba6ed58f9e0323ab3a862dd Reviewed-by: Alexey Edelev Reviewed-by: Qt CI Bot Reviewed-by: Joerg Bornemann --- src/corelib/Qt6CTestMacros.cmake | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/corelib/Qt6CTestMacros.cmake b/src/corelib/Qt6CTestMacros.cmake index 04595a776da..13d794024ae 100644 --- a/src/corelib/Qt6CTestMacros.cmake +++ b/src/corelib/Qt6CTestMacros.cmake @@ -132,6 +132,10 @@ endfunction() # This makes possible to have relative paths to the source files in the # generated ninja rules. # +# BUILD_DIR: A custom build dir relative to the calling project CMAKE_CURRENT_BINARY_DIR. +# Useful when configuring the same test project with different options in separate +# build dirs. +# # BINARY: Path to the test artifact that will be executed after the build is complete. If a # relative path is specified, it will be counted from the build directory. # Can also be passed a random executable to be found in PATH, like 'ctest'. @@ -143,8 +147,24 @@ endfunction() # 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) macro(_qt_internal_test_expect_pass _dir) - cmake_parse_arguments(_ARGS "SIMULATE_IN_SOURCE" "BINARY;TESTNAME" "BUILD_OPTIONS;BINARY_ARGS" - ${ARGN}) + set(_test_option_args + SIMULATE_IN_SOURCE + ) + set(_test_single_args + BINARY + TESTNAME + BUILD_DIR + ) + set(_test_multi_args + BUILD_OPTIONS + BINARY_ARGS + ) + cmake_parse_arguments(_ARGS + "${_test_option_args}" + "${_test_single_args}" + "${_test_multi_args}" + ${ARGN} + ) if(_ARGS_TESTNAME) set(testname "${_ARGS_TESTNAME}") else() @@ -157,6 +177,10 @@ macro(_qt_internal_test_expect_pass _dir) 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}") + endif() + set(__expect_pass_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/${_dir}") if(_ARGS_SIMULATE_IN_SOURCE) set(__expect_pass_in_source_build_dir "${CMAKE_CURRENT_BINARY_DIR}/in_source")