From e4b8c488bd8b350f1a19874c4859ae2699afc747 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Fri, 17 May 2019 14:22:57 +0200 Subject: Improve configure2cmake to find_package only in certain conditions It doesn't make much sense to look for X11 related packages on macOS and Windows by default. Usually they would not be there, and as a result the configuration step would show a long list of scary not found packages, and also eat precious configure time. Change the conversion script to allow putting conditions around generated find_package calls. These conditions can be manually set in the conversion script library mapping, using the emit_if argument, which we do for the X11 and Wayland related packages. They are also computed by checking which features use a given library, and if the feature is protected by a simple emitIf condition like config.linux, the relevant library find_package call will be protected by the same condition. If a developer still wishes to look for all packages, they can define the CACHE variable QT_FIND_ALL_PACKAGES_ALWAYS to ON. The relevant configure.cmake files are regenerated in this patch. Change-Id: I6f918a94f50257ec41d6216305dae9774933389a Reviewed-by: Tobias Hunger --- util/cmake/configurejson2cmake.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'util/cmake/configurejson2cmake.py') diff --git a/util/cmake/configurejson2cmake.py b/util/cmake/configurejson2cmake.py index 040e8ee7b4..d1646ed082 100755 --- a/util/cmake/configurejson2cmake.py +++ b/util/cmake/configurejson2cmake.py @@ -181,9 +181,29 @@ def parseLib(ctx, lib, data, cm_fh, cmake_find_packages_set): if newlib.targetName in cmake_find_packages_set: return + # If certain libraries are used within a feature, but the feature + # is only emitted conditionally with a simple condition (like + # 'on Windows' or 'on Linux'), we should enclose the find_package + # call for the library into the same condition. + emit_if = newlib.emit_if + + # Only look through features if a custom emit_if wasn't provided. + if not emit_if: + for feature in data['features']: + feature_data = data['features'][feature] + if 'condition' in feature_data and \ + 'libs.{}'.format(lib) in feature_data['condition'] and \ + 'emitIf' in feature_data and \ + 'config.' in feature_data['emitIf']: + emit_if = feature_data['emitIf'] + break + + if emit_if: + emit_if = map_condition(emit_if) + cmake_find_packages_set.add(newlib.targetName) - cm_fh.write(generate_find_package_info(newlib)) + cm_fh.write(generate_find_package_info(newlib, emit_if=emit_if)) def lineify(label, value, quote=True): @@ -890,7 +910,7 @@ def processLibraries(ctx, data, cm_fh): return for lib in data['libraries']: - parseLib(ctx, lib, data['libraries'][lib], cm_fh, cmake_find_packages_set) + parseLib(ctx, lib, data, cm_fh, cmake_find_packages_set) def processSubconfigs(dir, ctx, data): -- cgit v1.2.3