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 use bundled dependencies and option to disable features. #9254

Closed
wants to merge 8 commits into from
98 changes: 62 additions & 36 deletions recipes/qt/6.x.x/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,23 @@ class QtConan(ConanFile):
homepage = "https://www.qt.io"
license = "LGPL-3.0"
settings = "os", "arch", "compiler", "build_type"
provides = []

options = {
"shared": [True, False],
"opengl": ["no", "desktop", "dynamic"],
"with_vulkan": [True, False],
"openssl": [True, False],
"with_pcre2": [True, False],
"with_pcre2": [True, False, "qt"],
"with_glib": [True, False],
"with_doubleconversion": [True, False],
"with_freetype": [True, False],
"with_doubleconversion": [True, False, "qt"],
"with_freetype": [True, False, "qt"],
"with_fontconfig": [True, False],
"with_icu": [True, False],
"with_harfbuzz": [True, False],
"with_libjpeg": ["libjpeg", "libjpeg-turbo", False],
"with_libpng": [True, False],
"with_sqlite3": [True, False],
"with_harfbuzz": [True, False, "qt"],
"with_libjpeg": ["libjpeg", "libjpeg-turbo", False, "qt"],
"with_libpng": [True, False, "qt"],
"with_sqlite3": [True, False, "qt"],
"with_mysql": [True, False],
"with_pq": [True, False],
"with_odbc": [True, False],
Expand All @@ -91,6 +92,7 @@ class QtConan(ConanFile):
"cross_compile": "ANY",
"sysroot": "ANY",
"multiconfiguration": [True, False],
"disabled_features": "ANY",
}
options.update({module: [True, False] for module in _submodules})

Expand Down Expand Up @@ -130,6 +132,7 @@ class QtConan(ConanFile):
"cross_compile": None,
"sysroot": None,
"multiconfiguration": False,
"disabled_features": "",
}
default_options.update({module: False for module in _submodules})

Expand Down Expand Up @@ -164,6 +167,10 @@ def _get_module_tree(self):

return self._submodules_tree

def _with_conan_dependency(self, dep):
option = self.options.get_safe(dep, False)
return option and option != "qt"

def export_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
Expand Down Expand Up @@ -230,6 +237,16 @@ def _enablemodule(mod):
if self.options.get_safe(module):
_enablemodule(module)

for opt, dep in [("with_doubleconversion", "double-conversion"),
("with_freetype", "freetype"),
("with_harfbuzz", "harfbuzz"),
("with_libjpeg", "libjpeg"),
("with_libpng", "libpng"),
("with_sqlite3", "sqlite3"),
("with_pcre2", "pcre2")]:
if self.options.get_safe(opt, False) == "qt":
self.provides.append(dep)

def validate(self):
# C++ minimum standard required
if self.settings.compiler.get_safe("cppstd"):
Expand Down Expand Up @@ -259,7 +276,7 @@ def validate(self):
if self.settings.os != "Windows" and self.options.get_safe("opengl", "no") == "dynamic":
raise ConanInvalidConfiguration("Dynamic OpenGL is supported only on Windows.")

if self.options.get_safe("with_fontconfig", False) and not self.options.get_safe("with_freetype", False):
if self.options.get_safe("with_fontconfig", False) and not self._with_conan_dependency("with_freetype"):
raise ConanInvalidConfiguration("with_fontconfig cannot be enabled if with_freetype is disabled.")

if "MT" in self.settings.get_safe("compiler.runtime", default="") and self.options.shared:
Expand All @@ -273,32 +290,32 @@ def requirements(self):
self.requires("zlib/1.2.11")
if self.options.openssl:
self.requires("openssl/1.1.1m")
if self.options.with_pcre2:
if self._with_conan_dependency("with_pcre2"):
self.requires("pcre2/10.37")
if self.options.get_safe("with_vulkan"):
self.requires("vulkan-loader/1.2.182")
if tools.is_apple_os(self.settings.os):
self.requires("moltenvk/1.1.4")
if self.options.with_glib:
self.requires("glib/2.70.1")
if self.options.with_doubleconversion and not self.options.multiconfiguration:
if self._with_conan_dependency("with_doubleconversion") and not self.options.multiconfiguration:
self.requires("double-conversion/3.1.7")
if self.options.get_safe("with_freetype", False) and not self.options.multiconfiguration:
if self._with_conan_dependency("with_freetype") and not self.options.multiconfiguration:
self.requires("freetype/2.11.0")
if self.options.get_safe("with_fontconfig", False):
self.requires("fontconfig/2.13.93")
if self.options.get_safe("with_icu", False):
self.requires("icu/70.1")
if self.options.get_safe("with_harfbuzz", False) and not self.options.multiconfiguration:
if self._with_conan_dependency("with_harfbuzz") and not self.options.multiconfiguration:
self.requires("harfbuzz/3.2.0")
if self.options.get_safe("with_libjpeg", False) and not self.options.multiconfiguration:
if self.options.with_libjpeg == "libjpeg-turbo":
self.requires("libjpeg-turbo/2.1.2")
else:
elif self.options.with_libjpeg == "libjpeg":
self.requires("libjpeg/9d")
if self.options.get_safe("with_libpng", False) and not self.options.multiconfiguration:
if self._with_conan_dependency("with_libpng") and not self.options.multiconfiguration:
self.requires("libpng/1.6.37")
if self.options.with_sqlite3 and not self.options.multiconfiguration:
if self._with_conan_dependency("with_sqlite3") and not self.options.multiconfiguration:
self.requires("sqlite3/3.37.2")
self.options["sqlite3"].enable_column_metadata = True
if self.options.get_safe("with_mysql", False):
Expand Down Expand Up @@ -572,22 +589,26 @@ def _configure_cmake(self):
self._cmake.definitions["FEATURE_%s" % conf_arg] = ("ON" if self.options.get_safe(opt, False) else "OFF")


for opt, conf_arg in [
("with_doubleconversion", "doubleconversion"),
("with_freetype", "freetype"),
("with_harfbuzz", "harfbuzz"),
("with_libjpeg", "jpeg"),
("with_libpng", "png"),
("with_sqlite3", "sqlite"),
("with_pcre2", "pcre2"),]:
for opt, feature, conf_arg in [
("with_doubleconversion", "doubleconversion", "doubleconversion"),
("with_freetype", "freetype", "freetype"),
("with_harfbuzz", "harfbuzz", "harfbuzz"),
("with_libjpeg", "jpeg", "jpeg"),
("with_libpng", "png", "png"),
("with_sqlite3", "sqlite", "sql_sqlite"),
("with_pcre2", "pcre2", "pcre2")]:
if self.options.get_safe(opt, False):
if self.options.multiconfiguration:
self._cmake.definitions["FEATURE_%s" % conf_arg] = "ON"
self._cmake.definitions["FEATURE_%s" % conf_arg] = "ON"
if self.options.multiconfiguration or self.options.get_safe(opt, False) == "qt":
self._cmake.definitions["FEATURE_system_%s" % feature] = "OFF"
else:
self._cmake.definitions["FEATURE_system_%s" % conf_arg] = "ON"
self._cmake.definitions["FEATURE_system_%s" % feature] = "ON"
else:
self._cmake.definitions["FEATURE_%s" % conf_arg] = "OFF"
self._cmake.definitions["FEATURE_system_%s" % conf_arg] = "OFF"
self._cmake.definitions["FEATURE_system_%s" % feature] = "OFF"

for feature in str(self.options.disabled_features).split(" "):
self._cmake.definitions["FEATURE_%s" % feature] = "OFF"

if self.settings.os == "Macos":
self._cmake.definitions["FEATURE_framework"] = "OFF"
Expand Down Expand Up @@ -779,6 +800,9 @@ def _create_private_module(module, dependencies=[]):
if self.options.gui:
_create_private_module("Gui", ["CorePrivate", "Gui"])

if self.options.widgets:
_create_private_module("Widgets", ["CorePrivate", "GuiPrivate", "Widgets"])

if self.options.qtdeclarative:
_create_private_module("Qml", ["CorePrivate", "Qml"])

Expand Down Expand Up @@ -853,9 +877,9 @@ def _create_plugin(pluginname, libname, type, requires):
self.cpp_info.components[componentname].requires = _get_corrected_reqs(requires)

core_reqs = ["zlib::zlib"]
if self.options.with_pcre2:
if self._with_conan_dependency("with_pcre2"):
core_reqs.append("pcre2::pcre2")
if self.options.with_doubleconversion:
if self._with_conan_dependency("with_doubleconversion"):
core_reqs.append("double-conversion::double-conversion")
if self.options.get_safe("with_icu", False):
core_reqs.append("icu::icu")
Expand All @@ -877,9 +901,9 @@ def _create_plugin(pluginname, libname, type, requires):
gui_reqs = []
if self.options.with_dbus:
gui_reqs.append("DBus")
if self.options.with_freetype:
if self._with_conan_dependency("with_freetype"):
gui_reqs.append("freetype::freetype")
if self.options.with_libpng:
if self._with_conan_dependency("with_libpng"):
gui_reqs.append("libpng::libpng")
if self.options.get_safe("with_fontconfig", False):
gui_reqs.append("fontconfig::fontconfig")
Expand All @@ -893,14 +917,17 @@ def _create_plugin(pluginname, libname, type, requires):
gui_reqs.append("vulkan-loader::vulkan-loader")
if tools.is_apple_os(self.settings.os):
gui_reqs.append("moltenvk::moltenvk")
if self.options.with_harfbuzz:
if self._with_conan_dependency("with_harfbuzz"):
gui_reqs.append("harfbuzz::harfbuzz")
if self.options.with_libjpeg == "libjpeg-turbo":
gui_reqs.append("libjpeg-turbo::libjpeg-turbo")
if self.options.with_libjpeg == "libjpeg":
gui_reqs.append("libjpeg::libjpeg")
_create_module("Gui", gui_reqs)

self.cpp_info.components["qtGui"].build_modules["cmake_find_package"].append(self._cmake_qt6_private_file("Gui"))
self.cpp_info.components["qtGui"].build_modules["cmake_find_package_multi"].append(self._cmake_qt6_private_file("Gui"))

if self.settings.os == "Windows":
_create_plugin("QWindowsIntegrationPlugin", "qwindows", "platforms", ["Core", "Gui"])
self.cpp_info.components["qtQWindowsIntegrationPlugin"].system_libs = ["advapi32", "dwmapi", "gdi32", "imm32",
Expand All @@ -925,7 +952,7 @@ def _create_plugin(pluginname, libname, type, requires):
_create_plugin("QXcbIntegrationPlugin", "qxcb", "platforms", ["Core", "Gui", "XcbQpaPrivate"])

if self.options.with_sqlite3:
_create_plugin("QSQLiteDriverPlugin", "qsqlite", "sqldrivers", ["sqlite3::sqlite3"])
_create_plugin("QSQLiteDriverPlugin", "qsqlite", "sqldrivers", ["sqlite3::sqlite3"] if self._with_conan_dependency("with_sqlite3") else [])
if self.options.with_pq:
_create_plugin("QPSQLDriverPlugin", "qsqlpsql", "sqldrivers", ["libpq::libpq"])
if self.options.with_odbc:
Expand All @@ -941,6 +968,8 @@ def _create_plugin(pluginname, libname, type, requires):
_create_module("Test")
if self.options.widgets:
_create_module("Widgets", ["Gui"])
self.cpp_info.components["qtWidgets"].build_modules["cmake_find_package"].append(self._cmake_qt6_private_file("Widgets"))
self.cpp_info.components["qtWidgets"].build_modules["cmake_find_package_multi"].append(self._cmake_qt6_private_file("Widgets"))
if self.options.gui and self.options.widgets:
_create_module("PrintSupport", ["Gui", "Widgets"])
if self.options.get_safe("opengl", "no") != "no" and self.options.gui:
Expand Down Expand Up @@ -1207,9 +1236,6 @@ def _create_plugin(pluginname, libname, type, requires):
self.cpp_info.components["qtCore"].build_modules["cmake_find_package"].append(self._cmake_entry_point_file)
self.cpp_info.components["qtCore"].build_modules["cmake_find_package_multi"].append(self._cmake_entry_point_file)

self.cpp_info.components["qtGui"].build_modules["cmake_find_package"].append(self._cmake_qt6_private_file("Gui"))
self.cpp_info.components["qtGui"].build_modules["cmake_find_package_multi"].append(self._cmake_qt6_private_file("Gui"))

for m in os.listdir(os.path.join("lib", "cmake")):
module = os.path.join("lib", "cmake", m, "%sMacros.cmake" % m)
component_name = m.replace("Qt6", "qt")
Expand Down