Repository: conan-io/conan-center-index

Issue:
[question] building Qt 5 for iOS
Qt 5 tries to build for iOS with bitcode enabled, but its dependencies are built with bitcode disabled.

I've tried adding `QMAKE_CFLAGS+=-fembed-bitcode=off` (and the same for `QMAKE_CXXFLAGS`, `QMAKE_LFLAGS` and `QMAKE_OBJECTIVE_CFLAGS`), but it doesn't help: this flag is passed before the `-fembed-bitcode` which is probably coming from mkspec. `CONFIG-=bitcode` can't be passed to `configure`, unfortunately.

Is the only way to patch `qtbase/mkspecs/features/uikit/bitcode.prf` to remove bitcode flags?

Example of error:

```
Checking for Zstandard... 
Trying source 0 (type pkgConfig) of library zstd ...
pkg-config use disabled globally.
  => source produced no result.
Trying source 1 (type inline) of library zstd ...
+ cd /Users/kambala/.conan/data/qt/5.15.5/_/_/build/181d5c9ad190c6d07344f95e48053866c50d8379/build_folder/config.tests/zstd && /Users/kambala/.conan/data/qt/5.15.5/_/_/build/181d5c9ad190c6d07344f95e48053866c50d8379/build_folder/qtbase/bin/qmake "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += static warn_off console single_arch" 'DEFINES += PCRE2_STATIC' 'INCLUDEPATH += /Users/kambala/.conan/data/pcre2/10.40/_/_/package/fb70439ef4214351c5be71ba5e3a6edd12f6e4e5/include /Users/kambala/.conan/data/double-conversion/3.2.0/_/_/package/6442e54871cb828a85b811dd62ed4e7975d61324/include /Users/kambala/.conan/data/zstd/1.5.2/_/_/package/5fcae7f4671065a802bcee65f1bd61b5b386ff20/include /Users/kambala/.conan/data/libpng/1.6.37/_/_/package/2fa0a23ec170d2ae457128c32bfe7fc75aecb372/include' 'QMAKE_LIBDIR+=/Users/kambala/.conan/data/pcre2/10.40/_/_/package/fb70439ef4214351c5be71ba5e3a6edd12f6e4e5/lib /Users/kambala/.conan/data/double-conversion/3.2.0/_/_/package/6442e54871cb828a85b811dd62ed4e7975d61324/lib /Users/kambala/.conan/data/zstd/1.5.2/_/_/package/5fcae7f4671065a802bcee65f1bd61b5b386ff20/lib /Users/kambala/.conan/data/libpng/1.6.37/_/_/package/2fa0a23ec170d2ae457128c32bfe7fc75aecb372/lib' QMAKE_RPATHLINKDIR+=/Users/kambala/.conan/data/pcre2/10.40/_/_/package/fb70439ef4214351c5be71ba5e3a6edd12f6e4e5/lib:/Users/kambala/.conan/data/double-conversion/3.2.0/_/_/package/6442e54871cb828a85b811dd62ed4e7975d61324/lib:/Users/kambala/.conan/data/zstd/1.5.2/_/_/package/5fcae7f4671065a802bcee65f1bd61b5b386ff20/lib:/Users/kambala/.conan/data/libpng/1.6.37/_/_/package/2fa0a23ec170d2ae457128c32bfe7fc75aecb372/lib QMAKE_CFLAGS+=-fembed-bitcode=off QMAKE_CXXFLAGS+=-fembed-bitcode=off QMAKE_LFLAGS+=-fembed-bitcode=off QMAKE_OBJECTIVE_CFLAGS+=-fembed-bitcode=off -early "CONFIG += cross_compile" 'QMAKE_USE += zstd' 'QMAKE_LIBS_ZSTD = -lzstd' /Users/kambala/.conan/data/qt/5.15.5/_/_/build/181d5c9ad190c6d07344f95e48053866c50d8379/build_folder/config.tests/zstd
+ cd /Users/kambala/.conan/data/qt/5.15.5/_/_/build/181d5c9ad190c6d07344f95e48053866c50d8379/build_folder/config.tests/zstd && MAKEFLAGS= /usr/bin/make
> /Applications/Xcode12.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -fembed-bitcode=off -O2 -std=gnu++11  -arch arm64 -isysroot /Applications/Xcode12.4.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.4.sdk -miphoneos-version-min=12.0 -fobjc-nonfragile-abi -fobjc-legacy-dispatch -w -fembed-bitcode -fPIC -DPCRE2_STATIC -I. -I/Users/kambala/.conan/data/qt/5.15.5/_/_/source/qt5/qtbase/mkspecs/common/uikit -I/Users/kambala/.conan/data/pcre2/10.40/_/_/package/fb70439ef4214351c5be71ba5e3a6edd12f6e4e5/include -I/Users/kambala/.conan/data/double-conversion/3.2.0/_/_/package/6442e54871cb828a85b811dd62ed4e7975d61324/include -I/Users/kambala/.conan/data/zstd/1.5.2/_/_/package/5fcae7f4671065a802bcee65f1bd61b5b386ff20/include -I/Users/kambala/.conan/data/libpng/1.6.37/_/_/package/2fa0a23ec170d2ae457128c32bfe7fc75aecb372/include -I/Users/kambala/.conan/data/qt/5.15.5/_/_/source/qt5/qtbase/mkspecs/macx-ios-clang -o main.o main.cpp
> /Applications/Xcode12.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -stdlib=libc++ -fembed-bitcode=off  -arch arm64 -isysroot /Applications/Xcode12.4.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.4.sdk -miphoneos-version-min=12.0 -fembed-bitcode -Wl,-rpath,@executable_path/Frameworks -o zstd main.o   -L/Users/kambala/.conan/data/pcre2/10.40/_/_/package/fb70439ef4214351c5be71ba5e3a6edd12f6e4e5/lib -L/Users/kambala/.conan/data/double-conversion/3.2.0/_/_/package/6442e54871cb828a85b811dd62ed4e7975d61324/lib -L/Users/kambala/.conan/data/zstd/1.5.2/_/_/package/5fcae7f4671065a802bcee65f1bd61b5b386ff20/lib -L/Users/kambala/.conan/data/libpng/1.6.37/_/_/package/2fa0a23ec170d2ae457128c32bfe7fc75aecb372/lib -lzstd   
> ld: '/Users/kambala/.conan/data/zstd/1.5.2/_/_/package/5fcae7f4671065a802bcee65f1bd61b5b386ff20/lib/libzstd.a(zstd_compress.c.o)' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture arm64
> clang: error: linker command failed with exit code 1 (use -v to see invocation)
> make: *** [zstd] Error 1
 => source failed verification.
test config.qtbase.libraries.zstd FAILED

...

ERROR: Feature 'zstd' was enabled, but the pre-condition 'libs.zstd' failed.
```


Discussion:
I don't know whether it's the only way to remove hardcoded bitcode flags from Qt5 build system, but I confirm that in conancenter, bitcode shouldn't be enabled by default, but should come from conan profile.
> I don't know whether it's the only way to remove hardcoded bitcode flags from Qt5 build system, but I confirm that in conancenter, bitcode shouldn't be enabled by default, but should come from conan profile.

@SpaceIm do you know if there's profile option besides CMakeToolchain's `tools.build:tools.apple:enable_bitcode` to control bitcode? Just noticed that Boost recipe also adds bitcode unconditionally: https://github.com/conan-io/conan-center-index/blob/f47ff2901878cbc6b462a14b98a73bdd34ca7a22/recipes/boost/all/conanfile.py#L1112
for a simple local workaround did the following in a hook file:

```python
def pre_build(output, conanfile, **kwargs):
    if kwargs["reference"].name != "qt":
        return
    output.info("deleting bitcode flags")
    open(f"{conanfile.source_folder}/qt5/qtbase/mkspecs/features/uikit/bitcode.prf", "w").close()
```

Resolving patch:
diff --git a/recipes/qt/5.x.x/conanfile.py b/recipes/qt/5.x.x/conanfile.py
--- a/recipes/qt/5.x.x/conanfile.py
+++ b/recipes/qt/5.x.x/conanfile.py
@@ -441,6 +441,7 @@ def source(self):
             "-ldbus-1d",
             "-ldbus-1"
         )
+        open(os.path.join(self.source_folder, "qt5", "qtbase", "mkspecs", "features", "uikit", "bitcode.prf"), "w").close()
 
     def _make_program(self):
         if self._is_msvc:


Test patch: