Skip to content

Commit

Permalink
(#20093) qt5: fix build with apple-clang 15 + add package_type + bump…
Browse files Browse the repository at this point in the history
… deps + use version range for zlib

* fix qmake build with apple-clang 15

* fix build with apple-clang 15 when deployment target of macOS is < 14

see https://bugreports.qt.io/browse/QTBUG-114316

* improve robustness of macOS builds when deps are shared

* add package_type

* use is_msvc_static_runtime()

* use host_version for wayland in build requirements

* bump dependencies + use version range for zlib

* decrease min conan v2 version, 2.0.5 is enough for <host_version>

* adapt patches to each version

* bump dependencies

* also patch 5.15.11
  • Loading branch information
SpaceIm authored Oct 26, 2023
1 parent 62ca891 commit 79c5a17
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 33 deletions.
50 changes: 50 additions & 0 deletions recipes/qt/5.x.x/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ patches:
"patch_file": "patches/android-openssl.diff"
- "base_path": "qt5/qtbase"
"patch_file": "patches/android-new-ndk.diff"
- patch_file: "patches/5.15.8-fix-qmake-default-libdirs-apple-clang-15.patch"
base_path: "qt5/qtbase"
patch_description: "Fix qmake build with apple-clang>=15"
patch_type: "portability"
patch_source: "https://codereview.qt-project.org/c/qt/qtbase/+/503916"
- patch_file: "patches/5.15.10-fix-macos-cpp-lib-memory-resource.patch"
base_path: "qt5/qtbase"
patch_description: "Fix usage of memory_resource with apple-clang>=15 and deployment target of macOS < 14"
patch_type: "portability"
patch_source: "https://codereview.qt-project.org/c/qt/qtbase/+/482392"
"5.15.10":
- "base_path": "qt5/qtbase"
"patch_file": "patches/aa2a39dea5.diff"
Expand All @@ -121,6 +131,16 @@ patches:
"patch_file": "patches/android-openssl.diff"
- "base_path": "qt5/qtbase"
"patch_file": "patches/android-new-ndk.diff"
- patch_file: "patches/5.15.8-fix-qmake-default-libdirs-apple-clang-15.patch"
base_path: "qt5/qtbase"
patch_description: "Fix qmake build with apple-clang>=15"
patch_type: "portability"
patch_source: "https://codereview.qt-project.org/c/qt/qtbase/+/503916"
- patch_file: "patches/5.15.10-fix-macos-cpp-lib-memory-resource.patch"
base_path: "qt5/qtbase"
patch_description: "Fix usage of memory_resource with apple-clang>=15 and deployment target of macOS < 14"
patch_type: "portability"
patch_source: "https://codereview.qt-project.org/c/qt/qtbase/+/482392"
"5.15.9":
- "base_path": "qt5/qtbase"
"patch_file": "patches/aa2a39dea5.diff"
Expand All @@ -144,6 +164,16 @@ patches:
"patch_file": "patches/android-openssl.diff"
- "base_path": "qt5/qtbase"
"patch_file": "patches/android-new-ndk.diff"
- patch_file: "patches/5.15.8-fix-qmake-default-libdirs-apple-clang-15.patch"
base_path: "qt5/qtbase"
patch_description: "Fix build with apple-clang 15"
patch_type: "portability"
patch_source: "https://codereview.qt-project.org/c/qt/qtbase/+/503916"
- patch_file: "patches/5.15.7-fix-macos-cpp-lib-memory-resource.patch"
base_path: "qt5/qtbase"
patch_description: "Fix usage of memory_resource with apple-clang>=15 and deployment target of macOS < 14"
patch_type: "portability"
patch_source: "https://codereview.qt-project.org/c/qt/qtbase/+/482392"
"5.15.8":
- patch_file: "patches/aa2a39dea5.diff"
base_path: "qt5/qtbase"
Expand All @@ -167,6 +197,16 @@ patches:
base_path: "qt5/qtbase"
- patch_file: "patches/android-new-ndk.diff"
base_path: "qt5/qtbase"
- patch_file: "patches/5.15.8-fix-qmake-default-libdirs-apple-clang-15.patch"
base_path: "qt5/qtbase"
patch_description: "Fix build with apple-clang 15"
patch_type: "portability"
patch_source: "https://codereview.qt-project.org/c/qt/qtbase/+/503916"
- patch_file: "patches/5.15.7-fix-macos-cpp-lib-memory-resource.patch"
base_path: "qt5/qtbase"
patch_description: "Fix usage of memory_resource with apple-clang>=15 and deployment target of macOS < 14"
patch_type: "portability"
patch_source: "https://codereview.qt-project.org/c/qt/qtbase/+/482392"
"5.15.7":
- patch_file: "patches/337f28c9ab.patch"
base_path: "qt5/qtbase"
Expand Down Expand Up @@ -198,3 +238,13 @@ patches:
base_path: "qt5/qtbase"
- patch_file: "patches/android-new-ndk.diff"
base_path: "qt5/qtbase"
- patch_file: "patches/5.15.7-fix-qmake-default-libdirs-apple-clang-15.patch"
base_path: "qt5/qtbase"
patch_description: "Fix build with apple-clang 15"
patch_type: "portability"
patch_source: "https://codereview.qt-project.org/c/qt/qtbase/+/503916"
- patch_file: "patches/5.15.7-fix-macos-cpp-lib-memory-resource.patch"
base_path: "qt5/qtbase"
patch_description: "Fix usage of memory_resource with apple-clang>=15 and deployment target of macOS < 14"
patch_type: "portability"
patch_source: "https://codereview.qt-project.org/c/qt/qtbase/+/482392"
67 changes: 34 additions & 33 deletions recipes/qt/5.x.x/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from conan.tools.env import Environment, VirtualBuildEnv, VirtualRunEnv
from conan.tools.files import chdir, copy, get, load, replace_in_file, rm, rmdir, save, export_conandata_patches, apply_conandata_patches
from conan.tools.gnu import PkgConfigDeps
from conan.tools.microsoft import msvc_runtime_flag, is_msvc, VCVars
from conan.tools.microsoft import is_msvc, msvc_runtime_flag, is_msvc_static_runtime, VCVars
from conan.tools.scm import Version
import configparser
import glob
Expand All @@ -15,7 +15,7 @@
import textwrap
import shutil

required_conan_version = ">=1.59.0"
required_conan_version = ">=1.60.0 <2 || >=2.0.5"


class QtConan(ConanFile):
Expand All @@ -33,7 +33,7 @@ class QtConan(ConanFile):
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://www.qt.io"
license = "LGPL-3.0-only"

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand Down Expand Up @@ -308,7 +308,7 @@ def validate(self):
raise ConanInvalidConfiguration("Qt without libc++ needs qt:with_doubleconversion. "
"Either enable qt:with_doubleconversion or switch to libc++")

if "MT" in self.settings.get_safe("compiler.runtime", default="") and self.options.shared:
if is_msvc_static_runtime(self) and self.options.shared:
raise ConanInvalidConfiguration("Qt cannot be built as shared library with static runtime")

if self.settings.compiler == "apple-clang":
Expand Down Expand Up @@ -349,7 +349,7 @@ def requirements(self):
if is_apple_os(self):
self.requires("moltenvk/1.2.2")
if self.options.with_glib:
self.requires("glib/2.77.0")
self.requires("glib/2.78.0")
# if self.options.with_libiconv: # QTBUG-84708
# self.requires("libiconv/1.16")# QTBUG-84708
if self.options.with_doubleconversion and not self.options.multiconfiguration:
Expand All @@ -361,56 +361,56 @@ def requirements(self):
if self.options.get_safe("with_icu", False):
self.requires("icu/73.2")
if self.options.get_safe("with_harfbuzz", False) and not self.options.multiconfiguration:
self.requires("harfbuzz/8.0.1")
self.requires("harfbuzz/8.2.1")
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.5")
self.requires("libjpeg-turbo/3.0.0")
else:
self.requires("libjpeg/9e")
if self.options.get_safe("with_libpng", False) and not self.options.multiconfiguration:
self.requires("libpng/1.6.40")
if self.options.with_sqlite3 and not self.options.multiconfiguration:
self.requires("sqlite3/3.42.0")
self.requires("sqlite3/3.43.1")
if self.options.get_safe("with_mysql", False):
self.requires("libmysqlclient/8.0.31")
self.requires("libmysqlclient/8.1.0")
if self.options.with_pq:
self.requires("libpq/15.3")
self.requires("libpq/15.4")
if self.options.with_odbc:
if self.settings.os != "Windows":
self.requires("odbc/2.3.11")
if self.options.get_safe("with_openal", False):
self.requires("openal-soft/1.22.2")
if self.options.get_safe("with_libalsa", False):
self.requires("libalsa/1.2.7.2")
if self.options.get_safe("with_x11", False):
self.requires("xkbcommon/1.5.0")
self.requires("libalsa/1.2.10")
if self.options.get_safe("with_x11"):
self.requires("xorg/system")
if self.options.get_safe("with_x11") or self.options.qtwayland:
self.requires("xkbcommon/1.5.0")
if self.options.get_safe("opengl", "no") != "no":
self.requires("opengl/system")
if self.options.with_zstd:
self.requires("zstd/1.5.5")
if self.options.qtwebengine and self.settings.os in ["Linux", "FreeBSD"]:
self.requires("expat/2.5.0")
self.requires("opus/1.3.1")
self.requires("opus/1.4")
if not self.options.qtwayland:
self.requires("xorg-proto/2022.2")
self.requires("libxshmfence/1.3")
self.requires("nss/3.89")
self.requires("nss/3.93")
self.requires("libdrm/2.4.114")
self.requires("egl/system")
if self.options.get_safe("with_gstreamer", False):
self.requires("gst-plugins-base/1.19.2")
if self.options.get_safe("with_pulseaudio", False):
self.requires("pulseaudio/14.2")
if self.options.with_dbus:
self.requires("dbus/1.15.6")
self.requires("dbus/1.15.8")
if self.options.qtwayland:
self.requires("wayland/1.22.0")
self.requires("xkbcommon/1.5.0")
if self.settings.os in ['Linux', 'FreeBSD'] and self.options.with_gssapi:
self.requires("krb5/1.18.3") # conan-io/conan-center-index#4102
if self.options.get_safe("with_atspi"):
self.requires("at-spi2-core/2.49.1")
self.requires("at-spi2-core/2.50.0")
if self.options.get_safe("with_md4c", False):
self.requires("md4c/0.4.8")

Expand All @@ -437,12 +437,12 @@ def build_requirements(self):
self.tool_requires("gperf/3.1")
# gperf, bison, flex, python >= 2.7.5 & < 3
if self._settings_build.os == "Windows":
self.tool_requires("winflexbison/2.5.24")
self.tool_requires("winflexbison/2.5.25")
else:
self.tool_requires("bison/3.8.2")
self.tool_requires("flex/2.6.4")
if self.options.qtwayland:
self.tool_requires("wayland/1.22.0")
self.tool_requires("wayland/<host_version>")

def source(self):
get(self, **self.conan_data["sources"][self.version],
Expand Down Expand Up @@ -475,18 +475,6 @@ def generate(self):
env.prepend_path("PKG_CONFIG_PATH", self.generators_folder)
if self.settings.os == "Windows":
env.prepend_path("PATH", os.path.join(self.source_folder, "qt5", "gnuwin32", "bin"))
if self._settings_build.os == "Macos":
# On macOS, SIP resets DYLD_LIBRARY_PATH injected by VirtualBuildEnv & VirtualRunEnv
dyld_library_path = "$DYLD_LIBRARY_PATH"
dyld_library_path_build = vbe.vars().get("DYLD_LIBRARY_PATH")
if dyld_library_path_build:
dyld_library_path = f"{dyld_library_path_build}:{dyld_library_path}"
if not cross_building(self):
dyld_library_path_host = vre.vars().get("DYLD_LIBRARY_PATH")
if dyld_library_path_host:
dyld_library_path = f"{dyld_library_path_host}:{dyld_library_path}"
save(self, "bash_env", f'export DYLD_LIBRARY_PATH="{dyld_library_path}"')
env.define_path("BASH_ENV", os.path.abspath("bash_env"))
env.vars(self).save_script("conan_qt_env_file")

def _make_program(self):
Expand Down Expand Up @@ -801,6 +789,19 @@ def _getenvpath(var):
if self._settings_build.os == "Linux" and self.settings.compiler == "clang":
args += ['QMAKE_CXXFLAGS+="-ftemplate-depth=1024"']

if self._settings_build.os == "Macos":
# On macOS, SIP resets DYLD_LIBRARY_PATH injected by VirtualBuildEnv & VirtualRunEnv.
# Qt builds several executables (moc etc) which are called later on during build of
# libraries, and these executables link to several external dependencies in requirements().
# If these external libs are shared, moc calls fail because its dylib dependencies
# are not found (unless they can be accidentally found in system paths).
# So the workaround is to add libdirs of these external dependencies to LC_RPATH
# of runtime artifacts.
if not cross_building(self):
for libpath in VirtualRunEnv(self).vars().get("DYLD_LIBRARY_PATH", "").split(":"):
# see https://doc.qt.io/qt-5/qmake-variable-reference.html#qmake-rpathdir
args += [f"QMAKE_RPATHDIR+=\"{libpath}\""]

if self.options.qtwebengine and self.settings.os in ["Linux", "FreeBSD"]:
args += ["-qt-webengine-ffmpeg",
"-system-webengine-opus",
Expand Down Expand Up @@ -1048,7 +1049,7 @@ def _create_plugin(pluginname, libname, plugintype, requires):
"exec_prefix=${prefix}",
]
self.cpp_info.components["qtCore"].set_property("pkg_config_custom_content", "\n".join(pkg_config_vars))

if self.settings.os == "Windows":
module = "WinMain"
componentname = f"qt{module}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
--- a/src/corelib/global/qcompilerdetection.h
+++ b/src/corelib/global/qcompilerdetection.h
@@ -1050,16 +1050,22 @@
# endif // !_HAS_CONSTEXPR
# endif // !__GLIBCXX__ && !_LIBCPP_VERSION
# endif // Q_OS_QNX
-# if (defined(Q_CC_CLANG) || defined(Q_CC_INTEL)) && defined(Q_OS_MAC) && defined(__GNUC_LIBSTD__) \
- && ((__GNUC_LIBSTD__-0) * 100 + __GNUC_LIBSTD_MINOR__-0 <= 402)
+# if (defined(Q_CC_CLANG) || defined(Q_CC_INTEL)) && defined(Q_OS_MAC)
+# if defined(__GNUC_LIBSTD__) && ((__GNUC_LIBSTD__-0) * 100 + __GNUC_LIBSTD_MINOR__-0 <= 402)
// Apple has not updated libstdc++ since 2007, which means it does not have
// <initializer_list> or std::move. Let's disable these features
-# undef Q_COMPILER_INITIALIZER_LISTS
-# undef Q_COMPILER_RVALUE_REFS
-# undef Q_COMPILER_REF_QUALIFIERS
+# undef Q_COMPILER_INITIALIZER_LISTS
+# undef Q_COMPILER_RVALUE_REFS
+# undef Q_COMPILER_REF_QUALIFIERS
// Also disable <atomic>, since it's clearly not there
-# undef Q_COMPILER_ATOMICS
-# endif
+# undef Q_COMPILER_ATOMICS
+# endif
+# if defined(__cpp_lib_memory_resource) \
+ && ((defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 140000) \
+ || (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 170000))
+# undef __cpp_lib_memory_resource // Only supported on macOS 14 and iOS 17
+# endif
+# endif // (defined(Q_CC_CLANG) || defined(Q_CC_INTEL)) && defined(Q_OS_MAC)
# if defined(Q_CC_CLANG) && defined(Q_CC_INTEL) && Q_CC_INTEL >= 1500
// ICC 15.x and 16.0 have their own implementation of std::atomic, which is activated when in Clang mode
// (probably because libc++'s <atomic> on OS X failed to compile), but they're missing some
--- a/src/corelib/tools/qduplicatetracker_p.h
+++ b/src/corelib/tools/qduplicatetracker_p.h
@@ -52,7 +52,7 @@

#include <qglobal.h>

-#if QT_HAS_INCLUDE(<memory_resource>) && __cplusplus > 201402L
+#if defined(__cpp_lib_memory_resource) && __cplusplus > 201402L
# include <unordered_set>
# include <memory_resource>
#else
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
--- a/src/corelib/global/qcompilerdetection.h
+++ b/src/corelib/global/qcompilerdetection.h
@@ -1041,16 +1041,22 @@
# endif // !_HAS_CONSTEXPR
# endif // !__GLIBCXX__ && !_LIBCPP_VERSION
# endif // Q_OS_QNX
-# if (defined(Q_CC_CLANG) || defined(Q_CC_INTEL)) && defined(Q_OS_MAC) && defined(__GNUC_LIBSTD__) \
- && ((__GNUC_LIBSTD__-0) * 100 + __GNUC_LIBSTD_MINOR__-0 <= 402)
+# if (defined(Q_CC_CLANG) || defined(Q_CC_INTEL)) && defined(Q_OS_MAC)
+# if defined(__GNUC_LIBSTD__) && ((__GNUC_LIBSTD__-0) * 100 + __GNUC_LIBSTD_MINOR__-0 <= 402)
// Apple has not updated libstdc++ since 2007, which means it does not have
// <initializer_list> or std::move. Let's disable these features
-# undef Q_COMPILER_INITIALIZER_LISTS
-# undef Q_COMPILER_RVALUE_REFS
-# undef Q_COMPILER_REF_QUALIFIERS
+# undef Q_COMPILER_INITIALIZER_LISTS
+# undef Q_COMPILER_RVALUE_REFS
+# undef Q_COMPILER_REF_QUALIFIERS
// Also disable <atomic>, since it's clearly not there
-# undef Q_COMPILER_ATOMICS
-# endif
+# undef Q_COMPILER_ATOMICS
+# endif
+# if defined(__cpp_lib_memory_resource) \
+ && ((defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 140000) \
+ || (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 170000))
+# undef __cpp_lib_memory_resource // Only supported on macOS 14 and iOS 17
+# endif
+# endif // (defined(Q_CC_CLANG) || defined(Q_CC_INTEL)) && defined(Q_OS_MAC)
# if defined(Q_CC_CLANG) && defined(Q_CC_INTEL) && Q_CC_INTEL >= 1500
// ICC 15.x and 16.0 have their own implementation of std::atomic, which is activated when in Clang mode
// (probably because libc++'s <atomic> on OS X failed to compile), but they're missing some
--- a/src/corelib/tools/qduplicatetracker_p.h
+++ b/src/corelib/tools/qduplicatetracker_p.h
@@ -52,7 +52,7 @@

#include <qglobal.h>

-#if QT_HAS_INCLUDE(<memory_resource>) && __cplusplus > 201402L
+#if defined(__cpp_lib_memory_resource) && __cplusplus > 201402L
# include <unordered_set>
# include <memory_resource>
#else
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--- a/mkspecs/features/toolchain.prf
+++ b/mkspecs/features/toolchain.prf
@@ -283,9 +283,12 @@ isEmpty($${target_prefix}.INCDIRS) {
}
}
}
- isEmpty(QMAKE_DEFAULT_LIBDIRS)|isEmpty(QMAKE_DEFAULT_INCDIRS): \
+ isEmpty(QMAKE_DEFAULT_INCDIRS): \
!integrity: \
- error("failed to parse default search paths from compiler output")
+ error("failed to parse default include paths from compiler output")
+ isEmpty(QMAKE_DEFAULT_LIBDIRS): \
+ !integrity:!darwin: \
+ error("failed to parse default library paths from compiler output")
QMAKE_DEFAULT_LIBDIRS = $$unique(QMAKE_DEFAULT_LIBDIRS)
} else: ghs {
cmd = $$QMAKE_CXX $$QMAKE_CXXFLAGS -$${LITERAL_HASH} -o /tmp/fake_output /tmp/fake_input.cpp
@@ -407,7 +410,7 @@ isEmpty($${target_prefix}.INCDIRS) {
QMAKE_DEFAULT_INCDIRS = $$split(INCLUDE, $$QMAKE_DIRLIST_SEP)
}

- unix:if(!cross_compile|host_build) {
+ unix:!darwin:if(!cross_compile|host_build) {
isEmpty(QMAKE_DEFAULT_INCDIRS): QMAKE_DEFAULT_INCDIRS = /usr/include /usr/local/include
isEmpty(QMAKE_DEFAULT_LIBDIRS): QMAKE_DEFAULT_LIBDIRS = /lib /usr/lib
}
Loading

0 comments on commit 79c5a17

Please sign in to comment.