Trying to build older version of opencv with contrib for ios: Not possible?

For iOS I’m trying to build an earlier version of opencv with contrib (4.2 to be exact) using this command:
python3 opencv/platforms/ios/build_framework.py ./contrib_output --without objc --contrib opencv_contrib --iphoneos_archs arm64 --iphonesimulator_archs x86_64

But I’m getting this error:

Using IPHONEOS_DEPLOYMENT_TARGET=8.0
Using iPhoneOS ARCHS=['arm64']
Using iPhoneSimulator ARCHS=['x86_64']
============================================================
ERROR: cannot use a string pattern on a bytes-like object
============================================================
Traceback (most recent call last):
  File "/Users/xyz/Documents/openCV/opencv/platforms/ios/build_framework.py", line 120, in build
    self._build(outdir)
  File "/Users/xyz/Documents/openCV/opencv/platforms/ios/build_framework.py", line 88, in _build
    xcode_ver = getXCodeMajor()
                ^^^^^^^^^^^^^^^
  File "/Users/xyz/Documents/openCV/opencv/platforms/ios/build_framework.py", line 45, in getXCodeMajor
    m = re.match(r'Xcode\s+(\d+)\..*', ret, flags=re.IGNORECASE)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/re/__init__.py", line 167, in match
    return _compile(pattern, flags).match(string)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: cannot use a string pattern on a bytes-like object

if you want to get around that error, you could edit the source of build_framework.py and insert something along the lines of ret.decode('utf-8') in the re.match call

I’m a total stranger to python but I tried the fallowing. Unfortunately it didn’t work:

def getXCodeMajor():
ret = check_output([“xcodebuild”, “-version”]).decode(‘utf-8’)
print (‘---------’ , ret)
m = re.match(r’Xcode\s+(\d+)..*', ret, flags=re.IGNORECASE)
ret = ret.decode(‘utf-8’)

if m:
    return int(m.group(1))
else:
    raise Exception("Failed to parse Xcode version")

I managed to pass that error somehow but I have new problems now:

– Check size of size_t
CMake Error at /opt/homebrew/lib/python3.11/site-packages/cmake/data/share/cmake-3.27/Modules/CheckTypeSize.cmake:146 (try_compile):
Cannot copy output executable

''

to destination specified by COPY_FILE:

'/Users/xyz/Documents/openCV/contrib_output/build/build-arm64-iphoneos/CMakeFiles/CheckTypeSize/SIZEOF_SIZE_T.bin'

because:

No such file or directory (input)

Recorded try_compile output location doesn’t exist:

/Users/xyz/Documents/openCV/contrib_output/build/build-arm64-iphoneos/CMakeFiles/CMakeScratch/TryCompile-kspIwK/Release/cmTC_ed1bc.app/cmTC_ed1bc

Call Stack (most recent call first):
/opt/homebrew/lib/python3.11/site-packages/cmake/data/share/cmake-3.27/Modules/CheckTypeSize.cmake:271 (__check_type_size_impl)
3rdparty/libjpeg-turbo/CMakeLists.txt:25 (check_type_size)

– Check size of unsigned long
CMake Error at /opt/homebrew/lib/python3.11/site-packages/cmake/data/share/cmake-3.27/Modules/CheckTypeSize.cmake:146 (try_compile):
Cannot copy output executable

''

to destination specified by COPY_FILE:

'/Users/xyz/Documents/openCV/contrib_output/build/build-arm64-iphoneos/CMakeFiles/CheckTypeSize/SIZEOF_UNSIGNED_LONG.bin'

because:

No such file or directory (input)

Recorded try_compile output location doesn’t exist:

/Users/xyz/Documents/openCV/contrib_output/build/build-arm64-iphoneos/CMakeFiles/CMakeScratch/TryCompile-gLKvsK/Release/cmTC_4ce9e.app/cmTC_4ce9e

Call Stack (most recent call first):
/opt/homebrew/lib/python3.11/site-packages/cmake/data/share/cmake-3.27/Modules/CheckTypeSize.cmake:271 (__check_type_size_impl)
3rdparty/libjpeg-turbo/CMakeLists.txt:26 (check_type_size)

not after the match call but in the match call:

m = re.match(r'Xcode\s+(\d+)\..*', ret.decode('utf-8'), flags=re.IGNORECASE)

that’s just a guess. according to the error message it should work.

that other error is completely beyond me. '' indicates that something wasn’t set or couldn’t be figured out by the cmake script.

try fixing the first issue, then make sure to clean the “cmake cache” before trying to configure/generate again.