Skip to content

Commit

Permalink
Conan: Improve 'QT_HOST_PATH' handling in build recipe
Browse files Browse the repository at this point in the history
If cross-building pass the '-o qt_host_path=/foo' option into
'-DQT_HOST_PATH=/foo' for CMake so the user should not need to export
that in the environment explicitly.

The signature of 'append_cmake_prefix_path()' was changed to
'append_cmake_arg()' as the same functionality can be utilized
for any CMake argument in the recipes.

Pick-to: 6.3
Change-Id: I700d0acc86debbb8ee670330c22c167f3a585a3d
Reviewed-by: Alexandru Croitor <[email protected]>
  • Loading branch information
iieklund committed May 19, 2022
1 parent e3201e7 commit 13d1a60
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def add_cmake_prefix_path(conan_file: ConanFile, dep: str) -> None:
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=""))
formatted_cmake_args_str = conan_file._shared.append_cmake_prefix_path(
cmake_args_str, dep_cpp_info.rootpath
formatted_cmake_args_str = conan_file._shared.append_cmake_arg(
cmake_args_str, "CMAKE_PREFIX_PATH", 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)
Expand Down Expand Up @@ -128,6 +128,14 @@ def requirements(self):
print("Setting 3rd party package requirement: {0}".format(requirement))
self.requires(requirement)

def _resolve_qt_host_path(self) -> str:
# When cross-building the user needs to pass 'qt_host_path' which is transformed to
# QT_HOST_PATH later on. Resolve the exact path.
qt_host_path = self.options.get_safe("qt_host_path")
if qt_host_path is None:
raise QtConanError("Expected 'qt_host_path' option in cross-build context")
return str(Path(os.path.expandvars(str(qt_host_path))).expanduser().resolve(strict=True))

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 Expand Up @@ -214,6 +222,14 @@ def _check_mutually_exclusive_options(options: Dict[str, bool]) -> None:
else:
raise QtConanError("Unknown build_type: {0}".format(self.settings.build_type))

if tools.cross_building(conanfile=self):
# pass the QT_HOST_PATH as CMake argument so the user does not need to export it
cmake_args_qtbase = str(self.options.get_safe("cmake_args_qtbase", default=""))
formatted_cmake_args_qtbase = self._shared.append_cmake_arg(
cmake_args_qtbase, "QT_HOST_PATH", self._resolve_qt_host_path()
)
setattr(self.options, "cmake_args_qtbase", formatted_cmake_args_qtbase)

if self.settings.os == "Android":
if self.options.get_safe("android_sdk_version") == None:
cmake_args_qtbase = str(self.options.get_safe("cmake_args_qtbase"))
Expand Down Expand Up @@ -241,13 +257,7 @@ def package(self):
def package_info(self):
self._shared.package_info(self)
if tools.cross_building(conanfile=self):
qt_host_path = self.options.get_safe("qt_host_path")
if qt_host_path is None:
raise QtConanError("Unable to cross-compile, 'qt_host_path' option missing?")
resolved_qt_host_path = str(
Path(os.path.expandvars(str(qt_host_path))).expanduser().resolve(strict=True)
)
self.env_info.QT_HOST_PATH.append(resolved_qt_host_path)
self.env_info.QT_HOST_PATH.append(self._resolve_qt_host_path())

def package_id(self):
# https://docs.conan.io/en/latest/creating_packages/define_abi_compatibility.html
Expand Down

0 comments on commit 13d1a60

Please sign in to comment.