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 <simon.hausmann@qt.io>
This commit is contained in:
Alexandru Croitor 2019-09-21 16:22:36 +02:00
parent 900df48122
commit f35cc5090a
2 changed files with 33 additions and 17 deletions

View File

@ -471,8 +471,12 @@ 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})
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
@ -491,6 +495,8 @@ function(qt_config_compile_test name)
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()

View File

@ -516,9 +516,18 @@ def parseTest(ctx, test, data, cm_fh):
details = data["test"]
if isinstance(details, str):
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", "")
if isinstance(head, list):
head = "\n".join(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)