diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-04-02 10:33:04 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-04-03 16:05:19 +0200 |
commit | d2931a2626eb67b8b39e25fc62501c01901ab1d3 (patch) | |
tree | f2245dbe7e98d0b56ca816a5a845938234b500fd /util | |
parent | de78425ca0c508eb02aaac794ecbcda5ff09a5eb (diff) |
CMake: Handle standalone config.tests in configure libraries section
Some library entries in configure.json have a test entry.
An example is assimp in qtquick3d.
qmake tries to find the library via the sources section, and then tries
to compile the test found in config.tests/assimp/assimp.pro while
automagically passing it the include and link flags it found for assimp.
We didn't handle that in CMake, and now we kind of do.
configurejson2cmake will now create a corresponding
qt_config_compile_test call where it will pass a list of packages and
libraries to find and link against.
pro2cmake will in turn generate new code for the standalone
config.test project. This code will iterate over packages that need to
be found (like WrapAssimp) and then link against a list of passed-in
targets.
In this way the config.test/assimp/main.cpp file can successfully
use assimp code (due to propagated include headers).
qt_config_compile_test is augmented to take a new PACKAGES argument,
with an example as follows
PACKAGES PACKAGE Foo 6 COMPONENTS Bar
PACKAGE Baz REQUIRED
The arguments will be parsed and passed to the try_compile project,
to call find_package() on them.
We also need to pass the C/C++ standard values to the try_compile
project, as well as other try_compile specific flags, like the
toolchain, as given by qt_get_platform_try_compile_vars().
Change-Id: I4a3f76c75309c70c78e580b80114b33870b2cf79
Reviewed-by: Leander Beernaert <leander.beernaert@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'util')
-rwxr-xr-x | util/cmake/configurejson2cmake.py | 84 | ||||
-rwxr-xr-x | util/cmake/pro2cmake.py | 12 |
2 files changed, 80 insertions, 16 deletions
diff --git a/util/cmake/configurejson2cmake.py b/util/cmake/configurejson2cmake.py index 5f60e55ca4..11b216dc37 100755 --- a/util/cmake/configurejson2cmake.py +++ b/util/cmake/configurejson2cmake.py @@ -499,6 +499,70 @@ def parseInput(ctx, sinput, data, cm_fh): return +def get_library_usage_for_compile_test(library): + result = {} + mapped_library = find_3rd_party_library_mapping(library) + if not mapped_library: + result["fixme"] = f"# FIXME: use: unmapped library: {library}\n" + return result + + if mapped_library.test_library_overwrite: + target_name = mapped_library.test_library_overwrite + else: + target_name = mapped_library.targetName + result["target_name"] = target_name + result["package_name"] = mapped_library.packageName + result["extra"] = mapped_library.extra + return result + + +# Handles config.test/foo/foo.pro projects. +def write_standalone_compile_test(cm_fh, ctx, data, config_test_name, is_library_test): + rel_test_project_path = f"{ctx['test_dir']}/{config_test_name}" + if posixpath.exists(f"{ctx['project_dir']}/{rel_test_project_path}/CMakeLists.txt"): + label = "" + libraries = [] + packages = [] + + if "label" in data: + label = data["label"] + + if is_library_test and config_test_name in data["libraries"]: + if "label" in data["libraries"][config_test_name]: + label = data["libraries"][config_test_name]["label"] + + # If a library entry in configure.json has a test, and + # the test uses a config.tests standalone project, we + # need to get the package and target info for the + # library, and pass it to the test so compiling and + # linking succeeds. + library_usage = get_library_usage_for_compile_test(config_test_name) + if "target_name" in library_usage: + libraries.append(library_usage["target_name"]) + if "package_name" in library_usage: + find_package_arguments = [] + find_package_arguments.append(library_usage["package_name"]) + if "extra" in library_usage: + find_package_arguments.extend(library_usage["extra"]) + package_line = "PACKAGE " + " ".join(find_package_arguments) + packages.append(package_line) + + cm_fh.write( + f""" +qt_config_compile_test("{config_test_name}" + LABEL "{label}" + PROJECT_PATH "${{CMAKE_CURRENT_SOURCE_DIR}}/{rel_test_project_path}" +""" + ) + if libraries: + libraries_string = " ".join(libraries) + cm_fh.write(f" LIBRARIES {libraries_string}\n") + if packages: + packages_string = " ".join(packages) + cm_fh.write(f" PACKAGES {packages_string}") + cm_fh.write(f")\n") + + def write_compile_test( ctx, name, details, data, cm_fh, manual_library_list=None, is_library_test=False ): @@ -514,15 +578,7 @@ def write_compile_test( print(f" XXXX Failed to locate inherited library test {inherited_test_name}") if isinstance(details, str): - rel_test_project_path = f"{ctx['test_dir']}/{details}" - if posixpath.exists(f"{ctx['project_dir']}/{rel_test_project_path}/CMakeLists.txt"): - cm_fh.write( - f""" -qt_config_compile_test("{details}" - LABEL "{data['label']}" - PROJECT_PATH "${{CMAKE_CURRENT_SOURCE_DIR}}/{rel_test_project_path}") -""" - ) + write_standalone_compile_test(cm_fh, ctx, data, details, is_library_test) return def resolve_head(detail): @@ -644,14 +700,12 @@ qt_config_compile_test("{details}" if len(library) == 0: continue - mapped_library = find_3rd_party_library_mapping(library) - if not mapped_library: - qmakeFixme += f"# FIXME: use: unmapped library: {library}\n" + library_usage = get_library_usage_for_compile_test(library) + if "fixme" in library_usage: + qmakeFixme += library_usage["fixme"] continue - if mapped_library.test_library_overwrite: - library_list.append(mapped_library.test_library_overwrite) else: - library_list.append(mapped_library.targetName) + library_list.append(library_usage["target_name"]) cm_fh.write(f"qt_config_compile_test({featureName(name)}\n") cm_fh.write(lineify("LABEL", data.get("label", ""))) diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index e496a2448d..8d1a62ddc9 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -3912,7 +3912,17 @@ def handle_config_test_project(scope: Scope, cm_fh: IO[str]): project_name = os.path.splitext(os.path.basename(scope.file_absolute_path))[0] content = ( f"cmake_minimum_required(VERSION 3.14.0)\n" - f"project(config_test_{project_name} LANGUAGES CXX)\n" + f"project(config_test_{project_name} LANGUAGES C CXX)\n" + """ +foreach(p ${QT_CONFIG_COMPILE_TEST_PACKAGES}) + find_package(${p}) +endforeach() + +if(QT_CONFIG_COMPILE_TEST_LIBRARIES) + link_libraries(${QT_CONFIG_COMPILE_TEST_LIBRARIES}) +endif() + +""" ) cm_fh.write(f"{content}\n") |