From f35cc5090a3d78ee7f843625d2c19e472e031cc7 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Sat, 21 Sep 2019 16:22:36 +0200 Subject: [PATCH] configurejson2cmake: handle out-of-line config tests Generate appropriate qt_config_compile_test() calls for config tests that have CMake projects. These are protected by an if(EXISTS) check so that configuration doesn't fail for repos where the config tests have not been ported yet. Adjust the qt_config_compile_test() function to use try_compile for projects specified via new PROJECT_PATH argument. Change-Id: I83c061e384f68688a654b782fd7a9bede282d1e3 Reviewed-by: Qt CMake Build Bot Reviewed-by: Simon Hausmann --- cmake/QtFeature.cmake | 38 ++++++++++++++++++------------- util/cmake/configurejson2cmake.py | 12 +++++++++- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/cmake/QtFeature.cmake b/cmake/QtFeature.cmake index edf2a95c65..4be4cd550c 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 2c3d98ddfb..51d89d56ab 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)