summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2019-05-17 14:22:57 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2019-05-20 13:15:16 +0000
commite4b8c488bd8b350f1a19874c4859ae2699afc747 (patch)
tree2c232002f97aae4f010e49c1dab09f8a9d9b4be5 /util
parent42c8c38564c11a86a553139f21322ad232ab5957 (diff)
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 <tobias.hunger@qt.io>
Diffstat (limited to 'util')
-rwxr-xr-xutil/cmake/configurejson2cmake.py24
-rw-r--r--util/cmake/helper.py39
2 files changed, 57 insertions, 6 deletions
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):
diff --git a/util/cmake/helper.py b/util/cmake/helper.py
index ee4274abd7..d9e9fd16e3 100644
--- a/util/cmake/helper.py
+++ b/util/cmake/helper.py
@@ -35,7 +35,8 @@ class LibraryMapping:
targetName: typing.Optional[str], *,
resultVariable: typing.Optional[str] = None,
extra: typing.List[str] = [],
- appendFoundSuffix: bool = True) -> None:
+ appendFoundSuffix: bool = True,
+ emit_if: str = '') -> None:
self.soName = soName
self.packageName = packageName
self.resultVariable = resultVariable
@@ -43,6 +44,10 @@ class LibraryMapping:
self.extra = extra
self.targetName = targetName
+ # if emit_if is non-empty, the generated find_package call
+ # for a library will be surrounded by this condition.
+ self.emit_if = emit_if
+
def is_qt(self) -> bool:
return self.packageName == 'Qt' \
or self.packageName == 'Qt5' \
@@ -172,6 +177,7 @@ _qt_library_map = [
# qtzlib: No longer supported.
]
+# Note that the library map is adjusted dynamically further down.
_library_map = [
# 3rd party:
LibraryMapping('atspi', 'ATSPI2', 'PkgConfig::ATSPI2'),
@@ -247,6 +253,20 @@ _library_map = [
]
+def _adjust_library_map():
+ # Assign a Linux condition on all x and wayland related packages.
+ # We don't want to get pages of package not found messages on
+ # Windows and macOS, and this also improves configure time on
+ # those platforms.
+ linux_package_prefixes = ['xcb', 'x11', 'xkb', 'xrender', 'xlib', 'wayland']
+ for i, _ in enumerate(_library_map):
+ if any([_library_map[i].soName.startswith(p) for p in linux_package_prefixes]):
+ _library_map[i].emit_if = 'config.linux'
+
+
+_adjust_library_map()
+
+
def find_3rd_party_library_mapping(soName: str) -> typing.Optional[LibraryMapping]:
for i in _library_map:
if i.soName == soName:
@@ -356,8 +376,10 @@ def map_3rd_party_library(lib: str) -> str:
return mapping.targetName + libpostfix
-def generate_find_package_info(lib: LibraryMapping, use_qt_find_package: bool=True, *,
- indent: int = 0) -> str:
+def generate_find_package_info(lib: LibraryMapping,
+ use_qt_find_package: bool=True, *,
+ indent: int = 0,
+ emit_if: str = '') -> str:
isRequired = False
extra = lib.extra.copy()
@@ -377,7 +399,8 @@ def generate_find_package_info(lib: LibraryMapping, use_qt_find_package: bool=Tr
extra += ['PROVIDED_TARGETS', cmake_target_name]
result = ''
- ind = ' ' * indent
+ one_ind = ' '
+ ind = one_ind * indent
if use_qt_find_package:
if extra:
@@ -393,4 +416,12 @@ def generate_find_package_info(lib: LibraryMapping, use_qt_find_package: bool=Tr
else:
result = '{}find_package({})\n'.format(ind, lib.packageName)
+ # If a package should be found only in certain conditions, wrap
+ # the find_package call within that condition.
+ if emit_if:
+ result = "if(({emit_if}) OR QT_FIND_ALL_PACKAGES_ALWAYS)\n" \
+ "{ind}{result}endif()\n".format(emit_if=emit_if,
+ result=result,
+ ind=one_ind)
+
return result