CMake: scripts: Extract code to write find_package lines

Extract code to write find_package lines from configurejson2cmake.py
and move this over into helper.py.

Change-Id: Iefd313b2a56cb78a99a7f3151c3f6c6284482f79
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Tobias Hunger 2019-05-09 10:51:27 +02:00
parent 80e0c615a9
commit 862ebbf7ea
2 changed files with 42 additions and 25 deletions

View File

@ -33,7 +33,8 @@ import re
import sys
from typing import Set, Union, List, Dict
from helper import map_qt_library, featureName, map_platform, find_3rd_party_library_mapping
from helper import map_qt_library, featureName, map_platform, \
find_3rd_party_library_mapping, generate_find_package_info
knownTests = set() # type: Set[str]
@ -182,31 +183,8 @@ def parseLib(ctx, lib, data, cm_fh, cmake_find_packages_set):
cmake_find_packages_set.add(newlib.targetName)
isRequired = False
cm_fh.write(generate_find_package_info(newlib))
extra = newlib.extra.copy()
if extra:
if "REQUIRED" in extra:
isRequired = True
extra.remove("REQUIRED")
cmake_target_name = newlib.targetName
# _nolink or not does not matter at this point:
if cmake_target_name.endswith('_nolink') or cmake_target_name.endswith('/nolink'):
cmake_target_name = cmake_target_name[:-7]
if cmake_target_name:
extra += ['PROVIDED_TARGETS', cmake_target_name]
if extra:
cm_fh.write('qt_find_package({} {})\n'.format(newlib.packageName, ' '.join(extra)))
else:
cm_fh.write('qt_find_package({})\n'.format(newlib.packageName))
if isRequired:
cm_fh.write('set_package_properties({} PROPERTIES TYPE REQUIRED)\n'.format(newlib.packageName))
def lineify(label, value, quote=True):
if value:

View File

@ -338,3 +338,42 @@ def map_3rd_party_library(lib: str) -> str:
if not mapping or not mapping.targetName:
return lib
return mapping.targetName + libpostfix
def generate_find_package_info(lib: LibraryMapping, use_qt_find_package: bool=True, *,
indent: int = 0) -> str:
isRequired = False
extra = lib.extra.copy()
if "REQUIRED" in extra and use_qt_find_package:
isRequired = True
extra.remove("REQUIRED")
cmake_target_name = lib.targetName
# _nolink or not does not matter at this point:
if cmake_target_name.endswith('_nolink') or cmake_target_name.endswith('/nolink'):
cmake_target_name = cmake_target_name[:-7]
if cmake_target_name and use_qt_find_package:
extra += ['PROVIDED_TARGETS', cmake_target_name]
result = ''
ind = ' ' * indent
if use_qt_find_package:
if extra:
result = '{}qt_find_package({} {})\n'.format(ind, lib.packageName, ' '.join(extra))
else:
result = '{}qt_find_package({})\n'.format(ind, lib.packageName)
if isRequired:
result += '{}set_package_properties({} PROPERTIES TYPE REQUIRED)\n'.format(ind, lib.packageName)
else:
if extra:
result = '{}find_package({} {})\n'.format(ind, lib.packageName, ' '.join(extra))
else:
result = '{}find_package({})\n'.format(ind, lib.packageName)
return result