Skip to content

build_xcframework.py fails if the OpenCV directory is under /private/var #26712

@homuler

Description

@homuler

System Information

OpenCV version: 4.10.0
Operating System / Platform: macOS Sonoma 14.5
CMake version: 3.30.2
Xcode version: 16.2
Python version: 3.12.5

Detailed description

When OpenCV directory is placed under /private/var, build_xcframework.py fails with the following error.

CompileC /private/var/tmp/opencv-test/out/iphoneos/build/build-arm64-iphoneos/modules/objc/framework_build/build/opencv2.build/Release-iphoneos/Objects-normal/arm64/MatQuickLook.o /private/var/tmp/opencv-test/out/iphoneos/build/build-arm64-iphoneos/modules/objc_bindings_generator/ios/gen/objc/imgcodecs/MatQuickLook.mm normal arm64 objective-c++ com.apple.compilers.llvm.clang.1_0.compiler (in target 'opencv2' from project 'opencv2')
    cd /private/var/tmp/opencv-test/out/iphoneos/build/build-arm64-iphoneos/modules/objc_bindings_generator/ios/gen
    
    Using response file: /private/var/tmp/opencv-test/out/iphoneos/build/build-arm64-iphoneos/modules/objc/framework_build/build/opencv2.build/Release-iphoneos/Objects-normal/arm64/af3fcb34312c57c0f52879cdce924b91-common-args.resp
    
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c++ -ivfsstatcache /var/folders/wl/rp5twb9s5391yw5bljspp9yw0000gn/C/com.apple.DeveloperTools/16.2-16C5032a/Xcode/SDKStatCaches.noindex/iphoneos18.2-22C146-d5b9239ec3bf5b3adbecdf21472871e3.sdkstatcache -fmessage-length\=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit\=0 -fno-color-diagnostics -Wno-trigraphs -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-implicit-atomic-properties -Wno-objc-interface-ivars -Wno-arc-repeated-use-of-weak -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wno-float-conversion -Wno-non-literal-null-conversion -Wno-objc-literal-conversion -Wshorten-64-to-32 -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wno-undeclared-selector -Wno-deprecated-implementations -Wno-c++11-extensions -Wno-implicit-fallthrough -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -Winvalid-offsetof -Wno-sign-conversion -Wno-infinite-recursion -Wno-move -Wno-comma -Wno-block-capture-autoreleasing -Wno-strict-prototypes -Wno-range-loop-analysis -Wno-semicolon-before-method-body -Wno-incomplete-umbrella @/private/var/tmp/opencv-test/out/iphoneos/build/build-arm64-iphoneos/modules/objc/framework_build/build/opencv2.build/Release-iphoneos/Objects-normal/arm64/af3fcb34312c57c0f52879cdce924b91-common-args.resp -MMD -MT dependencies -MF /private/var/tmp/opencv-test/out/iphoneos/build/build-arm64-iphoneos/modules/objc/framework_build/build/opencv2.build/Release-iphoneos/Objects-normal/arm64/MatQuickLook.d --serialize-diagnostics /private/var/tmp/opencv-test/out/iphoneos/build/build-arm64-iphoneos/modules/objc/framework_build/build/opencv2.build/Release-iphoneos/Objects-normal/arm64/MatQuickLook.dia -c /private/var/tmp/opencv-test/out/iphoneos/build/build-arm64-iphoneos/modules/objc_bindings_generator/ios/gen/objc/imgcodecs/MatQuickLook.mm -o /private/var/tmp/opencv-test/out/iphoneos/build/build-arm64-iphoneos/modules/objc/framework_build/build/opencv2.build/Release-iphoneos/Objects-normal/arm64/MatQuickLook.o
/private/var/tmp/opencv-test/out/iphoneos/build/build-arm64-iphoneos/modules/objc_bindings_generator/ios/gen/objc/imgcodecs/MatQuickLook.mm:10:9: fatal error: 'Imgproc.h' file not found
   10 | #import "Imgproc.h"
      |         ^~~~~~~~~~~
1 error generated.

It seems that gen_objc.py is ignoring some files when generating header files, and under certain conditions, it ends up ignoring the necessary header files.

re_bad = re.compile(r'(private|.inl.hpp$|_inl.hpp$|.detail.hpp$|.details.hpp$|_winrt.hpp$|/cuda/|/legacy/)')
# .h files before .hpp
h_files = []
hpp_files = []
for root, dirnames, filenames in os.walk(os.path.join(module_location, 'include')):
h_files += [os.path.join(root, filename) for filename in fnmatch.filter(filenames, '*.h')]
hpp_files += [os.path.join(root, filename) for filename in fnmatch.filter(filenames, '*.hpp')]
srcfiles = h_files + hpp_files
srcfiles = [f for f in srcfiles if not re_bad.search(f.replace('\\', '/'))]

For example, when trying to build OpenCV using Bazel, this issue occurs because Bazel places the code under /private/var/tmp.

Steps to reproduce

  1. clone the repository under /private/var/tmp
  2. run platforms/apple/build_xcframework.py --iphoneos_archs arm64 --build_only_specified_archs --out out

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions