Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qt6: add ability to crossbuild #26529

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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