Skip to content

Commit

Permalink
add option to allow disabling videoio
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceIm committed Jan 10, 2023
1 parent 5bf15a9 commit 7619df4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
41 changes: 25 additions & 16 deletions recipes/opencv/4.x/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class OpenCVConan(ConanFile):
"gapi": [True, False],
"highgui": [True, False],
"stitching": [True, False],
"videoio": [True, False],
"dnn_cuda": [True, False],
"cuda_arch_bin": [None, "ANY"],
"cpu_baseline": [None, "ANY"],
Expand Down Expand Up @@ -170,6 +171,7 @@ class OpenCVConan(ConanFile):
"gapi": True,
"highgui": True,
"stitching": True,
"videoio": True,
"dnn_cuda": False,
"cuda_arch_bin": None,
"cpu_baseline": None,
Expand Down Expand Up @@ -269,15 +271,17 @@ def config_options(self):
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
if not self.options.dnn:
self.options.rm_safe("dnn_cuda")
if not self.options.highgui:
self.options.rm_safe("with_gtk")
if not self.options.dnn:
del self.options.dnn_cuda
if not self.options.videoio:
self.options.rm_safe("with_ffmpeg")
if not self.options.with_cuda:
del self.options.with_cublas
del self.options.with_cudnn
del self.options.with_cufft
del self.options.dnn_cuda
self.options.rm_safe("dnn_cuda")
del self.options.cuda_arch_bin
if bool(self.options.with_jpeg):
if self.options.get_safe("with_jpeg2000") == "jasper":
Expand Down Expand Up @@ -680,7 +684,7 @@ def generate(self):
tc.variables["BUILD_opencv_photo"] = True
tc.variables["BUILD_opencv_stitching"] = self.options.stitching
tc.variables["BUILD_opencv_video"] = True
tc.variables["BUILD_opencv_videoio"] = True
tc.variables["BUILD_opencv_videoio"] = self.options.videoio

# Contrib modules
tc.variables["OPENCV_EXTRA_MODULES_PATH"] = os.path.join(self._contrib_folder, "modules").replace("\\", "/")
Expand Down Expand Up @@ -910,6 +914,9 @@ def opencv_cudawarping():
def opencv_dnn():
return ["opencv_dnn"] if self.options.dnn else []

def opencv_videoio():
return ["opencv_videoio"] if self.options.videoio else []

def opencv_xfeatures2d():
return ["opencv_xfeatures2d"] if self.options.contrib_xfeatures2d else []

Expand Down Expand Up @@ -941,9 +948,6 @@ def requires_video():
requires.extend(opencv_dnn())
return requires

def requires_videoio():
return ["opencv_imgproc", "opencv_imgcodecs"] + ffmpeg() + eigen() + ipp()

opencv_components = [
{"target": "opencv_calib3d", "lib": "calib3d", "requires": requires_calib3d()},
{"target": "opencv_core", "lib": "core", "requires": requires_core()},
Expand All @@ -955,7 +959,6 @@ def requires_videoio():
{"target": "opencv_objdetect", "lib": "objdetect", "requires": requires_objdetect()},
{"target": "opencv_photo", "lib": "photo", "requires": requires_photo()},
{"target": "opencv_video", "lib": "video", "requires": requires_video()},
{"target": "opencv_videoio", "lib": "videoio", "requires": requires_videoio()},
]
if self.options.with_ipp == "opencv-icv" and not self.options.shared:
opencv_components.extend([
Expand All @@ -976,8 +979,8 @@ def requires_videoio():
{"target": "opencv_gapi", "lib": "gapi", "requires": requires_gapi},
])
if self.options.highgui:
requires_highgui = ["opencv_core", "opencv_imgproc", "opencv_imgcodecs", "opencv_videoio"] + \
freetype() + gtk() + eigen() + ipp()
requires_highgui = ["opencv_core", "opencv_imgproc", "opencv_imgcodecs"] + \
opencv_videoio() + freetype() + gtk() + eigen() + ipp()
opencv_components.extend([
{"target": "opencv_highgui", "lib": "highgui", "requires": requires_highgui},
])
Expand All @@ -988,6 +991,11 @@ def requires_videoio():
opencv_components.extend([
{"target": "opencv_stitching", "lib": "stitching", "requires": requires_stitching},
])
if self.options.videoio:
requires_videoio = ["opencv_imgproc", "opencv_imgcodecs"] + ffmpeg() + eigen() + ipp()
opencv_components.extend([
{"target": "opencv_videoio", "lib": "videoio", "requires": requires_videoio},
])

# Contrib components
if self.options.get_safe("contrib_alphamat"):
Expand Down Expand Up @@ -1154,7 +1162,7 @@ def requires_videoio():
{"target": "opencv_structured_light", "lib": "structured_light", "requires": requires_structured_light},
])
if self.options.get_safe("contrib_superres"):
requires_superres = ["opencv_imgproc", "opencv_video", "opencv_optflow", "opencv_videoio"] + \
requires_superres = ["opencv_imgproc", "opencv_video", "opencv_optflow"] + opencv_videoio() + \
eigen() + ipp() + opencv_cudaarithm() + opencv_cudafilters() + opencv_cudawarping() + \
opencv_cudaimgproc() + opencv_cudaoptflow() + opencv_cudacodec()
opencv_components.extend([
Expand All @@ -1176,9 +1184,8 @@ def requires_videoio():
{"target": "opencv_tracking", "lib": "tracking", "requires": requires_tracking},
])
if self.options.contrib_videostab:
requires_videostab = ["opencv_imgproc", "opencv_features2d", "opencv_video", "opencv_photo",
"opencv_calib3d", "opencv_videoio"] + \
eigen() + ipp() + opencv_cudawarping() + opencv_cudaoptflow()
requires_videostab = ["opencv_imgproc", "opencv_features2d", "opencv_video", "opencv_photo", "opencv_calib3d"] + \
opencv_videoio() + eigen() + ipp() + opencv_cudawarping() + opencv_cudaoptflow()
opencv_components.extend([
{"target": "opencv_videostab", "lib": "videostab", "requires": requires_videostab},
])
Expand Down Expand Up @@ -1303,9 +1310,11 @@ def add_components(components):
elif self.settings.os == "Macos":
if self.options.highgui:
self.cpp_info.components["opencv_highgui"].frameworks = ["Cocoa"]
self.cpp_info.components["opencv_videoio"].frameworks = ["Cocoa", "Accelerate", "AVFoundation", "CoreGraphics", "CoreMedia", "CoreVideo", "QuartzCore"]
if self.options.videoio:
self.cpp_info.components["opencv_videoio"].frameworks = ["Cocoa", "Accelerate", "AVFoundation", "CoreGraphics", "CoreMedia", "CoreVideo", "QuartzCore"]
elif self.settings.os == "iOS":
self.cpp_info.components["opencv_videoio"].frameworks = ["AVFoundation", "QuartzCore"]
if self.options.videoio:
self.cpp_info.components["opencv_videoio"].frameworks = ["AVFoundation", "QuartzCore"]

# TODO: to remove in conan v2 once cmake_find_package* generators removed
self.cpp_info.filenames["cmake_find_package"] = "OpenCV"
Expand Down
2 changes: 1 addition & 1 deletion recipes/opencv/4.x/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def requirements(self):
def generate(self):
tc = CMakeToolchain(self)
tc.variables["built_gapi"] = self.dependencies["opencv"].options.gapi
tc.variables["built_with_ffmpeg"] = self.dependencies["opencv"].options.with_ffmpeg
tc.variables["built_with_ffmpeg"] = self.dependencies["opencv"].options.videoio and self.dependencies["opencv"].options.with_ffmpeg
tc.variables["built_contrib_sfm"] = self.dependencies["opencv"].options.contrib_sfm
tc.generate()

Expand Down
2 changes: 1 addition & 1 deletion recipes/opencv/4.x/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TestPackageConan(ConanFile):
def build(self):
cmake = CMake(self)
cmake.definitions["built_gapi"] = self.options["opencv"].gapi
cmake.definitions["built_with_ffmpeg"] = self.options["opencv"].with_ffmpeg
cmake.definitions["built_with_ffmpeg"] = self.options["opencv"].videoio and self.options["opencv"].with_ffmpeg
cmake.definitions["built_contrib_sfm"] = self.options["opencv"].contrib_sfm
cmake.configure()
cmake.build()
Expand Down

0 comments on commit 7619df4

Please sign in to comment.