Skip to content

Commit

Permalink
Conan: Add optional ICU Conan package dependency
Browse files Browse the repository at this point in the history
If the "icu" option is passed for the build then add the optional
ICU Conan package dependency. The ICU version needs to be parsed
from a file which is provisioned by the Qt CI.

If the ICU version can not be parsed, e.g. if "conan export" is
being executed outside Qt CI machines, then use a fallback
version for it.

For the Qt build system to pick up the ICU dependency built
by Conan we need to pass the ICU package path via
CMAKE_PREFIX_PATH.

Pick-to: 6.2 6.3
Task-number: QTBUG-97072
Change-Id: I83059664c59dff68af76da8509e618442b530516
Reviewed-by: Toni Saario <[email protected]>
  • Loading branch information
iieklund committed Jan 18, 2022
1 parent 9198a9b commit f2230ea
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import os
import re
import json
import shutil
import subprocess
from functools import lru_cache
from pathlib import Path
Expand Down Expand Up @@ -328,11 +329,28 @@ def get_cmake_args_for_configure(self, conan_options: Options) -> List[Optional[
return ret


def add_cmake_prefix_path(conan_file: ConanFile, dep: str) -> None:
if dep not in conan_file.deps_cpp_info.deps:
raise QtConanError("Unable to find dependency: {0}".format(dep))
dep_cpp_info = conan_file.deps_cpp_info[dep]
cmake_args_str = str(conan_file.options.get_safe("cmake_args_qtbase", default=""))
_common = conan_file.python_requires["qt-conan-common"].module
formatted_cmake_args_str = _common.append_cmake_prefix_path(
cmake_args_str, dep_cpp_info.rootpath
)
print("Adjusted cmake args for qtbase build: {0}".format(formatted_cmake_args_str))
setattr(conan_file.options, "cmake_args_qtbase", formatted_cmake_args_str)


def _build_qtbase(conan_file: ConanFile):
# we call the Qt's configure(.bat) directly
script = Path("configure.bat") if tools.os_info.is_windows else Path("configure")
configure = Path(conan_file.build_folder).joinpath(script).resolve(strict=True)

if conan_file.options.get_safe("icu", default="no"):
# we need to tell Qt build system where to find the ICU
add_cmake_prefix_path(conan_file, dep="icu")

# convert the Conan options to Qt configure(.bat) arguments
parser = conan_file._qt_option_parser
qt_configure_options = parser.convert_conan_options_to_qt_options(conan_file.options)
Expand Down Expand Up @@ -372,7 +390,6 @@ class QtBase(ConanFile):
_qt_option_parser = QtOptionParser()
options = _qt_option_parser.get_qt_conan_options()
default_options = _qt_option_parser.get_default_qt_conan_options()
exports = "configure_options.json", "configure_features.txt", ".cmake.conf"
exports_sources = "*", "!conan*.*"
# use commit ID as the RREV (recipe revision)
revision_mode = "scm"
Expand All @@ -385,6 +402,42 @@ def set_version(self):
_prerelease = _parse_qt_version_by_key("QT_REPO_MODULE_PRERELEASE_VERSION_SEGMENT")
self.version = _ver + "-" + _prerelease if _prerelease else _ver

def export(self):
self.copy("configure_options.json")
self.copy("configure_features.txt")
self.copy(".cmake.conf")
_common = self.python_requires["qt-conan-common"].module
conf = _common.qt_sw_versions_config_folder() / _common.qt_sw_versions_config_name()
if not conf.exists():
# If using "conan export" outside Qt CI provisioned machines
print("Warning: Couldn't find '{0}'. 3rd party dependencies skipped.".format(conf))
else:
shutil.copy2(conf, self.export_folder)

def requirements(self):
parse_sw_req = self.python_requires["qt-conan-common"].module.parse_qt_sw_pkg_dependency
# list of tuples, (package_name, fallback version)
optional_requirements = [("icu", "56.1")]
for req_name, req_ver_fallback in optional_requirements:
if self.options.get_safe(req_name, default="no") == "yes":
# Note! If this conan package is being "conan export"ed outside Qt CI and the
# sw versions .ini file is not present then it will fall-back to default version
ver = parse_sw_req(
config_folder=Path(self.recipe_folder),
package_name=req_name,
target_os=str(self.settings.os),
)
if not ver:
print(
"Warning: Using fallback version '{0}' for: {1}".format(
req_name, req_ver_fallback
)
)
ver = req_ver_fallback
requirement = "{0}/{1}@qt/everywhere".format(req_name, ver)
print("Setting 3rd party package requirement: {0}".format(requirement))
self.requires(requirement)

def configure(self):
if self.settings.compiler == "gcc" and tools.Version(self.settings.compiler.version) < "8":
raise ConanInvalidConfiguration("Qt6 does not support GCC before 8")
Expand Down

0 comments on commit f2230ea

Please sign in to comment.