diff --git a/cmake/QtFeature.cmake b/cmake/QtFeature.cmake index edf2a95c652..4be4cd550cf 100644 --- a/cmake/QtFeature.cmake +++ b/cmake/QtFeature.cmake @@ -471,26 +471,32 @@ function(qt_feature_copy_global_config_features_to_core target) endfunction() function(qt_config_compile_test name) - cmake_parse_arguments(arg "" "LABEL" "LIBRARIES;CODE" ${ARGN}) + cmake_parse_arguments(arg "" "LABEL;PROJECT_PATH" "LIBRARIES;CODE" ${ARGN}) - foreach(library IN ITEMS ${arg_LIBRARIES}) - if(NOT TARGET "${library}") - # If the dependency looks like a cmake target, then make this compile test - # fail instead of cmake abort later via CMAKE_REQUIRED_LIBRARIES. - string(FIND "${library}" "::" cmake_target_namespace_separator) - if(NOT cmake_target_namespace_separator EQUAL -1) - set(HAVE_${name} FALSE) - break() + if(arg_PROJECT_PATH) + try_compile(HAVE_${name} "${CMAKE_BINARY_DIR}/config.tests/${name}" "${arg_PROJECT_PATH}" + "${name}") + else() + foreach(library IN ITEMS ${arg_LIBRARIES}) + if(NOT TARGET "${library}") + # If the dependency looks like a cmake target, then make this compile test + # fail instead of cmake abort later via CMAKE_REQUIRED_LIBRARIES. + string(FIND "${library}" "::" cmake_target_namespace_separator) + if(NOT cmake_target_namespace_separator EQUAL -1) + set(HAVE_${name} FALSE) + break() + endif() endif() - endif() - endforeach() + endforeach() - if(NOT DEFINED HAVE_${name}) - set(_save_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") - set(CMAKE_REQUIRED_LIBRARIES "${arg_LIBRARIES}") - check_cxx_source_compiles("${arg_UNPARSED_ARGUMENTS} ${arg_CODE}" HAVE_${name}) - set(CMAKE_REQUIRED_LIBRARIES "${_save_CMAKE_REQUIRED_LIBRARIES}") + if(NOT DEFINED HAVE_${name}) + set(_save_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") + set(CMAKE_REQUIRED_LIBRARIES "${arg_LIBRARIES}") + check_cxx_source_compiles("${arg_UNPARSED_ARGUMENTS} ${arg_CODE}" HAVE_${name}) + set(CMAKE_REQUIRED_LIBRARIES "${_save_CMAKE_REQUIRED_LIBRARIES}") + endif() endif() + set(TEST_${name} "${HAVE_${name}}" CACHE INTERNAL "${arg_LABEL}") endfunction() diff --git a/util/cmake/configurejson2cmake.py b/util/cmake/configurejson2cmake.py index 2c3d98ddfb8..51d89d56abc 100755 --- a/util/cmake/configurejson2cmake.py +++ b/util/cmake/configurejson2cmake.py @@ -516,7 +516,16 @@ def parseTest(ctx, test, data, cm_fh): details = data["test"] if isinstance(details, str): - print(f" XXXX UNHANDLED TEST SUB-TYPE {details} in test description") + if not ctx['test_dir']: + print(f" XXXX UNHANDLED TEST SUB-TYPE {details} in test description") + return + + cm_fh.write(f""" +if(EXISTS "${{CMAKE_CURRENT_SOURCE_DIR}}/{ctx['test_dir']}/{data['test']}/CMakeLists.txt") + qt_config_compile_test("{data['test']}" + PROJECT_PATH "${{CMAKE_CURRENT_SOURCE_DIR}}/{ctx['test_dir']}/{data['test']}") +endif() +""") return head = details.get("head", "") @@ -975,6 +984,7 @@ def processSubconfigs(dir, ctx, data): def processJson(dir, ctx, data): ctx["module"] = data.get("module", "global") + ctx["test_dir"] = data.get("testDir", "") ctx = processFiles(ctx, data)