Skip to content

Commit

Permalink
(#24071) opencv 4.x: honor dynamic runtime from conan profile when co…
Browse files Browse the repository at this point in the history
…mpiler is clang-cl
  • Loading branch information
SpaceIm authored May 30, 2024
1 parent fd2f2bb commit c49991d
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions recipes/opencv/4.x/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from conan.tools.env import VirtualBuildEnv, VirtualRunEnv
from conan.tools.files import apply_conandata_patches, collect_libs, copy, export_conandata_patches, get, rename, replace_in_file, rmdir, save
from conan.tools.gnu import PkgConfigDeps
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime
from conan.tools.microsoft import msvc_runtime_flag
from conan.tools.scm import Version
import os
import re
Expand Down Expand Up @@ -220,6 +220,14 @@ class OpenCVConan(ConanFile):

short_paths = True

@property
def _is_cl_like(self):
return self.settings.compiler.get_safe("runtime") is not None

@property
def _is_cl_like_static_runtime(self):
return self._is_cl_like and "MT" in msvc_runtime_flag(self)

@property
def _is_mingw(self):
return self.settings.os == "Windows" and self.settings.compiler == "gcc"
Expand Down Expand Up @@ -1190,8 +1198,8 @@ def validate(self):
self._check_mandatory_options(self._opencv_modules)
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, 11)
if self.options.shared and is_msvc(self) and is_msvc_static_runtime(self):
raise ConanInvalidConfiguration("Visual Studio with static runtime is not supported for shared library.")
if self.options.shared and self._is_cl_like and self._is_cl_like_static_runtime:
raise ConanInvalidConfiguration("MSVC or clang-cl with static runtime are not supported for shared library.")
if self.settings.compiler == "clang" and Version(self.settings.compiler.version) < "4":
raise ConanInvalidConfiguration("Clang 3.x can't build OpenCV 4.x due to an internal bug.")
if self.options.get_safe("dnn_cuda") and \
Expand Down Expand Up @@ -1445,7 +1453,7 @@ def generate(self):
tc.variables["WITH_GDAL"] = self.options.get_safe("with_gdal", False)
tc.variables["WITH_GDCM"] = self.options.get_safe("with_gdcm", False)
tc.variables["WITH_EIGEN"] = self.options.with_eigen
tc.variables["WITH_DSHOW"] = is_msvc(self)
tc.variables["WITH_DSHOW"] = self._is_cl_like
tc.variables["WITH_MSMF"] = self.options.get_safe("with_msmf", False)
tc.variables["WITH_MSMF_DXVA"] = self.options.get_safe("with_msmf_dxva", False)
tc.variables["OPENCV_MODULES_PUBLIC"] = "opencv"
Expand Down Expand Up @@ -1522,8 +1530,8 @@ def generate(self):
tc.variables["ENABLE_PIC"] = self.options.get_safe("fPIC", True)
tc.variables["ENABLE_CCACHE"] = False

if is_msvc(self):
tc.variables["BUILD_WITH_STATIC_CRT"] = is_msvc_static_runtime(self)
if self._is_cl_like:
tc.variables["BUILD_WITH_STATIC_CRT"] = self._is_cl_like_static_runtime

if self.settings.os == "Android":
tc.variables["BUILD_ANDROID_EXAMPLES"] = False
Expand Down

0 comments on commit c49991d

Please sign in to comment.