CMake: pro2cmake.py: Fix library mapping

Fix library substitution again which broke when I merged all the
library related pieces of information.

Keep Qt and 3rdparty libraries separate so that dbus does not get
mapped into Qt::DBus (or the other way around).

Make names in helper.py more consistent while at it.

Change-Id: I5e5bf02bdabf8bafe991c5701deca76bde4df2c3
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Tobias Hunger 2019-05-06 12:26:31 +02:00
parent f26a156dd3
commit 059f4ade7f
3 changed files with 45 additions and 29 deletions

View File

@ -33,7 +33,7 @@ import re
import sys
from typing import Set, Union, List, Dict
from helper import map_qt_library, featureName, substitute_platform, find_library_mapping
from helper import map_qt_library, featureName, map_platform, find_3rd_party_library_mapping
knownTests = set() # type: Set[str]
@ -165,7 +165,7 @@ def processFiles(ctx, data):
return ctx
def parseLib(ctx, lib, data, cm_fh, cmake_find_packages_set):
newlib = find_library_mapping(lib)
newlib = find_3rd_party_library_mapping(lib)
if not newlib:
print(' XXXX Unknown library "{}".'.format(lib))
return
@ -174,7 +174,7 @@ def parseLib(ctx, lib, data, cm_fh, cmake_find_packages_set):
print(' **** Skipping library "{}" -- was masked.'.format(lib))
return
print(' mapped library {} to {}.'.format(lib, newlib))
print(' mapped library {} to {}.'.format(lib, newlib.targetName))
# Avoid duplicate find_package calls.
if newlib.targetName in cmake_find_packages_set:
@ -251,7 +251,7 @@ def map_condition(condition):
substitution = None
appendFoundSuffix = True
if match.group(1) == 'libs':
libmapping = find_library_mapping(match.group(2))
libmapping = find_3rd_party_library_mapping(match.group(2))
if libmapping and libmapping.packageName:
substitution = libmapping.packageName
@ -282,7 +282,7 @@ def map_condition(condition):
substitution = 'INPUT_{}'.format(featureName(match.group(2)))
elif match.group(1) == 'config':
substitution = substitute_platform(match.group(2))
substitution = map_platform(match.group(2))
elif match.group(1) == 'arch':
if match.group(2) == 'i386':

View File

@ -67,7 +67,7 @@ _qt_library_map = [
LibraryMapping('core', 'Qt5', 'Qt::Core', extra = ['COMPONENTS', 'Core']),
LibraryMapping('coretest', 'Qt5', 'Qt::3DCoreTest', extra = ['COMPONENTS', '3DCoreTest']),
LibraryMapping('crypto-lib', 'Qt5', 'Qt::AppManCrypto', extra = ['COMPONENTS', 'AppManCrypto']),
LibraryMapping('dbus', 'Qt5', 'Qt::Dbus', extra = ['COMPONENTS', 'DBus']),
LibraryMapping('dbus', 'Qt5', 'Qt::DBus', extra = ['COMPONENTS', 'DBus']),
LibraryMapping('devicediscovery', 'Qt5', 'Qt::DeviceDiscoverySupport', extra = ['COMPONENTS', 'DeviceDiscoverySupport']),
LibraryMapping('devicediscovery_support', 'Qt5', 'Qt::DeviceDiscoverySupport', extra = ['COMPONENTS', 'DeviceDiscoverySupport']),
LibraryMapping('edid', 'Qt5', 'Qt::EdidSupport', extra = ['COMPONENTS', 'EdidSupport']),
@ -189,10 +189,11 @@ _library_map = [
LibraryMapping('host_dbus', None, None),
LibraryMapping('icu', 'ICU', 'ICU::i18n ICU::uc ICU::data', extra=['COMPONENTS', 'i18n', 'uc', 'data']),
LibraryMapping('journald', 'Libsystemd', 'PkgConfig::Libsystemd'),
LibraryMapping('jpeg', 'JPEG', 'JPEG::JPEG'), # see also libjpeg
LibraryMapping('libatomic', 'Atomic', 'Atomic'),
LibraryMapping('libdl', None, None),
LibraryMapping('libdl', None, '${CMAKE_DL_LIBS}'),
LibraryMapping('libinput', 'Libinput', 'Libinput::Libinput'),
LibraryMapping('libjpeg', 'JPEG', 'JPEG::JPEG'),
LibraryMapping('libjpeg', 'JPEG', 'JPEG::JPEG'), # see also jpeg
LibraryMapping('libpng', 'PNG', 'PNG::PNG'),
LibraryMapping('libproxy', 'Libproxy', 'PkgConfig::Libproxy'),
LibraryMapping('librt', 'WrapRt','WrapRt'),
@ -246,7 +247,7 @@ _library_map = [
]
def find_library_mapping(soName: str) -> typing.Optional[LibraryMapping]:
def find_3rd_party_library_mapping(soName: str) -> typing.Optional[LibraryMapping]:
for i in _library_map:
if i.soName == soName:
return i
@ -272,6 +273,7 @@ def map_qt_library(lib: str) -> str:
mapped = find_qt_library_mapping(lib)
qt_name = lib
if mapped:
assert mapped.targetName # Qt libs must have a target name set
qt_name = mapped.targetName
if private:
qt_name += 'Private'
@ -314,19 +316,25 @@ platform_mapping = {
}
def substitute_platform(platform: str) -> str:
def map_platform(platform: str) -> str:
""" Return the qmake platform as cmake platform or the unchanged string. """
return platform_mapping.get(platform, platform)
def substitute_libs(lib: str) -> str:
def is_known_3rd_party_library(lib: str) -> bool:
if lib.endswith('/nolink') or lib.endswith('_nolink'):
lib = lib[:-7]
mapping = find_3rd_party_library_mapping(lib)
return mapping is not None and mapping.targetName is not None
def map_3rd_party_library(lib: str) -> str:
libpostfix = ''
if lib.endswith('/nolink'):
lib = lib[:-7]
libpostfix = '_nolink'
mapping = find_qt_library_mapping(lib)
if not mapping:
mapping = find_library_mapping(lib)
if not mapping:
return lib + libpostfix
mapping = find_3rd_party_library_mapping(lib)
if not mapping or not mapping.targetName:
return lib
return mapping.targetName + libpostfix

View File

@ -42,8 +42,8 @@ import typing
from sympy.logic import (simplify_logic, And, Or, Not,)
import pyparsing as pp
from helper import map_qt_library, featureName, \
substitute_platform, substitute_libs
from helper import map_qt_library, map_3rd_party_library, is_known_3rd_party_library, \
featureName, map_platform
def _parse_commandline():
@ -810,15 +810,14 @@ def map_condition(condition: str) -> str:
part = 'TARGET {}'.format(map_qt_library(feature.group(2)))
else:
feature = featureName(feature.group(2))
if feature.startswith('system_') and substitute_libs(feature[7:]) != feature[7:]:
# Qt6 always uses system libraries!
if feature.startswith('system_') and is_known_3rd_party_library(feature[7:]):
part = 'ON'
elif feature == 'dlopen':
part = 'ON'
else:
part = 'QT_FEATURE_' + feature
else:
part = substitute_platform(part)
part = map_platform(part)
part = part.replace('true', 'ON')
part = part.replace('false', 'OFF')
@ -939,7 +938,9 @@ def write_library_list(cm_fh: typing.IO[str], cmake_keyword: str,
if d.startswith('-'):
d = '# Remove: {}'.format(d[1:])
else:
d = substitute_libs(d)
d = map_3rd_party_library(d)
if not d or d in dependencies_to_print:
continue
dependencies_to_print.append(d)
is_framework = False
@ -954,18 +955,24 @@ def write_library_list(cm_fh: typing.IO[str], cmake_keyword: str,
def write_library_section(cm_fh: typing.IO[str], scope: Scope,
public: typing.List[str],
private: typing.List[str],
mixed: typing.List[str], *,
qt_private: typing.List[str],
qt_mixed: typing.List[str], *,
indent: int = 0, known_libraries=set()):
public_dependencies = [] # typing.List[str]
private_dependencies = [] # typing.List[str]
public_dependencies = [] # type: typing.List[str]
private_dependencies = [] # type: typing.List[str]
for key in public:
public_dependencies += [map_qt_library(q) for q in scope.expand(key)
if map_qt_library(q) not in known_libraries]
public_dependencies += [q for q in scope.expand(key)
if q not in known_libraries]
for key in private:
private_dependencies += [q for q in scope.expand(key)
if q not in known_libraries]
for key in qt_private:
private_dependencies += [map_qt_library(q) for q in scope.expand(key)
if map_qt_library(q) not in known_libraries]
for key in mixed:
for key in qt_mixed:
for lib in scope.expand(key):
mapped_lib = map_qt_library(lib)
if mapped_lib in known_libraries:
@ -1028,7 +1035,8 @@ def write_sources_section(cm_fh: typing.IO[str], scope: Scope, *,
write_library_section(cm_fh, scope,
['QMAKE_USE', 'LIBS'],
['QT_FOR_PRIVATE', 'QMAKE_USE_PRIVATE', 'QMAKE_USE_FOR_PRIVATE', 'LIBS_PRIVATE'],
['QMAKE_USE_PRIVATE', 'QMAKE_USE_FOR_PRIVATE', 'LIBS_PRIVATE'],
['QT_FOR_PRIVATE',],
['QT',],
indent=indent, known_libraries=known_libraries)