diff --git a/cmake/QtBaseTopLevelHelpers.cmake b/cmake/QtBaseTopLevelHelpers.cmake index ea334206a02..4b56e9a6646 100644 --- a/cmake/QtBaseTopLevelHelpers.cmake +++ b/cmake/QtBaseTopLevelHelpers.cmake @@ -69,6 +69,10 @@ macro(qt_internal_top_level_setup_no_create_targets) endmacro() macro(qt_internal_top_level_end) + if(QT_BUILD_TESTS) + qt_internal_finalize_test_batch_blacklist() + endif() + qt_internal_print_top_level_info() # Depends on QtBuildInternalsConfig being included, which is the case whenver any repo is diff --git a/cmake/QtBuildRepoHelpers.cmake b/cmake/QtBuildRepoHelpers.cmake index 6750b3b31e6..59c3cdce02c 100644 --- a/cmake/QtBuildRepoHelpers.cmake +++ b/cmake/QtBuildRepoHelpers.cmake @@ -783,6 +783,12 @@ macro(qt_build_tests) endif() endif() + if(NOT QT_SUPERBUILD) + # In a super build, we don't want to finalize the batch blacklist at the end of each repo, + # but rather once at the end of the top-level configuration. + qt_internal_finalize_test_batch_blacklist() + endif() + set(CMAKE_UNITY_BUILD ${QT_UNITY_BUILD}) unset(QT_INTERNAL_CONFIGURING_TESTS) endmacro() diff --git a/cmake/QtTestHelpers.cmake b/cmake/QtTestHelpers.cmake index a761f23005e..6713f95d2c6 100644 --- a/cmake/QtTestHelpers.cmake +++ b/cmake/QtTestHelpers.cmake @@ -825,10 +825,10 @@ function(qt_internal_add_test name) if(NOT blacklist_files) set_target_properties(${name} PROPERTIES _qt_blacklist_files "") set(blacklist_files "") - cmake_language(EVAL CODE "cmake_language(DEFER DIRECTORY \"${CMAKE_SOURCE_DIR}\" CALL \"_qt_internal_finalize_batch\" \"${name}\") ") endif() list(PREPEND blacklist_files "${CMAKE_CURRENT_SOURCE_DIR}/${blacklist_path}") - set_target_properties(${name} PROPERTIES _qt_blacklist_files "${blacklist_files}") + set_target_properties(${name} PROPERTIES + _qt_blacklist_files "${blacklist_files}") endif() else() set(blacklist_path "BLACKLIST") @@ -891,6 +891,35 @@ function(qt_internal_add_test name) qt_internal_add_test_finalizers("${name}") endfunction() +# Generates a blacklist file for the global batched test target. +function(qt_internal_finalize_test_batch_blacklist) + _qt_internal_test_batch_target_name(batch_target_name) + if(NOT TARGET "${batch_target_name}") + return() + endif() + + set(generated_blacklist_file "${CMAKE_CURRENT_BINARY_DIR}/BLACKLIST") + + set(final_contents "") + + get_target_property(blacklist_files "${batch_target_name}" _qt_blacklist_files) + if(blacklist_files) + foreach(blacklist_file ${blacklist_files}) + file(READ "${blacklist_file}" file_contents) + if(file_contents) + string(APPEND final_contents "${file_contents}\n") + endif() + endforeach() + endif() + + qt_configure_file(OUTPUT "${generated_blacklist_file}" CONTENT "${final_contents}") + + qt_internal_add_resource(${batch_target_name} "batch_blacklist" + PREFIX "/" + FILES "${generated_blacklist_file}" + BASE ${CMAKE_CURRENT_BINARY_DIR}) +endfunction() + # Given an optional test timeout value (specified via qt_internal_add_test's TIMEOUT option) # returns a percentage of the final timeout to be passed to the androidtestrunner executable. # diff --git a/src/corelib/Qt6AndroidMacros.cmake b/src/corelib/Qt6AndroidMacros.cmake index 3fccd18d261..83222307b1f 100644 --- a/src/corelib/Qt6AndroidMacros.cmake +++ b/src/corelib/Qt6AndroidMacros.cmake @@ -1715,6 +1715,7 @@ function(_qt_internal_android_create_runner_wrapper target) set(wrapper_path "${target_binary_dir}/${target}") endif() + get_property(__qt_core_macros_module_base_dir GLOBAL PROPERTY __qt_core_macros_module_base_dir) set(template_file "${__qt_core_macros_module_base_dir}/Qt6CoreConfigureFileTemplate.in") set(qt_core_configure_file_contents "${script_content}") configure_file("${template_file}" "${wrapper_path}") diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index d922f9bd251..489a489efd0 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -8,7 +8,9 @@ # ###################################### -set(__qt_core_macros_module_base_dir "${CMAKE_CURRENT_LIST_DIR}") +# Save the 'macros base dir' in a global property instead of a variable, to allow access in a +# deferred function where the variable might not be accessible by the function scope. +set_property(GLOBAL PROPERTY __qt_core_macros_module_base_dir "${CMAKE_CURRENT_LIST_DIR}") # macro used to create the names of output files preserving relative dirs macro(_qt_internal_make_output_file infile prefix ext outfile ) @@ -780,26 +782,6 @@ function(_qt_internal_finalize_executable target) endif() endfunction() -function(_cat IN_FILE OUT_FILE) - file(READ ${IN_FILE} CONTENTS) - file(APPEND ${OUT_FILE} "${CONTENTS}\n") -endfunction() - -function(_qt_internal_finalize_batch name) - find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS Core) - - set(generated_blacklist_file "${CMAKE_CURRENT_BINARY_DIR}/BLACKLIST") - get_target_property(blacklist_files "${name}" _qt_blacklist_files) - file(WRITE "${generated_blacklist_file}" "") - foreach(blacklist_file ${blacklist_files}) - _cat("${blacklist_file}" "${generated_blacklist_file}") - endforeach() - qt_internal_add_resource(${name} "batch_blacklist" - PREFIX "/" - FILES "${CMAKE_CURRENT_BINARY_DIR}/BLACKLIST" - BASE ${CMAKE_CURRENT_BINARY_DIR}) -endfunction() - # If a task needs to run before any targets are finalized in the current directory # scope, call this function and pass the ID of that task as the argument. function(_qt_internal_delay_finalization_until_after defer_id) @@ -2110,6 +2092,7 @@ function(__qt_internal_sanitize_resource_name out_var name) endfunction() function(__qt_internal_generate_init_resource_source_file out_var target resource_name) + get_property(__qt_core_macros_module_base_dir GLOBAL PROPERTY __qt_core_macros_module_base_dir) set(template_file "${__qt_core_macros_module_base_dir}/Qt6CoreResourceInit.in.cpp") # Gets replaced in the template @@ -2378,6 +2361,7 @@ function(_qt_internal_process_resource target resourceName) # string(APPEND qrcContents " \n\n") + get_property(__qt_core_macros_module_base_dir GLOBAL PROPERTY __qt_core_macros_module_base_dir) set(template_file "${__qt_core_macros_module_base_dir}/Qt6CoreConfigureFileTemplate.in") set(qt_core_configure_file_contents "${qrcContents}") configure_file("${template_file}" "${generatedResourceFile}")