Skip to content

Commit

Permalink
qt6: add ability to crossbuild (#26529)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcar87 authored Feb 5, 2025
1 parent 281c563 commit f0671ac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
19 changes: 10 additions & 9 deletions recipes/qt/6.x.x/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,6 @@ def configure(self):
self.output.debug(f"qt6 option: {option}")

def validate_build(self):
if cross_building(self):
raise ConanInvalidConfiguration("cross compiling qt 6 is not yet supported. Contributions are welcome")

check_min_cppstd(self, 17)

def validate(self):
Expand Down Expand Up @@ -624,7 +621,12 @@ def generate(self):
if self.options.cross_compile:
tc.variables["QT_QMAKE_DEVICE_OPTIONS"] = f"CROSS_COMPILE={self.options.cross_compile}"
if cross_building(self):
tc.variables["QT_HOST_PATH"] = self.dependencies.direct_build["qt"].package_folder
# Mainly to locate Qt6HostInfoConfig.cmake
tc.cache_variables["QT_HOST_PATH"] = self.dependencies.direct_build["qt"].package_folder
# Stand-in for Qt6CoreTools - which is loaded for the executable targets
tc.cache_variables["CMAKE_PROJECT_Qt_INCLUDE"] = os.path.join(self.dependencies.direct_build["qt"].package_folder, self._cmake_executables_file)
# Ensure tools for host are always built
tc.cache_variables["QT_FORCE_BUILD_TOOLS"] = True

tc.variables["FEATURE_pkg_config"] = "ON"
if self.settings.compiler == "gcc" and self.settings.build_type == "Debug" and not self.options.shared:
Expand Down Expand Up @@ -663,8 +665,6 @@ def package_id(self):
self.info.settings.compiler.runtime = "MT/MTd"
elif self.info.settings.compiler == "msvc":
self.info.settings.compiler.runtime_type = "Release/Debug"
if self.info.settings.os == "Android":
del self.info.options.android_sdk

def source(self):
destination = self.source_folder
Expand Down Expand Up @@ -835,7 +835,7 @@ def package(self):
rmdir(self, os.path.join(self.package_folder, "licenses", module))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
for mask in ["Find*.cmake", "*Config.cmake", "*-config.cmake"]:
rm(self, mask, self.package_folder, recursive=True)
rm(self, mask, self.package_folder, recursive=True, excludes="Qt6HostInfoConfig.cmake")
rm(self, "*.la*", os.path.join(self.package_folder, "lib"), recursive=True)
rm(self, "*.pdb*", self.package_folder, recursive=True)
rm(self, "ensure_pro_file.cmake", self.package_folder, recursive=True)
Expand All @@ -850,7 +850,8 @@ def package(self):
if os.path.isfile(os.path.join(self.package_folder, "lib", "cmake", m, f"{m[:-5]}Macros.cmake")):
continue

rmdir(self, os.path.join(self.package_folder, "lib", "cmake", m))
if m != "Qt6HostInfo":
rmdir(self, os.path.join(self.package_folder, "lib", "cmake", m))

extension = ""
if self.settings.os == "Windows":
Expand All @@ -862,7 +863,7 @@ def package(self):
filecontents += f"set(QT_VERSION_PATCH {ver.patch})\n"
if self.settings.os == "Macos":
filecontents += 'set(__qt_internal_cmake_apple_support_files_path "${CMAKE_CURRENT_LIST_DIR}/../../../lib/cmake/Qt6/macos")\n'
targets = ["moc", "rcc", "tracegen", "cmake_automoc_parser", "qlalr", "qmake"]
targets = ["moc", "qlalr", "rcc", "tracegen", "cmake_automoc_parser", "qmake", "qtpaths", "syncqt", "tracepointgen"]
if self.options.with_dbus:
targets.extend(["qdbuscpp2xml", "qdbusxml2cpp"])
if self.options.gui:
Expand Down
12 changes: 10 additions & 2 deletions recipes/qt/6.x.x/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.env import VirtualRunEnv
from conan.tools.files import copy, save


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualBuildEnv"
generators = "CMakeDeps", "VirtualBuildEnv"
test_type = "explicit"

def layout(self):
Expand All @@ -21,12 +21,20 @@ def requirements(self):
def build_requirements(self):
if not can_run(self):
self.tool_requires(self.tested_reference_str)
self.tool_requires("cmake/[>=3.27 <4]")

def generate(self):
path = self.dependencies["qt"].package_folder.replace("\\", "/")
save(self, "qt.conf", f"""[Paths]
Prefix = {path}""")

tc = CMakeToolchain(self)
if 'qt' in self.dependencies.build:
qt_tools_rootdir = self.conf.get("user.qt:tools_directory", None)
for tool in ["moc", "rcc", "uic"]:
tc.cache_variables[f"CMAKE_AUTO{tool.upper()}_EXECUTABLE"] = os.path.join(qt_tools_rootdir, f"{tool}.exe" if self.settings_build.os == "Windows" else tool)
tc.generate()

VirtualRunEnv(self).generate()
if can_run(self):
VirtualRunEnv(self).generate(scope="build")
Expand Down

0 comments on commit f0671ac

Please sign in to comment.